2023-08-03 22:03:40 +08:00
|
|
|
<template>
|
|
|
|
<div class="result-toolbar p-3 flex justify-between rounded-md bg-sn-white">
|
|
|
|
<div class="result-toolbar__left">
|
2023-09-06 20:58:59 +08:00
|
|
|
<button v-if="canCreate" class="btn btn-secondary" @click="$emit('newResult')">
|
2023-08-03 22:03:40 +08:00
|
|
|
<i class="sn-icon sn-icon-new-task"></i>
|
|
|
|
{{ i18n.t('my_modules.results.add_label') }}
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-08-04 23:06:32 +08:00
|
|
|
<div class="result-toolbar__right flex items-center" @click="$emit('expandAll')">
|
2023-08-03 22:03:40 +08:00
|
|
|
<button class="btn btn-secondary mr-3">
|
|
|
|
{{ i18n.t('my_modules.results.expand_label') }}
|
|
|
|
</button>
|
2023-08-04 23:06:32 +08:00
|
|
|
<button class="btn btn-secondary mr-3" @click="$emit('collapseAll')">
|
2023-08-03 22:03:40 +08:00
|
|
|
{{ i18n.t('my_modules.results.collapse_label') }}
|
|
|
|
</button>
|
|
|
|
|
2023-08-23 17:59:21 +08:00
|
|
|
<FilterDropdown :filters="filters" @applyFilters="setFilters" />
|
2023-08-04 23:06:32 +08:00
|
|
|
|
|
|
|
<div class="dropdown">
|
|
|
|
<button class="dropdown-toggle btn btn-light icon-btn mr-3" id="sortDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
|
|
|
<i class="sn-icon sn-icon-sort"></i>
|
|
|
|
</button>
|
|
|
|
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="sortDropdown">
|
2023-08-07 21:23:02 +08:00
|
|
|
<li v-for="sort in sorts" :key="sort">
|
|
|
|
<a class="cursor-pointer" @click="setSort(sort)">
|
|
|
|
{{ i18n.t(`my_modules.results.sorts.${sort}`)}}
|
2023-08-04 23:06:32 +08:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2023-08-03 22:03:40 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-08-07 21:23:02 +08:00
|
|
|
const SORTS = [
|
|
|
|
'updated_at_asc',
|
|
|
|
'updated_at_desc',
|
|
|
|
'created_at_asc',
|
|
|
|
'created_at_desc',
|
|
|
|
'name_asc',
|
|
|
|
'name_desc'
|
|
|
|
];
|
|
|
|
|
2023-08-23 17:59:21 +08:00
|
|
|
import FilterDropdown from '../shared/filters/filter_dropdown.vue';
|
|
|
|
|
2023-08-03 22:03:40 +08:00
|
|
|
export default {
|
|
|
|
name: 'ResultsToolbar',
|
|
|
|
props: {
|
2023-08-23 17:59:21 +08:00
|
|
|
sort: { type: String, required: true },
|
2023-09-06 20:58:59 +08:00
|
|
|
canCreate: { type: Boolean, required: true }
|
2023-08-04 23:06:32 +08:00
|
|
|
},
|
2023-08-23 17:59:21 +08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
filters: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: { FilterDropdown },
|
2023-08-07 21:23:02 +08:00
|
|
|
created() {
|
2023-08-23 17:59:21 +08:00
|
|
|
this.filters = [
|
|
|
|
{
|
|
|
|
key: 'query',
|
|
|
|
type: 'Text',
|
|
|
|
label: this.i18n.t('my_modules.results.filters.query.label'),
|
|
|
|
placeholder: this.i18n.t('my_modules.results.filters.query.placeholder')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'created_at',
|
|
|
|
type: 'DateRange',
|
|
|
|
label: this.i18n.t('my_modules.results.filters.created_at.label')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'updated_at',
|
|
|
|
type: 'DateRange',
|
|
|
|
label: this.i18n.t('my_modules.results.filters.updated_at.label')
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-08-07 21:23:02 +08:00
|
|
|
this.sorts = SORTS;
|
|
|
|
},
|
2023-08-04 23:06:32 +08:00
|
|
|
methods: {
|
|
|
|
setSort(sort) {
|
|
|
|
this.$emit('setSort', sort);
|
2023-08-23 17:59:21 +08:00
|
|
|
},
|
|
|
|
setFilters(filters) {
|
|
|
|
this.$emit('setFilters', filters);
|
2023-08-04 23:06:32 +08:00
|
|
|
}
|
2023-08-03 22:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|