From 0c70e5b30c7659cc26d90f03f2b01dde1566a7c1 Mon Sep 17 00:00:00 2001 From: CzBiX Date: Tue, 16 Apr 2019 19:32:56 +0800 Subject: [PATCH] Add state fileter --- src/components/Drawer.vue | 98 ++++++++++++++++++++------- src/components/Torrents.vue | 12 ++-- src/components/drawer/FilterGroup.vue | 5 +- src/consts.ts | 55 +++++++-------- src/sites.ts | 30 ++++++++ src/store.ts | 25 ++++++- src/utils.ts | 44 ++++++++++++ 7 files changed, 208 insertions(+), 61 deletions(-) create mode 100644 src/sites.ts create mode 100644 src/utils.ts diff --git a/src/components/Drawer.vue b/src/components/Drawer.vue index a4dc27a..1ab6b5e 100644 --- a/src/components/Drawer.vue +++ b/src/components/Drawer.vue @@ -75,7 +75,50 @@ import FilterGroup from './drawer/FilterGroup.vue'; import { api } from '../Api'; import { mapState, mapMutations, mapGetters } from 'vuex'; import { formatSize } from '../filters'; -import { SiteMap } from '../consts'; +import { SiteMap, StateType, AllStateTypes } from '../consts'; + +const stateList = [ + { + title: 'Downloading', + state: StateType.Downloading, + icon: 'download', + }, + { + title: 'Seeding', + state: StateType.Seeding, + icon: 'upload', + }, + { + title: 'Completed', + state: StateType.Completed, + icon: 'check', + }, + { + title: 'Resumed', + state: StateType.Resumed, + icon: 'play', + }, + { + title: 'Paused', + state: StateType.Paused, + icon: 'pause', + }, + { + title: 'Active', + state: StateType.Active, + icon: 'filter', + }, + { + title: 'Inactive', + state: StateType.Inactive, + icon: 'filter-outline', + }, + { + title: 'Errored', + state: StateType.Errored, + icon: 'alert', + }, +]; export default { components: { @@ -89,23 +132,6 @@ export default { data() { return { basicItems: null, - // { - // 'icon': 'mdi-menu-up', - // 'icon-alt': 'mdi-menu-down', - // 'text': 'Status', - // 'model': true, - // 'children': [ - // { icon: 'mdi-filter-remove', text: 'All' }, - // { icon: 'mdi-download', text: 'Downloading' }, - // { icon: 'mdi-upload', text: 'Seeding' }, - // { icon: 'mdi-check', text: 'Completed' }, - // { icon: 'mdi-play', text: 'Resumed' }, - // { icon: 'mdi-pause', text: 'Paused' }, - // { icon: 'mdi-filter', text: 'Active' }, - // { icon: 'mdi-filter-outline', text: 'Inactive' }, - // { icon: 'mdi-alert', text: 'Errored' }, - // ], - // }, endItems: null, }; }, @@ -126,19 +152,44 @@ export default { 'allTorrents', 'torrentGroupByCategory', 'torrentGroupBySite', + 'torrentGroupByState', ]), items() { if (!this.isDataReady) { return _.concat(this.basicItems, this.endItems); } + const filterGroups = []; + const totalSize = formatSize(_.sumBy(this.allTorrents, 'size')); + + const states = stateList.map((item) => { + let value = this.torrentGroupByState[item.state]; + if (_.isUndefined(value)) { + value = []; + } + const size = formatSize(_.sumBy(value, 'size')); + const title = item.title + ` (${value.length})`; + const append = `[${size}]`; + return { icon: 'mdi-' + item.icon, title, key: item.state, append}; + }); + filterGroups.push({ + 'icon': 'mdi-menu-up', + 'icon-alt': 'mdi-menu-down', + 'title': 'State', + 'model': true, + 'select': 'state', + 'children': [ + { icon: 'mdi-filter-remove', title: `All (${this.allTorrents.length})`, key: null, append: `[${totalSize}]` }, + ...states, + ], + }); + const categories: any[] = _.sortBy(Object.entries(this.torrentGroupByCategory).map(([key, value]) => { const size = formatSize(_.sumBy(value, 'size')); - const title = key ? key : 'Uncategorized'; - const append = `(${value.length})[${size}]`; + const title = (key ? key : 'Uncategorized') + ` (${value.length})`; + const append = `[${size}]`; return { icon: 'mdi-folder-open', title, key, append}; }), 'key'); - const totalSize = formatSize(_.sumBy(this.allTorrents, 'size')); filterGroups.push({ 'icon': 'mdi-menu-up', 'icon-alt': 'mdi-menu-down', @@ -146,7 +197,6 @@ export default { 'model': false, 'select': 'category', 'children': [ - { icon: 'mdi-folder-open', title: 'All', key: null, append: `(${this.allTorrents.length})[${totalSize}]` }, ...categories, ], }); @@ -154,9 +204,9 @@ export default { const sites: any[] = _.sortBy(Object.entries(this.torrentGroupBySite).map(([key, value]) => { const size = formatSize(_.sumBy(value, 'size')); const site = (SiteMap as any)[key]; - const title = site ? site.name : 'Others'; + const title = (site ? site.name : 'Others') + ` (${value.length})`; const icon = _.defaultTo(site ? site.icon : null, 'mdi-server'); - const append = `(${value.length})[${size}]`; + const append = `[${size}]`; return { icon, title, key, append }; }), 'title'); filterGroups.push({ diff --git a/src/components/Torrents.vue b/src/components/Torrents.vue index 9caae05..b9c171b 100644 --- a/src/components/Torrents.vue +++ b/src/components/Torrents.vue @@ -13,20 +13,20 @@ hide-details @click.stop="selectedRows = []" > - + mdi-delete - + mdi-play - + mdi-pause @@ -157,6 +157,7 @@ export default Vue.extend({ 'allTorrents', 'torrentGroupByCategory', 'torrentGroupBySite', + 'torrentGroupByState', ]), ...mapState({ filter(state, getters) { @@ -183,6 +184,9 @@ export default Vue.extend({ if (this.filter.category !== null) { list = _.intersection(list, this.torrentGroupByCategory[this.filter.category]); } + if (this.filter.state !== null) { + list = _.intersection(list, this.torrentGroupByState[this.filter.state]); + } return list; }, diff --git a/src/components/drawer/FilterGroup.vue b/src/components/drawer/FilterGroup.vue index 183b0e0..c8edd5f 100644 --- a/src/components/drawer/FilterGroup.vue +++ b/src/components/drawer/FilterGroup.vue @@ -1,7 +1,7 @@