Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] fix(files_versions): Use NcDateTime for proper translated version dates #45911

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -41,9 +41,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 @@ -58,10 +62,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 @@ -118,6 +124,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 @@ -130,17 +137,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 @@ -151,6 +159,7 @@ export default defineComponent({
NcActionLink,
NcActionButton,
NcAvatar,
NcDateTime,
NcListItem,
BackupRestore,
Download,
Expand All @@ -164,20 +173,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 @@ -221,6 +216,10 @@ export default defineComponent({
},

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

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

Expand All @@ -247,10 +246,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 @@ -286,6 +281,10 @@ export default defineComponent({
},
},

created() {
this.fetchDisplayName()
},

methods: {
labelUpdate() {
this.$emit('label-update-request')
Expand Down Expand Up @@ -351,11 +350,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.

Loading