diff --git a/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.ts b/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.ts
index 343a393..a8219c3 100644
--- a/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.ts
+++ b/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.ts
@@ -1,7 +1,9 @@
import { Component } from "@angular/core";
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
import { ControlSchedulerComponent } from "../control-scheduler/control-scheduler.component";
-
+import { ActivatedRoute } from "@angular/router";
+import { DeviceService } from "../../service/device.service";
+import Swal from "sweetalert2";
@Component({
selector: "app-scheduler-list",
templateUrl: "./scheduler-list.component.html",
@@ -9,6 +11,8 @@ import { ControlSchedulerComponent } from "../control-scheduler/control-schedule
})
export class SchedulerListComponent {
public breadcrumb: any;
+ listScheduler: any;
+ deviceId: any;
schedules = [
{
id: 1,
@@ -22,11 +26,24 @@ export class SchedulerListComponent {
},
];
- constructor(private modalService: NgbModal) {}
+ constructor(
+ private modalService: NgbModal,
+ private route: ActivatedRoute,
+ private deviceService: DeviceService
+ ) {}
ngOnInit(): void {
+ this.route.params.subscribe((params) => {
+ const id = params["id"];
+ this.deviceId = id;
+ if (id) {
+ this.dataListScheduler(id);
+ }
+ });
this.breadcrumb = {
mainlabel: "Scheduler List",
+ linkBack: "/device/control-device",
+ isLinkBack: true,
links: [
{
name: "Home",
@@ -45,19 +62,28 @@ export class SchedulerListComponent {
};
}
- addSchedulerItem(item) {
+ dataListScheduler(id) {
+ this.deviceService.getDeviceScheduler(id).subscribe((data) => {
+ this.listScheduler = data.results;
+ });
+ }
+
+ addSchedulerItem() {
const modalRef = this.modalService.open(ControlSchedulerComponent, {
size: "md",
- backdrop: "static",
- keyboard: false,
- centered: true
+ backdrop: "static",
+ keyboard: false,
+ centered: true,
});
- modalRef.componentInstance.device = item;
+ modalRef.componentInstance.deviceId = this.deviceId;
+ modalRef.componentInstance.mode = "add";
modalRef.result.then(
(result) => {
if (result) {
- console.log(result);
+ this.deviceService.postDeviceScheduler(result).subscribe((res) => {
+ this.dataListScheduler(this.deviceId);
+ });
}
},
(reason) => {
@@ -67,4 +93,27 @@ export class SchedulerListComponent {
// Handle edit action
}
+ deleteSchedule(id) {
+ Swal.fire({
+ title: "Apakah kamu yakin ingin menghapus jadwal ini?",
+ text: "Tindakan ini tidak dapat dibatalkan.",
+ icon: "warning",
+ showCancelButton: true,
+ confirmButtonColor: "#37a647",
+ cancelButtonColor: "#d33",
+ confirmButtonText: "Ya, hapus!",
+ cancelButtonText: "Batal",
+ }).then((result) => {
+ if (result.isConfirmed) {
+ this.deviceService.deleteDeviceScheduler(id).subscribe((data) => {
+ this.dataListScheduler(this.deviceId);
+ });
+ Swal.fire({
+ title: "Terhapus!",
+ text: "Jadwal berhasil dihapus.",
+ icon: "success",
+ });
+ }
+ });
+ }
}
diff --git a/src/app/content/hemat-app/service/device.service.ts b/src/app/content/hemat-app/service/device.service.ts
index fc44ae3..e15c24c 100644
--- a/src/app/content/hemat-app/service/device.service.ts
+++ b/src/app/content/hemat-app/service/device.service.ts
@@ -115,4 +115,34 @@ export class DeviceService {
});
return this.http.get
(url, { headers });
}
+
+ getDeviceScheduler(id): Observable {
+ const endpoint = `/device-scheduler`;
+ const url = `${BASE_URL}${endpoint}?device_id=${id}`;
+ const headers = new HttpHeaders({
+ 'Content-Type': 'application/json',
+ 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
+ });
+ return this.http.get(url, { headers });
+ }
+
+ postDeviceScheduler(data): Observable {
+ const endpoint = `/device-scheduler`;
+ const url = `${BASE_URL}${endpoint}`;
+ const headers = new HttpHeaders({
+ "Content-Type": "application/json",
+ "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
+ });
+ return this.http.post(url, data, { headers });
+ }
+
+ deleteDeviceScheduler(id): Observable {
+ const endpoint = `/device-scheduler/${id}`;
+ const url = `${BASE_URL}${endpoint}`;
+ const headers = new HttpHeaders({
+ "Content-Type": "application/json",
+ "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
+ });
+ return this.http.delete(url, { headers });
+ }
}
diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html
index 0192d31..90aef66 100644
--- a/src/app/login/login.component.html
+++ b/src/app/login/login.component.html
@@ -138,7 +138,7 @@
- (v@2024.08.22.2)
+ (v@2024.08.26.2)