Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 51 additions & 12 deletions apps/settings/src/components/AppStoreSidebar/AppDetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@
<span>{{ t('settings', 'Limit app usage to groups') }}</span>
</label>
<NcSelect v-if="isLimitedToGroups(app)"
v-model="appGroups"
input-id="limitToGroups"
:options="groups"
:value="appGroups"
:options="appGroupsOptions"
:limit="5"
label="name"
:multiple="true"
:loading="loadingGroups"
:close-on-select="false"
@option:selected="addGroupLimitation"
@option:deselected="removeGroupLimitation"
@search="asyncFindGroup">
@search="searchGroup">
<span slot="noResult">{{ t('settings', 'No results') }}</span>
</NcSelect>
</div>
Expand Down Expand Up @@ -188,6 +187,12 @@ import AppManagement from '../../mixins/AppManagement.js'
import { mdiBug, mdiFeatureSearch, mdiStar, mdiTextBox, mdiTooltipQuestion } from '@mdi/js'
import { useAppsStore } from '../../store/apps-store'

import sortedUniq from 'lodash/sortedUniq.js'
import uniq from 'lodash/uniq.js'
import debounce from 'debounce'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'

export default {
name: 'AppDetailsTab',

Expand Down Expand Up @@ -224,6 +229,10 @@ export default {
data() {
return {
groupCheckedAppsData: false,
groups: [],
appGroupsOptions: [],
appGroupsSelected: [],
loadingGroups: false,
}
},

Expand Down Expand Up @@ -319,19 +328,49 @@ export default {
rateAppUrl() {
return `${this.appstoreUrl}#comments`
},
appGroups() {
return this.app.groups.map(group => { return { id: group, name: group } })
},
groups() {
return this.$store.getters.getGroups
.filter(group => group.id !== 'disabled')
.sort((a, b) => a.name.localeCompare(b.name))
appGroups: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a computed with setter that dispatches a store event is not really recommended. This should rather be handled in an event handler.

get() {
return this.appGroupsSelected
},
set(val) {
this.appGroupsOptions = this.groups.filter((group) => !val.includes(group))
this.appGroupsSelected = val
this.$store.dispatch('enableApp', { appId: this.app.id, groups: val })
},
},
},
mounted() {
if (this.app.groups.length > 0) {
this.groupCheckedAppsData = true
this.appGroupsSelected = this.app.groups
}

// Populate the groups with a first set so the dropdown is not empty
// when opening the page the first time
this.searchGroup('')
},
methods: {
searchGroup: debounce(function(query) {
this.loadingGroups = true
axios
.get(
generateOcsUrl('cloud/groups?offset=0&search={query}&limit=20', {
query,
}),
)
.then((res) => res.data.ocs)
.then((ocs) => ocs.data.groups)
.then((groups) => {
this.groups = sortedUniq(uniq(this.groups.concat(groups)))
if (this.appGroupsOptions.length === 0) {
this.appGroupsOptions = this.groups.filter((group) => !this.app.groups.includes(group))
}
})
.catch((err) => console.error('could not search groups', err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the logger instead of the console

.then(() => {
this.loadingGroups = false
})
}, 500),
},
}
</script>
Expand Down
13 changes: 0 additions & 13 deletions apps/settings/src/mixins/AppManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ export default {
}
return true
},
addGroupLimitation(groupArray) {
const group = groupArray.pop()
const groups = this.app.groups.concat([]).concat([group.id])
this.$store.dispatch('enableApp', { appId: this.app.id, groups })
},
removeGroupLimitation(group) {
const currentGroups = this.app.groups.concat([])
const index = currentGroups.indexOf(group.id)
if (index > -1) {
currentGroups.splice(index, 1)
}
this.$store.dispatch('enableApp', { appId: this.app.id, groups: currentGroups })
},
forceEnable(appId) {
this.$store.dispatch('forceEnableApp', { appId, groups: [] })
.then((response) => { rebuildNavigation() })
Expand Down