@7365admin1/layer-common 4.97.1-staging.662 → 4.97.1-staging.664

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.
@@ -34,12 +34,31 @@
34
34
  <AppField :model-value="orderNumberPreview" label="Preview" readonly />
35
35
  </div>
36
36
 
37
+ <!-- Service365 (resident) app, per site and service (DV-1002). Inventory stores keep
38
+ their own switches for materials recorded straight to a unit. -->
39
+ <v-divider class="my-4" />
40
+ <div class="text-subtitle-1 mb-1">Service365 app</div>
41
+ <p class="text-body-2 text-medium-emphasis mb-2">
42
+ Let residents and tenants see the materials used in their own unit (item, quantity, date and work order).
43
+ </p>
44
+ <v-switch v-model="showMaterialsInResidentApp" color="primary" hide-details
45
+ :disabled="isLoading || !canManageSiteSettings"
46
+ label="Show materials used in the Service365 app" />
47
+ <v-switch v-model="showMaterialCostInResidentApp" color="primary" hide-details
48
+ :disabled="isLoading || !canManageSiteSettings || !showMaterialsInResidentApp"
49
+ label="Also show the cost" />
50
+
37
51
  <!-- Still a `v-btn`: `AppButton` has no loading state, and the
38
52
  spinner on save is feedback, not decoration. -->
39
53
  <v-btn v-if="canManageSiteSettings" class="screen-btn-primary text-none mt-4"
40
54
  variant="flat" :loading="isLoading" @click="save">
41
55
  Save
42
56
  </v-btn>
57
+
58
+ <!-- Opt-in per app (web M&E first): the site's own subjects. -->
59
+ <WorkOrderSubjectsSettings v-if="showSubjects" class="mt-8" :site-id="siteId"
60
+ :service="service" :organization="organization"
61
+ :can-manage="canManageSiteSettings" :number-preview="orderNumberPreview" />
43
62
  </v-expansion-panel-text>
44
63
  </v-expansion-panel>
45
64
 
@@ -54,7 +73,11 @@
54
73
  const props = defineProps({
55
74
  siteId: { type: String, required: true },
56
75
  canManageSiteSettings: { type: Boolean, default: false },
57
- service: { type: String, required: true }
76
+ service: { type: String, required: true },
77
+ // Work Order Settings > Subjects (added subjects with prefix and preset titles).
78
+ showSubjects: { type: Boolean, default: false },
79
+ // The organisation adding the subjects (the one in the address).
80
+ organization: { type: String, default: "" }
58
81
  })
59
82
 
60
83
  const openPanels = ref([0]) // default open first
@@ -81,6 +104,9 @@ const uploadedSiteLogo = ref("")
81
104
 
82
105
  const prefix = ref("")
83
106
  const noOfDigits = ref(1)
107
+ /** Service365 (resident) app switches; missing on a saved setting = off. */
108
+ const showMaterialsInResidentApp = ref(false)
109
+ const showMaterialCostInResidentApp = ref(false)
84
110
  const isLoading = ref(false)
85
111
 
