initial commit
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
||||
import { first } from 'rxjs/operators';
|
||||
import { CellGroupRoutineEventAttendee, CellGroupRoutineEvents } from '../../entity/CellGroupRoutineEvents';
|
||||
import { MsgBoxService } from '../../services/msg-box.service';
|
||||
import { NbToastrService } from '@nebular/theme';
|
||||
import { SessionService } from '../../services/session.service';
|
||||
import { LineService } from '../../services/line.service';
|
||||
import { HeaderService } from '../../services/header.service';
|
||||
import { StringUtils } from '../../utilities/string-utils';
|
||||
import { AuthService } from '../../services/auth.service';
|
||||
import { DateUtils } from '../../utilities/date-utils';
|
||||
import { NumberUtils } from '../../utilities/number-utils';
|
||||
import { CellGroupRoutineEventsService } from '../../services/crudServices/cell-group-routine-events.service';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-dinner',
|
||||
templateUrl: './dinner.component.html',
|
||||
styleUrls: ['./dinner.component.scss']
|
||||
})
|
||||
export class DinnerComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private cellGroupRoutineEventsService: CellGroupRoutineEventsService,
|
||||
private messageService: MsgBoxService,
|
||||
private toastrService: NbToastrService,
|
||||
private sessionService: SessionService,
|
||||
private lineService: LineService,
|
||||
private cdRef: ChangeDetectorRef,
|
||||
private headerService: HeaderService,
|
||||
private authService: AuthService
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
cellGroupEvent: CellGroupRoutineEvents;
|
||||
data: CellGroupRoutineEventAttendee;
|
||||
|
||||
potluckItems: DinnerInfo[] = [{ item: '' }];
|
||||
|
||||
isLoading: boolean = true;
|
||||
processing: boolean = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.headerService.setHeader("晚宴系統")
|
||||
this.getAllData();
|
||||
}
|
||||
getAllData() {
|
||||
|
||||
this.isLoading = true;
|
||||
this.cellGroupRoutineEventsService.getComingEvent().pipe(first()).subscribe(result => {
|
||||
this.cellGroupEvent = result;
|
||||
|
||||
this.data = this.cellGroupEvent.attendees.find(a => a.id == this.authService.userAccess.memberId);
|
||||
if (!this.data) {
|
||||
this.data = new CellGroupRoutineEventAttendee(this.cellGroupEvent.id, this.authService.userAccess.memberId);
|
||||
this.data.name = this.authService.userAccess.firstName;
|
||||
this.cellGroupEvent.attendees.push(this.data);
|
||||
} else {
|
||||
this.potluckItems = this.data.potluckItem.split("|").map(s => new DinnerInfo(s));
|
||||
}
|
||||
this.cdRef.detectChanges();
|
||||
this.isLoading = false;
|
||||
|
||||
});
|
||||
}
|
||||
update(): void {
|
||||
this.processing = true;
|
||||
this.data.potluckItem = this.potluckItems.filter(item => !!item.item).map(t => t.item).join('|');
|
||||
this.cellGroupRoutineEventsService.createOrUpdateAttendee(this.data).pipe(first()).subscribe(result => {
|
||||
|
||||
this.processing = false;
|
||||
this.toastrService.success('菜單更新完成!');
|
||||
this.lineService.pushCommandMessage('Cac4ac5a8d7fc52daa444d71dc7c360a9', 'dinner');
|
||||
});
|
||||
}
|
||||
|
||||
addAttendee() {
|
||||
if (this.potluckItems.length > 1) {
|
||||
this.potluckItems = this.potluckItems.filter(d => !!d.item);
|
||||
}
|
||||
this.potluckItems.push(new DinnerInfo(''));
|
||||
this.cdRef.detectChanges();
|
||||
}
|
||||
addItem() {
|
||||
if (this.potluckItems.length > 1) {
|
||||
this.potluckItems = this.potluckItems.filter(d => !!d.item);
|
||||
}
|
||||
this.potluckItems.push(new DinnerInfo(''));
|
||||
this.cdRef.detectChanges();
|
||||
}
|
||||
logout() {
|
||||
this.authService.logout();
|
||||
}
|
||||
}
|
||||
|
||||
export class DinnerInfo {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
constructor(item: string) {
|
||||
this.item = item;
|
||||
}
|
||||
item: string;
|
||||
}
|
||||
Reference in New Issue
Block a user