diff --git a/src/components/Torrents.vue b/src/components/Torrents.vue index 0ec5c74..d97844e 100644 --- a/src/components/Torrents.vue +++ b/src/components/Torrents.vue @@ -80,12 +80,16 @@ hide-details /> - {{ row.item.name }} + + {{ row.item.state | stateIcon }} + {{ row.item.name }} + {{ row.item.size | formatSize }} {{ row.item.progress | progressText }} @@ -117,6 +121,84 @@ import { mapState, mapGetters, mapMutations } from 'vuex'; import _ from 'lodash'; import { api } from '../Api'; import { formatSize, formatDuration } from '../filters'; +import { torrentIsState } from '../utils'; +import { StateType } from '../consts'; + +function getStateInfo(state: string) { + let icon; + switch (state) { + case 'metaDL': + case 'allocating': + case 'downloading': + case 'forcedDL': + icon = { + icon: 'download', + color: 'info', + }; + break; + case 'uploading': + case 'forcedUP': + icon = { + icon: 'upload', + color: 'info', + }; + break; + case 'stalledDL': + icon = { + icon: 'download', + color: null, + }; + break; + case 'stalledUP': + icon = { + icon: 'upload', + color: null, + }; + break; + case 'pausedDL': + icon = { + icon: 'pause', + color: 'warning', + }; + break; + case 'pausedUP': + icon = { + icon: 'check', + color: null, + }; + break; + case 'queuedDL': + case 'queuedUP': + icon = { + icon: 'timer-sand', + color: 'info', + }; + break; + case 'checkingDL': + case 'checkingUP': + case 'queuedForChecking': + case 'checkingResumeData': + case 'moving': + icon = { + icon: 'backup-restore', + color: 'info', + }; + break; + case 'error': + case 'unknown': + case 'missingFiles': + icon = { + icon: 'alert', + color: 'error', + }; + break; + default: + throw state; + break; + } + + return icon; +} export default Vue.extend({ name: 'torrents', @@ -209,6 +291,18 @@ export default Vue.extend({ return formatSize(speed) + '/s'; }, + stateIcon(state: string) { + const item = getStateInfo(state); + return 'mdi-' + item.icon; + }, + stateColor(state: string, isProgress?: boolean) { + const item = getStateInfo(state); + if (!isProgress) { + return item.color; + } + + return item.color || '#0008'; + }, }, methods: { @@ -256,6 +350,11 @@ export default Vue.extend({ padding: 0; } +.icon-label { + display: flex; + align-items: center; +} + ::v-deep .v-datatable thead th, .v-datatable tbody td { padding: 0 2px !important; width: auto; diff --git a/src/utils.ts b/src/utils.ts index 848d6dc..805bea5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import _ from 'lodash'; import { StateType } from './consts'; -const dlState = ['downloading', 'metaDL', 'stalledDL', 'checkingDL', 'pausedDL', 'queuedDL', 'forceDL']; +const dlState = ['downloading', 'metaDL', 'stalledDL', 'checkingDL', 'pausedDL', 'queuedDL', 'forceDL', 'allocating']; const upState = ['uploading', 'stalledUP', 'checkingUP', 'queuedUP', 'forceUP']; const completeState = ['uploading', 'stalledUP', 'checkingUP', 'pausedUP', 'queuedUP', 'forceUP']; const activeState = ['metaDL', 'downloading', 'forceDL', 'uploading', 'forcedUP', 'moving'];