Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

150 lignes
5.6 KiB

  1. import {AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core';
  2. import {NewTaskComponent} from "@app/tasks/new-task/new-task.component";
  3. import {NgbModal, NgbModalOptions} from "@ng-bootstrap/ng-bootstrap";
  4. import {ModalComponent} from "@app/_components/modal/modal.component";
  5. import {ApiConverter} from "@app/_helpers/api.converter";
  6. import {Subscription} from "rxjs";
  7. import {TaskJsonld, TaskNoteJsonld, TaskService} from "@app/core/api/v1";
  8. import {MatPaginator, MatPaginatorIntl, PageEvent} from "@angular/material/paginator";
  9. import {MatTableDataSource} from "@angular/material/table";
  10. import {User} from "@app/_models";
  11. import {AccountService} from "@app/_services";
  12. import {ModalStatus} from "@app/_helpers/modal.states";
  13. import {NewTaskNoteComponent} from "@app/tasks/new-task-note/new-task-note.component";
  14. @Component({
  15. selector: 'app-tasks',
  16. templateUrl: './tasks.component.html',
  17. styleUrl: './tasks.component.scss'
  18. })
  19. export class TasksComponent implements OnInit, AfterViewInit {
  20. @ViewChild(MatPaginator) tasksPaginator: MatPaginator;
  21. protected user: User | null;
  22. protected readonly ApiConverter = ApiConverter;
  23. protected tasksSub: Subscription;
  24. protected tasks: Array<TaskJsonld>;
  25. protected tasksDataSource;
  26. protected tasksLength: number;
  27. protected tasksPageEvent: PageEvent;
  28. protected tasksPageSize: number;
  29. protected tasksPageIndex: number;
  30. protected taskNotesVisibility: Map<string, boolean>;
  31. protected modalOptions: NgbModalOptions = {
  32. centered: true
  33. };
  34. constructor(
  35. private modalService: NgbModal,
  36. private accountService: AccountService,
  37. private taskService: TaskService
  38. ) {
  39. this.user = this.accountService.userValue;
  40. this.tasksSub = new Subscription();
  41. this.tasks = [];
  42. this.tasksPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype);
  43. this.tasksDataSource = new MatTableDataSource<TaskJsonld>(this.tasks);
  44. this.tasksLength = 0;
  45. this.tasksPageEvent = new PageEvent();
  46. this.tasksPageSize = 10;
  47. this.tasksPageIndex = 0;
  48. this.taskNotesVisibility = new Map<string, boolean>();
  49. }
  50. ngOnInit() {
  51. this.getTasksData();
  52. }
  53. ngAfterViewInit() {
  54. this.tasksDataSource.paginator = this.tasksPaginator;
  55. }
  56. getTasksData() {
  57. this.tasksSub = this.taskService.tasksGetCollection(
  58. this.tasksPageIndex + 1,
  59. this.tasksPageSize,
  60. // TODO: User-ID muss übergeben werden können, damit man nur die Tasks bekommt, die einem User zugewiesen sind
  61. ).subscribe(
  62. data => {
  63. this.tasks = data["hydra:member"];
  64. this.tasksLength = Number(data["hydra:totalItems"]);
  65. this.tasks.forEach(task => {
  66. if (task.id) {
  67. this.taskNotesVisibility.set(task.id, false);
  68. }
  69. });
  70. console.log(this.tasks);
  71. }
  72. );
  73. }
  74. tasksHandlePageEvent(e: PageEvent) {
  75. this.tasksPageEvent = e;
  76. this.tasksLength = e.length;
  77. this.tasksPageIndex = e.pageIndex.valueOf();
  78. this.tasksPageSize = e.pageSize.valueOf();
  79. this.getTasksData();
  80. }
  81. openModalNewTask() {
  82. const modalRefTask = this.modalService.open(NewTaskComponent, this.modalOptions);
  83. let task: TaskJsonld = {} as TaskJsonld;
  84. task.partner = null;
  85. task.completed = false;
  86. modalRefTask.componentInstance.task = task;
  87. modalRefTask.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  88. if (modalStatus === ModalStatus.Submitted) {
  89. modalRefTask.dismiss();
  90. this.getTasksData();
  91. }
  92. });
  93. }
  94. openModalNewTaskNote(task: TaskJsonld) {
  95. const modalRefTaskNote = this.modalService.open(NewTaskNoteComponent, this.modalOptions);
  96. let taskNote: TaskNoteJsonld = {} as TaskNoteJsonld;
  97. taskNote.task = task.id ?? null;
  98. modalRefTaskNote.componentInstance.taskNote = taskNote;
  99. modalRefTaskNote.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  100. if (modalStatus === ModalStatus.Submitted) {
  101. modalRefTaskNote.dismiss();
  102. this.getTasksData();
  103. }
  104. });
  105. }
  106. openModalEditTask(task: TaskJsonld) {
  107. const modalRefTaskEdit = this.modalService.open(NewTaskComponent, this.modalOptions);
  108. modalRefTaskEdit.componentInstance.task = task;
  109. modalRefTaskEdit.componentInstance.dueAtValue = ApiConverter.convertDate(task.dueAt);
  110. modalRefTaskEdit.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  111. if (modalStatus === ModalStatus.Submitted) {
  112. modalRefTaskEdit.dismiss();
  113. this.getTasksData();
  114. }
  115. });
  116. }
  117. openModalEditTaskNote(taskNote: TaskNoteJsonld) {
  118. const modalRefTaskNote = this.modalService.open(NewTaskNoteComponent, this.modalOptions);
  119. modalRefTaskNote.componentInstance.taskNote = taskNote;
  120. modalRefTaskNote.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  121. if (modalStatus === ModalStatus.Submitted) {
  122. modalRefTaskNote.dismiss();
  123. this.getTasksData();
  124. }
  125. });
  126. }
  127. showTaskNotes(task: TaskJsonld) {
  128. if (task.id) {
  129. const currentVisibility = this.taskNotesVisibility.get(task.id);
  130. this.taskNotesVisibility.set(task.id, !currentVisibility);
  131. }
  132. }
  133. }