replace filters with methods

This commit is contained in:
Thomas Amland 2020-09-01 20:12:14 +02:00
parent 0b7d731ed4
commit ec481171a6
5 changed files with 12 additions and 17 deletions

View File

@ -64,7 +64,7 @@
</router-link> </router-link>
</td> </td>
<td class="text-right d-none d-md-table-cell"> <td class="text-right d-none d-md-table-cell">
{{ item.duration | duration }} {{ $formatDuration(item.duration) }}
</td> </td>
<td class="text-right"> <td class="text-right">
<TrackContextMenu :track="item"> <TrackContextMenu :track="item">

View File

@ -38,7 +38,7 @@
</div> </div>
<div class="col p-0 text-truncate"> <div class="col p-0 text-truncate">
<div v-if="track" class="pr-3 text-right"> <div v-if="track" class="pr-3 text-right">
<span>{{ currentTime | duration }} / {{ duration | duration }}</span> {{ $formatDuration(currentTime) }} / {{ $formatDuration(duration) }}
</div> </div>
</div> </div>
</div> </div>

View File

@ -11,7 +11,7 @@
</td> </td>
<td>{{ item.artist }}</td> <td>{{ item.artist }}</td>
<td>{{ item.album }}</td> <td>{{ item.album }}</td>
<td>{{ item.duration | duration }}</td> <td>{{ $formatDuration(item.duration) }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -21,3 +21,12 @@ Object.keys(components).forEach((_key) => {
const key = _key as keyof typeof components const key = _key as keyof typeof components
Vue.component(key, components[key]) Vue.component(key, components[key])
}) })
Vue.prototype.$formatDuration = (value: number) => {
if (!isFinite(value)) {
return '∞'
}
const minutes = Math.floor(value / 60)
const seconds = Math.floor(value % 60)
return (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds
}

View File

@ -1,14 +0,0 @@
import Vue from 'vue'
Vue.filter('duration', (value: number) => {
if (!isFinite(value)) {
return '∞'
}
const minutes = Math.floor(value / 60)
const seconds = Math.floor(value % 60)
return (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds
})
Vue.filter('dateTime', (value: string) => {
return value
})