diff --git a/.editorconfig b/.editorconfig index 22e78dcf34..d0b9ea0a22 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,6 @@ trim_trailing_whitespace = true [*.{js,jsx,ts,tsx,vue}] indent_style = space -max_line_length = 100 [*.{md,markdown}] max_line_length = 0 diff --git a/.eslintrc.js b/.eslintrc.js index 9985da1e26..b00dfc044c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,7 +4,8 @@ module.exports = { 'plugin:vue/recommended', 'eslint:recommended', '@vue/standard', - '@vue/eslint-config-typescript/recommended' + '@vue/eslint-config-typescript/recommended', + '@vue/eslint-config-prettier', ], rules: { 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', @@ -14,6 +15,6 @@ module.exports = { 'no-use-before-define': 'off', 'vue/no-v-html': 'off', 'vue/no-v-text-v-html-on-component': 'off', - '@typescript-eslint/no-explicit-any': 'off' - } + '@typescript-eslint/no-explicit-any': 'off', + }, } diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000..4b3dbbdef6 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "semi": false, + "singleQuote": true, + "bracketSameLine": false, + "htmlWhitespaceSensitivity": "ignore", + "singleAttributePerLine": true +} diff --git a/package-lock.json b/package-lock.json index c44be3e02b..53febd5b9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -58,6 +58,7 @@ "@typescript-eslint/eslint-plugin": "^5.42.1", "@typescript-eslint/parser": "^5.42.1", "@vitejs/plugin-vue2": "^2.0.1", + "@vue/eslint-config-prettier": "^7.0.0", "@vue/eslint-config-standard": "^8.0.1", "@vue/eslint-config-typescript": "^11.0.2", "@vue/test-utils": "^1.3.3", @@ -68,6 +69,7 @@ "jsdom": "^20.0.2", "mockdate": "^3.0.5", "monaco-vscode-textmate-theme-converter": "^0.1.7", + "prettier": "^2.7.1", "sass": "~1.32", "shx": "^0.3.4", "standard-version": "^9.5.0", @@ -2743,6 +2745,20 @@ "@vue/shared": "3.2.43" } }, + "node_modules/@vue/eslint-config-prettier": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@vue/eslint-config-prettier/-/eslint-config-prettier-7.0.0.tgz", + "integrity": "sha512-/CTc6ML3Wta1tCe1gUeO0EYnVXfo3nJXsIhZ8WJr3sov+cGASr6yuiibJTL6lmIBm7GobopToOuB3B6AWyV0Iw==", + "dev": true, + "dependencies": { + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-prettier": "^4.0.0" + }, + "peerDependencies": { + "eslint": ">= 7.28.0", + "prettier": ">= 2.0.0" + } + }, "node_modules/@vue/eslint-config-standard": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/@vue/eslint-config-standard/-/eslint-config-standard-8.0.1.tgz", @@ -5048,6 +5064,18 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-config-prettier": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz", + "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==", + "dev": true, + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, "node_modules/eslint-config-standard": { "version": "17.0.0", "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-17.0.0.tgz", @@ -5266,6 +5294,27 @@ "eslint": ">=7.0.0" } }, + "node_modules/eslint-plugin-prettier": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz", + "integrity": "sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==", + "dev": true, + "dependencies": { + "prettier-linter-helpers": "^1.0.0" + }, + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "eslint": ">=7.28.0", + "prettier": ">=2.0.0" + }, + "peerDependenciesMeta": { + "eslint-config-prettier": { + "optional": true + } + } + }, "node_modules/eslint-plugin-promise": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.1.1.tgz", @@ -5493,6 +5542,12 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "node_modules/fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "node_modules/fast-glob": { "version": "3.2.12", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", @@ -7897,6 +7952,33 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/pretty": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/pretty/-/pretty-2.0.0.tgz", @@ -12843,6 +12925,16 @@ "@vue/shared": "3.2.43" } }, + "@vue/eslint-config-prettier": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@vue/eslint-config-prettier/-/eslint-config-prettier-7.0.0.tgz", + "integrity": "sha512-/CTc6ML3Wta1tCe1gUeO0EYnVXfo3nJXsIhZ8WJr3sov+cGASr6yuiibJTL6lmIBm7GobopToOuB3B6AWyV0Iw==", + "dev": true, + "requires": { + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-prettier": "^4.0.0" + } + }, "@vue/eslint-config-standard": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/@vue/eslint-config-standard/-/eslint-config-standard-8.0.1.tgz", @@ -14509,6 +14601,13 @@ } } }, + "eslint-config-prettier": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz", + "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==", + "dev": true, + "requires": {} + }, "eslint-config-standard": { "version": "17.0.0", "resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-17.0.0.tgz", @@ -14668,6 +14767,15 @@ "semver": "^7.3.8" } }, + "eslint-plugin-prettier": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz", + "integrity": "sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, "eslint-plugin-promise": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.1.1.tgz", @@ -14813,6 +14921,12 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-glob": { "version": "3.2.12", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", @@ -16611,6 +16725,21 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prettier": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "dev": true + }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/pretty/-/pretty-2.0.0.tgz", diff --git a/package.json b/package.json index 3d3d5e7350..4cc7dcf8c1 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "serve": "vite", "serve:prod": "vite preview --port 5000", "serve:docs": "cd ./docs; bundle exec jekyll serve", - "lint": "eslint --ext .ts,.js,.vue ./src", + "lint": "eslint --ignore-path .gitignore ./src", + "format": "npm run lint -- --fix", "bootstrap": "husky install", "copy:host:config": "shx cp -f ./server/config.json ./dist/config.json", "deploy:host": "npx --yes -p @0x4447/potato potato -s dist -u -b app.fluidd.xyz -a \"$AWS_ACCESS_KEY_ID\" -t \"$AWS_SECRET_ACCESS_KEY\"", @@ -81,6 +82,7 @@ "@typescript-eslint/eslint-plugin": "^5.42.1", "@typescript-eslint/parser": "^5.42.1", "@vitejs/plugin-vue2": "^2.0.1", + "@vue/eslint-config-prettier": "^7.0.0", "@vue/eslint-config-standard": "^8.0.1", "@vue/eslint-config-typescript": "^11.0.2", "@vue/test-utils": "^1.3.3", @@ -91,6 +93,7 @@ "jsdom": "^20.0.2", "mockdate": "^3.0.5", "monaco-vscode-textmate-theme-converter": "^0.1.7", + "prettier": "^2.7.1", "sass": "~1.32", "shx": "^0.3.4", "standard-version": "^9.5.0", diff --git a/src/App.vue b/src/App.vue index d21ba9a4a4..7ba18ddbdf 100644 --- a/src/App.vue +++ b/src/App.vue @@ -40,16 +40,17 @@ fluid :class="{ 'fill-height': $route.meta && $route.meta.fillHeight, - [['single', 'double', 'triple', 'quad'][columnCount - 1]]: true + [['single', 'double', 'triple', 'quad'][columnCount - 1]]: true, }" class="constrained-width pa-2 pa-sm-4" > @@ -60,7 +61,7 @@ @@ -68,7 +69,8 @@ @@ -86,7 +88,7 @@ import FilesMixin from '@/mixins/files' import { LinkPropertyHref } from 'vue-meta' @Component({ - metaInfo () { + metaInfo() { const pageTitle = this.pageTitle const pageIcon = this.pageIcon @@ -94,10 +96,13 @@ import { LinkPropertyHref } from 'vue-meta' title: pageTitle, link: pageIcon, meta: [ - { name: 'theme-color', content: this.primaryColor } - ] + { + name: 'theme-color', + content: this.primaryColor, + }, + ], } - } + }, }) export default class App extends Mixins(StateMixin, FilesMixin) { toolsdrawer: boolean | null = null @@ -108,39 +113,40 @@ export default class App extends Mixins(StateMixin, FilesMixin) { flashMessageState: FlashMessage = { open: false, text: undefined, - type: undefined + type: undefined, } // Our app is in a loading state when the socket isn't quite ready, or // our translations are loading. - get updating () { + get updating() { return this.$store.state.version.busy } - get inLayout (): boolean { - return (this.$store.state.config.layoutMode) + get inLayout(): boolean { + return this.$store.state.config.layoutMode } - get columnCount () { + get columnCount() { return this.$store.state.config.containerColumnCount } - get loading () { + get loading() { return this.hasWait(this.$waits.onLoadLanguage) } - get progress () { + get progress() { let progress = this.$store.getters['printer/getPrintProgress'] progress = (progress * 100).toFixed() return progress } - get isMobile () { + get isMobile() { return this.$vuetify.breakpoint.mobile } - get pageTitle () { - const instanceName = this.$store.state.config.uiSettings.general.instanceName || '' + get pageTitle() { + const instanceName = + this.$store.state.config.uiSettings.general.instanceName || '' const pageName = this.$route.name if (this.printerPrinting) { @@ -150,7 +156,7 @@ export default class App extends Mixins(StateMixin, FilesMixin) { } } - get pageIcon (): LinkPropertyHref[] { + get pageIcon(): LinkPropertyHref[] { let icon const theme = this.$store.getters['config/getTheme'] if (this.printerPrinting) { @@ -168,7 +174,7 @@ export default class App extends Mixins(StateMixin, FilesMixin) { const lineWidth = 8 const radius = favIconSize / 2 - lineWidth / 2 const startAngle = 1.5 * Math.PI - const endAngle = startAngle + (percent * 2 * Math.PI / 100) + const endAngle = startAngle + (percent * 2 * Math.PI) / 100 /* Draw the initial gray circle */ context.moveTo(centerX, centerY) @@ -191,35 +197,39 @@ export default class App extends Mixins(StateMixin, FilesMixin) { } // Build a base64 encoded version of our svg with the correct theme color. - const svg_xml = 'data:image/svg+xml;base64,' + btoa(``) + const svg_xml = + 'data:image/svg+xml;base64,' + + btoa( + `` + ) return [ { rel: 'icon', type: 'image/svg+xml', sizes: '32x32', - href: icon || svg_xml + href: icon || svg_xml, }, { rel: 'icon', type: 'image/svg+xml', sizes: '16x16', - href: icon || svg_xml - } + href: icon || svg_xml, + }, ] } - get primaryColor () { + get primaryColor() { const theme = this.$store.getters['config/getTheme'] return theme.currentTheme.primary } - get customStyleSheet () { + get customStyleSheet() { return this.$store.getters['config/getCustomThemeFile']('custom', ['.css']) } @Watch('customStyleSheet') - async onCustomStyleSheet (value: string) { + async onCustomStyleSheet(value: string) { if (!value) { return } @@ -243,12 +253,17 @@ export default class App extends Mixins(StateMixin, FilesMixin) { document.head.appendChild(linkElement) } - get customBackgroundImage () { - return this.$store.getters['config/getCustomThemeFile']('background', ['.png', '.jpg', '.jpeg', '.gif']) + get customBackgroundImage() { + return this.$store.getters['config/getCustomThemeFile']('background', [ + '.png', + '.jpg', + '.jpeg', + '.gif', + ]) } @Watch('customBackgroundImage') - async onCustomBackgroundImage (value: string) { + async onCustomBackgroundImage(value: string) { if (!value) { return } @@ -259,28 +274,29 @@ export default class App extends Mixins(StateMixin, FilesMixin) { backgroundImage: `url(${url})`, backgroundSize: 'cover', backgroundAttachment: 'fixed', - backgroundRepeat: 'no-repeat' + backgroundRepeat: 'no-repeat', } } - mounted () { + mounted() { // this.onLoadLocale(this.$i18n.locale) EventBus.bus.$on('flashMessage', (payload: FlashMessage) => { this.flashMessageState.text = (payload && payload.text) || undefined this.flashMessageState.type = (payload && payload.type) || undefined - this.flashMessageState.timeout = (payload && payload.timeout !== undefined) ? payload.timeout : undefined + this.flashMessageState.timeout = + payload && payload.timeout !== undefined ? payload.timeout : undefined this.flashMessageState.open = true }) const legacyElementsSelectors = [ "link[rel*='icon'][type='image/png']", - "meta[name='theme-color']" + "meta[name='theme-color']", ] for (const legacyElementsSelector of legacyElementsSelectors) { const legacyElements = document.querySelectorAll(legacyElementsSelector) - legacyElements.forEach(item => { + legacyElements.forEach((item) => { const parentElement = item.parentElement if (parentElement) { @@ -290,11 +306,11 @@ export default class App extends Mixins(StateMixin, FilesMixin) { } } - handleToolsDrawerChange () { + handleToolsDrawerChange() { this.toolsdrawer = !this.toolsdrawer } - handleNavDrawerChange () { + handleNavDrawerChange() { this.navdrawer = !this.navdrawer } } diff --git a/src/api/httpClientActions.ts b/src/api/httpClientActions.ts index 0d10e21f2f..0c1543635c 100644 --- a/src/api/httpClientActions.ts +++ b/src/api/httpClientActions.ts @@ -2,184 +2,231 @@ import Vue from 'vue' import { AxiosRequestConfig, AxiosResponse } from 'axios' export const httpClientActions = { - get, D = any> (url: string, options?: AxiosRequestConfig) { + get, D = any>( + url: string, + options?: AxiosRequestConfig + ) { return Vue.$httpClient.get(url, options) }, - post, D = any> (url: string, data: any, options?: AxiosRequestConfig) { + post, D = any>( + url: string, + data: any, + options?: AxiosRequestConfig + ) { return Vue.$httpClient.post(url, data, options) }, - delete, D = any> (url: string, options?: AxiosRequestConfig) { + delete, D = any>( + url: string, + options?: AxiosRequestConfig + ) { return Vue.$httpClient.delete(url, options) }, - get defaults () { + get defaults() { return Vue.$httpClient.defaults }, - accessInfoGet (options?: AxiosRequestConfig) { + accessInfoGet(options?: AxiosRequestConfig) { return this.get<{ result: { - default_source: string, + default_source: string available_sources: string[] } }>('/access/info', options) }, - accessRefreshJwtPost (refresh_token: string, options?: AxiosRequestConfig) { + accessRefreshJwtPost(refresh_token: string, options?: AxiosRequestConfig) { return this.post<{ result: { - username: string, - token: string, - action: string, + username: string + token: string + action: string source: string } }>('/access/refresh_jwt', { refresh_token }, options) }, - accessLoginPost (username: string, password: string, source = 'moonraker', options?: AxiosRequestConfig) { + accessLoginPost( + username: string, + password: string, + source = 'moonraker', + options?: AxiosRequestConfig + ) { return this.post<{ result: { - username: string, - token: string, - refresh_token: string, - action: string, + username: string + token: string + refresh_token: string + action: string source: string } - }>('/access/login', { - username, - password, - source - }, options) - }, - - accessLogoutPost (options?: AxiosRequestConfig) { + }>( + '/access/login', + { + username, + password, + source, + }, + options + ) + }, + + accessLogoutPost(options?: AxiosRequestConfig) { return this.post<{ result: { - username: string, + username: string action: string } }>('access/logout', undefined, options) }, - accessOneshotTokenGet (options?: AxiosRequestConfig) { + accessOneshotTokenGet(options?: AxiosRequestConfig) { return this.get<{ result: string }>('/access/oneshot_token', options) }, - accessCurrentUserGet (options?: AxiosRequestConfig) { + accessCurrentUserGet(options?: AxiosRequestConfig) { return this.get<{ result: { - username: string, - source: string, + username: string + source: string created_on: number } }>('/access/user', options) }, - accessUsersListGet (options?: AxiosRequestConfig) { + accessUsersListGet(options?: AxiosRequestConfig) { return this.get<{ result: { users: Array<{ - username: string, - source: string, + username: string + source: string created_on: number }> } }>('/access/users/list', options) }, - accessUserPost (username: string, password: string, options?: AxiosRequestConfig) { + accessUserPost( + username: string, + password: string, + options?: AxiosRequestConfig + ) { return this.post<{ result: { - username: string, - token: string, - refresh_token: string, - action: string, + username: string + token: string + refresh_token: string + action: string source: string } - }>('/access/user', { - username, - password - }, options) + }>( + '/access/user', + { + username, + password, + }, + options + ) }, - accessUserDelete (username: string, options?: AxiosRequestConfig) { + accessUserDelete(username: string, options?: AxiosRequestConfig) { return this.delete<{ result: { - username: string, + username: string action: string } }>('/access/user', { ...options, - params: { username } + params: { username }, }) }, - accessUserPasswordPost (password: string, new_password: string, options?: AxiosRequestConfig) { + accessUserPasswordPost( + password: string, + new_password: string, + options?: AxiosRequestConfig + ) { return this.post<{ result: { - username: string, + username: string action: string } - }>('/access/user/password', { - password, - new_password - }, options) + }>( + '/access/user/password', + { + password, + new_password, + }, + options + ) }, - accessApiKeyGet (options?: AxiosRequestConfig) { + accessApiKeyGet(options?: AxiosRequestConfig) { return this.get<{ result: string }>('/access/api_key', options) }, - accessApiKeyPost (options?: AxiosRequestConfig) { + accessApiKeyPost(options?: AxiosRequestConfig) { return this.post<{ result: string }>('/access/api_key', undefined, options) }, - serverDatabaseItemGet (namespace: string, options?: AxiosRequestConfig) { + serverDatabaseItemGet( + namespace: string, + options?: AxiosRequestConfig + ) { return this.get<{ result: { - namespace: string, - key: string, + namespace: string + key: string value: T } }>(`/server/database/item?namespace=${namespace}`, options) }, - serverDatabaseItemPost (namespace: string, key: string, value: T, options?: AxiosRequestConfig) { + serverDatabaseItemPost( + namespace: string, + key: string, + value: T, + options?: AxiosRequestConfig + ) { return this.post<{ result: { - namespace: string, - key: string, + namespace: string + key: string value: T } - }>('/server/database/item', { - namespace, - key, - value - }, options) - }, - - serverFilesUploadPost (data: FormData, options?: AxiosRequestConfig) { + }>( + '/server/database/item', + { + namespace, + key, + value, + }, + options + ) + }, + + serverFilesUploadPost(data: FormData, options?: AxiosRequestConfig) { return this.post<{ result: { item: { - path: string, + path: string root: string } - print_started?: boolean, + print_started?: boolean action: string } }>('/server/files/upload', data, options) }, - serverFilesGet (filepath: string, options?: AxiosRequestConfig) { + serverFilesGet(filepath: string, options?: AxiosRequestConfig) { return this.get(`/server/files/${filepath}?date=${Date.now()}`, options) - } + }, } diff --git a/src/api/socketActions.ts b/src/api/socketActions.ts index 5c72f28ef2..5a65c6ae64 100644 --- a/src/api/socketActions.ts +++ b/src/api/socketActions.ts @@ -13,448 +13,380 @@ const baseEmit = (method: string, options: NotifyOptions) => { } export const SocketActions = { - async machineServicesRestart (service: string) { + async machineServicesRestart(service: string) { const wait = Waits.onServiceRestart - baseEmit( - 'machine.services.restart', { - dispatch: 'void', - params: { service }, - wait - } - ) + baseEmit('machine.services.restart', { + dispatch: 'void', + params: { service }, + wait, + }) }, - async machineServicesStart (service: string) { + async machineServicesStart(service: string) { const wait = Waits.onServiceStart - baseEmit( - 'machine.services.start', { - dispatch: 'void', - params: { service }, - wait - } - ) + baseEmit('machine.services.start', { + dispatch: 'void', + params: { service }, + wait, + }) }, - async machineServicesStop (service: string) { + async machineServicesStop(service: string) { const wait = Waits.onServiceStop - baseEmit( - 'machine.services.stop', { - dispatch: 'void', - params: { service }, - wait - } - ) - }, - - async machineReboot () { - baseEmit( - 'machine.reboot', { - dispatch: 'void' - } - ) - }, - - async machineShutdown () { - baseEmit( - 'machine.shutdown', { - dispatch: 'void' - } - ) - }, - - async machineUpdateStatus (refresh = false) { - baseEmit( - 'machine.update.status', { - dispatch: 'version/onUpdateStatus', - params: { refresh }, - wait: Waits.onVersionRefresh - } - ) - }, - - async machineUpdateRecover (name: string, hard = false) { + baseEmit('machine.services.stop', { + dispatch: 'void', + params: { service }, + wait, + }) + }, + + async machineReboot() { + baseEmit('machine.reboot', { + dispatch: 'void', + }) + }, + + async machineShutdown() { + baseEmit('machine.shutdown', { + dispatch: 'void', + }) + }, + + async machineUpdateStatus(refresh = false) { + baseEmit('machine.update.status', { + dispatch: 'version/onUpdateStatus', + params: { refresh }, + wait: Waits.onVersionRefresh, + }) + }, + + async machineUpdateRecover(name: string, hard = false) { let dispatch = 'version/onUpdatedClient' if (name === 'moonraker') dispatch = 'version/onUpdatedMoonraker' if (name === 'klipper') dispatch = 'version/onUpdatedKlipper' - baseEmit( - 'machine.update.recover', { - dispatch, - params: { name, hard } - } - ) - }, - - async machineUpdateMoonraker () { - baseEmit( - 'machine.update.moonraker', { - dispatch: 'version/onUpdatedMoonraker' - } - ) - }, - - async machineUpdateKlipper () { - baseEmit( - 'machine.update.klipper', { - dispatch: 'version/onUpdatedKlipper', - params: { - include_deps: true - } - } - ) - }, - - async machineUpdateClient (name: string) { + baseEmit('machine.update.recover', { + dispatch, + params: { name, hard }, + }) + }, + + async machineUpdateMoonraker() { + baseEmit('machine.update.moonraker', { + dispatch: 'version/onUpdatedMoonraker', + }) + }, + + async machineUpdateKlipper() { + baseEmit('machine.update.klipper', { + dispatch: 'version/onUpdatedKlipper', + params: { + include_deps: true, + }, + }) + }, + + async machineUpdateClient(name: string) { let dispatch = 'version/onUpdatedClient' if (name === 'fluidd') dispatch = 'version/onUpdatedFluidd' - baseEmit( - 'machine.update.client', { - dispatch, - params: { name } - } - ) - }, - - async machineUpdateSystem () { - baseEmit( - 'machine.update.system', { - dispatch: 'version/onUpdatedSystem' - } - ) - }, - - async machineUpdateAll () { - baseEmit( - 'machine.update.full', { - dispatch: 'version/onUpdatedAll' - } - ) - }, - - async machineProcStats () { - baseEmit( - 'machine.proc_stats', { - dispatch: 'server/onMachineProcStats' - } - ) - }, - - async machineSystemInfo () { - baseEmit( - 'machine.system_info', { - dispatch: 'server/onMachineSystemInfo' - } - ) - }, - - async machineDevicePowerDevices () { - baseEmit( - 'machine.device_power.devices', { - dispatch: 'power/onInit' - } - ) - }, - - async machineDevicePowerStatus (device: string) { - baseEmit( - 'machine.device_power.status', { - dispatch: 'power/onStatus', - params: { [device]: null } - } - ) - }, - - async machineDevicePowerToggle (device: string, state: string, wait?: string) { - const emit = (state === 'on') - ? 'machine.device_power.on' - : 'machine.device_power.off' - baseEmit( - emit, { - dispatch: 'power/onToggle', - params: { [device]: null }, - wait - } - ) - }, - - async machineTimelapseSetSettings (settings: Partial, wait?: string) { - baseEmit( - 'machine.timelapse.post_settings', { - dispatch: 'timelapse/onSettings', - params: settings, - wait - } - ) - }, - - async machineTimelapseSaveFrames (wait?: string) { - baseEmit( - 'machine.timelapse.saveframes', { - wait - } - ) - }, - - async machineTimelapseRender () { + baseEmit('machine.update.client', { + dispatch, + params: { name }, + }) + }, + + async machineUpdateSystem() { + baseEmit('machine.update.system', { + dispatch: 'version/onUpdatedSystem', + }) + }, + + async machineUpdateAll() { + baseEmit('machine.update.full', { + dispatch: 'version/onUpdatedAll', + }) + }, + + async machineProcStats() { + baseEmit('machine.proc_stats', { + dispatch: 'server/onMachineProcStats', + }) + }, + + async machineSystemInfo() { + baseEmit('machine.system_info', { + dispatch: 'server/onMachineSystemInfo', + }) + }, + + async machineDevicePowerDevices() { + baseEmit('machine.device_power.devices', { + dispatch: 'power/onInit', + }) + }, + + async machineDevicePowerStatus(device: string) { + baseEmit('machine.device_power.status', { + dispatch: 'power/onStatus', + params: { [device]: null }, + }) + }, + + async machineDevicePowerToggle(device: string, state: string, wait?: string) { + const emit = + state === 'on' ? 'machine.device_power.on' : 'machine.device_power.off' + baseEmit(emit, { + dispatch: 'power/onToggle', + params: { [device]: null }, + wait, + }) + }, + + async machineTimelapseSetSettings( + settings: Partial, + wait?: string + ) { + baseEmit('machine.timelapse.post_settings', { + dispatch: 'timelapse/onSettings', + params: settings, + wait, + }) + }, + + async machineTimelapseSaveFrames(wait?: string) { + baseEmit('machine.timelapse.saveframes', { + wait, + }) + }, + + async machineTimelapseRender() { baseEmit('machine.timelapse.render', {}) }, - async printerInfo () { - baseEmit( - 'printer.info', { - dispatch: 'printer/onPrinterInfo' - } - ) - }, - - async printerRestart () { - baseEmit( - 'printer.restart', { - dispatch: 'void', - wait: Waits.onKlipperRestart - } - ) - }, - - async printerFirmwareRestart () { - baseEmit( - 'printer.firmware_restart', { - dispatch: 'void', - wait: Waits.onKlipperFirmwareRestart - } - ) - }, - - async printerQueryEndstops () { - baseEmit( - 'printer.query_endstops.status', { - dispatch: 'printer/onQueryEndstops', - wait: Waits.onQueryEndstops - } - ) - }, - - async printerObjectsList () { - baseEmit( - 'printer.objects.list', { - dispatch: 'printer/onPrinterObjectsList' - } - ) - }, - - async printerObjectsSubscribe (objects: {[key: string]: null}) { - baseEmit( - 'printer.objects.subscribe', { - dispatch: 'printer/onPrinterObjectsSubscribe', - params: { - objects - } - } - ) - }, - - async printerPrintStart (path: string) { - baseEmit( - 'printer.print.start', { - dispatch: 'void', - params: { - filename: path - } - } - ) - }, - - async printerPrintCancel () { - baseEmit( - 'printer.print.cancel', { - dispatch: 'printer/onPrintCancel', - wait: Waits.onPrintCancel - } - ) - }, - - async printerPrintPause () { - baseEmit( - 'printer.print.pause', { - dispatch: 'printer/onPrintPause', - wait: Waits.onPrintPause - } - ) - }, - - async printerPrintResume () { - baseEmit( - 'printer.print.resume', { - dispatch: 'printer/onPrintResume', - wait: Waits.onPrintResume - } - ) - }, - - async printerGcodeScript (gcode: string, wait?: string) { - baseEmit( - 'printer.gcode.script', { - dispatch: 'console/onGcodeScript', - params: { - script: gcode - }, - wait - } - ) - }, - - async printerGcodeHelp () { - baseEmit( - 'printer.gcode.help', { - dispatch: 'console/onGcodeHelp' - } - ) - }, - - async printerEmergencyStop () { - baseEmit( - 'printer.emergency_stop', { - dispatch: 'void' - } - ) - }, - - async serverInfo () { - baseEmit( - 'server.info', { - dispatch: 'server/onServerInfo' - } - ) - }, - - async identify (params?: { client_name: string, version: string, type: string, url: string }) { + async printerInfo() { + baseEmit('printer.info', { + dispatch: 'printer/onPrinterInfo', + }) + }, + + async printerRestart() { + baseEmit('printer.restart', { + dispatch: 'void', + wait: Waits.onKlipperRestart, + }) + }, + + async printerFirmwareRestart() { + baseEmit('printer.firmware_restart', { + dispatch: 'void', + wait: Waits.onKlipperFirmwareRestart, + }) + }, + + async printerQueryEndstops() { + baseEmit('printer.query_endstops.status', { + dispatch: 'printer/onQueryEndstops', + wait: Waits.onQueryEndstops, + }) + }, + + async printerObjectsList() { + baseEmit('printer.objects.list', { + dispatch: 'printer/onPrinterObjectsList', + }) + }, + + async printerObjectsSubscribe(objects: { [key: string]: null }) { + baseEmit('printer.objects.subscribe', { + dispatch: 'printer/onPrinterObjectsSubscribe', + params: { + objects, + }, + }) + }, + + async printerPrintStart(path: string) { + baseEmit('printer.print.start', { + dispatch: 'void', + params: { + filename: path, + }, + }) + }, + + async printerPrintCancel() { + baseEmit('printer.print.cancel', { + dispatch: 'printer/onPrintCancel', + wait: Waits.onPrintCancel, + }) + }, + + async printerPrintPause() { + baseEmit('printer.print.pause', { + dispatch: 'printer/onPrintPause', + wait: Waits.onPrintPause, + }) + }, + + async printerPrintResume() { + baseEmit('printer.print.resume', { + dispatch: 'printer/onPrintResume', + wait: Waits.onPrintResume, + }) + }, + + async printerGcodeScript(gcode: string, wait?: string) { + baseEmit('printer.gcode.script', { + dispatch: 'console/onGcodeScript', + params: { + script: gcode, + }, + wait, + }) + }, + + async printerGcodeHelp() { + baseEmit('printer.gcode.help', { + dispatch: 'console/onGcodeHelp', + }) + }, + + async printerEmergencyStop() { + baseEmit('printer.emergency_stop', { + dispatch: 'void', + }) + }, + + async serverInfo() { + baseEmit('server.info', { + dispatch: 'server/onServerInfo', + }) + }, + + async identify(params?: { + client_name: string + version: string + type: string + url: string + }) { baseEmit('server.connection.identify', { dispatch: 'socket/onConnectionId', - params + params, }) }, - async timelapseState () { - baseEmit( - 'machine.timelapse.get_settings', { - dispatch: 'timelapse/onSettings' - } - ) + async timelapseState() { + baseEmit('machine.timelapse.get_settings', { + dispatch: 'timelapse/onSettings', + }) - baseEmit( - 'machine.timelapse.lastframeinfo', { - dispatch: 'timelapse/onLastFrame' - } - ) + baseEmit('machine.timelapse.lastframeinfo', { + dispatch: 'timelapse/onLastFrame', + }) }, - async serverConfig () { - baseEmit( - 'server.config', { - dispatch: 'server/onServerConfig' - } - ) + async serverConfig() { + baseEmit('server.config', { + dispatch: 'server/onServerConfig', + }) }, /** * Writes data to moonraker's DB. */ - async serverWrite (key: string, value: any, namespace: string = Globals.MOONRAKER_DB.fluidd.NAMESPACE) { - baseEmit( - 'server.database.post_item', { - params: { - namespace, - key, - value - } - } - ) - }, - - async serverDelete (key: string, namespace: string = Globals.MOONRAKER_DB.fluidd.NAMESPACE) { - baseEmit( - 'server.database.delete_item', { - params: { - namespace, - key - } - } - ) - }, - - async serverRead (key?: string, namespace: string = Globals.MOONRAKER_DB.fluidd.NAMESPACE) { - baseEmit( - 'server.database.get_item', { - dispatch: 'socket/onServerRead', - params: { - namespace, - key - } - } - ) - }, - - async serverRestart () { - baseEmit( - 'server.restart', { - dispatch: 'void' - } - ) - }, - - async serverTemperatureStore () { - baseEmit( - 'server.temperature_store', { - dispatch: 'charts/initTempStore' - } - ) - }, - - async serverGcodeStore () { - baseEmit( - 'server.gcode_store', { - dispatch: 'console/onGcodeStore' - } - ) - }, - - async serverHistoryList (params?: { start?: number; limit?: number; before?: number; since?: number; order?: string }) { - baseEmit( - 'server.history.list', { - dispatch: 'history/onHistoryList', - params - } - ) - }, - - async serverHistoryTotals () { - baseEmit( - 'server.history.totals', { - dispatch: 'history/onHistoryTotals' - } - ) - }, - - async serverHistoryDeleteJob (uid: string) { - const params = uid === 'all' - ? { - all: true - } - : { uid } - - baseEmit( - 'server.history.delete_job', { - dispatch: 'history/onDelete', - params - } - ) - }, - - async serverHistoryResetTotals () { - baseEmit( - 'server.history.reset_totals', { - dispatch: 'history/onHistoryChange' - } - ) + async serverWrite( + key: string, + value: any, + namespace: string = Globals.MOONRAKER_DB.fluidd.NAMESPACE + ) { + baseEmit('server.database.post_item', { + params: { + namespace, + key, + value, + }, + }) + }, + + async serverDelete( + key: string, + namespace: string = Globals.MOONRAKER_DB.fluidd.NAMESPACE + ) { + baseEmit('server.database.delete_item', { + params: { + namespace, + key, + }, + }) + }, + + async serverRead( + key?: string, + namespace: string = Globals.MOONRAKER_DB.fluidd.NAMESPACE + ) { + baseEmit('server.database.get_item', { + dispatch: 'socket/onServerRead', + params: { + namespace, + key, + }, + }) + }, + + async serverRestart() { + baseEmit('server.restart', { + dispatch: 'void', + }) + }, + + async serverTemperatureStore() { + baseEmit('server.temperature_store', { + dispatch: 'charts/initTempStore', + }) + }, + + async serverGcodeStore() { + baseEmit('server.gcode_store', { + dispatch: 'console/onGcodeStore', + }) + }, + + async serverHistoryList(params?: { + start?: number + limit?: number + before?: number + since?: number + order?: string + }) { + baseEmit('server.history.list', { + dispatch: 'history/onHistoryList', + params, + }) + }, + + async serverHistoryTotals() { + baseEmit('server.history.totals', { + dispatch: 'history/onHistoryTotals', + }) + }, + + async serverHistoryDeleteJob(uid: string) { + const params = + uid === 'all' + ? { + all: true, + } + : { uid } + + baseEmit('server.history.delete_job', { + dispatch: 'history/onDelete', + params, + }) + }, + + async serverHistoryResetTotals() { + baseEmit('server.history.reset_totals', { + dispatch: 'history/onHistoryChange', + }) }, /** @@ -462,126 +394,104 @@ export const SocketActions = { * Expects the full path including root. * Optionally pass the just the filename and path. */ - async serverFilesMetaData (filepath: string) { - baseEmit( - 'server.files.metadata', { - dispatch: 'files/onFileMetaData', - params: { filename: filepath } - } - ) + async serverFilesMetaData(filepath: string) { + baseEmit('server.files.metadata', { + dispatch: 'files/onFileMetaData', + params: { filename: filepath }, + }) }, /** * This only requires path, but we pass root along too * for brevity. */ - async serverFilesGetDirectory (root: string, path: string) { + async serverFilesGetDirectory(root: string, path: string) { const wait = `${Waits.onFileSystem}${path}` - baseEmit( - 'server.files.get_directory', - { - dispatch: 'files/onServerFilesGetDirectory', - wait, - params: { root, path, extended: true } - } - ) + baseEmit('server.files.get_directory', { + dispatch: 'files/onServerFilesGetDirectory', + wait, + params: { root, path, extended: true }, + }) }, - async serverFilesListRoot (root: string) { + async serverFilesListRoot(root: string) { const wait = `${Waits.onFileSystem}${root}` - baseEmit( - 'server.files.list', - { - dispatch: 'files/onServerFilesListRoot', - wait, - params: { root } - } - ) + baseEmit('server.files.list', { + dispatch: 'files/onServerFilesListRoot', + wait, + params: { root }, + }) }, - async serverFilesMove (source: string, dest: string) { + async serverFilesMove(source: string, dest: string) { const wait = Waits.onFileSystem - baseEmit( - 'server.files.move', { - dispatch: 'void', - wait, - params: { - source, - dest - } - } - ) + baseEmit('server.files.move', { + dispatch: 'void', + wait, + params: { + source, + dest, + }, + }) }, /** * Create a directory. * Root should be included in the path. */ - async serverFilesPostDirectory (path: string) { + async serverFilesPostDirectory(path: string) { const wait = Waits.onFileSystem - baseEmit( - 'server.files.post_directory', { - dispatch: 'void', - wait, - params: { - path - } - } - ) - }, - - async serverFilesDeleteFile (path: string) { + baseEmit('server.files.post_directory', { + dispatch: 'void', + wait, + params: { + path, + }, + }) + }, + + async serverFilesDeleteFile(path: string) { const wait = Waits.onFileSystem - baseEmit( - 'server.files.delete_file', { - dispatch: 'void', - wait, - params: { - path - } - } - ) - }, - - async serverFilesDeleteDirectory (path: string, force = false) { + baseEmit('server.files.delete_file', { + dispatch: 'void', + wait, + params: { + path, + }, + }) + }, + + async serverFilesDeleteDirectory(path: string, force = false) { const wait = Waits.onFileSystem - baseEmit( - 'server.files.delete_directory', { - dispatch: 'void', - wait, - params: { - path, - force - } - } - ) - }, - - async serverAnnouncementsList () { - baseEmit( - 'server.announcements.list', { - dispatch: 'announcements/onAnnouncementsList' - } - ) - }, - - async serverAnnouncementsDismiss (entry_id: string, wake_time?: number) { - baseEmit( - 'server.announcements.dismiss', { - dispatch: 'void', - params: { - entry_id, - wake_time - } - } - ) - }, - - async serverWebcamsList () { - baseEmit( - 'server.webcams.list', { - dispatch: 'webcams/onWebcamsList' - } - ) - } + baseEmit('server.files.delete_directory', { + dispatch: 'void', + wait, + params: { + path, + force, + }, + }) + }, + + async serverAnnouncementsList() { + baseEmit('server.announcements.list', { + dispatch: 'announcements/onAnnouncementsList', + }) + }, + + async serverAnnouncementsDismiss(entry_id: string, wake_time?: number) { + baseEmit('server.announcements.dismiss', { + dispatch: 'void', + params: { + entry_id, + wake_time, + }, + }) + }, + + async serverWebcamsList() { + baseEmit('server.webcams.list', { + dispatch: 'webcams/onWebcamsList', + }) + }, } diff --git a/src/components/common/AddInstanceDialog.vue b/src/components/common/AddInstanceDialog.vue index fc4d8ebffd..1e7ba26b60 100644 --- a/src/components/common/AddInstanceDialog.vue +++ b/src/components/common/AddInstanceDialog.vue @@ -11,7 +11,9 @@ > - {{ $t('app.general.title.add_printer') }} + + {{ $t('app.general.title.add_printer') }} + @@ -28,10 +30,7 @@ persistent-hint :hint="$t('app.endpoint.hint.add_printer')" :loading="verifying" - :rules="[ - $rules.required, - customRules.url - ]" + :rules="[$rules.required, customRules.url]" >