LibraryTrackTable.vue 6.04 KB
Newer Older
1
2
3
<template>
  <div>
    <div class="ui inline form">
4
      <div class="fields">
5
        <div class="ui six wide field">
6
          <label><translate>Search</translate></label>
Eliot Berriot's avatar
Eliot Berriot committed
7
          <input type="text" v-model="search" :placeholder="labels.searchPlaceholder" />
8
9
        </div>
        <div class="ui field">
10
          <label><translate>Import status</translate></label>
11
          <select class="ui dropdown" v-model="importedFilter">
12
13
14
15
            <option :value="null"><translate>Any</translate></option>
            <option :value="'imported'"><translate>Imported</translate></option>
            <option :value="'not_imported'"><translate>Not imported</translate></option>
            <option :value="'import_pending'"><translate>Import pending</translate></option>
16
17
18
          </select>
        </div>
      </div>
19
    </div>
20
21
22
23
24
25
26
27
28
29
30
31
    <div class="dimmable">
      <div v-if="isLoading" class="ui active inverted dimmer">
          <div class="ui loader"></div>
      </div>
      <action-table
        v-if="result"
        @action-launched="fetchData"
        :objects-data="result"
        :actions="actions"
        :action-url="'federation/library-tracks/action/'"
        :filters="actionFilters">
        <template slot="header-cells">
32
33
34
35
36
37
          <th><translate>Status</translate></th>
          <th><translate>Title</translate></th>
          <th><translate>Artist</translate></th>
          <th><translate>Album</translate></th>
          <th><translate>Published date</translate></th>
          <th v-if="showLibrary"><translate>Library</translate></th>
38
39
40
41
42
        </template>
        <template slot="action-success-footer" slot-scope="scope">
          <router-link
            v-if="scope.result.action === 'import'"
            :to="{name: 'library.import.batches.detail', params: {id: scope.result.result.batch.id }}">
Eliot Berriot's avatar
Eliot Berriot committed
43
44
45
46
            <translate
              :translate-params="{id: scope.result.result.batch.id}">
              Import #%{ id } launched
            </translate>
47
48
49
50
          </router-link>
        </template>
        <template slot="row-cells" slot-scope="scope">
          <td>
51
52
53
            <span v-if="scope.obj.status === 'imported'" class="ui basic green label"><translate>In library</translate></span>
            <span v-else-if="scope.obj.status === 'import_pending'" class="ui basic yellow label"><translate>Import pending</translate></span>
            <span v-else class="ui basic label"><translate>Not imported</translate></span>
54
55
56
57
58
          </td>
          <td>
            <span :title="scope.obj.title">{{ scope.obj.title|truncate(30) }}</span>
          </td>
          <td>
59
            <span class="discrete link" @click="updateSearch({key: 'artist', value: scope.obj.artist_name})" :title="scope.obj.artist_name">{{ scope.obj.artist_name|truncate(30) }}</span>
60
61
          </td>
          <td>
62
            <span class="discrete link" @click="updateSearch({key: 'album', value: scope.obj.album_title})" :title="scope.obj.album_title">{{ scope.obj.album_title|truncate(20) }}</span>
63
64
65
66
67
          </td>
          <td>
            <human-date :date="scope.obj.published_date"></human-date>
          </td>
          <td v-if="showLibrary">
68
            <span class="discrete link" @click="updateSearch({key: 'domain', value: scope.obj.library.actor.domain})">{{ scope.obj.library.actor.domain }}</span>
69
70
71
72
          </td>
        </template>
      </action-table>
    </div>
73
74
75
76
77
78
79
80
81
    <div>
      <pagination
        v-if="result && result.results.length > 0"
        @page-changed="selectPage"
        :compact="true"
        :current="page"
        :paginate-by="paginateBy"
        :total="result.count"
        ></pagination>
Eliot Berriot's avatar
Eliot Berriot committed
82

83
      <span v-if="result && result.results.length > 0">
Eliot Berriot's avatar
Eliot Berriot committed
84
85
86
87
        <translate
          :translate-params="{start: ((page-1) * paginateBy) + 1, end: ((page-1) * paginateBy) + result.results.length, total: result.count}">
          Showing results %{ start }-%{ end } on %{ total }
        </translate>
88
89
      </span>
    </div>
90
91
92
93
94
95
96
  </div>
</template>

<script>
import axios from 'axios'
import _ from 'lodash'

Eliot Berriot's avatar
Eliot Berriot committed
97
import Pagination from '@/components/Pagination'
98
import ActionTable from '@/components/common/ActionTable'
Eliot Berriot's avatar
Eliot Berriot committed
99

100
export default {
Eliot Berriot's avatar
Eliot Berriot committed
101
102
103
104
105
  props: {
    filters: {type: Object, required: false},
    showLibrary: {type: Boolean, default: false}
  },
  components: {
106
107
    Pagination,
    ActionTable
Eliot Berriot's avatar
Eliot Berriot committed
108
  },
109
110
111
112
113
  data () {
    return {
      isLoading: false,
      result: null,
      page: 1,
Eliot Berriot's avatar
Eliot Berriot committed
114
      paginateBy: 25,
115
      search: '',
116
      importedFilter: null
117
118
119
120
121
122
    }
  },
  created () {
    this.fetchData()
  },
  methods: {
123
124
125
126
127
128
    updateSearch ({key, value}) {
      if (value.indexOf(' ') > -1) {
        value = `"${value}"`
      }
      this.search = `${key}:${value}`
    },
129
130
131
    fetchData () {
      let params = _.merge({
        'page': this.page,
Eliot Berriot's avatar
Eliot Berriot committed
132
        'page_size': this.paginateBy,
133
134
        'q': this.search
      }, this.filters)
135
      if (this.importedFilter !== null) {
136
        params.status = this.importedFilter
137
      }
138
139
140
141
142
143
144
145
146
147
148
      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
      })
    },
149
150
151
152
153
    selectPage: function (page) {
      this.page = page
    }
  },
  computed: {
Eliot Berriot's avatar
Eliot Berriot committed
154
155
156
157
158
    labels () {
      return {
        searchPlaceholder: this.$gettext('Search by title, artist, domain...')
      }
    },
159
160
161
    actionFilters () {
      var currentFilters = {
        q: this.search
162
      }
163
164
      if (this.filters) {
        return _.merge(currentFilters, this.filters)
165
      } else {
166
        return currentFilters
167
      }
168
169
    },
    actions () {
170
      let msg = this.$gettext('Import')
171
172
173
      return [
        {
          name: 'import',
174
          label: msg,
175
176
177
          filterCheckable: (obj) => { return obj.status === 'not_imported' }
        }
      ]
178
179
180
181
    }
  },
  watch: {
    search (newValue) {
182
183
      this.page = 1
      this.fetchData()
Eliot Berriot's avatar
Eliot Berriot committed
184
185
186
    },
    page () {
      this.fetchData()
187
188
    },
    importedFilter () {
189
      this.page = 1
190
      this.fetchData()
191
192
193
194
    }
  }
}
</script>