From 8bbbc3e3e4d7df73ad3ee82391dc7f315b54af16 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Mon, 23 Nov 2026 16:25:26 +0200 Subject: [PATCH] feat: the new Home for a tenant administrator without a home dashboard: the greeting with the AI spark over a sky in the AI's light, tied to the white-label colour; the status line counting critical and active alarms and inactive devices live; the folded composer that opens on focus or / and hands its message to the AI Assistant, with Chats beside it and the chats waiting for you; IoT Hub with its search, solution templates and device library in rows that scroll sideways, the other kinds of items and Hide with Undo; the other cards as frames for now; Customize Home and Show on Home keep the cards shown per user --- ui-ngx/src/app/core/auth/auth.actions.ts | 11 +- ui-ngx/src/app/core/auth/auth.effects.ts | 8 + ui-ngx/src/app/core/auth/auth.reducer.ts | 4 + ui-ngx/src/app/core/auth/auth.selectors.ts | 5 + .../services/ai-assistant-panel.service.ts | 20 +- .../ai/ai-prompt-input.component.html | 7 +- .../ai/ai-prompt-input.component.scss | 96 +++++ .../ai/ai-prompt-input.component.ts | 7 + .../ai-assistant/ai-assistant.component.ts | 7 +- .../home-links/home-links-routing.module.ts | 3 - .../home-links/home-links.component.html | 24 +- .../home-links/home-links.component.scss | 56 +-- .../pages/home-links/home-links.component.ts | 52 +-- .../pages/home-links/home-links.module.ts | 52 ++- .../ai-assistant-home.component.scss | 97 +++++ .../components/ai-assistant-home.component.ts | 55 +++ .../home/components/alarms-home.component.ts | 16 + .../components/api-usage-home.component.ts | 16 + .../customize-home-dialog.component.scss | 73 ++++ .../customize-home-dialog.component.ts | 65 ++++ .../components/dashboards-home.component.ts | 16 + .../devices-activity-home.component.ts | 16 + .../home/components/devices-home.component.ts | 16 + .../components/get-started-home.component.ts | 16 + .../home/components/home-card.component.scss | 152 ++++++++ .../home/components/home-card.component.ts | 70 ++++ .../home-cards-footer.component.scss | 70 ++++ .../components/home-cards-footer.component.ts | 65 ++++ .../components/home-hscroll.component.scss | 166 ++++++++ .../home/components/home-hscroll.component.ts | 133 +++++++ .../components/iot-hub-home.component.html | 105 +++++ .../components/iot-hub-home.component.scss | 361 ++++++++++++++++++ .../home/components/iot-hub-home.component.ts | 198 ++++++++++ .../components/mobile-app-home.component.ts | 16 + .../notifications-home.component.ts | 16 + .../components/quick-links-home.component.ts | 16 + .../status-line-home.component.scss | 65 ++++ .../components/status-line-home.component.ts | 157 ++++++++ .../waiting-ai-chats-home.component.scss | 72 ++++ .../waiting-ai-chats-home.component.ts | 42 ++ .../components/welcome-home.component.scss | 49 +++ .../home/components/welcome-home.component.ts | 35 ++ .../home-links/home/home-cards.models.ts | 27 ++ .../pages/customer-user-home.component.ts | 20 + .../home/pages/home-page.component.scss | 69 ++++ .../home/pages/home-page.component.ts | 47 +++ .../home/pages/sys-admin-home.component.ts | 19 + .../pages/tenant-admin-home.component.html | 65 ++++ .../pages/tenant-admin-home.component.scss | 99 +++++ .../home/pages/tenant-admin-home.component.ts | 35 ++ .../app/shared/models/user-settings.models.ts | 16 + .../assets/locale/locale.constant-en_US.json | 56 +++ 52 files changed, 2838 insertions(+), 141 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/ai-assistant-home.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/ai-assistant-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/alarms-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/api-usage-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/customize-home-dialog.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/customize-home-dialog.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/dashboards-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-activity-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/get-started-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/mobile-app-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/notifications-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/quick-links-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/home-cards.models.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/pages/customer-user-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/pages/sys-admin-home.component.ts create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.ts diff --git a/ui-ngx/src/app/core/auth/auth.actions.ts b/ui-ngx/src/app/core/auth/auth.actions.ts index 60501f9472..5a1778c63f 100644 --- a/ui-ngx/src/app/core/auth/auth.actions.ts +++ b/ui-ngx/src/app/core/auth/auth.actions.ts @@ -4,7 +4,7 @@ import { Action } from '@ngrx/store'; import { AuthUser, User } from '@shared/models/user.model'; import { AuthPayload } from '@core/auth/auth.models'; -import { AiTourStep, UserSettings } from '@shared/models/user-settings.models'; +import { AiTourStep, HomeCardsSettings, UserSettings } from '@shared/models/user-settings.models'; export enum AuthActionTypes { AUTHENTICATED = '[Auth] Authenticated', @@ -17,6 +17,7 @@ export enum AuthActionTypes { UPDATE_MOBILE_QR_ENABLED = '[Auth] Update Mobile QR Enabled', UPDATE_OPENED_MENU_SECTION = '[Preferences] Update Opened Menu Section', UPDATE_AI_TOUR = '[Preferences] Update AI tour', + UPDATE_HOME_CARDS = '[Preferences] Update home cards', PUT_USER_SETTINGS = '[Preferences] Put user settings', DELETE_USER_SETTINGS = '[Preferences] Delete user settings', UPDATE_LICENSE_PARAMS = '[Auth] Update License Parameters', @@ -80,6 +81,12 @@ export class ActionPreferencesUpdateAiTour implements Action { constructor(readonly payload: { step: AiTourStep; seen: boolean }) {} } +export class ActionPreferencesUpdateHomeCards implements Action { + readonly type = AuthActionTypes.UPDATE_HOME_CARDS; + + constructor(readonly payload: HomeCardsSettings) {} +} + export class ActionPreferencesPutUserSettings implements Action { readonly type = AuthActionTypes.PUT_USER_SETTINGS; @@ -100,5 +107,5 @@ export class ActionUpdateLicenseParams implements Action { export type AuthActions = ActionAuthAuthenticated | ActionAuthUnauthenticated | ActionAuthLoadUser | ActionAuthUpdateUserDetails | ActionAuthUpdateLastPublicDashboardId | ActionAuthUpdateHasRepository | - ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesUpdateAiTour | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings | + ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesUpdateAiTour | ActionPreferencesUpdateHomeCards | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings | ActionAuthUpdateAuthUser | ActionUpdateMobileQrCodeEnabled | ActionUpdateLicenseParams; diff --git a/ui-ngx/src/app/core/auth/auth.effects.ts b/ui-ngx/src/app/core/auth/auth.effects.ts index 54e50c3126..49812fc732 100644 --- a/ui-ngx/src/app/core/auth/auth.effects.ts +++ b/ui-ngx/src/app/core/auth/auth.effects.ts @@ -35,6 +35,14 @@ export class AuthEffects { concatMap(([action, state]) => this.userSettingsService.putUserSettings({ aiTour: state.userSettings.aiTour ?? {} })) ), {dispatch: false}); + persistHomeCards = createEffect(() => this.actions$.pipe( + ofType( + AuthActionTypes.UPDATE_HOME_CARDS, + ), + withLatestFrom(this.store.pipe(select(selectAuthState))), + concatMap(([action, state]) => this.userSettingsService.putUserSettings({ homeCards: state.userSettings.homeCards ?? {} })) + ), {dispatch: false}); + putUserSettings = createEffect(() => this.actions$.pipe( ofType( AuthActionTypes.PUT_USER_SETTINGS, diff --git a/ui-ngx/src/app/core/auth/auth.reducer.ts b/ui-ngx/src/app/core/auth/auth.reducer.ts index 4eadd67641..9643135e4b 100644 --- a/ui-ngx/src/app/core/auth/auth.reducer.ts +++ b/ui-ngx/src/app/core/auth/auth.reducer.ts @@ -107,6 +107,10 @@ export const authReducer = ( userSettings = {...state.userSettings, aiTour}; return { ...state, ...{ userSettings }}; + case AuthActionTypes.UPDATE_HOME_CARDS: + userSettings = {...state.userSettings, homeCards: {...state.userSettings.homeCards, ...action.payload}}; + return { ...state, ...{ userSettings }}; + case AuthActionTypes.PUT_USER_SETTINGS: userSettings = {...state.userSettings, ...action.payload}; return { ...state, ...{ userSettings }}; diff --git a/ui-ngx/src/app/core/auth/auth.selectors.ts b/ui-ngx/src/app/core/auth/auth.selectors.ts index 02b8578b7d..99034a89fd 100644 --- a/ui-ngx/src/app/core/auth/auth.selectors.ts +++ b/ui-ngx/src/app/core/auth/auth.selectors.ts @@ -101,6 +101,11 @@ export const selectAiTourStepSeen = (step: AiTourStep) => createSelector( aiTour => !!aiTour[step] ); +export const selectHomeCards = createSelector( + selectAuthState, + (state: AuthState) => state.userSettings?.homeCards ?? {} +); + export const getCurrentAuthState = (store: Store): AuthState => { let state: AuthState; store.pipe(select(selectAuth), take(1)).subscribe( 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 357e284df0..52c7b6abc4 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 @@ -5,13 +5,7 @@ import { defer, Observable, Subject } from 'rxjs'; import { distinctUntilChanged, filter, finalize, map } from 'rxjs/operators'; import { NavigationEnd, NavigationStart, Router } from '@angular/router'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { - AiAssistantPanelConfig, - AiAssistantViewType, - AiChatClientContext, - AiChatView, - ChatInfo -} from '@shared/models/ai-chat.models'; +import { AiAssistantPanelConfig, AiAssistantViewType, AiChatClientContext, AiChatView, ChatInfo, AiPromptMessage } from '@shared/models/ai-chat.models'; import { EntityId } from '@shared/models/id/entity-id'; import { getDefaultTimezone } from '@shared/models/time/time.models'; import { LocalStorageService } from '@core/local-storage/local-storage.service'; @@ -160,6 +154,18 @@ export class AiAssistantPanelService implements OnDestroy { private _openOnArrival = false; + private _handOff: AiPromptMessage | null = null; + + handOff(prompt: AiPromptMessage): void { + this._handOff = prompt; + } + + takeHandOff(): AiPromptMessage | null { + const prompt = this._handOff; + this._handOff = null; + return prompt; + } + carryChat(chatId: string): void { this._carried = {chatId, from: this.contextKey(), at: Date.now()}; } diff --git a/ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html b/ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html index 98f64bb0f1..edb5bfcbb4 100644 --- a/ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html +++ b/ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html @@ -4,7 +4,7 @@ SPDX-License-Identifier: BUSL-1.1 --> -
+
@if (attachEnabled()) { } @@ -57,7 +57,7 @@ {{ 'ai-assistant.suggestion-sr' | translate: {text: suggestion} }} } + @if (slim) { + + } @if (canStop) { + } + + +
+
+ `, + styleUrls: ['./customize-home-dialog.component.scss'], + encapsulation: ViewEncapsulation.None, + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class CustomizeHomeDialogComponent { + + readonly dialogRef = inject(MatDialogRef); + + private data = inject(MAT_DIALOG_DATA); + private store = inject(Store); + + private settings = toSignal(this.store.select(selectHomeCards), {initialValue: {}}); + + readonly rows = computed(() => this.data.cards.map(id => ({card: HOME_CARDS[id], shown: isHomeCardShown(this.settings(), id)}))); + + readonly anyHidden = computed(() => this.rows().some(row => !row.shown)); + + toggle(id: HomeCardId, shown: boolean): void { + this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: shown})); + } + + showAll(): void { + this.store.dispatch(new ActionPreferencesUpdateHomeCards(Object.fromEntries(this.data.cards.map(id => [id, true])))); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/dashboards-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/dashboards-home.component.ts new file mode 100644 index 0000000000..b15dfddc07 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/dashboards-home.component.ts @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { HOME_CARDS } from '@home/pages/home-links/home/home-cards.models'; + +@Component({ + selector: 'tb-dashboards-home', + template: ``, + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class DashboardsHomeComponent { + + readonly card = HOME_CARDS[HomeCardId.DASHBOARDS]; +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-activity-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-activity-home.component.ts new file mode 100644 index 0000000000..5674d56bec --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-activity-home.component.ts @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { HOME_CARDS } from '@home/pages/home-links/home/home-cards.models'; + +@Component({ + selector: 'tb-devices-activity-home', + template: ``, + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class DevicesActivityHomeComponent { + + readonly card = HOME_CARDS[HomeCardId.ACTIVITY]; +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.ts new file mode 100644 index 0000000000..1b7489f283 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.ts @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { HOME_CARDS } from '@home/pages/home-links/home/home-cards.models'; + +@Component({ + selector: 'tb-devices-home', + template: ``, + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class DevicesHomeComponent { + + readonly card = HOME_CARDS[HomeCardId.DEVICES]; +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/get-started-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/get-started-home.component.ts new file mode 100644 index 0000000000..50febbe4cb --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/get-started-home.component.ts @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { HOME_CARDS } from '@home/pages/home-links/home/home-cards.models'; + +@Component({ + selector: 'tb-get-started-home', + template: ``, + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class GetStartedHomeComponent { + + readonly card = HOME_CARDS[HomeCardId.GET_STARTED]; +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.scss new file mode 100644 index 0000000000..200f658143 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.scss @@ -0,0 +1,152 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +:host { + display: block; + min-width: 0; +} + +.tb-home-card { + position: relative; + display: flex; + flex-direction: column; + gap: 12px; + box-sizing: border-box; + min-width: 0; + padding: var(--tb-home-card-padding, 20px); + border-radius: 12px; + background: var(--tb-surface, #fff); + box-shadow: var(--tb-home-card-shadow); +} + +.tb-home-card-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px 12px; + min-height: 36px; + flex-wrap: wrap; +} + +.tb-home-card-title { + &:hover, &:focus, &:active { + border-bottom: none; + } + + display: inline-flex; + align-items: center; + gap: 6px; + max-width: 100%; + overflow: hidden; + font: 600 16px/24px var(--tb-font, Roboto, sans-serif); + letter-spacing: 0.15px; + white-space: nowrap; + text-overflow: ellipsis; + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); + text-decoration: none; + border-bottom: none; + + &.link::after { + content: 'chevron_right'; + display: inline-block; + margin-left: -2px; + font-family: 'Material Icons'; + font-size: 20px; + font-weight: normal; + line-height: 1; + color: var(--tb-ink-38, rgba(0, 0, 0, 0.38)); + } + + &.link:hover { + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + + &::after { + color: inherit; + } + } + + &.link:focus-visible { + outline: 2px solid var(--tb-primary-500); + outline-offset: 2px; + border-radius: 4px; + } +} + +.tb-home-card-icon { + flex: none; + width: 20px; + height: 20px; + font-size: 20px; + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); +} + +.tb-home-card-actions { + display: flex; + flex-wrap: nowrap; + align-items: center; + gap: 4px; + min-width: 0; + margin-left: auto; + + &:empty { + display: none; + } +} + +.tb-home-card.hideable { + padding-top: 16px; + + .tb-home-card-header { + min-height: 32px; + flex-wrap: nowrap; + } +} + +.tb-home-card-header.expanded .tb-home-card-actions { + flex: 1; + justify-content: flex-end; +} + +.tb-home-card-hide.mat-mdc-icon-button.mat-mdc-button-base { + --mdc-icon-button-state-layer-size: 32px; + --mat-icon-button-state-layer-size: 32px; + display: inline-flex; + align-items: center; + justify-content: center; + width: 32px; + height: 32px; + padding: 0; + color: var(--tb-ink-38, rgba(0, 0, 0, 0.38)); + + .mat-icon { + width: 20px; + height: 20px; + font-size: 20px; + } + + &:hover, &:focus-visible { + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); + } +} + +@media (hover: hover) { + .tb-home-card-hide.mat-mdc-icon-button.mat-mdc-button-base { + opacity: 0; + transition: opacity .15s, color .15s; + } + + .tb-home-card:is(:hover, :focus-within) .tb-home-card-hide.mat-mdc-icon-button.mat-mdc-button-base { + opacity: 1; + } +} + +@media (hover: hover) and (prefers-reduced-motion: reduce) { + .tb-home-card-hide.mat-mdc-icon-button.mat-mdc-button-base { + transition: none; + } +} + +@media (max-width: 599px) { + .tb-home-card.hideable { + padding-top: var(--tb-home-card-padding, 20px); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts new file mode 100644 index 0000000000..911741e6f5 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component, inject, input } from '@angular/core'; +import { Store } from '@ngrx/store'; +import { MatSnackBar } from '@angular/material/snack-bar'; +import { TranslateService } from '@ngx-translate/core'; +import { AppState } from '@core/core.state'; +import { ActionPreferencesUpdateHomeCards } from '@core/auth/auth.actions'; +import { HomeCardDefinition } from '@home/pages/home-links/home/home-cards.models'; + +const UNDO_MS = 6000; + +@Component({ + selector: 'tb-home-card', + template: ` +
+
+ @if (card().link) { + + {{ card().icon }} + {{ card().name | translate }} + + } @else { + + {{ card().icon }} + {{ card().name | translate }} + + } +
+ @if (hideable() && !expanded()) { + + } + +
+
+ +
+ `, + styleUrls: ['./home-card.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class HomeCardComponent { + + card = input.required(); + + hideable = input(false); + + expanded = input(false); + + private store = inject(Store); + private snackBar = inject(MatSnackBar); + private translate = inject(TranslateService); + + hide(): void { + const id = this.card().id; + const name = this.translate.instant(this.card().name); + this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: false})); + this.snackBar.open(this.translate.instant('home.customize.hidden', {name}), this.translate.instant('home.customize.undo'), { + duration: UNDO_MS, + horizontalPosition: 'end', + verticalPosition: 'bottom' + }).onAction().subscribe(() => this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: true}))); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.scss new file mode 100644 index 0000000000..867b3e1e0c --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.scss @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +:host { + display: block; +} + +.tb-home-foot { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 4px 16px; + margin-top: 8px; + padding: 12px 0 0; + border-top: 1px solid var(--tb-line-soft, rgba(0, 0, 0, 0.05)); +} + +.tb-hidden-cards { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 2px; + min-width: 0; +} + +.tb-hidden-lbl { + margin: 0 6px 0 4px; + font: 400 13px/20px var(--tb-font, Roboto, sans-serif); + color: var(--tb-ink-54, rgba(0, 0, 0, 0.54)); +} + +.tb-foot-btn { + display: inline-flex; + align-items: center; + gap: 6px; + height: 32px; + padding: 0 10px 0 8px; + border: 0; + border-radius: 8px; + background: none; + font: 400 14px/20px var(--tb-font, Roboto, sans-serif); + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); + cursor: pointer; + transition: background-color .15s ease, color .15s ease; + + .mat-icon { + width: 18px; + height: 18px; + font-size: 18px; + line-height: 18px; + color: var(--tb-ink-54, rgba(0, 0, 0, 0.54)); + } + + &:hover { + background: rgba(0, 0, 0, 0.04); + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + + .mat-icon { + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); + } + } + + &:focus-visible { + outline: 2px solid var(--tb-primary-500); + outline-offset: -2px; + } +} + +.tb-customize-btn { + margin-left: auto; +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.ts new file mode 100644 index 0000000000..fae7c38405 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.ts @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component, computed, inject, input } from '@angular/core'; +import { toSignal } from '@angular/core/rxjs-interop'; +import { MatDialog } from '@angular/material/dialog'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { selectHomeCards } from '@core/auth/auth.selectors'; +import { ActionPreferencesUpdateHomeCards } from '@core/auth/auth.actions'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { HOME_CARDS, isHomeCardShown } from '@home/pages/home-links/home/home-cards.models'; +import { + CustomizeHomeDialogComponent, + CustomizeHomeDialogData +} from '@home/pages/home-links/home/components/customize-home-dialog.component'; + +@Component({ + selector: 'tb-home-cards-footer', + template: ` +
+ @if (hidden().length) { +
+ {{ 'home.customize.show-on-home' | translate }} + @for (card of hidden(); track card.id) { + + } +
+ } + +
+ `, + styleUrls: ['./home-cards-footer.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class HomeCardsFooterComponent { + + cards = input.required(); + + private store = inject(Store); + private dialog = inject(MatDialog); + + private settings = toSignal(this.store.select(selectHomeCards), {initialValue: {}}); + + readonly hidden = computed(() => this.cards().filter(id => !isHomeCardShown(this.settings(), id)).map(id => HOME_CARDS[id])); + + show(id: HomeCardId): void { + this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: true})); + setTimeout(() => document.querySelector(`[data-home-card="${id}"]`)?.scrollIntoView({behavior: 'smooth', block: 'center'})); + } + + customize(): void { + this.dialog.open(CustomizeHomeDialogComponent, { + panelClass: 'tb-customize-home-panel', + autoFocus: 'first-tabbable', + data: {cards: this.cards()} + }); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.scss new file mode 100644 index 0000000000..05b71c6228 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.scss @@ -0,0 +1,166 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +tb-home-hscroll { + display: block; + min-width: 0; +} + +.tb-hscroll { + margin: 0 -20px; + + .tb-hscroll-view { + position: relative; + + &::before, &::after { + content: ''; + position: absolute; + top: 0; + bottom: 0; + z-index: 1; + width: 56px; + pointer-events: none; + transition: opacity .15s ease; + } + + &::before { + left: 0; + background: linear-gradient(90deg, var(--tb-surface, #fff), transparent); + } + + &::after { + right: 0; + background: linear-gradient(270deg, var(--tb-surface, #fff), transparent); + } + } + + &.at-start .tb-hscroll-view::before, &.at-end .tb-hscroll-view::after { + opacity: 0; + } + + .tb-hscroll-track { + position: relative; + display: flex; + gap: 12px; + overflow-x: auto; + padding: 2px 20px; + scroll-padding: 0 20px; + scroll-snap-type: x proximity; + overscroll-behavior-x: contain; + scrollbar-width: none; + + &::-webkit-scrollbar { + display: none; + } + + > * { + flex: none; + scroll-snap-align: start; + } + + @media (prefers-reduced-motion: no-preference) { + scroll-behavior: smooth; + } + } + + &.dragging .tb-hscroll-track { + scroll-behavior: auto; + scroll-snap-type: none; + } + + .tb-hscroll-btn { + position: absolute; + top: var(--arrow-y, 50%); + z-index: 2; + display: inline-flex; + align-items: center; + justify-content: center; + width: 32px; + height: 32px; + padding: 0; + border: 0; + border-radius: 50%; + background: var(--tb-surface, #fff); + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.14), 0 4px 14px rgba(16, 24, 40, 0.2); + cursor: pointer; + opacity: 0; + pointer-events: none; + transform: translateY(-50%); + transition: opacity .15s ease; + + &:hover { + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.16), 0 6px 18px rgba(16, 24, 40, 0.26); + } + + &.prev { + left: 10px; + } + + &.next { + right: 10px; + } + + .mat-icon { + width: 24px; + height: 24px; + font-size: 24px; + } + } + + &:hover .tb-hscroll-btn { + opacity: 1; + pointer-events: auto; + } + + &.at-start .tb-hscroll-btn.prev, &.at-end .tb-hscroll-btn.next { + opacity: 0; + pointer-events: none; + } + + .tb-hscroll-bar { + position: relative; + height: 12px; + margin: 2px 20px -4px; + cursor: pointer; + touch-action: none; + opacity: 0; + transition: opacity .15s ease; + + > i { + position: absolute; + top: 4px; + left: 0; + height: 4px; + border-radius: 2px; + background: var(--tb-ink-12, rgba(0, 0, 0, 0.12)); + transition: background-color .15s ease; + } + + &:hover > i { + background: var(--tb-ink-38, rgba(0, 0, 0, 0.38)); + } + } + + &:hover .tb-hscroll-bar, &.dragging .tb-hscroll-bar { + opacity: 1; + } + + &.dragging .tb-hscroll-bar > i { + background: var(--tb-ink-38, rgba(0, 0, 0, 0.38)); + } + + &.fits .tb-hscroll-bar { + visibility: hidden; + } + + @media (hover: none) { + .tb-hscroll-btn, .tb-hscroll-bar { + display: none; + } + + .tb-hscroll-view::before, .tb-hscroll-view::after { + width: 24px; + } + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.ts new file mode 100644 index 0000000000..1f46148992 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.ts @@ -0,0 +1,133 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { + AfterViewInit, + ChangeDetectionStrategy, + Component, + DestroyRef, + ElementRef, + inject, + input, + signal, + ViewChild, + ViewEncapsulation +} from '@angular/core'; + +const MIN_THUMB = 32; + +@Component({ + selector: 'tb-home-hscroll', + template: ` +
+
+
+ +
+ + +
+ +
+ `, + styleUrls: ['./home-hscroll.component.scss'], + encapsulation: ViewEncapsulation.None, + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class HomeHscrollComponent implements AfterViewInit { + + label = input(); + + @ViewChild('track', {static: true}) trackRef: ElementRef; + @ViewChild('bar', {static: true}) barRef: ElementRef; + + readonly atStart = signal(true); + readonly atEnd = signal(false); + readonly fits = signal(false); + readonly dragging = signal(false); + readonly thumbWidth = signal(MIN_THUMB); + readonly thumbX = signal(0); + readonly arrowY = signal(null); + + private destroyRef = inject(DestroyRef); + + ngAfterViewInit(): void { + const observer = new ResizeObserver(() => this.layout()); + observer.observe(this.trackRef.nativeElement); + const mutations = new MutationObserver(() => this.layout()); + mutations.observe(this.trackRef.nativeElement, {childList: true, subtree: true}); + this.destroyRef.onDestroy(() => { + observer.disconnect(); + mutations.disconnect(); + }); + this.layout(); + } + + sync(): void { + const track = this.trackRef.nativeElement; + const width = track.clientWidth; + const max = track.scrollWidth - width; + const x = track.scrollLeft; + const rail = this.barRef.nativeElement.clientWidth; + this.atStart.set(x < 2); + this.atEnd.set(x > max - 2); + this.fits.set(max < 2); + const thumb = Math.max(MIN_THUMB, rail * width / Math.max(1, track.scrollWidth)); + this.thumbWidth.set(thumb); + this.thumbX.set(max > 0 ? (x / max) * (rail - thumb) : 0); + } + + step(dir: number): void { + const track = this.trackRef.nativeElement; + const pad = parseFloat(getComputedStyle(track).paddingLeft) || 0; + const left = track.scrollLeft; + const right = left + track.clientWidth; + const kids = Array.from(track.children) as HTMLElement[]; + const next = dir > 0 + ? kids.find(kid => kid.offsetLeft + kid.offsetWidth > right - pad + 1) + : kids.reverse().find(kid => kid.offsetLeft < left + pad - 1); + if (next) { + track.scrollTo({left: dir > 0 ? next.offsetLeft - pad : next.offsetLeft + next.offsetWidth + pad - track.clientWidth}); + } + } + + press(event: PointerEvent): void { + event.preventDefault(); + const bar = this.barRef.nativeElement; + const track = this.trackRef.nativeElement; + bar.setPointerCapture(event.pointerId); + this.dragging.set(true); + const move = (moveEvent: PointerEvent) => { + const rect = bar.getBoundingClientRect(); + const thumb = this.thumbWidth(); + const share = Math.min(1, Math.max(0, (moveEvent.clientX - rect.left - thumb / 2) / Math.max(1, rect.width - thumb))); + track.scrollLeft = share * (track.scrollWidth - track.clientWidth); + }; + const end = () => { + bar.removeEventListener('pointermove', move); + this.dragging.set(false); + }; + bar.addEventListener('pointermove', move); + bar.addEventListener('pointerup', end, {once: true}); + bar.addEventListener('pointercancel', end, {once: true}); + move(event); + } + + private layout(): void { + const view = this.trackRef.nativeElement.parentElement; + const picture = (this.trackRef.nativeElement.querySelector('[data-hscroll-anchor]') ?? this.trackRef.nativeElement.firstElementChild) as HTMLElement; + if (view && picture) { + const rect = picture.getBoundingClientRect(); + if (rect.height) { + this.arrowY.set(rect.top + rect.height / 2 - view.getBoundingClientRect().top); + } + } + this.sync(); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.html new file mode 100644 index 0000000000..6c54056848 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.html @@ -0,0 +1,105 @@ + + + + @if (searching()) { + + } @else { + + } + + @if (failed()) { +

{{ 'home.iot-hub.unavailable' | translate }}

+ } @else { +
+ {{ 'home.iot-hub.templates' | translate }} + + @for (tile of templates(); track tile.item.id; let first = $first) { + + } @empty { + @if (!loaded()) { + @for (n of [1, 2, 3, 4]; track n) { + + } + } + } + +
+
+ {{ 'home.iot-hub.device-library' | translate }} + + @for (tile of devices(); track tile.item.id) { + + } + @if (deviceTotal()) { + + } + +
+ } +
+
{{ 'home.iot-hub.also' | translate }}
+ +
+
diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.scss new file mode 100644 index 0000000000..52f4974bc7 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.scss @@ -0,0 +1,361 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +:host { + display: block; + min-width: 0; +} + +.tb-iot-hub-row { + display: flex; + flex-direction: column; + gap: 8px; + min-width: 0; +} + +.tb-iot-hub-row-title { + align-self: flex-start; + font: 500 14px/20px var(--tb-font, Roboto, sans-serif); + letter-spacing: .1px; + color: var(--tb-ink-60, rgba(0, 0, 0, 0.6)); + text-decoration: none; + border-bottom: none; + + &:not(.plain)::after { + content: 'chevron_right'; + display: inline-block; + margin-left: -2px; + font-family: 'Material Icons'; + font-size: 18px; + font-weight: normal; + line-height: 1; + vertical-align: bottom; + color: var(--tb-ink-38, rgba(0, 0, 0, 0.38)); + } + + &:not(.plain):hover, &:not(.plain):focus, &:not(.plain):active { + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + border-bottom: none; + + &::after { + color: inherit; + } + } +} + +.tb-iot-hub-card { + display: flex; + flex-direction: column; + gap: 6px; + width: 224px; + padding: 0; + border: 0; + border-radius: 8px; + background: none; + font: inherit; + text-align: left; + cursor: pointer; + + &:focus-visible { + outline: 2px solid var(--tb-primary-500); + outline-offset: 2px; + } + + &.placeholder { + cursor: default; + + .tb-iot-hub-card-image { + background: rgba(0, 0, 0, 0.04); + } + } +} + +.tb-iot-hub-card-image { + position: relative; + display: flex; + align-items: center; + justify-content: center; + box-sizing: border-box; + width: 100%; + aspect-ratio: 16 / 10; + padding: 14px; + border-radius: 10px; + + img { + display: block; + width: 100%; + height: auto; + border-radius: 4px; + box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 6px 16px rgba(16, 24, 40, 0.14); + transition: transform .2s ease; + } +} + +@media (prefers-reduced-motion: no-preference) { + .tb-iot-hub-card:hover .tb-iot-hub-card-image img { + transform: translateY(-2px); + } +} + +.tb-iot-hub-card-installed.mat-icon { + position: absolute; + top: 8px; + right: 8px; + width: 18px; + height: 18px; + overflow: visible; + font-size: 18px; + color: #10181d; + background: radial-gradient(circle closest-side, #86e8a6 70%, transparent 72%); +} + +.tb-iot-hub-card-label { + display: flex; + flex-direction: column; + align-items: flex-start; + min-width: 0; + padding: 0 2px; +} + +.tb-iot-hub-card-name { + max-width: 100%; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + font: 500 13px/18px var(--tb-font, Roboto, sans-serif); + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); +} + +.tb-iot-hub-card-meta { + font: 400 12px/16px var(--tb-font, Roboto, sans-serif); + color: var(--tb-text-muted, rgba(0, 0, 0, 0.56)); +} + +.tb-iot-hub-device { + display: flex; + align-items: center; + gap: 10px; + box-sizing: border-box; + width: 228px; + padding: 8px 12px 8px 8px; + border: 1px solid var(--tb-line, rgba(0, 0, 0, 0.12)); + border-radius: 8px; + background: none; + font: inherit; + text-align: left; + cursor: pointer; + transition: border-color .15s ease; + + &:hover { + border-color: rgba(0, 0, 0, 0.2); + } + + &:focus-visible { + outline: 2px solid var(--tb-primary-500); + outline-offset: 2px; + } +} + +.tb-iot-hub-device-thumb { + position: relative; + flex: none; + width: 48px; + height: 48px; + overflow: hidden; + border-radius: 6px; + + img { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + object-fit: contain; + background: #fff; + } +} + +.tb-iot-hub-all .tb-iot-hub-device-thumb { + display: inline-flex; + align-items: center; + justify-content: center; + background: rgba(0, 0, 0, 0.04); + color: var(--tb-ink-60, rgba(0, 0, 0, 0.6)); + + .mat-icon { + width: 20px; + height: 20px; + font-size: 20px; + } +} + +.tb-iot-hub-device-text { + display: flex; + flex-direction: column; + min-width: 0; + + b { + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + font: 500 13px/18px var(--tb-font, Roboto, sans-serif); + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + } + + small { + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + font: 400 12px/16px var(--tb-font, Roboto, sans-serif); + color: var(--tb-text-muted, rgba(0, 0, 0, 0.56)); + } +} + +.tb-iot-hub-kinds { + display: flex; + flex-wrap: wrap; + gap: 8px; +} + +.tb-iot-hub-kind { + display: flex; + align-items: center; + gap: 6px; + box-sizing: border-box; + height: 32px; + padding: 0 14px 0 10px; + border: 1px solid var(--tb-line, rgba(0, 0, 0, 0.12)); + border-radius: 16px; + background: var(--tb-surface, #fff); + font: 400 14px/20px var(--tb-font, Roboto, sans-serif); + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); + text-decoration: none; + transition: background-color .15s ease, border-color .15s ease; + + &:hover, &:focus, &:active { + border-bottom: 1px solid var(--tb-line, rgba(0, 0, 0, 0.12)); + } + + &:hover { + background: rgba(0, 0, 0, 0.04); + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + } + + &:focus-visible { + outline: 2px solid var(--tb-primary-500); + outline-offset: 2px; + } + + .mat-icon { + width: 18px; + height: 18px; + font-size: 18px; + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); + } +} + +.tb-iot-hub-unavailable { + margin: 0; + font: 400 14px/20px var(--tb-font, Roboto, sans-serif); + color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6)); +} + +.tb-iot-hub-find.mat-mdc-icon-button.mat-mdc-button-base { + --mdc-icon-button-state-layer-size: 32px; + --mat-icon-button-state-layer-size: 32px; + display: inline-flex; + align-items: center; + justify-content: center; + width: 32px; + height: 32px; + padding: 0; + color: var(--tb-ink-60, rgba(0, 0, 0, 0.6)); + + .mat-icon { + width: 20px; + height: 20px; + font-size: 20px; + } +} + +.tb-iot-hub-search { + display: flex; + flex: 1; + align-items: center; + gap: 4px; + box-sizing: border-box; + min-width: 0; + max-width: 380px; + height: 32px; + padding: 0 2px 0 10px; + border: 1px solid var(--tb-line, rgba(0, 0, 0, 0.12)); + border-radius: 8px; + background: var(--tb-surface, #fff); + + &:focus-within { + border-color: var(--tb-primary-500); + } + + > .mat-icon { + flex: none; + width: 20px; + height: 20px; + font-size: 20px; + color: var(--tb-ink-54, rgba(0, 0, 0, 0.54)); + } + + .tb-search-input { + flex: 1; + min-width: 0; + margin-left: 2px; + padding: 0; + border: 0; + outline: 0; + background: transparent; + font: 400 14px/20px var(--tb-font, Roboto, sans-serif); + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + + &::-webkit-search-cancel-button { + display: none; + } + } + + .mat-mdc-icon-button.mat-mdc-button-base { + --mdc-icon-button-state-layer-size: 28px; + --mat-icon-button-state-layer-size: 28px; + flex: none; + display: inline-flex; + align-items: center; + justify-content: center; + width: 28px; + height: 28px; + padding: 0; + border-radius: 8px; + color: var(--tb-ink-38, rgba(0, 0, 0, 0.38)); + + .mat-icon { + width: 18px; + height: 18px; + font-size: 18px; + line-height: 18px; + } + + &:hover { + background: rgba(0, 0, 0, 0.06); + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); + } + } + + .tb-search-clear { + display: none !important; + } + + &.has-text { + .tb-search-clear { + display: inline-flex !important; + } + + .tb-search-go { + background: var(--tb-primary-500); + color: var(--tb-primary-contrast-500, #fff); + } + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.ts new file mode 100644 index 0000000000..0f9e09f302 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.ts @@ -0,0 +1,198 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component, ElementRef, inject, signal, ViewChild } from '@angular/core'; +import { Router } from '@angular/router'; +import { forkJoin } from 'rxjs'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { HOME_CARDS } from '@home/pages/home-links/home/home-cards.models'; +import { IotHubApiService } from '@core/http/iot-hub-api.service'; +import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; +import { ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; +import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; +import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; +import { Direction, SortOrder } from '@shared/models/page/sort-order'; +import { PageLink } from '@shared/models/page/page-link'; + +const SHOWN = 8; + +const TEMPLATE_TINTS = ['#e0f2f1,#80cbc4', '#e3f2fd,#90caf9', '#fff3e0,#ffcc80', '#f3e5f5,#ce93d8', '#e8f5e9,#a5d6a7', + '#e0f7fa,#80deea', '#fbe9e7,#ffab91', '#ede7f6,#b39ddb']; + +const DEVICE_TINTS = ['#eceff1,#b0bec5', '#fbe9e7,#ffab91', '#e0f7fa,#80deea', '#fffde7,#fff59d', '#efebe9,#bcaaa4', + '#ede7f6,#b39ddb', '#e8f5e9,#a5d6a7', '#e3f2fd,#90caf9']; + +export interface IotHubKind { + type: ItemType; + name: string; + icon: string; + route: string; +} + +const KINDS: IotHubKind[] = [ + {type: ItemType.WIDGET, name: 'home.iot-hub.widgets', icon: 'widgets', route: 'widgets'}, + {type: ItemType.CALCULATED_FIELD, name: 'home.iot-hub.calculated-fields', icon: 'functions', route: 'calculated-fields'}, + {type: ItemType.ALARM_RULE, name: 'home.iot-hub.alarm-rules', icon: 'notification_important', route: 'alarm-rules'}, + {type: ItemType.RULE_CHAIN, name: 'home.iot-hub.rule-chains', icon: 'account_tree', route: 'rule-chains'} +]; + +interface HubTile { + item: MpItemVersionView; + tint: string; + image: string | null; + meta: string; +} + +@Component({ + selector: 'tb-iot-hub-home', + templateUrl: './iot-hub-home.component.html', + styleUrls: ['./iot-hub-home.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class IoTHubHomeComponent { + + readonly card = HOME_CARDS[HomeCardId.IOT_HUB]; + + readonly kinds = KINDS; + + readonly templates = signal([]); + readonly devices = signal([]); + readonly deviceTotal = signal(0); + readonly loaded = signal(false); + readonly failed = signal(false); + readonly searching = signal(false); + readonly query = signal(''); + + @ViewChild('searchInput') searchInput: ElementRef; + @ViewChild('searchOpener', {read: ElementRef}) searchOpener: ElementRef; + + private router = inject(Router); + private api = inject(IotHubApiService); + private actions = inject(IotHubActionsService); + + private installedTemplates: IotHubInstalledItem[] = []; + private installedDeviceCounts: Record = {}; + + constructor() { + this.load(); + } + + isInstalled(item: MpItemVersionView): boolean { + return this.installedTemplates.some(installed => installed.itemId === item.itemId); + } + + open(item: MpItemVersionView): void { + const installed = item.type === ItemType.SOLUTION_TEMPLATE ? this.installedTemplates.find(i => i.itemId === item.itemId) : undefined; + const count = item.type === ItemType.DEVICE ? this.installedDeviceCounts[item.itemId] || 0 : 0; + this.actions.openItemDetail(item, installed, count).subscribe(result => { + if (result === 'installed' || result === 'deleted') { + this.loadInstalled(); + } + }); + } + + browse(route: string): void { + this.router.navigate(['/iot-hub', route]); + } + + openSearch(): void { + this.searching.set(true); + setTimeout(() => this.searchInput?.nativeElement.focus()); + } + + closeSearch(focusOpener = true): void { + this.query.set(''); + this.searching.set(false); + if (focusOpener) { + setTimeout(() => this.searchOpener?.nativeElement.focus()); + } + } + + clearSearch(): void { + this.query.set(''); + this.searchInput?.nativeElement.focus(); + } + + search(): void { + const search = this.query().trim(); + if (search) { + this.router.navigate(['/iot-hub/search'], {queryParams: {search}}); + } else { + this.searchInput?.nativeElement.focus(); + } + } + + onSearchKeydown(event: KeyboardEvent): void { + if (event.key === 'Enter') { + event.preventDefault(); + this.search(); + } else if (event.key === 'Escape') { + event.preventDefault(); + this.closeSearch(); + } + } + + onSearchFocusOut(event: FocusEvent): void { + const field = (event.currentTarget as HTMLElement); + if (!field.contains(event.relatedTarget as Node) && !this.query().trim()) { + this.closeSearch(false); + } + } + + private load(): void { + const config = {ignoreLoading: true, ignoreErrors: true}; + const sortOrder: SortOrder = {property: 'totalInstallCount', direction: Direction.DESC}; + const query = (type: ItemType) => new MpItemVersionQuery(new PageLink(SHOWN, 0, null, sortOrder), {type}); + forkJoin({ + templates: this.api.getPublishedVersions(query(ItemType.SOLUTION_TEMPLATE), config), + devices: this.api.getPublishedVersions(query(ItemType.DEVICE), config) + }).subscribe({ + next: ({templates, devices}) => { + this.templates.set(templates.data.map((item, i) => this.tile(item, TEMPLATE_TINTS[i % TEMPLATE_TINTS.length], item.useCases?.[0] ?? ''))); + this.devices.set(devices.data.map((item, i) => this.tile(item, DEVICE_TINTS[i % DEVICE_TINTS.length], this.deviceMeta(item)))); + this.deviceTotal.set(devices.totalElements); + this.loaded.set(true); + }, + error: () => { + this.failed.set(true); + this.loaded.set(true); + } + }); + this.loadInstalled(); + } + + private loadInstalled(): void { + const config = {ignoreLoading: true, ignoreErrors: true}; + forkJoin({ + templates: this.api.getInstalledItems(new PageLink(10000, 0), ItemType.SOLUTION_TEMPLATE, undefined, config), + deviceCounts: this.api.getInstalledItemCounts(ItemType.DEVICE, config) + }).subscribe({ + next: ({templates, deviceCounts}) => { + this.installedTemplates = templates.data; + this.installedDeviceCounts = deviceCounts; + this.templates.update(tiles => [...tiles]); + }, + error: () => {} + }); + } + + private tile(item: MpItemVersionView, tint: string, meta: string): HubTile { + return {item, tint: `linear-gradient(135deg, ${tint})`, image: this.preview(item), meta}; + } + + private deviceMeta(item: MpItemVersionView): string { + const vendor = item.dataDescriptor?.vendor; + const connectivity: string[] = item.dataDescriptor?.connectivity ?? []; + const via = item.dataDescriptor?.hardwareType === 'Gateway' ? 'Gateway' : connectivity[connectivity.length - 1]; + return [vendor, via].filter(Boolean).join(' · '); + } + + private preview(item: MpItemVersionView): string | null { + if (!item.image) { + return null; + } + const [path, params] = item.image.split('?'); + const withPreview = path.endsWith('/preview') ? path : `${path}/preview`; + return this.api.resolveResourceUrl(params ? `${withPreview}?${params}` : withPreview); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/mobile-app-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/mobile-app-home.component.ts new file mode 100644 index 0000000000..1279f75a75 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/mobile-app-home.component.ts @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { HOME_CARDS } from '@home/pages/home-links/home/home-cards.models'; + +@Component({ + selector: 'tb-mobile-app-home', + template: ``, + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class MobileAppHomeComponent { + + readonly card = HOME_CARDS[HomeCardId.MOBILE_APP]; +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/notifications-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/notifications-home.component.ts new file mode 100644 index 0000000000..f0087d9cc1 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/notifications-home.component.ts @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { HOME_CARDS } from '@home/pages/home-links/home/home-cards.models'; + +@Component({ + selector: 'tb-notifications-home', + template: ``, + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class NotificationsHomeComponent { + + readonly card = HOME_CARDS[HomeCardId.NOTIFICATIONS]; +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/quick-links-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/quick-links-home.component.ts new file mode 100644 index 0000000000..c8e614aad4 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/quick-links-home.component.ts @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { HOME_CARDS } from '@home/pages/home-links/home/home-cards.models'; + +@Component({ + selector: 'tb-quick-links-home', + template: ``, + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class QuickLinksHomeComponent { + + readonly card = HOME_CARDS[HomeCardId.QUICK_LINKS]; +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.scss new file mode 100644 index 0000000000..d78ca2a89c --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.scss @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +:host { + display: block; +} + +.tb-status-line { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 6px 8px; + margin-top: 12px; + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); +} + +.tb-pill { + display: inline-flex; + align-items: center; + gap: 8px; + height: 32px; + padding: 0 14px; + border-radius: 16px; + background: var(--tb-surface, #fff); + box-shadow: var(--tb-home-card-shadow); + font: 400 14px/20px var(--tb-font, Roboto, sans-serif); + letter-spacing: 0; + white-space: nowrap; + transition: box-shadow .15s ease; + + &:has(.tb-status-link:hover) { + box-shadow: var(--tb-home-card-shadow), 0 4px 12px -4px rgba(20, 52, 58, 0.14); + } +} + +.tb-status-link { + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + text-decoration: none; + border-bottom: none; + + &:hover, &:focus, &:active { + border-bottom: none; + } + + &:hover { + text-decoration: underline; + } + + &:focus-visible { + outline: 2px solid var(--tb-primary-500); + outline-offset: 2px; + border-radius: 4px; + } +} + +.tb-status-dot { + flex: none; + width: 8px; + height: 8px; + border-radius: 50%; + background: var(--tb-ink-38, rgba(0, 0, 0, 0.38)); +} + +.warn .tb-status-dot { + background: rgb(246, 103, 22); +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.ts new file mode 100644 index 0000000000..5d40dfa850 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.ts @@ -0,0 +1,157 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, NgZone, signal, WritableSignal } from '@angular/core'; +import { Router } from '@angular/router'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { getCurrentAuthUser, selectPersistDeviceStateToTelemetry } from '@core/auth/auth.selectors'; +import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service'; +import { AlarmCountCmd, EntityCountCmd, TelemetrySubscriber } from '@shared/models/telemetry/telemetry.models'; +import { AliasFilterType } from '@shared/models/alias.models'; +import { EntityType } from '@shared/models/entity-type.models'; +import { EntityKeyType, EntityKeyValueType, FilterPredicateType, BooleanOperation, KeyFilter } from '@shared/models/query/query.models'; +import { AlarmSearchStatus, AlarmSeverity } from '@shared/models/alarm.models'; +import { Authority } from '@shared/models/authority.enum'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { take } from 'rxjs/operators'; + +type StatusKind = 'crit' | 'warn' | 'ok'; + +interface StatusPart { + key: string; + params?: Record; + card?: HomeCardId; + link?: string; +} + +@Component({ + selector: 'tb-status-line-home', + template: ` + @if (parts().length) { +
+ @for (part of parts(); track part.key; let first = $first) { + + @if (first) { + @if (kind() === 'crit') { + + } @else { + + } + } + @if (part.link) { + {{ part.key | translate: part.params }} + } @else { + {{ part.key | translate: part.params }} + } + + } +
+ } + `, + styleUrls: ['./status-line-home.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class StatusLineHomeComponent { + + private telemetryWsService = inject(TelemetryWebsocketService); + private zone = inject(NgZone); + private router = inject(Router); + private store = inject(Store); + + private readonly customer = getCurrentAuthUser(this.store)?.authority === Authority.CUSTOMER_USER; + + private critical = signal(null); + private active = signal(null); + private devices = signal(null); + private inactive = signal(null); + + private subscribers: TelemetrySubscriber[] = []; + + readonly parts = computed(() => { + const critical = this.critical(); + const active = this.active(); + const devices = this.devices(); + const inactive = this.inactive(); + if (critical === null || active === null || devices === null || inactive === null) { + return []; + } + if (!devices) { + return this.customer ? [{key: 'home.status.nothing-assigned'}] : []; + } + const parts: StatusPart[] = []; + if (critical) { + parts.push({key: 'home.status.critical-alarms', params: {count: critical}, card: HomeCardId.ALARMS, link: '/alarms'}); + } else if (active) { + parts.push({key: 'home.status.active-alarms', params: {count: active}, card: HomeCardId.ALARMS, link: '/alarms'}); + } else { + parts.push({key: 'home.status.no-alarms'}); + } + if (inactive) { + parts.push({key: 'home.status.inactive-devices', params: {count: inactive}, card: HomeCardId.DEVICES, link: '/entities/devices'}); + } else { + parts.push({key: devices === 1 ? 'home.status.device-active' : 'home.status.all-devices-active', params: {count: devices}}); + } + return parts; + }); + + readonly kind = computed(() => this.critical() ? 'crit' : this.inactive() ? 'warn' : 'ok'); + + constructor() { + this.store.select(selectPersistDeviceStateToTelemetry).pipe(take(1)).subscribe(persisted => { + const activeKeyType = persisted ? EntityKeyType.TIME_SERIES : EntityKeyType.SERVER_ATTRIBUTE; + this.countAlarms(this.critical, [AlarmSeverity.CRITICAL]); + this.countAlarms(this.active); + this.countDevices(this.devices); + this.countDevices(this.inactive, [{ + key: {type: activeKeyType, key: 'active'}, + valueType: EntityKeyValueType.BOOLEAN, + predicate: { + type: FilterPredicateType.BOOLEAN, + operation: BooleanOperation.EQUAL, + value: {defaultValue: false} + } + }]); + }); + inject(DestroyRef).onDestroy(() => this.subscribers.forEach(subscriber => subscriber.unsubscribe())); + } + + open(part: StatusPart): void { + const card = part.card ? document.querySelector(`[data-home-card="${part.card}"]`) : null; + if (card) { + card.scrollIntoView({behavior: 'smooth', block: 'center'}); + } else if (part.link) { + this.router.navigateByUrl(part.link); + } + } + + private countAlarms(target: WritableSignal, severityList?: AlarmSeverity[]): void { + const cmd = new AlarmCountCmd(); + cmd.query = { + entityFilter: null, + statusList: [AlarmSearchStatus.ACTIVE], + ...(severityList ? {severityList} : {}) + }; + const subscriber = this.subscribe(cmd); + subscriber.alarmCount$.subscribe(update => target.set(update.count ?? 0)); + subscriber.subscribe(); + } + + private countDevices(target: WritableSignal, keyFilters?: KeyFilter[]): void { + const cmd = new EntityCountCmd(); + cmd.query = { + entityFilter: {type: AliasFilterType.entityType, entityType: EntityType.DEVICE}, + keyFilters + }; + const subscriber = this.subscribe(cmd); + subscriber.entityCount$.subscribe(update => target.set(update.count ?? 0)); + subscriber.subscribe(); + } + + private subscribe(cmd: AlarmCountCmd | EntityCountCmd): TelemetrySubscriber { + const subscriber = new TelemetrySubscriber(this.telemetryWsService, this.zone); + subscriber.subscriptionCommands.push(cmd); + this.subscribers.push(subscriber); + return subscriber; + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.scss new file mode 100644 index 0000000000..91b748ebaf --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.scss @@ -0,0 +1,72 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +:host { + display: block; + min-width: 0; +} + +.tb-ai-attn-block { + margin-top: 12px; + container-type: inline-size; +} + +.tb-ai-attn-h { + margin: 0 2px 6px; + font: 500 14px/20px var(--tb-font, Roboto, sans-serif); + letter-spacing: .1px; + color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); +} + +.tb-ai-attn { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 8px; +} + +.tb-chat-pill { + &:hover, &:focus, &:active { + border-bottom: none; + } + + display: inline-flex; + align-items: center; + gap: 8px; + box-sizing: border-box; + height: 40px; + max-width: 300px; + padding: 0 14px 0 12px; + border-radius: 12px; + background: var(--tb-surface, #fff); + box-shadow: var(--tb-home-card-shadow); + font: 500 14px/20px var(--tb-font, Roboto, sans-serif); + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + text-decoration: none; + border-bottom: none; + transition: box-shadow .15s ease; + + &:hover, &:focus-visible { + outline: 0; + box-shadow: var(--tb-home-card-shadow), 0 4px 12px -4px rgba(20, 52, 58, 0.14); + } +} + +.tb-chat-pill-t { + flex: 0 1 auto; + min-width: 0; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; +} + +@container (max-width: 560px) { + .tb-ai-attn { + flex-direction: column; + align-items: stretch; + } + + .tb-chat-pill { + width: 100%; + max-width: none; + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.ts new file mode 100644 index 0000000000..ba67ce3686 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.ts @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core'; +import { AiChatsService } from '@core/services/ai-chats.service'; + +const SHOWN = 2; + +@Component({ + selector: 'tb-waiting-ai-chats-home', + template: ` + @if (waiting().length) { +
+
{{ 'home.ai.waiting' | translate }}
+
+ @for (chat of shown(); track chat.id) { + + + {{ chat.title || ('ai-assistant.new-chat' | translate) }} + + } +
+
+ } + `, + styleUrls: ['./waiting-ai-chats-home.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class WaitingAIChatsHomeComponent { + + readonly chats = inject(AiChatsService); + + readonly waiting = computed(() => this.chats.statusChats().filter(chat => this.chats.needsAttention(chat)) + .sort((a, b) => (this.chats.levelOf(a) === 'error' ? 0 : 1) - (this.chats.levelOf(b) === 'error' ? 0 : 1))); + + readonly shown = computed(() => this.waiting().slice(0, SHOWN)); + + constructor() { + this.chats.watchStatus(); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.scss new file mode 100644 index 0000000000..19f67cd243 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.scss @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +:host { + display: block; + min-width: 0; +} + +.tb-home-kicker { + margin: 0 0 4px; + font: 500 12px/16px var(--tb-font, Roboto, sans-serif); + letter-spacing: .5px; + text-transform: uppercase; + color: var(--tb-ink-54, rgba(0, 0, 0, 0.54)); +} + +.tb-greeting { + margin: 0; + font: 600 28px/36px var(--tb-font, Roboto, sans-serif); + letter-spacing: -0.2px; + color: var(--tb-ink, rgba(0, 0, 0, 0.87)); + + &.with-spark { + display: flex; + align-items: center; + gap: 10px; + } +} + +.tb-greeting .tb-greet-spark { + --m: 44px; + --ai-mark-ink-a: color-mix(in oklab, var(--tb-primary-500) 50%, var(--ai-mark-ink-c)); + --ai-mark-ink-b: color-mix(in oklab, var(--tb-primary-500) 20%, var(--ai-mark-ink-c)); + width: calc(var(--m) * var(--ai-spark)); + height: calc(var(--m) * var(--ai-spark)); + border-radius: 0; + background: none; + box-shadow: none; + animation: none; +} + +@media (max-width: 959px) { + .tb-greeting .tb-greet-spark { + --m: 34px; + } + + .tb-greeting.with-spark { + gap: 8px; + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.ts new file mode 100644 index 0000000000..25a2900df2 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.ts @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component, inject, input } from '@angular/core'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { getCurrentAuthState } from '@core/auth/auth.selectors'; + +@Component({ + selector: 'tb-welcome-home', + template: ` +
{{ today | date: 'EEEE d MMMM' }}
+

