Skip to content

Commit c5aecf5

Browse files
Adapt router.js for setting document title.
Adapt store to store Promise for dynamic requested categories. Create new constants file to store category name with associated translation. Signed-off-by: julia.kirschenheuter <julia.kirschenheuter@nextcloud.com> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
1 parent 723278d commit c5aecf5

9 files changed

Lines changed: 174 additions & 23 deletions
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @copyright 2022, Julia Kirschenheuter <julia.kirschenheuter@nextcloud.com>
3+
*
4+
* @author Julia Kirschenheuter <julia.kirschenheuter@nextcloud.com>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
import { translate as t } from '@nextcloud/l10n'
24+
25+
/** Enum of verification constants, according to Apps */
26+
export const APPS_SECTION_ENUM = Object.freeze({
27+
enabled: t('settings', 'Active apps'),
28+
disabled: t('settings', 'Disabled apps'),
29+
updates: t('settings', 'Updates'),
30+
'app-bundles': t('settings', 'App bundles'),
31+
featured: t('settings', 'Featured apps'),
32+
})

apps/settings/src/router.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import Vue from 'vue'
2626
import Router from 'vue-router'
2727
import { generateUrl } from '@nextcloud/router'
28+
import { APPS_SECTION_ENUM } from './constants/AppsConstants.js'
29+
import store from './store/index.js'
2830

