@dizmo/dcs-client-library 4.2.1 → 4.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { language } from "../modules/language";
|
|
7
7
|
import { HumanizeDurationLanguage, HumanizeDuration, } from "humanize-duration-ts";
|
|
8
8
|
import { AllocationMode } from "../types/types";
|
|
9
|
+
import { t } from "./componentTranslations";
|
|
9
10
|
import "./itemElement";
|
|
10
11
|
class AllocationElement extends HTMLElement {
|
|
11
12
|
constructor() {
|
|
@@ -78,11 +79,11 @@ class AllocationElement extends HTMLElement {
|
|
|
78
79
|
: "";
|
|
79
80
|
const infoRows = this.buildInfoRows([
|
|
80
81
|
{
|
|
81
|
-
label:
|
|
82
|
+
label: t("js_from"),
|
|
82
83
|
value: from ? getReadableTime(parseInt(from)) : "",
|
|
83
84
|
},
|
|
84
85
|
{
|
|
85
|
-
label:
|
|
86
|
+
label: t("js_to"),
|
|
86
87
|
value: to ? getReadableTime(parseInt(to)) : "",
|
|
87
88
|
},
|
|
88
89
|
]);
|
|
@@ -127,20 +128,20 @@ class AllocationElement extends HTMLElement {
|
|
|
127
128
|
const duration = this.getAttribute("duration");
|
|
128
129
|
const infoRows = this.buildInfoRows([
|
|
129
130
|
{
|
|
130
|
-
label:
|
|
131
|
+
label: t("js_start"),
|
|
131
132
|
value: item.template
|
|
132
133
|
? formatStartOffset(startOffset, humanizer, LANG)
|
|
133
134
|
: "",
|
|
134
135
|
},
|
|
135
136
|
{
|
|
136
|
-
label:
|
|
137
|
+
label: t("js_duration"),
|
|
137
138
|
value: item.template ? formatDuration(duration, humanizer, LANG) : "",
|
|
138
139
|
},
|
|
139
140
|
]);
|
|
140
141
|
this.shadowRoot.innerHTML = `
|
|
141
142
|
<style>${this.getStyles()}</style>
|
|
142
143
|
<div class="container">
|
|
143
|
-
${this.buildItemElement(item)}
|
|
144
|
+
${this.buildItemElement(item, {}, this.getAttribute("leafType") || "resource")}
|
|
144
145
|
<div class="info-section">${infoRows}</div>
|
|
145
146
|
</div>
|
|
146
147
|
`;
|
|
@@ -172,6 +173,7 @@ class AllocationElement extends HTMLElement {
|
|
|
172
173
|
.info-row {
|
|
173
174
|
display: flex;
|
|
174
175
|
flex-direction: row;
|
|
176
|
+
justify-content: space-between;
|
|
175
177
|
}
|
|
176
178
|
.info-label {
|
|
177
179
|
width: 80px;
|
|
@@ -195,7 +197,7 @@ const formatStartOffset = (startOffset, humanizer, lang) => {
|
|
|
195
197
|
return "";
|
|
196
198
|
const offset = parseInt(startOffset);
|
|
197
199
|
if (offset === 0) {
|
|
198
|
-
return
|
|
200
|
+
return t("js_at-start");
|
|
199
201
|
}
|
|
200
202
|
return ("+" +
|
|
201
203
|
humanizer.humanize(offset, {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function t(key: string): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getMostSuitedLanguage } from "../helper/language.js";
|
|
2
|
+
const translations = {
|
|
3
|
+
en: {
|
|
4
|
+
js_from: "From",
|
|
5
|
+
js_to: "To",
|
|
6
|
+
js_start: "Start",
|
|
7
|
+
js_duration: "Duration",
|
|
8
|
+
"js_at-start": "At start",
|
|
9
|
+
need_suffix: "Need",
|
|
10
|
+
},
|
|
11
|
+
de: {
|
|
12
|
+
js_from: "Von",
|
|
13
|
+
js_to: "Bis",
|
|
14
|
+
js_start: "Start",
|
|
15
|
+
js_duration: "Dauer",
|
|
16
|
+
"js_at-start": "Am Anfang",
|
|
17
|
+
need_suffix: "Bedarf",
|
|
18
|
+
},
|
|
19
|
+
fr: {
|
|
20
|
+
js_from: "De",
|
|
21
|
+
js_to: "À",
|
|
22
|
+
js_start: "Début",
|
|
23
|
+
js_duration: "Durée",
|
|
24
|
+
"js_at-start": "Au début",
|
|
25
|
+
need_suffix: "Besoin",
|
|
26
|
+
},
|
|
27
|
+
it: {
|
|
28
|
+
js_from: "Da",
|
|
29
|
+
js_to: "A",
|
|
30
|
+
js_start: "Inizio",
|
|
31
|
+
js_duration: "Durata",
|
|
32
|
+
"js_at-start": "All'inizio",
|
|
33
|
+
need_suffix: "Fabbisogno",
|
|
34
|
+
},
|
|
35
|
+
es: {
|
|
36
|
+
js_from: "De",
|
|
37
|
+
js_to: "A",
|
|
38
|
+
js_start: "Inicio",
|
|
39
|
+
js_duration: "Duración",
|
|
40
|
+
"js_at-start": "Al inicio",
|
|
41
|
+
need_suffix: "Necesidad",
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const supportedLanguages = Object.keys(translations);
|
|
45
|
+
export function t(key) {
|
|
46
|
+
const lang = getMostSuitedLanguage(supportedLanguages, "en");
|
|
47
|
+
return translations[lang]?.[key] ?? translations["en"][key] ?? key;
|
|
48
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// Shared web component that can display resource, package, need, and event items.
|
|
2
2
|
import { ItemType } from "../types/types";
|
|
3
|
+
import { t } from "./componentTranslations";
|
|
4
|
+
const packageIconLight = `data:image/svg+xml,${encodeURIComponent('<svg width="27.5" height="27.5" xmlns="http://www.w3.org/2000/svg" xml:space="preserve"><path d="m4.42,22.06l0,-6.22l3.11,0l0,6.22l-3.11,0zm5.18,-6.22l0,-5.18l3.11,0l0,5.18l-3.11,0zm5.18,-5.18l0,-5.18l3.11,0l0,5.18l-3.11,0zm5.18,11.41l0,-16.59l3.11,0l0,16.59l-3.11,0z" fill="#424142" transform="rotate(-90.2178 13.7484 13.7683)"/></svg>')}`;
|
|
5
|
+
const packageIconDark = `data:image/svg+xml,${encodeURIComponent('<svg width="27.5" height="27.5" xmlns="http://www.w3.org/2000/svg" xml:space="preserve"><path d="m4.42,22.06l0,-6.22l3.11,0l0,6.22l-3.11,0zm5.18,-6.22l0,-5.18l3.11,0l0,5.18l-3.11,0zm5.18,-5.18l0,-5.18l3.11,0l0,5.18l-3.11,0zm5.18,11.41l0,-16.59l3.11,0l0,16.59l-3.11,0z" fill="#ffffff" transform="rotate(-90.2178 13.7484 13.7683)"/></svg>')}`;
|
|
6
|
+
const needBadgeIcon = `data:image/svg+xml,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M477.28-240q21.96 0 37.3-15.34 15.33-15.33 15.33-37.32 0-21.99-15.33-37.18-15.34-15.18-37.3-15.18-21.95 0-37.29 15.18-15.34 15.19-15.34 37.18 0 21.99 15.34 37.32Q455.33-240 477.28-240ZM483.28-646.98q23.07 0 40.15 14.91 17.07 14.91 17.07 37.27 0 20.8-12.66 37.08-12.67 16.29-28.71 30.33-23 20-40.62 44.24-17.62 24.24-17.62 54.24 0 14.81 11.15 24.86Q463.2-394 478.07-394q15.93 0 27.15-10.6 11.21-10.6 15.17-26.31 4.48-20.05 17.64-35.71 13.17-15.66 28.45-29.95 23-21.76 39.02-48.11 16.02-26.36 16.02-58.12 0-51.48-41.14-84.58t-95.9-33.1q-38.96 0-73.82 16.48-34.86 16.48-53.81 49.96-7.48 12.71-4.76 27.16 2.73 14.45 14.71 21.95 14.72 8.71 30.8 5.35 16.07-3.35 27.03-17.83 10.52-14.05 26.09-21.81 15.58-7.76 32.56-7.76Z"/></svg>')}`;
|
|
3
7
|
class ItemElement extends HTMLElement {
|
|
4
8
|
constructor() {
|
|
5
9
|
super();
|
|
@@ -36,7 +40,7 @@ class ItemElement extends HTMLElement {
|
|
|
36
40
|
const showLeftImage = itemType === ItemType.Resource && (imgUrl || iconUrl);
|
|
37
41
|
// Resources and needs show secondline, events show formatted date
|
|
38
42
|
const displaySecondLine = itemType === ItemType.Need && secondline
|
|
39
|
-
? `${secondline}
|
|
43
|
+
? `${secondline} ${t("need_suffix")}`
|
|
40
44
|
: secondline;
|
|
41
45
|
const showSecondLine = (itemType === ItemType.Resource || itemType === ItemType.Need) &&
|
|
42
46
|
displaySecondLine;
|
|
@@ -115,6 +119,23 @@ class ItemElement extends HTMLElement {
|
|
|
115
119
|
.invert {
|
|
116
120
|
filter: invert(1);
|
|
117
121
|
}
|
|
122
|
+
.need-badge {
|
|
123
|
+
position: absolute;
|
|
124
|
+
bottom: -3px;
|
|
125
|
+
right: -3px;
|
|
126
|
+
width: 16px;
|
|
127
|
+
height: 16px;
|
|
128
|
+
border-radius: 50%;
|
|
129
|
+
display: flex;
|
|
130
|
+
justify-content: center;
|
|
131
|
+
align-items: center;
|
|
132
|
+
pointer-events: none;
|
|
133
|
+
overflow: hidden;
|
|
134
|
+
}
|
|
135
|
+
.need-badge img {
|
|
136
|
+
width: 100%;
|
|
137
|
+
height: 100%;
|
|
138
|
+
}
|
|
118
139
|
</style>
|
|
119
140
|
<div class="item">
|
|
120
141
|
${showLeftImage
|
|
@@ -131,7 +152,8 @@ class ItemElement extends HTMLElement {
|
|
|
131
152
|
</div>
|
|
132
153
|
<button class="item_button not-invert" id="open-item-btn" itemid="${itemId}"
|
|
133
154
|
template="${template}" icolor="${color}"${color ? ` style="background-color: ${color} !important"` : ""}>
|
|
134
|
-
<img class="item_button-image${invertIcon(color)}" loading="lazy" src="${iconUrl}" />
|
|
155
|
+
<img class="item_button-image${iconUrl ? invertIcon(color) : ""}" loading="lazy" src="${iconUrl || getDefaultIcon(itemType, color)}" />
|
|
156
|
+
${itemType === ItemType.Need ? `<div class="need-badge" style="background-color: ${isIconInverted(color) ? "#ffffff" : "#000000"};"><img src="${needBadgeIcon}" style="${isIconInverted(color) ? "" : "filter: invert(1);"}"></div>` : ""}
|
|
135
157
|
</button>
|
|
136
158
|
</div>
|
|
137
159
|
`;
|
|
@@ -154,6 +176,14 @@ const formatDateToLocale = (dateString) => {
|
|
|
154
176
|
return dateString;
|
|
155
177
|
}
|
|
156
178
|
};
|
|
179
|
+
const getDefaultIcon = (itemType, color) => {
|
|
180
|
+
if (itemType === ItemType.Package) {
|
|
181
|
+
const isInverted = invertIcon(color) === " invert";
|
|
182
|
+
return isInverted ? packageIconDark : packageIconLight;
|
|
183
|
+
}
|
|
184
|
+
return "";
|
|
185
|
+
};
|
|
186
|
+
const isIconInverted = (color) => invertIcon(color) === " invert";
|
|
157
187
|
const invertIcon = (backgroundColor) => {
|
|
158
188
|
if (!backgroundColor ||
|
|
159
189
|
backgroundColor === "transparent" ||
|
package/dist/types/types.d.ts
CHANGED