-
-
Notifications
You must be signed in to change notification settings - Fork 540
/
Listing.vue
213 lines (184 loc) · 7.48 KB
/
Listing.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<template>
<div>
<div v-if="initializing" class="card loading">
<loading-graphic />
</div>
<data-list
v-if="!initializing"
:rows="items"
:columns="columns"
:sort="false"
:sort-column="sortColumn"
:sort-direction="sortDirection"
@visible-columns-updated="visibleColumns = $event"
>
<div slot-scope="{ hasSelections }">
<div class="card p-0 relative">
<data-list-filter-presets
v-if="!reordering"
ref="presets"
:active-preset="activePreset"
:preferences-prefix="preferencesPrefix"
@selected="selectPreset"
@reset="filtersReset"
/>
<div class="data-list-header" v-if="!reordering">
<data-list-filters
:filters="filters"
:active-preset="activePreset"
:active-preset-payload="activePresetPayload"
:active-filters="activeFilters"
:active-filter-badges="activeFilterBadges"
:active-count="activeFilterCount"
:search-query="searchQuery"
:saves-presets="true"
:preferences-prefix="preferencesPrefix"
@filter-changed="filterChanged"
@search-changed="searchChanged"
@saved="$refs.presets.setPreset($event)"
@deleted="$refs.presets.refreshPresets()"
@restore-preset="$refs.presets.viewPreset($event)"
@reset="filtersReset"
/>
</div>
<div v-show="items.length === 0" class="p-3 text-center text-grey-50" v-text="__('No results')" />
<data-list-bulk-actions
:url="actionUrl"
@started="actionStarted"
@completed="actionCompleted"
/>
<data-list-table
v-show="items.length"
:allow-bulk-actions="!reordering"
:loading="loading"
:reorderable="reordering"
:sortable="!reordering"
:toggle-selection-on-row-click="true"
:allow-column-picker="true"
:column-preferences-key="preferencesKey('columns')"
@sorted="sorted"
@reordered="reordered"
>
<template slot="cell-title" slot-scope="{ row: entry }">
<div class="flex items-center">
<div class="little-dot mr-1" :class="getStatusClass(entry)" />
<a :href="entry.edit_url" @click.stop>{{ entry.title }}</a>
</div>
</template>
<template slot="cell-slug" slot-scope="{ row: entry }">
<span class="font-mono text-2xs">{{ entry.slug }}</span>
</template>
<template slot="actions" slot-scope="{ row: entry, index }">
<dropdown-list>
<dropdown-item :text="__('View')" :external-link="entry.permalink" v-if="entry.viewable" />
<dropdown-item :text="__('Edit')" :redirect="entry.edit_url" v-if="entry.editable" />
<div class="divider" v-if="entry.actions.length" />
<data-list-inline-actions
:item="entry.id"
:url="actionUrl"
:actions="entry.actions"
@started="actionStarted"
@completed="actionCompleted"
/>
</dropdown-list>
</template>
</data-list-table>
</div>
<data-list-pagination
class="mt-3"
:resource-meta="meta"
:per-page="perPage"
@page-selected="selectPage"
@per-page-changed="changePerPage"
/>
</div>
</data-list>
</div>
</template>
<script>
import Listing from '../Listing.vue';
export default {
mixins: [Listing],
props: {
collection: String,
reordering: Boolean,
reorderUrl: String,
site: String,
},
data() {
return {
listingKey: 'entries',
preferencesPrefix: `collections.${this.collection}`,
requestUrl: cp_url(`collections/${this.collection}/entries`),
currentSite: this.site,
initialSite: this.site,
}
},
watch: {
reordering(reordering, wasReordering) {
if (reordering === wasReordering) return;
reordering ? this.reorder() : this.cancelReordering();
},
activeFilters: {
deep: true,
handler(filters) {
this.currentSite = filters.site ? filters.site.site : null;
}
},
site(site) {
this.currentSite = site;
},
currentSite(site) {
this.setSiteFilter(site);
this.$emit('site-changed', site);
}
},
methods: {
getStatusClass(entry) {
// TODO: Replace with `entry.status` (will need to pass down)
if (entry.published && entry.private) {
return 'bg-transparent border border-grey-60';
} else if (entry.published) {
return 'bg-green';
} else {
return 'bg-grey-40';
}
},
reorder() {
this.filtersReset();
// When reordering, we *need* a site, since mixing them up would be awkward.
// If we're dealing with multiple sites, it's possible the user "cleared"
// the site filter so we'll want to fall back to the initial site.
this.setSiteFilter(this.currentSite || this.initialSite);
this.page = 1;
this.sortColumn = 'order';
},
cancelReordering() {
this.request();
},
reordered(items) {
this.items = items;
},
setSiteFilter(site) {
this.filterChanged({ handle: 'site', values: { site }});
},
saveOrder() {
const payload = {
ids: this.items.map(item => item.id),
page: this.page,
perPage: this.perPage,
site: this.currentSite
};
this.$axios.post(this.reorderUrl, payload)
.then(response => {
this.$emit('reordered');
this.$toast.success(__('Entries successfully reordered'))
})
.catch(e => {
console.log(e);
this.$toast.error(__('Something went wrong'));
});
},
}
}
</script>