1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
<!--
- SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcAppNavigation data-cy-files-navigation
class="files-navigation"
:aria-label="t('files', 'Files')">
<template #search>
<NcAppNavigationSearch v-model="searchQuery" :label="t('files', 'Filter filenames…')" />
</template>
<template #default>
<NcAppNavigationList :aria-label="t('files', 'Views')">
<FilesNavigationItem :views="viewMap" />
</NcAppNavigationList>
<!-- Settings modal-->
<SettingsModal :open="settingsOpened"
data-cy-files-navigation-settings
@close="onSettingsClose" />
</template>
<!-- Non-scrollable navigation bottom elements -->
<template #footer>
<ul class="app-navigation-entry__settings">
<!-- User storage usage statistics -->
<NavigationQuota />
<!-- Files settings modal toggle-->
<NcAppNavigationItem :name="t('files', 'Files settings')"
data-cy-files-navigation-settings-button
@click.prevent.stop="openSettings">
<IconCog slot="icon" :size="20" />
</NcAppNavigationItem>
</ul>
</template>
</NcAppNavigation>
</template>
<script lang="ts">
import type { View } from '@nextcloud/files'
import { emit } from '@nextcloud/event-bus'
import { translate as t, getCanonicalLocale, getLanguage } from '@nextcloud/l10n'
import { defineComponent } from 'vue'
import IconCog from 'vue-material-design-icons/Cog.vue'
import NcAppNavigation from '@nextcloud/vue/dist/Components/NcAppNavigation.js'
import NcAppNavigationItem from '@nextcloud/vue/dist/Components/NcAppNavigationItem.js'
import NcAppNavigationList from '@nextcloud/vue/dist/Components/NcAppNavigationList.js'
import NcAppNavigationSearch from '@nextcloud/vue/dist/Components/NcAppNavigationSearch.js'
import NavigationQuota from '../components/NavigationQuota.vue'
import SettingsModal from './Settings.vue'
import FilesNavigationItem from '../components/FilesNavigationItem.vue'
import { useNavigation } from '../composables/useNavigation'
import { useFilenameFilter } from '../composables/useFilenameFilter'
import { useFiltersStore } from '../store/filters.ts'
import { useViewConfigStore } from '../store/viewConfig.ts'
import logger from '../logger.ts'
const collator = Intl.Collator(
[getLanguage(), getCanonicalLocale()],
{
numeric: true,
usage: 'sort',
},
)
export default defineComponent({
name: 'Navigation',
components: {
IconCog,
FilesNavigationItem,
NavigationQuota,
NcAppNavigation,
NcAppNavigationItem,
NcAppNavigationList,
NcAppNavigationSearch,
SettingsModal,
},
setup() {
const filtersStore = useFiltersStore()
const viewConfigStore = useViewConfigStore()
const { currentView, views } = useNavigation()
const { searchQuery } = useFilenameFilter()
return {
currentView,
searchQuery,
t,
views,
filtersStore,
viewConfigStore,
}
},
data() {
return {
settingsOpened: false,
}
},
computed: {
/**
* The current view ID from the route params
*/
currentViewId() {
return this.$route?.params?.view || 'files'
},
/**
* Map of parent ids to views
*/
viewMap(): Record<string, View[]> {
return this.views
.reduce((map, view) => {
map[view.parent!] = [...(map[view.parent!] || []), view]
// TODO Allow undefined order for natural sort
map[view.parent!].sort((a, b) => {
if (typeof a.order === 'number' || typeof b.order === 'number') {
return (a.order ?? 0) - (b.order ?? 0)
}
return collator.compare(a.name, b.name)
})
return map
}, {} as Record<string, View[]>)
},
},
watch: {
currentViewId(newView, oldView) {
if (this.currentViewId !== this.currentView?.id) {
// This is guaranteed to be a view because `currentViewId` falls back to the default 'files' view
const view = this.views.find(({ id }) => id === this.currentViewId)!
// The new view as active
this.showView(view)
logger.debug(`Navigation changed from ${oldView} to ${newView}`, { to: view })
}
},
},
beforeMount() {
// This is guaranteed to be a view because `currentViewId` falls back to the default 'files' view
const view = this.views.find(({ id }) => id === this.currentViewId)!
this.showView(view)
logger.debug('Navigation mounted. Showing requested view', { view })
},
methods: {
/**
* Set the view as active on the navigation and handle internal state
* @param view View to set active
*/
showView(view: View) {
// Closing any opened sidebar
window.OCA?.Files?.Sidebar?.close?.()
this.$navigation.setActive(view)
emit('files:navigation:changed', view)
},
/**
* Open the settings modal
*/
openSettings() {
this.settingsOpened = true
},
/**
* Close the settings modal
*/
onSettingsClose() {
this.settingsOpened = false
},
},
})
</script>
<style scoped lang="scss">
// TODO: remove when https://github.com/nextcloud/nextcloud-vue/pull/3539 is in
.app-navigation::v-deep .app-navigation-entry-icon {
background-repeat: no-repeat;
background-position: center;
}
.app-navigation::v-deep .app-navigation-entry.active .button-vue.icon-collapse:not(:hover) {
color: var(--color-primary-element-text);
}
.app-navigation > ul.app-navigation__list {
// Use flex gap value for more elegant spacing
padding-bottom: var(--default-grid-baseline, 4px);
}
.app-navigation-entry__settings {
height: auto !important;
overflow: hidden !important;
padding-top: 0 !important;
// Prevent shrinking or growing
flex: 0 0 auto;
}
.files-navigation {
:deep(.app-navigation__content > ul.app-navigation__list) {
will-change: scroll-position;
}
}
</style>
|