-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathguide.component.ts
More file actions
91 lines (77 loc) · 2.61 KB
/
Copy pathguide.component.ts
File metadata and controls
91 lines (77 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { ConnectionToken } from '@app/model';
import { Command, InfoItem } from './model';
import { Component, Input, OnInit } from '@angular/core';
import { NzNotificationService } from 'ng-zorro-antd/notification';
import { ConnectTokenService, HttpService, I18nService } from '@app/services';
@Component({
standalone: false,
selector: 'elements-connector-guide',
templateUrl: 'guide.component.html',
styleUrls: ['guide.component.scss']
})
export class ElementConnectorGuideComponent implements OnInit {
@Input() assetType: string;
@Input() canReuse: boolean;
@Input() token: ConnectionToken;
@Input() infoItems: Array<InfoItem>;
@Input() commands: Array<Command>;
hoverClipTip = '';
passwordMask = '******';
passwordShow = '******';
showClient = false;
reusable = false;
constructor(
private _http: HttpService,
private _i18n: I18nService,
private _toastr: NzNotificationService,
private _connectTokenSvc: ConnectTokenService
) {}
ngOnInit() {
this.hoverClipTip = this._i18n.instant('Click to copy');
if (this.token && this.token.is_reusable !== undefined) {
this.reusable = this.token.is_reusable;
}
}
setReusable(newValue: boolean) {
this._connectTokenSvc.setReusable(this.token, newValue).subscribe(
res => {
this.token = Object.assign(this.token, res);
const tokenItem = this.infoItems.find(item => item.name === 'date_expired');
tokenItem.value = `${this.token.date_expired}`;
this.reusable = newValue;
},
error => {
this.reusable = !newValue;
this.token.is_reusable = !newValue;
let msg = '';
if (error.status === 404) {
msg = this._i18n.instant('Token expired');
} else {
msg = error.error.msg || error.error.is_reusable || error.message;
}
this._toastr.error(msg, '', { nzDuration: 2000, nzClass: 'custom-error-notification' });
}
);
}
startClient(cmd) {
this._http.getLocalClientUrlAndSetCommand(this.token, cmd.value).then((res: any) => {
window.open(res.url);
});
}
showPassword($event) {
$event.stopPropagation();
if (this.passwordShow === this.passwordMask) {
const passwordItem = this.infoItems.find(item => item.name === 'password');
this.passwordShow = passwordItem.value;
} else {
this.passwordShow = this.passwordMask;
}
}
async onCopySuccess(evt) {
const msg = await this._i18n.t('Copied');
this._toastr.success(msg, '', { nzClass: 'custom-success-notification' });
}
onHoverClipRef(evt) {
this.hoverClipTip = this._i18n.instant('Click to copy');
}
}