funkwhale/front/src/components/manage/library/EditsCardList.vue

285 wiersze
8.1 KiB
Vue
Czysty Zwykły widok Historia

<template>
<div class="ui text container">
2021-12-06 10:35:20 +00:00
<slot />
<div class="ui inline form">
<div class="fields">
<div class="ui field">
2020-08-01 09:11:51 +00:00
<label for="search-edits"><translate translate-context="Content/Search/Input.Label/Noun">Search</translate></label>
<form @submit.prevent="search.query = $refs.search.value">
2021-12-06 10:35:20 +00:00
<input
id="search-edits"
ref="search"
name="search"
type="text"
:value="search.query"
:placeholder="labels.searchPlaceholder"
>
</form>
</div>
<div class="field">
2020-08-01 09:11:51 +00:00
<label for="edit-status"><translate translate-context="*/*/*">Status</translate></label>
2021-12-06 10:35:20 +00:00
<select
id="edit-status"
class="ui dropdown"
:value="getTokenValue('is_approved', '')"
@change="addSearchToken('is_approved', $event.target.value)"
>
<option value="">
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/*/Dropdown">
All
</translate>
</option>
<option value="null">
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/Admin/*/Noun">
Pending review
</translate>
</option>
<option value="yes">
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/*/*/Short">
Approved
</translate>
</option>
<option value="no">
2021-12-06 10:35:20 +00:00
<translate translate-context="Content/Library/*/Short">
Rejected
</translate>
</option>
</select>
</div>
<div class="field">
2020-08-01 09:11:51 +00:00
<label for="edit-ordering"><translate translate-context="Content/Search/Dropdown.Label/Noun">Ordering</translate></label>
2021-12-06 10:35:20 +00:00
<select
id="edit-ordering"
v-model="ordering"
class="ui dropdown"
>
<option
v-for="(option, key) in orderingOptions"
:key="key"
:value="option[0]"
>
{{ sharedLabels.filters[option[1]] }}
</option>
</select>
</div>
<div class="field">
2020-08-01 09:11:51 +00:00
<label for="edit-ordering-direction"><translate translate-context="Content/Search/Dropdown.Label/Noun">Order</translate></label>
2021-12-06 10:35:20 +00:00
<select
id="edit-ordering-direction"
v-model="orderingDirection"
class="ui dropdown"
>
<option value="+">
<translate translate-context="Content/Search/Dropdown">
Ascending
</translate>
</option>
<option value="-">
<translate translate-context="Content/Search/Dropdown">
Descending
</translate>
</option>
</select>
</div>
</div>
</div>
<div class="dimmable">
2021-12-06 10:35:20 +00:00
<div
v-if="isLoading"
class="ui active inverted dimmer"
>
<div class="ui loader" />
</div>
<div v-else-if="result?.count > 0">
<edit-card
2021-12-06 10:35:20 +00:00
v-for="obj in result.results"
:key="obj.uuid"
:obj="obj"
:current-state="getCurrentState(obj.target)"
@deleted="handle('delete', obj.uuid, null)"
@approved="handle('approved', obj.uuid, $event)"
2021-12-06 10:35:20 +00:00
/>
</div>
2021-12-06 10:35:20 +00:00
<empty-state
v-else
:refresh="true"
@refresh="fetchData()"
/>
</div>
2021-12-06 10:35:20 +00:00
<div class="ui hidden divider" />
<div>
<pagination
v-if="result && result.count > paginateBy"
:compact="true"
:current="page"
:paginate-by="paginateBy"
:total="result.count"
2021-12-06 10:35:20 +00:00
@page-changed="selectPage"
/>
<span v-if="result && result.results.length > 0">
2021-12-06 10:35:20 +00:00
<translate
translate-context="Content/*/Paragraph"
:translate-params="{start: ((page-1) * paginateBy) + 1, end: ((page-1) * paginateBy) + result.results.length, total: result.count}"
>
Showing results %{ start }-%{ end } on %{ total }
</translate>
</span>
</div>
</div>
</template>
<script>
import axios from 'axios'
import { uniq, merge } from 'lodash-es'
2022-04-23 07:37:43 +00:00
import time from '~/utils/time'
import Pagination from '~/components/vui/Pagination.vue'
2022-04-23 07:37:43 +00:00
import OrderingMixin from '~/components/mixins/Ordering.vue'
import EditCard from '~/components/library/EditCard.vue'
2022-05-02 15:06:44 +00:00
import { normalizeQuery, parseTokens } from '~/utils/search'
2022-04-23 07:37:43 +00:00
import SmartSearchMixin from '~/components/mixins/SmartSearch.vue'
2022-05-02 15:06:44 +00:00
import useEditConfigs from '~/composables/useEditConfigs'
import useSharedLabels from '~/composables/locale/useSharedLabels'
export default {
components: {
Pagination,
EditCard
},
mixins: [OrderingMixin, SmartSearchMixin],
2021-12-06 10:35:20 +00:00
props: {
filters: { type: Object, required: false, default: () => { return {} } }
},
setup () {
const sharedLabels = useSharedLabels()
2022-05-02 15:06:44 +00:00
const configs = useEditConfigs()
return { sharedLabels, configs }
},
data () {
return {
time,
isLoading: false,
result: null,
page: 1,
search: {
query: this.defaultQuery,
tokens: parseTokens(normalizeQuery(this.defaultQuery))
},
orderingOptions: [
['creation_date', 'creation_date'],
2021-12-06 10:35:20 +00:00
['applied_date', 'applied_date']
],
targets: {
track: {}
}
}
},
2021-12-06 10:35:20 +00:00
computed: {
labels () {
return {
searchPlaceholder: this.$pgettext('Content/Search/Input.Placeholder', 'Search by account, summary, domain…')
}
}
},
watch: {
search (newValue) {
this.page = 1
this.fetchData()
},
page () {
this.fetchData()
},
ordering () {
this.fetchData()
},
orderingDirection () {
this.fetchData()
}
},
created () {
this.fetchData()
},
methods: {
fetchData () {
const params = merge({
2021-12-06 10:35:20 +00:00
page: this.page,
page_size: this.paginateBy,
q: this.search.query,
ordering: this.getOrderingAsString()
}, this.filters)
2021-12-06 10:35:20 +00:00
const self = this
self.isLoading = true
this.result = null
2021-12-06 10:35:20 +00:00
axios.get('mutations/', { params: params }).then((response) => {
self.result = response.data
self.isLoading = false
self.fetchTargets()
}, error => {
self.isLoading = false
self.errors = error.backendErrors
})
},
fetchTargets () {
// we request target data via the API so we can display previous state
// additionnal data next to the edit card
2021-12-06 10:35:20 +00:00
const self = this
const typesAndIds = {
track: {
url: 'tracks/',
2021-12-06 10:35:20 +00:00
ids: []
}
}
this.result.results.forEach((m) => {
if (!m.target || !typesAndIds[m.target.type]) {
return
}
2021-12-06 10:35:20 +00:00
typesAndIds[m.target.type].ids.push(m.target.id)
})
Object.keys(typesAndIds).forEach((k) => {
2021-12-06 10:35:20 +00:00
const config = typesAndIds[k]
if (config.ids.length === 0) {
return
}
axios.get(config.url, { params: { id: uniq(config.ids), hidden: 'null' } }).then((response) => {
response.data.results.forEach((e) => {
2022-05-02 08:57:33 +00:00
self.targets[k][e.id] = {
payload: e,
2022-05-02 15:06:44 +00:00
currentState: configs[k].fields.reduce((state/*: Record<string, unknown> */, field) => {
state[field.id] = { value: field.getValue(e) }
return state
}, {})
2022-05-02 08:57:33 +00:00
}
})
}, error => {
self.errors = error.backendErrors
})
})
},
selectPage: function (page) {
this.page = page
},
handle (type, id, value) {
if (type === 'delete') {
this.exclude.push(id)
}
this.result.results.forEach((e) => {
if (e.uuid === id) {
e.is_approved = value
}
})
},
getCurrentState (target) {
if (!target) {
return {}
}
if (this.targets[target.type] && this.targets[target.type][String(target.id)]) {
return this.targets[target.type][String(target.id)].currentState
}
return {}
}
}
}
</script>