Skip to content

Commit 1af8c99

Browse files
committed
feat: open output media list items in the viewer just like simple output media items
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 41a72c1 commit 1af8c99

File tree

3 files changed

+81
-18
lines changed

3 files changed

+81
-18
lines changed

src/components/fields/ImageDisplay.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
-->
55
<template>
66
<div class="image-display">
7-
<img :src="imageUrl" :style="style">
7+
<img :src="imageUrl"
8+
:style="style"
9+
:class="{ clickable }">
810
</div>
911
</template>
1012

@@ -38,6 +40,10 @@ export default {
3840
type: [Number, null],
3941
default: null,
4042
},
43+
clickable: {
44+
type: Boolean,
45+
default: false,
46+
},
4147
},
4248
4349
emits: [],
@@ -87,6 +93,10 @@ export default {
8793
// width: 200px;
8894
width: auto;
8995
height: 200px;
96+
97+
&.clickable {
98+
cursor: pointer !important;
99+
}
90100
}
91101
}
92102
</style>

src/components/fields/ListOfMediaField.vue

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
<component :is="displayComponent"
4545
:file-id="fileId"
4646
:is-output="isOutput"
47-
@delete="onDelete(fileId)" />
47+
:clickable="isOutput"
48+
@delete="onDelete(fileId)"
49+
@click.native="onPreviewClick(isOutput, fileId)" />
4850
<div class="buttons">
4951
<NcButton v-if="!isOutput"
5052
type="tertiary"
@@ -63,13 +65,19 @@
6365
</template>
6466
</NcButton>
6567
</a>
68+
<NcButton v-if="isOutput"
69+
:title="t('assistant', 'Save this media')"
70+
@click="onSave(fileId)">
71+
<template #icon>
72+
<ContentSaveIcon />
73+
</template>
74+
</NcButton>
6675
<NcButton v-if="isOutput"
6776
:title="t('assistant', 'Share this media')"
6877
@click="onShare(fileId)">
6978
<template #icon>
7079
<ShareVariantIcon />
7180
</template>
72-
{{ t('assistant', 'Share') }}
7381
</NcButton>
7482
</div>
7583
</div>
@@ -80,6 +88,7 @@
8088
<script>
8189
import DownloadIcon from 'vue-material-design-icons/Download.vue'
8290
import ShareVariantIcon from 'vue-material-design-icons/ShareVariant.vue'
91+
import ContentSaveIcon from 'vue-material-design-icons/ContentSave.vue'
8392
8493
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
8594
@@ -117,6 +126,7 @@ export default {
117126
DeleteIcon,
118127
DownloadIcon,
119128
ShareVariantIcon,
129+
ContentSaveIcon,
120130
NcButton,
121131
},
122132
@@ -244,21 +254,47 @@ export default {
244254
})
245255
},
246256
onShare(fileId) {
247-
if (this.value !== null) {
248-
const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/file/{fileId}/share', {
249-
taskId: this.providedCurrentTaskId(),
250-
fileId,
251-
})
252-
axios.post(url).then(response => {
253-
const shareToken = response.data.ocs.data.shareToken
254-
const shareUrl = window.location.protocol + '//' + window.location.host + generateUrl('/s/{shareToken}', { shareToken })
255-
console.debug('[assistant] generated share link', shareUrl)
256-
const message = t('assistant', 'Output file share link copied to clipboard')
257-
this.copyString(shareUrl, message)
258-
}).catch(error => {
259-
console.error(error)
260-
})
257+
if (this.value === null) {
258+
return
261259
}
260+
261+
const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/file/{fileId}/share', {
262+
taskId: this.providedCurrentTaskId(),
263+
fileId,
264+
})
265+
axios.post(url).then(response => {
266+
const shareToken = response.data.ocs.data.shareToken
267+
const shareUrl = window.location.protocol + '//' + window.location.host + generateUrl('/s/{shareToken}', { shareToken })
268+
console.debug('[assistant] generated share link', shareUrl)
269+
const message = t('assistant', 'Output file share link copied to clipboard')
270+
this.copyString(shareUrl, message)
271+
}).catch(error => {
272+
console.error(error)
273+
})
274+
},
275+
onSave(fileId) {
276+
if (this.value === null) {
277+
return
278+
}
279+
280+
const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/file/{fileId}/save', {
281+
taskId: this.providedCurrentTaskId(),
282+
fileId,
283+
})
284+
return axios.post(url).then(response => {
285+
const savedPath = response.data.ocs.data.path
286+
const savedFileId = response.data.ocs.data.fileId
287+
console.debug('[assistant] save output file', savedPath)
288+
289+
const directUrl = window.location.protocol + '//' + window.location.host + generateUrl('/f/{savedFileId}', { savedFileId })
290+
const openMessage = `<a href="${directUrl}" target="_blank">${t('assistant', 'Click this to open the file')}</a>`
291+
showSuccess(openMessage, { isHTML: true })
292+
293+
const afterCopyMessage = t('assistant', 'This output file has been saved in {path}', { path: savedPath })
294+
this.copyString(directUrl, afterCopyMessage)
295+
}).catch(error => {
296+
console.error(error)
297+
})
262298
},
263299
async copyString(content, message) {
264300
try {
@@ -270,6 +306,24 @@ export default {
270306
showError(t('assistant', 'Could not copy to clipboard'))
271307
}
272308
},
309+
onPreviewClick(isOutput, fileId) {
310+
// do not open input media files in the viewer
311+
if (this.value === null || !isOutput) {
312+
return
313+
}
314+
315+
const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/file/{fileId}/save', {
316+
taskId: this.providedCurrentTaskId(),
317+
fileId,
318+
})
319+
return axios.post(url).then(response => {
320+
const savedPath = response.data.ocs.data.path
321+
console.debug('[assistant] view output file', savedPath)
322+
OCA.Viewer.open({ path: savedPath })
323+
}).catch(error => {
324+
console.error(error)
325+
})
326+
},
273327
},
274328
}
275329
</script>

src/components/fields/MediaField.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ export default {
295295
return axios.post(url).then(response => {
296296
const savedPath = response.data.ocs.data.path
297297
console.debug('[assistant] view output file', savedPath)
298-
// This works and shows the Viewer on top the assitant's NcModal because we give it container="#content"
299298
OCA.Viewer.open({ path: savedPath })
300299
}).catch(error => {
301300
console.error(error)

0 commit comments

Comments
 (0)