From 8196779378b2befeed00c9a94cb5fe5a6e459ef6 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Mon, 16 Nov 2026 13:06:57 +0200 Subject: [PATCH] feat: AI assistant labels, action details and review types for mail templates, custom translation and custom menus; welcome examples on those pages; a change from the chat reloads the open mail templates, translation and custom menu pages (an open menu editor goes back to the list when its menu is deleted), the user's side menu, and the texts of the language in use --- .../services/ai-assistant-panel.service.ts | 14 +++ .../components/ai/ai-action-detail.models.ts | 94 +++++++++++++++++++ .../home/components/ai/ai-action.models.ts | 12 ++- .../ai/ai-approval-card.component.html | 2 +- .../ai/ai-approval-card.component.ts | 9 +- .../home/components/ai/ai-chat.component.ts | 40 ++++++-- .../home/components/ai/ai-welcome.models.ts | 6 +- .../pages/admin/mail-templates.component.ts | 19 +++- .../custom-menu-config.component.ts | 24 ++++- .../custom-menu-table.component.ts | 14 ++- .../translation-map-table.component.ts | 10 ++ .../translation-table.component.ts | 12 ++- .../assets/locale/locale.constant-en_US.json | 73 +++++++++++++- 13 files changed, 309 insertions(+), 20 deletions(-) diff --git a/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts b/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts index 4a5e28bb20..bd6c9ece6f 100644 --- a/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts +++ b/ui-ngx/src/app/core/services/ai-assistant-panel.service.ts @@ -19,6 +19,13 @@ import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { selectAuthUser } from '@core/auth/auth.selectors'; +export interface AiCustomizationSaved { + kind: 'MAIL_TEMPLATES' | 'TRANSLATION' | 'MENU'; + locale?: string; + menuId?: string; + deleted?: boolean; +} + @Injectable({ providedIn: 'root' }) export class AiAssistantPanelService implements OnDestroy { @@ -362,6 +369,13 @@ export class AiAssistantPanelService implements OnDestroy { this._whiteLabelingSaved$.next(target); } + private _customizationSaved$ = new Subject(); + readonly customizationSaved$ = this._customizationSaved$.asObservable(); + + emitCustomizationSaved(event: AiCustomizationSaved): void { + this._customizationSaved$.next(event); + } + emitUpdatedData(affectedEntities: Array): void { this._updatedData$.next(affectedEntities); } diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts b/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts index 01bfb9783d..c0d886bff0 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-action-detail.models.ts @@ -1221,6 +1221,100 @@ function describe(tool: string, values: Values, result: unknown, names: AiDetail ...images([{label: text('image-logo'), value: values.logoImage}, {label: text('image-collapsed-logo'), value: values.collapsedLogoImage}, {label: text('image-favicon'), value: values.favicon}])]}; } + case 'read_mail_templates': { + if (!isObject(result)) { + return {hood: text('read-mail-templates'), blocks: generic(result, 'result')}; + } + const note: AiDetailBlock[] = [{type: 'note', text: text(result.useSystemTemplates ? 'mail-system-in-use' : 'mail-own-in-use')}]; + if (str(result.template)) { + const blocks: AiDetailBlock[] = [...note, {type: 'facts', rows: [{label: K + 'fact.subject', value: str(result.subject) ?? '—', raw: true}]}]; + if (str(result.body)) { + blocks.push({type: 'code', label: 'HTML', text: result.body}); + } + return {hood: text('read-mail-template', {template: result.template}), blocks}; + } + const rows = (Array.isArray(result.templates) ? result.templates.filter(isObject) : []).map(item => `${item.template} · ${item.subject ?? '—'}`); + return {hood: text('read-mail-templates'), blocks: [...note, ...(rows.length ? [{type: 'list', rows} as AiDetailBlock] : [])]}; + } + case 'save_mail_template': { + if (values.useSystemTemplates) { + return {hood: text('mail-use-system'), blocks: []}; + } + const blocks: AiDetailBlock[] = []; + if (str(values.subject)) { + blocks.push({type: 'facts', rows: [{label: K + 'fact.subject', value: values.subject, raw: true}]}); + } + const replace = Array.isArray(values.replace) ? values.replace.filter(isObject) : []; + if (replace.length) { + blocks.push({type: 'list', label: text('mail-replaced'), rows: replace.map(item => `${item.from} → ${item.to}`)}); + } + if (str(values.body)) { + blocks.push({type: 'code', label: 'HTML', text: values.body}); + } + return {hood: str(values.template) ? text('save-mail-template', {template: values.template}) : text('save-mail-templates'), blocks}; + } + case 'read_custom_translation': { + const locale = str(isObject(result) ? result.locale : undefined) ?? str(values.locale) ?? '—'; + if (!isObject(result)) { + return {hood: text('read-custom-translation', {locale}), blocks: generic(result, 'result')}; + } + const blocks: AiDetailBlock[] = []; + const matches = (Array.isArray(result.matches) ? result.matches.filter(isObject) : []).slice(0, MAX_ROWS) + .map(match => `${match.key} · ${match.text}${match.customized ? ' ✎' : ''}`); + if (matches.length) { + blocks.push({type: 'list', label: text('translation-matches'), rows: matches}); + } + const customized = Object.entries(isObject(result.customized) ? result.customized : {}).slice(0, MAX_ROWS) + .map(([key, value]) => `${key} · ${value}`); + if (customized.length) { + blocks.push({type: 'list', label: text('translation-customized'), rows: customized}); + } + return {hood: text('read-custom-translation', {locale}), blocks}; + } + case 'save_custom_translation': { + const blocks: AiDetailBlock[] = []; + const set = (Array.isArray(values.set) ? values.set.filter(isObject) : []).map(item => `${item.key} → ${item.text}`); + if (set.length) { + blocks.push({type: 'list', label: text('translation-set'), rows: set.slice(0, MAX_ROWS)}); + } + const removed = Array.isArray(values.remove) ? values.remove.map(String) : []; + if (removed.length) { + blocks.push({type: 'list', label: text('translation-removed'), rows: removed.slice(0, MAX_ROWS)}); + } + return {hood: text('save-custom-translation', {locale: str(values.locale) ?? '—'}), blocks}; + } + case 'read_custom_menus': { + if (!isObject(result)) { + return {hood: text('read-custom-menus'), blocks: generic(result, 'result')}; + } + if (Array.isArray(result.menus)) { + const rows = result.menus.filter(isObject).slice(0, MAX_ROWS).map(menu => `${menu.name} · ${aiHumanize(String(menu.scope))} · ${aiHumanize(String(menu.assigneeType))}`); + return {hood: text('read-custom-menus'), blocks: rows.length ? [{type: 'list', rows}] : generic(result.note, 'result')}; + } + const rows: string[] = []; + const walk = (items: unknown, depth: number) => { + for (const item of Array.isArray(items) ? items.filter(isObject) : []) { + rows.push(`${' '.repeat(depth)}${str(item.custom) ?? str(item.name) ?? item.id}${item.hidden ? ' ⊘' : ''}`); + walk(item.pages, depth + 1); + } + }; + walk(result.items, 0); + return {hood: text('read-custom-menu', {name: str(result.name) ?? '—'}), blocks: rows.length ? [{type: 'list', rows: rows.slice(0, 80)}] : []}; + } + case 'save_custom_menu': { + const changes = (Array.isArray(values.changes) ? values.changes.filter(isObject) : []) + .map(change => [aiHumanize(String(change.action)), str(change.item) ?? str(change.name), str(change.item) && str(change.name) ? '→ ' + change.name : undefined, + str(change.url) ?? str(change.dashboardId)].filter(Boolean).join(' ')); + const blocks: AiDetailBlock[] = []; + const rows = facts(values, ['menuId', 'changes']); + if (rows.length) { + blocks.push({type: 'facts', rows}); + } + if (changes.length) { + blocks.push({type: 'list', label: text('menu-changes'), rows: changes.slice(0, MAX_ROWS)}); + } + return {hood: str(values.menuId) ? text('save-custom-menu') : text('create-custom-menu', {name: str(values.name) ?? '—'}), blocks}; + } case 'read_ota': { if (!isObject(result)) { return {hood: text('read-ota'), blocks: generic(result, 'result')}; diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts b/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts index 724bee92b0..5f70c22df4 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-action.models.ts @@ -70,6 +70,12 @@ const TOOL_WORDS: Record = { read_white_labeling: 'read-white-labeling', read_website_brand: 'read-website-brand', save_white_labeling: 'save-white-labeling', + read_mail_templates: 'read-mail-templates', + save_mail_template: 'save-mail-template', + read_custom_translation: 'read-custom-translation', + save_custom_translation: 'save-custom-translation', + read_custom_menus: 'read-custom-menus', + save_custom_menu: 'save-custom-menu', save_ota_package: 'save-ota-package', assign_ota_package: 'assign-ota-package', save_platform_settings: 'save-platform-settings', @@ -144,7 +150,8 @@ const DELETED_TARGETS: Record = { ASSET_PROFILE: 'delete-asset-profile', SECRET: 'delete-secret', AI_MODEL: 'delete-ai-model', - RESOURCE: 'delete-resource' + RESOURCE: 'delete-resource', + CUSTOM_MENU: 'delete-custom-menu' }; const ACTION_PREFIX = 'ai-assistant.action.'; @@ -456,6 +463,9 @@ const ENTITY_KINDS: Record = { DASHBOARD_FILTER: {icon: 'filter_list', palette: 'view'}, WIDGET_TYPE: {icon: 'widgets', palette: 'view'}, OTA_PACKAGE: {icon: 'system_update', palette: 'device'}, + MAIL_TEMPLATE: {icon: 'mail', palette: 'view'}, + CUSTOM_TRANSLATION: {icon: 'translate', palette: 'view'}, + CUSTOM_MENU: {icon: 'menu', palette: 'view'}, IMAGE: {icon: 'image', palette: 'view'}, TB_RESOURCE: {icon: 'image', palette: 'view'}, CUSTOMER: {icon: 'supervisor_account', palette: 'people'}, diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.html index 862272bbea..fdedffcd95 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.html +++ b/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.html @@ -18,7 +18,7 @@ } @else if (review) { - } @switch (state) { diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts index d5290cd2da..431f6e0952 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-approval-card.component.ts @@ -23,6 +23,7 @@ import { } from '@shared/models/ai-chat.models'; import { AiAction } from '@home/components/ai/ai-action.models'; import { EntityType, entityTypeTranslations } from '@shared/models/entity-type.models'; +import { MailTemplate, mailTemplateTranslations } from '@shared/models/settings.models'; export type ApprovalCardState = 'pending' | 'approved' | 'auto' | 'denied' | 'expired'; @@ -51,7 +52,7 @@ const VALUE_TOKENS: Record = { const CODE_FIELDS = new Set(['arguments', 'expression', 'output']); -const OWN_TYPE_LABELS = new Set(['DASHBOARD_WIDGET', 'DASHBOARD_STATE', 'DASHBOARD_ENTITY_ALIAS', 'DASHBOARD_FILTER', 'NOTIFICATION', 'NOTIFICATION_SETTINGS', 'NOTIFICATION_PREFERENCES', 'IMAGE', 'PLATFORM_SETTINGS', 'RELATION', 'VERSION', 'WHITE_LABELING']); +const OWN_TYPE_LABELS = new Set(['DASHBOARD_WIDGET', 'DASHBOARD_STATE', 'DASHBOARD_ENTITY_ALIAS', 'DASHBOARD_FILTER', 'NOTIFICATION', 'NOTIFICATION_SETTINGS', 'NOTIFICATION_PREFERENCES', 'IMAGE', 'PLATFORM_SETTINGS', 'RELATION', 'VERSION', 'WHITE_LABELING', 'MAIL_TEMPLATE', 'CUSTOM_TRANSLATION', 'CUSTOM_MENU']); const PROFILE_TYPES = new Set([EntityType.DEVICE_PROFILE, EntityType.ASSET_PROFILE]); @@ -192,6 +193,12 @@ export class AiApprovalCardComponent implements OnChanges { } } + get recordName(): string { + const name = this.review?.name; + const template = this.review?.entityType === 'MAIL_TEMPLATE' && name ? mailTemplateTranslations.get(name as MailTemplate) : undefined; + return template ? this.translate.instant(template) : name; + } + get alarmRule(): boolean { return this.review?.detail === 'alarm-rule'; } diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts index ff73273a81..11f4dbd74a 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-chat.component.ts @@ -32,6 +32,7 @@ import { AiChatsService } from '@core/services/ai-chats.service'; import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { aiParse } from '@home/components/ai/ai-action-detail.models'; import { WhiteLabelingService } from '@core/http/white-labeling.service'; +import { CustomMenuService } from '@core/http/custom-menu.service'; import { ActionNotificationShow } from '@core/notification/notification.actions'; import { isNotEmptyStr, parseHttpErrorMessage } from '@core/utils'; import { ActionChatMessage, AiStartedFrom, ApprovalChatMessage, ChatMessage, GeneralChatMessage } from '@shared/models/solution-creator.models'; @@ -360,6 +361,7 @@ export class AiChatComponent implements OnInit, OnDestroy { private chats = inject(AiChatsService); private panelService = inject(AiAssistantPanelService); private whiteLabelingService = inject(WhiteLabelingService); + private customMenuService = inject(CustomMenuService); private translate = inject(TranslateService); private clipboard = inject(ClipboardService); private store = inject(Store); @@ -1047,15 +1049,41 @@ export class AiChatComponent implements OnInit, OnDestroy { } private applySideEffects(executionId: string, tool: string | undefined, args: unknown): void { - if (tool !== 'save_white_labeling' || this.appliedEffects.has(executionId)) { + if (!tool || this.appliedEffects.has(executionId)) { return; } - this.appliedEffects.add(executionId); - const target = (aiParse(args) as {target?: string})?.target === 'LOGIN' ? 'LOGIN' : 'GENERAL'; - if (target === 'GENERAL') { - this.whiteLabelingService.loadUserWhiteLabelingParams().subscribe(); + const values = (aiParse(args) ?? {}) as {target?: string; locale?: string; menuId?: string; targetType?: string; targetId?: string}; + switch (tool) { + case 'save_white_labeling': { + const target = values.target === 'LOGIN' ? 'LOGIN' : 'GENERAL'; + if (target === 'GENERAL') { + this.whiteLabelingService.loadUserWhiteLabelingParams().subscribe(); + } + this.panelService.emitWhiteLabelingSaved(target); + break; + } + case 'save_mail_template': + this.panelService.emitCustomizationSaved({kind: 'MAIL_TEMPLATES'}); + break; + case 'save_custom_translation': + if (values.locale && (values.locale === this.translate.currentLang || values.locale === this.translate.getDefaultLang())) { + this.translate.currentLoader.getTranslation(values.locale).subscribe(translation => + this.translate.setTranslation(values.locale, translation, true)); + } + this.panelService.emitCustomizationSaved({kind: 'TRANSLATION', locale: values.locale}); + break; + case 'save_custom_menu': + case 'delete': + if (tool === 'delete' && values.targetType !== 'CUSTOM_MENU') { + return; + } + this.customMenuService.loadCustomMenu(true).subscribe(); + this.panelService.emitCustomizationSaved({kind: 'MENU', menuId: values.menuId ?? values.targetId, deleted: tool === 'delete'}); + break; + default: + return; } - this.panelService.emitWhiteLabelingSaved(target); + this.appliedEffects.add(executionId); } private finishAction(finished: ToolFinished): void { diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts b/ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts index a867adcce2..786b15c287 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts +++ b/ui-ngx/src/app/modules/home/components/ai/ai-welcome.models.ts @@ -75,9 +75,9 @@ const WELCOMES: Partial> = { [AiAssistantViewType.OTA_UPDATES]: {key: 'ota-updates', examples: ['rollout', 'add']}, [AiAssistantViewType.WHITE_LABELING]: {key: 'white-labeling', examples: ['brand']}, [AiAssistantViewType.LOGIN_WHITE_LABELING]: {key: 'login-white-labeling', examples: ['match']}, - [AiAssistantViewType.MAIL_TEMPLATES]: {key: 'mail-templates'}, - [AiAssistantViewType.CUSTOM_TRANSLATION]: {key: 'custom-translation'}, - [AiAssistantViewType.CUSTOM_MENU]: {key: 'custom-menu'}, + [AiAssistantViewType.MAIL_TEMPLATES]: {key: 'mail-templates', examples: ['name', 'activation']}, + [AiAssistantViewType.CUSTOM_TRANSLATION]: {key: 'custom-translation', examples: ['rename', 'find']}, + [AiAssistantViewType.CUSTOM_MENU]: {key: 'custom-menu', examples: ['simple', 'link']}, [AiAssistantViewType.IMAGES]: {key: 'images', examples: ['icon']}, [AiAssistantViewType.JAVASCRIPT_LIBRARY]: {key: 'javascript-library', examples: ['module']}, [AiAssistantViewType.RESOURCES_LIBRARY]: {key: 'resources-library'}, diff --git a/ui-ngx/src/app/modules/home/pages/admin/mail-templates.component.ts b/ui-ngx/src/app/modules/home/pages/admin/mail-templates.component.ts index f35f96ed3e..89127da557 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/mail-templates.component.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/mail-templates.component.ts @@ -1,6 +1,9 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { Component, OnInit } from '@angular/core'; +import { Component, DestroyRef, inject, OnInit } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { filter, switchMap } from 'rxjs/operators'; +import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { PageComponent } from '@shared/components/page.component'; import { HasDirtyFlag } from '@core/guards/confirm-on-exit.guard'; import { Store } from '@ngrx/store'; @@ -44,6 +47,9 @@ export class MailTemplatesComponent extends PageComponent implements OnInit, Has hugeRteOptions: Partial; + private aiAssistantPanelService = inject(AiAssistantPanelService); + private destroyRef = inject(DestroyRef); + constructor(protected store: Store, private route: ActivatedRoute, private wl: WhiteLabelingService, @@ -81,7 +87,16 @@ export class MailTemplatesComponent extends PageComponent implements OnInit, Has '| link table image | alignleft aligncenter alignright alignjustify ' + '| numlist bullist outdent indent | blocks | removeformat code | fullscreen'; } - this.mailTemplatesSettings = this.route.snapshot.data.mailTemplatesSettings; + this.applySettings(this.route.snapshot.data.mailTemplatesSettings); + this.aiAssistantPanelService.customizationSaved$.pipe( + filter(event => event.kind === 'MAIL_TEMPLATES' && !this.isDirty), + switchMap(() => this.wl.getMailTemplates(true)), + takeUntilDestroyed(this.destroyRef) + ).subscribe(settings => this.applySettings(settings)); + } + + private applySettings(settings: MailTemplatesSettings) { + this.mailTemplatesSettings = settings; this.mailTemplateTypes = Object.keys(MailTemplate).filter(type => Object.keys(this.mailTemplatesSettings).includes(type)); if (this.isTenantAdmin()) { this.useSystemMailSettings = isDefinedAndNotNull(this.mailTemplatesSettings.useSystemMailSettings) ? this.mailTemplatesSettings.useSystemMailSettings : true; diff --git a/ui-ngx/src/app/modules/home/pages/custom-menu/custom-menu-config.component.ts b/ui-ngx/src/app/modules/home/pages/custom-menu/custom-menu-config.component.ts index 6fbef50183..57a2007ee8 100644 --- a/ui-ngx/src/app/modules/home/pages/custom-menu/custom-menu-config.component.ts +++ b/ui-ngx/src/app/modules/home/pages/custom-menu/custom-menu-config.component.ts @@ -1,12 +1,16 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { Component, ElementRef, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; +import { Component, DestroyRef, ElementRef, inject, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { filter, switchMap, tap } from 'rxjs/operators'; +import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { PageComponent } from '@shared/components/page.component'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { ActivatedRoute, Router } from '@angular/router'; import { MatDialog } from '@angular/material/dialog'; import { + afterLoadCustomMenuConfig, beforeSaveCustomMenuConfig, CustomMenuConfig, CustomMenuInfo, @@ -73,6 +77,9 @@ export class CustomMenuConfigComponent extends PageComponent implements OnInit, return !this.readonly && this.visibleMenuItemsControls().length > 1; } + private aiAssistantPanelService = inject(AiAssistantPanelService); + private destroyRef = inject(DestroyRef); + constructor(protected store: Store, private fb: UntypedFormBuilder, private router: Router, @@ -99,6 +106,21 @@ export class CustomMenuConfigComponent extends PageComponent implements OnInit, this.computeMaxIconNameBlockWidth(); }); this.computeMaxIconNameBlockWidth(); + this.aiAssistantPanelService.customizationSaved$.pipe( + filter(event => event.kind === 'MENU' && event.menuId === this.customMenu.id.id), + tap(event => { + if (event.deleted) { + this.forcePristine = true; + this.goBack(); + } + }), + filter(event => !event.deleted && !this.isDirty), + switchMap(() => this.customMenuService.getCustomMenuConfig(this.customMenu.id.id)), + takeUntilDestroyed(this.destroyRef) + ).subscribe(config => { + this.customMenuConfig = afterLoadCustomMenuConfig(config, this.customMenu.scope); + this.cancel(); + }); } ngOnDestroy() { diff --git a/ui-ngx/src/app/modules/home/pages/custom-menu/custom-menu-table.component.ts b/ui-ngx/src/app/modules/home/pages/custom-menu/custom-menu-table.component.ts index 4da08170a7..42158420fe 100644 --- a/ui-ngx/src/app/modules/home/pages/custom-menu/custom-menu-table.component.ts +++ b/ui-ngx/src/app/modules/home/pages/custom-menu/custom-menu-table.component.ts @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { Component, OnInit, Renderer2, ViewContainerRef } from '@angular/core'; +import { Component, DestroyRef, inject, OnInit, Renderer2, ViewContainerRef } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { TranslateService } from '@ngx-translate/core'; import { DatePipe } from '@angular/common'; import { MatDialog } from '@angular/material/dialog'; @@ -66,7 +68,17 @@ export class CustomMenuTableComponent implements OnInit { private viewContainerRef: ViewContainerRef) { } + private aiAssistantPanelService = inject(AiAssistantPanelService); + private destroyRef = inject(DestroyRef); + ngOnInit() { + this.aiAssistantPanelService.customizationSaved$.pipe( + takeUntilDestroyed(this.destroyRef) + ).subscribe(event => { + if (event.kind === 'MENU') { + this.customMenuTableConfig.updateData(); + } + }); this.customMenuTableConfig.tableTitle = ''; this.customMenuTableConfig.headerComponent = CustomMenuTableHeaderComponent; this.customMenuTableConfig.detailsPanelEnabled = false; diff --git a/ui-ngx/src/app/modules/home/pages/custom-translation/translation-map-table.component.ts b/ui-ngx/src/app/modules/home/pages/custom-translation/translation-map-table.component.ts index cd70f2ab7b..3072f54dbc 100644 --- a/ui-ngx/src/app/modules/home/pages/custom-translation/translation-map-table.component.ts +++ b/ui-ngx/src/app/modules/home/pages/custom-translation/translation-map-table.component.ts @@ -6,6 +6,7 @@ import { Component, ElementRef, EventEmitter, + inject, Input, NgZone, OnDestroy, OnInit, @@ -13,6 +14,7 @@ import { ViewChild } from '@angular/core'; import { PageComponent } from '@shared/components/page.component'; +import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { MatSort, SortDirection } from '@angular/material/sort'; import { PageLink, PageQueryParam } from '@shared/models/page/page-link'; import { BehaviorSubject, forkJoin, merge, Observable, of, Subject } from 'rxjs'; @@ -99,6 +101,7 @@ export class TranslationMapTableComponent extends PageComponent implements OnIni private tableResize$: ResizeObserver; private destroy$ = new Subject(); + private aiAssistantPanelService = inject(AiAssistantPanelService); private defaultSortOrder: SortOrder = { property: 'k', direction: Direction.ASC }; constructor(protected store: Store, @@ -140,6 +143,13 @@ export class TranslationMapTableComponent extends PageComponent implements OnIni this.paginator.pageIndex = this.pageLink.page; this.paginator.pageSize = this.pageLink.pageSize; this.dataSource.loadTranslateInfo(this.pageLink, this.filterParams.value); + this.aiAssistantPanelService.customizationSaved$.pipe( + takeUntil(this.destroy$) + ).subscribe(event => { + if (event.kind === 'TRANSLATION' && event.locale === this.localeCode) { + this.updateData(true); + } + }); this.initSubscriptions(); this.newKey = this.fb.group({ diff --git a/ui-ngx/src/app/modules/home/pages/custom-translation/translation-table.component.ts b/ui-ngx/src/app/modules/home/pages/custom-translation/translation-table.component.ts index a9c4dcd787..0056c82f1a 100644 --- a/ui-ngx/src/app/modules/home/pages/custom-translation/translation-table.component.ts +++ b/ui-ngx/src/app/modules/home/pages/custom-translation/translation-table.component.ts @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { ChangeDetectionStrategy, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { ChangeDetectionStrategy, Component, ElementRef, inject, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service'; import { TranslateService } from '@ngx-translate/core'; import { MatDialog } from '@angular/material/dialog'; import { CustomTranslationService } from '@core/http/custom-translation.service'; @@ -51,6 +52,8 @@ export class TranslationTableComponent extends PageComponent implements OnInit, private destroy$ = new Subject(); + private aiAssistantPanelService = inject(AiAssistantPanelService); + constructor(protected store: Store, private fb: FormBuilder, private customTranslationService: CustomTranslationService, @@ -72,6 +75,13 @@ export class TranslationTableComponent extends PageComponent implements OnInit, this.sort.active = this.pageLink.sortOrder.property; this.sort.direction = (this.pageLink.sortOrder.direction).toLowerCase() as SortDirection; this.dataSource.loadTranslateInfo(this.pageLink); + this.aiAssistantPanelService.customizationSaved$.pipe( + takeUntil(this.destroy$) + ).subscribe(event => { + if (event.kind === 'TRANSLATION') { + this.updateData(true); + } + }); this.textSearch.valueChanges.pipe( debounceTime(150), distinctUntilChanged((prev, current) => (this.pageLink.textSearch ?? '') === current.trim()), diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 3e5b733415..cb9b64c6e5 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -899,6 +899,25 @@ "website-not-read": "The site blocked automated reading, so only its icon was read", "save-white-labeling": "Changed the platform's white labeling", "save-white-labeling-login": "Changed the login page's white labeling", + "read-mail-templates": "Read the mail templates", + "read-mail-template": "Read the {{template}} email", + "mail-system-in-use": "The platform's own templates are in use", + "mail-own-in-use": "The tenant's own templates are in use", + "save-mail-template": "Changed the {{template}} email", + "save-mail-templates": "Changed the emails", + "mail-use-system": "Went back to the platform's own mail templates", + "mail-replaced": "Replaced", + "read-custom-translation": "Read the custom translation {{locale}}", + "translation-matches": "Found texts", + "translation-customized": "Customized texts", + "save-custom-translation": "Changed texts of {{locale}}", + "translation-set": "Changed", + "translation-removed": "Back to the platform's text", + "read-custom-menus": "Read the custom menus", + "read-custom-menu": "Read the menu {{name}}", + "save-custom-menu": "Changed the custom menu", + "create-custom-menu": "Created the custom menu {{name}}", + "menu-changes": "Changes", "reset-white-labeling": "Reset the platform's white labeling to the defaults", "reset-white-labeling-login": "Reset the login page's white labeling to the defaults", "save-ota-package": "Created the OTA package {{name}}", @@ -1001,6 +1020,7 @@ "no": "No", "fact": { "link": "Link", + "subject": "Subject", "last-connect": "Last connected", "version": "Version", "branch": "Branch", @@ -1330,6 +1350,30 @@ "run": "Saving the white labeling", "done": "Saved the white labeling" }, + "read-mail-templates": { + "run": "Reading the mail templates", + "done": "Read the mail templates" + }, + "save-mail-template": { + "run": "Changing the emails", + "done": "Changed the emails" + }, + "read-custom-translation": { + "run": "Reading the custom translation", + "done": "Read the custom translation" + }, + "save-custom-translation": { + "run": "Changing the texts", + "done": "Changed the texts" + }, + "read-custom-menus": { + "run": "Reading the custom menus", + "done": "Read the custom menus" + }, + "save-custom-menu": { + "run": "Saving the custom menu", + "done": "Saved the custom menu" + }, "save-ota-package": { "run": "Creating the OTA package", "done": "Created the OTA package" @@ -1342,6 +1386,10 @@ "run": "Deleting the OTA package", "done": "Deleted the OTA package" }, + "delete-custom-menu": { + "run": "Deleting the custom menu", + "done": "Deleted the custom menu" + }, "commit-version": { "run": "Saving a version", "done": "Saved a version" @@ -1685,6 +1733,10 @@ "domain": "Domain", "baseUrl": "Base URL", "prohibitDifferentUrl": "Base URL only", + "subject": "Subject", + "useSystemTemplates": "Platform's templates", + "assignTo": "Assigned to", + "assignees": "Assignees", "url": "URL", "tag": "Tag", "entities": "Entities", @@ -1767,6 +1819,9 @@ "IMAGE": "Image", "VERSION": "Version", "WHITE_LABELING": "White labeling", + "MAIL_TEMPLATE": "Mail template", + "CUSTOM_TRANSLATION": "Custom translation", + "CUSTOM_MENU": "Custom menu", "RELATION": "Relations", "PLATFORM_SETTINGS": "Platform settings", "ENTITY_GROUP": "Group", @@ -2456,17 +2511,29 @@ "mail-templates": { "title": "Ask about mail templates", "line": "The emails the platform sends, such as activation and password reset.", - "suggestion": "Which emails can I change here?" + "suggestion": "Which emails can I change here?", + "example": { + "name": {"label": "Use our name", "message": "Put our company name Acme IoT instead of ThingsBoard in all emails."}, + "activation": {"label": "Friendlier activation email", "message": "Make the activation email shorter and friendlier, in our brand color #0f7b6c."} + } }, "custom-translation": { "title": "Ask about custom translation", "line": "Your own wording and languages for the platform.", - "suggestion": "How do I change a label in the UI for one language?" + "suggestion": "How do I change a label in the UI for one language?", + "example": { + "rename": {"label": "Rename a word", "message": "Call devices \"machines\" in the menu and page titles."}, + "find": {"label": "What did we change?", "message": "Which texts have we customized so far?"} + } }, "custom-menu": { "title": "Ask about custom menus", "line": "Which menu items your users see, and where.", - "suggestion": "How do I hide menu items from a customer's users?" + "suggestion": "How do I hide menu items from a customer's users?", + "example": { + "simple": {"label": "Simpler menu for customers", "message": "Make a menu for customer users with only Home, Dashboards and Alarms."}, + "link": {"label": "Add a help link", "message": "Add a Help link to https://docs.example.com at the end of our menu."} + } }, "images": { "title": "Ask about your images",