Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
open output files in viewer on click
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Apr 29, 2025
commit 07f488f51553846e3a68fc34e717281445efc3db
3 changes: 3 additions & 0 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public function handle(Event $event): void {
$indexingComplete = $this->appConfig->getValueInt('context_chat', 'last_indexed_time', 0) !== 0;
$this->initialStateService->provideInitialState('contextChatIndexingComplete', $indexingComplete);
}
if (class_exists(\OCA\Viewer\Event\LoadViewer::class)) {
$this->eventDispatcher->dispatchTyped(new \OCA\Viewer\Event\LoadViewer());
}
Util::addScript(Application::APP_ID, Application::APP_ID . '-main');
}
}
2 changes: 1 addition & 1 deletion lib/Service/AssistantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public function saveOutputFile(string $userId, int $ocpTaskId, int $fileId): arr
$fileCopy = $this->saveFile($userId, $ocpTaskId, $fileId);
return [
'fileId' => $fileCopy->getId(),
'path' => $fileCopy->getInternalPath(),
'path' => preg_replace('/^files\//', '/', $fileCopy->getInternalPath()),
];
}

Expand Down
10 changes: 9 additions & 1 deletion src/components/fields/FileDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<template>
<div class="file-display">
<div class="preview">
<img :src="imageUrl">
<img :src="imageUrl" :class="{ clickable }">
<span v-if="fileName"
class="file-name"
:title="fileName">
Expand Down Expand Up @@ -42,6 +42,10 @@ export default {
type: Boolean,
default: false,
},
clickable: {
type: Boolean,
default: false,
},
},

emits: [],
Expand Down Expand Up @@ -100,6 +104,10 @@ export default {
justify-content: center;
img {
width: 100px;

&.clickable {
cursor: pointer !important;
}
}
.file-name {
max-width: 100px;
Expand Down
32 changes: 28 additions & 4 deletions src/components/fields/MediaField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
<component :is="displayComponent"
:file-id="value"
:show-delete="false"
:is-output="isOutput" />
:is-output="isOutput"
:clickable="true"
@click.native="onPreviewClick" />
<div v-if="isOutput"
class="buttons">
<a :href="getDownloadUrl()"
Expand Down Expand Up @@ -256,13 +258,17 @@ export default {
taskId: this.providedCurrentTaskId(),
fileId: this.value,
})
axios.post(url).then(response => {
return axios.post(url).then(response => {
const savedPath = response.data.ocs.data.path
const savedFileId = response.data.ocs.data.fileId
console.debug('[assistant] save output file', savedPath)

const directUrl = window.location.protocol + '//' + window.location.host + generateUrl('/f/{savedFileId}', { savedFileId })
const message = t('assistant', 'This output file has been saved in {path}', { path: savedPath }) + '\n' + directUrl
this.copyString(directUrl, message)
const openMessage = `<a href="${directUrl}" target="_blank">${t('assistant', 'Click this to open the file')}</a>`
showSuccess(openMessage, { isHTML: true })

const afterCopyMessage = t('assistant', 'This output file has been saved in {path}', { path: savedPath })
this.copyString(directUrl, afterCopyMessage)
}).catch(error => {
console.error(error)
})
Expand All @@ -277,6 +283,24 @@ export default {
showError(t('assistant', 'Could not copy to clipboard'))
}
},
onPreviewClick() {
if (this.value === null) {
return
}

const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/file/{fileId}/save', {
taskId: this.providedCurrentTaskId(),
fileId: this.value,
})
return axios.post(url).then(response => {
const savedPath = response.data.ocs.data.path
console.debug('[assistant] view output file', savedPath)
// TODO find a way to make it work when the assistant is in a modal itself
OCA.Viewer.open({ path: savedPath })
}).catch(error => {
console.error(error)
})
},
},
}
</script>
Expand Down