Documents: fix update

pull/3890/head
Julio Montoya 5 years ago
parent e190bf5ad9
commit f559f37e76
  1. 12
      assets/vue/App.vue
  2. 2
      assets/vue/components/Toolbar.vue
  3. 1
      assets/vue/components/documents/Form.vue
  4. 20
      assets/vue/components/documents/ResourceLinkForm.vue
  5. 38
      assets/vue/mixins/ListMixin.js
  6. 2
      assets/vue/mixins/ShowMixin.js
  7. 30
      assets/vue/mixins/UpdateMixin.js
  8. 12
      assets/vue/store/modules/crud.js
  9. 4
      assets/vue/utils/fetch.js
  10. 9
      assets/vue/views/documents/List.vue
  11. 1
      assets/vue/views/documents/Update.vue
  12. 1
      assets/vue/views/documents/UpdateFile.vue
  13. 4
      src/CoreBundle/EventSubscriber/ResolveResourceFileContentUrlSubscriber.php

@ -225,12 +225,8 @@ export default {
const layout = computed( const layout = computed(
() => `${currentRoute.value.meta.layout || defaultLayout}Layout` () => `${currentRoute.value.meta.layout || defaultLayout}Layout`
); );
const rightDrawerOpen = ref(false); const rightDrawerOpen = ref(false);
//console.log('isSidebarOpen');console.log(isSidebarOpen.value);
console.log('isSidebarOpen');
console.log(isSidebarOpen.value);
return { return {
layout, layout,
@ -308,7 +304,6 @@ export default {
//let content = document.getElementById("sectionMainContent"); //let content = document.getElementById("sectionMainContent");
this.legacyContent = ''; this.legacyContent = '';
/*if (content && false === this.contentLoaded) { /*if (content && false === this.contentLoaded) {
console.log('updated ok '); console.log('updated ok ');
content.style.display = 'block'; content.style.display = 'block';
this.legacyContent = content.outerHTML; this.legacyContent = content.outerHTML;
@ -333,11 +328,10 @@ export default {
} else { } else {
if (document.querySelector("#sectionMainContent")) { if (document.querySelector("#sectionMainContent")) {
document.querySelector("#sectionMainContent").remove(); document.querySelector("#sectionMainContent").remove();
console.log('remove'); //console.log('remove');
} }
console.log('Replace URL', url); //console.log('Replace URL', url);
window.location.replace(url); window.location.replace(url);
/*axios.get(url, { /*axios.get(url, {

@ -1,6 +1,6 @@
<template> <template>
<div class="q-card"> <div class="q-card">
<slot name="left" /> <!-- <slot name="left" />-->
<!-- <q-space />--> <!-- <q-space />-->
<div class="p-4 flex flex-row gap-1"> <div class="p-4 flex flex-row gap-1">
<q-btn <q-btn

@ -46,7 +46,6 @@ export default {
}, },
titleErrors() { titleErrors() {
const errors = []; const errors = [];
if (!this.v$.item.title.$dirty) return errors; if (!this.v$.item.title.$dirty) return errors;
has(this.violations, 'title') && errors.push(this.violations.title); has(this.violations, 'title') && errors.push(this.violations.title);

@ -1,10 +1,5 @@
<template> <template>
<v-row> <div class="q-card">
<v-col
cols="12"
sm="6"
md="6"
>
<div v-if="item"> <div v-if="item">
<div v-if="item['resourceLinkListFromEntity']"> <div v-if="item['resourceLinkListFromEntity']">
<ul> <ul>
@ -23,9 +18,10 @@
{{ $t('Group') }}: {{ link.session.resourceNode.title }} {{ $t('Group') }}: {{ link.session.resourceNode.title }}
</div> </div>
<v-select <q-select
v-model="link.visibility" v-model="link.visibility"
:options="visibilityList" :options="visibilityList"
emit-value
label="Status" label="Status"
persistent-hint persistent-hint
/> />
@ -33,8 +29,7 @@
</ul> </ul>
</div> </div>
</div> </div>
</v-col> </div>
</v-row>
</template> </template>
<script> <script>
@ -65,8 +60,8 @@ export default {
return { return {
// See ResourceLink entity constants. // See ResourceLink entity constants.
visibilityList: [ visibilityList: [
{value: 2, text: 'Published'}, {value: 2, label: 'Published'},
{value: 0, text: 'Draft'}, {value: 0, label: 'Draft'},
], ],
}; };
}, },
@ -85,9 +80,6 @@ export default {
violations() { violations() {
return this.errors || {}; return this.errors || {};
} }
},
methods: {
}, },
validations: { validations: {
item: { item: {

@ -36,10 +36,9 @@ export default {
console.log('watch listmixin'); console.log('watch listmixin');
// react to route changes... // react to route changes...
this.resetList = true; this.resetList = true;
/*this.onRequest({
this.onRequest({
pagination: this.pagination, pagination: this.pagination,
}); });*/
let nodeId = this.$route.params['node']; let nodeId = this.$route.params['node'];
if (!isEmpty(nodeId)) { if (!isEmpty(nodeId)) {
this.findResourceNode('/api/resource_nodes/'+ nodeId); this.findResourceNode('/api/resource_nodes/'+ nodeId);
@ -47,23 +46,26 @@ export default {
}, },
deletedItem(item) { deletedItem(item) {
console.log('deletedItem');
this.showMessage(this.$i18n.t('{resource} deleted', {'resource': item['resourceNode'].title})); this.showMessage(this.$i18n.t('{resource} deleted', {'resource': item['resourceNode'].title}));
// this.showMessage(`${item['@id']} deleted.`);
}, },
error(message) { error(message) {
console.log('error');
message && this.showError(message); message && this.showError(message);
}, },
items() { /*items() {
console.log('items');
this.pagination.page = this.nextPage; this.pagination.page = this.nextPage;
if (isEmpty(this.pagination.page)) { if (isEmpty(this.pagination.page)) {
this.pagination.page = 1; this.pagination.page = 1;
} }
console.log(this.pagination.page );
this.pagination.rowsNumber = this.totalItems; this.pagination.rowsNumber = this.totalItems;
this.nextPage = null; this.nextPage = null;
//this.options.totalItems = this.totalItems; //this.options.totalItems = this.totalItems;
} }*/
}, },
methods: { methods: {
onRequest(props) { onRequest(props) {
@ -101,15 +103,9 @@ export default {
this.pagination.descending = descending; this.pagination.descending = descending;
this.pagination.rowsPerPage = itemsPerPage; this.pagination.rowsPerPage = itemsPerPage;
}); });
/*this.getPage({ params }).then(() => {
this.pagination.sortBy = sortBy;
this.pagination.descending = descending;
this.pagination.rowsPerPage = itemsPerPage;
//this.filters = { ...this.filter };
});*/
}, },
fetchNewItems({ page, itemsPerPage, sortBy, sortDesc, totalItems } = {}) { fetchNewItems({ page, itemsPerPage, sortBy, sortDesc, totalItems } = {}) {
console.log('fetchNewItems');
let params = { let params = {
...this.filters ...this.filters
}; };
@ -127,29 +123,29 @@ export default {
params[`order[${sortBy}]`] = sortDesc ? 'desc' : 'asc' params[`order[${sortBy}]`] = sortDesc ? 'desc' : 'asc'
} }
//this.resetList = true;
//this.getPage(params).then(() => {
this.options.sortBy = sortBy; this.options.sortBy = sortBy;
this.options.sortDesc = sortDesc; this.options.sortDesc = sortDesc;
this.options.itemsPerPage = itemsPerPage; this.options.itemsPerPage = itemsPerPage;
this.options.totalItems = totalItems; this.options.totalItems = totalItems;
//});
}, },
onSendFilter() { onSendFilter() {
console.log('onSendFilter');
this.resetList = true; this.resetList = true;
this.pagination.page = 1; this.pagination.page = 1;
this.onRequest({pagination: this.pagination}) this.onRequest({pagination: this.pagination})
}, },
resetFilter() { resetFilter() {
console.log('resetFilter');
this.filters = {}; this.filters = {};
this.pagination.page = 1; this.pagination.page = 1;
this.onRequest({pagination: this.pagination}) this.onRequest({pagination: this.pagination})
}, },
addHandler() { addHandler() {
console.log('addHandler');
let folderParams = this.$route.query; let folderParams = this.$route.query;
this.$router.push({name: `${this.$options.servicePrefix}Create`, query: folderParams}); this.$router.push({name: `${this.$options.servicePrefix}Create`, query: folderParams});
}, },
@ -165,6 +161,7 @@ export default {
}, },
showHandler(item) { showHandler(item) {
console.log('showHandler');
let folderParams = this.$route.query; let folderParams = this.$route.query;
folderParams['id'] = item['@id']; folderParams['id'] = item['@id'];
@ -195,6 +192,7 @@ export default {
this.onUpdateOptions(this.options);*/ this.onUpdateOptions(this.options);*/
}, },
editHandler(item) { editHandler(item) {
console.log('editHandler');
let folderParams = this.$route.query; let folderParams = this.$route.query;
folderParams['id'] = item['@id']; folderParams['id'] = item['@id'];
@ -207,12 +205,11 @@ export default {
} }
if ('file' === item.filetype) { if ('file' === item.filetype) {
folderParams['getFile'] = false; folderParams['getFile'] = true;
if (item.resourceNode.resourceFile && if (item.resourceNode.resourceFile &&
item.resourceNode.resourceFile.mimeType && item.resourceNode.resourceFile.mimeType &&
'text/html' === item.resourceNode.resourceFile.mimeType) { 'text/html' === item.resourceNode.resourceFile.mimeType) {
folderParams['getFile'] = true; //folderParams['getFile'] = true;
} }
this.$router.push({ this.$router.push({
@ -223,6 +220,7 @@ export default {
} }
}, },
deleteHandler(item) { deleteHandler(item) {
console.log('deleteHandler');
console.log(item); console.log(item);
this.pagination.page = 1; this.pagination.page = 1;
this.deleteItem(item).then(() => this.deleteItem(item).then(() =>

@ -37,7 +37,7 @@ export default {
this.deleteItem(this.item).then(() => { this.deleteItem(this.item).then(() => {
let folderParams = this.$route.query; let folderParams = this.$route.query;
folderParams['id'] = ''; folderParams['id'] = '';
this.showMessage(`${this.item['@id']} deleted.`); //this.showMessage(`${this.item['@id']} deleted.`);
this.$router this.$router
.push( .push(
{ {

@ -14,13 +14,17 @@ export default {
}, },
}; };
}, },
created() { mounted() {
console.log('mounted');
// Changed // Changed
let id = this.$route.params.id; let id = this.$route.params.id;
if (isEmpty(id)) { if (isEmpty(id)) {
id = this.$route.query.id; id = this.$route.query.id;
} }
if (!isEmpty(id)) {
// Ajax call
this.retrieve(decodeURIComponent(id)); this.retrieve(decodeURIComponent(id));
}
// default // default
//this.retrieve(decodeURIComponent(this.$route.params.id)); //this.retrieve(decodeURIComponent(this.$route.params.id));
}, },
@ -29,27 +33,32 @@ export default {
}, },
computed: { computed: {
retrieved() { retrieved() {
// call from list
console.log('retrieved'); console.log('update mixin retrieved');
let id = this.$route.params.id; let id = this.$route.params.id;
console.log('first');
console.log(id); console.log(id);
if (isEmpty(id)) { if (isEmpty(id)) {
console.log('second');
id = this.$route.query.id; id = this.$route.query.id;
console.log(id);
} }
let item = this.find(decodeURIComponent(id)); let item = this.find(decodeURIComponent(id));
console.log(item);
return item; return item;
//return this.find(decodeURIComponent(this.$route.params.id)); //return this.find(decodeURIComponent(this.$route.params.id));
} }
}, },
methods: { methods: {
del() { del() {
console.log('del');
console.log(this.retrieved); console.log(this.retrieved);
this.deleteItem(this.retrieved).then(() => { this.deleteItem(this.retrieved).then(() => {
let folderParams = this.$route.query; let folderParams = this.$route.query;
this.showMessage(`${this.item['@id']} deleted.`); //this.showMessage(`${this.item['@id']} deleted.`);
this.$router this.$router
.push({ .push({
name: `${this.$options.servicePrefix}List`, name: `${this.$options.servicePrefix}List`,
@ -65,23 +74,24 @@ export default {
this.delReset(); this.delReset();
this.createReset(); this.createReset();
}, },
onSendForm() { onSendForm() {
console.log('onSendForm');
const updateForm = this.$refs.updateForm; const updateForm = this.$refs.updateForm;
updateForm.v$.$touch(); updateForm.v$.$touch();
console.log('onSendForm');
if (!updateForm.v$.$invalid) { if (!updateForm.v$.$invalid) {
this.update(updateForm.v$.item.$model); this.update(updateForm.v$.item.$model);
} }
}, },
resetForm() { resetForm() {
console.log('resetForm');
this.$refs.updateForm.v$.$reset(); this.$refs.updateForm.v$.$reset();
this.item = { ...this.retrieved }; this.item = { ...this.retrieved };
} }
}, },
watch: { watch: {
deleted(deleted) { deleted(deleted) {
console.log('deleted');
if (!deleted) { if (!deleted) {
return; return;
} }
@ -96,19 +106,25 @@ export default {
}, },
error(message) { error(message) {
console.log('error');
message && this.showError(message); message && this.showError(message);
}, },
deleteError(message) { deleteError(message) {
console.log('deleteError');
message && this.showError(message); message && this.showError(message);
}, },
updated(val) { updated(val) {
console.log('updated');
this.showMessage(`${val['@id']} updated.`); this.showMessage(`${val['@id']} updated.`);
}, },
retrieved(val) { retrieved(val) {
console.log('retrieved(val)');
if (!isEmpty(val)) {
this.item = {...val}; this.item = {...val};
} }
} }
}
}; };

@ -74,7 +74,6 @@ export default function makeCrudModule({
.then(data => { .then(data => {
commit(ACTIONS.TOGGLE_LOADING); commit(ACTIONS.TOGGLE_LOADING);
commit(ACTIONS.ADD, data); commit(ACTIONS.ADD, data);
commit(ACTIONS.SET_CREATED, data); commit(ACTIONS.SET_CREATED, data);
}) })
.catch(e => handleError(commit, e)); .catch(e => handleError(commit, e));
@ -152,7 +151,6 @@ export default function makeCrudModule({
{ params = { properties: ['@id', 'name'] } } = {} { params = { properties: ['@id', 'name'] } } = {}
) => { ) => {
commit(ACTIONS.TOGGLE_LOADING); commit(ACTIONS.TOGGLE_LOADING);
if (!service) throw new Error('No service specified!'); if (!service) throw new Error('No service specified!');
service service
@ -166,7 +164,6 @@ export default function makeCrudModule({
}) })
.catch(e => handleError(commit, e)); .catch(e => handleError(commit, e));
}, },
load: ({ commit }, id, options = {}) => { load: ({ commit }, id, options = {}) => {
if (!service) throw new Error('No service specified!'); if (!service) throw new Error('No service specified!');
@ -185,7 +182,8 @@ export default function makeCrudModule({
.catch(e => handleError(commit, e)); .catch(e => handleError(commit, e));
}, },
findResourceNode: ({ commit }, id) => { findResourceNode: ({ commit }, id) => {
//console.log('findResourceNode'); console.log('findResourceNode');
console.log(id);
if (!service) throw new Error('No service specified!'); if (!service) throw new Error('No service specified!');
service service
@ -212,6 +210,7 @@ export default function makeCrudModule({
commit(ACTIONS.RESET_UPDATE); commit(ACTIONS.RESET_UPDATE);
}, },
update: ({ commit }, item) => { update: ({ commit }, item) => {
console.log('crud update');
commit(ACTIONS.SET_ERROR, ''); commit(ACTIONS.SET_ERROR, '');
commit(ACTIONS.TOGGLE_LOADING); commit(ACTIONS.TOGGLE_LOADING);
@ -246,6 +245,7 @@ export default function makeCrudModule({
//this.$set(state, 'isLoading', false); //this.$set(state, 'isLoading', false);
}, },
[ACTIONS.ADD]: (state, item) => { [ACTIONS.ADD]: (state, item) => {
console.log('ACTIONS.ADD');
//this.$set(state.byId, item['@id'], item); //this.$set(state.byId, item['@id'], item);
state.byId[item['@id']] = item; state.byId[item['@id']] = item;
state.isLoading = false; state.isLoading = false;
@ -297,6 +297,7 @@ export default function makeCrudModule({
Object.assign(state, { created }); Object.assign(state, { created });
}, },
[ACTIONS.SET_DELETED]: (state, deleted) => { [ACTIONS.SET_DELETED]: (state, deleted) => {
console.log('SET_DELETED');
if (!state.allIds.includes(deleted['@id'])) { if (!state.allIds.includes(deleted['@id'])) {
return; return;
} }
@ -307,6 +308,7 @@ export default function makeCrudModule({
}); });
}, },
[ACTIONS.SET_DELETED_MULTIPLE]: (state, deleted) => { [ACTIONS.SET_DELETED_MULTIPLE]: (state, deleted) => {
console.log('SET_DELETED_MULTIPLE');
//console.log(deleted['@id']); //console.log(deleted['@id']);
/*if (!state.allIds.includes(deleted['@id'])) { /*if (!state.allIds.includes(deleted['@id'])) {
return; return;
@ -331,6 +333,8 @@ export default function makeCrudModule({
Object.assign(state, { totalItems }); Object.assign(state, { totalItems });
}, },
[ACTIONS.SET_UPDATED]: (state, updated) => { [ACTIONS.SET_UPDATED]: (state, updated) => {
console.log('SET_UPDATED');
console.log(updated);
Object.assign(state, { Object.assign(state, {
byId: { byId: {
[updated['@id']]: updated [updated['@id']]: updated

@ -23,7 +23,7 @@ const makeParamArray = (key, arr) =>
export default function(id, options = {}) { export default function(id, options = {}) {
console.log('fetch'); console.log('fetch');
console.log(options.method); console.log(options.method, 'method');
if ('undefined' === typeof options.headers) options.headers = new Headers(); if ('undefined' === typeof options.headers) options.headers = new Headers();
@ -123,8 +123,6 @@ export default function(id, options = {}) {
}*/ }*/
return global.fetch(new URL(id, entryPoint), options).then(response => { return global.fetch(new URL(id, entryPoint), options).then(response => {
console.log(response);
if (response.ok) return response; if (response.ok) return response;
return response.json().then(json => { return response.json().then(json => {

@ -19,12 +19,12 @@
<!-- />--> <!-- />-->
<!-- </DataFilter>--> <!-- </DataFilter>-->
<!-- :filter="filter"-->
<q-table <q-table
dense dense
:rows="items" :rows="items"
:columns="columns" :columns="columns"
row-key="@id" row-key="@id"
:filter="filter"
@request="onRequest" @request="onRequest"
v-model:pagination="pagination" v-model:pagination="pagination"
:no-data-label="$t('Data unavailable')" :no-data-label="$t('Data unavailable')"
@ -131,6 +131,9 @@ export default {
}; };
}, },
created() { created() {
},
mounted() {
console.log('vue/views/documents/List.vue'); console.log('vue/views/documents/List.vue');
const route = useRoute() const route = useRoute()
let nodeId = route.params['node']; let nodeId = route.params['node'];
@ -141,8 +144,6 @@ export default {
this.onRequest({ this.onRequest({
pagination: this.pagination, pagination: this.pagination,
}); });
},
mounted() {
// Detect when scrolled to bottom. // Detect when scrolled to bottom.
/*const listElm = document.querySelector('#documents'); /*const listElm = document.querySelector('#documents');
listElm.addEventListener('scroll', e => { listElm.addEventListener('scroll', e => {
@ -206,7 +207,6 @@ export default {
if (this.item.title.trim()) { if (this.item.title.trim()) {
if (this.item.id) { if (this.item.id) {
//this.$toast.add({severity:'success', summary: 'Successful', detail: 'Product Updated', life: 3000});
} else { } else {
//this.products.push(this.product); //this.products.push(this.product);
this.item.parentResourceNodeId = this.$route.params.node; this.item.parentResourceNodeId = this.$route.params.node;
@ -218,7 +218,6 @@ export default {
}]); }]);
this.create(this.item); this.create(this.item);
//this.$toast.add({severity:'success', summary: 'Successful', detail: 'Product Created', life: 3000});
this.showMessage('Saved'); this.showMessage('Saved');
} }

@ -42,7 +42,6 @@ export default {
ResourceLinkForm ResourceLinkForm
}, },
mixins: [UpdateMixin], mixins: [UpdateMixin],
computed: { computed: {
...mapFields('documents', { ...mapFields('documents', {
deleteLoading: 'isLoading', deleteLoading: 'isLoading',

@ -58,7 +58,6 @@ export default {
}), }),
...mapGetters('documents', ['find']) ...mapGetters('documents', ['find'])
}, },
methods: { methods: {
...mapActions('documents', { ...mapActions('documents', {
createReset: 'resetCreate', createReset: 'resetCreate',

@ -91,10 +91,10 @@ class ResolveResourceFileContentUrlSubscriber implements EventSubscriberInterfac
'type' => $resourceNode->getResourceType()->getName(), 'type' => $resourceNode->getResourceType()->getName(),
]; ];
if ($getFile) { //if ($getFile) {
// Get all links from resource. // Get all links from resource.
$mediaObject->setResourceLinkListFromEntity(); $mediaObject->setResourceLinkListFromEntity();
} //}
$mediaObject->contentUrl = $this->generator->generate('chamilo_core_resource_view', $params); $mediaObject->contentUrl = $this->generator->generate('chamilo_core_resource_view', $params);
$mediaObject->downloadUrl = $this->generator->generate('chamilo_core_resource_download', $params); $mediaObject->downloadUrl = $this->generator->generate('chamilo_core_resource_download', $params);

Loading…
Cancel
Save