Skip to content

Instantly share code, notes, and snippets.

@repen
Created June 5, 2022 08:49
Show Gist options
  • Save repen/6dd3b3cba28dead67a952506c8ed7653 to your computer and use it in GitHub Desktop.
Save repen/6dd3b3cba28dead67a952506c8ed7653 to your computer and use it in GitHub Desktop.
import { Component, OnInit } from '@angular/core';
import {ModalDismissReasons, NgbModal} from "@ng-bootstrap/ng-bootstrap";
import {InternetService} from "../../../../../service/common/internet/internet.service";
import {environment} from "../../../../../../../environments/environment";
import {ServerPanelService} from "../../server-panel.service";
import {IServer} from "../../server-panel.service";
interface IAlert {
type: string;
message: string;
show: boolean;
}
@Component({
selector: 'add-server-button',
templateUrl: './add-server.component.html',
styleUrls: ['./add-server.component.scss']
})
export class AddServerComponent implements OnInit {
closeResult = '';
disabledButton = true;
serverForm: IServer;
alert: IAlert = {type: "", message: "", show: false};
constructor(
protected modalService: NgbModal,
protected internetService: InternetService,
public serverPanelService: ServerPanelService
) {
this.serverForm = {
username: "",
address: "",
password: "",
name: "",
};
}
ngOnInit(): void {
}
open(content:any) {
this.alert.show = false;
this.modalService.open(content, {}).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
console.log("Save", result);
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
getDismissReason(reason: any): string {
console.log(reason, "!!");
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
clickAddServer(){
if (!!this.serverForm.address && !!this.serverForm.username && !!this.serverForm.password){
this.serverForm.name = this.serverForm.address;
this.internetService.methodPost(environment.config.server_create, this.serverForm,
(res)=>{
this.serverPanelService.loadServerList();
this.modalService.dismissAll(res.message);
}, ()=>{});
} else {
this.alert.type = "danger";
this.alert.message = "Incorrect values of form.";
this.alert.show = true;
}
}
onChangeInput(newValue: any){
console.log(newValue);
if (!!this.serverForm.address && !!this.serverForm.username && !!this.serverForm.password){
this.disabledButton = false;
} else {
this.disabledButton = true;
}
}
closeAlert(alert: IAlert) {
alert.show = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment