-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: table column is customizable through settings
- Loading branch information
Showing
5 changed files
with
158 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,137 @@ | ||
<template> | ||
<div class="task-list"> | ||
<b-table | ||
:fields="showTasksFields" | ||
:items="sortedTasks" | ||
responsive | ||
striped | ||
show-empty | ||
thead-tr-class="text-nowrap" | ||
tbody-tr-class="tasks-list__tasks__item" | ||
class="card tasks-list__tasks" | ||
> | ||
<template #empty> | ||
<slot name="empty"> | ||
<p class="text-center m-0" v-html="$t('tasksList.empty')"></p> | ||
</slot> | ||
</template> | ||
<template #cell(state)="{ item }"> | ||
<slot name="status" v-bind="{ item }"> | ||
<ellipse-status :status="item.state" :progress="item.progress * 100" horizontal /> | ||
</slot> | ||
</template> | ||
<template #cell(name)="{ item }"> | ||
<div class="tasks-list__tasks__item__name m-0 fw-bold"> | ||
<slot v-bind="{ item }"> | ||
{{ item.name }} | ||
</slot> | ||
</div> | ||
<div class="d-flex align-items-center"> | ||
<b-badge variant="tertiary" class="tasks-list__tasks__item__id my-1"> | ||
{{ item.id }} | ||
</b-badge> | ||
<template v-if="item.state === 'RUNNING' && stoppable"> | ||
<span class="px-1"> – </span> | ||
<b-button | ||
variant="link" | ||
size="sm" | ||
class="tasks-list__tasks__item__stop text-danger p-0" | ||
@click="stopTask(item.id)" | ||
> | ||
{{ $t('tasksList.stop') }} | ||
</b-button> | ||
</template> | ||
</div> | ||
<div v-if="isBatchDownloadEncrypted(item)" class="font-italic tasks-list__tasks__item__encrypted"> | ||
{{ $t('tasksList.encrypted') }} | ||
</div> | ||
<div v-if="hasZipSize(item)" class="tasks-list__tasks__item__size m-0 fw-bold"> | ||
{{ humanSize(item.result.size, false, $tm('human.size')) }} | ||
</div> | ||
</template> | ||
<template #table-colgroup="{ fields }"> | ||
<col v-for="{ key } in taskFields" :key="key" :style="{ width: key === 'state' ? '140px' : 'auto' }" /> | ||
</template> | ||
</b-table> | ||
</div> | ||
<page-table> | ||
<template #thead> | ||
<page-table-th | ||
v-for="field in columns" | ||
:key="field.name" | ||
:label="field.text" | ||
sortable | ||
emphasis | ||
:name="field.name" | ||
/> | ||
</template> | ||
<page-table-tr v-for="(item, index) in tasks" :key="index"> | ||
<td v-for="(column, i) in columns" :key="i"> | ||
<slot :name="`cell(${column.value})`" v-bind="{ item, column }">{{ item[column.value] }}</slot> | ||
</td> | ||
|
||
<page-table-td-actions> | ||
<button-icon | ||
variant="outline-secondary" | ||
square | ||
hide-label | ||
size="sm" | ||
icon-left="magnifying-glass" | ||
class="border-0 me-1" | ||
/> | ||
<button-icon | ||
variant="outline-secondary" | ||
square | ||
hide-label | ||
size="sm" | ||
icon-left="arrow-clockwise" | ||
class="border-0 me-1" | ||
/> | ||
<button-icon variant="outline-secondary" square hide-label size="sm" icon-left="trash" class="border-0 me-1" /> | ||
</page-table-td-actions> | ||
</page-table-tr> | ||
</page-table> | ||
<!-- <template #empty> | ||
<slot name="empty"> | ||
<p class="text-center m-0" v-html="$t('tasksList.empty')"></p> | ||
</slot> | ||
</template> | ||
<template #cell(state)="{ item }"> | ||
<slot name="status" v-bind="{ item }"> | ||
<ellipse-status :status="item.state" :progress="item.progress * 100" horizontal /> | ||
</slot> | ||
</template> | ||
<template #cell(name)="{ item }"> | ||
<div class="tasks-list__tasks__item__name m-0 fw-bold"> | ||
<slot v-bind="{ item }"> | ||
{{ item.name }} | ||
</slot> | ||
</div> | ||
<div class="d-flex align-items-center"> | ||
<b-badge variant="tertiary" class="tasks-list__tasks__item__id my-1"> | ||
{{ item.id }} | ||
</b-badge> | ||
<template v-if="item.state === 'RUNNING' && stoppable"> | ||
<span class="px-1"> – </span> | ||
<b-button | ||
variant="link" | ||
size="sm" | ||
class="tasks-list__tasks__item__stop text-danger p-0" | ||
@click="stopTask(item.id)" | ||
> | ||
{{ $t('tasksList.stop') }} | ||
</b-button> | ||
</template> | ||
</div> | ||
<div v-if="isBatchDownloadEncrypted(item)" class="font-italic tasks-list__tasks__item__encrypted"> | ||
{{ $t('tasksList.encrypted') }} | ||
</div> | ||
<div v-if="hasZipSize(item)" class="tasks-list__tasks__item__size m-0 fw-bold"> | ||
{{ humanSize(item.result.size, false, $tm('human.size')) }} | ||
</div> | ||
</template> | ||
<template #table-colgroup="{ fields }"> | ||
<col v-for="{ key } in taskFields" :key="key" :style="{ width: key === 'state' ? '140px' : 'auto' }" /> | ||
</template> | ||
</b-table> | ||
</div>--> | ||
</template> | ||
|
||
<script> | ||
<script setup> | ||
import { sortBy } from 'lodash' | ||
import { computed } from 'vue' | ||
import { useStore } from 'vuex' | ||
import EllipseStatus from '@/components/EllipseStatus' | ||
import humanSize from '@/utils/humanSize' | ||
export default { | ||
name: 'TasksList', | ||
components: { | ||
EllipseStatus | ||
defineOptions({ name: 'TaskList' }) | ||
defineProps({ | ||
/** | ||
* Object of tasks passed from the parent | ||
*/ | ||
tasks: { | ||
type: Array | ||
}, | ||
props: { | ||
/** | ||
* Object of tasks passed from the parent | ||
*/ | ||
tasks: { | ||
type: Array | ||
}, | ||
taskFields: { | ||
type: Array | ||
}, | ||
/** | ||
* Display a button to stop the task | ||
*/ | ||
stoppable: { | ||
type: Boolean | ||
} | ||
columns: { | ||
type: Array, | ||
default: () => [] | ||
}, | ||
computed: { | ||
sortedTasks() { | ||
// Move running tasks on top | ||
const states = ['RUNNING'] | ||
return sortBy(this.tasks, ({ state }) => -states.indexOf(state)) | ||
}, | ||
showTasksFields() { | ||
return this.tasks.length ? ['state', 'name'] : this.taskFields | ||
} | ||
}, | ||
methods: { | ||
isBatchDownloadEncrypted(item) { | ||
return item.name.includes('BatchDownload') && item.args.batchDownload.encrypted | ||
}, | ||
hasZipSize(item) { | ||
return item.name.includes('BatchDownload') && item.state !== 'ERROR' && item.result?.size !== undefined | ||
}, | ||
async stopPendingTasks() { | ||
await this.$store.dispatch('indexing/stopPendingTasks') | ||
await this.$store.dispatch('indexing/getTasks') | ||
}, | ||
async stopTask(name) { | ||
await this.$store.dispatch('indexing/stopTask', name) | ||
await this.$store.dispatch('indexing/getTasks') | ||
}, | ||
async deleteDoneTasks() { | ||
await this.$store.dispatch('indexing/deleteDoneTasks') | ||
await this.$store.dispatch('indexing/getTasks') | ||
}, | ||
humanSize | ||
/** | ||
* Display a button to stop the task | ||
*/ | ||
stoppable: { | ||
type: Boolean | ||
} | ||
}) | ||
const store = useStore() | ||
const sortedTasks = computed(() => { | ||
// Move running tasks on top | ||
const states = ['RUNNING'] | ||
return sortBy(this.tasks, ({ state }) => -states.indexOf(state)) | ||
}) | ||
const showTasksFields = computed(() => { | ||
return this.tasks.length ? this.taskFields : [] | ||
}) | ||
function isBatchDownloadEncrypted(item) { | ||
return item.name.includes('BatchDownload') && item.args.batchDownload.encrypted | ||
} | ||
function hasZipSize(item) { | ||
return item.name.includes('BatchDownload') && item.state !== 'ERROR' && item.result?.size !== undefined | ||
} | ||
async function stopPendingTasks() { | ||
await store.dispatch('indexing/stopPendingTasks') | ||
await store.dispatch('indexing/getTasks') | ||
} | ||
async function stopTask(name) { | ||
await store.dispatch('indexing/stopTask', name) | ||
await store.dispatch('indexing/getTasks') | ||
} | ||
async function deleteDoneTasks() { | ||
await store.dispatch('indexing/deleteDoneTasks') | ||
await store.dispatch('indexing/getTasks') | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters