-
-
Notifications
You must be signed in to change notification settings - Fork 641
Expand file tree
/
Copy pathRevision.vue
More file actions
176 lines (163 loc) · 6.3 KB
/
Copy pathRevision.vue
File metadata and controls
176 lines (163 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
<div
class="relative block cursor-pointer space-y-2 px-3 py-2 text-sm hover:[&_.revision-message]:underline"
:class="{
'status-working-copy': revision.action === 'working',
'status-published': revision.attributes.published,
'border border-ui-accent-bg dark:border-ui-accent-bg/90 rounded-lg py-2.5 bg-[hsl(from_var(--theme-color-ui-accent-bg)_h_s_97)] dark:bg-[hsl(from_var(--theme-color-ui-accent-bg)_h_40_20)]': revision.attributes.current,
'bg-gradient-to-b from-transparent from-60% to-white dark:to-gray-800 -mt-1': isLast,
}"
v-tooltip="revision.attributes.current ? __('Current Revision') : null"
@click="open"
>
<div class="flex gap-3">
<Avatar v-if="revision.user" :user="revision.user" class="size-6 shrink-0 mt-1" />
<div class="grid gap-1">
<div v-if="revision.message" class="revision-message font-medium" v-text="revision.message" />
<Subheading class="text-xs text-gray-500! dark:text-gray-400!" :class="{ 'text-gray-800! dark:text-white!': revision.attributes.current }">
{{ time }}
<template v-if="revision.user">
by {{ revision.user.name || revision.user.email }}
</template>
</Subheading>
</div>
<div class="flex items-center gap-1 ml-auto">
<Badge
size="sm"
:color="
revision.action === 'working'
? 'gray'
: {
publish: 'green',
revision: 'gray',
restore: 'gray',
unpublish: 'red',
}[revision.action]
"
:text="
revision.action === 'working'
? __('Working Copy')
: {
publish: __('Published'),
revision: __('Revision'),
restore: __('Restored'),
unpublish: __('Unpublished'),
}[revision.action]
"
/>
<Button
v-if="sharedPreviewUrl"
icon="share-link"
icon-only
size="xs"
variant="ghost"
inset
:aria-label="__('Share Revision')"
v-tooltip="__('Share Revision')"
:loading="copyingPreviewLink"
@click.stop="copyPreviewLink"
/>
</div>
<revision-preview
v-if="showDetails"
:revision="revision"
component="entry-publish-form"
:component-props="componentProps"
@closed="showDetails = false"
>
<template #action-buttons-right>
<restore-revision
v-if="canRestoreRevisions"
:revision="revision"
:url="restoreUrl"
:reference="reference"
class="ltr:ml-4 rtl:mr-4"
/>
</template>
</revision-preview>
</div>
</div>
</template>
<script>
import RestoreRevision from './Restore.vue';
import RevisionPreview from './Preview.vue';
import DateFormatter from '@/components/DateFormatter.js';
import { Subheading, Badge, Avatar, Button } from '@/components/ui';
export default {
components: {
RevisionPreview,
RestoreRevision,
Subheading,
Badge,
Avatar,
Button,
},
props: {
revision: Object,
restoreUrl: String,
sharedPreviewUrl: String,
reference: String,
canRestoreRevisions: Boolean,
isLast: Boolean,
},
data() {
return {
showDetails: false,
copyingPreviewLink: false,
componentProps: {
initialActions: 'actions',
collectionTitle: 'collection.title',
collectionUrl: 'collection.url',
initialTitle: 'title',
initialReference: 'reference',
initialFieldset: 'blueprint',
initialValues: 'values',
initialLocalizedFields: 'localizedFields',
initialMeta: 'meta',
initialPublished: 'published',
initialPermalink: 'permalink',
initialLocalizations: 'localizations',
initialHasOrigin: 'hasOrigin',
initialOriginValues: 'originValues',
initialOriginMeta: 'originMeta',
initialSite: 'locale',
initialIsWorkingCopy: 'hasWorkingCopy',
initialReadOnly: 'readOnly',
},
};
},
computed: {
time() {
return DateFormatter.format(this.revision.date * 1000, 'time');
},
},
methods: {
open() {
if (this.revision.action === 'working') {
this.$emit('working-copy-selected');
return;
}
this.showDetails = true;
},
async copyPreviewLink() {
this.copyingPreviewLink = true;
try {
const payload = this.revision.action === 'working' ? {} : { revision: this.revision.date };
const { data } = await this.$axios.post(this.sharedPreviewUrl, payload);
try {
await navigator.clipboard.writeText(data.url);
this.$toast.success(
__('messages.shared_preview_link_copied', { hours: data.expires_in_hours }),
);
} catch {
Statamic.$callbacks.call('copyToClipboard', data.url);
}
} catch {
this.$toast.error(__('Unable to copy preview link'));
} finally {
this.copyingPreviewLink = false;
}
},
},
};
</script>