86
112
  const toast = reactive({
@@ -154,6 +180,8 @@ watchEffect(() => {
154
180
  if (workOrderSetting.value) {
155
181
  prefix.value = workOrderSetting.value.prefix
156
182
  noOfDigits.value = workOrderSetting.value.noOfDigits
183
+ showMaterialsInResidentApp.value = !!workOrderSetting.value.showMaterialsInResidentApp
184
+ showMaterialCostInResidentApp.value = !!workOrderSetting.value.showMaterialCostInResidentApp
157
185
  }
158
186
  })
159
187
 
@@ -178,7 +206,10 @@ async function save() {
178
206
  site: props.siteId,
179
207
  service: props.service,
180
208
  prefix: prefix.value,
181
- noOfDigits: noOfDigits.value
209
+ noOfDigits: noOfDigits.value,
210
+ showMaterialsInResidentApp: showMaterialsInResidentApp.value,
211
+ // Cost only shows with the materials.
212
+ showMaterialCostInResidentApp: showMaterialsInResidentApp.value && showMaterialCostInResidentApp.value
182
213
  })
183
214
  show("Saved successfully", "success")
184
215
  } catch {
@@ -0,0 +1,151 @@
1
+ <!--
2
+ An added subject's preset titles on one line: as many chips as fit the
3
+ width ("No Power", "Warm", "Faulty"), then a "+3" button that opens the rest.
4
+ Re-measured whenever the cell is resized.
5
+ -->
6
+ <template>
7
+ <div ref="wrap" class="preset-chips">
8
+ <span v-if="!titles.length" class="preset-chips__none">—</span>
9
+
10
+ <template v-else>
11
+ <v-chip
12
+ v-for="title in shown"
13
+ :key="title"
14
+ size="small"
15
+ variant="tonal"
16
+ class="preset-chips__chip"
17
+ >
18
+ {{ title }}
19
+ </v-chip>
20
+
21
+ <v-menu v-if="hidden.length" location="bottom end" :close-on-content-click="false">
22
+ <template #activator="{ props: menu }">
23
+ <v-chip
24
+ v-bind="menu"
25
+ size="small"
26
+ variant="flat"
27
+ class="preset-chips__more"
28
+ :aria-label="`Show ${hidden.length} more preset titles`"
29
+ @click.stop
30
+ >
31
+ +{{ hidden.length }}
32
+ </v-chip>
33
+ </template>
34
+ <v-card class="preset-chips__menu pa-3">
35
+ <div class="preset-chips__menu-title mb-2">Preset titles</div>
36
+ <div class="d-flex flex-wrap ga-2">
37
+ <v-chip v-for="title in titles" :key="title" size="small" variant="tonal">
38
+ {{ title }}
39
+ </v-chip>
40
+ </div>
41
+ </v-card>
42
+ </v-menu>
43
+ </template>
44
+
45
+ <!-- Off-screen copies, measured to work out how many fit. -->
46
+ <div ref="measure" class="preset-chips__measure" aria-hidden="true">
47
+ <v-chip v-for="title in titles" :key="title" size="small" variant="tonal" class="preset-chips__chip">
48
+ {{ title }}
49
+ </v-chip>
50
+ <v-chip size="small" variant="flat" class="preset-chips__more">+{{ titles.length }}</v-chip>
51
+ </div>
52
+ </div>
53
+ </template>
54
+
55
+ <script setup lang="ts">
56
+ const props = defineProps({
57
+ titles: { type: Array as PropType<string[]>, default: () => [] },
58
+ });
59
+
60
+ const GAP = 6;
61
+ const wrap = ref<HTMLElement | null>(null);
62
+ const measure = ref<HTMLElement | null>(null);
63
+ const fit = ref(Number.POSITIVE_INFINITY);
64
+
65
+ const shown = computed(() => props.titles.slice(0, fit.value));
66
+ const hidden = computed(() => props.titles.slice(fit.value));
67
+
68
+ function remeasure() {
69
+ const box = wrap.value;
70
+ const copies = measure.value?.children;
71
+ if (!box || !copies || !props.titles.length) return;
72
+ const width = box.clientWidth;
73
+ const widths = Array.from(copies).map((el) => (el as HTMLElement).offsetWidth);
74
+ const moreWidth = widths.pop() ?? 0;
75
+ const total = widths.reduce((sum, w, i) => sum + w + (i ? GAP : 0), 0);
76
+ if (total <= width) {
77
+ fit.value = widths.length;
78
+ return;
79
+ }
80
+ // Leave room for the "+N" button; always show at least one title.
81
+ let used = 0;
82
+ let count = 0;
83
+ for (const w of widths) {
84
+ const next = used + (count ? GAP : 0) + w;
85
+ if (next + GAP + moreWidth > width) break;
86
+ used = next;
87
+ count += 1;
88
+ }
89
+ fit.value = Math.max(1, count);
90
+ }
91
+
92
+ let observer: ResizeObserver | null = null;
93
+ onMounted(() => {
94
+ nextTick(remeasure);
95
+ if (typeof ResizeObserver !== "undefined" && wrap.value) {
96
+ observer = new ResizeObserver(() => remeasure());
97
+ observer.observe(wrap.value);
98
+ }
99
+ });
100
+ onBeforeUnmount(() => observer?.disconnect());
101
+ watch(
102
+ () => props.titles.join("\u0000"),
103
+ () => nextTick(remeasure)
104
+ );
105
+ </script>
106
+
107
+ <style scoped>
108
+ .preset-chips {
109
+ position: relative;
110
+ display: flex;
111
+ align-items: center;
112
+ gap: 6px;
113
+ min-width: 0;
114
+ width: 100%;
115
+ overflow: hidden;
116
+ flex-wrap: nowrap;
117
+ }
118
+ .preset-chips__chip {
119
+ flex-shrink: 0;
120
+ }
121
+ .preset-chips__more {
122
+ flex-shrink: 0;
123
+ background: var(--text);
124
+ color: var(--card);
125
+ font-weight: 700;
126
+ cursor: pointer;
127
+ }
128
+ .preset-chips__none {
129
+ color: var(--muted);
130
+ }
131
+ .preset-chips__measure {
132
+ position: absolute;
133
+ visibility: hidden;
134
+ pointer-events: none;
135
+ display: flex;
136
+ gap: 6px;
137
+ white-space: nowrap;
138
+ left: 0;
139
+ top: 0;
140
+ }
141
+ .preset-chips__menu {
142
+ max-width: 320px;
143
+ }
144
+ .preset-chips__menu-title {
145
+ font-size: 12px;
146
+ font-weight: 700;
147
+ text-transform: uppercase;
148
+ letter-spacing: 0.04em;
149
+ color: var(--muted);
150
+ }
151
+ </style>
@@ -0,0 +1,652 @@
1
+ <!--
2
+ Work Order Settings > Subjects: the subjects this service adds at the site,
3
+ on top of the built-in list. Each has a prefix that goes before ("#AC-ME001")
4
+ or after ("#ME001-AC") the work order number, and the preset titles offered
5
+ under Subject once it is picked on Create Feedback / Create Work Order.
6
+ -->
7
+ <template>
8
+ <div class="wo-subjects">
9
+ <div class="wo-subjects__head">
10
+ <div>
11
+ <div class="wo-subjects__title">Subjects</div>
12
+ <div class="wo-subjects__hint">
13
+ Added to the built-in subjects on Create Feedback and Create Work Order. A subject's preset titles
14
+ are offered under Subject once it is picked.
15
+ </div>
16
+ </div>
17
+ <v-btn
18
+ v-if="canManage"
19
+ class="screen-btn-primary text-none"
20
+ variant="flat"
21
+ prepend-icon="mdi-plus"
22
+ @click="openCreate"
23
+ >
24
+ Add Subject
25
+ </v-btn>
26
+ </div>
27
+
28
+ <TableMain
29
+ :headers="headers"
30
+ :items="items"
31
+ :loading="loading"
32
+ :show-header="true"
33
+ v-model:page="page"
34
+ :pages="pages"
35
+ :page-range="pageRange"
36
+ :offset="420"
37
+ @refresh="load"
38
+ >
39
+ <template #item.prefix="{ item }">
40
+ <div v-if="item.prefix" class="wo-subjects__prefix">
41
+ <span class="wo-subjects__prefix-code">{{ item.prefix }}</span>
42
+ <span class="wo-subjects__prefix-sample">{{ sampleNumber(item) }}</span>
43
+ </div>
44
+ <span v-else class="wo-subjects__muted">—</span>
45
+ </template>
46
+
47
+ <template #item.presetTitles="{ item }">
48
+ <WorkOrderSubjectPresetChips :titles="item.presetTitles || []" />
49
+ </template>
50
+
51
+ <template #item.description="{ item }">
52
+ <span class="wo-subjects__desc">{{ item.description || "—" }}</span>
53
+ </template>
54
+
55
+ <template #item.actions="{ item }">
56
+ <div v-if="canManage" class="d-flex justify-end ga-1">
57
+ <v-btn
58
+ icon="mdi-square-edit-outline"
59
+ variant="text"
60
+ size="small"
61
+ :aria-label="`Edit ${item.subject}`"
62
+ @click.stop="openEdit(item)"
63
+ />
64
+ <v-btn
65
+ icon="mdi-trash-can-outline"
66
+ variant="text"
67
+ size="small"
68
+ :aria-label="`Delete ${item.subject}`"
69
+ @click.stop="askDelete(item)"
70
+ />
71
+ </div>
72
+ </template>
73
+
74
+ <template #no-data>
75
+ <div class="wo-subjects__empty">
76
+ <v-icon icon="mdi-format-list-bulleted-type" size="32" />
77
+ <span>No subjects added yet.</span>
78
+ </div>
79
+ </template>
80
+ </TableMain>
81
+
82
+ <!-- Add / Edit -->
83
+ <FormDialog v-model="formOpen" @close="closeForm">
84
+ <template #title>
85
+ <!-- Indented to the body's own left edge, so the title lines up with the fields. -->
86
+ <span class="wo-subjects__dialog-title">{{ editing ? "Edit Subject" : "Add Subject" }}</span>
87
+ </template>
88
+
89
+ <v-form ref="formRef" class="wo-subjects__form" @submit.prevent="save">
90
+ <!-- Subject -->
91
+ <div class="wo-subjects__field">
92
+ <InputLabel title="Subject" required />
93
+ <v-text-field
94
+ v-model="form.subject"
95
+ variant="outlined"
96
+ density="comfortable"
97
+ placeholder="e.g. Aircon"
98
+ hide-details="auto"
99
+ maxlength="100"
100
+ validate-on="blur"
101
+ :rules="[requiredRule, builtInRule]"
102
+ />
103
+ </div>
104
+
105
+ <!-- Prefix, and which side of the work order number it goes -->
106
+ <div class="wo-subjects__field">
107
+ <InputLabel title="Prefix" />
108
+ <v-text-field
109
+ v-model="form.prefix"
110
+ variant="outlined"
111
+ density="comfortable"
112
+ placeholder="e.g. AC"
113
+ hide-details
114
+ maxlength="10"
115
+ @update:model-value="onPrefixInput"
116
+ />
117
+ <div class="wo-subjects__help">Letters only. Leave empty for no prefix.</div>
118
+ </div>
119
+
120
+ <!-- Where the prefix goes: each choice shows the number it makes -->
121
+ <div class="wo-subjects__field">
122
+ <InputLabel title="Prefix Position" />
123
+ <div class="wo-subjects__positions" role="radiogroup" aria-label="Prefix position">
124
+ <button
125
+ v-for="option in positionOptions"
126
+ :key="option.value"
127
+ type="button"
128
+ role="radio"
129
+ class="wo-subjects__position"
130
+ :class="{ 'wo-subjects__position--on': form.prefixPosition === option.value }"
131
+ :aria-checked="form.prefixPosition === option.value"
132
+ @click="form.prefixPosition = option.value"
133
+ >
134
+ <span class="wo-subjects__position-head">
135
+ <v-icon
136
+ size="18"
137
+ :icon="form.prefixPosition === option.value ? 'mdi-radiobox-marked' : 'mdi-radiobox-blank'"
138
+ />
139
+ {{ option.label }}
140
+ </span>
141
+ <span class="wo-subjects__position-sample">{{ positionSample(option.value) }}</span>
142
+ </button>
143
+ </div>
144
+ </div>
145
+
146
+ <!-- The number as it will read, drawn like the settings' own Preview -->
147
+ <AppField :model-value="sampleNumber(form)" label="Preview" readonly />
148
+ <div v-if="!form.prefix" class="wo-subjects__help wo-subjects__help--tight">
149
+ No prefix yet: the number stays as it is.
150
+ </div>
151
+
152
+ <!-- Preset titles: typed, then added with the button (or Enter) -->
153
+ <div class="wo-subjects__field">
154
+ <InputLabel title="Preset Titles" />
155
+ <div class="wo-subjects__preset-row">
156
+ <v-text-field
157
+ v-model="presetSearch"
158
+ variant="outlined"
159
+ density="comfortable"
160
+ placeholder="e.g. No Power"
161
+ hide-details
162
+ maxlength="100"
163
+ @keydown.enter.prevent="addTypedPreset"
164
+ />
165
+ <v-btn
166
+ class="text-none wo-subjects__add-preset"
167
+ variant="flat"
168
+ color="primary"
169
+ height="48"
170
+ prepend-icon="mdi-plus"
171
+ :disabled="!presetSearch.trim()"
172
+ @click="addTypedPreset"
173
+ >
174
+ Add
175
+ </v-btn>
176
+ </div>
177
+ <div v-if="form.presetTitles.length" class="wo-subjects__preset-chips">
178
+ <v-chip
179
+ v-for="title in form.presetTitles"
180
+ :key="title"
181
+ size="small"
182
+ variant="tonal"
183
+ closable
184
+ :close-label="`Remove ${title}`"
185
+ @click:close="removePreset(title)"
186
+ >
187
+ {{ title }}
188
+ </v-chip>
189
+ </div>
190
+ <div v-else class="wo-subjects__help">Offered under Subject once this subject is picked.</div>
191
+ </div>
192
+
193
+ <!-- Description -->
194
+ <div class="wo-subjects__field">
195
+ <InputLabel title="Description" required />
196
+ <v-textarea
197
+ v-model="form.description"
198
+ variant="outlined"
199
+ density="comfortable"
200
+ placeholder="What this subject covers, e.g. aircon not cooling, leaking, noisy"
201
+ hide-details="auto"
202
+ auto-grow
203
+ rows="3"
204
+ maxlength="500"
205
+ validate-on="blur"
206
+ :rules="[requiredRule]"
207
+ />
208
+ <div class="wo-subjects__help">Shown under the subject in the Subject list on Create Feedback and Create Work Order.</div>
209
+ </div>
210
+ </v-form>
211
+
212
+ <template #footer>
213
+ <v-btn
214
+ class="text-capitalize screen-btn-primary"
215
+ variant="flat"
216
+ block
217
+ :loading="saving"
218
+ :disabled="saving || !form.subject.trim() || !form.description.trim()"
219
+ @click="save"
220
+ >
221
+ {{ editing ? "Save" : "Add Subject" }}
222
+ </v-btn>
223
+ </template>
224
+ </FormDialog>
225
+
226
+ <!-- Delete -->
227
+ <ConfirmDialog v-model="deleteOpen" :loading="deleting">
228
+ <template #title>Delete Subject</template>
229
+ <template #description>
230
+ Delete "{{ pendingDelete?.subject }}"? It will no longer be offered on new feedbacks and work orders.
231
+ Ones already raised keep it.
232
+ </template>
233
+ <template #footer>
234
+ <v-row no-gutters class="w-100">
235
+ <v-col cols="6" class="pr-2">
236
+ <v-btn block variant="outlined" class="text-none screen-btn-ghost" :disabled="deleting" @click="deleteOpen = false">
237
+ Cancel
238
+ </v-btn>
239
+ </v-col>
240
+ <v-col cols="6" class="pl-2">
241
+ <v-btn block variant="flat" color="error" class="text-none" :loading="deleting" @click="confirmDelete">
242
+ Delete
243
+ </v-btn>
244
+ </v-col>
245
+ </v-row>
246
+ </template>
247
+ </ConfirmDialog>
248
+
249
+ <Snackbar v-model="toast.show" :text="toast.message" :color="toast.color" />
250
+ </div>
251
+ </template>
252
+
253
+ <script setup lang="ts">
254
+ const props = defineProps({
255
+ siteId: { type: String, required: true },
256
+ /** The work-order-settings service these subjects belong to ("M&E", ...). */
257
+ service: { type: String, required: true },
258
+ /** The organisation adding them (the one in the address). */
259
+ organization: { type: String, default: "" },
260
+ canManage: { type: Boolean, default: false },
261
+ /** The work order number without a subject prefix ("ME0001"), for the samples. */
262
+ numberPreview: { type: String, default: "" },
263
+ });
264
+
265
+ const { getSubjects, createSubject, updateSubject, deleteSubject } = useWorkOrderSubject();
266
+ const { requiredRule } = useUtils();
267
+ /** The built-in subjects (as API-core refuses them): an added one may not reuse a name. */
268
+ const BUILT_IN = [
269
+ "Building Facade",
270
+ "Car Park",
271
+ "Cleaning",
272
+ "Facilities",
273
+ "Landscape",
274
+ "Lift",
275
+ "Pest Control",
276
+ "Security",
277
+ "Security Systems",
278
+ "Water Features",
279
+ "Others",
280
+ ].map((t) => t.toLowerCase());
281
+
282
+ const headers = [
283
+ { title: "Prefix", value: "prefix", align: "start", width: "140" },
284
+ { title: "Subject", value: "subject", align: "start" },
285
+ { title: "Preset Titles", value: "presetTitles", align: "start", width: "32%" },
286
+ { title: "Description", value: "description", align: "start" },
287
+ { title: "", value: "actions", align: "end", width: "110" },
288
+ ];
289
+
290
+ const positionOptions: Array<{ label: string; value: TWorkOrderSubjectPrefixPosition }> = [
291
+ { label: "Before", value: "before" },
292
+ { label: "After", value: "after" },
293
+ ];
294
+
295
+ /** What a position makes of the number: the typed prefix, or "AC" as the example until one is typed. */
296
+ function positionSample(position: TWorkOrderSubjectPrefixPosition) {
297
+ return sampleNumber({ prefix: form.prefix || "AC", prefixPosition: position });
298
+ }
299
+
300
+ const items = ref<TWorkOrderSubject[]>([]);
301
+ const loading = ref(false);
302
+ const page = ref(1);
303
+ const pages = ref(0);
304
+ const pageRange = ref("");
305
+
306
+ async function load() {
307
+ loading.value = true;
308
+ try {
309
+ const res = await getSubjects({
310
+ site: props.siteId,
311
+ service: props.service,
312
+ ...(props.organization ? { organization: props.organization } : {}),
313
+ page: page.value,
314
+ limit: 20,
315
+ });
316
+ items.value = res?.items ?? [];
317
+ pages.value = res?.pages ?? 0;
318
+ pageRange.value = res?.pageRange ?? "";
319
+ } catch (e: any) {
320
+ show(e?.data?.message || "Could not load the subjects.", "error");
321
+ } finally {
322
+ loading.value = false;
323
+ }
324
+ }
325
+
326
+ watch(page, load);
327
+ watch(() => [props.siteId, props.service, props.organization], () => {
328
+ page.value = 1;
329
+ load();
330
+ });
331
+ onMounted(load);
332
+
333
+ function sampleNumber(source: { prefix?: string; prefixPosition?: string }) {
334
+ const base = props.numberPreview || "0001";
335
+ return `#${withSubjectPrefix(base, { subjectPrefix: source.prefix, subjectPrefixPosition: source.prefixPosition })}`;
336
+ }
337
+
338
+ /* ---------------- Add / Edit ---------------- */
339
+
340
+ type TForm = {
341
+ subject: string;
342
+ prefix: string;
343
+ prefixPosition: TWorkOrderSubjectPrefixPosition;
344
+ presetTitles: string[];
345
+ description: string;
346
+ };
347
+ const blankForm = (): TForm => ({ subject: "", prefix: "", prefixPosition: "before", presetTitles: [], description: "" });
348
+
349
+ const formOpen = ref(false);
350
+ const formRef = ref<any>(null);
351
+ const editing = ref<TWorkOrderSubject | null>(null);
352
+ const form = reactive<TForm>(blankForm());
353
+ const presetSearch = ref("");
354
+ const saving = ref(false);
355
+
356
+ const builtInRule = (v: string) =>
357
+ !BUILT_IN.includes(String(v ?? "").trim().toLowerCase()) || "This is already a built-in subject.";
358
+
359
+ function openCreate() {
360
+ editing.value = null;
361
+ Object.assign(form, blankForm());
362
+ formOpen.value = true;
363
+ }
364
+
365
+ function openEdit(item: TWorkOrderSubject) {
366
+ editing.value = item;
367
+ Object.assign(form, {
368
+ subject: item.subject ?? "",
369
+ prefix: item.prefix ?? "",
370
+ prefixPosition: item.prefixPosition === "after" ? "after" : "before",
371
+ presetTitles: [...(item.presetTitles ?? [])],
372
+ description: item.description ?? "",
373
+ });
374
+ formOpen.value = true;
375
+ }
376
+
377
+ function closeForm() {
378
+ formOpen.value = false;
379
+ presetSearch.value = "";
380
+ }
381
+
382
+ function onPrefixInput(value: string) {
383
+ form.prefix = String(value ?? "").toUpperCase().replace(/[^A-Z]/g, "");
384
+ }
385
+
386
+ /** Trimmed, no blanks, no repeats (any case). */
387
+ function tidyPresets(values: string[]) {
388
+ const seen = new Set<string>();
389
+ form.presetTitles = (values ?? [])
390
+ .map((v) => String(v ?? "").trim())
391
+ .filter((v) => v && !seen.has(v.toLowerCase()) && seen.add(v.toLowerCase()));
392
+ }
393
+
394
+ function removePreset(title: string) {
395
+ form.presetTitles = form.presetTitles.filter((t) => t !== title);
396
+ }
397
+
398
+ /** The typed title, added with the Add button or Enter - and on save, so it is not lost. */
399
+ function addTypedPreset() {
400
+ const typed = presetSearch.value.trim();
401
+ if (!typed) return;
402
+ tidyPresets([...form.presetTitles, typed]);
403
+ presetSearch.value = "";
404
+ }
405
+
406
+ async function save() {
407
+ addTypedPreset();
408
+ const valid = await formRef.value?.validate?.();
409
+ if (valid && valid.valid === false) return;
410
+ const body = {
411
+ subject: form.subject.trim(),
412
+ prefix: form.prefix,
413
+ prefixPosition: form.prefixPosition,
414
+ presetTitles: form.presetTitles,
415
+ description: form.description.trim(),
416
+ };
417
+ saving.value = true;
418
+ try {
419
+ if (editing.value?._id) {
420
+ await updateSubject(editing.value._id, body);
421
+ show("Subject updated", "success");
422
+ } else {
423
+ await createSubject({
424
+ ...body,
425
+ site: props.siteId,
426
+ service: props.service,
427
+ ...(props.organization ? { organization: props.organization } : {}),
428
+ });
429
+ show("Subject added", "success");
430
+ }
431
+ closeForm();
432
+ await load();
433
+ } catch (e: any) {
434
+ show(e?.data?.message || "Could not save the subject.", "error");
435
+ } finally {
436
+ saving.value = false;
437
+ }
438
+ }
439
+
440
+ /* ---------------- Delete ---------------- */
441
+
442
+ const deleteOpen = ref(false);
443
+ const deleting = ref(false);
444
+ const pendingDelete = ref<TWorkOrderSubject | null>(null);
445
+
446
+ function askDelete(item: TWorkOrderSubject) {
447
+ pendingDelete.value = item;
448
+ deleteOpen.value = true;
449
+ }
450
+
451
+ async function confirmDelete() {
452
+ if (!pendingDelete.value?._id) return;
453
+ deleting.value = true;
454
+ try {
455
+ await deleteSubject(pendingDelete.value._id);
456
+ show("Subject deleted", "success");
457
+ deleteOpen.value = false;
458
+ if (items.value.length === 1 && page.value > 1) page.value -= 1;
459
+ else await load();
460
+ } catch (e: any) {
461
+ show(e?.data?.message || "Could not delete the subject.", "error");
462
+ } finally {
463
+ deleting.value = false;
464
+ }
465
+ }
466
+
467
+ /* ---------------- Toast ---------------- */
468
+
469
+ const toast = reactive({ show: false, message: "", color: "" });
470
+ function show(message: string, color: string) {
471
+ toast.show = true;
472
+ toast.message = message;
473
+ toast.color = color;
474
+ }
475
+ </script>
476
+
477
+ <style scoped>
478
+ .wo-subjects {
479
+ display: flex;
480
+ flex-direction: column;
481
+ gap: 16px;
482
+ }
483
+ .wo-subjects__head {
484
+ display: flex;
485
+ align-items: flex-start;
486
+ justify-content: space-between;
487
+ gap: 16px;
488
+ padding-bottom: 16px;
489
+ border-bottom: 1px solid var(--border);
490
+ }
491
+ .wo-subjects__title {
492
+ font-size: 15px;
493
+ font-weight: 700;
494
+ color: var(--text);
495
+ }
496
+ .wo-subjects__hint {
497
+ font-size: 13px;
498
+ color: var(--text2);
499
+ }
500
+ .wo-subjects__muted,
501
+ .wo-subjects__label {
502
+ font-size: 13px;
503
+ color: var(--muted);
504
+ }
505
+
506
+ /* ---- Add / Edit dialog ---- */
507
+ /* FormDialog's toolbar sits flush left; its body is padded 16px. */
508
+ .wo-subjects__dialog-title {
509
+ padding-left: 16px;
510
+ font-size: 17px;
511
+ font-weight: 800;
512
+ color: var(--text);
513
+ }
514
+ .wo-subjects__form {
515
+ display: flex;
516
+ flex-direction: column;
517
+ gap: 20px;
518
+ padding: 20px 0 8px;
519
+ }
520
+ .wo-subjects__field {
521
+ display: flex;
522
+ flex-direction: column;
523
+ gap: 6px;
524
+ }
525
+ .wo-subjects__field :deep(.app-input-label) {
526
+ font-size: 14px;
527
+ font-weight: 700;
528
+ color: var(--text);
529
+ }
530
+ /* Typed text and placeholders: the theme's ink, not Vuetify's faded default. */
531
+ .wo-subjects__form :deep(.v-field__input) {
532
+ color: var(--text);
533
+ }
534
+ .wo-subjects__form :deep(.v-field__input::placeholder) {
535
+ color: var(--muted);
536
+ opacity: 1;
537
+ }
538
+ .wo-subjects__help {
539
+ font-size: 13px;
540
+ line-height: 1.4;
541
+ color: var(--text2);
542
+ }
543
+ .wo-subjects__help--tight {
544
+ margin-top: -14px;
545
+ }
546
+ .wo-subjects__preset-row {
547
+ display: flex;
548
+ align-items: center;
549
+ gap: 10px;
550
+ }
551
+ .wo-subjects__preset-row > :first-child {
552
+ flex: 1 1 auto;
553
+ }
554
+ .wo-subjects__add-preset {
555
+ flex: 0 0 auto;
556
+ min-width: 88px;
557
+ }
558
+
559
+ /* Prefix position: two choices side by side, each with the number it makes. */
560
+ .wo-subjects__positions {
561
+ display: grid;
562
+ grid-template-columns: 1fr 1fr;
563
+ gap: 10px;
564
+ }
565
+ .wo-subjects__position {
566
+ display: flex;
567
+ flex-direction: column;
568
+ align-items: flex-start;
569
+ gap: 6px;
570
+ padding: 10px 12px;
571
+ border: 1px solid var(--border);
572
+ border-radius: 10px;
573
+ background: var(--card);
574
+ color: var(--text);
575
+ text-align: left;
576
+ cursor: pointer;
577
+ transition: border-color 0.15s, background-color 0.15s;
578
+ }
579
+ .wo-subjects__position:hover {
580
+ border-color: var(--accent);
581
+ }
582
+ .wo-subjects__position:focus-visible {
583
+ outline: 2px solid var(--accent);
584
+ outline-offset: 2px;
585
+ }
586
+ .wo-subjects__position--on {
587
+ border-color: var(--accent);
588
+ background: var(--accent-soft);
589
+ }
590
+ .wo-subjects__position-head {
591
+ display: inline-flex;
592
+ align-items: center;
593
+ gap: 6px;
594
+ font-size: 14px;
595
+ font-weight: 700;
596
+ }
597
+ .wo-subjects__position--on .wo-subjects__position-head {
598
+ color: var(--accent-text, var(--accent));
599
+ }
600
+ .wo-subjects__position-sample {
601
+ font-size: 15px;
602
+ font-weight: 700;
603
+ letter-spacing: 0.02em;
604
+ font-variant-numeric: tabular-nums;
605
+ color: var(--text);
606
+ }
607
+ @media (max-width: 420px) {
608
+ .wo-subjects__positions {
609
+ grid-template-columns: 1fr;
610
+ }
611
+ }
612
+ .wo-subjects__preset-chips {
613
+ display: flex;
614
+ flex-wrap: wrap;
615
+ gap: 6px;
616
+ }
617
+ .wo-subjects__prefix {
618
+ display: flex;
619
+ flex-direction: column;
620
+ line-height: 1.25;
621
+ }
622
+ .wo-subjects__prefix-code {
623
+ font-weight: 700;
624
+ }
625
+ .wo-subjects__prefix-sample {
626
+ font-size: 12px;
627
+ color: var(--muted);
628
+ font-variant-numeric: tabular-nums;
629
+ }
630
+ .wo-subjects__desc {
631
+ display: -webkit-box;
632
+ -webkit-line-clamp: 2;
633
+ -webkit-box-orient: vertical;
634
+ overflow: hidden;
635
+ }
636
+ .wo-subjects__required {
637
+ color: var(--err);
638
+ }
639
+ .wo-subjects__empty {
640
+ display: flex;
641
+ flex-direction: column;
642
+ align-items: center;
643
+ gap: 8px;
644
+ padding: 24px 0;
645
+ color: var(--muted);
646
+ }
647
+ @media (max-width: 600px) {
648
+ .wo-subjects__head {
649
+ flex-direction: column;
650
+ }
651
+ }
652
+ </style>
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Work Order Settings > Subjects: the subjects a site adds on top of the
3
+ * built-in list (API-core `/api/work-order-subjects`; each app proxies it).
4
+ *
5
+ * - The settings table lists, adds, edits and deletes them (one service's own).
6
+ * - Create Feedback (every app) and a management app's Create Work Order offer
7
+ * every subject of the site; a service app's own Create Work Order only its
8
+ * service's and organisation's (`getSubjects({ site, service, organization, limit: 0 })`).
9
+ * - A subject's `prefix` decorates a work order number: before "#AC-ME001",
10
+ * after "#ME001-AC" (`withSubjectPrefix`).
11
+ */
12
+ export default function useWorkOrderSubject() {
13
+ function getSubjects(body: {
14
+ site: string;
15
+ service?: string;
16
+ organization?: string;
17
+ search?: string;
18
+ page?: number;
19
+ /** 0: every subject (the create forms). */
20
+ limit?: number;
21
+ }) {
22
+ return useNuxtApp().$api<TWorkOrderSubjectList>("/api/work-order-subjects/list", {
23
+ method: "POST",
24
+ body,
25
+ });
26
+ }
27
+
28
+ function createSubject(body: TWorkOrderSubjectCreate) {
29
+ return useNuxtApp().$api<TWorkOrderSubject>("/api/work-order-subjects", {
30
+ method: "POST",
31
+ body,
32
+ });
33
+ }
34
+
35
+ function updateSubject(id: string, body: Partial<TWorkOrderSubjectFields>) {
36
+ return useNuxtApp().$api<TWorkOrderSubject>(`/api/work-order-subjects/id/${id}`, {
37
+ method: "PUT",
38
+ body,
39
+ });
40
+ }
41
+
42
+ function deleteSubject(id: string) {
43
+ return useNuxtApp().$api<{ message: string }>(`/api/work-order-subjects/id/${id}`, {
44
+ method: "DELETE",
45
+ });
46
+ }
47
+
48
+ return { getSubjects, createSubject, updateSubject, deleteSubject };
49
+ }
50
+
51
+ /**
52
+ * `number` ("ME001", or "#ME001.1") with a record's saved added-subject prefix on
53
+ * the side it was saved for: "AC-ME001" before, "ME001-AC" after. A leading "#"
54
+ * stays in front. Unchanged when the record has no prefix.
55
+ */
56
+ export function withSubjectPrefix(
57
+ number: string | null | undefined,
58
+ record?: { subjectPrefix?: string; subjectPrefixPosition?: string } | null
59
+ ): string {
60
+ const text = String(number ?? "");
61
+ const prefix = String(record?.subjectPrefix ?? "").trim();
62
+ if (!text || !prefix) return text;
63
+ const hash = text.startsWith("#") ? "#" : "";
64
+ const bare = hash ? text.slice(1) : text;
65
+ return record?.subjectPrefixPosition === "after"
66
+ ? `${hash}${bare}-${prefix}`
67
+ : `${hash}${prefix}-${bare}`;
68
+ }
69
+
70
+ /**
71
+ * The built-in subjects plus the site's added ones, alphabetical, "Others"
72
+ * last; an added subject named like a built-in one is not shown twice.
73
+ */
74
+ export function mergeSubjectOptions<T extends { title: string }>(
75
+ builtIn: T[],
76
+ added: TWorkOrderSubject[]
77
+ ): Array<T | (TWorkOrderSubject & { title: string; value: string; subtitle?: string; added: true })> {
78
+ const taken = new Set(builtIn.map((o) => o.title.trim().toLowerCase()));
79
+ const extra = added
80
+ .filter((s) => s?.subject && !taken.has(s.subject.trim().toLowerCase()))
81
+ .map((s) => ({
82
+ ...s,
83
+ title: s.subject,
84
+ value: s.subject,
85
+ subtitle: s.description || undefined,
86
+ added: true as const,
87
+ }));
88
+ const isOthers = (o: { title: string }) => o.title.trim().toLowerCase() === "others";
89
+ const all = [...builtIn, ...extra];
90
+ return [
91
+ ...all.filter((o) => !isOthers(o)).sort((a, b) => a.title.localeCompare(b.title, undefined, { sensitivity: "base" })),
92
+ ...all.filter(isOthers),
93
+ ];
94
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.97.1-staging.662",
5
+ "version": "4.97.1-staging.664",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
@@ -0,0 +1,33 @@
1
+ /** Where an added subject's prefix goes on a work order number: "#AC-ME001" / "#ME001-AC". */
2
+ declare type TWorkOrderSubjectPrefixPosition = "before" | "after";
3
+
4
+ /** The editable fields of an added subject (Work Order Settings > Subjects). */
5
+ declare type TWorkOrderSubjectFields = {
6
+ subject: string;
7
+ prefix?: string;
8
+ prefixPosition?: TWorkOrderSubjectPrefixPosition;
9
+ presetTitles?: string[];
10
+ description?: string;
11
+ };
12
+
13
+ declare type TWorkOrderSubjectCreate = TWorkOrderSubjectFields & {
14
+ site: string;
15
+ service: string;
16
+ organization?: string;
17
+ };
18
+
19
+ declare type TWorkOrderSubject = TWorkOrderSubjectFields & {
20
+ _id: string;
21
+ site: string;
22
+ service: string;
23
+ organization?: string | null;
24
+ createdAt?: string;
25
+ updatedAt?: string;
26
+ };
27
+
28
+ declare type TWorkOrderSubjectList = {
29
+ items: TWorkOrderSubject[];
30
+ total: number;
31
+ pages: number;
32
+ pageRange: string;
33
+ };