+ @if (spark()) { + + } + {{ (name ? 'home.greeting.' + daypart + '-name' : 'home.greeting.' + daypart) | translate: {name} }} +

+ `, + styleUrls: ['./welcome-home.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class WelcomeHomeComponent { + + spark = input(false); + + readonly today = new Date(); + + readonly daypart = this.today.getHours() < 12 ? 'morning' : this.today.getHours() < 18 ? 'afternoon' : 'evening'; + + readonly name = (() => { + const auth = getCurrentAuthState(inject(Store)); + return (auth?.userDetails?.firstName || auth?.authUser?.firstName || '').trim().split(/\s+/)[0] || null; + })(); +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/home-cards.models.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/home-cards.models.ts new file mode 100644 index 0000000000..e1755afc30 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/home-cards.models.ts @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { HomeCardId, HomeCardsSettings } from '@shared/models/user-settings.models'; + +export interface HomeCardDefinition { + id: HomeCardId; + icon: string; + name: string; + link?: string; + height: number; +} + +export const HOME_CARDS: Record = { + [HomeCardId.IOT_HUB]: {id: HomeCardId.IOT_HUB, icon: 'hub', name: 'home.cards.iot-hub', link: '/iot-hub', height: 500}, + [HomeCardId.ALARMS]: {id: HomeCardId.ALARMS, icon: 'warning', name: 'home.cards.alarms', link: '/alarms', height: 430}, + [HomeCardId.DASHBOARDS]: {id: HomeCardId.DASHBOARDS, icon: 'dashboard', name: 'home.cards.dashboards', link: '/dashboards', height: 357}, + [HomeCardId.DEVICES]: {id: HomeCardId.DEVICES, icon: 'memory', name: 'home.cards.devices', link: '/entities/devices', height: 430}, + [HomeCardId.ACTIVITY]: {id: HomeCardId.ACTIVITY, icon: 'show_chart', name: 'home.cards.activity', height: 250}, + [HomeCardId.GET_STARTED]: {id: HomeCardId.GET_STARTED, icon: 'rocket_launch', name: 'home.cards.get-started', height: 405}, + [HomeCardId.NOTIFICATIONS]: {id: HomeCardId.NOTIFICATIONS, icon: 'notifications', name: 'home.cards.notifications', + link: '/notification/inbox', height: 525}, + [HomeCardId.QUICK_LINKS]: {id: HomeCardId.QUICK_LINKS, icon: 'link', name: 'home.cards.quick-links', height: 205}, + [HomeCardId.USAGE]: {id: HomeCardId.USAGE, icon: 'data_usage', name: 'home.cards.usage', link: '/usage', height: 232}, + [HomeCardId.MOBILE_APP]: {id: HomeCardId.MOBILE_APP, icon: 'phone_iphone', name: 'home.cards.mobile-app', height: 225} +}; + +export const isHomeCardShown = (settings: HomeCardsSettings, id: HomeCardId): boolean => settings?.[id] !== false; diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/pages/customer-user-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/customer-user-home.component.ts new file mode 100644 index 0000000000..d8797e0e63 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/customer-user-home.component.ts @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component } from '@angular/core'; + +@Component({ + selector: 'tb-customer-user-home', + template: ` +
+
+ + +
+
+ `, + styleUrls: ['./tenant-admin-home.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class CustomerUserHomeComponent { +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.scss new file mode 100644 index 0000000000..33cb168644 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.scss @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +:host { + --tb-home-page: #f4f6f7; + --tb-home-ai-glow: oklch(0.80 0.11 182); + --tb-home-card-shadow: 0 1px 1px rgba(20, 52, 58, 0.06), 0 2px 6px -1px rgba(20, 52, 58, 0.08); + position: relative; + isolation: isolate; + display: block; + min-height: 100%; + box-sizing: border-box; + container: tb-home / inline-size; + background-color: var(--tb-home-page); + background-image: + radial-gradient(1300px 560px at 16% -120px, color-mix(in oklab, var(--tb-home-ai-glow) 34%, var(--tb-home-page)) 0%, + color-mix(in oklab, var(--tb-home-ai-glow) 12%, var(--tb-home-page)) 42%, var(--tb-home-page) 78%), + linear-gradient(180deg, #eaedef 0px, var(--tb-home-page) 360px); + background-repeat: no-repeat; +} + +.tb-home-sky { + position: absolute; + top: 0; + left: 0; + right: 0; + z-index: -1; + height: 600px; + overflow: hidden; + pointer-events: none; + background: var(--ai-field-wash); + -webkit-mask-image: linear-gradient(180deg, #000 0, #000 200px, transparent 100%); + mask-image: linear-gradient(180deg, #000 0, #000 200px, transparent 100%); + animation: tb-home-sky-in 1.2s cubic-bezier(.4, 0, .2, 1); + + @media (prefers-reduced-motion: reduce) { + animation: none; + } +} + +@keyframes tb-home-sky-in { + from { + opacity: 0; + } +} + +@supports (color: oklch(from red l c h)) { + :host(.tenant-brand) { + --tb-home-tenant-glow: oklch(from var(--tb-primary-500) 0.80 min(c, 0.11) h); + background-image: + radial-gradient(820px 520px at 6% -120px, color-mix(in oklab, var(--tb-home-tenant-glow) 34%, transparent) 0%, + color-mix(in oklab, var(--tb-home-tenant-glow) 12%, transparent) 42%, transparent 78%), + radial-gradient(900px 520px at 80% -140px, color-mix(in oklab, var(--tb-home-ai-glow) 34%, transparent) 0%, + color-mix(in oklab, var(--tb-home-ai-glow) 12%, transparent) 42%, transparent 78%), + linear-gradient(180deg, #eaedef 0px, var(--tb-home-page) 360px); + } + + :host(.tenant-brand) .tb-home-sky { + --tb-home-sky-field: oklch(from var(--tb-primary-500) 0.86 min(c, 0.08) h); + --tb-home-sky-soft: oklch(from var(--tb-primary-500) 0.89 min(c, 0.05) h); + background: + radial-gradient(46% 80% at 41% 24%, color-mix(in oklab, var(--ai-light-lilac) calc(var(--ai-w-lilac) * .87), transparent), transparent 72%), + radial-gradient(70% 88% at 14% 2%, color-mix(in oklab, var(--tb-home-sky-field) calc(var(--ai-w-teal) * .87), transparent), transparent 70%), + radial-gradient(72% 82% at 66% 0%, color-mix(in oklab, var(--ai-light-teal) calc(var(--ai-w-teal) * .87), transparent), transparent 70%), + radial-gradient(44% 56% at 2% 96%, color-mix(in oklab, var(--tb-home-sky-soft) calc(var(--ai-w-mint) * .87), transparent), transparent 70%), + radial-gradient(45% 60% at 100% 100%, color-mix(in oklab, var(--ai-light-peach) calc(var(--ai-w-peach) * .87), transparent), transparent 70%), + radial-gradient(50% 70% at 100% 52%, color-mix(in oklab, var(--ai-light-amber) calc(var(--ai-w-amber) * .87), transparent), transparent 70%), + var(--ai-light-paper); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.ts new file mode 100644 index 0000000000..4565a37d04 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.ts @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { getCurrentAuthUser } from '@core/auth/auth.selectors'; +import { Authority } from '@shared/models/authority.enum'; +import { TourService } from '@core/services/tour.service'; + +const DEFAULT_PRIMARY = '#00695c'; + +@Component({ + selector: 'tb-home-page', + template: ` + @if (aiSky) { + + } + @switch (authority) { + @case (Authority.SYS_ADMIN) { + + } + @case (Authority.TENANT_ADMIN) { + + } + @case (Authority.CUSTOMER_USER) { + + } + } + `, + styleUrls: ['./home-page.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush, + host: { + '[class.tenant-brand]': 'tenantBrand' + } +}) +export class HomePageComponent { + + readonly Authority = Authority; + + readonly authority = getCurrentAuthUser(inject(Store))?.authority; + + readonly aiSky = inject(TourService).aiAvailable(); + + readonly tenantBrand = getComputedStyle(document.body).getPropertyValue('--tb-primary-500') + .trim().toLowerCase() !== DEFAULT_PRIMARY; +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/pages/sys-admin-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/sys-admin-home.component.ts new file mode 100644 index 0000000000..3d142261a1 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/sys-admin-home.component.ts @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component } from '@angular/core'; + +@Component({ + selector: 'tb-sys-admin-home', + template: ` +
+
+ +
+
+ `, + styleUrls: ['./tenant-admin-home.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class SysAdminHomeComponent { +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.html b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.html new file mode 100644 index 0000000000..d222af52db --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.html @@ -0,0 +1,65 @@ + + + @switch (id) { + @case (HomeCardId.IOT_HUB) { + + } + @case (HomeCardId.ALARMS) { + + } + @case (HomeCardId.DASHBOARDS) { + + } + @case (HomeCardId.DEVICES) { + + } + @case (HomeCardId.ACTIVITY) { + + } + @case (HomeCardId.GET_STARTED) { + + } + @case (HomeCardId.NOTIFICATIONS) { + + } + @case (HomeCardId.QUICK_LINKS) { + + } + @case (HomeCardId.USAGE) { + + } + @case (HomeCardId.MOBILE_APP) { + + } + } + +
+
+ + +
+
+ @if (aiAvailable) { +
+ + +
+ } +
+ @for (id of mainCards(); track id) { + + } +
+
+ @for (id of sideCards(); track id) { + + } +
+
+ +
diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.scss new file mode 100644 index 0000000000..8713f6fc7c --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.scss @@ -0,0 +1,99 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +:host { + display: block; +} + +.tb-home { + display: flex; + flex-direction: column; + gap: 16px; + box-sizing: border-box; + max-width: 1200px; + margin: 0 auto; + padding: 16px 24px 48px; +} + +.tb-home-head { + padding: 28px 0 12px; +} + +.tb-home-grid { + display: grid; + grid-template-columns: minmax(0, 1fr); + gap: 16px; + align-items: start; +} + +.tb-col { + display: flex; + flex-direction: column; + gap: 16px; + min-width: 0; +} + +.tb-grid-hero { + --tb-home-compose-width: 760px; + min-width: 0; +} + +@media (min-width: 960px) { + @container tb-home (min-width: 808px) { + .tb-home-grid { + grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); + } + + .tb-home-grid.with-hero { + > .tb-grid-hero { + --tb-home-compose-width: min(760px, calc((min(100cqw, 1200px) - 64px) * 2 / 3)); + grid-column: 1 / -1; + grid-row: 1; + max-width: 760px; + } + + > .tb-col-main { + grid-column: 1; + grid-row: 2; + } + + > .tb-col-side { + grid-column: 2; + grid-row: 2; + } + } + } + + @container tb-home (min-width: 1024px) { + .tb-home-grid.with-hero { + grid-template-rows: auto 1fr; + + > .tb-grid-hero { + --tb-home-compose-width: min(760px, calc(100% - 48px)); + grid-column: 1; + max-width: none; + } + + > .tb-col-side { + grid-row: 1 / span 2; + } + } + } +} + +@media (min-width: 1920px) { + .tb-home { + max-width: 1440px; + } + + @container tb-home (min-width: 808px) { + .tb-home-grid { + grid-template-columns: minmax(0, 1fr) 400px; + } + } +} + +@media (max-width: 599px) { + .tb-home { + padding: 8px 12px 32px; + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.ts new file mode 100644 index 0000000000..a7efe4bab4 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.ts @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core'; +import { toSignal } from '@angular/core/rxjs-interop'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { selectHomeCards } from '@core/auth/auth.selectors'; +import { TourService } from '@core/services/tour.service'; +import { HomeCardId } from '@shared/models/user-settings.models'; +import { isHomeCardShown } from '@home/pages/home-links/home/home-cards.models'; + +const MAIN_CARDS = [HomeCardId.IOT_HUB, HomeCardId.ALARMS, HomeCardId.DASHBOARDS, HomeCardId.DEVICES, HomeCardId.ACTIVITY]; +const SIDE_CARDS = [HomeCardId.GET_STARTED, HomeCardId.NOTIFICATIONS, HomeCardId.QUICK_LINKS, HomeCardId.USAGE, HomeCardId.MOBILE_APP]; + +@Component({ + selector: 'tb-tenant-admin-home', + templateUrl: './tenant-admin-home.component.html', + styleUrls: ['./tenant-admin-home.component.scss'], + standalone: false, + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class TenantAdminHomeComponent { + + readonly HomeCardId = HomeCardId; + + readonly cards = [...MAIN_CARDS, ...SIDE_CARDS]; + + readonly aiAvailable = inject(TourService).aiAvailable(); + + private settings = toSignal(inject(Store).select(selectHomeCards), {initialValue: {}}); + + readonly mainCards = computed(() => MAIN_CARDS.filter(id => isHomeCardShown(this.settings(), id))); + + readonly sideCards = computed(() => SIDE_CARDS.filter(id => isHomeCardShown(this.settings(), id))); +} diff --git a/ui-ngx/src/app/shared/models/user-settings.models.ts b/ui-ngx/src/app/shared/models/user-settings.models.ts index 8b10bd9d40..a38c899eee 100644 --- a/ui-ngx/src/app/shared/models/user-settings.models.ts +++ b/ui-ngx/src/app/shared/models/user-settings.models.ts @@ -13,6 +13,7 @@ export interface UserSettings { includeResourcesInExportDashboard?: boolean; isSolutionSidebarExpanded?: boolean; aiTour?: AiTourSettings; + homeCards?: HomeCardsSettings; } export enum AiTourStep { @@ -24,6 +25,21 @@ export enum AiTourStep { export type AiTourSettings = Partial>; +export enum HomeCardId { + IOT_HUB = 'iotHub', + ALARMS = 'alarms', + DASHBOARDS = 'dashboards', + DEVICES = 'devices', + ACTIVITY = 'activity', + GET_STARTED = 'getStarted', + NOTIFICATIONS = 'notifications', + QUICK_LINKS = 'quickLinks', + USAGE = 'usage', + MOBILE_APP = 'mobileApp' +} + +export type HomeCardsSettings = Partial>; + export const initialUserSettings: UserSettings = { openedMenuSections: [] }; 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 3c8e37e281..1be26c95ef 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -8525,6 +8525,62 @@ "show-help": "Show help" }, "home": { + "iot-hub": { + "search": "Search IoT Hub", + "open-results": "Open results in IoT Hub", + "all-devices": "All {{count}} devices", + "also": "Also in IoT Hub", + "unavailable": "IoT Hub is not available right now.", + "templates": "Solution templates", + "device-library": "Device library", + "widgets": "Widgets", + "calculated-fields": "Calculated fields", + "alarm-rules": "Alarm rules", + "rule-chains": "Rule chains" + }, + "status": { + "critical-alarms": "{ count, plural, =1 {1 critical alarm} other {# critical alarms} }", + "active-alarms": "{ count, plural, =1 {1 active alarm, none critical} other {# active alarms, none critical} }", + "no-alarms": "No active alarms", + "inactive-devices": "{ count, plural, =1 {1 device inactive} other {# devices inactive} }", + "device-active": "Device active", + "all-devices-active": "All {{count}} devices active", + "nothing-assigned": "No devices or dashboards assigned to you yet" + }, + "greeting": { + "morning": "Good morning", + "afternoon": "Good afternoon", + "evening": "Good evening", + "morning-name": "Good morning, {{name}}", + "afternoon-name": "Good afternoon, {{name}}", + "evening-name": "Good evening, {{name}}" + }, + "cards": { + "iot-hub": "IoT Hub", + "alarms": "Alarms", + "dashboards": "Dashboards", + "devices": "Devices", + "activity": "Activity", + "get-started": "Get started", + "notifications": "Notifications", + "quick-links": "Quick links", + "usage": "Usage", + "mobile-app": "Mobile app" + }, + "ai": { + "placeholder": "Ask the AI Assistant…", + "chats": "Chats", + "waiting": "Waiting for you" + }, + "customize": { + "title": "Customize Home", + "show-on-home": "Show on Home", + "show-all": "Show all", + "cards": "Cards on Home", + "hide": "Hide {{name}}", + "hidden": "{{name}} hidden", + "undo": "Undo" + }, "home": "Home", "profile": "Profile", "logout": "Logout",