From e077eb971b5420308a302c840595bd68453ad5e0 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Thu, 28 Nov 2019 16:52:12 -0300 Subject: [PATCH] Changes the name for action to get all collection names and adds selector to capabilities list. #274. --- .../edition/collection-edition-form.vue | 6 +- .../edition/importer-edition-form.vue | 4 +- src/admin/roles/role-edition-form.vue | 276 +++++++++++------- src/admin/roles/roles-list.vue | 8 +- src/js/store/modules/capability/actions.js | 15 + src/js/store/modules/capability/mutations.js | 11 +- src/js/store/modules/collection/actions.js | 4 +- src/js/store/modules/filter/actions.js | 2 +- 8 files changed, 213 insertions(+), 113 deletions(-) diff --git a/src/admin/components/edition/collection-edition-form.vue b/src/admin/components/edition/collection-edition-form.vue index af135ffaa..ba0f6bf19 100644 --- a/src/admin/components/edition/collection-edition-form.vue +++ b/src/admin/components/edition/collection-edition-form.vue @@ -550,7 +550,7 @@ export default { 'updateHeaderImage', 'fetchPages', 'fetchPage', - 'fetchCollectionsForParent' + 'fetchAllCollectionNames' ]), updateSlug: _.debounce(function() { if(!this.form.name || this.form.name.length <= 0){ @@ -668,7 +668,7 @@ export default { // Generates options for parent collection this.isFetchingCollections = true; - this.fetchCollectionsForParent() + this.fetchAllCollectionNames() .then((collections) => { this.collections = collections; this.isFetchingCollections = false; @@ -848,7 +848,7 @@ export default { // Generates options for parent collection this.isFetchingCollections = true; - this.fetchCollectionsForParent() + this.fetchAllCollectionNames() .then((resp) => { resp.request.then((collections) => { this.collections = collections; diff --git a/src/admin/components/edition/importer-edition-form.vue b/src/admin/components/edition/importer-edition-form.vue index f078d1f07..9310dd21b 100644 --- a/src/admin/components/edition/importer-edition-form.vue +++ b/src/admin/components/edition/importer-edition-form.vue @@ -216,7 +216,7 @@ export default { 'runImporter' ]), ...mapActions('collection', [ - 'fetchCollectionsForParent' + 'fetchAllCollectionNames' ]), createImporter() { // Puts loading on Draft Importer creation @@ -386,7 +386,7 @@ export default { loadCollections() { // Generates options for target collection this.isFetchingCollections = true; - this.fetchCollectionsForParent() + this.fetchAllCollectionNames() .then((resp) => { resp.request.then((collections) => { this.collections = collections; diff --git a/src/admin/roles/role-edition-form.vue b/src/admin/roles/role-edition-form.vue index 4445c0275..8b04c591c 100644 --- a/src/admin/roles/role-edition-form.vue +++ b/src/admin/roles/role-edition-form.vue @@ -3,7 +3,21 @@

{{ $route.meta.title }} {{ role.name }}



+ @@ -211,8 +253,12 @@ export default { data() { return { + isUpdatingRole: false, isLoadingRole: false, - isLoadingCapabilities: false + isLoadingCapabilities: false, + selectedCollection: 'all', + collections: [], + isLoadingCollections: false } }, computed: { @@ -224,7 +270,7 @@ let collectionCapabilities = {} for (let [capabilityKey, capability] of Object.entries(capabilities)) { - if (capability.scope === 'repository') + if (capability.scope === 'collection') collectionCapabilities[capabilityKey] = capability; } return collectionCapabilities; @@ -241,22 +287,40 @@ } }, methods: { + ...mapActions('collection', [ + 'fetchAllCollectionNames' + ]), ...mapActions('capability', [ + 'updateRole', 'fetchRole', 'fetchCapabilities', 'addCapabilityToRole', 'removeCapabilityFromRole' ]), + ...mapGetters('collection', [ + 'getCollections' + ]), ...mapGetters('capability', [ 'getRole', 'getCapabilities' ]), + onUpdateRoleName: _.debounce(function(newName) { + const updatedRole = JSON.parse(JSON.stringify(this.role)); + updatedRole['name'] = newName; + this.isUpdatingRole = true; + this.updateRole(updatedRole) + .then(() => { + this.isUpdatingRole = false; + }).catch(() => { + this.isUpdatingRole = false; + }); + }, 800), onUpdateCapability(value, capabilityKey) { if (value) this.addCapabilityToRole({ capabilityKey: capabilityKey, role: this.roleSlug }) else this.removeCapabilityFromRole({ capabilityKey: capabilityKey, role: this.roleSlug }) - } + }, }, created() { this.roleSlug = this.$route.params.roleSlug; @@ -276,6 +340,22 @@ }).catch(() => { this.isLoadingCapabilities = false; }); + + this.isLoadingCollections = true; + this.fetchAllCollectionNames() + .then((resp) => { + resp.request + .then((collections) => { + this.collections = collections; + this.isLoadingCollections = false; + }).catch(() => { + this.isLoadingCollections = false; + }); + }) + .catch(() => { + this.isLoadingCollections = false; + }); + } } \ No newline at end of file diff --git a/src/admin/roles/roles-list.vue b/src/admin/roles/roles-list.vue index 44ecfe592..883f42524 100644 --- a/src/admin/roles/roles-list.vue +++ b/src/admin/roles/roles-list.vue @@ -1,11 +1,15 @@