perbakan UI scheduler

This commit is contained in:
Fuzi_fauzia 2024-08-22 15:45:48 +07:00
parent a2d166ac1a
commit 9654cf92e8
3 changed files with 109 additions and 52 deletions

View File

@ -13,15 +13,15 @@
<form [formGroup]="myForm"> <form [formGroup]="myForm">
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-12"> <div class="form-group col-md-12">
<label for="timeOn" style="color: #242222">Time On:</label> <label for="timeset" style="color: #242222">Time</label>
<input <input
type="time" type="time"
class="form-control" class="form-control"
formControlName="timeOn" formControlName="timeset"
id="timeOn" id="timeset"
/> />
<div <div
*ngIf="myForm.get('timeOn').touched && myForm.get('timeOn').invalid" *ngIf="myForm.get('timeset').touched && myForm.get('timeset').invalid"
class="text-danger" class="text-danger"
> >
Time On is required. Time On is required.
@ -29,37 +29,50 @@
</div> </div>
<div class="form-group col-md-12"> <div class="form-group col-md-12">
<label for="timeOff" style="color: #242222">Time Off:</label> <label for="switch" style="color: #242222">Switch:</label>
<input
type="time"
class="form-control"
formControlName="timeOff"
id="timeOff"
/>
<div
*ngIf="myForm.get('timeOff').touched && myForm.get('timeOff').invalid"
class="text-danger"
>
Time Off is required.
</div>
</div>
<div class="form-group col-md-12">
<label for="status" style="color: #242222">Status:</label>
<select <select
id="status" id="switch"
class="form-control custom-select" class="form-control custom-select"
formControlName="status" formControlName="switch"
> >
<option *ngFor="let data of dataMasterStatus" [value]="data.id"> <option *ngFor="let data of dataSwitch" [value]="data.value">
{{ data.name }} {{ data.label }}
</option> </option>
</select> </select>
<div <div
*ngIf="myForm.get('status').touched && myForm.get('status').invalid" *ngIf="myForm.get('switch').touched && myForm.get('switch').invalid"
class="text-danger" class="text-danger"
> >
Status is required. Switch is required.
</div>
</div>
<!-- Checkbox for Days of the Week -->
<div class="form-group col-md-12">
<label style="color: #242222">Select Days:</label>
<div *ngFor="let day of daysOfWeek">
<div class="form-check">
<input
type="checkbox"
class="form-check-input"
[formControlName]="day.value"
(change)="onDayChange(day.value, $event.target.checked)"
/>
<label class="form-check-label" style="color: #242222">{{ day.label }}</label>
</div>
</div>
</div>
<!-- Checkbox for Repeat -->
<div class="form-group col-md-12">
<label style="color: #242222">Repeat:</label>
<div class="form-check">
<input
type="checkbox"
class="form-check-input"
formControlName="repeat"
/>
<label class="form-check-label" style="color: #242222">Yes</label>
</div> </div>
</div> </div>
</div> </div>
@ -82,7 +95,7 @@
type="button" type="button"
style="color: #ffffff !important; background-color: #37a647 !important" style="color: #ffffff !important; background-color: #37a647 !important"
class="btn btn-primary" class="btn btn-primary"
(click)="addRow()" (click)="save()"
> >
Save Save
</button> </button>

View File

@ -1,7 +1,6 @@
import { Component } from "@angular/core"; import { Component } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from "@angular/forms"; import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms";
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap"; import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
import { BuildingService } from "../../service/monitoring-api.service";
@Component({ @Component({
selector: "app-control-scheduler", selector: "app-control-scheduler",
@ -11,40 +10,76 @@ import { BuildingService } from "../../service/monitoring-api.service";
export class ControlSchedulerComponent { export class ControlSchedulerComponent {
labelModal: string = ""; labelModal: string = "";
myForm: FormGroup; myForm: FormGroup;
dataMasterStatus: any; dataSwitch = [
{
label: 'On',
value: true
}, {
label: 'Off',
value: false
}
];
daysOfWeek = [
{ label: 'Monday', value: 'monday' },
{ label: 'Tuesday', value: 'tuesday' },
{ label: 'Wednesday', value: 'wednesday' },
{ label: 'Thursday', value: 'thursday' },
{ label: 'Friday', value: 'friday' },
{ label: 'Saturday', value: 'saturday' },
{ label: 'Sunday', value: 'sunday' }
];
selectedDays: string[] = [];
constructor( constructor(
public activeModal: NgbActiveModal, public activeModal: NgbActiveModal,
private monitoringApiService: BuildingService,
private fb: FormBuilder, private fb: FormBuilder,
) {} ) {}
ngOnInit() { ngOnInit() {
this.dataListMaster();
this.createForm() this.createForm()
} }
addRow() {}
createForm() { createForm() {
this.myForm = this.fb.group({ const controls = {
timeOn: ["", Validators.required], timeset: ["", Validators.required],
status: ["", Validators.required], switch: [false],
timeOff: ["", Validators.required], repeat: [false], // Default value for repeat checkbox
};
// Initialize checkboxes for each day of the week
this.daysOfWeek.forEach(day => {
controls[day.value] = [false]; // Each day starts as unchecked
}); });
this.myForm = this.fb.group(controls);
} }
dataListMaster() { onDayChange(day: string, isChecked: boolean) {
this.monitoringApiService.getMasterListData().subscribe((data) => { if (isChecked) {
const dataCategory = data.data.find( this.selectedDays.push(day);
(item) => item.name === "master_status" } else {
).headerDetailParam; this.selectedDays = this.selectedDays.filter(d => d !== day);
this.dataMasterStatus = dataCategory.filter( }
(item) => item.statusName.toLowerCase() === "aktif" }
);
console.log(this.dataMasterStatus); save() {
const formValues = this.myForm.value;
});
// Collect selected days' labels
const selectedDays = this.daysOfWeek
.filter(day => formValues[day.value])
.map(day => day.label);
// Construct the final output
const result = {
timeset: formValues.timeset,
switch: formValues.switch,
repeat: formValues.repeat,
day: selectedDays
};
console.log("Form Result: ", result);
} }
} }

View File

@ -1,4 +1,4 @@
import { Component } from "@angular/core"; import { Component, HostListener } from "@angular/core";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import { BuildingService } from "../../service/monitoring-api.service"; import { BuildingService } from "../../service/monitoring-api.service";
import { DeviceService } from "../../service/device.service"; import { DeviceService } from "../../service/device.service";
@ -196,4 +196,13 @@ export class DeviceControlComponent {
); );
// Handle edit action // Handle edit action
} }
@HostListener('document:click', ['$event'])
clickout(event) {
if (!event.target.closest('.menu-popup') && !event.target.closest('.btn')) {
this.filteredDeviceRows.forEach(item => {
item.menuOpen = false;
});
}
}
} }