From bcd8ed33895475dfcf2d7e1f3d2bf24883cc005d Mon Sep 17 00:00:00 2001 From: CzBiX Date: Sat, 14 Sep 2019 21:46:00 +0800 Subject: [PATCH] Find same named torrent when set category --- src/components/Torrents.vue | 10 +- .../dialogs/ConfirmDeleteDialog.vue | 25 +--- .../dialogs/ConfirmSetCategoryDialog.vue | 118 ++++++++++++++++++ src/utils.ts | 21 ++++ 4 files changed, 150 insertions(+), 24 deletions(-) create mode 100644 src/components/dialogs/ConfirmSetCategoryDialog.vue diff --git a/src/components/Torrents.vue b/src/components/Torrents.vue index a1ded1d..539fce3 100644 --- a/src/components/Torrents.vue +++ b/src/components/Torrents.vue @@ -141,6 +141,7 @@ + Delete torrents - Are you sure you want to delete the selected torrents from the transfer list? + Are you sure to delete selected torrents from transfer list?
  1. {{ row.name }} @@ -49,6 +49,7 @@ import _ from 'lodash'; import Vue from 'vue'; import api from '@/Api'; import { mapGetters } from 'vuex'; +import { getSameNamedTorrents } from '@/utils'; export default Vue.extend({ props: { @@ -65,7 +66,7 @@ export default Vue.extend({ }, created() { this.torrents = this.value; - this.sameNamedTorrents = this.getSameNamedTorrents(); + this.sameNamedTorrents = getSameNamedTorrents(this.allTorrents, this.torrents); }, computed: { ...mapGetters(['allTorrents']), @@ -77,26 +78,6 @@ export default Vue.extend({ closeDialog() { this.$emit('input', []); }, - getSameNamedTorrents() { - const hashes = _.map(this.torrents, (t) => t.hash); - const result = []; - for (const t1 of this.torrents) { - for (const t2 of this.allTorrents) { - if (hashes.includes(t2.hash)) { - continue; - } - - if (t1.name != t2.name) { - continue; - } - - result.push(t2); - hashes.push(t2); - } - } - - return result; - }, async submit() { if (this.submitting) { return; diff --git a/src/components/dialogs/ConfirmSetCategoryDialog.vue b/src/components/dialogs/ConfirmSetCategoryDialog.vue new file mode 100644 index 0000000..7005ed0 --- /dev/null +++ b/src/components/dialogs/ConfirmSetCategoryDialog.vue @@ -0,0 +1,118 @@ + + + + + diff --git a/src/utils.ts b/src/utils.ts index 0788791..658d34b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -66,3 +66,24 @@ export function codeToFlag(code: string) { } export const isWindows = navigator.userAgent.includes('Windows'); + +export function getSameNamedTorrents(allTorrents: Array, torrents: Array) { + const hashes = _.map(torrents, (t) => t.hash); + const result = []; + for (const t1 of torrents) { + for (const t2 of allTorrents) { + if (hashes.includes(t2.hash)) { + continue; + } + + if (t1.name != t2.name) { + continue; + } + + result.push(t2); + hashes.push(t2); + } + } + + return result; +}; \ No newline at end of file