Skip to content

Commit

Permalink
Merge pull request #59 from fdm-monster/feat/31-introduce-drag-n-drop…
Browse files Browse the repository at this point in the history
…-printer-placement

Feat/31 introduce drag n drop printer placement
  • Loading branch information
davidzwa authored Apr 24, 2023
2 parents e635167 + e8ed23d commit d14c95d
Show file tree
Hide file tree
Showing 20 changed files with 471 additions and 144 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fdm-monster/client",
"version": "1.0.0-rc7",
"version": "1.0.0",
"private": false,
"author": "David Zwart",
"license": "AGPL-3.0-or-later",
Expand Down
7 changes: 7 additions & 0 deletions src/backend/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseService } from "./base.service";

export class AppService extends BaseService {
static async updateClientDist() {
return await this.postApi("api/server/update-client-bundle-github");
}
}
33 changes: 33 additions & 0 deletions src/components/Generic/Actions/PrinterCreateAction.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<v-btn
class="ma-2"
color="primary"
fab
small
@click.c.capture.native.stop="openCreatePrinterDialog()"
>
<v-icon>add</v-icon>
</v-btn>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { useDialogsStore } from "../../../store/dialog.store";
import { DialogName } from "../Dialogs/dialog.constants";
export default defineComponent({
name: "PrinterCreateAction",
props: {},
setup: () => {
return {
dialogsStore: useDialogsStore(),
};
},
computed: {},
methods: {
openCreatePrinterDialog() {
this.dialogsStore.openDialog(DialogName.CreatePrinterDialog);
},
},
});
</script>
4 changes: 2 additions & 2 deletions src/components/Generic/Actions/PrinterDeleteAction.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<v-btn color="warning" outlined @click="deletePrinter()">
<v-btn class="ma-2" color="primary" fab small @click.prevent.stop="deletePrinter()">
<v-icon>delete</v-icon>
<span class="d-none d-lg-inline">Delete printer</span>
</v-btn>
</template>

