Guest User

Untitled

a guest
Apr 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.07 KB | None | 0 0
  1. import {Component, Input, OnInit} from '@angular/core';
  2. import {isNullOrUndefined} from "util";
  3. import {Attribute} from '@numen/common-bpo';
  4. import {ChangeLogService, Row} from "@numen/cmis-changelog-ihm";
  5. import {Observable} from "rxjs/Observable";
  6. import {zip} from "rxjs/observable/zip";
  7. import * as moment from "moment";
  8.  
  9. interface key {
  10. v_key: string,
  11. v_name_key: string,
  12. v_type_property: string
  13. }
  14.  
  15. @Component({
  16. selector: 'app-change-log',
  17. templateUrl: './change-log.component.html',
  18. })
  19. export class ChangeLogComponent implements OnInit {
  20. @Input() public currentObjectId: string;
  21. headers = []//['Date de modification', 'Utilisateur', 'Modifications'];
  22.  
  23. constructor(private changeLogService: ChangeLogService) {
  24. }
  25.  
  26. ngOnInit() {
  27. }
  28.  
  29. public showTable() {
  30. return !isNullOrUndefined(this.currentObjectId);
  31. }
  32.  
  33. public onError(error) {
  34. console.error(error);
  35. }
  36.  
  37. public beforePageViewedAction = (rows:Row[]): Observable<Row[]> => {
  38.  
  39. let extractChangeLog = (p_change_log: Attribute[]) => {
  40.  
  41. let v_keys_changed: string[] = [];
  42. let v_keys = p_change_log.map(a => a.key);
  43. let p_change_log_get = (key: string) => {
  44. let attr = p_change_log.find((attr) => attr.key === key);
  45. return isNullOrUndefined(attr) ? null : attr.value;
  46. };
  47.  
  48. v_keys.forEach((v_key) => {
  49. if (v_key.endsWith('.from') && isNullOrUndefined(v_keys_changed.find(key => key === v_key.replace('.from', '')))) {
  50. v_keys_changed.push(v_key.replace('.from', ''))
  51. } else if (v_key.endsWith('.to') && isNullOrUndefined(v_keys_changed.find(key => key === v_key.replace('.to', '')))) {
  52. v_keys_changed.push(v_key.replace('.to', ''))
  53. }
  54. });
  55.  
  56. if (v_keys_changed.length > 0) {
  57. let obs = v_keys_changed
  58. .filter(v_key => p_change_log_get(v_key.concat('.from')) !== p_change_log_get(v_key.concat('.to')))
  59. .map(v_key => {
  60. return zip(
  61. this.changeLogService.getPropName(v_key),
  62. this.changeLogService.getPropType(v_key)
  63. ).map(arr => {
  64. return {v_key: v_key, v_name_key: arr[0].name, v_type_property: arr[1].type};
  65. });
  66. });
  67.  
  68. if (isNullOrUndefined(obs)) return;
  69.  
  70.  
  71. return obs.map(ob$ => {
  72. return ob$.map((key: key) => {
  73. let keyName = isNullOrUndefined(key.v_name_key) ? key.v_key : key.v_name_key;
  74. let from = p_change_log_get(key.v_key.concat('.from'));
  75. let to = p_change_log_get(key.v_key.concat('.to'));
  76. if (key.v_type_property === 'datetime') {
  77. return [
  78. keyName,
  79. from === null || from === 'NULL' ? 'vide' : moment(from).format('DD/MM/YYYY'),
  80. to === null || to === 'NULL' ? 'vide' : moment(to).format('DD/MM/YYYY')
  81. ]
  82. } else {
  83. return [
  84. keyName,
  85. from === null || from === 'NULL' ? 'vide' : from,
  86. to === null || to === 'NULL' ? 'vide' : to
  87. ];
  88. }
  89. });
  90. });
  91. }
  92. };
  93.  
  94. if (!isNullOrUndefined(rows)) {
  95. (<any[]> rows).forEach(async (row: Row) => {
  96. if (isNullOrUndefined(row.subTable)) row.subTable = {header: '', subRows: []};
  97.  
  98. if (row.change_type === 'created' && row.changed_object_base_type_id === 'cmis:document') {
  99. {
  100. // TODO:
  101. // select to_char(d.creation_date,'DD/MM/YYYY'), lot.name, lot.properties->'fact:codeLot'
  102. // into v_date_scan, v_name_lot, v_name_oxi
  103. // from numenvault.object_document d, numenvault.object_folder lot, numenvault.object_folder_link l
  104. // where d.id=l.id_child_object and l.id_parent_folder=lot.id and d.object_type_id='fact:facture' and d.id=p_id_object;
  105. }
  106. row.subTable.header = "Réception de la carte grise";
  107. } else if (row.change_type === 'created' && row.changed_object_base_type_id === 'cmis:item' && row.object_type_id === 'wi:cgManualBusinessDiscard')
  108. row.subTable.header = "Mise à disposition de la carte grise";
  109. else if (row.change_type === 'updated' && row.changed_object_base_type_id === 'cmis:document') {
  110. row.subTable.header = "Mise à jour des propriétés de la carte grise";
  111.  
  112. let extract$ = extractChangeLog(row.data);
  113. if (!isNullOrUndefined(extract$)) {
  114. extract$.forEach((ob$) => {
  115. ob$.subscribe(([v_key, v_value_init, v_value_final]) => {
  116. row.subTable.subRows.push({
  117. key: v_key,
  118. value: {from: v_value_init, to: v_value_final}
  119. });
  120. })
  121. }, (err) => {
  122. console.error(err);
  123. });
  124. }
  125. } else if (row.change_type === 'updated' && row.changed_object_base_type_id === 'cmis:item' && row.object_type_id === 'wi:cgManualBusinessDiscard') {
  126. let statut_init = '';
  127. let statut_final = '';
  128. let statut_wf_engine = '';
  129. let switch_code = '';
  130.  
  131. row.data.forEach(attr => {
  132. switch (attr.key) {
  133. case 'nvlt:status.from' : {
  134. statut_init = attr.value;
  135. break;
  136. }
  137. case 'nvlt:status.to' : {
  138. statut_final = attr.value;
  139. break;
  140. }
  141. case 'nvlt:wfEngineData.from' : {
  142. statut_wf_engine = attr.value;
  143. break;
  144. }
  145. case 'nvlt:switchCode.from' : {
  146. switch_code = attr.value;
  147. break;
  148. }
  149. default:
  150. break;
  151. }
  152. });
  153.  
  154. if (statut_init === 'AVAILABLE' && statut_final === 'IN_PROGRESS')
  155. row.subTable.header = 'Traitement en cours';
  156. else if (statut_wf_engine === 'COMPLETED') {
  157. if (switch_code === 'VALIDATE')
  158. row.subTable.header = 'Document validé';
  159. else if (switch_code === 'CANCEL')
  160. row.subTable.header = 'Document rejeté';
  161. else if (switch_code === 'MAIL')
  162. row.subTable.header = 'Document retourné au fournisseur';
  163. }
  164. else if (statut_init === 'IN_PROGRESS' && statut_final === 'AVAILABLE')
  165. row.subTable.header = 'Carte grise à traiter';
  166. else
  167. row.subTable.header = 'Modification non identifiée';
  168.  
  169. } else
  170. row.subTable.header = 'Modification non identifiée';
  171.  
  172.  
  173. if (row.changed_by === 'root')
  174. row.changed_by_name = 'numen';
  175.  
  176. if (row.changed_by_name == '')
  177. row.changed_by_name = row.changed_by;
  178. })
  179. }
  180. return Observable.of(rows);
  181. };
  182.  
  183. }
Add Comment
Please, Sign In to add comment