@7365admin1/layer-common 4.97.1-staging.690 → 4.97.1-staging.692

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.
@@ -7,33 +7,14 @@
7
7
  <v-card-text class="screen-modal__body pa-0">
8
8
  <v-form v-model="validForm" :disabled="disable">
9
9
  <v-row no-gutters class="px-6 pt-4">
10
- <v-col cols="12" class="mt-2">
11
- <v-row no-gutters>
12
- <InputLabel class="text-capitalize font-weight-bold" title="Block Name" required />
13
- <v-col cols="12">
14
- <v-text-field v-model="building.name" class="filter-field" density="comfortable" :rules="[requiredRule]"></v-text-field>
15
- </v-col>
16
- </v-row>
17
- </v-col>
18
-
19
10
  <v-col v-if="prop.mode === 'add'" cols="12">
20
11
  <v-row>
21
12
  <v-col cols="6" class="mt-2">
22
13
  <v-row no-gutters>
23
14
  <InputLabel class="text-capitalize font-weight-bold" title="Block No." required />
24
15
  <v-col cols="12">
25
- <v-select v-model.number="building.block" :items="blocks" item-title="label" item-value="value"
26
- class="filter-field" density="comfortable" :rules="[
27
- requiredRule,
28
- () =>
29
- (building.block && building.block > 0) ||
30
- 'Block is required',
31
- ]" type="number">
32
- <template v-slot:item="{ props: itemProps, item }">
33
- <v-list-item v-bind="itemProps" :disabled="item?.raw?.disabled"></v-list-item>
34
- </template>
35
-
36
- </v-select>
16
+ <v-text-field v-model.trim="building.block" class="filter-field" density="comfortable"
17
+ placeholder="e.g. 12 or 12A" maxlength="5" :rules="[requiredRule, blockRule]"></v-text-field>
37
18
  </v-col>
38
19
  </v-row>
39
20
  </v-col>
@@ -206,6 +187,7 @@
206
187
 
207
188
  <script setup lang="ts">
208
189
  import InputLabel from './InputLabel.vue';
190
+ import { blockLabel, normaliseBlock, BLOCK_NO_MESSAGE } from "../utils/building-block";
209
191
 
