79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { NbDialogRef } from '@nebular/theme';
|
|
import { HappinessTask, HappinessTaskType, HappinessWeek } from '../../../entity/HappinessGroup';
|
|
import { HappinessTaskService } from '../../../services/crudServices/happiness-group.service';
|
|
import { first } from 'rxjs/operators';
|
|
import { DropDownOption } from '../../../entity/dropDownOption';
|
|
import { StringUtils } from '../../../utilities/string-utils';
|
|
|
|
@Component({
|
|
selector: 'ngx-week-task-editor',
|
|
templateUrl: './week-task-editor.component.html',
|
|
styleUrls: ['./week-task-editor.component.scss']
|
|
})
|
|
export class WeekTaskEditorComponent implements OnInit {
|
|
processing: boolean = false;
|
|
allData: HappinessWeek[];
|
|
data: HappinessWeek;
|
|
taskrOptions: DropDownOption[] = [];
|
|
constructor(
|
|
private happinessTaskService: HappinessTaskService,
|
|
private dlgRef: NbDialogRef<WeekTaskEditorComponent>
|
|
) {
|
|
|
|
}
|
|
ngOnInit(): void {
|
|
if (this.data.tasks.length == 0) {
|
|
this.data.tasks = [];
|
|
for (let i = HappinessTaskType.IceBreak; i <= HappinessTaskType.Dessert; i++) {
|
|
this.data.tasks.push(
|
|
{
|
|
weekId: this.data.id,
|
|
id: 'new',
|
|
type: i as HappinessTaskType,
|
|
tasker: '',
|
|
content: ''
|
|
} as HappinessTask
|
|
|
|
)
|
|
}
|
|
}
|
|
let names = [] as string[];
|
|
this.allData.forEach(week => {
|
|
if (week.tasks) {
|
|
names = names.concat(week.tasks.map(t => t.tasker.trim()));
|
|
|
|
}
|
|
});
|
|
this.taskrOptions = names.filter(function (item, pos) {
|
|
return !StringUtils.isNullOrWhitespace(item) && names.indexOf(item) == pos;
|
|
}).map(name => new DropDownOption(name, name));
|
|
}
|
|
|
|
close() {
|
|
this.dlgRef.close();
|
|
}
|
|
update() {
|
|
if (this.processing == false) {
|
|
|
|
this.processing = true;
|
|
|
|
this.happinessTaskService.createOrUpdateAll(this.data.tasks).pipe(first()).subscribe(result => {
|
|
this.processing = false;
|
|
this.dlgRef.close(true);
|
|
});
|
|
}
|
|
}
|
|
|
|
getTaskTitle(t: HappinessTaskType) {
|
|
switch (t) {
|
|
case HappinessTaskType.IceBreak: return '帶遊戲';
|
|
case HappinessTaskType.Worship: return '唱歌';
|
|
case HappinessTaskType.Testimony: return '見證';
|
|
case HappinessTaskType.Message: return '信息';
|
|
case HappinessTaskType.Gift: return '準備禮物';
|
|
case HappinessTaskType.Dessert: return '準備點心';
|
|
default: break;
|
|
}
|
|
}
|
|
} |