From 94e499c859596b8fe54ec29e192f66cc09b0bfc4 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Sat, 5 Aug 2023 13:02:16 +0200 Subject: [PATCH] now possible to try again from result form, add copy button in result form Signed-off-by: Julien Veyssier --- package-lock.json | 42 ++++++++++ package.json | 1 + src/assistant.js | 36 ++++++--- src/components/AssistantForm.vue | 89 +++++++++++++++++---- src/components/AssistantHeaderMenuEntry.vue | 3 +- 5 files changed, 144 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8620e55d..04d176df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "@nextcloud/vue": "^7.8.2", "v-click-outside": "^3.2.0", "vue": "^2.7.12", + "vue-clipboard2": "^0.3.3", "vue-material-design-icons": "^5.1.2", "vue2-audio-recorder": "^1.0.4" }, @@ -5798,6 +5799,16 @@ "resolved": "https://registry.npmjs.org/clamp/-/clamp-1.0.1.tgz", "integrity": "sha512-kgMuFyE78OC6Dyu3Dy7vcx4uy97EIbVxJB/B0eJ3bUNAkwdNcxYzgKltnyADiYwsR7SEqkkUPsEUT//OVS6XMA==" }, + "node_modules/clipboard": { + "version": "2.0.11", + "resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.11.tgz", + "integrity": "sha512-C+0bbOqkezLIsmWSvlsXS0Q0bmkugu7jcfMIACB+RDEntIzQIkdr148we28AfSloQLRdZlYL/QYyrq05j/3Faw==", + "dependencies": { + "good-listener": "^1.2.2", + "select": "^1.1.2", + "tiny-emitter": "^2.0.0" + } + }, "node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", @@ -6496,6 +6507,11 @@ "node": ">=0.4.0" } }, + "node_modules/delegate": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/delegate/-/delegate-3.2.0.tgz", + "integrity": "sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==" + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -8566,6 +8582,14 @@ "dev": true, "peer": true }, + "node_modules/good-listener": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/good-listener/-/good-listener-1.2.2.tgz", + "integrity": "sha512-goW1b+d9q/HIwbVYZzZ6SsTr4IgE+WA44A0GmPIQstuOrgsFcT7VEJ48nmr9GaRtNu0XTKacFLGnBPAM6Afouw==", + "dependencies": { + "delegate": "^3.1.2" + } + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -14306,6 +14330,11 @@ "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true }, + "node_modules/select": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz", + "integrity": "sha512-OwpTSOfy6xSs1+pwcNrv0RBMOzI39Lp3qQKUTPVVPRjCdNa5JH/oPRiqsesIskK8TVgmRiHwO4KXlV2Li9dANA==" + }, "node_modules/select-hose": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz", @@ -15607,6 +15636,11 @@ "node": ">=0.6.0" } }, + "node_modules/tiny-emitter": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.1.0.tgz", + "integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==" + }, "node_modules/tinycolor2": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.6.0.tgz", @@ -16350,6 +16384,14 @@ "csstype": "^3.1.0" } }, + "node_modules/vue-clipboard2": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/vue-clipboard2/-/vue-clipboard2-0.3.3.tgz", + "integrity": "sha512-aNWXIL2DKgJyY/1OOeITwAQz1fHaCIGvUFHf9h8UcoQBG5a74MkdhS/xqoYe7DNZdQmZRL+TAdIbtUs9OyVjbw==", + "dependencies": { + "clipboard": "^2.0.0" + } + }, "node_modules/vue-color": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/vue-color/-/vue-color-2.8.1.tgz", diff --git a/package.json b/package.json index 11e3d914..2052ba97 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@nextcloud/vue": "^7.8.2", "v-click-outside": "^3.2.0", "vue": "^2.7.12", + "vue-clipboard2": "^0.3.3", "vue-material-design-icons": "^5.1.2", "vue2-audio-recorder": "^1.0.4" }, diff --git a/src/assistant.js b/src/assistant.js index 9e8efc71..d7621d61 100644 --- a/src/assistant.js +++ b/src/assistant.js @@ -6,16 +6,22 @@ __webpack_public_path__ = linkTo('textprocessing_assistant', 'js/') // eslint-di /** * Creates an assistant modal and return a promise which provides the result * - * OCA.TPAssistant.openAssistantForm('my_app_id', 'my task identifier', 'OCP\\TextProcessing\\FreePromptTaskType', 'count to 3').then(r => {console.debug('scheduled task', r.data.ocs.data.task)}) + * OCA.TPAssistant.openAssistantForm({ + * appId: 'my_app_id', + * identifier: 'my task identifier', + * taskType: 'OCP\\TextProcessing\\FreePromptTaskType', + * input: 'count to 3' + * }).then(r => {console.debug('scheduled task', r.data.ocs.data.task)}) * - * @param {string} appId the scheduling app id - * @param {string} identifier the task identifier - * @param {string} taskType the task type class - * @param {string} inputText optional initial input text - * @param {boolean} isInsideViewer Should be true if this function is called while the Viewer is displayed + * @param {object} params parameters for the assistant + * @param {string} params.appId the scheduling app id + * @param {string} params.identifier the task identifier + * @param {string} params.taskType the task type class + * @param {string} params.input optional initial input text + * @param {boolean} params.isInsideViewer Should be true if this function is called while the Viewer is displayed * @return {Promise} */ -export async function openAssistantForm(appId, identifier = '', taskType = null, inputText = '', isInsideViewer = undefined) { +export async function openAssistantForm({ appId, identifier = '', taskType = null, input = '', isInsideViewer = undefined }) { const { default: Vue } = await import(/* webpackChunkName: "vue-lazy" */'vue') const { default: AssistantModal } = await import(/* webpackChunkName: "assistant-modal-lazy" */'./components/AssistantModal.vue') Vue.mixin({ methods: { t, n } }) @@ -30,7 +36,7 @@ export async function openAssistantForm(appId, identifier = '', taskType = null, const view = new View({ propsData: { isInsideViewer, - input: inputText, + input, selectedTaskTypeId: taskType, }, }).$mount(modalElement) @@ -143,13 +149,22 @@ async function openAssistantResult(task) { input: task.input, output: task.output, selectedTaskTypeId: task.type, - readonly: true, }, }).$mount(modalElement) view.$on('cancel', () => { view.$destroy() }) + view.$on('submit', (data) => { + view.$destroy() + scheduleTask(task.appId, task.identifier, data.taskTypeId, data.input) + .then((response) => { + console.debug('scheduled task', response.data?.ocs?.data?.task) + }) + .catch(error => { + console.error('Assistant scheduling error', error) + }) + }) } async function addAssistantMenuEntry() { @@ -168,7 +183,7 @@ async function addAssistantMenuEntry() { }).$mount(menuEntry) view.$on('click', () => { - openAssistantForm('textprocessing_assistant') + openAssistantForm({ appId: 'textprocessing_assistant' }) .then(r => { console.debug('scheduled task', r) }) @@ -177,6 +192,7 @@ async function addAssistantMenuEntry() { /** * Expose OCA.TPAssistant.openTextProcessingModal to let apps use the assistant + * and add a header right menu entry */ function init() { if (!OCA.TPAssistant) { diff --git a/src/components/AssistantForm.vue b/src/components/AssistantForm.vue index 37e5cc30..d4cb4ee4 100644 --- a/src/components/AssistantForm.vue +++ b/src/components/AssistantForm.vue @@ -25,28 +25,48 @@ :link-autocomplete="false" /> - - {{ selectedTaskType.name }} - - +