diff --git a/package.json b/package.json index e9755c58..5e1a3a6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fdm-monster/client", - "version": "1.5.0-rc8", + "version": "1.5.0-rc9", "author": "David Zwart", "license": "AGPL-3.0-or-later", "repository": { diff --git a/src/backend/printer-group.service.ts b/src/backend/printer-group.service.ts index 41522eaa..8c7c608c 100644 --- a/src/backend/printer-group.service.ts +++ b/src/backend/printer-group.service.ts @@ -51,4 +51,12 @@ export class PrinterGroupService extends BaseService { }; return (await this.deleteApi(path, body)) as GroupWithPrintersDto[]; } + + static async updateGroupName(groupId: IdType, name: string) { + const path = `${ServerApi.updateGroupNameRoute(groupId)}`; + const body = { + name, + }; + return (await this.patchApi(path, body)) as GroupWithPrintersDto[]; + } } diff --git a/src/backend/server.api.ts b/src/backend/server.api.ts index b96aecd9..9851f769 100644 --- a/src/backend/server.api.ts +++ b/src/backend/server.api.ts @@ -26,6 +26,7 @@ export class ServerApi { static printerGroupRoute = `${ServerApi.base}/printer-group`; static createGroupRoute = `${ServerApi.base}/printer-group`; static deleteGroupRoute = (id: IdType) => `${ServerApi.base}/printer-group/${id}`; + static updateGroupNameRoute = (id: IdType) => `${ServerApi.base}/printer-group/${id}/name`; static addPrinterToGroupRoute = (id: IdType) => `${ServerApi.base}/printer-group/${id}/printer`; static deletePrinterFromGroupRoute = ServerApi.addPrinterToGroupRoute; diff --git a/src/components/PrinterList/PrintersView.vue b/src/components/PrinterList/PrintersView.vue index c22508c3..090476e6 100644 --- a/src/components/PrinterList/PrintersView.vue +++ b/src/components/PrinterList/PrintersView.vue @@ -4,11 +4,23 @@ Printers + + @@ -142,16 +154,37 @@

Existing groups:

- - {{ group.name }} - + + {{ group.name }} + + + + +

Update group name

+ + Select a group to update its name. + + Name + + Update name

Add group

@@ -164,8 +197,8 @@ > Name + Create new group - Save @@ -203,7 +236,10 @@ const floorStore = useFloorStore(); const dialogsStore = useDialogsStore(); const featureStore = useFeatureStore(); const groupsWithPrinters = ref[]>([]); +const filteredGroupsWithPrinters = ref[]>([]); const newGroupName = ref(""); +const updatedGroupName = ref(""); +const selectedGroup = ref(); const search = ref(""); const expanded = ref([]); @@ -236,8 +272,21 @@ const printerGroupsQuery = useQuery({ }, }); -const printers = computed(() => printerStore.printers); +const printers = computed(() => { + if (!hasPrinterGroupFeature.value || !filteredGroupsWithPrinters.value?.length) { + return printerStore.printers; + } + const printerIdsInFilteredGroups = + filteredGroupsWithPrinters.value.flatMap((g) => g.printers.map((p) => p.printerId)) || []; + return printerStore.printers.filter((p) => printerIdsInFilteredGroups.includes(p.id)); +}); + const currentEventReceivedAt = computed(() => printerStateStore.printerCurrentEventReceivedAtById); +const selectedGroupObject = computed(() => { + if (!selectedGroup.value && selectedGroup.value !== 0) return; + + return groupsWithPrinters.value[selectedGroup.value]; +}); const diffSeconds = (timestamp: number) => { if (!timestamp) return; @@ -295,6 +344,28 @@ const createGroup = async () => { snackbar.info("Created group"); }; +const selectGroupForUpdatingName = () => { + if (!selectedGroupObject.value) return; + + updatedGroupName.value = selectedGroupObject.value?.name; +}; + +const updateGroupName = async (group?: GroupWithPrintersDto) => { + if (!group?.id) { + throw new Error("Group id was not defined"); + } + const existingGroup = groupsWithPrinters.value.find((g) => g.id === group.id); + if (!existingGroup) { + throw new Error("Group was not found, please reload the page"); + } + if (!updatedGroupName.value?.trim()?.length) { + throw new Error("Please set a non-empty group name"); + } + + await PrinterGroupService.updateGroupName(group.id, updatedGroupName.value.trim()); + await printerGroupsQuery.refetch(); +}; + const deleteGroup = async (groupId: IdType) => { const existingGroup = groupsWithPrinters.value.find((g) => g.id === groupId); if (!existingGroup) {