refs #729. RemoteCalendar and RemoteCalendarRule. Finish

oggui/calendar
Manuel Aranda Rosales 2024-09-26 12:03:20 +02:00
parent 30bd210b09
commit 390f454ac2
9 changed files with 100 additions and 34 deletions

View File

@ -15,14 +15,10 @@ import { PxeBootFilesComponent } from './components/ogboot/pxe-boot-files/pxe-bo
import {OgbootStatusComponent} from "./components/ogboot/ogboot-status/ogboot-status.component"; import {OgbootStatusComponent} from "./components/ogboot/ogboot-status/ogboot-status.component";
import { OgdhcpComponent } from './components/ogdhcp/ogdhcp.component'; import { OgdhcpComponent } from './components/ogdhcp/ogdhcp.component';
import { OgDhcpSubnetsComponent } from './components/ogdhcp/og-dhcp-subnets/og-dhcp-subnets.component'; import { OgDhcpSubnetsComponent } from './components/ogdhcp/og-dhcp-subnets/og-dhcp-subnets.component';
<<<<<<< HEAD
import { CommandsComponent } from './components/commands/commands.component';
import { CalendarComponent } from "./components/calendar/calendar.component"; import { CalendarComponent } from "./components/calendar/calendar.component";
=======
import { CommandsComponent } from './components/commands/main-commands/commands.component'; import { CommandsComponent } from './components/commands/main-commands/commands.component';
import { CommandsGroupsComponent } from './components/commands/commands-groups/commands-groups.component'; import { CommandsGroupsComponent } from './components/commands/commands-groups/commands-groups.component';
import { CommandsTaskComponent } from './components/commands/commands-task/commands-task.component'; import { CommandsTaskComponent } from './components/commands/commands-task/commands-task.component';
>>>>>>> 30cd43ff0fcccafbf6d2b7534dd31ba0b3c2c257
const routes: Routes = [ const routes: Routes = [
{ path: '', redirectTo: 'auth/login', pathMatch: 'full' }, { path: '', redirectTo: 'auth/login', pathMatch: 'full' },
{ {

View File

@ -39,7 +39,7 @@
<ng-container matColumnDef="actions"> <ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef i18n="@@columnActions" style="text-align: center;">Acciones</th> <th mat-header-cell *matHeaderCellDef i18n="@@columnActions" style="text-align: center;">Acciones</th>
<td mat-cell *matCellDef="let calendar" style="text-align: center;"> <td mat-cell *matCellDef="let calendar" style="text-align: center;">
<button mat-icon-button color="primary" (click)="editImage(calendar)" i18n="@@editImage"> <mat-icon>edit</mat-icon></button> <button mat-icon-button color="primary" (click)="editCalendar(calendar)" i18n="@@editImage"> <mat-icon>edit</mat-icon></button>
<button mat-icon-button color="primary" (click)="sync(calendar)"><mat-icon>sync</mat-icon></button> <button mat-icon-button color="primary" (click)="sync(calendar)"><mat-icon>sync</mat-icon></button>
<button mat-icon-button color="warn" (click)="deleteCalendar(calendar)" i18n="@@buttonDelete"><mat-icon>delete</mat-icon></button> <button mat-icon-button color="warn" (click)="deleteCalendar(calendar)" i18n="@@buttonDelete"><mat-icon>delete</mat-icon></button>
</td> </td>

View File

@ -90,10 +90,10 @@ export class CalendarComponent implements OnInit {
console.log('Syncing calendars'); console.log('Syncing calendars');
} }
editImage(calendar: any): void { editCalendar(calendar: any): void {
const dialogRef = this.dialog.open(CreateCalendarComponent, { const dialogRef = this.dialog.open(CreateCalendarComponent, {
width: '700px', width: '700px',
data: calendar data: calendar['@id']
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
@ -103,28 +103,28 @@ export class CalendarComponent implements OnInit {
}); });
} }
deleteCalendar(role: any): void { deleteCalendar(calendar: any): void {
const dialogRef = this.dialog.open(DeleteModalComponent, { const dialogRef = this.dialog.open(DeleteModalComponent, {
width: '300px', width: '400px',
data: { name: role.name } data: { name: calendar.name }
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if (result) { if (result) {
const apiUrl = `${this.baseUrl}/remote-calendars/${role.uuid}`; const apiUrl = `${this.baseUrl}${calendar['@id']}`;
this.http.delete(apiUrl).subscribe({ this.http.delete(apiUrl).subscribe({
next: () => { next: () => {
console.log('Role deleted successfully'); console.log('Calendar deleted successfully');
this.search(); this.search();
this.toastService.success('Role deleted successfully'); this.toastService.success('Calendar deleted successfully');
}, },
error: (error) => { error: (error) => {
console.error('Error deleting role:', error); this.toastService.error('Error deleting calendar');
} }
}); });
} else { } else {
console.log('Role deletion cancelled'); console.log('calendar deletion cancelled');
} }
}); });
} }

View File

@ -16,8 +16,6 @@
} }
.checkbox-group { .checkbox-group {
display: flex;
flex-direction: column;
margin: 15px 0; margin: 15px 0;
align-items: flex-start; align-items: flex-start;
} }

View File

@ -4,11 +4,19 @@
<div *ngIf="!isRemoteAvailable" class="form-group"> <div *ngIf="!isRemoteAvailable" class="form-group">
<mat-label>Selecciona los días de la semana</mat-label> <mat-label>Selecciona los días de la semana</mat-label>
<div class="checkbox-group"> <div class="row">
<mat-checkbox *ngFor="let day of weekDays" [(ngModel)]="busyWeekDays[day]"> <div class="col-md-6 checkbox-group">
<mat-checkbox *ngFor="let day of weekDays.slice(0, (weekDays.length / 2) + 1)" [(ngModel)]="busyWeekDays[day]">
{{ day }} {{ day }}
</mat-checkbox> </mat-checkbox>
</div> </div>
<div class="col-md-6 checkbox-group ">
<mat-checkbox *ngFor="let day of weekDays.slice(weekDays.length / 2 + 1 )" [(ngModel)]="busyWeekDays[day]">
{{ day }}
</mat-checkbox>
</div>
</div>
<div class="time-fields"> <div class="time-fields">
<mat-form-field appearance="fill" class="time-field"> <mat-form-field appearance="fill" class="time-field">

View File

@ -30,7 +30,7 @@ export class CreateCalendarRuleComponent {
private toastService: ToastrService, private toastService: ToastrService,
private http: HttpClient, private http: HttpClient,
public dialogRef: MatDialogRef<CreateCalendarRuleComponent>, public dialogRef: MatDialogRef<CreateCalendarRuleComponent>,
@Inject(MAT_DIALOG_DATA) public data: any @Inject(MAT_DIALOG_DATA) public data: any,
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
@ -78,7 +78,7 @@ export class CreateCalendarRuleComponent {
remoteCalendar: this.calendarId, remoteCalendar: this.calendarId,
busyWeekDays: this.selectedDaysIndices, busyWeekDays: this.selectedDaysIndices,
busyFromHour: this.busyFromHour, busyFromHour: this.busyFromHour,
busyToHour: this.busyFromHour, busyToHour: this.busyToHour,
availableFromDate: this.availableFromDate, availableFromDate: this.availableFromDate,
availableToDate: this.availableToDate, availableToDate: this.availableToDate,
isRemoteAvailable: this.isRemoteAvailable, isRemoteAvailable: this.isRemoteAvailable,

View File

@ -1,15 +1,21 @@
<h2 mat-dialog-title>{{ isEditMode ? 'Editar' : 'Añadir' }} calendario</h2> <h2 mat-dialog-title>{{ isEditMode ? 'Editar' : 'Añadir' }} calendario</h2>
<mat-dialog-content class="form-container"> <mat-dialog-content class="form-container">
<button mat-flat-button color="primary" *ngIf="isEditMode" (click)="createRule()" style="padding: 10px;">Añadir regla</button>
<!-- Campo para el nombre --> <!-- Campo para el nombre -->
<mat-form-field appearance="fill" class="full-width"> <mat-form-field appearance="fill" class="full-width">
<mat-label>Nombre</mat-label> <mat-label>Nombre</mat-label>
<input matInput [(ngModel)]="name"> <input matInput [(ngModel)]="name" required>
<mat-icon *ngIf="isEditMode" matSuffix (click)="submitForm()">mode_edit</mat-icon>
</mat-form-field> </mat-form-field>
<div style="display: flex; justify-content: space-between; align-items: center;">
<div *ngIf="isEditMode" mat-subheader>Reglas</div>
<button mat-flat-button color="primary" *ngIf="isEditMode" (click)="createRule()" style="padding: 10px;">
Añadir regla
</button>
</div>
<div mat-subheader>Reglas</div> <mat-divider *ngIf="isEditMode"></mat-divider>
<mat-list>
<mat-list *ngIf="isEditMode">
<ng-container *ngFor="let rule of remoteCalendarRules;"> <ng-container *ngFor="let rule of remoteCalendarRules;">
<mat-list-item> <mat-list-item>
<div class="list-item-content"> <div class="list-item-content">
@ -23,7 +29,7 @@
<button mat-icon-button color="primary" class="right-icon" (click)="createRule(rule)" i18n="@@editImage"> <button mat-icon-button color="primary" class="right-icon" (click)="createRule(rule)" i18n="@@editImage">
<mat-icon>edit</mat-icon> <mat-icon>edit</mat-icon>
</button> </button>
<button mat-icon-button color="warn" class="right-icon" > <button mat-icon-button color="warn" class="right-icon" (click)="deleteCalendarRule(rule)" >
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
</button> </button>
</div> </div>
@ -35,5 +41,5 @@
<mat-dialog-actions align="end"> <mat-dialog-actions align="end">
<button mat-button (click)="onNoClick()">Cancelar</button> <button mat-button (click)="onNoClick()">Cancelar</button>
<button mat-button (click)="submitForm()" cdkFocusInitial>{{ isEditMode ? 'Guardar' : 'Añadir' }}</button> <button mat-button (click)="submitForm()" [disabled]="!name || name === ''" cdkFocusInitial> Guardar </button>
</mat-dialog-actions> </mat-dialog-actions>

View File

@ -3,6 +3,8 @@ import {ToastrService} from "ngx-toastr";
import {HttpClient} from "@angular/common/http"; import {HttpClient} from "@angular/common/http";
import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from "@angular/material/dialog"; import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from "@angular/material/dialog";
import {CreateCalendarRuleComponent} from "../create-calendar-rule/create-calendar-rule.component"; import {CreateCalendarRuleComponent} from "../create-calendar-rule/create-calendar-rule.component";
import {DataService} from "../data.service";
import {DeleteModalComponent} from "../../../shared/delete_modal/delete-modal/delete-modal.component";
@Component({ @Component({
selector: 'app-create-calendar', selector: 'app-create-calendar',
@ -22,17 +24,29 @@ export class CreateCalendarComponent implements OnInit {
public dialogRef: MatDialogRef<CreateCalendarComponent>, public dialogRef: MatDialogRef<CreateCalendarComponent>,
@Inject(MAT_DIALOG_DATA) public data: any, @Inject(MAT_DIALOG_DATA) public data: any,
public dialog: MatDialog, public dialog: MatDialog,
private dataService: DataService,
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
if (this.data) { if (this.data) {
this.isEditMode = true; this.load()
this.name = this.data.name;
this.remoteCalendarRules = this.data.remoteCalendarRules;
this.calendarId = this.data['@id']
} }
} }
load(): void {
this.dataService.getRemoteCalendar(this.data).subscribe({
next: (response) => {
this.isEditMode = true;
this.name = response.name;
this.remoteCalendarRules = response.remoteCalendarRules;
this.calendarId = this.data;
},
error: (err) => {
console.error('Error fetching remote calendar:', err);
}
});
}
onNoClick(): void { onNoClick(): void {
this.dialogRef.close(); this.dialogRef.close();
} }
@ -48,6 +62,7 @@ export class CreateCalendarComponent implements OnInit {
next: (response) => { next: (response) => {
this.toastService.success('Calendar updated successfully'); this.toastService.success('Calendar updated successfully');
this.dialogRef.close(true); this.dialogRef.close(true);
this.load()
}, },
error: (error) => { error: (error) => {
console.error('Error:', error); console.error('Error:', error);
@ -60,6 +75,7 @@ export class CreateCalendarComponent implements OnInit {
next: (response) => { next: (response) => {
this.toastService.success('Calendar created successfully'); this.toastService.success('Calendar created successfully');
this.dialogRef.close(true); this.dialogRef.close(true);
this.load()
}, },
error: (error) => { error: (error) => {
console.error('Error:', error); console.error('Error:', error);
@ -80,6 +96,32 @@ export class CreateCalendarComponent implements OnInit {
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if (result) { if (result) {
this.load()
}
});
}
deleteCalendarRule(rule: any): void {
const dialogRef = this.dialog.open(DeleteModalComponent, {
width: '400px',
});
dialogRef.afterClosed().subscribe(result => {
if (result) {
const apiUrl = `${this.baseUrl}${rule['@id']}`;
this.http.delete(apiUrl).subscribe({
next: () => {
console.log('Calendar deleted successfully');
this.load();
this.toastService.success('Calendar deleted successfully');
},
error: (error) => {
this.toastService.error('Error deleting calendar');
}
});
} else {
console.log('calendar deletion cancelled');
} }
}); });
} }

View File

@ -29,4 +29,20 @@ export class DataService {
}) })
); );
} }
getRemoteCalendar(id: string): Observable<any> {
return this.http.get<any>(`${this.baseUrl}${id}`).pipe(
map(response => {
if (response.name && response.remoteCalendarRules) {
return response;
} else {
throw new Error('Unexpected response format');
}
}),
catchError(error => {
console.error('Error fetching calendar', error);
return throwError(error);
})
);
}
} }