2023-08-03 22:03:40 +08:00
|
|
|
<template>
|
|
|
|
<div class="results-wrapper">
|
2023-09-25 19:58:13 +08:00
|
|
|
<ResultsToolbar
|
|
|
|
ref="resultsToolbar"
|
|
|
|
:sort="sort"
|
2023-09-06 20:58:59 +08:00
|
|
|
:canCreate="canCreate == 'true'"
|
2023-09-08 19:42:02 +08:00
|
|
|
:archived="archived == 'true'"
|
|
|
|
:active_url="active_url"
|
|
|
|
:archived_url="archived_url"
|
2023-09-25 19:58:13 +08:00
|
|
|
:headerSticked="headerSticked"
|
|
|
|
:moduleName="moduleName"
|
2023-08-23 17:59:21 +08:00
|
|
|
@setSort="setSort"
|
|
|
|
@setFilters="setFilters"
|
|
|
|
@newResult="createResult"
|
|
|
|
@expandAll="expandAll"
|
|
|
|
@collapseAll="collapseAll"
|
2023-08-31 21:50:35 +08:00
|
|
|
class="my-4"
|
2023-08-23 17:59:21 +08:00
|
|
|
/>
|
2023-08-03 22:03:40 +08:00
|
|
|
<div class="results-list">
|
2023-09-12 23:33:47 +08:00
|
|
|
<Result v-for="result in results" :key="result.id"
|
2023-11-20 18:38:41 +08:00
|
|
|
ref="results"
|
2023-08-21 15:22:56 +08:00
|
|
|
:result="result"
|
|
|
|
:resultToReload="resultToReload"
|
2023-10-19 21:51:18 +08:00
|
|
|
:activeDragResult="activeDragResult"
|
2024-07-30 15:31:21 +08:00
|
|
|
:userSettingsUrl="userSettingsUrl"
|
2023-08-21 15:22:56 +08:00
|
|
|
@result:elements:loaded="resultToReload = null"
|
|
|
|
@result:move_element="reloadResult"
|
2023-08-24 21:55:20 +08:00
|
|
|
@result:attachments:loaded="resultToReload = null"
|
|
|
|
@result:move_attachment="reloadResult"
|
2023-09-06 20:58:59 +08:00
|
|
|
@result:duplicated="resetPageAndReload"
|
|
|
|
@result:archived="removeResult"
|
|
|
|
@result:deleted="removeResult"
|
|
|
|
@result:restored="removeResult"
|
2023-10-19 21:51:18 +08:00
|
|
|
@result:drag_enter="dragEnter"
|
2023-08-21 15:22:56 +08:00
|
|
|
/>
|
2023-08-03 22:03:40 +08:00
|
|
|
</div>
|
2023-10-26 18:01:48 +08:00
|
|
|
<clipboardPasteModal v-if="showClipboardPasteModal"
|
|
|
|
:image="pasteImages"
|
|
|
|
:objects="results"
|
|
|
|
:objectType="'result'"
|
|
|
|
:selectedObjectId="firstObjectInViewport()"
|
|
|
|
@files="uploadFilesToResult"
|
|
|
|
@cancel="showClipboardPasteModal = false"
|
|
|
|
/>
|
2023-08-03 22:03:40 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-01-04 23:34:36 +08:00
|
|
|
import axios from '../../packs/custom_axios.js';
|
|
|
|
import ResultsToolbar from './results_toolbar.vue';
|
|
|
|
import Result from './result.vue';
|
2023-08-03 22:03:40 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
import stackableHeadersMixin from '../mixins/stackableHeadersMixin';
|
|
|
|
import moduleNameObserver from '../mixins/moduleNameObserver';
|
2023-09-25 19:58:13 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
import clipboardPasteModal from '../shared/content/attachments/clipboard_paste_modal.vue';
|
|
|
|
import AssetPasteMixin from '../shared/content/attachments/mixins/paste.js';
|
2023-10-26 18:01:48 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
export default {
|
|
|
|
name: 'Results',
|
|
|
|
components: { ResultsToolbar, Result, clipboardPasteModal },
|
|
|
|
mixins: [stackableHeadersMixin, moduleNameObserver, AssetPasteMixin],
|
|
|
|
props: {
|
|
|
|
url: { type: String, required: true },
|
|
|
|
canCreate: { type: String, required: true },
|
|
|
|
archived: { type: String, required: true },
|
|
|
|
active_url: { type: String, required: true },
|
2024-07-30 15:31:21 +08:00
|
|
|
archived_url: { type: String, required: true },
|
|
|
|
userSettingsUrl: { type: String, required: false }
|
2024-01-04 23:34:36 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
results: [],
|
2024-04-04 15:10:33 +08:00
|
|
|
sort: null,
|
2024-01-04 23:34:36 +08:00
|
|
|
filters: {},
|
|
|
|
resultToReload: null,
|
|
|
|
nextPageUrl: null,
|
|
|
|
loadingPage: false,
|
2024-07-30 15:31:21 +08:00
|
|
|
activeDragResult: null,
|
|
|
|
userSettingsUrl: null
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2024-07-30 15:31:21 +08:00
|
|
|
this.userSettingsUrl = document.querySelector('meta[name="user-settings-url"]').getAttribute('content');
|
2024-01-04 23:34:36 +08:00
|
|
|
window.addEventListener('scroll', this.loadResults, false);
|
|
|
|
window.addEventListener('scroll', this.initStackableHeaders, false);
|
|
|
|
this.nextPageUrl = this.url;
|
|
|
|
this.loadResults();
|
|
|
|
this.initStackableHeaders();
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
window.removeEventListener('scroll', this.loadResults, false);
|
|
|
|
window.removeEventListener('scroll', this.initStackableHeaders, false);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getHeader() {
|
|
|
|
return this.$refs.resultsToolbar.$refs.resultsHeaderToolbar;
|
2023-08-03 22:03:40 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
reloadResult(result) {
|
|
|
|
this.resultToReload = result;
|
2023-08-03 22:03:40 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
resetPageAndReload() {
|
2023-09-12 23:33:47 +08:00
|
|
|
this.nextPageUrl = this.url;
|
2024-01-04 23:34:36 +08:00
|
|
|
this.results = [];
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.loadResults();
|
|
|
|
});
|
2023-08-30 21:47:54 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
loadResults() {
|
|
|
|
if (this.nextPageUrl === null || this.loadingPage) return;
|
2023-08-30 21:47:54 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
if (window.scrollY + window.innerHeight >= document.body.scrollHeight - 20) {
|
|
|
|
this.loadingPage = true;
|
2024-04-04 15:10:33 +08:00
|
|
|
const params = this.sort ? { ...this.filters, sort: this.sort } : { ...this.filters };
|
|
|
|
axios.get(this.nextPageUrl, { params }).then((response) => {
|
2024-01-04 23:34:36 +08:00
|
|
|
this.results = this.results.concat(response.data.data);
|
2024-04-04 15:10:33 +08:00
|
|
|
this.sort = response.data.meta.sort;
|
2024-01-04 23:34:36 +08:00
|
|
|
this.nextPageUrl = response.data.links.next;
|
|
|
|
this.loadingPage = false;
|
|
|
|
});
|
2023-08-03 22:03:40 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
},
|
|
|
|
setSort(sort) {
|
|
|
|
this.sort = sort;
|
|
|
|
this.resetPageAndReload();
|
|
|
|
},
|
|
|
|
setFilters(filters) {
|
|
|
|
this.filters = filters;
|
|
|
|
this.resetPageAndReload();
|
|
|
|
},
|
|
|
|
createResult() {
|
|
|
|
axios.post(
|
|
|
|
`${this.url}`,
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
).then(
|
|
|
|
(response) => {
|
|
|
|
this.results = [{ newResult: true, ...response.data.data }, ...this.results];
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
expandAll() {
|
|
|
|
$('.result-wrapper .collapse').collapse('show');
|
2024-06-27 21:31:35 +08:00
|
|
|
this.toggleCollapsed(false);
|
2024-01-04 23:34:36 +08:00
|
|
|
},
|
|
|
|
collapseAll() {
|
|
|
|
$('.result-wrapper .collapse').collapse('hide');
|
2024-06-27 21:31:35 +08:00
|
|
|
this.toggleCollapsed(true);
|
|
|
|
},
|
|
|
|
toggleCollapsed(newState) {
|
|
|
|
this.results = this.results.map((result) => ({
|
|
|
|
...result,
|
|
|
|
attributes: {
|
|
|
|
...result.attributes,
|
|
|
|
collapsed: newState
|
|
|
|
}
|
|
|
|
}));
|
2024-01-04 23:34:36 +08:00
|
|
|
},
|
|
|
|
removeResult(result_id) {
|
|
|
|
this.results = this.results.filter((r) => r.id != result_id);
|
|
|
|
},
|
|
|
|
dragEnter(id) {
|
|
|
|
this.activeDragResult = id;
|
|
|
|
},
|
|
|
|
uploadFilesToResult(file, resultId) {
|
|
|
|
this.$refs.results.find((child) => child.result?.id == resultId).uploadFiles(file);
|
|
|
|
},
|
|
|
|
firstObjectInViewport() {
|
|
|
|
const result = $('.result-wrapper:not(.locked)').toArray().find((element) => {
|
|
|
|
const { top, bottom } = element.getBoundingClientRect();
|
|
|
|
return bottom > 0 && top < window.innerHeight;
|
|
|
|
});
|
|
|
|
return result ? result.dataset.id : null;
|
2023-08-03 22:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2023-08-03 22:03:40 +08:00
|
|
|
</script>
|