Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fix scheduler time label styling and translations (#2551)

Koenefb8b3682da8
diff --git a/ui/app/shared/locales/en/or.json b/ui/app/shared/locales/en/or.json
index 8d8f2db8d..9cf1bbea6 100644
--- a/ui/app/shared/locales/en/or.json
+++ b/ui/app/shared/locales/en/or.json
@@ -652,6 +652,37 @@
"type": "Schedule type"
},
"rrule": {
+ "and": "and",
+ "at": "at",
+ "day": "day",
+ "days": "days",
+ "every": "every",
+ "for": "for",
+ "hour": "hour",
+ "hours": "hours",
+ "in": "in",
+ "last": "last",
+ "minute": "minute",
+ "minutes": "minutes",
+ "month": "month",
+ "months": "months",
+ "nd": "nd",
+ "on": "on",
+ "on the": "on the",
+ "or": "or",
+ "rd": "rd",
+ "st": "st",
+ "th": "th",
+ "the": "the",
+ "time": "time",
+ "times": "times",
+ "until": "until",
+ "week": "week",
+ "weekday": "weekday",
+ "weekdays": "weekdays",
+ "weeks": "weeks",
+ "year": "year",
+ "years": "years",
"frequency": {
"YEARLY_one": "Year",
"YEARLY_other": "Years",
diff --git a/ui/app/shared/locales/nl/or.json b/ui/app/shared/locales/nl/or.json
index 5b805878e..447c0065f 100644
--- a/ui/app/shared/locales/nl/or.json
+++ b/ui/app/shared/locales/nl/or.json
@@ -649,6 +649,37 @@
"type": "Schema type"
},
"rrule": {
+ "and": "en",
+ "at": "om",
+ "day": "dag",
+ "days": "dagen",
+ "every": "elke",
+ "for": "voor",
+ "hour": "uur",
+ "hours": "uren",
+ "in": "in",
+ "last": "laatste",
+ "minute": "minuut",
+ "minutes": "minuten",
+ "month": "maand",
+ "months": "maanden",
+ "nd": "de",
+ "on": "op",
+ "on the": "op de",
+ "or": "of",
+ "rd": "de",
+ "st": "ste",
+ "th": "de",
+ "the": "de",
+ "time": "tijd",
+ "times": "tijden",
+ "until": "tot",
+ "week": "week",
+ "weekday": "weekdag",
+ "weekdays": "weekdagen",
+ "weeks": "weken",
+ "year": "jaar",
+ "years": "jaren",
"frequency": {
"YEARLY_one": "Jaar",
"YEARLY_other": "Jaren",
diff --git a/ui/component/or-rules/src/or-rule-viewer.ts b/ui/component/or-rules/src/or-rule-viewer.ts
index 043caf24b..34558f048 100644
--- a/ui/component/or-rules/src/or-rule-viewer.ts
+++ b/ui/component/or-rules/src/or-rule-viewer.ts
@@ -66,6 +66,7 @@ export const style = css`
or-scheduler {
margin-left: 10px;
margin-right: 20px;
+ max-width: 400px;
}
.wrapper {
diff --git a/ui/component/or-scheduler/src/index.ts b/ui/component/or-scheduler/src/index.ts
index 793fbd484..fea7914d3 100644
--- a/ui/component/or-scheduler/src/index.ts
+++ b/ui/component/or-scheduler/src/index.ts
@@ -64,16 +64,9 @@ function range(start: number, end: number): number[] {
return Array.from({ length: end - start + 1 }, (_, i) => start + i);
}
-// TODO: use es2023
-function toSpliced<T>(arr: T[], index: number, count: number): T[] {
- const shallowCopy = [...arr];
- shallowCopy.splice(index, count);
- return shallowCopy;
-}
-
-const byWeekNoOptions = toSpliced(range(-53, 53), 53, 1);
-const byYearDayOptions = toSpliced(range(-366, 366), 366, 1); // TODO: optimize option rendering
-const byMonthDayOptions = toSpliced(range(-31, 31), 31, 1);
+const byWeekNoOptions = range(-53, 53).filter(Boolean); // Exclude 0
+const byYearDayOptions = range(-366, 366).filter(Boolean);
+const byMonthDayOptions = range(-31, 31).filter(Boolean);
const byHourOptions = range(1, 24);
const byMinuteOrSecondsOptions = range(1, 60);
@@ -114,9 +107,15 @@ declare global {
@customElement("or-scheduler")
export class OrScheduler extends translate(i18next)(LitElement) {
static styles = css`
- .capitalize {
- display: inline-block;
- &::first-letter { text-transform: uppercase; }
+ .time-label {
+ display: flex;
+ &>:first-child {
+ display: inline-block;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ &::first-letter { text-transform: uppercase; }
+ }
}
`;
@@ -200,7 +199,12 @@ export class OrScheduler extends translate(i18next)(LitElement) {
} else if (diff === 0) {
template = html`<or-translate value="fromTo" .options="${fromTo}"></or-translate>`;
}
- return html`<span class="capitalize">${this._rrule!.toText()} ${template}</span>`;
+ const fromToTemplate = html`<span>&nbsp;${template}</span>`;
+ const monthNames = Object.values(MONTHS).map(i18next.t) as string[];
+ const orderISO = Object.values(WEEKDAYS).map(i18next.t) as string[];
+ const dayNames = [orderISO.pop()!, ...orderISO]; // Must start with Sunday
+ const rule = this._rrule!.toText((id) => i18next.t(`rrule.${id}`), { dayNames, monthNames, tokens: {} });
+ return html`<span class="time-label"><span>${rule}</span>${fromToTemplate}</span>`;
}
const format = this.isAllDay ? "DD-MM-YYYY" : "DD-MM-YYYY HH:mm";
@@ -374,20 +378,22 @@ export class OrScheduler extends translate(i18next)(LitElement) {
protected _applyTimezoneOffset(schedule: CalendarEvent | undefined, offset: number): CalendarEvent | undefined {
if (schedule) {
let { start, end, recurrence } = { ...schedule };
- if (start) start += offset;
- if (end) end += offset;
if (recurrence && RRule.fromString(recurrence).origOptions.until) {
const origOptions = RRule.fromString(recurrence).origOptions;
origOptions.until = new Date(Number(origOptions.until) + offset)
recurrence = this._getRRule(new RRule(origOptions))
}
- return { start, end, recurrence }
+ return {
+ start: start != null ? start + offset : start,
+ end: end != null ? end + offset : end,
+ recurrence
+ }
}
}
protected render() {
return html`
- <or-vaadin-button @click="${() => this._dialog!.open()}">${this._timeLabel}</or-vaadin-button>
+ <or-vaadin-button style="max-width: 100%" @click="${() => this._dialog!.open()}">${this._timeLabel}</or-vaadin-button>
<or-vaadin-dialog id="scheduler" header-title="${i18next.t(this.header)}" ?opened="${this.open}" @closed="${this._onClose}"
${dialogHeaderRenderer(this._getDialogHeader, [])}
${dialogRenderer(this._getDialogContent, [