Documents: Disable delete doc for students

pull/3741/head
Julio Montoya 5 years ago
parent 49b9ea1519
commit 07b45a8b78
  1. 33
      assets/vue/mixins/ListMixin.js
  2. 1
      assets/vue/store/modules/crud.js
  3. 3
      assets/vue/store/security.js
  4. 124
      assets/vue/views/documents/List.vue

@ -12,7 +12,7 @@ export default {
//sortBy: [], vuetify //sortBy: [], vuetify
//sortDesc: [], , vuetify //sortDesc: [], , vuetify
page: 1, page: 1,
itemsPerPage: 5 itemsPerPage: 20
}, },
filters: {} filters: {}
}; };
@ -40,10 +40,36 @@ export default {
this.options.totalItems = this.totalItems; this.options.totalItems = this.totalItems;
} }
}, },
methods: { methods: {
fetchNewItems({ page, itemsPerPage, sortBy, sortDesc, totalItems } = {}) {
let params = {
...this.filters
};
if (itemsPerPage > 0) {
params = { ...params, itemsPerPage, page };
}
if (this.$route.params.node) {
params[`resourceNode.parent`] = this.$route.params.node;
}
if (isString(sortBy) && isBoolean(sortDesc)) {
//params[`order[${sortBy[0]}]`] = sortDesc[0] ? 'desc' : 'asc'
params[`order[${sortBy}]`] = sortDesc ? 'desc' : 'asc'
}
//this.resetList = true;
this.getPage(params).then(() => {
this.options.sortBy = sortBy;
this.options.sortDesc = sortDesc;
this.options.itemsPerPage = itemsPerPage;
this.options.totalItems = totalItems;
});
},
onUpdateOptions({ page, itemsPerPage, sortBy, sortDesc, totalItems } = {}) { onUpdateOptions({ page, itemsPerPage, sortBy, sortDesc, totalItems } = {}) {
console.log({ page, itemsPerPage, sortBy, sortDesc, totalItems }); //console.log({ page, itemsPerPage, sortBy, sortDesc, totalItems });
let params = { let params = {
...this.filters ...this.filters
}; };
@ -62,7 +88,6 @@ export default {
} }
this.resetList = true; this.resetList = true;
console.log(params);
this.getPage(params).then(() => { this.getPage(params).then(() => {
this.options.sortBy = sortBy; this.options.sortBy = sortBy;

@ -121,7 +121,6 @@ export default function makeCrudModule({
retrieved['hydra:totalItems'] retrieved['hydra:totalItems']
); );
commit(ACTIONS.SET_VIEW, retrieved['hydra:view']); commit(ACTIONS.SET_VIEW, retrieved['hydra:view']);
if (true === state.resetList) { if (true === state.resetList) {
commit(ACTIONS.RESET_LIST); commit(ACTIONS.RESET_LIST);
} }

@ -29,6 +29,9 @@ export default {
isAdmin(state, getters) { isAdmin(state, getters) {
return getters.isAuthenticated && (getters.hasRole('ROLE_SUPER_ADMIN') || getters.hasRole('ROLE_ADMIN')); return getters.isAuthenticated && (getters.hasRole('ROLE_SUPER_ADMIN') || getters.hasRole('ROLE_ADMIN'));
}, },
isCurrentTeacher(state, getters) {
return getters.isAuthenticated && (getters.hasRole('ROLE_CURRENT_COURSE_TEACHER'));
},
getUser(state) { getUser(state) {
return state.user; return state.user;
}, },

@ -27,6 +27,20 @@
</b-col> </b-col>
<b-col /> <b-col />
<b-col> <b-col>
<!-- <div v-if="this.selected.length > 0" >-->
<!-- <b-button variant="info" size="sm" @click="deleteSelected">-->
<!-- {{ $t('Info') }}-->
<!-- </b-button>-->
<!-- <b-button variant="secondary" size="sm" @click="deleteSelected">-->
<!-- {{ $t('Edit') }}-->
<!-- </b-button>-->
<!-- <b-button variant="danger" size="sm" @click="deleteSelected">-->
<!-- {{ $t('Delete') }}-->
<!-- </b-button>-->
<!-- </div>-->
<b-pagination <b-pagination
v-model="options.page" v-model="options.page"
:disabled.sync="isLoading" :disabled.sync="isLoading"
@ -51,10 +65,9 @@
:per-page="0" :per-page="0"
:fields="fields" :fields="fields"
:items="items" :items="items"
@row-selected="onRowSelected" @row-selected="onRowSelected"
selectable selectable
small
:current-page.sync="options.page" :current-page.sync="options.page"
:sort-by.sync="options.sortBy" :sort-by.sync="options.sortBy"
:sort-desc.sync="options.sortDesc" :sort-desc.sync="options.sortDesc"
@ -71,16 +84,16 @@
</div> </div>
</template> </template>
<template v-slot:cell(selected)="{ rowSelected }"> <!-- <template v-slot:cell(selected)="{ rowSelected }">-->
<template v-if="rowSelected"> <!-- <template v-if="rowSelected">-->
<span aria-hidden="true">&check;</span> <!-- <span aria-hidden="true">&check;</span>-->
<span class="sr-only">{{ $t('Selected') }}</span> <!-- <span class="sr-only">{{ $t('Selected') }}</span>-->
</template> <!-- </template>-->
<template v-else> <!-- <template v-else>-->
<span aria-hidden="true">&nbsp;</span> <!-- <span aria-hidden="true">&nbsp;</span>-->
<span class="sr-only">{{ $t('Not selected') }}</span> <!-- <span class="sr-only">{{ $t('Not selected') }}</span>-->
</template> <!-- </template>-->
</template> <!-- </template>-->
<template <template
v-slot:cell(resourceNode.title)="row" v-slot:cell(resourceNode.title)="row"
@ -121,6 +134,7 @@
</template> </template>
<template <template
v-if="isAuthenticated && isCurrentTeacher"
v-slot:cell(action)="row" v-slot:cell(action)="row"
> >
<ActionCell <ActionCell
@ -131,6 +145,19 @@
:handle-delete="() => deleteHandler(row.item)" :handle-delete="() => deleteHandler(row.item)"
/> />
</template> </template>
<template
v-else
v-slot:cell(action)="row"
>
<ActionCell
slot="action"
:row="row"
:handle-show="() => showHandler(row.item)"
/>
</template>
</b-table> </b-table>
<p> <p>
@ -159,7 +186,7 @@ export default {
components: { components: {
Toolbar, Toolbar,
ActionCell, ActionCell,
ResourceFileIcon ResourceFileIcon,
}, },
mixins: [ListMixin], mixins: [ListMixin],
data() { data() {
@ -167,7 +194,6 @@ export default {
sortBy: 'title', sortBy: 'title',
sortDesc: false, sortDesc: false,
fields: [ fields: [
'selected',
{label: this.$i18n.t('Title'), key: 'resourceNode.title', sortable: true}, {label: this.$i18n.t('Title'), key: 'resourceNode.title', sortable: true},
{label: this.$i18n.t('Modified'), key: 'resourceNode.updatedAt', sortable: true}, {label: this.$i18n.t('Modified'), key: 'resourceNode.updatedAt', sortable: true},
{label: this.$i18n.t('Size'), key: 'resourceNode.resourceFile.size', sortable: true}, {label: this.$i18n.t('Size'), key: 'resourceNode.resourceFile.size', sortable: true},
@ -176,6 +202,7 @@ export default {
pageOptions: [5, 10, 15, 20, this.$i18n.t('All')], pageOptions: [5, 10, 15, 20, this.$i18n.t('All')],
selected: [], selected: [],
selectMode: 'multi', selectMode: 'multi',
isBusy: false
}; };
}, },
@ -183,15 +210,50 @@ export default {
let nodeId = this.$route.params['node']; let nodeId = this.$route.params['node'];
this.findResourceNode('/api/resource_nodes/' + nodeId); this.findResourceNode('/api/resource_nodes/' + nodeId);
this.onUpdateOptions(this.options); this.onUpdateOptions(this.options);
},
mounted() {
// Detect when scrolled to bottom.
/*const listElm = document.querySelector('#documents');
listElm.addEventListener('scroll', e => {
console.log('aaa');
if(listElm.scrollTop + listElm.clientHeight >= listElm.scrollHeight) {
this.onScroll();
}
});*/
//const tableScrollBody = this.$refs['selectableTable'].$el;
/* Consider debouncing the event call */
//tableScrollBody.addEventListener("scroll", this.onScroll);
//window.addEventListener('scroll', this.onScroll)
window.addEventListener('scroll', () =>{
/*if(window.top.scrollY > window.outerHeight){
if (!this.isBusy) {
this.fetchItems();
}
}*/
});
/*const tableScrollBody = this.$refs['documents'];
tableScrollBody.addEventListener("scroll", this.onScroll);*/
}, },
computed: { computed: {
// From crud.js list function // From crud.js list function
...mapGetters('documents', { ...mapGetters('documents', {
items: 'list' items: 'list',
}), }),
...mapGetters('resourcenode', { ...mapGetters('resourcenode', {
resourceNode: 'getResourceNode' resourceNode: 'getResourceNode'
}), }),
...mapGetters({
'isAuthenticated': 'security/isAuthenticated',
'isAdmin': 'security/isAdmin',
'isCurrentTeacher': 'security/isCurrentTeacher',
}),
// From ListMixin // From ListMixin
...mapFields('documents', { ...mapFields('documents', {
deletedItem: 'deleted', deletedItem: 'deleted',
@ -201,8 +263,40 @@ export default {
totalItems: 'totalItems', totalItems: 'totalItems',
view: 'view' view: 'view'
}), }),
}, },
methods: { methods: {
async fetchItems() {
console.log('fetchItems');
/* No need to call if all items retrieved */
if (this.items.length === this.totalItems) return;
/* Enable busy state */
this.isBusy = true;
/* Missing error handling if call fails */
let currentPage = this.options.page;
console.log(currentPage);
const startIndex = currentPage++ * this.options.itemsPerPage;
const endIndex = startIndex + this.options.itemsPerPage;
console.log(this.items.length);
console.log(this.totalItems);
console.log(startIndex, endIndex);
this.options.page = currentPage;
await this.fetchNewItems(this.options);
//const newItems = await this.callDatabase(startIndex, endIndex);
/* Add new items to existing ones */
//this.items = this.items.concat(newItems);
/* Disable busy state */
this.isBusy = false;
return true;
},
onRowSelected(items) { onRowSelected(items) {
this.selected = items this.selected = items
}, },

Loading…
Cancel
Save