2018-05-26 09:59:57 +00:00
|
|
|
import { Component, Input, Output, EventEmitter, ViewChild, OnInit, OnChanges, SimpleChanges } from '@angular/core';
|
2018-05-25 09:18:06 +00:00
|
|
|
import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe';
|
2018-05-25 11:02:27 +00:00
|
|
|
import { MessageService } from 'primeng/components/common/messageservice';
|
2018-05-26 09:59:57 +00:00
|
|
|
import { Message } from 'primeng/primeng';
|
2018-04-06 13:02:46 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-probe-detail',
|
|
|
|
templateUrl: './detail.component.html',
|
2018-05-25 11:02:27 +00:00
|
|
|
providers: [MessageService]
|
2018-04-06 13:02:46 +00:00
|
|
|
})
|
2018-05-26 09:59:57 +00:00
|
|
|
export class ProbeDetailComponent implements OnChanges {
|
2018-04-06 13:02:46 +00:00
|
|
|
|
2018-05-26 09:08:40 +00:00
|
|
|
@Input() pending: boolean;
|
2018-05-25 09:18:06 +00:00
|
|
|
@Input() probeHost: ProbeHost;
|
|
|
|
@Output() modify = new EventEmitter<ProbeHost>();
|
|
|
|
@Output() discovery = new EventEmitter<number>();
|
2018-04-06 13:02:46 +00:00
|
|
|
|
2018-05-26 09:59:57 +00:00
|
|
|
connectionStatus: Message[] = [];
|
|
|
|
|
2018-05-25 09:18:06 +00:00
|
|
|
editMode = false;
|
2018-05-26 09:08:40 +00:00
|
|
|
displayNameErrMsg: string;
|
|
|
|
descriptionErrMsg: string;
|
|
|
|
displayName: string;
|
|
|
|
description: string;
|
2018-04-06 13:02:46 +00:00
|
|
|
|
2018-05-25 11:02:27 +00:00
|
|
|
constructor(private messageService: MessageService) {
|
2018-04-27 07:31:27 +00:00
|
|
|
}
|
|
|
|
|
2018-05-26 09:59:57 +00:00
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
if (changes['probeHost']) {
|
|
|
|
this.checkConnectStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkConnectStatus() {
|
|
|
|
this.connectionStatus = [];
|
|
|
|
const msg = this.probeHost.probe.connectDate ? {
|
|
|
|
severity: 'success',
|
|
|
|
summary: 'Connected',
|
|
|
|
detail: this.probeHost.probe.connectAddress
|
|
|
|
} : {
|
|
|
|
severity: 'warn', // info, warn, error
|
|
|
|
summary: 'Not Connected',
|
|
|
|
};
|
|
|
|
this.connectionStatus.push(msg);
|
|
|
|
}
|
|
|
|
|
2018-05-26 09:08:40 +00:00
|
|
|
onDisplayNameEditing(value: string) {
|
|
|
|
const msg: string = this.checkValidDisplayName(value);
|
|
|
|
if (msg !== null) {
|
|
|
|
this.displayNameErrMsg = msg;
|
|
|
|
} else {
|
|
|
|
this.displayNameErrMsg = null;
|
|
|
|
this.displayName = value;
|
2018-05-25 11:02:27 +00:00
|
|
|
}
|
2018-05-26 09:08:40 +00:00
|
|
|
}
|
2018-05-25 11:02:27 +00:00
|
|
|
|
2018-05-26 09:08:40 +00:00
|
|
|
onDescriptionEditing(value: string) {
|
|
|
|
const msg: string = this.checkValidDescription(value);
|
|
|
|
if (msg !== null) {
|
|
|
|
this.descriptionErrMsg = msg;
|
|
|
|
} else {
|
|
|
|
this.descriptionErrMsg = null;
|
|
|
|
this.description = value;
|
2018-05-25 11:02:27 +00:00
|
|
|
}
|
2018-05-26 09:08:40 +00:00
|
|
|
}
|
2018-05-25 11:02:27 +00:00
|
|
|
|
2018-05-26 09:08:40 +00:00
|
|
|
onEditSave() {
|
|
|
|
this.probeHost.probe.displayName = this.displayName;
|
|
|
|
this.probeHost.probe.description = this.description;
|
2018-05-25 09:18:06 +00:00
|
|
|
this.modify.emit(this.probeHost);
|
|
|
|
this.editMode = false;
|
2018-04-06 13:02:46 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 06:20:23 +00:00
|
|
|
onDiscoveryClick() {
|
2018-05-25 09:18:06 +00:00
|
|
|
this.discovery.emit(this.probeHost.id);
|
2018-04-29 10:43:14 +00:00
|
|
|
}
|
2018-05-25 11:02:27 +00:00
|
|
|
|
2018-05-26 09:08:40 +00:00
|
|
|
checkValidDisplayName(value: string): string | null {
|
|
|
|
if (value.length <= 2 || value.length > 20) {
|
2018-05-25 11:02:27 +00:00
|
|
|
return 'displayname length : 3 ~ 20';
|
|
|
|
}
|
|
|
|
const regex = /[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi;
|
2018-05-26 09:08:40 +00:00
|
|
|
if (value.match(regex)) {
|
2018-05-25 11:02:27 +00:00
|
|
|
return 'Cannot use special characters.';
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-05-26 09:08:40 +00:00
|
|
|
checkValidDescription(value: string): string | null {
|
|
|
|
if (value.length > 50) {
|
2018-05-25 11:02:27 +00:00
|
|
|
return 'description length : 0 ~ 50';
|
|
|
|
}
|
|
|
|
const regex = /[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi;
|
2018-05-26 09:08:40 +00:00
|
|
|
if (value.match(regex)) {
|
2018-05-25 11:02:27 +00:00
|
|
|
return 'Cannot use special characters.';
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-04-06 13:02:46 +00:00
|
|
|
}
|
2018-04-06 11:02:18 +00:00
|
|
|
|