Skip to content

Commit

Permalink
Merge pull request #124 from fdm-monster/feat/batch-connect-usb-and-s…
Browse files Browse the repository at this point in the history
…ocket

feat: batch connect USB and Socket based on feature flags of API
  • Loading branch information
davidzwa authored May 14, 2023
2 parents 81157c1 + d25c19c commit c2d5b79
Showing 8 changed files with 142 additions and 59 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.1.3",
"version": "1.1.4",
"private": false,
"author": "David Zwart",
"license": "AGPL-3.0-or-later",
11 changes: 11 additions & 0 deletions src/backend/batch.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BaseService } from "./base.service";

export class BatchService extends BaseService {
static async batchConnectUsb(printerIds: string[]) {
return await this.postApi("api/batch/connect/usb", { printerIds });
}

static async batchConnectSocket(printerIds: string[]) {
return await this.postApi(`api/batch/connect/socket`, { printerIds });
}
}
110 changes: 110 additions & 0 deletions src/components/Settings/EmergencyCommands.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<template>
<v-card>
<v-toolbar color="primary">
<v-avatar>
<v-icon>settings</v-icon>
</v-avatar>
<v-toolbar-title>Emergency Commands</v-toolbar-title>
</v-toolbar>
<v-list subheader three-line>
<v-subheader>Emergency Commands to rectify problematic situations</v-subheader>

<v-list-item>
<v-list-item-content>
<v-list-item-title>Server commands</v-list-item-title>
<v-list-item-subtitle>
Restart the server
<br />
<v-btn color="primary" @click="restartServer()">Restart server</v-btn>
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>

<v-list-item>
<v-list-item-content>
<v-list-item-title>Batch USB connect</v-list-item-title>
<v-list-item-subtitle>
Connect all USB devices
<br />
<v-btn color="primary" @click="connectUSBs()" :disabled="!hasConnectUsbFeature">
<v-icon class="mr-2">usb</v-icon>
Connect USBs</v-btn
>
<v-alert v-if="!hasConnectUsbFeature">
<v-icon class="mr-2">warning</v-icon>
This feature is not available, please update the FDM Monster server
</v-alert>
</v-list-item-subtitle>
<v-list-item-subtitle class="mt-2">
Connect all Sockets
<br />
<v-btn color="primary" @click="connectSockets()" :disabled="!hasConnectSocketFeature">
<v-icon class="mr-2">hub</v-icon>
Connect Sockets</v-btn
>
</v-list-item-subtitle>
<v-alert v-if="!hasConnectSocketFeature">
<v-icon class="mr-2">warning</v-icon>
This feature is not available, please update the FDM Monster server
</v-alert>
</v-list-item-content>
</v-list-item>
</v-list>
</v-card>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { ServerPrivateService } from "@/backend/server-private.service";
import { BatchService } from "../../backend/batch.service";
import { usePrintersStore } from "../../store/printers.store";
import { useFeatureStore } from "../../store/features.store";
interface Data {
property: number;
}
export default defineComponent({
name: "EmergencyCommands",
setup: () => {
return {
printerStore: usePrintersStore(),
featureStore: useFeatureStore(),
};
},
props: {},
data: (): Data => ({
property: 0,
}),
async created() {},
async mounted() {},
computed: {
hasConnectUsbFeature() {
return this.featureStore.hasFeature("batchConnectUsbCalls");
},
hasConnectSocketFeature() {
return this.featureStore.hasFeature("batchConnectSocketCalls");
},
},
methods: {
async restartServer() {
await ServerPrivateService.restartServer();
},
async connectUSBs() {
if (!confirm("Are you sure you want to connect all USBs?")) {
return;
}
const printerIds = this.printerStore.printers.map((p) => p.id);
await BatchService.batchConnectUsb(printerIds);
},
async connectSockets() {
if (!confirm("Are you sure you want to connect all sockets?")) {
return;
}
const printerIds = this.printerStore.printers.map((p) => p.id);
await BatchService.batchConnectSocket(printerIds);
},
},
watch: {},
});
</script>
53 changes: 0 additions & 53 deletions src/components/Settings/ServerRelatedSettings.vue

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/Settings/SettingsView.vue
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ export default defineComponent({
path: "/settings/user-management",
},
{ title: "FDM Monster settings", icon: "image", path: "/settings/system" },
{ title: "Other", icon: "help", path: "/settings/server-related" },
{ title: "Emergency Commands", icon: "warning", path: "/settings/emergency-commands" },
],
}),
computed: {},
9 changes: 9 additions & 0 deletions src/models/batch.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface BatchSingletonModel {
success?: boolean;
failure?: boolean;
printerId: string;
time: number;
error?: string;
}

export type BatchModel = BatchSingletonModel[];
8 changes: 7 additions & 1 deletion src/models/server/features.model.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,13 @@ export interface IFeatureFlag {

export class FeaturesModel {
batchReprintCalls?: IFeatureFlag;
batchConnectUsbCalls?: IFeatureFlag;
batchConnectSocketCalls?: IFeatureFlag;
}

export type TFeatureFlags = keyof FeaturesModel;
export const featureFlagsList: TFeatureFlags[] = ["batchReprintCalls"];
export const featureFlagsList: TFeatureFlags[] = [
"batchReprintCalls",
"batchConnectUsbCalls",
"batchConnectSocketCalls",
];
6 changes: 3 additions & 3 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import Settings from "../components/Settings/SettingsView.vue";
import AboutHelp from "../components/AboutHelp/AboutView.vue";
import PrintStatisticsView from "@/components/PrintStatistics/PrintStatisticsView.vue";
import FdmSettings from "@/components/Settings/FdmSettings.vue";
import ServerRelatedSettings from "@/components/Settings/ServerRelatedSettings.vue";
import EmergencyCommands from "../components/Settings/EmergencyCommands.vue";
import UserManagementSettings from "@/components/Settings/UserManagementSettings.vue";
import FloorSettings from "@/components/Settings/FloorSettings.vue";
import GridSettings from "../components/Settings/GridSettings.vue";
@@ -49,8 +49,8 @@ const routes: Array<RouteConfig> = [
component: FdmSettings,
},
{
path: "server-related",
component: ServerRelatedSettings,
path: "emergency-commands",
component: EmergencyCommands,
},
],
},

0 comments on commit c2d5b79

Please sign in to comment.