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
fix: update task notification button label, do not close assistant on…
… click, toggle notification request instead

Signed-off-by: Edward Ly <[email protected]>
  • Loading branch information
edward-ly committed Jun 18, 2025
commit d791d6d78de0f4201c9f32f01da0cb68207944e5
27 changes: 15 additions & 12 deletions src/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export async function openAssistantForm({
const syncSubmit = (inputs, taskTypeId, newTaskCustomId = '') => {
view.loading = true
view.showSyncTaskRunning = true
view.isNotifyEnabled = false
view.progress = null
view.expectedRuntime = null
view.inputs = inputs
Expand Down Expand Up @@ -212,11 +213,10 @@ export async function openAssistantForm({
view.selectedTaskId = null
lastTask = null
})
view.$on('background-notify', () => {
cancelTaskPolling()
view.showSyncTaskRunning = false
view.loading = false
setNotifyReady(lastTask.id)
view.$on('background-notify', (enable) => {
setNotifyReady(lastTask.id, enable).then(res => {
view.isNotifyEnabled = enable
})
})
view.$on('cancel-task', () => {
cancelTaskPolling()
Expand Down Expand Up @@ -275,11 +275,13 @@ export async function getTask(taskId) {
return axios.get(url, { signal: window.assistantAbortController.signal })
}

export async function setNotifyReady(taskId) {
export async function setNotifyReady(taskId, enable) {
const { default: axios } = await import('@nextcloud/axios')
const { generateOcsUrl } = await import('@nextcloud/router')
const url = generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/notify', { taskId })
return axios.post(url, {})
return axios({
method: enable ? 'post' : 'delete',
url: generateOcsUrl('/apps/assistant/api/v1/task/{taskId}/notify', { taskId }),
})
}

export async function cancelTask(taskId) {
Expand Down Expand Up @@ -468,6 +470,7 @@ export async function openAssistantTask(
const syncSubmit = (inputs, taskTypeId, newTaskCustomId = '') => {
view.loading = true
view.showSyncTaskRunning = true
view.isNotifyEnabled = false
view.expectedRuntime = null
view.inputs = inputs
view.selectedTaskTypeId = taskTypeId
Expand Down Expand Up @@ -566,10 +569,10 @@ export async function openAssistantTask(
view.selectedTaskId = null
lastTask = null
})
view.$on('background-notify', () => {
cancelTaskPolling()
view.showSyncTaskRunning = false
setNotifyReady(lastTask.id)
view.$on('background-notify', (enable) => {
setNotifyReady(lastTask.id, enable).then(res => {
view.isNotifyEnabled = enable
})
})
view.$on('cancel-task', () => {
cancelTaskPolling()
Expand Down
7 changes: 6 additions & 1 deletion src/components/AssistantTextProcessingForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
:description="shortInput"
:progress="progress"
:expected-runtime="expectedRuntime"
@background-notify="$emit('background-notify')"
:is-notify-enabled="isNotifyEnabled"
@background-notify="$emit('background-notify', $event)"
@cancel="$emit('cancel-task')" />
<NcAppContent v-else class="session-area">
<div class="session-area__top-bar">
Expand Down Expand Up @@ -227,6 +228,10 @@ export default {
type: [Number, null],
default: null,
},
isNotifyEnabled: {
type: Boolean,
default: false,
},
actionButtons: {
type: Array,
default: () => [],
Expand Down
7 changes: 6 additions & 1 deletion src/components/AssistantTextProcessingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
:short-input="shortInput"
:progress="progress"
:expected-runtime="expectedRuntime"
:is-notify-enabled="isNotifyEnabled"
@sync-submit="onSyncSubmit"
@action-button-clicked="onActionButtonClicked"
@try-again="$emit('try-again', $event)"
@load-task="$emit('load-task', $event)"
@new-task="$emit('new-task')"
@background-notify="$emit('background-notify')"
@background-notify="$emit('background-notify', $event)"
@cancel-task="$emit('cancel-task')" />
</div>
</div>
Expand Down Expand Up @@ -105,6 +106,10 @@ export default {
type: [Number, null],
default: null,
},
isNotifyEnabled: {
type: Boolean,
default: false,
},
actionButtons: {
type: Array,
default: () => [],
Expand Down
17 changes: 12 additions & 5 deletions src/components/RunningEmptyContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
{{ formattedRuntime }}
</div>
<NcButton
@click="$emit('background-notify')">
@click="$emit('background-notify', !isNotifyEnabled)">
<template #icon>
<ProgressClockIcon />
<BellRingOutlineIcon v-if="isNotifyEnabled" />
<BellOutlineIcon v-else />
</template>
{{ t('assistant', 'Run task in the background and get notified') }}
{{ t('assistant', 'Get notified when the task finishes') }}
</NcButton>
<NcButton
@click="$emit('cancel')">
Expand All @@ -40,8 +41,9 @@
</template>

<script>
import BellOutlineIcon from 'vue-material-design-icons/BellOutline.vue'
import BellRingOutlineIcon from 'vue-material-design-icons/BellRingOutline.vue'
import CloseIcon from 'vue-material-design-icons/Close.vue'
import ProgressClockIcon from 'vue-material-design-icons/ProgressClock.vue'

import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
Expand All @@ -56,8 +58,9 @@ export default {
NcEmptyContent,
NcLoadingIcon,
NcProgressBar,
BellOutlineIcon,
BellRingOutlineIcon,
CloseIcon,
ProgressClockIcon,
},

props: {
Expand All @@ -73,6 +76,10 @@ export default {
type: [Number, null],
default: null,
},
isNotifyEnabled: {
type: Boolean,
default: false,
},
},

emits: [
Expand Down
11 changes: 7 additions & 4 deletions src/views/AssistantPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
:short-input="shortInput"
:progress="progress"
:expected-runtime="expectedRuntime"
:is-notify-enabled="isNotifyEnabled"
@sync-submit="onSyncSubmit"
@try-again="onTryAgain"
@load-task="onLoadTask"
Expand Down Expand Up @@ -63,6 +64,7 @@ export default {
showSyncTaskRunning: false,
progress: null,
loading: false,
isNotifyEnabled: false,
}
},

Expand All @@ -89,10 +91,10 @@ export default {
},

methods: {
onBackgroundNotify() {
cancelTaskPolling()
this.showSyncTaskRunning = false
setNotifyReady(this.task.id)
onBackgroundNotify(enable) {
setNotifyReady(this.task.id, enable).then(res => {
this.isNotifyEnabled = enable
})
},
onCancel() {
cancelTaskPolling()
Expand All @@ -101,6 +103,7 @@ export default {
},
syncSubmit(inputs, taskTypeId, newTaskIdentifier = '') {
this.showSyncTaskRunning = true
this.isNotifyEnabled = false
this.progress = null
this.task.completionExpectedAt = null
this.task.scheduledAt = null
Expand Down