diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 44359ad..5dcd606 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -2,7 +2,7 @@

Dodawanie nowych urządzeń

-
+
Podaj przypisany do urządzenia stały adres IP @@ -40,23 +42,20 @@

Usuwanie urządzeń

- +
Podaj nazwę czujnika (w przypadku ESPEasy name device) + >Podaj przypisany do urządzenia stały adres IP - {{ nameDeleteDevice.value.length }} / 100 + {{ ipDeviceDel.value.length }} / 15
diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index d507d28..8ad83e1 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -1,11 +1,8 @@ import { Component, OnInit } from "@angular/core"; -import { - FormControl, - FormGroupDirective, - NgForm, - Validators -} from "@angular/forms"; -import { ErrorStateMatcher } from "@angular/material/core"; +import { FormControl } from "@angular/forms"; +import { HttpClient } from "@angular/common/http"; +import { Observable } from "rxjs/Observable"; +import "rxjs/Rx"; @Component({ selector: "app-admin", @@ -13,7 +10,35 @@ import { ErrorStateMatcher } from "@angular/material/core"; styleUrls: ["./admin.component.less"] }) export class AdminComponent implements OnInit { - constructor() {} + name = new FormControl(""); + ip = new FormControl(""); + ipDelete = new FormControl(""); + + constructor(private http: HttpClient) {} + + onAddDevice() { + if (this.name.value.length > 0 && this.ip.value.length > 0) { + this.http + .post("http://localhost:3000/device", { + name: this.name.value, + ip: this.ip.value + }) + .subscribe(data => { + this.name.reset(); + this.ip.reset(); + }); + } + } + + onDeviceDelete() { + if (this.ipDelete.value.length > 0) { + this.http + .delete("http://localhost:3000/device/" + this.ipDelete.value) + .subscribe(data => { + this.ipDelete.reset(); + }); + } + } ngOnInit() {} } diff --git a/src/app/shared/status/status.service.ts b/src/app/shared/status/status.service.ts index 63435cc..8d3bf51 100644 --- a/src/app/shared/status/status.service.ts +++ b/src/app/shared/status/status.service.ts @@ -7,17 +7,17 @@ import "rxjs/Rx"; providedIn: "root" }) export class StatusService { - private url_pilkarzyki1 = - "http://localhost:3000/chillroom-server?ip=192.168.8.107"; + // private url_pilkarzyki1 = + // "http://localhost:3000/chillroom-server?ip=192.168.8.107"; private url_db = "http://localhost:3000/all"; private status_url = "http://localhost:3000/status/"; constructor(private http: HttpClient) {} - getPilkarzyki1(): Observable { - return this.http.get(this.url_pilkarzyki1); - } + // getPilkarzyki1(): Observable { + // return this.http.get(this.url_pilkarzyki1); + // } getDB(): Observable { return this.http.get(this.url_db); }