Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

280 строки
9.1 KiB

  1. import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
  2. import {AgGridComponent} from '../../components/ag-grid-component';
  3. import {AppService} from '../../services/app.service';
  4. import {MeetingService} from '../../services/meeting.service';
  5. import {TabsComponent} from '../../components/tabs/tabs.component';
  6. import {ModalComponent} from '../../components/modal/modal.component';
  7. import {Subscription} from 'rxjs';
  8. import {OperatorViewComponent} from './operator-view/operator-view.component';
  9. import {OperatorsListComponent} from './operators-list/operators-list.component';
  10. import {OperatorsContactListComponent} from './operators-contact-list/operators-contact-list.component';
  11. import {IOperator} from '../../model/entities/operator';
  12. import {IOperatorContact} from '../../model/entities/operator-contact';
  13. import {Factory} from '../../factory/factory';
  14. import {OperatorDataEditComponent} from './operator-view/operator-data-edit/operator-data-edit.component';
  15. import {OperatorService} from '../../services/operator.service';
  16. import {IOperatorNote} from '../../model/entities/operator-note';
  17. import {IOperatorMeeting} from '../../model/entities/operator-meeting';
  18. import {isNull} from 'util';
  19. @Component({
  20. selector: 'app-operators',
  21. templateUrl: './operators.component.html',
  22. styleUrls: ['./operators.component.scss']
  23. })
  24. export class OperatorsComponent extends AgGridComponent implements OnInit, OnDestroy {
  25. @ViewChild('tabsCM', { static: true }) tabsCM: TabsComponent;
  26. @ViewChild('modalOperator', { static: true }) modalOperator: ModalComponent;
  27. @ViewChild('operatorView', { static: true }) operatorView: OperatorViewComponent;
  28. @ViewChild('operatorsList', { static: true }) operatorsList: OperatorsListComponent;
  29. @ViewChild('operatorsContactList', { static: true }) operatorsContactList: OperatorsContactListComponent;
  30. @ViewChild('modalOperatorDataEdit', { static: true }) modalOperatorDataEdit: ModalComponent;
  31. @ViewChild('operatorDataEdit', { static: true }) operatorDataEdit: OperatorDataEditComponent;
  32. @ViewChild('headline', { static: true }) headline: ElementRef;
  33. @ViewChild('content', { static: true }) content: ElementRef;
  34. private operators: IOperator[];
  35. private operatorsSub: Subscription;
  36. private operatorsContactsSub: Subscription;
  37. public operatorContacts: IOperatorContact[];
  38. constructor(private appService: AppService, private operatorService: OperatorService, private meetingService: MeetingService) {
  39. super();
  40. this.operatorService.apiGetOperatorData();
  41. }
  42. ngOnInit() {
  43. this.operatorContacts = [];
  44. this.operatorsSub = this.operatorService.getOperators$().subscribe(
  45. data => {
  46. this.operators = data;
  47. this.setComponentData();
  48. }
  49. );
  50. this.operatorsContactsSub = this.operatorService.getOperatorContacts$().subscribe(
  51. data => {
  52. this.operatorContacts = data;
  53. this.setComponentData();
  54. }
  55. );
  56. }
  57. /**
  58. * Set component data after all data has been received
  59. */
  60. private setComponentData() {
  61. if (!isNull(this.operators) && !isNull(this.operatorContacts)) {
  62. this.operatorsList.setData(this.operators);
  63. this.operatorsContactList.setData(this.operators, this.operatorContacts);
  64. }
  65. }
  66. /**
  67. * Operator row is clicked
  68. * @param e
  69. */
  70. public rowClickedOperator(e: any) {
  71. this.operatorService.apiGetOperatorFull(e.data.operator_id).subscribe(
  72. data => {
  73. this.operatorView.setData(data.result_data as IOperator);
  74. this.modalOperator.openModal();
  75. },
  76. error => {}
  77. );
  78. }
  79. /**
  80. * OnClick Create operator
  81. */
  82. public createOperator(): void {
  83. this.modalOperatorDataEdit.openModal();
  84. this.operatorDataEdit.setData(Factory.getEmptyOperator());
  85. }
  86. /**
  87. * Creates operator
  88. * @param operator
  89. */
  90. public createOperatorFunction(operator: IOperator): void {
  91. this.operatorService.apiCreateOperator(operator).subscribe(
  92. data => {
  93. this.modalOperatorDataEdit.closeModal();
  94. },
  95. error => {}
  96. );
  97. }
  98. /**
  99. * Saves operator
  100. * @param operator
  101. */
  102. public editOperatorFunction(operator: IOperator): void {
  103. this.operatorService.apiEditOperator(operator).subscribe(
  104. data => {
  105. this.operatorView.setData(data.result_data as IOperator);
  106. },
  107. error => {}
  108. );
  109. }
  110. /**
  111. * Creates operator contact
  112. * @param operatorContact
  113. */
  114. public createOperatorContactFunction(operatorContact: IOperatorContact): void {
  115. this.operatorService.apiCreateOperatorContact(operatorContact).subscribe(
  116. data => {
  117. this.operatorView.setData(data.result_data as IOperator);
  118. },
  119. error => {}
  120. );
  121. }
  122. /**
  123. * Edit operator contact
  124. * @param operatorContact
  125. */
  126. public editOperatorContactFunction(operatorContact: IOperatorContact): void {
  127. this.operatorService.apiEditOperatorContact(operatorContact).subscribe(
  128. data => {
  129. this.operatorView.setData(data.result_data as IOperator, true);
  130. },
  131. error => {}
  132. );
  133. }
  134. /**
  135. * Deletes operator contact
  136. * @param operatorId
  137. */
  138. public deleteOperatorContactFunction(operatorId: number): void {
  139. this.operatorService.apiDeleteOperatorContact(operatorId).subscribe(
  140. data => {
  141. this.operatorView.setData(data.result_data as IOperator);
  142. },
  143. error => {}
  144. );
  145. }
  146. /**
  147. * Creates operator note entry
  148. * @param operatorNote
  149. */
  150. public createOperatorNoteFunction(operatorNote: IOperatorNote): void {
  151. this.operatorService.apiCreateOperatorNote(operatorNote).subscribe(
  152. data => {
  153. this.operatorView.setData(data.result_data as IOperator);
  154. },
  155. error => {}
  156. );
  157. }
  158. /**
  159. * Edits operator note entry
  160. * @param operatorNote
  161. */
  162. public editOperatorNoteFunction(operatorNote: IOperatorNote): void {
  163. this.operatorService.apiEditOperatorNote(operatorNote).subscribe(
  164. data => {
  165. this.operatorView.setData(data.result_data as IOperator, true);
  166. },
  167. error => {}
  168. );
  169. }
  170. /**
  171. * Deletes operator note entry
  172. * @param operatorNoteId
  173. */
  174. public deleteOperatorNoteFunction(operatorNoteId: number): void {
  175. this.operatorService.apiDeleteOperatorNote(operatorNoteId).subscribe(
  176. data => {
  177. this.operatorView.setData(data.result_data as IOperator);
  178. },
  179. error => {}
  180. );
  181. }
  182. /**
  183. * Creates operator meeting entry
  184. * @param operatorMeeting
  185. */
  186. public createOperatorMeetingFunction(operatorMeeting: IOperatorMeeting): void {
  187. this.meetingService.apiCreateOperatorMeeting(operatorMeeting).subscribe(
  188. data => {
  189. this.operatorView.setData(data.result_data as IOperator);
  190. },
  191. error => {}
  192. );
  193. }
  194. /**
  195. * Edits operator meeting entry
  196. * @param operatorMeeting
  197. */
  198. public editOperatorMeetingFunction(operatorMeeting: IOperatorMeeting): void {
  199. this.meetingService.apiEditOperatorMeeting(operatorMeeting).subscribe(
  200. data => {
  201. this.operatorView.setData(data.result_data as IOperator, true);
  202. },
  203. error => {}
  204. );
  205. }
  206. /**
  207. * Deletes operator meeting entry
  208. * @param operatorMeetingId
  209. */
  210. public deleteOperatorMeetingFunction(operatorMeetingId: number): void {
  211. this.meetingService.apiDeleteOperatorMeeting(operatorMeetingId).subscribe(
  212. data => {
  213. this.operatorView.setData(data.result_data as IOperator);
  214. },
  215. error => {}
  216. );
  217. }
  218. /**
  219. * Edit report after meeting has started
  220. * @param reportValues
  221. */
  222. public editOperatorMeetingReportFunction(reportValues: any): void {
  223. const meetingId: number = reportValues.id;
  224. const report: string = reportValues.report;
  225. this.meetingService.apiEditOperatorMeetingReport(meetingId, report).subscribe(
  226. data => {
  227. this.operatorView.setData(data.result_data as IOperator, true);
  228. },
  229. error => {}
  230. );
  231. }
  232. /**
  233. * Shortcut to operator detail
  234. * @param operator
  235. */
  236. public shortcutFunction(operator: IOperator): void {
  237. this.operatorService.apiGetOperatorFull(operator.id).subscribe(
  238. data => {
  239. this.operatorView.setData(data.result_data as IOperator);
  240. this.modalOperator.openModal();
  241. },
  242. error => {}
  243. );
  244. }
  245. /**
  246. * Destroy
  247. */
  248. ngOnDestroy(): void {
  249. if (this.operatorsSub !== null && this.operatorsSub !== undefined) {
  250. this.operatorsSub.unsubscribe();
  251. }
  252. }
  253. }