Skip to content
Snippets Groups Projects
Commit 99e6757b authored by Elmar Ludwig's avatar Elmar Ludwig
Browse files

avoid pre-loading all file-refs available to the user, fixes #2566

Closes #2566

Merge request studip/studip!1748
parent 736c8d12
No related branches found
No related tags found
No related merge requests found
...@@ -7,17 +7,10 @@ ...@@ -7,17 +7,10 @@
<option v-show="canBeEmpty" value=""> <option v-show="canBeEmpty" value="">
<translate>Keine Auswahl</translate> <translate>Keine Auswahl</translate>
</option> </option>
<optgroup v-if="this.context.type === 'courses' && courseFiles.length !== 0" :label="textOptGroupCourse"> <option v-for="(file, index) in files" :key="index" :value="file.id">
<option v-for="(file, index) in courseFiles" :key="index" :value="file.id"> {{ file.name }}
{{ file.name }} </option>
</option> <option v-show="files.length === 0" disabled>
</optgroup>
<optgroup v-if="userFiles.length !== 0" :label="textOptGroupUser">
<option v-for="(file, index) in userFiles" :key="index" :value="file.id">
{{ file.name }}
</option>
</optgroup>
<option v-show="userFiles.length === 0 && courseFiles.length === 0" disabled>
<translate>Keine Dateien vorhanden</translate> <translate>Keine Dateien vorhanden</translate>
</option> </option>
</select> </select>
...@@ -45,17 +38,12 @@ export default { ...@@ -45,17 +38,12 @@ export default {
return { return {
currentValue: '', currentValue: '',
selectedFolderId: '', selectedFolderId: '',
loadedCourseFiles: [], files: [],
courseFiles: [],
loadedUserFiles: [],
userFiles: [],
textOptGroupCourse: this.$gettext('Dateibereich der Veranstaltung'),
textOptGroupUser: this.$gettext('Persönlicher Dateibereich'),
}; };
}, },
computed: { computed: {
...mapGetters({ ...mapGetters({
context: 'context', fileRefById: 'file-refs/byId',
relatedFileRefs: 'file-refs/related', relatedFileRefs: 'file-refs/related',
urlHelper: 'urlHelper', urlHelper: 'urlHelper',
userId: 'userId', userId: 'userId',
...@@ -64,12 +52,13 @@ export default { ...@@ -64,12 +52,13 @@ export default {
}, },
methods: { methods: {
...mapActions({ ...mapActions({
loadFileRef: 'file-refs/loadById',
loadRelatedFileRefs: 'file-refs/loadRelated', loadRelatedFileRefs: 'file-refs/loadRelated',
}), }),
selectFile() { selectFile() {
this.$emit( this.$emit(
'selectFile', 'selectFile',
this.userFiles.concat(this.courseFiles).find((file) => file.id === this.currentValue) this.files.find((file) => file.id === this.currentValue)
); );
}, },
filterFiles(loadArray) { filterFiles(loadArray) {
...@@ -79,9 +68,6 @@ export default { ...@@ -79,9 +68,6 @@ export default {
if (fileTermsOfUse !== null && fileTermsOfUse.attributes['download-condition'] !== 0) { if (fileTermsOfUse !== null && fileTermsOfUse.attributes['download-condition'] !== 0) {
return false; return false;
} }
if (this.selectedFolderId !== '' && this.selectedFolderId !== file.relationships.parent.data.id) {
return false;
}
if (this.mimeType !== '' && this.mimeType !== file.attributes['mime-type']) { if (this.mimeType !== '' && this.mimeType !== file.attributes['mime-type']) {
return false; return false;
} }
...@@ -115,40 +101,32 @@ export default { ...@@ -115,40 +101,32 @@ export default {
), ),
})); }));
}, },
updateFiles() { async getFolderFiles() {
this.courseFiles = this.filterFiles(this.loadedCourseFiles); const parent = { type: 'folders', id: `${this.selectedFolderId}` };
this.userFiles = this.filterFiles(this.loadedUserFiles);
},
async getCourseFiles() {
const parent = { type: 'courses', id: `${this.context.id}` };
const relationship = 'file-refs'; const relationship = 'file-refs';
const options = { include: 'terms-of-use', 'page[limit]': 10000 }; const options = { include: 'terms-of-use', 'page[limit]': 10000 };
await this.loadRelatedFileRefs({ parent, relationship, options }); await this.loadRelatedFileRefs({ parent, relationship, options });
this.loadedCourseFiles = this.relatedFileRefs({ parent, relationship }); const files = this.relatedFileRefs({ parent, relationship });
this.updateFiles(); this.files = this.filterFiles(files);
},
async getUserFiles() {
const parent = { type: 'users', id: `${this.userId}` };
const relationship = 'file-refs';
const options = { include: 'terms-of-use', 'page[limit]': 10000 };
await this.loadRelatedFileRefs({ parent, relationship, options });
this.loadedUserFiles = this.relatedFileRefs({ parent, relationship });
this.updateFiles();
}, },
}, },
mounted() { async mounted() {
if (this.context.type !== 'users') { if (this.value != '') {
this.getCourseFiles(); await this.loadFileRef({ id: this.value });
} const fileRef = this.fileRefById({ id: this.value });
this.getUserFiles();
this.currentValue = this.value; if (fileRef) {
this.selectedFolderId = fileRef.relationships.parent.data.id;
this.currentValue = this.value;
}
}
}, },
watch: { watch: {
selectedFolderId() { selectedFolderId() {
this.updateFiles(); if (this.selectedFolderId !== '') {
this.getFolderFiles();
}
}, },
}, },
}; };
......
...@@ -158,5 +158,10 @@ export default { ...@@ -158,5 +158,10 @@ export default {
await this.getUserFolders(); await this.getUserFolders();
this.confirmSelectedFolder(); this.confirmSelectedFolder();
}, },
watch: {
value() {
this.currentValue = this.value;
}
},
}; };
</script> </script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment