Skip to content

Commit

Permalink
Merge pull request #45900 from nextcloud/fix/files-versions-date
Browse files Browse the repository at this point in the history
fix(files_versions): Use `NcDateTime` for proper translated version dates
  • Loading branch information
susnux authored Jun 17, 2024
2 parents 121c8db + 879120d commit 0b805ea
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
62 changes: 35 additions & 27 deletions apps/files_versions/src/components/Version.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
<!-- author -->
<template #name>
<div class="version__info">
<div v-if="versionLabel" class="version__info__label">{{ versionLabel }}</div>
<div v-if="versionLabel"
class="version__info__label"
:title="versionLabel">
{{ versionLabel }}
</div>
<div v-if="versionAuthor" class="version__info">
<div v-if="versionLabel">•</div>
<span v-if="versionLabel">•</span>
<NcAvatar class="avatar"
:user="version.author"
:size="16"
Expand All @@ -45,10 +49,12 @@
<!-- Version file size as subline -->
<template #subname>
<div class="version__info version__info__subline">
<span :title="formattedDate">{{ version.mtime | humanDateFromNow }}</span>
<NcDateTime class="version__info__date"
relative-time="short"
:timestamp="version.mtime" />
<!-- Separate dot to improve alignement -->
<span>•</span>
<span>{{ version.size | humanReadableSize }}</span>
<span>{{ humanReadableSize }}</span>
</div>
</template>

Expand Down Expand Up @@ -105,6 +111,7 @@
</template>

<script lang="ts">
import type { PropType } from 'vue'
import type { Version } from '../utils/versions'

import BackupRestore from 'vue-material-design-icons/BackupRestore.vue'
Expand All @@ -117,17 +124,18 @@ import Pencil from 'vue-material-design-icons/Pencil.vue'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionLink from '@nextcloud/vue/dist/Components/NcActionLink.js'
import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js'
import NcDateTime from '@nextcloud/vue/dist/Components/NcDateTime.js'
import NcListItem from '@nextcloud/vue/dist/Components/NcListItem.js'
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip.js'

import { defineComponent, type PropType } from 'vue'
import axios from '@nextcloud/axios'
import { getRootUrl, generateOcsUrl } from '@nextcloud/router'
import { joinPaths } from '@nextcloud/paths'
import { loadState } from '@nextcloud/initial-state'
import { Permission, formatFileSize } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import moment from '@nextcloud/moment'
import { defineComponent } from 'vue'

import axios from '@nextcloud/axios'

const hasPermission = (permissions: number, permission: number): boolean => (permissions & permission) !== 0

Expand All @@ -138,6 +146,7 @@ export default defineComponent({
NcActionLink,
NcActionButton,
NcAvatar,
NcDateTime,
NcListItem,
BackupRestore,
Download,
Expand All @@ -151,20 +160,6 @@ export default defineComponent({
tooltip: Tooltip,
},

created() {
this.fetchDisplayName()
},

filters: {
humanReadableSize(bytes: number): string {
return formatFileSize(bytes)
},

humanDateFromNow(timestamp: number): string {
return moment(timestamp).fromNow()
},
},

props: {
version: {
type: Object as PropType<Version>,
Expand Down Expand Up @@ -208,6 +203,10 @@ export default defineComponent({
},

computed: {
humanReadableSize() {
return formatFileSize(this.version.size)
},

versionLabel(): string {
const label = this.version.label ?? ''

Expand All @@ -234,10 +233,6 @@ export default defineComponent({
}
},

formattedDate(): string {
return moment(this.version.mtime).format('LLL')
},

enableLabeling(): boolean {
return this.capabilities.files.version_labeling === true
},
Expand Down Expand Up @@ -273,6 +268,10 @@ export default defineComponent({
},
},

created() {
this.fetchDisplayName()
},

methods: {
labelUpdate() {
this.$emit('label-update-request')
Expand Down Expand Up @@ -338,11 +337,20 @@ export default defineComponent({

&__label {
font-weight: 700;
// Fix overflow on narrow screens
overflow: hidden;
text-overflow: ellipsis;
}

&__date {
// Fix overflow on narrow screens
overflow: hidden;
text-overflow: ellipsis;
}

&__subline {
color: var(--color-text-maxcontrast)
}
color: var(--color-text-maxcontrast)
}
}

&__image {
Expand Down
4 changes: 2 additions & 2 deletions dist/files_versions-files_versions.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_versions-files_versions.js.map

Large diffs are not rendered by default.

0 comments on commit 0b805ea

Please sign in to comment.