Skip to content

Commit

Permalink
Merge pull request #3 from nextcloud/enh/custom-task-select
Browse files Browse the repository at this point in the history
Custom task select
  • Loading branch information
julien-nc authored Sep 29, 2023
2 parents fab13e4 + 9c981a5 commit 5d8e584
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/Listener/TaskFailedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function handle(Event $event): void {
}

$notificationTarget = null;
$notificationActionLabel = null;

// we dispatch an event to ask the app that scheduled the task if it wants a notification
// and what the target should be
Expand Down
1 change: 1 addition & 0 deletions lib/Listener/TaskSuccessfulListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function handle(Event $event): void {
}

$notificationTarget = null;
$notificationActionLabel = null;

// we dispatch an event to ask the app that scheduled the task if it wants a notification
// and what the target should be
Expand Down
34 changes: 18 additions & 16 deletions src/components/AssistantForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
<CreationIcon :size="16" class="icon" />
<span>{{ t('assistant', 'Nextcloud Assistant') }}</span>
</span>
<NcSelect
:value="selectedTaskType"
class="task-select"
:options="taskTypes"
label="name"
:placeholder="t('assistant', 'Choose a task')"
input-id="task-select"
@input="onTaskInput" />
<TaskTypeSelect
:value.sync="mySelectedTaskTypeId"
class="task-custom-select"
:inline="3"
:options="taskTypes" />
<h2 v-if="selectedTaskType"
class="task-name">
{{ selectedTaskType.name }}
Expand Down Expand Up @@ -74,7 +71,8 @@ import CreationIcon from 'vue-material-design-icons/Creation.vue'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcRichContenteditable from '@nextcloud/vue/dist/Components/NcRichContenteditable.js'
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
import TaskTypeSelect from './TaskTypeSelect.vue'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
Expand All @@ -87,9 +85,9 @@ Vue.use(VueClipboard)
export default {
name: 'AssistantForm',
components: {
TaskTypeSelect,
NcButton,
NcRichContenteditable,
NcSelect,
CreationIcon,
ContentCopyIcon,
ClipboardCheckOutlineIcon,
Expand Down Expand Up @@ -161,9 +159,6 @@ export default {
this.loading = false
})
},
onTaskInput(taskType) {
this.mySelectedTaskTypeId = taskType?.id ?? null
},
onCancel() {
this.$emit('cancel')
},
Expand Down Expand Up @@ -204,6 +199,10 @@ export default {
max-height: 200px !important;
}
.editable-input {
min-height: 92px !important;
}
.assistant-bubble {
align-self: start;
display: flex;
Expand All @@ -216,9 +215,12 @@ export default {
}
}
.task-select {
align-self: start;
width: 250px;
.task-custom-select {
width: 100%;
}
.task-action-select {
width: 100%;
}
.task-name {
Expand Down
5 changes: 5 additions & 0 deletions src/components/AssistantModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export default {
// this is to avoid scroll on the container and leave it to the result block
.assistant-modal .modal-container {
display: flex !important;
//&__content {
//padding: 16px;
//}
}
</style>

Expand All @@ -151,6 +155,7 @@ export default {
.assistant-modal--wrapper {
width: 100%;
padding: 16px;
overflow-y: auto;
}
.assistant-modal--content {
Expand Down
120 changes: 120 additions & 0 deletions src/components/TaskTypeSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>
<div class="task-type-select">
<NcButton v-for="(t, i) in buttonTypes"
:key="i + t.id"
:type="getButtonType(t)"
@click="onTaskSelected(t)">
{{ t.name }}
</NcButton>
<NcActions v-if="actionTypes.length > 0"
:force-menu="true">
<NcActionButton v-for="(t, i) in actionTypes"
:key="i + t.id"
class="no-icon-action"
:aria-label="t.name"
:close-after-click="true"
@click="onMenuTaskSelected(t)">
<template #icon>
<div style="width: 16px" />
</template>
{{ t.name }}
</NcActionButton>
</NcActions>
</div>
</template>

<script>
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
export default {
name: 'TaskTypeSelect',
components: {
NcButton,
NcActions,
NcActionButton,
},
props: {
value: {
type: [String, null],
default: null,
},
options: {
type: Array,
required: true,
},
inline: {
type: Number,
default: 3,
},
},
emits: [
'update:value',
],
data() {
return {
extraButtonType: null,
}
},
computed: {
buttonTypes() {
// extra button replaces the last one
if (this.extraButtonType !== null) {
const types = this.options.slice(0, this.inline - 1)
types.push(this.extraButtonType)
return types
} else {
return this.options.slice(0, this.inline)
}
},
actionTypes() {
if (this.extraButtonType !== null) {
// the extra button replaces the last one so we need the last one as an action
// take all non-inline options that are not selected and that are not the extra button
const types = this.options.slice(this.inline).filter(t => t.id !== this.value && t.id !== this.extraButtonType.id)
// add the one that was a button and that has been replaced
if (this.extraButtonType.id !== this.options[this.inline - 1].id) {
types.unshift(this.options[this.inline - 1])
}
return types
} else {
return this.options.slice(this.inline)
}
},
},
mounted() {
},
methods: {
getButtonType(taskType) {
return taskType.id === this.value
? 'primary'
: 'secondary'
},
onTaskSelected(taskType) {
this.$emit('update:value', taskType.id)
},
onMenuTaskSelected(taskType) {
this.extraButtonType = taskType
this.onTaskSelected(taskType)
},
},
}
</script>

<style lang="scss">
.task-type-select {
display: flex;
align-items: center;
flex-wrap: wrap;
row-gap: 8px;
column-gap: 6px;
}
</style>

0 comments on commit 5d8e584

Please sign in to comment.