Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Component, Input, OnInit} from '@angular/core';
- import {isNullOrUndefined} from "util";
- import {Attribute} from '@numen/common-bpo';
- import {ChangeLogService, Row} from "@numen/cmis-changelog-ihm";
- import {Observable} from "rxjs/Observable";
- import {zip} from "rxjs/observable/zip";
- import * as moment from "moment";
- interface key {
- v_key: string,
- v_name_key: string,
- v_type_property: string
- }
- @Component({
- selector: 'app-change-log',
- templateUrl: './change-log.component.html',
- })
- export class ChangeLogComponent implements OnInit {
- @Input() public currentObjectId: string;
- headers = []//['Date de modification', 'Utilisateur', 'Modifications'];
- constructor(private changeLogService: ChangeLogService) {
- }
- ngOnInit() {
- }
- public showTable() {
- return !isNullOrUndefined(this.currentObjectId);
- }
- public onError(error) {
- console.error(error);
- }
- public beforePageViewedAction = (rows:Row[]): Observable<Row[]> => {
- let extractChangeLog = (p_change_log: Attribute[]) => {
- let v_keys_changed: string[] = [];
- let v_keys = p_change_log.map(a => a.key);
- let p_change_log_get = (key: string) => {
- let attr = p_change_log.find((attr) => attr.key === key);
- return isNullOrUndefined(attr) ? null : attr.value;
- };
- v_keys.forEach((v_key) => {
- if (v_key.endsWith('.from') && isNullOrUndefined(v_keys_changed.find(key => key === v_key.replace('.from', '')))) {
- v_keys_changed.push(v_key.replace('.from', ''))
- } else if (v_key.endsWith('.to') && isNullOrUndefined(v_keys_changed.find(key => key === v_key.replace('.to', '')))) {
- v_keys_changed.push(v_key.replace('.to', ''))
- }
- });
- if (v_keys_changed.length > 0) {
- let obs = v_keys_changed
- .filter(v_key => p_change_log_get(v_key.concat('.from')) !== p_change_log_get(v_key.concat('.to')))
- .map(v_key => {
- return zip(
- this.changeLogService.getPropName(v_key),
- this.changeLogService.getPropType(v_key)
- ).map(arr => {
- return {v_key: v_key, v_name_key: arr[0].name, v_type_property: arr[1].type};
- });
- });
- if (isNullOrUndefined(obs)) return;
- return obs.map(ob$ => {
- return ob$.map((key: key) => {
- let keyName = isNullOrUndefined(key.v_name_key) ? key.v_key : key.v_name_key;
- let from = p_change_log_get(key.v_key.concat('.from'));
- let to = p_change_log_get(key.v_key.concat('.to'));
- if (key.v_type_property === 'datetime') {
- return [
- keyName,
- from === null || from === 'NULL' ? 'vide' : moment(from).format('DD/MM/YYYY'),
- to === null || to === 'NULL' ? 'vide' : moment(to).format('DD/MM/YYYY')
- ]
- } else {
- return [
- keyName,
- from === null || from === 'NULL' ? 'vide' : from,
- to === null || to === 'NULL' ? 'vide' : to
- ];
- }
- });
- });
- }
- };
- if (!isNullOrUndefined(rows)) {
- (<any[]> rows).forEach(async (row: Row) => {
- if (isNullOrUndefined(row.subTable)) row.subTable = {header: '', subRows: []};
- if (row.change_type === 'created' && row.changed_object_base_type_id === 'cmis:document') {
- {
- // TODO:
- // select to_char(d.creation_date,'DD/MM/YYYY'), lot.name, lot.properties->'fact:codeLot'
- // into v_date_scan, v_name_lot, v_name_oxi
- // from numenvault.object_document d, numenvault.object_folder lot, numenvault.object_folder_link l
- // 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;
- }
- row.subTable.header = "Réception de la carte grise";
- } else if (row.change_type === 'created' && row.changed_object_base_type_id === 'cmis:item' && row.object_type_id === 'wi:cgManualBusinessDiscard')
- row.subTable.header = "Mise à disposition de la carte grise";
- else if (row.change_type === 'updated' && row.changed_object_base_type_id === 'cmis:document') {
- row.subTable.header = "Mise à jour des propriétés de la carte grise";
- let extract$ = extractChangeLog(row.data);
- if (!isNullOrUndefined(extract$)) {
- extract$.forEach((ob$) => {
- ob$.subscribe(([v_key, v_value_init, v_value_final]) => {
- row.subTable.subRows.push({
- key: v_key,
- value: {from: v_value_init, to: v_value_final}
- });
- })
- }, (err) => {
- console.error(err);
- });
- }
- } else if (row.change_type === 'updated' && row.changed_object_base_type_id === 'cmis:item' && row.object_type_id === 'wi:cgManualBusinessDiscard') {
- let statut_init = '';
- let statut_final = '';
- let statut_wf_engine = '';
- let switch_code = '';
- row.data.forEach(attr => {
- switch (attr.key) {
- case 'nvlt:status.from' : {
- statut_init = attr.value;
- break;
- }
- case 'nvlt:status.to' : {
- statut_final = attr.value;
- break;
- }
- case 'nvlt:wfEngineData.from' : {
- statut_wf_engine = attr.value;
- break;
- }
- case 'nvlt:switchCode.from' : {
- switch_code = attr.value;
- break;
- }
- default:
- break;
- }
- });
- if (statut_init === 'AVAILABLE' && statut_final === 'IN_PROGRESS')
- row.subTable.header = 'Traitement en cours';
- else if (statut_wf_engine === 'COMPLETED') {
- if (switch_code === 'VALIDATE')
- row.subTable.header = 'Document validé';
- else if (switch_code === 'CANCEL')
- row.subTable.header = 'Document rejeté';
- else if (switch_code === 'MAIL')
- row.subTable.header = 'Document retourné au fournisseur';
- }
- else if (statut_init === 'IN_PROGRESS' && statut_final === 'AVAILABLE')
- row.subTable.header = 'Carte grise à traiter';
- else
- row.subTable.header = 'Modification non identifiée';
- } else
- row.subTable.header = 'Modification non identifiée';
- if (row.changed_by === 'root')
- row.changed_by_name = 'numen';
- if (row.changed_by_name == '')
- row.changed_by_name = row.changed_by;
- })
- }
- return Observable.of(rows);
- };
- }
Add Comment
Please, Sign In to add comment