ScheduleEntry position

This commit is contained in:
Patrick Haßel 2022-10-25 14:04:46 +02:00
parent db79d17f7d
commit 7bd2e2f93d
6 changed files with 42 additions and 17 deletions

View File

@ -17,7 +17,7 @@ export class Schedule {
validateNumberNotNull(json['id']),
validateBooleanNotNull(json['enabled']),
validateStringNotEmptyNotNull(json['title']),
validateListOrEmpty(json['entries'], ScheduleEntry.fromJson, ScheduleEntry.compare),
validateListOrEmpty(json['entries'], ScheduleEntry.fromJson, ScheduleEntry.comparePosition),
);
}
@ -25,10 +25,6 @@ export class Schedule {
return item.id;
}
public static compareId(a: Schedule, b: Schedule): number {
return a.id - b.id;
}
public static compareName(a: Schedule, b: Schedule): number {
return a.title.localeCompare(b.title);
}

View File

@ -11,6 +11,7 @@ export class ScheduleEntry {
private constructor(
public id: number,
public position: number,
public enabled: boolean,
public monday: boolean,
public tuesday: boolean,
@ -38,6 +39,7 @@ export class ScheduleEntry {
static fromJson(json: any): ScheduleEntry {
return new ScheduleEntry(
validateNumberNotNull(json['id']),
validateNumberNotNull(json['position']),
validateBooleanNotNull(json['enabled']),
validateBooleanNotNull(json['monday']),
validateBooleanNotNull(json['tuesday']),
@ -65,13 +67,8 @@ export class ScheduleEntry {
return item.id;
}
public static compare(a: ScheduleEntry, b: ScheduleEntry): number {
if (a.nextFuzzyTimestamp === null) {
return +1;
} else if (b.nextFuzzyTimestamp === null) {
return -1;
}
return getDaySeconds(a.nextFuzzyTimestamp.date) - getDaySeconds(b.nextFuzzyTimestamp.date);
public static comparePosition(a: ScheduleEntry, b: ScheduleEntry): number {
return a.position - b.position;
}
}

View File

@ -30,9 +30,11 @@
<th colspan="6">Nächste Ausführung</th>
<th colspan="2">Eingeschaft setzen</th>
<th>Massenverarbeitung</th>
<th>&nbsp;</th>
<th class="noBorderFirst">&nbsp;</th>
<th class="noBorderMiddle">&nbsp;</th>
<th class="noBorderLast">&nbsp;</th>
</tr>
<tr *ngFor="let entry of schedule.entries" [class.disabled]="entry.nextClearTimestamp === null">
<tr *ngFor="let entry of schedule.entries; trackBy: ScheduleEntry.trackBy" [class.disabled]="entry.nextClearTimestamp === null">
<ng-container *ngTemplateOutlet="boolean;context:{entry: entry, value: entry.enabled, key:'enabled'}"></ng-container>
<ng-container *ngTemplateOutlet="boolean;context:{entry: entry, value: entry.monday, key:'monday'}"></ng-container>
<ng-container *ngTemplateOutlet="boolean;context:{entry: entry, value: entry.tuesday, key:'tuesday'}"></ng-container>
@ -173,8 +175,16 @@
<app-search [searchService]="bulkService" [initial]="entry.bulk?.id" (valueChange)="set(entry, 'bulk', $event)"></app-search>
</td>
<td class="delete" (click)="delete(entry)">
<fa-icon title="Löschen" [icon]="faTimes"></fa-icon>
<td class="delete noBorderFirst" (click)="delete(entry)">
<fa-icon [icon]="faTimes"></fa-icon>
</td>
<td class="noBorderMiddle" (click)="set(entry, 'position', entry.position - 1)">
<fa-icon *ngIf="entry.position > 0" [icon]="faUp"></fa-icon>
</td>
<td class="noBorderLast" (click)="set(entry, 'position', entry.position + 1)">
<fa-icon *ngIf="entry.position < schedule.entries.length - 1" [icon]="faDown"></fa-icon>
</td>
</tr>

View File

@ -3,7 +3,7 @@ import {ScheduleService} from "../../../api/schedule/schedule.service";
import {Schedule} from "../../../api/schedule/Schedule";
import {ScheduleEntry} from "../../../api/schedule/entry/ScheduleEntry";
import {ScheduleEntryService} from "../../../api/schedule/entry/schedule-entry.service";
import {faCheckCircle, faCircle, faTimesCircle} from '@fortawesome/free-regular-svg-icons';
import {faArrowAltCircleDown, faArrowAltCircleUp, faCheckCircle, faCircle, faTimesCircle} from '@fortawesome/free-regular-svg-icons';
import {ActivatedRoute, Router} from "@angular/router";
import {PropertyService} from "../../../api/property/property.service";
import {Scene} from "../../../api/scene/Scene";
@ -19,12 +19,18 @@ import {NO_OP} from "../../../api/api.service";
})
export class ScheduleEditorComponent implements OnInit {
readonly ScheduleEntry = ScheduleEntry;
readonly faCheckCircle = faCheckCircle;
readonly faCircle = faCircle;
readonly faTimes = faTimesCircle;
readonly faUp = faArrowAltCircleUp;
readonly faDown = faArrowAltCircleDown;
readonly Schedule = Schedule;
schedule!: Schedule;

View File

@ -79,6 +79,19 @@ table.vertical {
padding: 0;
}
.noBorderFirst {
border-right-width: 0;
}
.noBorderMiddle {
border-right-width: 0;
border-left-width: 0;
}
.noBorderLast {
border-left-width: 0;
}
.first {
border-right-width: 0;
padding-right: 0;

View File

@ -12,6 +12,8 @@ public class ScheduleEntryDto implements Serializable {
public final long id;
public final int position;
public final boolean enabled;
public final boolean monday;
@ -54,6 +56,7 @@ public class ScheduleEntryDto implements Serializable {
public ScheduleEntryDto(final ScheduleEntry entry, final PropertyDto property, final BulkDto bulk) {
this.id = entry.getId();
this.position = entry.getPosition();
this.enabled = entry.isEnabled();
this.monday = entry.isMonday();
this.tuesday = entry.isTuesday();