Expand Down Expand Up @@ -30,6 +29,7 @@ export default defineComponent({
},
methods: {
async deletePrinter() {
if (!confirm("Are you sure to delete this printer?")) return;
await this.printersStore.deletePrinter(this.printerId);
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Generic/Actions/PrinterSettingsAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { defineComponent, PropType } from "vue";
import { Printer } from "@/models/printers/printer.model";
export default defineComponent({
name: "PrinterUrlAction",
name: "PrinterSettingsAction",
props: {
printer: Object as PropType<Printer>,
},
Expand Down
16 changes: 12 additions & 4 deletions src/components/Generic/Dialogs/BatchJsonCreateDialog.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<BaseDialog :id="dialogId" max-width="500px">
<BaseDialog :id="dialogId" max-width="700px">
<validation-observer ref="validationObserver" v-slot="{ invalid }">
<v-card>
<v-card class="pa-4">
<v-card-title>
<span class="text-h5"> Batch Import JSON printers </span>
</v-card-title>
Expand All @@ -13,16 +13,18 @@
v-model="formData.json"
:error-messages="errors"
data-vv-validate-on="change|blur"
rows="10"
@change="updatePrinterCount()"
>
<template v-slot:label>
<div>JSON import <small>(optional)</small></div>
</template>
</v-textarea>
</validation-provider>
{{ numPrinters }} printers
{{ numPrinters }} printers found
</v-col>
</v-row>
<v-btn class="mt-2">Validate printers</v-btn>
</v-card-text>
<v-card-actions>
<em class="red--text">* indicates required field</em>
Expand Down Expand Up @@ -118,7 +120,6 @@ export default defineComponent({
const answer = confirm(`Are you sure to import ${numPrinters} printers?`);
if (answer) {
printers.forEach((p) => {
p.enabled = false;
if (p["_id"]) {
delete p["_id"];
}
Expand All @@ -130,6 +131,13 @@ export default defineComponent({
p.settingsAppearance = p["settingsApperance"];
delete p["settingsApperance"];
}
if (p["name"]) {
if (!p.settingsAppearance) {
p.settingsAppearance = {};
}
p.settingsAppearance.name = p["name"];
delete p["name"];
}
});
await PrintersService.batchImportPrinters(printers);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Generic/Dialogs/CreatePrinterDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<v-card-text>
<v-row>
<v-col :cols="showChecksPanel ? 8 : 12">
<PrinterCrudForm ref="printerCrudForm" @onChange="onFormChange" />
<PrinterCrudForm ref="printerCrudForm" />
</v-col>

<PrinterChecksPanel v-if="showChecksPanel" :cols="4" :test-progress="testProgress">
Expand Down
1 change: 1 addition & 0 deletions src/components/Generic/Dialogs/dialog.constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum DialogName {
BatchJson = "BatchJson",
CreatePrinterDialog = "CreatePrinterDialog",
PlacePrinterDialog = "PlacePrinterDialog",
CreatePrinterFloorDialog = "CreatePrinterFloorDialog",
PrinterMaintenanceDialog = "PrinterMaintenanceDialog",
UpdatePrinterDialog = "UpdatePrinterDialog",
Expand Down
13 changes: 13 additions & 0 deletions src/components/PrinterGrid/HomeToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,33 @@
{{ f.name }}
</v-btn>
</v-btn-toggle>

<v-btn color="primary" class="mt-0 ml-6" v-if="!printersStore.printers?.length" to="/printers">
You have no printers. Click here to start!
</v-btn>
<v-alert color="primary" class="mt-4 ml-12" v-if="printersStore.floorlessPrinters.length">
<v-icon>warning</v-icon>
{{ printersStore.floorlessPrinters.length }} unplaced printer(s)!</v-alert
>
<div class="ma-4 pt-6">
<v-switch v-model="gridStore.gridEditMode" label="Printer Relocate Mode"></v-switch>
</div>
<v-spacer></v-spacer>
</v-toolbar>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { usePrintersStore } from "@/store/printers.store";
import { useGridStore } from "../../store/grid.store";
export default defineComponent({
name: "HomeToolbar",
components: {},
setup() {
return {
printersStore: usePrintersStore(),
gridStore: useGridStore(),
};
},
data(): {
Expand Down
32 changes: 32 additions & 0 deletions src/components/PrinterGrid/PrinterGrid.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<template>
<div>
<div v-if="gridStore.gridEditMode" class="ml-4 mt-4 mb-0" style="cursor: move">
<span class="pr-4">
Drag and drop {{ printersStore.floorlessPrinters.length }} unplaced printer(s) here:
</span>
<div
v-for="printer of printersStore.floorlessPrinters"
:key="printer.id"
class="d-inline-block text-center mr-1 mb-1"
draggable="true"
style="width: 100px; height: 40px; border: 1px solid gray; border-radius: 2px"
@dragstart="onDragStart(printer, $event)"
>
<strong text-center>{{ printer.printerName }}</strong>
</div>
<div class="mt-4">Clear printers by clicking on their tile below:</div>
</div>
<v-row v-for="y in rows" :key="y" class="ma-1" no-gutters>
<v-col v-for="x in columns" :key="x" :cols="columnWidth" :sm="columnWidth">
<v-row class="test-top" no-gutters>
Expand Down Expand Up @@ -50,6 +66,8 @@ import {
} from "@/constants/printer-grid.constants";
import { usePrintersStore } from "@/store/printers.store";
import { Printer } from "../../models/printers/printer.model";
import { useGridStore } from "../../store/grid.store";
import { dragAppId, INTENT, PrinterPlace } from "../../constants/drag.constants";
export default defineComponent({
components: { PrinterGridTile },
Expand All @@ -65,6 +83,7 @@ export default defineComponent({
setup() {
return {
printersStore: usePrintersStore(),
gridStore: useGridStore(),
};
},
async created() {
Expand All @@ -91,6 +110,19 @@ export default defineComponent({
},
},
methods: {
onDragStart(printer: Printer, ev: DragEvent) {
if (!ev.dataTransfer) return;
if (!printer.id) return;
ev.dataTransfer.setData(
"text",
JSON.stringify({
appId: dragAppId,
intent: INTENT.PRINTER_PLACE,
printerId: printer.id,
} as PrinterPlace)
);
},
getPrinter(col: number, row: number) {
const x = col;
const y = row;
Expand Down
Loading

0 comments on commit d14c95d

Please sign in to comment.