1 import {Component, Input, ViewChild, OnInit} from '@angular/core';
2 import {Location} from '@angular/common';
3 import {FormatService} from '@eg/core/format.service';
4 import {AdminPageComponent} from '@eg/staff/share/admin-page/admin-page.component';
5 import {ActivatedRoute} from '@angular/router';
6 import {IdlService, IdlObject} from '@eg/core/idl.service';
7 import {ToastService} from '@eg/share/toast/toast.service';
8 import {PcrudService} from '@eg/core/pcrud.service';
9 import {OrgService} from '@eg/core/org.service';
10 import {PermService} from '@eg/core/perm.service';
11 import {AuthService} from '@eg/core/auth.service';
12 import {NetService} from '@eg/core/net.service';
13 import {GridCellTextGenerator} from '@eg/share/grid/grid';
14 import {StringComponent} from '@eg/share/string/string.component';
15 import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
16 import {ClonePortalEntriesDialogComponent} from './clone-portal-entries-dialog.component';
17 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
18 import {merge, Observable, empty} from 'rxjs';
21 templateUrl: './staff-portal-page.component.html'
24 export class AdminStaffPortalPageComponent extends AdminPageComponent implements OnInit {
27 fieldOrder = 'label,entry_type,target_url,entry_text,image_url,page_col,col_pos,owner,id';
30 refreshSelected: (idlThings: IdlObject[]) => void;
31 createNew: () => void;
32 cellTextGenerator: GridCellTextGenerator;
34 @ViewChild('refreshString', { static: true }) refreshString: StringComponent;
35 @ViewChild('refreshErrString', { static: true }) refreshErrString: StringComponent;
36 @ViewChild('cloneSuccessString', { static: true }) cloneSuccessString: StringComponent;
37 @ViewChild('cloneFailedString', { static: true }) cloneFailedString: StringComponent;
38 @ViewChild('cloneDialog', { static: true}) cloneDialog: ClonePortalEntriesDialogComponent;
39 @ViewChild('delConfirm', { static: true }) delConfirm: ConfirmDialogComponent;
42 route: ActivatedRoute,
44 format: FormatService,
51 private net: NetService
53 super(route, ngLocation, format, idl, org, auth, pcrud, perm, toast);
59 this.defaultNewRecord = this.idl.create(this.idlClass);
60 this.defaultNewRecord.owner(this.auth.user().ws_ou());
64 this.cloneDialog.open().subscribe(
66 this._handleClone(result.source_library, result.target_library, result.overwrite_target);
71 deleteSelected(idlThings: IdlObject[]) {
72 this.delConfirm.open().subscribe(confirmed => {
73 if (!confirmed) { return; }
74 super.deleteSelected(idlThings);
78 _handleClone(src: number, tgt: number, overwrite: Boolean) {
79 const updates: IdlObject[] = [];
81 const delObs = (overwrite) ?
82 this.pcrud.search('cusppe', { owner: tgt }, {}, {}) :
84 const newObs = this.pcrud.search('cusppe', { owner: src }, {}, {});
85 merge(delObs, newObs).subscribe(
87 if (entry.owner() === tgt) {
88 entry.isdeleted(true);
98 this.pcrud.autoApply(updates).subscribe(
101 this.cloneFailedString.current()
102 .then(str => this.toast.danger(str));
105 this.cloneSuccessString.current()
106 .then(str => this.toast.success(str));
107 this.searchOrgs = {primaryOrgId: tgt}; // change the org filter to the
108 // the one we just cloned into