2023-08-03 22:03:40 +08:00
|
|
|
<template>
|
|
|
|
<div class="results-wrapper">
|
2023-08-23 17:59:21 +08:00
|
|
|
<ResultsToolbar :sort="sort"
|
|
|
|
@setSort="setSort"
|
|
|
|
@setFilters="setFilters"
|
|
|
|
@newResult="createResult"
|
|
|
|
@expandAll="expandAll"
|
|
|
|
@collapseAll="collapseAll"
|
|
|
|
class="mb-3"
|
|
|
|
/>
|
2023-08-03 22:03:40 +08:00
|
|
|
<div class="results-list">
|
2023-08-21 15:22:56 +08:00
|
|
|
<Result v-for="result in results" :key="result.id"
|
|
|
|
:result="result"
|
|
|
|
:resultToReload="resultToReload"
|
|
|
|
@result:elements:loaded="resultToReload = null"
|
|
|
|
@result:move_element="reloadResult"
|
2023-08-23 21:05:31 +08:00
|
|
|
@duplicated="loadResults"
|
2023-08-21 15:22:56 +08:00
|
|
|
/>
|
2023-08-03 22:03:40 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-08-21 15:22:56 +08:00
|
|
|
import axios from '../../packs/custom_axios.js';
|
2023-08-03 22:03:40 +08:00
|
|
|
import ResultsToolbar from './results_toolbar.vue';
|
|
|
|
import Result from './result.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Results',
|
|
|
|
components: { ResultsToolbar, Result },
|
|
|
|
props: {
|
|
|
|
url: { type: String, required: true }
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2023-08-04 23:06:32 +08:00
|
|
|
results: [],
|
2023-08-23 17:59:21 +08:00
|
|
|
sort: 'created_at_desc',
|
2023-08-23 18:01:14 +08:00
|
|
|
filters: {},
|
2023-08-21 15:22:56 +08:00
|
|
|
resultToReload: null
|
2023-08-03 22:03:40 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.loadResults();
|
|
|
|
},
|
|
|
|
methods: {
|
2023-08-21 15:22:56 +08:00
|
|
|
reloadResult(result) {
|
|
|
|
this.resultToReload = result;
|
|
|
|
},
|
2023-08-03 22:03:40 +08:00
|
|
|
loadResults() {
|
|
|
|
axios.get(
|
2023-08-23 17:59:21 +08:00
|
|
|
`${this.url}`,
|
2023-08-03 22:03:40 +08:00
|
|
|
{
|
2023-08-23 17:59:21 +08:00
|
|
|
params: {
|
|
|
|
sort: this.sort,
|
|
|
|
...this.filters
|
|
|
|
},
|
2023-08-03 22:03:40 +08:00
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json'
|
|
|
|
}
|
2023-08-23 17:59:21 +08:00
|
|
|
},
|
2023-08-03 22:03:40 +08:00
|
|
|
).then((response) => this.results = response.data.data);
|
2023-08-04 23:06:32 +08:00
|
|
|
},
|
|
|
|
setSort(sort) {
|
|
|
|
this.sort = sort;
|
|
|
|
this.loadResults();
|
|
|
|
},
|
2023-08-23 17:59:21 +08:00
|
|
|
setFilters(filters) {
|
|
|
|
this.filters = filters;
|
|
|
|
this.loadResults();
|
|
|
|
},
|
2023-08-04 23:06:32 +08:00
|
|
|
createResult() {
|
|
|
|
axios.post(
|
|
|
|
`${this.url}`,
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
).then(
|
|
|
|
(response) => {
|
|
|
|
this.results.unshift(response.data.data)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
expandAll() {
|
|
|
|
$('.result-wrapper .collapse').collapse('show')
|
|
|
|
},
|
|
|
|
collapseAll() {
|
|
|
|
$('.result-wrapper .collapse').collapse('hide')
|
2023-08-03 22:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|