Newer
Older
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
<template>
<div>
<div class="ui inline form">
<input type="text" v-model="search" placeholder="Search by title, artist, domain..." />
</div>
<table v-if="result" class="ui compact very basic single line unstackable table">
<thead>
<tr>
<th colspan="1">
<div class="ui checkbox">
<input
type="checkbox"
@change="toggleCheckAll"
:checked="result.results.length === checked.length"><label> </label>
</div>
</th>
<th>Title</th>
<th>Artist</th>
<th>Album</th>
<th>Published date</th>
</tr>
</thead>
<tbody>
<tr v-for="track in result.results">
<td class="collapsing">
<div v-if="!track.local_track_file" class="ui checkbox">
<input
type="checkbox"
@change="toggleCheck(track.id)"
:checked="checked.indexOf(track.id) > -1"><label> </label>
</div>
<div v-else class="ui label">
In library
</div>
</td>
<td>
{{ track.title }}
</td>
<td>
{{ track.artist_name }}
</td>
<td>
{{ track.album_title }}
</td>
<td>
<human-date :date="track.published_date"></human-date>
</td>
</tr>
</tbody>
<tfoot class="full-width">
<tr>
<th colspan="5">
<button
@click="launchImport"
:disabled="checked.length === 0 || isImporting"
:class="['ui', 'green', {loading: isImporting}, 'button']">Import {{ checked.length }} tracks
</button>
</th>
</tr>
</tfoot>
</table>
</div>
</template>
<script>
import axios from 'axios'
import _ from 'lodash'
export default {
props: ['filters'],
data () {
return {
isLoading: false,
result: null,
page: 1,
paginateBy: 50,
search: '',
checked: {},
isImporting: false
}
},
created () {
this.fetchData()
},
methods: {
fetchData () {
let params = _.merge({
'page': this.page,
'paginate_by': this.paginateBy,
'q': this.search
}, this.filters)
let self = this
self.isLoading = true
self.checked = []
axios.get('/federation/library-tracks/', {params: params}).then((response) => {
self.result = response.data
self.isLoading = false
}, error => {
self.isLoading = false
self.errors = error.backendErrors
})
},
launchImport () {
let self = this
self.isImporting = true
let payload = {
library_tracks: this.checked
}
axios.post('/submit/federation/', payload).then((response) => {
console.log('Triggered import', response.data)
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.map(t => { return t.id })
}
},
toggleCheck (id) {
if (this.checked.indexOf(id) > -1) {
// we uncheck
this.checked.splice(this.checked.indexOf(id), 1)
} else {
this.checked.push(id)
}
}
},
watch: {
search (newValue) {
if (newValue.length > 0) {
this.fetchData()
}
}
}
}
</script>