1 import {Component, OnInit, Input, Renderer2} from '@angular/core';
2 import {ToastService} from '@eg/share/toast/toast.service';
3 import {AuthService} from '@eg/core/auth.service';
4 import {DialogComponent} from '@eg/share/dialog/dialog.component';
5 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
8 selector: 'eg-op-change',
9 templateUrl: 'op-change.component.html'
12 export class OpChangeComponent
13 extends DialogComponent implements OnInit {
15 @Input() username: string;
16 @Input() password: string;
17 @Input() loginType = 'temp';
19 @Input() successMessage: string;
20 @Input() failMessage: string;
23 private modal: NgbModal, // required for passing to parent
24 private renderer: Renderer2,
25 private toast: ToastService,
26 private auth: AuthService) {
32 // Focus the username any time the dialog is opened.
33 this.onOpen$.subscribe(
34 val => this.renderer.selectRootElement('#username').focus()
38 login(): Promise<any> {
39 if (!(this.username && this.password)) {
40 return Promise.reject('Missing Params');
43 return this.auth.login(
44 { username : this.username,
45 password : this.password,
46 workstation : this.auth.workstation(),
54 // Fetch the user object
55 this.auth.testAuthToken().then(
58 this.toast.success(this.successMessage);
64 this.toast.danger(this.failMessage);
69 restore(): Promise<any> {
70 return this.auth.undoOpChange().then(
71 ok => this.toast.success(this.successMessage),
72 err => this.toast.danger(this.failMessage)