Skip to content

Commit

Permalink
show empty content if no AI provider was found (if task type list is …
Browse files Browse the repository at this point in the history
…empty)

Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Mar 21, 2024
1 parent 34b0152 commit f5f1b4c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 9 deletions.
6 changes: 0 additions & 6 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserSession;
use OCP\TextProcessing\IManager as ITextProcessingManager;
use OCP\Util;

/**
Expand All @@ -26,7 +25,6 @@ public function __construct(
private IConfig $config,
private IInitialState $initialStateService,
private ?string $userId,
private ITextProcessingManager $textProcessingManager
) {
}

Expand All @@ -44,10 +42,6 @@ public function handle(Event $event): void {
return;
}

if (!$this->textProcessingManager->hasProviders()) {
return;
}

$adminAssistantEnabled = $this->config->getAppValue(Application::APP_ID, 'assistant_enabled', '1') === '1';
$userAssistantEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'assistant_enabled', '1') === '1';
$assistantEnabled = $adminAssistantEnabled && $userAssistantEnabled;
Expand Down
3 changes: 1 addition & 2 deletions src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
</h3>
<NcCheckboxRadioSwitch
:checked="state.assistant_enabled"
:disabled="!state.text_processing_available"
@update:checked="onCheckboxChanged($event, 'assistant_enabled')">
<div class="checkbox-text">
{{ t('assistant', 'Top-right assistant') }}
<div v-if="!state.text_processing_available" class="checkbox-text">
<InformationOutlineIcon class="icon" />
<span>
{{ t('assistant', 'To enable this feature, please install any AI text processing provider.') }}
{{ t('assistant', 'To be able to use this feature, please install at least one AI text processing provider.') }}
</span>
</div>
</div>
Expand Down
12 changes: 11 additions & 1 deletion src/components/AssistantTextProcessingForm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div class="assistant-form">
<NcLoadingIcon v-if="loadingTaskTypes" />
<NoProviderEmptyContent v-else-if="taskTypes.length === 0" />
<div v-else
class="assistant-form">
<span class="assistant-bubble">
<CreationIcon :size="16" class="icon" />
<span>{{ t('assistant', 'Nextcloud Assistant') }}</span>
Expand Down Expand Up @@ -134,6 +137,7 @@ import TaskTypeSelect from './TaskTypeSelect.vue'
import AssistantFormInputs from './AssistantFormInputs.vue'
import Text2ImageDisplay from './Text2Image/Text2ImageDisplay.vue'
import TaskList from './TaskList.vue'
import NoProviderEmptyContent from './NoProviderEmptyContent.vue'
import axios from '@nextcloud/axios'
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
Expand All @@ -148,6 +152,7 @@ const FREE_PROMPT_TASK_TYPE_ID = 'OCP\\TextProcessing\\FreePromptTaskType'
export default {
name: 'AssistantTextProcessingForm',
components: {
NoProviderEmptyContent,
TaskList,
Text2ImageDisplay,
TaskTypeSelect,
Expand Down Expand Up @@ -199,6 +204,7 @@ export default {
mySelectedTaskTypeId: this.selectedTaskTypeId || FREE_PROMPT_TASK_TYPE_ID,
copied: false,
showHistory: false,
loadingTaskTypes: false,
}
},
computed: {
Expand Down Expand Up @@ -274,13 +280,17 @@ export default {
},
methods: {
getTaskTypes() {
this.loadingTaskTypes = true
axios.get(generateOcsUrl('/apps/assistant/api/v1/task-types'))
.then((response) => {
this.taskTypes = response.data.ocs.data.types
})
.catch((error) => {
console.error(error)
})
.then(() => {
this.loadingTaskTypes = false
})
},
onSubmit() {
this.$emit('submit', { inputs: this.myInputs, selectedTaskTypeId: this.mySelectedTaskTypeId })
Expand Down
69 changes: 69 additions & 0 deletions src/components/NoProviderEmptyContent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<template>
<NcEmptyContent
:name="t('assistant', 'No provider found')"
:description="t('assistant', 'AI Providers need to be installed to use the Assistant')">
<template v-if="isAdmin" #action>
<span v-html="actionHtml" />
</template>
<template #icon>
<AssistantIcon />
</template>
</NcEmptyContent>
</template>

<script>
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import AssistantIcon from './icons/AssistantIcon.vue'
import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl } from '@nextcloud/router'
const toolSectionUrl = generateUrl('/settings/apps/tools')
const toolLinkText = t('assistant', 'tool')
const toolLink = `<a class="external" target="_blank" href="${toolSectionUrl}">${toolLinkText}</a>`
const integrationSectionUrl = generateUrl('/settings/apps/integration')
const integrationLinkText = t('assistant', 'integration')
const integrationLink = `<a class="external" target="_blank" href="${integrationSectionUrl}">${integrationLinkText}</a>`
export default {
name: 'NoProviderEmptyContent',
components: {
AssistantIcon,
NcEmptyContent,
},
props: {
},
data() {
return {
isAdmin: getCurrentUser()?.isAdmin,
}
},
computed: {
actionHtml() {
return t('assistant', 'AI provider apps can be found in the {toolLink} and {integrationLink} app settings sections.', {
toolLink,
integrationLink,
}, undefined, { escape: false, sanitize: false })
},
},
watch: {
},
mounted() {
},
methods: {
},
}
</script>
<style lang="scss">
// nothing yet
</style>

0 comments on commit f5f1b4c

Please sign in to comment.