|
| 1 | +<script setup lang="ts"> |
| 2 | +import { BDropdown, BDropdownDivider, BDropdownGroup } from "bootstrap-vue"; |
| 3 | +import { computed } from "vue"; |
| 4 | +
|
| 5 | +import type { Panel } from "@/stores/toolStore"; |
| 6 | +
|
| 7 | +import PanelViewMenuItem from "./PanelViewMenuItem.vue"; |
| 8 | +
|
| 9 | +const groupsDefinitions = [ |
| 10 | + { type: "ontology", title: "...by Ontology" }, |
| 11 | + { type: "activity", title: "...for Activity" }, |
| 12 | + { type: "publication", title: "...from Publication" }, |
| 13 | + { type: "training", title: "...for Training" }, |
| 14 | +]; |
| 15 | +
|
| 16 | +const props = defineProps<{ |
| 17 | + panelViews: Record<string, Panel>; |
| 18 | + currentPanelView: string; |
| 19 | + storeLoading: boolean; |
| 20 | +}>(); |
| 21 | +
|
| 22 | +const emit = defineEmits<{ |
| 23 | + (e: "updatePanelView", panelViewId: string): void; |
| 24 | +}>(); |
| 25 | +
|
| 26 | +const defaultPanelView = computed(() => props.panelViews["default"] || Object.values(props.panelViews)[0]); |
| 27 | +
|
| 28 | +const groupedPanelViews = computed(() => { |
| 29 | + const groups = []; |
| 30 | + for (const group of groupsDefinitions) { |
| 31 | + const viewType = group.type; |
| 32 | + const panelViews = panelViewsOfType(viewType); |
| 33 | + if (panelViews.length > 0) { |
| 34 | + groups.push({ |
| 35 | + type: viewType, |
| 36 | + title: group.title, |
| 37 | + panelViews: panelViews, |
| 38 | + }); |
| 39 | + } |
| 40 | + } |
| 41 | + return groups; |
| 42 | +}); |
| 43 | +
|
| 44 | +const ungroupedPanelViews = computed(() => panelViewsOfType("generic")); |
| 45 | +
|
| 46 | +function panelViewsOfType(panelViewType: string) { |
| 47 | + const panelViews = []; |
| 48 | + for (const panelViewId in props.panelViews) { |
| 49 | + const panelView = props.panelViews[panelViewId]; |
| 50 | + if (panelView?.view_type === panelViewType) { |
| 51 | + panelViews.push(panelView); |
| 52 | + } |
| 53 | + } |
| 54 | + return panelViews; |
| 55 | +} |
| 56 | +
|
| 57 | +function updatePanelView(panelView: Panel) { |
| 58 | + emit("updatePanelView", panelView.id); |
| 59 | +} |
| 60 | +</script> |
| 61 | + |
1 | 62 | <template> |
2 | | - <b-dropdown |
| 63 | + <BDropdown |
3 | 64 | v-b-tooltip.hover.top.noninteractive |
4 | 65 | right |
5 | 66 | block |
|
16 | 77 | <slot name="panel-view-selector"></slot><span class="sr-only">View all tool panel configurations</span> |
17 | 78 | </template> |
18 | 79 | <PanelViewMenuItem |
| 80 | + v-if="defaultPanelView" |
19 | 81 | :current-panel-view="currentPanelView" |
20 | 82 | :panel-view="defaultPanelView" |
21 | 83 | @onSelect="updatePanelView" /> |
22 | | - <b-dropdown-group v-for="group in groupedPanelViews" :id="group.type" :key="group.type"> |
| 84 | + <BDropdownGroup v-for="group in groupedPanelViews" :id="group.type" :key="group.type"> |
23 | 85 | <template v-slot:header> |
24 | 86 | <small class="font-weight-bold">{{ group.title }}</small> |
25 | 87 | </template> |
|
29 | 91 | :current-panel-view="currentPanelView" |
30 | 92 | :panel-view="panelView" |
31 | 93 | @onSelect="updatePanelView" /> |
32 | | - </b-dropdown-group> |
33 | | - <b-dropdown-divider v-if="ungroupedPanelViews.length > 0" /> |
| 94 | + </BDropdownGroup> |
| 95 | + <BDropdownDivider v-if="ungroupedPanelViews.length > 0" /> |
34 | 96 | <PanelViewMenuItem |
35 | 97 | v-for="(panelView, key) in ungroupedPanelViews" |
36 | 98 | :key="key" |
37 | 99 | :current-panel-view="currentPanelView" |
38 | 100 | :panel-view="panelView" |
39 | 101 | @onSelect="updatePanelView" /> |
40 | | - </b-dropdown> |
| 102 | + </BDropdown> |
41 | 103 | </template> |
42 | 104 |
|
43 | | -<script> |
44 | | -import PanelViewMenuItem from "./PanelViewMenuItem"; |
45 | | -
|
46 | | -const groupsDefinitions = [ |
47 | | - { type: "ontology", title: "...by Ontology" }, |
48 | | - { type: "activity", title: "...for Activity" }, |
49 | | - { type: "publication", title: "...from Publication" }, |
50 | | - { type: "training", title: "...for Training" }, |
51 | | -]; |
52 | | -
|
53 | | -export default { |
54 | | - components: { PanelViewMenuItem }, |
55 | | - props: { |
56 | | - panelViews: { |
57 | | - type: Object, |
58 | | - }, |
59 | | - currentPanelView: { |
60 | | - type: String, |
61 | | - }, |
62 | | - storeLoading: { |
63 | | - type: Boolean, |
64 | | - default: false, |
65 | | - }, |
66 | | - }, |
67 | | - computed: { |
68 | | - defaultPanelView() { |
69 | | - return this.panelViewsOfType("default")[0]; |
70 | | - }, |
71 | | - groupedPanelViews() { |
72 | | - const groups = []; |
73 | | - for (const group of groupsDefinitions) { |
74 | | - const viewType = group.type; |
75 | | - const panelViews = this.panelViewsOfType(viewType); |
76 | | - if (panelViews.length > 0) { |
77 | | - groups.push({ |
78 | | - type: viewType, |
79 | | - title: group.title, |
80 | | - panelViews: panelViews, |
81 | | - }); |
82 | | - } |
83 | | - } |
84 | | - return groups; |
85 | | - }, |
86 | | - ungroupedPanelViews() { |
87 | | - return this.panelViewsOfType("generic"); |
88 | | - }, |
89 | | - }, |
90 | | - methods: { |
91 | | - updatePanelView(panelView) { |
92 | | - this.$emit("updatePanelView", panelView.id); |
93 | | - }, |
94 | | - panelViewsOfType(panelViewType) { |
95 | | - const panelViews = []; |
96 | | - for (const panelViewId in this.panelViews) { |
97 | | - const panelView = this.panelViews[panelViewId]; |
98 | | - if (panelView.view_type == panelViewType) { |
99 | | - panelViews.push(panelView); |
100 | | - } |
101 | | - } |
102 | | - return panelViews; |
103 | | - }, |
104 | | - }, |
105 | | -}; |
106 | | -</script> |
107 | | - |
108 | 105 | <style lang="scss"> |
109 | 106 | .tool-panel-dropdown .dropdown-menu { |
110 | 107 | overflow: auto; |
|
0 commit comments