// - Accessor functions alway refer to the active user.
user(): EgIdlObject {
- return this.activeUser.user
+ return this.activeUser ? this.activeUser.user : null;
};
// Workstation name.
--- /dev/null
+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">×</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;
+ }
+
+}
+
+
+
+<!-- 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>
-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 {
workstations: Workstation[] = [];
removeWorkstation: string;
newOwner: EgIdlObject;
- newName: String;
+ newName: string = 'NewTestName';
+
+ @ViewChild('workstationExistsDialog')
+ private wsExistsDialog: EgConfirmDialogComponent;
// Org selector options.
hideOrgs: number[];
}
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 {
@NgModule({
declarations: [
- WorkstationsComponent
+ WorkstationsComponent,
],
imports: [
CommonModule,
EgStaffModule,
WorkstationsRoutingModule
+ ],
+ providers: [
]
})
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: [
EgStaffNavComponent,
EgStaffSplashComponent,
EgStaffLoginComponent,
- EgOrgSelectComponent
+ EgOrgSelectComponent,
+ EgConfirmDialogComponent
],
imports: [
EgStaffRoutingModule,
exports: [
// Components available to all staff/sub modules
EgOrgSelectComponent,
+ EgConfirmDialogComponent,
FormsModule,
NgbModule
]
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();
+ }
}
}
catSearchQuery: string;
constructor(
- private renderer: Renderer,
- private router: Router
+ private renderer: Renderer,
+ private router: Router
) {}
ngOnInit() {