diff options
author | dartcafe <github@dartcafe.de> | 2020-01-20 21:47:38 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2020-01-20 21:47:38 +0300 |
commit | 2b08d5d28739d756f282b4fbccbb60e70d933a5e (patch) | |
tree | a452741400f1d4cbdcbf5f4c16bd721973e5fcca /src/js/views/PollList.vue | |
parent | 5b38402dc5ad99ec32908290df459a6db2dd0c2d (diff) |
sort poll list
Diffstat (limited to 'src/js/views/PollList.vue')
-rw-r--r-- | src/js/views/PollList.vue | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/js/views/PollList.vue b/src/js/views/PollList.vue index 325ec93a..e23152ab 100644 --- a/src/js/views/PollList.vue +++ b/src/js/views/PollList.vue @@ -26,16 +26,14 @@ <div v-if="noPolls" class=""> <div class="icon-polls" /> <h2> {{ t('No existing polls.') }} </h2> - <router-link :to="{ name: 'create'}" class="button new"> - <span>{{ t('polls', 'Click here to add a poll') }}</span> - </router-link> </div> <transition-group v-if="!noPolls" name="list" tag="div" class="table"> - <PollListItem key="0" :header="true" /> + <PollListItem key="0" :header="true" + :sort="sort" :reverse="reverse" @sortList="setSort($event)" /> <li is="PollListItem" - v-for="(poll, index) in filteredList" + v-for="(poll, index) in sortedList" :key="poll.id" :poll="poll" @deletePoll="removePoll(index, poll)" @@ -43,7 +41,7 @@ @clonePoll="callPoll(index, poll, 'clone')" /> </transition-group> </div> - <loading-overlay v-if="loading" /> + <LoadingOverlay v-if="isLoading" /> <!-- <modal-dialog /> --> </AppContent> </template> @@ -52,6 +50,8 @@ import { AppContent } from '@nextcloud/vue' import PollListItem from '../components/PollList/PollListItem' import { mapGetters } from 'vuex' +import sortBy from 'lodash/sortBy' + export default { name: 'PollList', @@ -63,7 +63,9 @@ export default { data() { return { noPolls: false, - loading: true + isLoading: true, + sort: 'created', + reverse: true } }, @@ -88,6 +90,14 @@ export default { } else { return this.allPolls } + }, + + sortedList() { + if (this.reverse) { + return sortBy(this.filteredList, this.sort).reverse() + } else { + return sortBy(this.filteredList, this.sort) + } } }, @@ -97,6 +107,11 @@ export default { }, methods: { + setSort(payload) { + this.sort = payload.sort + this.reverse = payload.reverse + }, + callPoll(index, poll, name) { this.$router.push({ name: name, @@ -107,14 +122,14 @@ export default { }, refreshPolls() { - this.loading = true + this.isLoading = true this.$store .dispatch('loadPolls') .then(() => { - this.loading = false + this.isLoading = false }) .catch((error) => { - this.loading = false + this.isLoading = false console.error('refresh poll: ', error.response) OC.Notification.showTemporary(t('polls', 'Error loading polls', 1, this.poll.title), { type: 'error' }) }) |