3b297cc7d83d73449e0c71c47e5b9d6b3bf35f25
[working/Evergreen.git] /
1 import {Component, OnInit, ViewChild} from '@angular/core';
2 import {Observable} from 'rxjs';
3 import {DialogComponent} from '@eg/share/dialog/dialog.component';
4 import {OrgService} from '@eg/core/org.service';
5 import {Pager} from '@eg/share/util/pager';
6 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
7 import {GridDataSource} from '@eg/share/grid/grid';
8 import {GridComponent} from '@eg/share/grid/grid.component';
9
10 @Component({
11     selector: 'eg-admin-ou-setting-history-dialog',
12     templateUrl: './org-unit-setting-history-dialog.component.html'
13 })
14
15 export class OuSettingHistoryDialogComponent extends DialogComponent implements OnInit {
16
17     entry: any = {};
18     history: any[] = [];
19     gridDataSource: GridDataSource;
20     @ViewChild('historyGrid', { static: true }) historyGrid: GridComponent;
21
22
23     constructor(
24         private org: OrgService,
25         private modal: NgbModal
26     ) {
27         super(modal);
28         this.gridDataSource = new GridDataSource();
29     }
30
31     ngOnInit() {
32         this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
33             return this.fetchHistory(pager);
34         };
35     }
36
37     fetchHistory(pager: Pager): Observable<any> {
38         return new Observable<any>(observer => {
39             this.gridDataSource.data = this.history;
40             observer.complete();
41         });
42     }
43
44     revert(log) {
45         if (log) {
46             const intTypes = ['integer', 'currency', 'link'];
47             if (intTypes.includes(this.entry.dataType)) {
48                 log.original_value = Number(log.original_value);
49             } else {
50                 log.original_value = log.original_value.replace(/^"(.*)"$/, '$1');
51             }
52
53             if (this.entry.dataType === 'bool') {
54                 if (log.original_value.match(/^t/)) {
55                     log.original_value = true;
56                 } else {
57                     log.original_value = false;
58                 }
59             }
60
61             this.close({
62                 setting: {[this.entry.name]: log.original_value},
63                 context: this.org.get(log.org),
64                 revert: true
65             });
66             this.gridDataSource.data = null;
67         }
68     }
69 }