210
192
  const prop = defineProps({
211
193
  site: {
@@ -232,40 +214,11 @@ const prop = defineProps({
232
214
  },
233
215
  });
234
216
 
235
- const { getSiteById } = useSite();
236
217
  const { getFileById } = useFile();
237
218
  const { deleteById, batchUpdateLevels } = useBuildingLevel();
238
219
 
239
- const site = ref<TSite | null>(null);
240
-
241
- const { data: getSiteReq } = useLazyAsyncData(
242
- "get-site-by-id-" + prop.site,
243
- async () => getSiteById(prop.site)
244
- );
245
-
246
- watchEffect(() => {
247
- if (getSiteReq.value) {
248
- site.value = getSiteReq.value;
249
- }
250
- });
251
-
252
- const blocks = computed(() => {
253
- if (!site.value) return [];
254
- // return
255
- // return [ { label: "1", value: 1, disabled: true }, { label: "2", value: 2 }, { label: "3", value: 3 } ];
256
- const array = Array.from({ length: site.value?.metadata?.block || 0 }, (_, i) => i + 1);
257
-
258
- const formattedArray = array.map((num) => {
259
- const isDisabled = prop.blocks.some((block) => block.block === num)
260
- return {
261
- label: num.toString(),
262
- value: num,
263
- disabled: isDisabled
264
- };
265
- });
266
-
267
- return formattedArray;
268
- });
220
+ // Block No: digits with at most one letter (12, 12A). The site's "number of blocks" no longer caps it.
221
+ const blockRule = (v: unknown) => normaliseBlock(v) !== null || BLOCK_NO_MESSAGE;
269
222
 
270
223
  const emit = defineEmits(["cancel", "success", "success:create-more", "refresh"]);
271
224
 
@@ -400,10 +353,26 @@ async function submit() {
400
353
  try {
401
354
  if (prop.mode === "add") {
402
355
  const buildingPayload = { ...building.value };
356
+ // One block field only: the stored name is derived from the number ("Blk 3").
357
+ const blockNo = normaliseBlock(buildingPayload.block);
358
+ if (blockNo === null) {
359
+ message.value = BLOCK_NO_MESSAGE;
360
+ return;
361
+ }
362
+ buildingPayload.block = blockNo;
363
+ if (prop.blocks.some((b) => normaliseBlock(b.block) === blockNo)) {
364
+ message.value = `Block ${blockNo} already exists. Choose a different Block No.`;
365
+ return;
366
+ }
367
+ const name = blockLabel(blockNo);
368
+ if (prop.blocks.some((b) => b.name?.trim().toLowerCase() === name.toLowerCase() && b.block !== blockNo)) {
369
+ message.value = `Another block is already named "${name}". Rename it first, or choose a different Block No.`;
370
+ return;
371
+ }
403
372
 
404
373
  let payload: TBuildingPayload = {
405
374
  site: buildingPayload.site,
406
- name: buildingPayload.name,
375
+ name,
407
376
  block: buildingPayload.block,
408
377
  levels: [...newLevelsArray.value],
409
378
  buildingFiles: (building.value.buildingFiles as string[] || []).map((id) => ({ id, name: buildingFilesNames.value[id] ?? "" }))
@@ -22,6 +22,7 @@
22
22
  <template #prepend-additional>
23
23
  <AppField v-model="searchInput" search compact placeholder="Search" klass="app-toolbar__search" />
24
24
  </template>
25
+ <template #item.block="{ value }">{{ value ? blockLabel(value) : "" }}</template>
25
26
  <template #item.createdAt="{ value }">
26
27
  {{ new Date(value).toLocaleDateString() }}
27
28
  </template>
@@ -52,13 +53,9 @@
52
53
  <v-card width="100%">
53
54
  <v-card-text style="max-height: 100vh; overflow-y: auto" class="pb-0">
54
55
  <v-row no-gutters class="mb-4">
55
- <v-col cols="12">
56
- <strong>Name:</strong> {{ selectedBuilding?.name ?? "N/A" }}
57
- </v-col>
58
-
59
56
  <v-col cols="12">
60
57
  <strong>Block:</strong>
61
- {{ selectedBuilding?.block ?? "N/A" }}
58
+ {{ selectedBuilding?.block ? blockLabel(selectedBuilding.block) : "N/A" }}
62
59
  </v-col>
63
60
 
64
61
  <v-col cols="12">
@@ -161,16 +158,13 @@
161
158
  // Relative import, never Nuxt auto-import: this layer's `utils/` are auto-imported
162
159
  // into the consuming apps but not reliably into the layer's own components.
163
160
  import { levelCount } from "../../utils/data";
161
+ import { blockLabel } from "../../utils/building-block";
164
162
 
165
163
 
166
164
  const props = defineProps({
167
165
  headers: {
168
166
  type: Array as PropType<Array<Record<string, any>>>,
169
167
  default: () => [
170
- {
171
- title: "Name",
172
- value: "name",
173
- },
174
168
  {
175
169
  title: "Block",
176
170
  value: "block",
@@ -30,8 +30,8 @@
30
30
  v-model="showImport"
31
31
  title="Import Blocks, Levels and Units from Excel"
32
32
  noun="rows"
33
- name-label="Building / Level / Unit"
34
- fill-hint="One row per unit: building name, level and unit. Pick Building Name and Level from the dropdowns (type a new name for a new building). No block number needed — an existing building keeps its own and a new one gets the next free number."
33
+ name-label="Block / Level / Unit"
34
+ fill-hint="One row per unit: Block No, Level and Unit Number. Pick Level from the dropdown where it already exists. A new Block No creates a new block (Blk 1, Blk 2 ...); an existing block keeps its name."
35
35
  duplicate-note="Units already on that level are skipped and left unchanged."
36
36
  template-file-name="units-import-template.xlsx"
37
37
  :download-template="() => downloadTemplate('building-units', { site })"
@@ -50,7 +50,7 @@
50
50
  <AppField v-model="searchInput" search compact placeholder="Search" klass="app-toolbar__search" />
51
51
  </template>
52
52
  <template #item.block="{ value, item }">
53
- {{ value ? `Block ${value}` : "" }}
53
+ {{ value ? blockLabel(value) : "" }}
54
54
  </template>
55
55
  </TableMain>
56
56
 
@@ -174,6 +174,7 @@
174
174
 
175
175
  <script setup lang="ts">
176
176
  import useImportTemplates from "../../composables/useImportTemplates";
177
+ import { blockLabel } from "../../utils/building-block";
177
178
  import { saveBlob } from "../../composables/useInventory";
178
179
  import { useDisplay } from 'vuetify/lib/composables/display.mjs';
179
180
 
@@ -189,13 +190,9 @@ const props = defineProps({
189
190
  title: "Level",
190
191
  value: "level.name",
191
192
  },
192
- // {
193
- // title: "Block",
194
- // value: "block",
195
- // },
196
193
  {
197
- title: "Block Name",
198
- value: "buildingName",
194
+ title: "Block",
195
+ value: "block",
199
196
  },
200
197
 
201
198
  // {
@@ -1512,7 +1512,7 @@ type OccupiedLevel = { _id: string; name: string; units?: OccupiedUnit[] };
1512
1512
  type OccupiedBlock = {
1513
1513
  _id: string;
1514
1514
  name: string;
1515
- block: number | null;
1515
+ block: number | string | null;
1516
1516
  levels?: OccupiedLevel[];
1517
1517
  };
1518
1518
  type UnitPerson = {
@@ -119,6 +119,7 @@
119
119
 
120
120
  <script setup lang="ts">
121
121
  import { property } from 'zod/v4';
122
+ import { normaliseBlock } from '../utils/building-block';
122
123
 
123
124
  const prop = defineProps({
124
125
  org: {
@@ -205,14 +206,14 @@ const { data: levelsData, refresh: refreshLevelsData, status: levelsStatus } = u
205
206
  `fetch-levels-data-${prop.site}-${form.block}`,
206
207
  async () => {
207
208
  if (!form.block) return Promise.resolve(null);
208
- return await getSiteLevels(prop.site, { block: Number(form.block) })
209
+ return await getSiteLevels(prop.site, { block: normaliseBlock(form.block) ?? form.block })
209
210
  }, { watch: [() => form.block],});
210
211
 
211
212
  const { data: unitsData, refresh: refreshUnitsData, status: unitsStatus } = useLazyAsyncData(
212
213
  `fetch-units-data-${prop.site}-${form.level}`,
213
214
  async () => {
214
215
  if (!form.level) return Promise.resolve(null);
215
- return await getSiteUnits(prop.site, Number(form.block), form.level)
216
+ return await getSiteUnits(prop.site, normaliseBlock(form.block) ?? form.block, form.level)
216
217
  }, { watch: [()=> form.level]});
217
218
 
218
219
  watch(
@@ -1,6 +1,6 @@
1
1
  export default function(){
2
2
 
3
- const formatLocation = ({block, level, unit}: {block: number, level: string, unit: string | TBuildingUnit}) => {
3
+ const formatLocation = ({block, level, unit}: {block: number | string, level: string, unit: string | TBuildingUnit}) => {
4
4
  const parts = [];
5
5
 
6
6
  if (block?.name) parts.push(`${block.name}`);
@@ -8,7 +8,7 @@ export default function () {
8
8
  );
9
9
  }
10
10
 
11
- async function getSiteLevels(siteId: string, query: { block: number }) {
11
+ async function getSiteLevels(siteId: string, query: { block: number | string }) {
12
12
  return await useNuxtApp().$api<Record<string, any>>(
13
13
  `/api/buildings/site/${siteId}`,
14
14
  {
@@ -18,7 +18,7 @@ export default function () {
18
18
  );
19
19
  }
20
20
 
21
- async function getSiteUnits(siteId: string, block: number, level: string) {
21
+ async function getSiteUnits(siteId: string, block: number | string, level: string) {
22
22
  return await useNuxtApp().$api<Record<string, any>>(
23
23
  `/api/building-units/site/${siteId}/block/${block}/level/${level}`,
24
24
  {
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.690",
5
+ "version": "4.97.1-staging.692",
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.",
@@ -2,7 +2,7 @@ declare type TBuilding = {
2
2
  _id?: string;
3
3
  site: string;
4
4
  name: string;
5
- block: number | null;
5
+ block: number | string | null;
6
6
  levels: { _id: string; name: string }[];
7
7
  buildingFiles: { id: string, name: string }[] | string[];
8
8
  };
@@ -15,7 +15,7 @@ declare type TBuildingUnit = {
15
15
  ownerName?: string;
16
16
  building: string;
17
17
  buildingName?: string;
18
- block: number | null;
18
+ block: number | string | null;
19
19
  level: { _id: string; name: string } | null;
20
20
  category: string;
21
21
  status: string;
@@ -0,0 +1,19 @@
1
+ /** The one block label used everywhere: "Blk 3", "Blk 12A". Block names are no longer typed; they come from the number. */
2
+ export const blockLabel = (block: number | string | null | undefined): string => `Blk ${block}`;
3
+
4
+ export const BLOCK_NO_MESSAGE = "Block No must be a number from 1 to 9999, optionally followed by one letter (for example 12 or 12A).";
5
+
6
+ /**
7
+ * Block No: 1-4 digits and at most one capital letter. Same rule as the API (core): trim, capitals,
8
+ * drop "Blk"/"Block" and leading zeros. Digits only -> a number; with a letter -> a string ("12A").
9
+ */
10
+ export function normaliseBlock(input: unknown): number | string | null {
11
+ if (typeof input === "number") return Number.isInteger(input) && input >= 1 && input <= 9999 ? input : null;
12
+ if (typeof input !== "string") return null;
13
+ const s = input.trim().toUpperCase().replace(/^(BLK|BLOCK)\.?\s*/, "").replace(/^0+(?=\d)/, "");
14
+ const m = /^(\d{1,4})([A-Z]?)$/.exec(s);
15
+ if (!m) return null;
16
+ const n = Number(m[1]);
17
+ if (n < 1) return null;
18
+ return m[2] ? `${n}${m[2]}` : n;
19
+ }