member_webapp/@overflow/probe/component/detail/detail.component.ts

67 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-05-25 11:02:27 +00:00
import { Component, Input, Output, EventEmitter, ViewChild } 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-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-25 09:18:06 +00:00
export class ProbeDetailComponent {
2018-04-06 13:02:46 +00:00
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-25 09:18:06 +00:00
editMode = false;
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-25 09:18:06 +00:00
onEditSave() {
2018-05-25 11:02:27 +00:00
const displayNameValidation = this.checkValidDisplayName();
if (displayNameValidation) {
alert(displayNameValidation);
return;
}
const descriptionValidation = this.checkValidDescription();
if (descriptionValidation) {
alert(descriptionValidation);
return;
}
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
checkValidDisplayName(): string {
const displayName = this.probeHost.probe.displayName;
if (displayName.length <= 2 || displayName.length > 20) {
return 'displayname length : 3 ~ 20';
}
const regex = /[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi;
if (displayName.match(regex)) {
return 'Cannot use special characters.';
}
return null;
}
checkValidDescription(): string {
const description = this.probeHost.probe.description;
if (description.length > 50) {
return 'description length : 0 ~ 50';
}
const regex = /[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi;
if (description.match(regex)) {
return 'Cannot use special characters.';
}
return null;
}
2018-04-06 13:02:46 +00:00
}
2018-04-06 11:02:18 +00:00