Skip to content
Snippets Groups Projects
Verified Commit f12fe004 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

See #228: use action table component for federation library tracks

parent fc88f72a
Branches
Tags
No related merge requests found
...@@ -16,89 +16,63 @@ ...@@ -16,89 +16,63 @@
</div> </div>
</div> </div>
</div> </div>
<table v-if="result" class="ui compact very basic single line unstackable table"> <action-table
<thead> v-if="result"
<tr> :objects-data="result"
<th> :actions="[['import', $t('Import')]]"
<div class="ui checkbox"> :action-url="'federation/library-tracks/action/'"
<input :filters="actionFilters">
type="checkbox" <template slot="header-cells">
@change="toggleCheckAll" <th>{{ $t('Status') }}</th>
:checked="result.results.length === checked.length"><label>&nbsp;</label> <th>{{ $t('Title') }}</th>
</div> <th>{{ $t('Artist') }}</th>
</th> <th>{{ $t('Album') }}</th>
<i18next tag="th" path="Title"/> <th>{{ $t('Published date') }}</th>
<i18next tag="th" path="Artist"/> <th v-if="showLibrary">{{ $t('Library') }}</th>
<i18next tag="th" path="Album"/> </template>
<i18next tag="th" path="Published date"/> <template slot="action-success-footer" slot-scope="scope">
<i18next tag="th" v-if="showLibrary" path="Library"/> <router-link
</tr> v-if="scope.result.action === 'import'"
</thead> :to="{name: 'library.import.batches.detail', params: {id: scope.result.result.batch.id }}">
<tbody> {{ $t('Import #{% id %} launched', {id: scope.result.result.batch.id}) }}
<tr v-for="track in result.results"> </router-link>
<td class="collapsing"> </template>
<div v-if="!track.local_track_file" class="ui checkbox"> <template slot="row-cells" slot-scope="scope">
<input <td>
type="checkbox" <span v-if="scope.obj.local_track_file" class="ui basic green label">{{ $t('In library') }}</span>
@change="toggleCheck(track.id)" <span v-else class="ui basic yellow label">{{ $t('Not imported') }}</span>
:checked="checked.indexOf(track.id) > -1"><label>&nbsp;</label> </td>
</div> <td>
<div v-else class="ui label"> <span :title="scope.obj.title">{{ scope.obj.title|truncate(30) }}</span>
<i18next path="In library"/> </td>
</div> <td>
</td> <span :title="scope.obj.artist_name">{{ scope.obj.artist_name|truncate(30) }}</span>
<td> </td>
<span :title="track.title">{{ track.title|truncate(30) }}</span> <td>
</td> <span :title="scope.obj.album_title">{{ scope.obj.album_title|truncate(20) }}</span>
<td> </td>
<span :title="track.artist_name">{{ track.artist_name|truncate(30) }}</span> <td>
</td> <human-date :date="scope.obj.published_date"></human-date>
<td> </td>
<span :title="track.album_title">{{ track.album_title|truncate(20) }}</span> <td v-if="showLibrary">
</td> {{ scope.obj.library.actor.domain }}
<td> </td>
<human-date :date="track.published_date"></human-date> </template>
</td> </action-table>
<td v-if="showLibrary"> <div>
{{ track.library.actor.domain }} <pagination
</td> v-if="result && result.results.length > 0"
</tr> @page-changed="selectPage"
</tbody> :compact="true"
<tfoot class="full-width"> :current="page"
<tr> :paginate-by="paginateBy"
<th> :total="result.count"
<pagination ></pagination>
v-if="result && result.results.length > 0"
@page-changed="selectPage"
:compact="true"
:current="page"
:paginate-by="paginateBy"
:total="result.count"
></pagination>
</th> <span v-if="result && result.results.length > 0">
<th v-if="result && result.results.length > 0"> {{ $t('Showing results {%start%}-{%end%} on {%total%}', {start: ((page-1) * paginateBy) + 1 , end: ((page-1) * paginateBy) + result.results.length, total: result.count})}}
{{ $t('Showing results {%start%}-{%end%} on {%total%}', {start: ((page-1) * paginateBy) + 1 , end: ((page-1) * paginateBy) + result.results.length, total: result.count})}} </span>
<th> </div>
<button
@click="launchImport"
:disabled="checked.length === 0 || isImporting"
:class="['ui', 'green', {loading: isImporting}, 'button']">
{{ $t('Import {%count%} tracks', {'count': checked.length}) }}
</button>
<router-link
v-if="importBatch"
:to="{name: 'library.import.batches.detail', params: {id: importBatch.id }}">
{{ $t('Import #{% id %} launched', {id: importBatch.id}) }}
</router-link>
</th>
<th></th>
<th></th>
<th></th>
<th v-if="showLibrary"></th>
</tr>
</tfoot>
</table>
</div> </div>
</template> </template>
...@@ -107,6 +81,7 @@ import axios from 'axios' ...@@ -107,6 +81,7 @@ import axios from 'axios'
import _ from 'lodash' import _ from 'lodash'
import Pagination from '@/components/Pagination' import Pagination from '@/components/Pagination'
import ActionTable from '@/components/common/ActionTable'
export default { export default {
props: { props: {
...@@ -114,7 +89,8 @@ export default { ...@@ -114,7 +89,8 @@ export default {
showLibrary: {type: Boolean, default: false} showLibrary: {type: Boolean, default: false}
}, },
components: { components: {
Pagination Pagination,
ActionTable
}, },
data () { data () {
return { return {
...@@ -123,9 +99,6 @@ export default { ...@@ -123,9 +99,6 @@ export default {
page: 1, page: 1,
paginateBy: 25, paginateBy: 25,
search: '', search: '',
checked: {},
isImporting: false,
importBatch: null,
importedFilter: null importedFilter: null
} }
}, },
...@@ -153,47 +126,26 @@ export default { ...@@ -153,47 +126,26 @@ export default {
self.errors = error.backendErrors self.errors = error.backendErrors
}) })
}, },
launchImport () { selectPage: function (page) {
let self = this this.page = page
self.isImporting = true }
let payload = { },
objects: this.checked, computed: {
action: 'import' actionFilters () {
} var currentFilters = {
axios.post('/federation/library-tracks/action/', payload).then((response) => { q: this.search
self.importBatch = response.data.result.batch
self.isImporting = false
self.fetchData()
}, error => {
self.isImporting = false
self.errors = error.backendErrors
})
},
toggleCheckAll () {
if (this.checked.length === this.result.results.length) {
// we uncheck
this.checked = []
} else {
this.checked = this.result.results.filter(t => {
return t.local_track_file === null
}).map(t => { return t.id })
} }
}, if (this.filters) {
toggleCheck (id) { return _.merge(currentFilters, this.filters)
if (this.checked.indexOf(id) > -1) {
// we uncheck
this.checked.splice(this.checked.indexOf(id), 1)
} else { } else {
this.checked.push(id) return currentFilters
} }
},
selectPage: function (page) {
this.page = page
} }
}, },
watch: { watch: {
search (newValue) { search (newValue) {
if (newValue.length > 0) { if (newValue.length > 0) {
this.page = 1
this.fetchData() this.fetchData()
} }
}, },
...@@ -201,6 +153,7 @@ export default { ...@@ -201,6 +153,7 @@ export default {
this.fetchData() this.fetchData()
}, },
importedFilter () { importedFilter () {
this.page = 1
this.fetchData() this.fetchData()
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment