Documents: fix update

pull/3890/head
Julio Montoya 4 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. 34
      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. 8
      src/CoreBundle/EventSubscriber/ResolveResourceFileContentUrlSubscriber.php

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

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

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

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

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

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

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

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

@ -23,7 +23,7 @@ const makeParamArray = (key, arr) =>
export default function(id, options = {}) {
console.log('fetch');
console.log(options.method);
console.log(options.method, 'method');
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 => {
console.log(response);
if (response.ok) return response;
return response.json().then(json => {

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

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

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

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

Loading…
Cancel
Save