LP#626157 Ang2 experiments
authorBill Erickson <berickxx@gmail.com>
Thu, 14 Dec 2017 17:44:17 +0000 (12:44 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 14 Dec 2017 17:44:17 +0000 (12:44 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/eg2-src/src/app/core/auth.ts
Open-ILS/eg2-src/src/app/share/confirm-dialog.component.ts [new file with mode: 0644]
Open-ILS/eg2-src/src/app/staff/admin/workstation/workstations/app.component.html
Open-ILS/eg2-src/src/app/staff/admin/workstation/workstations/app.component.ts
Open-ILS/eg2-src/src/app/staff/admin/workstation/workstations/app.module.ts
Open-ILS/eg2-src/src/app/staff/app.module.ts
Open-ILS/eg2-src/src/app/staff/nav.component.ts
Open-ILS/eg2-src/src/app/staff/splash.component.ts

index 611797a..9052f3a 100644 (file)
@@ -61,7 +61,7 @@ export class EgAuthService {
     // - Accessor functions alway refer to the active user.
 
     user(): EgIdlObject { 
-        return this.activeUser.user 
+        return this.activeUser ? this.activeUser.user : null;
     };
 
     // Workstation name.
diff --git a/Open-ILS/eg2-src/src/app/share/confirm-dialog.component.ts b/Open-ILS/eg2-src/src/app/share/confirm-dialog.component.ts
new file mode 100644 (file)
index 0000000..b9d527d
--- /dev/null
@@ -0,0 +1,71 @@
+import {Component, Input, ViewChild, TemplateRef} from '@angular/core';
+import {NgbModal, NgbModalRef} from '@ng-bootstrap/ng-bootstrap';
+
+// TODO: DOCS
+
+@Component({
+  selector: 'eg-confirm-dialog',
+  template: `
+    <ng-template #dialogContent>
+      <div class="modal-header bg-info">
+        <h4 class="modal-title">{{dialogTitle}}</h4>
+        <button type="button" class="close" 
+          i18n-aria-label aria-label="Close" 
+          (click)="dismiss('cross_click')">
+          <span aria-hidden="true">&times;</span>
+        </button>
+      </div>
+      <div class="modal-body"><p>{{dialogBody}}</p></div>
+      <div class="modal-footer">
+        <button type="button" class="btn btn-success" 
+          (click)="close('confirmed')" i18n>Confirm</button>
+        <button type="button" class="btn btn-warning" 
+          (click)="dismiss('canceled')" i18n>Cancel</button>
+      </div>
+    </ng-template>
+    `
+})
+export class EgConfirmDialogComponent {
+
+    // We need a reference to our template so we can pass it
+    // off to the modal service open() call.
+    @ViewChild('dialogContent')
+    private dialogContent: TemplateRef<any>;
+
+    // The modalRef allows direct control of the modal instance.
+    private modalRef: NgbModalRef = null;
+
+    @Input() public dialogTitle: string;
+    @Input() public dialogBody: string;
+
+    constructor(private modalService: NgbModal) {}
+
+    open(): Promise<void> {
+        return new Promise((resolve, reject) => {
+
+            if (this.modalRef !== null) {
+                console.error('Dismissing existing EgConfirmDialog!');
+                this.dismiss();
+            }
+
+            this.modalRef = this.modalService.open(this.dialogContent);
+            this.modalRef.result.then(
+                resolved => resolve(),
+                rejected => reject()
+            )
+        });
+    }
+
+    close(): void {
+        this.modalRef.close();
+        this.modalRef = null;
+    }
+
+    dismiss(): void {
+        this.modalRef.dismiss();
+        this.modalRef = null;
+    }
+
+}
+
+
index 5b95268..1bc1cf0 100644 (file)
@@ -1,3 +1,12 @@
+
+<!-- this will remain hidden until opened -->
+<eg-confirm-dialog 
+  #workstationExistsDialog 
+  i18n-dialogTitle i18n-dialogBody
+  dialogTitle="Workstation Exists"
+  dialogBody='Workstation "{{newName}}" already exists.  Use it anyway?'>
+</eg-confirm-dialog>
+
 <div class="row">
   <div class="col-8 offset-1">
     <div class="alert alert-warning" *ngIf="removingWs" i18n>
index b724dc0..43ca664 100644 (file)
@@ -1,10 +1,11 @@
-import {Component, OnInit} from '@angular/core';
+import {Component, OnInit, ViewChild} from '@angular/core';
 import {ActivatedRoute} from '@angular/router';
 import {EgStoreService} from '@eg/core/store';
 import {EgIdlObject} from '@eg/core/idl';
 import {EgNetService} from '@eg/core/net';
 import {EgAuthService} from '@eg/core/auth';
 import {EgOrgService} from '@eg/core/org';
+import {EgConfirmDialogComponent} from '@eg/share/confirm-dialog.component';
 
 // Slim version of the WS that's stored in the cache.
 interface Workstation {
@@ -22,7 +23,10 @@ export class WorkstationsComponent implements OnInit {
     workstations: Workstation[] = [];
     removeWorkstation: string;
     newOwner: EgIdlObject;
-    newName: String;
+    newName: string = 'NewTestName';
+
+    @ViewChild('workstationExistsDialog')
+    private wsExistsDialog: EgConfirmDialogComponent;
 
     // Org selector options.
     hideOrgs: number[];
@@ -59,7 +63,12 @@ export class WorkstationsComponent implements OnInit {
     }
 
     useNow(): void {
-      console.debug('using ' + this.selected().name);
+        //console.debug('using ' + this.selected().name);
+
+        this.wsExistsDialog.open().then(
+            confirmed => console.log('dialog confirmed'),
+            dismissed => console.log('dialog dismissed')
+        );
     }
 
     setDefault(): void {
index c7051fb..d0c5db3 100644 (file)
@@ -6,12 +6,14 @@ import {WorkstationsComponent} from './app.component';
 
 @NgModule({
   declarations: [
-    WorkstationsComponent
+    WorkstationsComponent,
   ],
   imports: [
     CommonModule,
     EgStaffModule,
     WorkstationsRoutingModule
+  ],
+  providers: [
   ]
 })
 
index 7b53d7f..3b9418f 100644 (file)
@@ -10,6 +10,8 @@ import {EgStaffNavComponent} from './nav.component';
 import {EgStaffLoginComponent} from './login.component';
 import {EgStaffSplashComponent} from './splash.component';
 import {EgOrgSelectComponent} from '@eg/share/org-select.component';
+import {EgConfirmDialogComponent} from '@eg/share/confirm-dialog.component';
+
 
 @NgModule({
   declarations: [
@@ -17,7 +19,8 @@ import {EgOrgSelectComponent} from '@eg/share/org-select.component';
     EgStaffNavComponent,
     EgStaffSplashComponent,
     EgStaffLoginComponent,
-    EgOrgSelectComponent
+    EgOrgSelectComponent,
+    EgConfirmDialogComponent
   ],
   imports: [
     EgStaffRoutingModule,
@@ -27,6 +30,7 @@ import {EgOrgSelectComponent} from '@eg/share/org-select.component';
   exports: [
     // Components available to all staff/sub modules
     EgOrgSelectComponent,
+    EgConfirmDialogComponent,
     FormsModule,
     NgbModule
   ]
index 62fb605..57dcfda 100644 (file)
@@ -16,8 +16,10 @@ export class EgStaffNavComponent implements OnInit {
     constructor(private auth: EgAuthService) {}
 
     ngOnInit() {
-        this.user = this.auth.user().usrname();
-        this.workstation = this.auth.workstation();
+        if (this.auth.user()) {
+            this.user = this.auth.user().usrname();
+            this.workstation = this.auth.workstation();
+        }
     }
 }
 
index e113437..beba23a 100644 (file)
@@ -10,8 +10,8 @@ export class EgStaffSplashComponent implements OnInit {
     catSearchQuery: string;
 
     constructor(
-      private renderer: Renderer,
-      private router: Router
+        private renderer: Renderer,
+        private router: Router
     ) {}
 
     ngOnInit() {