scinote-web/app/javascript/vue/shared/datatable/toolbar.vue

191 lines
4.9 KiB
Vue
Raw Normal View History

<template>
2023-11-24 18:08:28 +08:00
<div class="flex py-4 items-center justify-between">
<div class="flex items-center gap-4">
<a v-for="action in toolbarActions.left" :key="action.label"
:class="action.buttonStyle"
:href="action.path"
@click="doAction(action, $event)">
<i :class="action.icon"></i>
{{ action.label }}
</a>
</div>
2023-11-24 18:08:28 +08:00
<div>
2023-12-12 19:17:38 +08:00
<div class="flex items-center gap-2">
2023-11-24 18:08:28 +08:00
<MenuDropdown
2023-12-01 07:01:08 +08:00
v-if="archivedPageUrl"
:listItems="this.viewRendersMenu"
:btnClasses="'btn btn-light icon-btn'"
:btnText="i18n.t(`toolbar.${currentViewRender}_view`)"
:caret="true"
:position="'right'"
@setCardsView="$emit('setCardsView')"
@setTableView="$emit('setTableView')"
></MenuDropdown>
<MenuDropdown
v-if="archivedPageUrl"
:listItems="this.viewModesMenu"
2023-11-24 18:08:28 +08:00
:btnClasses="'btn btn-light icon-btn'"
:btnText="i18n.t(`projects.index.${currentViewMode}`)"
:caret="true"
:position="'right'"
></MenuDropdown>
</div>
</div>
2023-12-12 19:17:38 +08:00
<div class="flex items-center gap-2">
<a v-for="action in toolbarActions.right" :key="action.label"
:class="action.buttonStyle"
:href="action.path"
@click="doAction(action, $event)">
<i :class="action.icon"></i>
{{ action.label }}
</a>
2023-12-12 19:17:38 +08:00
<button
v-if="currentViewRender === 'table'"
@click="showColumnsModal = true"
class="btn btn-light icon-btn"
>
<i class="sn-icon sn-icon-reports"></i>
</button>
2023-12-11 16:18:22 +08:00
<div v-if="filters.length == 0"
class="sci-input-container-v2"
:class="{'w-48': showSearch, 'w-11': !showSearch}">
<input
ref="searchInput"
class="sci-input-field !pr-8"
type="text"
@focus="openSearch"
@blur="hideSearch"
:value="searchValue"
:placeholder="'Search...'"
@change="$emit('search:change', $event.target.value)"
/>
<i class="sn-icon sn-icon-search !m-2.5 !ml-auto right-0"></i>
</div>
2023-11-24 18:08:28 +08:00
<FilterDropdown v-else :filters="filters" @applyFilters="applyFilters" />
</div>
2023-12-12 19:17:38 +08:00
<teleport to="body">
<ColumnsModal
:tableState="tableState"
:columnDefs="columnDefs"
@hideColumn="(column) => $emit('hideColumn', column)"
@showColumn="(column) => $emit('showColumn', column)"
v-if="showColumnsModal"
@close="showColumnsModal = false" />
</teleport>
</div>
</template>
<script>
2023-12-11 16:18:22 +08:00
import MenuDropdown from '../menu_dropdown.vue';
2023-11-24 18:08:28 +08:00
import FilterDropdown from '../filters/filter_dropdown.vue';
2023-12-12 19:17:38 +08:00
import ColumnsModal from './modals/columns.vue';
2023-11-24 18:08:28 +08:00
export default {
name: 'Toolbar',
props: {
toolbarActions: {
type: Object,
2023-12-12 19:17:38 +08:00
required: true
},
searchValue: {
2023-12-12 19:17:38 +08:00
type: String
2023-11-24 18:08:28 +08:00
},
activePageUrl: {
2023-12-12 19:17:38 +08:00
type: String
2023-11-24 18:08:28 +08:00
},
archivedPageUrl: {
2023-12-12 19:17:38 +08:00
type: String
2023-11-24 18:08:28 +08:00
},
currentViewMode: {
type: String,
2023-12-12 19:17:38 +08:00
default: 'active'
2023-11-24 18:08:28 +08:00
},
filters: {
type: Array,
2023-12-12 19:17:38 +08:00
default: () => []
2023-12-01 07:01:08 +08:00
},
viewRenders: {
type: Array,
2023-12-12 19:17:38 +08:00
required: true
2023-12-01 07:01:08 +08:00
},
currentViewRender: {
type: String,
2023-12-12 19:17:38 +08:00
required: true
},
columnDefs: {
type: Array,
required: true
2023-12-11 16:18:22 +08:00
},
2023-12-12 19:17:38 +08:00
tableState: {
type: Object
}
2023-11-24 18:08:28 +08:00
},
components: {
MenuDropdown,
2023-12-11 16:18:22 +08:00
FilterDropdown,
2023-12-12 19:17:38 +08:00
ColumnsModal
2023-11-24 18:08:28 +08:00
},
computed: {
2023-12-01 07:01:08 +08:00
viewModesMenu() {
2023-11-24 18:08:28 +08:00
return [
2023-12-11 16:18:22 +08:00
{ text: this.i18n.t('projects.index.active'), url: this.activePageUrl },
2023-12-12 19:17:38 +08:00
{ text: this.i18n.t('projects.index.archived'), url: this.archivedPageUrl }
2023-12-11 16:18:22 +08:00
];
2023-12-01 07:01:08 +08:00
},
viewRendersMenu() {
return this.viewRenders.map((view) => {
2023-12-11 16:18:22 +08:00
const { type } = view;
2023-12-01 07:01:08 +08:00
switch (type) {
case 'cards':
2023-12-11 16:18:22 +08:00
return { text: this.i18n.t('toolbar.cards_view'), emit: 'setCardsView' };
2023-12-01 07:01:08 +08:00
case 'table':
2023-12-11 16:18:22 +08:00
return { text: this.i18n.t('toolbar.table_view'), emit: 'setTableView' };
2023-12-12 19:17:38 +08:00
case 'custom':
return { text: view.name, url: view.url };
2023-12-01 07:01:08 +08:00
default:
return view;
}
2023-12-11 16:18:22 +08:00
});
2023-12-12 19:17:38 +08:00
}
},
data() {
return {
2023-12-11 16:18:22 +08:00
showSearch: false,
2023-12-12 19:17:38 +08:00
showColumnsModal: false
2023-12-11 16:18:22 +08:00
};
},
watch: {
searchValue() {
if (this.searchValue.length > 0) {
this.openSearch();
}
2023-12-12 19:17:38 +08:00
}
},
methods: {
openSearch() {
this.showSearch = true;
},
hideSearch() {
if (this.searchValue.length === 0) {
this.showSearch = false;
}
},
doAction(action, event) {
2023-12-11 16:18:22 +08:00
switch (action.type) {
case 'emit':
event.preventDefault();
this.$emit('toolbar:action', action);
break;
case 'link':
break;
2023-12-11 16:18:22 +08:00
default:
break;
}
2023-11-24 18:08:28 +08:00
},
applyFilters(filters) {
this.$emit('applyFilters', filters);
2023-12-12 19:17:38 +08:00
}
}
2023-12-11 16:18:22 +08:00
};
</script>