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