diff options
author | patrick <patrick@westberliner.net> | 2021-03-14 12:48:32 +0300 |
---|---|---|
committer | patrick <patrick@westberliner.net> | 2021-03-14 12:48:32 +0300 |
commit | 0cfb1ea7a76c5415d34a7a41258a2fa27163e7fe (patch) | |
tree | d907a2f8adfe5ffe6b7252e22d204b9a9a28f525 | |
parent | 870b016ebb36ae2ced5425a1689fd4c55c56077b (diff) |
Removed support for nc 20.typescript
-rw-r--r-- | .eslintrc.js | 22 | ||||
-rw-r--r-- | appinfo/info.xml | 4 | ||||
-rw-r--r-- | src/main.ts | 69 | ||||
-rw-r--r-- | src/views/ChecksumTab.vue | 5 | ||||
-rw-r--r-- | src/views/ChecksumTab20.vue | 157 |
5 files changed, 46 insertions, 211 deletions
diff --git a/.eslintrc.js b/.eslintrc.js index aeb49d4..8e9eb78 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,12 +1,12 @@ module.exports = { - extends: [ - '@nextcloud' - ], - settings: { - 'import/resolver': { - 'node': { - 'extensions': ['.js', '.ts', 'vue'] - } - } - } -}; + extends: [ + '@nextcloud', + ], + settings: { + 'import/resolver': { + node: { + extensions: ['.js', '.ts', 'vue'], + }, + }, + }, +} diff --git a/appinfo/info.xml b/appinfo/info.xml index 6df22e4..25bec86 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -12,7 +12,7 @@ Select a algorithm and it will try to generate a hash. If you want an other algorithm, just click on the reload button. </description> - <version>1.1.2</version> + <version>1.2.0</version> <licence>agpl</licence> <author>westberliner</author> <types> @@ -29,6 +29,6 @@ <screenshot>https://raw.githubusercontent.com/westberliner/checksum/master/screenshots/checksum.gif</screenshot> <dependencies> <php min-version="7.2" /> - <nextcloud min-version="20" max-version="22" /> + <nextcloud min-version="21" max-version="22" /> </dependencies> </info> diff --git a/src/main.ts b/src/main.ts index 0de694c..7d408b0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -20,6 +20,7 @@ * */ + /// <reference types="@nextcloud/typings" /> declare var OC: Nextcloud.v20.OC @@ -28,50 +29,40 @@ declare var OCA: Checksum.OCA import Vue from 'vue' import { translate as t } from '@nextcloud/l10n' -// @ts-ignore -import ChecksumTab20 from './views/ChecksumTab20' -// @ts-ignore -import ChecksumTab from './views/ChecksumTab' +import ChecksumTab from './views/ChecksumTab.vue' -// Init Sharing tab component -const View = Vue.extend(ChecksumTab) -let tabInstance: Checksum.VueElement | null = null; +let tabInstance: Checksum.VueElement | null = null window.addEventListener('DOMContentLoaded', function() { if (OCA.Files && OCA.Files.Sidebar) { - let checksumTab - if (OC.config.version < '21') { - checksumTab = new OCA.Files.Sidebar.Tab('checksum', ChecksumTab20) - } else { - checksumTab = new OCA.Files.Sidebar.Tab({ - id: 'checksum', - name: t('checksum', 'Checksum'), - icon: 'icon-category-auth', + const checksumTab = new OCA.Files.Sidebar.Tab({ + id: 'checksum', + name: t('checksum', 'Checksum'), + icon: 'icon-category-auth', - mount(el: HTMLElement, fileInfo: Checksum.FileInfo, context: any) { - if (tabInstance) { - tabInstance.$destroy() - } - tabInstance = new View({ - // Better integration with vue parent component - parent: context, - }) - // Only mount after we have all the info we need - tabInstance.update(fileInfo) - tabInstance.$mount(el) - }, - update(fileInfo: Checksum.FileInfo) { - tabInstance?.update(fileInfo) - }, - destroy() { - tabInstance?.$destroy() - tabInstance = null - }, - enabled(fileInfo: Checksum.FileInfo): boolean { - return (fileInfo.type === 'file') - }, - }) - } + mount(el: HTMLElement, fileInfo: Checksum.FileInfo, context: any) { + if (tabInstance) { + tabInstance.$destroy() + } + tabInstance = new ChecksumTab({ + // Better integration with vue parent component + parent: context, + }) + // Only mount after we have all the info we need + tabInstance.update(fileInfo) + tabInstance.$mount(el) + }, + update(fileInfo: Checksum.FileInfo) { + tabInstance?.update(fileInfo) + }, + destroy() { + tabInstance?.$destroy() + tabInstance = null + }, + enabled(fileInfo: Checksum.FileInfo): boolean { + return (fileInfo.type === 'file') + }, + }) OCA.Files.Sidebar.registerTab(checksumTab) } }) diff --git a/src/views/ChecksumTab.vue b/src/views/ChecksumTab.vue index 42de059..9b800f5 100644 --- a/src/views/ChecksumTab.vue +++ b/src/views/ChecksumTab.vue @@ -37,12 +37,13 @@ </template> <script> +import Vue from 'vue' import { generateUrl } from '@nextcloud/router' import axios from '@nextcloud/axios' import Multiselect from '@nextcloud/vue/dist/Components/Multiselect' import Algorithms from '../model/Algorithms.ts' -export default { +export default Vue.extend({ name: 'ChecksumTab', components: { @@ -121,7 +122,7 @@ export default { this.hash = '' }, }, -} +}) </script> <style lang="scss" scoped> diff --git a/src/views/ChecksumTab20.vue b/src/views/ChecksumTab20.vue deleted file mode 100644 index 6a8b405..0000000 --- a/src/views/ChecksumTab20.vue +++ /dev/null @@ -1,157 +0,0 @@ -<!-- - - @copyright Copyright (c) 2021 Patrick Herzberg <patrick@westberliner.net> - - - - @author Patrick Herzberg <patrick@westberliner.net> - - - - @license GNU AGPL version 3 or any later version - - - - This program is free software: you can redistribute it and/or modify - - it under the terms of the GNU Affero General Public License as - - published by the Free Software Foundation, either version 3 of the - - License, or (at your option) any later version. - - - - This program is distributed in the hope that it will be useful, - - but WITHOUT ANY WARRANTY; without even the implied warranty of - - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - - GNU Affero General Public License for more details. - - - - You should have received a copy of the GNU Affero General Public License - - along with this program. If not, see <http://www.gnu.org/licenses/>. - - - --> -<template> - <Tab :id="id" - :icon="icon" - :name="name"> - <!-- checksum content --> - <Multiselect - v-model="algorithm" - :options="algorithms" - track-by="id" - label="label" - @change="onAlgorithmChangeHandler" /> - <br> - <br> - <p :class="{ 'icon-loading': loading }" class="checksum-hash-result"> - <span v-if="!loading && algorithm.id !== ''"><strong>{{ algorithm.label }}:</strong>{{ hash }}</span> - </p> - </Tab> -</template> - -<script> -import { generateUrl } from '@nextcloud/router' -import axios from '@nextcloud/axios' -import Multiselect from '@nextcloud/vue/dist/Components/Multiselect' -import Tab from '@nextcloud/vue/dist/Components/AppSidebarTab' -import Algorithms from '../model/Algorithms.ts' - -export default { - name: 'ChecksumTab20', - - components: { - Tab, - Multiselect, - }, - - mixins: [], - - props: { - fileInfo: { - type: Object, - default: () => {}, - required: true, - }, - }, - - data() { - return { - // Enabled won't work as intended. This is a workaround for now. - icon: (this.fileInfo.type === 'file') ? 'icon-category-auth' : '', - name: t('checksum', 'Checksum'), - loading: false, - algorithm: Algorithms[0], - algorithms: Algorithms, - hash: '', - } - }, - - computed: { - /** - * Needed to differenciate the tabs - * pulled from the AppSidebarTab component. - * - * @returns {string} - */ - id() { - return 'checksum' - }, - - /** - * Allow checksum only on files. - * - * @returns {boolean} - */ - enabled() { - return (this.fileInfo.type === 'file') - }, - - /** - * Returns the current active tab. - * Needed because AppSidebarTab also uses $parent.activeTab. - * - * @returns {string} - */ - activeTab() { - return this.$parent.activeTab - }, - - }, - - methods: { - /** - * Handles selection change event by triggering hash ajax call. - * - * @param {Object} algorithm - The selected algorithm object. - * @param {string} algorithm.id - The selected algorithm id. - * @param {string} algorithm.label - The selected algorithm label. - */ - onAlgorithmChangeHandler(algorithm) { - this.hash = '' - if (algorithm.id.length) { - this.loading = true - this.getChecksum(algorithm.id) - } - }, - - /** - * @param {string} algorithmType - The hasg algorithm type. - */ - getChecksum(algorithmType) { - const url = generateUrl('/apps/checksum/check') - const params = { source: `${this.fileInfo.path}/${this.fileInfo.name}`, type: algorithmType } - axios.get(url, { params }).then(response => { - this.loading = false - this.hash = response.data.msg - }).catch(err => { - console.error(err) - }) - }, - - /** - * Reset the current view to its default state - */ - resetState() { - this.loading = false - this.algorithm = this.Algorithms[0] - this.hash = '' - }, - }, -} -</script> - -<style lang="scss" scoped> - .checksum-hash-result { - text-align: center; - word-wrap: break-word; - } -</style> |