Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25 from owncloud/dynamic-nav-items
Browse files Browse the repository at this point in the history
Make use of the new dynamic navItems feature in phoenix
  • Loading branch information
kulmann authored Jun 9, 2020
2 parents 1ec89be + 35ccf26 commit 957ded8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/dynamic-nav-items.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Change: Dynamically add navItems for extensions with settings bundles

We now make use of a new feature in ocis-web-core, allowing us to add
navItems not only through configuration, but also after app initialization.
With this we now have navItems available for all extensions within the
settings ui, that have at least one settings bundle registered.

https://github.com/owncloud/ocis-settings/pull/25
6 changes: 3 additions & 3 deletions pkg/assets/embed.go

Large diffs are not rendered by default.

56 changes: 47 additions & 9 deletions ui/components/SettingsApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</template>

<script>
import { mapActions, mapGetters } from 'vuex'
import { mapActions, mapGetters, mapMutations } from 'vuex'
import SettingsBundle from './SettingsBundle.vue'
export default {
name: 'SettingsApp',
Expand All @@ -49,7 +49,7 @@ export default {
}
},
computed: {
...mapGetters(['settingsValuesLoaded']),
...mapGetters(['settingsValuesLoaded', 'getNavItems']),
...mapGetters('Settings', [
'extensions',
'initialized',
Expand All @@ -59,13 +59,7 @@ export default {
return this.$route.params.extension
},
selectedExtensionName () {
// TODO: extensions need to be registered with display names, separate from the settings bundles. until then: hardcoded translation
if (this.selectedExtension === 'ocis-accounts') {
return 'Account'
} else if (this.selectedExtension === 'ocis-test') {
return 'Test'
}
return this.selectedExtension
return this.getExtensionName(this.selectedExtension)
},
selectedSettingsBundles () {
if (this.selectedExtension) {
Expand All @@ -76,6 +70,7 @@ export default {
},
methods: {
...mapActions('Settings', ['initialize']),
...mapMutations(['ADD_NAV_ITEM']),
resetSelectedExtension () {
if (this.extensions.length > 0) {
if (this.extensionRouteParam && this.extensions.includes(this.extensionRouteParam)) {
Expand All @@ -84,14 +79,57 @@ export default {
this.selectedExtension = this.extensions[0]
}
}
},
resetMenuItems () {
this.extensions.forEach(extension => {
/*
* TODO:
* a) set up a map with possible extensions and icons?
* or b) let extensions register app info like displayName + icon?
* https://github.com/owncloud/ocis-settings/issues/27
*/
const navItem = {
name: this.getExtensionName(extension),
iconMaterial: this.getExtensionIcon(extension),
route: {
name: 'settings',
path: `/settings/${extension}`
}
}
this.ADD_NAV_ITEM({
extension: 'settings',
navItem
})
})
},
getExtensionName (extension) {
extension = extension || ''
switch (extension) {
case 'ocis-accounts': return this.$gettext('Account')
case 'ocis-hello': return this.$gettext('Hello')
default: {
const shortenedName = extension.replace('ocis-', '')
return shortenedName.charAt(0).toUpperCase() + shortenedName.slice(1)
}
}
},
getExtensionIcon (extension) {
extension = extension || ''
switch (extension) {
case 'ocis-accounts': return 'account_circle'
case 'ocis-hello': return 'tag_faces'
default: return 'application'
}
}
},
async created () {
await this.initialize()
this.resetMenuItems()
this.resetSelectedExtension()
},
watch: {
initialized () {
this.resetMenuItems()
this.resetSelectedExtension()
},
extensionRouteParam () {
Expand Down

0 comments on commit 957ded8

Please sign in to comment.