Changes the name for action to get all collection names and adds selector to capabilities list. #274.

This commit is contained in:
Mateus Machado Luna 2019-11-28 16:52:12 -03:00
parent 5d503465f7
commit e077eb971b
8 changed files with 213 additions and 113 deletions

View File

@ -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;

View File

@ -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;

View File

@ -3,7 +3,21 @@
<h1 class="wp-heading-inline">{{ $route.meta.title }}&nbsp;<strong>{{ role.name }}</strong></h1>
<hr class="wp-header-end">
<br>
<template v-if="!isLoadingRole">
<div class="name-edition-box">
<h2 id="role-name-label">{{ $i18n.get('Role name') }}</h2>
<input
aria-labelledby="role-name-label"
type="text"
id="rolen-name-input"
name="name"
@input="onUpdateRoleName($event.target.value)"
:value="role.name"
:placeholder="$i18n.get('Type here the role name...')">
</div>
</template>
<template v-if="!isLoadingRole && !isLoadingCapabilities">
<br>
<h2>{{ $i18n.get('Role\'s Repository related Capabilities List') }}</h2>
<table class="wp-list-table widefat fixed striped capabilities">
<thead>
@ -104,7 +118,34 @@
<br>
<template v-if="!isLoadingCollections">
<h2>{{ $i18n.get('Role\'s Collection related Capabilities List') }}</h2>
<div class="tablenav top">
<div class="alignleft collection-selector">
<label
for="bulk-action-selector-top"
class="screen-reader-text">
{{ $i18n.get('Select the collection to change capabilities') }}
</label>
<select
name="collection"
id="collection-select"
:value="selectedCollection"
@input="selectedCollection = $event.target.value">
<option value="all">{{ $i18n.get('All Collections') }}</option>
<option
:key="index"
v-for="(collection, index) of collections"
:value="collection.id">
{{ collection.name }}
</option>
</select>
</div>
<br class="clear">
</div>
<table class="wp-list-table widefat fixed striped capabilities">
<thead>
<tr>
@ -141,21 +182,21 @@
<tr
v-for="(capability, index) of collectionCapabilities"
:key="index"
:id="'capability-' + index">
:id="'capability-' + index.replace('%d', selectedCollection)">
<th
scope="row"
class="check-column">
<label
class="screen-reader-text"
:for="'capability_' + index">
:for="'capability_' + index.replace('%d', selectedCollection)">
{{ $i18n.get('Selecionar') + ' ' + capability.display_name }}
</label>
<input
type="checkbox"
name="roles[]"
:id="'capability_'+ index"
:checked="role.capabilities[index]"
@input="onUpdateCapability($event.target.checked, index)">
:id="'capability_'+ index.replace('%d', selectedCollection)"
:checked="role.capabilities[index.replace('%d', selectedCollection)]"
@input="onUpdateCapability($event.target.checked, index.replace('%d', selectedCollection))">
</th>
<td
class="name column-name"
@ -202,6 +243,7 @@
</tfoot>
</table>
</template>
</template>
</div>
</template>
@ -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;
});
}
}
</script>

View File

@ -1,11 +1,15 @@
<template>
<div>
<h1 class="wp-heading-inline">{{ $route.meta.title }}</h1>
<a class="page-title-action">
<router-link
to="/roles/new"
class="page-title-action">
{{ $i18n.get('Add new role') }}
</a>
</router-link>
<hr class="wp-header-end">
<br>
<h2 class="screen-reader-text">{{ $i18n.get('Roles list') }}</h2>
<table
v-if="!isLoadingRoles"

View File

@ -59,6 +59,21 @@ export const fetchRole = ({ commit }, roleSlug) => {
});
};
export const updateRole = ({ commit }, role) => {
return new Promise((resolve, reject) => {
axios.tainacan.patch('/roles/' + role.slug, role)
.then(res => {
const role = res.data
commit('setRole', role);
resolve(role);
})
.catch(error => {
reject(error);
});
});
};
// CAPABILITIES
export const fetchCapabilities = ({ commit }, { collectionId } ) => {
return new Promise((resolve, reject) => {

View File

@ -2,7 +2,7 @@ import Vue from 'vue';
// Roles
export const addCapabilityToRole = (state, {capabilityKey, role}) => {
if (state.capabilities[capabilityKey].roles[role.slug] == undefined) {
if (state.capabilities[capabilityKey] && state.capabilities[capabilityKey].roles[role.slug] == undefined) {
let updateRoles = state.capabilities[capabilityKey].roles.length ? state.capabilities[capabilityKey].roles : {};
updateRoles[role.slug] = role;
Vue.set(state.capabilities[capabilityKey], 'roles', updateRoles)
@ -13,10 +13,11 @@ export const addCapabilityToRole = (state, {capabilityKey, role}) => {
};
export const removeCapabilityFromRole = (state, {capabilityKey, role}) => {
if (state.capabilities[capabilityKey]) {
let updateRoles = state.capabilities[capabilityKey].roles;
delete updateRoles[role.slug];
Vue.set(state.capabilities[capabilityKey], 'roles', updateRoles)
}
if (state.role && state.role.slug && state.role.slug == role)
delete state.role.capabilities[capabilityKey]
};

View File

@ -457,12 +457,12 @@ export const fetchPage = ({ commit }, pageId ) => {
};
// Fetch Collections for choosing Parent Collection
export const fetchCollectionsForParent = ({ commit }) => {
export const fetchAllCollectionNames = ({ commit }) => {
const source = axios.CancelToken.source();
return new Object({
request: new Promise((resolve, reject) => {
axios.tainacan.get('/collections/?nopaging=1fetch_only=name,id', { cancelToken: source.token })
axios.tainacan.get('/collections/?nopaging=1&fetch_only=name,id', { cancelToken: source.token })
.then(res => {
let collections = res.data;
resolve( collections );

View File

@ -167,7 +167,7 @@ export const fetchRepositoryCollectionFilters = ({ dispatch, commit } ) => {
return new Promise((resolve, reject) => {
dispatch('collection/fetchCollectionsForParent', { } ,{ root: true })
dispatch('collection/fetchAllCollectionNames', { } ,{ root: true })
.then((resp) => {
resp.request
.then((res) => {