2931
// Dynamic loading
3032
const Users = () => import(/* webpackChunkName: 'settings-users' */'./views/Users')
@@ -40,8 +42,8 @@ Vue.use(Router)
4042
* ensure the proper route.
4143
* ⚠️ Routes needs to match the php routes.
4244
*/
43-
44-
export default new Router({
45+
const baseTitle = document.title
46+
const router = new Router({
4547
mode: 'history',
4648
// if index.php is in the url AND we got this far, then it's working:
4749
// let's keep using index.php in the url
@@ -66,10 +68,29 @@ export default new Router({
6668
component: Apps,
6769
props: true,
6870
name: 'apps',
71+
meta: {
72+
title: () => {
73+
return t('settings', 'Your apps')
74+
},
75+
},
6976
children: [
7077
{
7178
path: ':category',
7279
name: 'apps-category',
80+
meta: {
81+
title: async (to) => {
82+
if (to.name === 'apps') {
83+
return t('settings', 'Your apps')
84+
} else if (APPS_SECTION_ENUM[to.params.category]) {
85+
return APPS_SECTION_ENUM[to.params.category]
86+
}
87+
await store.dispatch('getCategories')
88+
const category = store.getters.getCategoryById(to.params.category)
89+
if (category.displayName) {
90+
return category.displayName
91+
}
92+
},
93+
},
7394
component: Apps,
7495
children: [
7596
{
@@ -83,3 +104,14 @@ export default new Router({
83104
},
84105
],
85106
})
107+
108+
router.afterEach(async (to) => {
109+
const metaTitle = await to.meta.title?.(to)
110+
if (metaTitle) {
111+
document.title = `${metaTitle} - ${baseTitle}`
112+
} else {
113+
document.title = baseTitle
114+
}
115+
})
116+
117+
export default router

apps/settings/src/store/apps.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const state = {
3434
updateCount: 0,
3535
loading: {},
3636
loadingList: false,
37+
gettingCategoriesPromise: null,
3738
}
3839

3940
const mutations = {
@@ -48,6 +49,10 @@ const mutations = {
4849
state.updateCount = updateCount
4950
},
5051

52+
updateCategories(state, categoriesPromise) {
53+
state.gettingCategoriesPromise = categoriesPromise
54+
},
55+
5156
setUpdateCount(state, updateCount) {
5257
state.updateCount = updateCount
5358
},
@@ -156,6 +161,9 @@ const getters = {
156161
getUpdateCount(state) {
157162
return state.updateCount
158163
},
164+
getCategoryById: (state) => (selectedCategoryId) => {
165+
return state.categories.find((category) => category.id === selectedCategoryId)
166+
},
159167
}
160168

161169
const actions = {
@@ -313,18 +321,25 @@ const actions = {
313321
.catch((error) => context.commit('API_FAILURE', error))
314322
},
315323

316-
getCategories(context) {
317-
context.commit('startLoading', 'categories')
318-
return api.get(generateUrl('settings/apps/categories'))
319-
.then((response) => {
320-
if (response.data.length > 0) {
321-
context.commit('appendCategories', response.data)
324+
async getCategories(context, { shouldRefetchCategories = false } = {}) {
325+
if (shouldRefetchCategories || !context.state.gettingCategoriesPromise) {
326+
context.commit('startLoading', 'categories')
327+
try {
328+
const categoriesPromise = api.get(generateUrl('settings/apps/categories'))
329+
context.commit('updateCategories', categoriesPromise)
330+
const categoriesPromiseResponse = await categoriesPromise
331+
if (categoriesPromiseResponse.data.length > 0) {
332+
context.commit('appendCategories', categoriesPromiseResponse.data)
322333
context.commit('stopLoading', 'categories')
323334
return true
324335
}
336+
context.commit('stopLoading', 'categories')
325337
return false
326-
})
327-
.catch((error) => context.commit('API_FAILURE', error))
338+
} catch (error) {
339+
context.commit('API_FAILURE', error)
340+
}
341+
}
342+
return context.state.gettingCategoriesPromise
328343
},
329344

330345
}

apps/settings/src/views/Apps.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@
3636
<NcAppNavigationItem id="app-category-enabled"
3737
:to="{ name: 'apps-category', params: { category: 'enabled' } }"
3838
icon="icon-category-enabled"
39-
:title="t('settings', 'Active apps')" />
39+
:title="$options.APPS_SECTION_ENUM.enabled" />
4040
<NcAppNavigationItem id="app-category-disabled"
4141
:to="{ name: 'apps-category', params: { category: 'disabled' } }"
4242
icon="icon-category-disabled"
43-
:title="t('settings', 'Disabled apps')" />
43+
:title="$options.APPS_SECTION_ENUM.disabled" />
4444
<NcAppNavigationItem v-if="updateCount > 0"
4545
id="app-category-updates"
4646
:to="{ name: 'apps-category', params: { category: 'updates' } }"
4747
icon="icon-download"
48-
:title="t('settings', 'Updates')">
48+
:title="$options.APPS_SECTION_ENUM.updates">
4949
<NcAppNavigationCounter slot="counter">
5050
{{ updateCount }}
5151
</NcAppNavigationCounter>
5252
</NcAppNavigationItem>
5353
<NcAppNavigationItem id="app-category-your-bundles"
5454
:to="{ name: 'apps-category', params: { category: 'app-bundles' } }"
5555
icon="icon-category-app-bundles"
56-
:title="t('settings', 'App bundles')" />
56+
:title="$options.APPS_SECTION_ENUM['app-bundles']" />
5757

5858
<NcAppNavigationSpacer />
5959

@@ -62,7 +62,7 @@
6262
<NcAppNavigationItem id="app-category-featured"
6363
:to="{ name: 'apps-category', params: { category: 'featured' } }"
6464
icon="icon-favorite"
65-
:title="t('settings', 'Featured apps')" />
65+
:title="$options.APPS_SECTION_ENUM.featured" />
6666

6767
<NcAppNavigationItem v-for="cat in categories"
6868
:key="'icon-category-' + cat.ident"
@@ -154,11 +154,13 @@ import AppManagement from '../mixins/AppManagement'
154154
import AppScore from '../components/AppList/AppScore'
155155
import Markdown from '../components/Markdown'
156156
157+
import { APPS_SECTION_ENUM } from './../constants/AppsConstants.js'
158+
157159
Vue.use(VueLocalStorage)
158160
159161
export default {
160162
name: 'Apps',
161-
163+
APPS_SECTION_ENUM,
162164
components: {
163165
NcAppContent,
164166
AppDetails,
@@ -273,7 +275,7 @@ export default {
273275
},
274276
275277
beforeMount() {
276-
this.$store.dispatch('getCategories')
278+
this.$store.dispatch('getCategories', { shouldRefetchCategories: true })
277279
this.$store.dispatch('getAllApps')
278280
this.$store.dispatch('getGroups', { offset: 0, limit: 5 })
279281
this.$store.commit('setUpdateCount', this.$store.getters.getServerData.updateCount)

dist/settings-apps-view-7418.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-apps-view-7418.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-vue-settings-apps-users-management.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-vue-settings-apps-users-management.js.LICENSE.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* @copyright 2022, Julia Kirschenheuter <julia.kirschenheuter@nextcloud.com>
3+
*
4+
* @author Julia Kirschenheuter <julia.kirschenheuter@nextcloud.com>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
123
/**
224
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
325
*
@@ -21,6 +43,30 @@
2143
*
2244
*/
2345

46+
/**
47+
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
48+
*
49+
* @author John Molakvoæ <skjnldsv@protonmail.com>
50+
* @author Julius Härtl <jus@bitgrid.net>
51+
* @author Roeland Jago Douma <roeland@famdouma.nl>
52+
*
53+
* @license AGPL-3.0-or-later
54+
*
55+
* This program is free software: you can redistribute it and/or modify
56+
* it under the terms of the GNU Affero General Public License as
57+
* published by the Free Software Foundation, either version 3 of the
58+
* License, or (at your option) any later version.
59+
*
60+
* This program is distributed in the hope that it will be useful,
61+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
62+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+
* GNU Affero General Public License for more details.
64+
*
65+
* You should have received a copy of the GNU Affero General Public License
66+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
67+
*
68+
*/
69+
2470
/**
2571
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
2672
*
@@ -44,3 +90,27 @@
4490
* along with this program. If not, see <http://www.gnu.org/licenses/>.
4591
*
4692
*/
93+
94+
/**
95+
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
96+
*
97+
* @author John Molakvoæ <skjnldsv@protonmail.com>
98+
* @author Julius Härtl <jus@bitgrid.net>
99+
* @author Roeland Jago Douma <roeland@famdouma.nl>
100+
*
101+
* @license AGPL-3.0-or-later
102+
*
103+
* This program is free software: you can redistribute it and/or modify
104+
* it under the terms of the GNU Affero General Public License as
105+
* published by the Free Software Foundation, either version 3 of the
106+
* License, or (at your option) any later version.
107+
*
108+
* This program is distributed in the hope that it will be useful,
109+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
110+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111+
* GNU Affero General Public License for more details.
112+
*
113+
* You should have received a copy of the GNU Affero General Public License
114+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
115+
*
116+
*/

dist/settings-vue-settings-apps-users-management.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)