mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
add distanceToNow and readableDate filter from date-fns
This commit is contained in:
parent
7fa75f224c
commit
05fc0a5163
3 changed files with 27 additions and 5 deletions
12
app/src/filters/date.js
Normal file
12
app/src/filters/date.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import formatDistanceToNow from 'date-fns/formatDistanceToNow'
|
||||
import format from 'date-fns/format'
|
||||
|
||||
import { dateFnsLocale as locale } from '@/i18n/helpers'
|
||||
|
||||
export function distanceToNow (dateStr, addSuffix = true) {
|
||||
return formatDistanceToNow(new Date(dateStr), { addSuffix, locale })
|
||||
}
|
||||
|
||||
export function readableDate (dateStr) {
|
||||
return format(new Date(dateStr), 'PPPpp', { locale })
|
||||
}
|
|
@ -21,10 +21,10 @@
|
|||
<p class="mb-0">
|
||||
<span :class="status === 'running' ? 'text-success' : 'text-danger'">
|
||||
<icon :iname="status === 'running' ? 'check-circle' : 'times'" />
|
||||
{{ status }}
|
||||
{{ $t(status) }}
|
||||
</span>
|
||||
<!-- FIXME format date to: (now - date) as words -->
|
||||
{{ $t('since') }} {{ last_state_change }}
|
||||
{{ $t('since') }} {{ last_state_change | distanceToNow }}
|
||||
</p>
|
||||
</div>
|
||||
<icon iname="chevron-right" class="lg fs-sm ml-auto" />
|
||||
|
@ -35,6 +35,7 @@
|
|||
|
||||
<script>
|
||||
import api from '@/helpers/api'
|
||||
import { distanceToNow } from '@/filters/date'
|
||||
|
||||
export default {
|
||||
name: 'ServiceList',
|
||||
|
@ -56,6 +57,10 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
filters: {
|
||||
distanceToNow
|
||||
},
|
||||
|
||||
methods: {
|
||||
fetchData () {
|
||||
// simply use the api helper since we will not store the request's result.
|
||||
|
|
|
@ -14,13 +14,12 @@
|
|||
<h2><icon iname="wrench" /> {{ $t('logs_operation') }}</h2>
|
||||
</template>
|
||||
<b-list-group flush>
|
||||
<!-- FIXME format title and span date as text and text'ago -->
|
||||
<b-list-group-item
|
||||
v-for="log in filteredOperations" :key="log.name"
|
||||
:to="{ name: 'tool-log', params: { name: log.name } }"
|
||||
:title="log.started_at"
|
||||
:title="log.started_at | readableDate"
|
||||
>
|
||||
<small class="mr-3">{{ log.started_at }} </small>
|
||||
<small class="mr-3">{{ log.started_at | distanceToNow }} </small>
|
||||
<icon :iname="log.icon" :class="'text-' + log.class" />
|
||||
{{ log.description }}
|
||||
</b-list-group-item>
|
||||
|
@ -31,6 +30,7 @@
|
|||
|
||||
<script>
|
||||
import api from '@/helpers/api'
|
||||
import { distanceToNow, readableDate } from '@/filters/date'
|
||||
|
||||
export default {
|
||||
name: 'ServiceList',
|
||||
|
@ -52,6 +52,11 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
filters: {
|
||||
distanceToNow,
|
||||
readableDate
|
||||
},
|
||||
|
||||
methods: {
|
||||
fetchData () {
|
||||
// simply use the api helper since we will not store the request's result.
|
||||
|
|
Loading…
Add table
Reference in a new issue