diff options
author | pacien | 2022-10-30 17:40:33 +0100 |
---|---|---|
committer | pacien | 2022-10-30 21:15:01 +0100 |
commit | 12eb302bcc93405f81b676b1a29a9731a5fec9be (patch) | |
tree | a99329c14eda80e6262464bd6bb9c570e85b8941 /viewer/src/views/layout/top/LayoutCommand.vue | |
parent | f864eeca506331c1dee2cd3f5f0df4fe806f303a (diff) | |
download | ldgallery-12eb302bcc93405f81b676b1a29a9731a5fec9be.tar.gz |
viewer/command: add item download button
This adds a download button which allows the user to save the current
item as a file.
This is necessary because some item viewers do not expose a download
option on their own.
The download icon appears together with the other command buttons at the
top-left corner of the screen, replacing the listing sorting menu which
is only relevant for item lists (directory and search views).
GitHub: closes #308
Diffstat (limited to 'viewer/src/views/layout/top/LayoutCommand.vue')
-rw-r--r-- | viewer/src/views/layout/top/LayoutCommand.vue | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/viewer/src/views/layout/top/LayoutCommand.vue b/viewer/src/views/layout/top/LayoutCommand.vue index 8919da3..d930fd2 100644 --- a/viewer/src/views/layout/top/LayoutCommand.vue +++ b/viewer/src/views/layout/top/LayoutCommand.vue | |||
@@ -2,7 +2,7 @@ | |||
2 | -- pictures into a searchable web gallery. | 2 | -- pictures into a searchable web gallery. |
3 | -- | 3 | -- |
4 | -- Copyright (C) 2019-2022 Guillaume FOUET | 4 | -- Copyright (C) 2019-2022 Guillaume FOUET |
5 | -- 2020 Pacien TRAN-GIRARD | 5 | -- 2020-2022 Pacien TRAN-GIRARD |
6 | -- | 6 | -- |
7 | -- This program is free software: you can redistribute it and/or modify | 7 | -- This program is free software: you can redistribute it and/or modify |
8 | -- it under the terms of the GNU Affero General Public License as | 8 | -- it under the terms of the GNU Affero General Public License as |
@@ -33,7 +33,24 @@ | |||
33 | size="lg" | 33 | size="lg" |
34 | /> | 34 | /> |
35 | </LdLink> | 35 | </LdLink> |
36 | <LayoutCommandSort :tabindex="20" /> | 36 | |
37 | <LayoutCommandSort | ||
38 | v-if="isListing" | ||
39 | :tabindex="20" | ||
40 | /> | ||
41 | <a | ||
42 | v-else | ||
43 | :title="t('command.download')" | ||
44 | :download="itemFileName" | ||
45 | :href="itemResourceUrl" | ||
46 | :tabindex="20" | ||
47 | > | ||
48 | <fa-icon | ||
49 | :icon="faFileDownload" | ||
50 | size="lg" | ||
51 | /> | ||
52 | </a> | ||
53 | |||
37 | <LdLink | 54 | <LdLink |
38 | :class="{ disabled: isEntryPoint(), [$style.commandSecondary]: true }" | 55 | :class="{ disabled: isEntryPoint(), [$style.commandSecondary]: true }" |
39 | :title="t('command.back')" | 56 | :title="t('command.back')" |
@@ -67,21 +84,42 @@ | |||
67 | import { Item } from '@/@types/gallery'; | 84 | import { Item } from '@/@types/gallery'; |
68 | import LdLink from '@/components/LdLink.vue'; | 85 | import LdLink from '@/components/LdLink.vue'; |
69 | import { useUiStore } from '@/store/uiStore'; | 86 | import { useUiStore } from '@/store/uiStore'; |
70 | import { faAngleDoubleLeft, faArrowLeft, faFolder, faLevelUpAlt, faSearch } from '@fortawesome/free-solid-svg-icons'; | 87 | import { useGalleryStore } from '@/store/galleryStore'; |
88 | import { useNavigation } from '@/services/navigation'; | ||
89 | import { isDirectory, isDownloadableItem } from '@/services/itemGuards'; | ||
90 | import { | ||
91 | faAngleDoubleLeft, | ||
92 | faArrowLeft, | ||
93 | faFolder, | ||
94 | faLevelUpAlt, | ||
95 | faSearch, | ||
96 | faFileDownload, | ||
97 | } from '@fortawesome/free-solid-svg-icons'; | ||
71 | import { computedEager } from '@vueuse/shared'; | 98 | import { computedEager } from '@vueuse/shared'; |
72 | import { computed } from 'vue'; | 99 | import { computed, PropType } from 'vue'; |
73 | import { useI18n } from 'vue-i18n'; | 100 | import { useI18n } from 'vue-i18n'; |
74 | import { useRoute, useRouter } from 'vue-router'; | 101 | import { useRoute, useRouter } from 'vue-router'; |
75 | import LayoutCommandSort from './LayoutCommandSort.vue'; | 102 | import LayoutCommandSort from './LayoutCommandSort.vue'; |
76 | 103 | ||
77 | const props = defineProps({ | 104 | const props = defineProps({ |
78 | currentItemPath: { type: Array<Item>, required: true }, | 105 | currentItemPath: { type: Array<Item>, required: true }, |
106 | item: { type: Object as PropType<Item>, required: true }, | ||
79 | }); | 107 | }); |
80 | 108 | ||
81 | const { t } = useI18n(); | 109 | const { t } = useI18n(); |
82 | const route = useRoute(); | 110 | const route = useRoute(); |
83 | const router = useRouter(); | 111 | const router = useRouter(); |
84 | const uiStore = useUiStore(); | 112 | const uiStore = useUiStore(); |
113 | const galleryStore = useGalleryStore(); | ||
114 | const navigation = useNavigation(); | ||
115 | |||
116 | const isListing = computedEager(() => !props.item || isDirectory(props.item)); | ||
117 | const itemFileName = computed(() => navigation.getFileName(props.item)); | ||
118 | const itemResourceUrl = computed(() => | ||
119 | isDownloadableItem(props.item) | ||
120 | ? galleryStore.resourceRoot + props.item.properties.resource | ||
121 | : '', | ||
122 | ); | ||
85 | 123 | ||
86 | const commandToggleSearchPanelIcon = computed(() => uiStore.fullWidth ? faSearch : faAngleDoubleLeft); | 124 | const commandToggleSearchPanelIcon = computed(() => uiStore.fullWidth ? faSearch : faAngleDoubleLeft); |
87 | const isRoot = computedEager(() => props.currentItemPath.length <= 1 && !uiStore.searchMode); | 125 | const isRoot = computedEager(() => props.currentItemPath.length <= 1 && !uiStore.searchMode); |