perbaikan UI scheduler
This commit is contained in:
parent
98159a1584
commit
7c443080d6
|
@ -13,7 +13,7 @@
|
|||
href="https://allbestsistem.com/"
|
||||
target="_blank"
|
||||
style="background-color: #ffffff !important;"
|
||||
>Smart Building Management Systems (V@2024-08-26.3)
|
||||
>Smart Building Management Systems (V@2024-08-27.2)
|
||||
</a></span
|
||||
>
|
||||
</p>
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Checkbox for Repeat -->
|
||||
<!-- <div class="form-group col-md-12">
|
||||
<div class="form-group col-md-12">
|
||||
<label style="color: #242222">Repeat:</label>
|
||||
<div class="form-check">
|
||||
<input
|
||||
|
@ -93,9 +93,9 @@
|
|||
/>
|
||||
<label class="form-check-label" style="color: #242222">Yes</label>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-12">
|
||||
<!-- <div class="form-group col-md-12">
|
||||
<label for="active" style="color: #242222">Active:</label>
|
||||
<select
|
||||
id="active"
|
||||
|
@ -112,7 +112,7 @@
|
|||
>
|
||||
Active is required.
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -8,7 +8,6 @@ import {
|
|||
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
||||
import { DeviceService } from "../../service/device.service";
|
||||
|
||||
|
||||
@Component({
|
||||
selector: "app-control-scheduler",
|
||||
templateUrl: "./control-scheduler.component.html",
|
||||
|
@ -62,9 +61,9 @@ export class ControlSchedulerComponent {
|
|||
|
||||
ngOnInit() {
|
||||
this.createForm();
|
||||
if (this.mode === 'add') {
|
||||
if (this.mode === "add") {
|
||||
this.labelModal = "Add Scheduler";
|
||||
} else if (this.mode === 'edit') {
|
||||
} else if (this.mode === "edit") {
|
||||
this.editForm();
|
||||
this.labelModal = "Edit Scheduler";
|
||||
}
|
||||
|
@ -88,7 +87,7 @@ export class ControlSchedulerComponent {
|
|||
this.myForm = this.fb.group(controls);
|
||||
}
|
||||
|
||||
editForm(){
|
||||
editForm() {
|
||||
this.selectedDays = this.data.days || [];
|
||||
this.myForm.patchValue({
|
||||
name: this.data.name,
|
||||
|
@ -123,7 +122,10 @@ export class ControlSchedulerComponent {
|
|||
.map((day) => day.value);
|
||||
|
||||
// Construct the final output
|
||||
const result = {
|
||||
let result = {};
|
||||
|
||||
if (this.mode === "add") {
|
||||
result = {
|
||||
name: formValues.name,
|
||||
device_id: formValues.device_id,
|
||||
timeset: formValues.timeset,
|
||||
|
@ -132,11 +134,23 @@ export class ControlSchedulerComponent {
|
|||
switch: formValues.switch,
|
||||
days: selectedDays,
|
||||
};
|
||||
} else {
|
||||
result = {
|
||||
id: this.data.id,
|
||||
name: formValues.name,
|
||||
device_id: formValues.device_id,
|
||||
timeset: formValues.timeset,
|
||||
recurring: formValues.recurring,
|
||||
active: formValues.active,
|
||||
switch: formValues.switch,
|
||||
days: selectedDays,
|
||||
};
|
||||
}
|
||||
|
||||
if (this.myForm.valid) {
|
||||
this.activeModal.close(result);
|
||||
} else {
|
||||
this.markFormGroupTouched(this.myForm)
|
||||
this.markFormGroupTouched(this.myForm);
|
||||
}
|
||||
|
||||
// console.log("Form Result: ", result);
|
||||
|
|
|
@ -175,7 +175,9 @@ export class DeviceControlComponent {
|
|||
}
|
||||
|
||||
schedulerItem(row) {
|
||||
this.router.navigate(["/device/scheduler", row.id, row.name]);
|
||||
console.log(row);
|
||||
|
||||
this.router.navigate(["/device/scheduler", row.id]);
|
||||
}
|
||||
|
||||
// schedulerItem(item) {
|
||||
|
|
|
@ -69,7 +69,7 @@ import { SchedulerListComponent } from './scheduler-list/scheduler-list.componen
|
|||
data: { mode: 'view' }
|
||||
},
|
||||
{
|
||||
path: 'scheduler/:id/:name',
|
||||
path: 'scheduler/:id',
|
||||
component: SchedulerListComponent,
|
||||
data: { mode: 'scheduler' }
|
||||
}
|
||||
|
|
|
@ -52,4 +52,3 @@
|
|||
background-color: #d1d9ff;
|
||||
color: #303f9f;
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
>
|
||||
<h4 class="form-section m-0" style="color: #242222">
|
||||
<i class="feather ft-calendar" style="color: #242222"></i>
|
||||
{{deviceName}}
|
||||
{{ deviceName ? deviceName : '' }}
|
||||
</h4>
|
||||
|
||||
<button
|
||||
|
@ -40,35 +40,50 @@
|
|||
class="list-group-item d-flex justify-content-between align-items-center mb-3"
|
||||
*ngFor="let schedule of listScheduler"
|
||||
>
|
||||
<div>
|
||||
<!-- Tambahkan checkbox di sini -->
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
[(ngModel)]="schedule.selected"
|
||||
(change)="checkSelected()"
|
||||
/>
|
||||
</div>
|
||||
<div (click)="editSchedule(schedule)">
|
||||
<h5 style="color: #242222">
|
||||
{{ schedule.name }} ({{schedule.switch ? 'On' : 'Off'}})
|
||||
{{ schedule.name }} ({{
|
||||
schedule.switch ? "On" : "Off"
|
||||
}})
|
||||
</h5>
|
||||
<h2 class="mb-0" style="color: #242222">
|
||||
{{ schedule.timeset }}
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<ui-switch
|
||||
style="border-color: #bef264 !important"
|
||||
class="switchery"
|
||||
switchColor="white"
|
||||
color="rgb(55, 166, 71)"
|
||||
size="small"
|
||||
[checked]="schedule.active"
|
||||
(change)="switchChanged($event, schedule)"
|
||||
></ui-switch>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Tambahkan tombol delete di sini -->
|
||||
<div class="d-flex justify-content-center">
|
||||
<button
|
||||
class="btn btn-sm btn-info mr-1"
|
||||
*ngIf="hasSelected"
|
||||
class="btn btn-danger mt-2"
|
||||
(click)="deleteSelectedSchedules()"
|
||||
style="
|
||||
background-color: transparent !important;
|
||||
border-color: #37a647 !important;
|
||||
"
|
||||
(click)="editSchedule(schedule)"
|
||||
>
|
||||
<i
|
||||
class="ficon la la-edit"
|
||||
style="color: #37a647 !important"
|
||||
></i>
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-sm btn-warning mr-1"
|
||||
style="
|
||||
background-color: transparent !important;
|
||||
border-color: #37a647 !important;
|
||||
"
|
||||
(click)="deleteSchedule(schedule.id)"
|
||||
>
|
||||
<i
|
||||
class="ficon la la-trash"
|
||||
|
@ -76,8 +91,6 @@
|
|||
></i>
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<ng-template #noSchedules>
|
||||
|
|
|
@ -14,6 +14,7 @@ export class SchedulerListComponent {
|
|||
listScheduler: any;
|
||||
deviceId: any;
|
||||
deviceName: any;
|
||||
hasSelected: boolean = false;
|
||||
schedules = [
|
||||
{
|
||||
id: 1,
|
||||
|
@ -36,11 +37,10 @@ export class SchedulerListComponent {
|
|||
ngOnInit(): void {
|
||||
this.route.params.subscribe((params) => {
|
||||
const id = params["id"];
|
||||
const name = params["name"];
|
||||
this.deviceName = name;
|
||||
this.deviceId = id;
|
||||
if (id) {
|
||||
this.dataListScheduler(id);
|
||||
this.dataDevice(id);
|
||||
}
|
||||
});
|
||||
this.breadcrumb = {
|
||||
|
@ -68,6 +68,24 @@ export class SchedulerListComponent {
|
|||
dataListScheduler(id) {
|
||||
this.deviceService.getDeviceScheduler(id).subscribe((data) => {
|
||||
this.listScheduler = data.results;
|
||||
console.log(this.listScheduler);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
dataDevice(id) {
|
||||
this.deviceService.getDeviceByid(id).subscribe((data) => {
|
||||
this.deviceName = data.data.name
|
||||
});
|
||||
}
|
||||
|
||||
switchChanged(e, item) {
|
||||
const data = {
|
||||
id: item.id,
|
||||
active: e,
|
||||
};
|
||||
this.deviceService.putDeviceSchedulerActive(data, item.id).subscribe((res) => {
|
||||
this.dataListScheduler(this.deviceId);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -97,7 +115,6 @@ export class SchedulerListComponent {
|
|||
}
|
||||
|
||||
editSchedule(data) {
|
||||
console.log(data);
|
||||
const modalRef = this.modalService.open(ControlSchedulerComponent, {
|
||||
size: "md",
|
||||
backdrop: "static",
|
||||
|
@ -111,7 +128,9 @@ export class SchedulerListComponent {
|
|||
modalRef.result.then(
|
||||
(result) => {
|
||||
if (result) {
|
||||
this.deviceService.putDeviceScheduler(result, data.id).subscribe((res) => {
|
||||
this.deviceService
|
||||
.putDeviceScheduler(result, data.id)
|
||||
.subscribe((res) => {
|
||||
this.dataListScheduler(this.deviceId);
|
||||
});
|
||||
}
|
||||
|
@ -122,9 +141,18 @@ export class SchedulerListComponent {
|
|||
);
|
||||
}
|
||||
|
||||
deleteSchedule(id) {
|
||||
checkSelected() {
|
||||
this.hasSelected = this.listScheduler.some((schedule) => schedule.selected);
|
||||
}
|
||||
|
||||
deleteSelectedSchedules() {
|
||||
const selectedSchedules = this.listScheduler.filter(
|
||||
(schedule) => schedule.selected
|
||||
);
|
||||
|
||||
if (selectedSchedules.length > 0) {
|
||||
Swal.fire({
|
||||
title: "Apakah kamu yakin ingin menghapus jadwal ini?",
|
||||
title: "Apakah kamu yakin ingin menghapus jadwal yang dipilih?",
|
||||
text: "Tindakan ini tidak dapat dibatalkan.",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
|
@ -135,15 +163,30 @@ export class SchedulerListComponent {
|
|||
allowOutsideClick: false,
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this.deviceService.deleteDeviceScheduler(id).subscribe((data) => {
|
||||
this.dataListScheduler(this.deviceId);
|
||||
selectedSchedules.forEach((schedule) => {
|
||||
this.deleteSchedule(schedule.id);
|
||||
});
|
||||
|
||||
Swal.fire({
|
||||
title: "Terhapus!",
|
||||
text: "Jadwal berhasil dihapus.",
|
||||
text: "Jadwal yang dipilih berhasil dihapus.",
|
||||
icon: "success",
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: "Tidak ada jadwal yang dipilih!",
|
||||
text: "Pilih setidaknya satu jadwal untuk dihapus.",
|
||||
icon: "info",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteSchedule(id) {
|
||||
this.deviceService.deleteDeviceScheduler(id).subscribe(() => {
|
||||
this.dataListScheduler(this.deviceId);
|
||||
this.hasSelected = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,15 +105,9 @@
|
|||
<i class="feather ft-plus"> New Floor</i>
|
||||
</button>
|
||||
</div>
|
||||
<small
|
||||
class="form-text text-muted danger"
|
||||
*ngIf="submitted && f.floorId.errors"
|
||||
class="invalid-feedback"
|
||||
>
|
||||
<div *ngIf="f.floorId.errors.required">
|
||||
Building is required
|
||||
<div *ngIf="projectInfo.get('floorId').touched && projectInfo.get('floorId').invalid" class="text-danger">
|
||||
Floor is required.
|
||||
</div>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -99,6 +99,16 @@ export class DeviceService {
|
|||
return this.http.get<any>(url, { headers });
|
||||
}
|
||||
|
||||
getDeviceByid(id): Observable<any> {
|
||||
const endpoint = `/devices`;
|
||||
const url = `${BASE_URL}${endpoint}/${id}`;
|
||||
const headers = new HttpHeaders({
|
||||
'Content-Type': 'application/json',
|
||||
'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
|
||||
});
|
||||
return this.http.get<any>(url, { headers });
|
||||
}
|
||||
|
||||
filterDashboard(building, floor): Observable<any> {
|
||||
const endpoint = `/building/dashboard/list`;
|
||||
const params = new URLSearchParams({
|
||||
|
@ -146,6 +156,16 @@ export class DeviceService {
|
|||
return this.http.put<any>(url, data, { headers });
|
||||
}
|
||||
|
||||
putDeviceSchedulerActive(data, id): Observable<any> {
|
||||
const endpoint = `/device-scheduler/${id}/Active`;
|
||||
const url = `${BASE_URL}${endpoint}`;
|
||||
const headers = new HttpHeaders({
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
|
||||
});
|
||||
return this.http.put<any>(url, data, { headers });
|
||||
}
|
||||
|
||||
deleteDeviceScheduler(id): Observable<any> {
|
||||
const endpoint = `/device-scheduler/${id}`;
|
||||
const url = `${BASE_URL}${endpoint}`;
|
||||
|
|
|
@ -138,7 +138,7 @@
|
|||
<p
|
||||
class="card-subtitle line-on-side text-muted text-center font-small-3 mx-2 my-1"
|
||||
>
|
||||
<span>(v@2024.08.26.3)</span>
|
||||
<span>(v@2024.08.27.2)</span>
|
||||
</p>
|
||||
<!-- <div class="card-body">
|
||||
<a
|
||||
|
|
Loading…
Reference in New Issue