2020-10-02 19:00:24 +02:00
|
|
|
/**
|
|
|
|
* A single opening hours range, shown on top of the OH-picker table
|
|
|
|
*/
|
2021-01-02 16:04:16 +01:00
|
|
|
import Svg from "../../Svg";
|
|
|
|
import {Utils} from "../../Utils";
|
|
|
|
import Combine from "../Base/Combine";
|
|
|
|
import {OH, OpeningHour} from "./OpeningHours";
|
2021-06-10 14:05:26 +02:00
|
|
|
import BaseUIElement from "../BaseUIElement";
|
2021-06-16 14:23:53 +02:00
|
|
|
import {FixedUiElement} from "../Base/FixedUiElement";
|
2021-01-02 16:04:16 +01:00
|
|
|
|
2021-06-16 14:23:53 +02:00
|
|
|
export default class OpeningHoursRange extends BaseUIElement {
|
|
|
|
private _oh: OpeningHour;
|
2020-10-04 01:04:46 +02:00
|
|
|
|
2021-06-16 14:23:53 +02:00
|
|
|
private readonly _onDelete: () => void;
|
2020-10-04 01:04:46 +02:00
|
|
|
|
2021-06-16 14:23:53 +02:00
|
|
|
constructor(oh: OpeningHour, onDelete: () => void) {
|
|
|
|
super();
|
2020-10-04 01:04:46 +02:00
|
|
|
this._oh = oh;
|
2021-06-16 14:23:53 +02:00
|
|
|
this._onDelete = onDelete;
|
2020-10-04 01:04:46 +02:00
|
|
|
this.SetClass("oh-timerange");
|
|
|
|
|
2021-06-16 14:23:53 +02:00
|
|
|
}
|
2020-10-04 01:04:46 +02:00
|
|
|
|
2021-06-16 14:23:53 +02:00
|
|
|
InnerConstructElement(): HTMLElement {
|
|
|
|
const height = this.getHeight();
|
|
|
|
const oh = this._oh;
|
|
|
|
const startTime = new FixedUiElement(Utils.TwoDigits(oh.startHour) + ":" + Utils.TwoDigits(oh.startMinutes)).SetClass("oh-timerange-label")
|
|
|
|
const endTime = new FixedUiElement(Utils.TwoDigits(oh.endHour) + ":" + Utils.TwoDigits(oh.endMinutes)).SetClass("oh-timerange-label")
|
2020-10-04 01:04:46 +02:00
|
|
|
|
2020-10-02 19:00:24 +02:00
|
|
|
|
2021-06-16 14:23:53 +02:00
|
|
|
const deleteRange =
|
|
|
|
Svg.delete_icon_ui()
|
|
|
|
.SetClass("oh-delete-range")
|
|
|
|
.onClick(() => {
|
|
|
|
this._onDelete()
|
|
|
|
});
|
2020-10-04 01:04:46 +02:00
|
|
|
|
2020-10-08 19:03:00 +02:00
|
|
|
|
2021-06-16 14:23:53 +02:00
|
|
|
let content = [deleteRange]
|
2020-10-08 19:03:00 +02:00
|
|
|
if (height > 2) {
|
2021-06-16 14:23:53 +02:00
|
|
|
content = [startTime, deleteRange, endTime];
|
2020-10-08 19:03:00 +02:00
|
|
|
}
|
|
|
|
|
2021-06-16 14:23:53 +02:00
|
|
|
const el = new Combine(content)
|
|
|
|
.SetClass("oh-timerange-inner").ConstructElement();
|
|
|
|
|
|
|
|
el.style.top = (100 * OH.startTime(oh) / 24) + "%"
|
|
|
|
el.style.height = (100 * (OH.endTime(oh) - OH.startTime(oh)) / 24) + "%"
|
|
|
|
return el;
|
2020-10-02 19:00:24 +02:00
|
|
|
}
|
|
|
|
|
2021-06-16 14:23:53 +02:00
|
|
|
|
2020-10-04 01:04:46 +02:00
|
|
|
private getHeight(): number {
|
2021-06-16 14:23:53 +02:00
|
|
|
const oh = this._oh;
|
2020-10-04 01:04:46 +02:00
|
|
|
|
|
|
|
let endhour = oh.endHour;
|
|
|
|
if (oh.endHour == 0 && oh.endMinutes == 0) {
|
|
|
|
endhour = 24;
|
|
|
|
}
|
2021-06-10 14:05:26 +02:00
|
|
|
return (endhour - oh.startHour + ((oh.endMinutes - oh.startMinutes) / 60));
|
2020-10-04 01:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-02 19:00:24 +02:00
|
|
|
}
|