LPXXX Angular Permission group tree admin UI
authorBill Erickson <berickxx@gmail.com>
Mon, 8 Apr 2019 17:30:12 +0000 (13:30 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 8 Apr 2019 17:30:12 +0000 (13:30 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/core/org.service.ts
Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
Open-ILS/src/eg2/src/app/staff/admin/server/perm-group-tree.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/perm-group-tree.component.ts

index c666957..ba2b4e3 100644 (file)
@@ -44,6 +44,17 @@ export class OrgService {
         return this.orgList;
     }
 
+    // Returns a list of org unit type objects
+    typeList(): IdlObject[] {
+        const types = [];
+        this.list().forEach(org => {
+            if ((types.filter(t => t.id() === org.ou_type().id())).length === 0) {
+                types.push(org.ou_type());
+            }
+        });
+        return types;
+    }
+
     /**
      * Returns a list of org units that match the selected criteria.
      * All filters must match for an org to be included in the result set.
index 8b018d5..7731dc2 100644 (file)
@@ -58,7 +58,7 @@ export class ComboboxComponent implements OnInit {
     // Entry ID of the default entry to select (optional)
     // onChange() is NOT fired when applying the default value,
     // unless startIdFiresOnChange is set to true.
-    @Input() startId: any;
+    @Input() startId: any = null;
     @Input() startIdFiresOnChange: boolean;
 
     @Input() asyncDataSource: (term: string) => Observable<ComboboxEntry>;
@@ -120,7 +120,7 @@ export class ComboboxComponent implements OnInit {
     // Apply a default selection where needed
     applySelection() {
 
-        if (this.startId &&
+        if (this.startId !== null &&
             this.entrylist && !this.defaultSelectionApplied) {
 
             const entry =
index 31a3477..fad1256 100644 (file)
 </eg-fm-record-editor>
 
 <div class="row">
-  <div class="col-lg-4">
+  <div class="col-lg-3">
     <h3 i18n>Permission Groups</h3>
     <eg-tree [tree]="tree" (nodeClicked)="nodeClicked($event)"></eg-tree>
   </div>
-  <div class="col-lg-8">
+  <div class="col-lg-9">
     <h3 i18n class="mb-3">Selected Permission Group</h3>
     <ng-container *ngIf="!selected">
       <div class="alert alert-info font-italic" i18n>
             
             <div class="row font-weight-bold">
               <div class="col-lg-5" i18n>Permissions</div>
-              <div class="col-lg-2" i18n>Depth</div>
-              <div class="col-lg-3" i18n>Group</div>
-              <div class="col-lg-2" i18n>Grantable?</div>
+              <div class="col-lg-4" i18n>Group</div>
+              <div class="col-lg-1" i18n>Depth</div>
+              <div class="col-lg-1" i18n>Grantable?</div>
+              <div class="col-lg-1" i18n>Select</div>
             </div>
 
             <div class="row" *ngFor="let map of groupPermMaps()">
               <div class="col-lg-5">{{map.perm().code()}}</div>
-              <div class="col-lg-2">{{map.depth()}}</div>
-              <div class="col-lg-3">{{map.grp().name()}}</div>
-              <div class="col-lg-2">
-                <ng-container *ngIf="permIsInherited(map); else nativeMap">
-                 <!-- TODO migrate to <eg-bool/> once merged-->
-                  {{map.grantable() == 't'}}
-                </ng-container>
-                <ng-template #nativeMap>
+              <div class="col-lg-4">{{map.grp().name()}}</div>
+              <ng-container *ngIf="permIsInherited(map); else nativeMap">
+                <div class="col-lg-1 text-center">{{map.depth()}}</div>
+                <!-- TODO migrate to <eg-bool/> once merged-->
+                <div class="col-lg-1">{{map.grantable() == 't'}}</div>
+              </ng-container>
+              <ng-template #nativeMap>
+                <div class="col-lg-1">
+                  <eg-combobox [entries]="orgDepths" [startId]="map.depth()"
+                    (onChange)="map.depth($event ? $event.id : null); map.ischanged(true)">
+                  </eg-combobox>
+                </div>
+                <div class="col-lg-1">
                   <input type="checkbox"
                     [ngModel]="map.grantable() == 't'"
                     (ngModelChange)="map.grantable($event ? 't' : 'f')"/>
-                </ng-template>
-              </div>
+                </div>
+                <div class="col-lg-1">
+                  <button class="btn btn-warning" (click)="deleteMap(map)" i18n>
+                    Delete
+                  </button>
+                </div>
+              </ng-template>
             </div>
           </ng-template>
         </ngb-tab>
index 0c11ff9..4151d8a 100644 (file)
@@ -24,6 +24,7 @@ export class PermGroupTreeComponent implements OnInit {
     permIdMap: {[id: number]: IdlObject};
     permEntries: ComboboxEntry[];
     permMaps: IdlObject[];
+    orgDepths: ComboboxEntry[];
 
     @ViewChild('editDialog') editDialog: FmRecordEditorComponent;
     @ViewChild('editString') editString: StringComponent;
@@ -47,6 +48,19 @@ export class PermGroupTreeComponent implements OnInit {
 
     ngOnInit() {
         this.loadPgtTree();
+        this.setOrgDepths();
+    }
+
+    setOrgDepths() {
+        const depths = this.org.typeList().map(t => Number(t.depth()));
+        const depths2 = [];
+        depths.forEach(d => {
+            if (!depths2.includes(d)) {
+                depths2.push(d);
+            }
+        });
+
+        this.orgDepths = depths2.sort().map(d => ({id: d, label: d}));
     }
 
     groupPermMaps(): IdlObject[] {
@@ -58,8 +72,6 @@ export class PermGroupTreeComponent implements OnInit {
             m1.perm().code() < m2.perm().code() ? -1 : 1);
     }
 
-
-
     loadPgtTree() {
 
         this.pcrud.search('pgt', {parent: null},
@@ -124,14 +136,9 @@ export class PermGroupTreeComponent implements OnInit {
     // Returns true if the perm map belongs to an ancestore of the
     // currently selected group.
     permIsInherited(map: IdlObject): boolean {
-        let treeNode = this.tree.findNode(this.selected.callerData.parent());
-        while (treeNode) {
-            if (+map.grp().id() === +treeNode.id) {
-                return true;
-            }
-            treeNode = this.tree.findNode(treeNode.callerData.parent());
-        }
-        return false;
+        // We know the provided map came from this.groupPermMaps() which
+        // only returns maps for the selected group plus parent groups.
+        return map.grp().id() !== this.selected.callerData.id();
     }
 
     // List of perm maps that owned by perm groups which are ancestors
@@ -226,5 +233,9 @@ export class PermGroupTreeComponent implements OnInit {
             }
         );
     }
+
+    deleteMap(map: IdlObject) {
+
+    }
 }