scinote-web/app/javascript/vue/results/results.vue

96 lines
2.1 KiB
Vue
Raw Normal View History

<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"
2023-08-31 21:50:35 +08:00
class="my-4"
2023-08-23 17:59:21 +08:00
/>
<div class="results-list">
<Result v-for="result in results" :key="result.id"
:result="result"
:resultToReload="resultToReload"
@result:elements:loaded="resultToReload = null"
@result:move_element="reloadResult"
@duplicated="loadResults"
/>
</div>
</div>
</template>
<script>
import axios from '../../packs/custom_axios.js';
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 {
results: [],
2023-08-23 17:59:21 +08:00
sort: 'created_at_desc',
filters: {},
resultToReload: null
}
},
created() {
this.loadResults();
},
methods: {
reloadResult(result) {
this.resultToReload = result;
},
loadResults() {
axios.get(
2023-08-23 17:59:21 +08:00
`${this.url}`,
{
2023-08-23 17:59:21 +08:00
params: {
sort: this.sort,
...this.filters
},
headers: {
'Accept': 'application/json'
}
2023-08-23 17:59:21 +08:00
},
).then((response) => this.results = response.data.data);
},
setSort(sort) {
this.sort = sort;
this.loadResults();
},
2023-08-23 17:59:21 +08:00
setFilters(filters) {
this.filters = filters;
this.loadResults();
},
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')
}
}
}
</script>