Browse Source

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

pull/16848/head
Igor Kulikov 2 weeks ago
parent
commit
8bbbc3e3e4
  1. 11
      ui-ngx/src/app/core/auth/auth.actions.ts
  2. 8
      ui-ngx/src/app/core/auth/auth.effects.ts
  3. 4
      ui-ngx/src/app/core/auth/auth.reducer.ts
  4. 5
      ui-ngx/src/app/core/auth/auth.selectors.ts
  5. 20
      ui-ngx/src/app/core/services/ai-assistant-panel.service.ts
  6. 7
      ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html
  7. 96
      ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.scss
  8. 7
      ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.ts
  9. 7
      ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.ts
  10. 3
      ui-ngx/src/app/modules/home/pages/home-links/home-links-routing.module.ts
  11. 24
      ui-ngx/src/app/modules/home/pages/home-links/home-links.component.html
  12. 56
      ui-ngx/src/app/modules/home/pages/home-links/home-links.component.scss
  13. 52
      ui-ngx/src/app/modules/home/pages/home-links/home-links.component.ts
  14. 52
      ui-ngx/src/app/modules/home/pages/home-links/home-links.module.ts
  15. 97
      ui-ngx/src/app/modules/home/pages/home-links/home/components/ai-assistant-home.component.scss
  16. 55
      ui-ngx/src/app/modules/home/pages/home-links/home/components/ai-assistant-home.component.ts
  17. 16
      ui-ngx/src/app/modules/home/pages/home-links/home/components/alarms-home.component.ts
  18. 16
      ui-ngx/src/app/modules/home/pages/home-links/home/components/api-usage-home.component.ts
  19. 73
      ui-ngx/src/app/modules/home/pages/home-links/home/components/customize-home-dialog.component.scss
  20. 65
      ui-ngx/src/app/modules/home/pages/home-links/home/components/customize-home-dialog.component.ts
  21. 16
      ui-ngx/src/app/modules/home/pages/home-links/home/components/dashboards-home.component.ts
  22. 16
      ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-activity-home.component.ts
  23. 16
      ui-ngx/src/app/modules/home/pages/home-links/home/components/devices-home.component.ts
  24. 16
      ui-ngx/src/app/modules/home/pages/home-links/home/components/get-started-home.component.ts
  25. 152
      ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.scss
  26. 70
      ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts
  27. 70
      ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.scss
  28. 65
      ui-ngx/src/app/modules/home/pages/home-links/home/components/home-cards-footer.component.ts
  29. 166
      ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.scss
  30. 133
      ui-ngx/src/app/modules/home/pages/home-links/home/components/home-hscroll.component.ts
  31. 105
      ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.html
  32. 361
      ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.scss
  33. 198
      ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.ts
  34. 16
      ui-ngx/src/app/modules/home/pages/home-links/home/components/mobile-app-home.component.ts
  35. 16
      ui-ngx/src/app/modules/home/pages/home-links/home/components/notifications-home.component.ts
  36. 16
      ui-ngx/src/app/modules/home/pages/home-links/home/components/quick-links-home.component.ts
  37. 65
      ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.scss
  38. 157
      ui-ngx/src/app/modules/home/pages/home-links/home/components/status-line-home.component.ts
  39. 72
      ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.scss
  40. 42
      ui-ngx/src/app/modules/home/pages/home-links/home/components/waiting-ai-chats-home.component.ts
  41. 49
      ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.scss
  42. 35
      ui-ngx/src/app/modules/home/pages/home-links/home/components/welcome-home.component.ts
  43. 27
      ui-ngx/src/app/modules/home/pages/home-links/home/home-cards.models.ts
  44. 20
      ui-ngx/src/app/modules/home/pages/home-links/home/pages/customer-user-home.component.ts
  45. 69
      ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.scss
  46. 47
      ui-ngx/src/app/modules/home/pages/home-links/home/pages/home-page.component.ts
  47. 19
      ui-ngx/src/app/modules/home/pages/home-links/home/pages/sys-admin-home.component.ts
  48. 65
      ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.html
  49. 99
      ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.scss
  50. 35
      ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.ts
  51. 16
      ui-ngx/src/app/shared/models/user-settings.models.ts
  52. 56
      ui-ngx/src/assets/locale/locale.constant-en_US.json

11
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;

8
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,

4
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 }};

5
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<AppState>): AuthState => {
let state: AuthState;
store.pipe(select(selectAuth), take(1)).subscribe(

20
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()};
}

7
ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.html

@ -4,7 +4,7 @@
SPDX-License-Identifier: BUSL-1.1
-->
<div class="tb-ai-composer" [class.docked]="docked" [class.drop]="dragging()" [class.has-text]="hasText()">
<div class="tb-ai-composer" [class.docked]="docked" [class.slim]="slim" [class.drop]="dragging()" [class.has-text]="hasText()">
@if (attachEnabled()) {
<input #fileInput type="file" hidden multiple [accept]="accept()" (change)="onFilesPicked($event)">
}
@ -57,7 +57,7 @@
<span id="composer-suggestion" class="tb-ai-sr-only">{{ 'ai-assistant.suggestion-sr' | translate: {text: suggestion} }}</span>
}
<textarea #textarea
rows="2"
[rows]="slim ? 1 : 2"
spellcheck="false"
[attr.aria-label]="'ai-assistant.ask-the-assistant' | translate"
[attr.aria-describedby]="suggestion && !hasText() ? 'composer-suggestion' : null"
@ -66,6 +66,9 @@
(input)="onInput()"
(paste)="onPaste($event)"
(keydown)="onKeydown($event)"></textarea>
@if (slim) {
<kbd class="composer-slash" aria-hidden="true">/</kbd>
}
<span class="composer-send-slot">
@if (canStop) {
<button type="button" class="composer-send composer-stop"

96
ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.scss

@ -650,3 +650,99 @@ $chevron: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox=
opacity: 1;
}
}
.tb-ai-composer.slim {
.composer-field {
border-radius: 12px;
&:not(:focus-within) {
border-color: transparent;
box-shadow: var(--tb-home-card-shadow, 0 1px 1px rgba(20, 52, 58, 0.06), 0 2px 6px -1px rgba(20, 52, 58, 0.08));
}
}
.composer-row {
padding-bottom: 12px;
transition: padding .24s ease;
}
textarea {
min-height: 24px;
transition: min-height .24s cubic-bezier(.2, .7, .2, 1);
}
.composer-foot {
max-height: 0;
padding-top: 0;
padding-bottom: 0;
border-top-width: 0;
opacity: 0;
overflow: clip;
transition: max-height .24s cubic-bezier(.2, .7, .2, 1), padding .24s cubic-bezier(.2, .7, .2, 1), opacity .18s ease;
}
.composer-slash {
position: absolute;
top: 50%;
right: 19px;
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-width: 22px;
height: 22px;
padding: 0 6px;
border: 1px solid var(--tb-line);
border-bottom-width: 2px;
border-radius: 6px;
background: var(--tb-surface);
color: var(--tb-ink-54);
font: 500 12px/1 var(--tb-font);
pointer-events: none;
transform: translateY(-50%);
}
&:not(:focus-within):not(.has-text) .composer-send-slot {
visibility: hidden;
}
&:is(:focus-within, .has-text) {
.composer-row {
padding-bottom: 8px;
}
textarea {
min-height: 72px;
}
.composer-foot {
max-height: 56px;
padding-top: 2px;
padding-bottom: 6px;
border-top-width: 1px;
opacity: 1;
overflow: visible;
}
.composer-slash {
display: none;
}
}
@media (hover: none), (max-width: 599px) {
.composer-slash {
display: none;
}
&:not(:focus-within):not(.has-text) .composer-send-slot {
visibility: visible;
}
}
@media (prefers-reduced-motion: reduce) {
textarea, .composer-foot, .composer-row {
transition: none;
}
}
}

7
ui-ngx/src/app/modules/home/components/ai/ai-prompt-input.component.ts

@ -86,6 +86,8 @@ export class AiPromptInputComponent implements OnChanges, AfterViewInit, OnDestr
@Input() docked = false;
@Input() slim = false;
@Input() pinned = false;
@Input() dropZone: HTMLElement;
@ -224,6 +226,11 @@ export class AiPromptInputComponent implements OnChanges, AfterViewInit, OnDestr
this.stop();
return;
}
if (event.key === 'Escape' && this.slim) {
event.preventDefault();
this.textarea?.nativeElement.blur();
return;
}
if (event.key === 'Enter' && (!event.shiftKey || event.metaKey || event.ctrlKey)) {
event.preventDefault();
this.send();

7
ui-ngx/src/app/modules/home/pages/ai-assistant/ai-assistant.component.ts

@ -235,9 +235,14 @@ export class AiAssistantComponent implements OnInit, OnDestroy {
]).subscribe({
next: ([, chats]) => {
const params = this.route.snapshot.queryParamMap;
const first = !params.get('chatId') && !params.get('solutionId') && !chats.length;
const handOff = this.panelService.takeHandOff();
const first = !handOff && !params.get('chatId') && !params.get('solutionId') && !chats.length;
this.openFromUrl(params.get('chatId'), params.get('solutionId'), chats, first || params.get('getStarted') === 'true');
this.ready.set(true);
if (handOff) {
this.newChat();
setTimeout(() => this.chat?.sendMsgFromUser(handOff));
}
},
error: err => {
this.ready.set(true);

3
ui-ngx/src/app/modules/home/pages/home-links/home-links-routing.module.ts

@ -25,7 +25,6 @@ import { MenuId } from '@core/services/menu.models';
import { MenuService } from '@core/services/menu.service';
const sysAdminHomePageJson = '/assets/dashboard/sys_admin_home_page.json';
const tenantAdminHomePageJson = '/assets/dashboard/tenant_admin_home_page.json';
// const customerUserHomePageJson = '/assets/dashboard/customer_user_home_page.json';
const getHomeDashboard = (store: Store<AppState>, resourcesService: ResourcesService) => {
@ -33,8 +32,6 @@ const getHomeDashboard = (store: Store<AppState>, resourcesService: ResourcesSer
switch (authority) {
case Authority.SYS_ADMIN:
return applySystemParametersToHomeDashboard(store, resourcesService.loadJsonResource(sysAdminHomePageJson), authority);
case Authority.TENANT_ADMIN:
return applySystemParametersToHomeDashboard(store, resourcesService.loadJsonResource(tenantAdminHomePageJson), authority);
// case Authority.CUSTOMER_USER:
// return applySystemParametersToHomeDashboard(store, resourcesService.loadJsonResource(customerUserHomePageJson), authority);
default:

24
ui-ngx/src/app/modules/home/pages/home-links/home-links.component.html

@ -8,27 +8,5 @@
@if (homeDashboard) {
<tb-dashboard-page [embedded]="true" [dashboard]="homeDashboard" [hideToolbar]="homeDashboard.hideDashboardToolbar" [hideMainToolbar]="hideMainToolbar"></tb-dashboard-page>
} @else {
<mat-grid-list class="tb-home-links" [cols]="cols" rowHeight="280px">
@for (section of homeSections$| async; track section) {
<mat-grid-tile [colspan]="sectionColspan(section)">
<mat-card appearance="outlined" style="width: 100%;">
<mat-card-title>
<span translate class="mat-headline-5">{{section.name}}</span>
</mat-card-title>
<mat-card-content>
<mat-grid-list rowHeight="170px" [cols]="section.places.length">
@for (place of section.places; track place) {
<mat-grid-tile>
<a mat-stroked-button class="tb-card-button" routerLink="{{place.path}}" [queryParams]="place.queryParams">
<tb-icon matButtonIcon class="tb-mat-96">{{place.icon}}</tb-icon>
<span>{{place.customTranslate ? (place.name | customTranslate) : (place.name | translate)}}</span>
</a>
</mat-grid-tile>
}
</mat-grid-list>
</mat-card-content>
</mat-card>
</mat-grid-tile>
}
</mat-grid-list>
<tb-home-page></tb-home-page>
}

56
ui-ngx/src/app/modules/home/pages/home-links/home-links.component.scss

@ -1,58 +1,8 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
@import '../../../../../scss/constants';
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
:host {
display: block;
width: 100%;
height: 100%;
}
:host ::ng-deep {
.tb-home-links {
.mat-headline-5 {
font-size: 20px;
@media #{$mat-gt-xmd} {
font-size: 24px;
}
}
.mat-mdc-card {
padding: 0;
margin: 8px;
.mat-mdc-card-title {
margin: 0;
padding: 24px 16px 16px;
}
.mat-mdc-card-title+.mat-mdc-card-content {
padding-top: 0;
}
.mat-mdc-card-content {
padding: 16px;
}
}
.tb-card-button.mat-mdc-outlined-button {
width: 100%;
height: 100%;
max-width: 240px;
display: flex;
flex-direction: column;
align-items: center;
color: rgba(0,0,0,0.76);
.mat-icon {
margin: auto;
}
span.mdc-button__label {
height: 18px;
min-height: 36px;
max-height: 36px;
padding: 0 0 20px 0;
margin: auto;
font-size: 18px;
font-weight: 400;
line-height: 18px;
white-space: normal;
text-align: center;
}
}
}
}

52
ui-ngx/src/app/modules/home/pages/home-links/home-links.component.ts

@ -1,15 +1,7 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
OnInit
} from '@angular/core';
import { MenuService } from '@core/services/menu.service';
import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout';
import { MediaBreakpoints } from '@shared/models/constants';
import { HomeSection } from '@core/services/menu.models';
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HomeDashboard } from '@shared/models/dashboard.models';
@ -22,50 +14,14 @@ import { HomeDashboard } from '@shared/models/dashboard.models';
})
export class HomeLinksComponent implements OnInit {
homeSections$ = this.menuService.homeSections();
cols = 2;
homeDashboard: HomeDashboard = this.route.snapshot.data.homeDashboard;
hideMainToolbar = true;
constructor(private menuService: MenuService,
public breakpointObserver: BreakpointObserver,
private cd: ChangeDetectorRef,
private route: ActivatedRoute) {
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.hideMainToolbar = (!!this.homeDashboard && !this.homeDashboard.isSystemDashboard);
if (!this.homeDashboard) {
this.updateColumnCount();
this.breakpointObserver
.observe([MediaBreakpoints.lg, MediaBreakpoints['gt-lg']])
.subscribe((state: BreakpointState) => this.updateColumnCount());
}
}
private updateColumnCount() {
this.cols = 2;
if (this.breakpointObserver.isMatched(MediaBreakpoints.lg)) {
this.cols = 3;
}
if (this.breakpointObserver.isMatched(MediaBreakpoints['gt-lg'])) {
this.cols = 4;
}
this.cd.detectChanges();
}
sectionColspan(section: HomeSection): number {
if (this.breakpointObserver.isMatched(MediaBreakpoints['gt-sm'])) {
let colspan = this.cols;
if (section && section.places && section.places.length <= colspan) {
colspan = section.places.length;
}
return colspan;
} else {
return 2;
}
}
}

52
ui-ngx/src/app/modules/home/pages/home-links/home-links.module.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@ -8,15 +9,62 @@ import { HomeLinksComponent } from './home-links.component';
import { SharedModule } from '@app/shared/shared.module';
import { HomeComponentsModule } from '@home/components/home-components.module';
import { HomePageComponent } from '@home/pages/home-links/home/pages/home-page.component';
import { SysAdminHomeComponent } from '@home/pages/home-links/home/pages/sys-admin-home.component';
import { TenantAdminHomeComponent } from '@home/pages/home-links/home/pages/tenant-admin-home.component';
import { CustomerUserHomeComponent } from '@home/pages/home-links/home/pages/customer-user-home.component';
import { HomeCardComponent } from '@home/pages/home-links/home/components/home-card.component';
import { WelcomeHomeComponent } from '@home/pages/home-links/home/components/welcome-home.component';
import { StatusLineHomeComponent } from '@home/pages/home-links/home/components/status-line-home.component';
import { AiAssistantHomeComponent } from '@home/pages/home-links/home/components/ai-assistant-home.component';
import { WaitingAIChatsHomeComponent } from '@home/pages/home-links/home/components/waiting-ai-chats-home.component';
import { IoTHubHomeComponent } from '@home/pages/home-links/home/components/iot-hub-home.component';
import { AlarmsHomeComponent } from '@home/pages/home-links/home/components/alarms-home.component';
import { DashboardsHomeComponent } from '@home/pages/home-links/home/components/dashboards-home.component';
import { DevicesHomeComponent } from '@home/pages/home-links/home/components/devices-home.component';
import { DevicesActivityHomeComponent } from '@home/pages/home-links/home/components/devices-activity-home.component';
import { GetStartedHomeComponent } from '@home/pages/home-links/home/components/get-started-home.component';
import { NotificationsHomeComponent } from '@home/pages/home-links/home/components/notifications-home.component';
import { QuickLinksHomeComponent } from '@home/pages/home-links/home/components/quick-links-home.component';
import { ApiUsageHomeComponent } from '@home/pages/home-links/home/components/api-usage-home.component';
import { MobileAppHomeComponent } from '@home/pages/home-links/home/components/mobile-app-home.component';
import { HomeCardsFooterComponent } from '@home/pages/home-links/home/components/home-cards-footer.component';
import { CustomizeHomeDialogComponent } from '@home/pages/home-links/home/components/customize-home-dialog.component';
import { HomeHscrollComponent } from '@home/pages/home-links/home/components/home-hscroll.component';
import { AiModule } from '@home/components/ai/ai.module';
@NgModule({
declarations:
[
HomeLinksComponent
HomeLinksComponent,
HomePageComponent,
SysAdminHomeComponent,
TenantAdminHomeComponent,
CustomerUserHomeComponent,
HomeCardComponent,
WelcomeHomeComponent,
StatusLineHomeComponent,
AiAssistantHomeComponent,
WaitingAIChatsHomeComponent,
IoTHubHomeComponent,
AlarmsHomeComponent,
DashboardsHomeComponent,
DevicesHomeComponent,
DevicesActivityHomeComponent,
GetStartedHomeComponent,
NotificationsHomeComponent,
QuickLinksHomeComponent,
ApiUsageHomeComponent,
MobileAppHomeComponent,
HomeCardsFooterComponent,
CustomizeHomeDialogComponent,
HomeHscrollComponent
],
imports: [
CommonModule,
SharedModule,
HomeComponentsModule,
AiModule,
HomeLinksRoutingModule
]
})

97
ui-ngx/src/app/modules/home/pages/home-links/home/components/ai-assistant-home.component.scss

@ -0,0 +1,97 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
:host {
display: block;
min-width: 0;
}
.tb-ai-compose-row {
display: flex;
align-items: flex-start;
gap: 8px;
min-width: 0;
max-width: var(--tb-home-compose-width, 760px);
container-type: inline-size;
}
.tb-ai-home-composer {
flex: 1 1 auto;
min-width: 0;
}
.tb-ai-chats-btn {
&:hover, &:focus, &:active {
border-bottom: none;
}
flex: none;
display: inline-flex;
align-items: center;
gap: 8px;
box-sizing: border-box;
height: 50px;
max-width: 160px;
padding: 0 12px 0 16px;
overflow: hidden;
white-space: nowrap;
border-radius: 12px;
background: transparent;
box-shadow: inset 0 0 0 1px var(--tb-line, rgba(0, 0, 0, 0.12));
font: 500 14px/20px var(--tb-font, Roboto, sans-serif);
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
text-decoration: none;
border-bottom: none;
mix-blend-mode: multiply;
transition: max-width .2s ease, padding .2s ease, margin .2s ease, opacity .15s ease, background-color .15s, color .15s;
.mat-icon {
flex: none;
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
}
.tb-ai-chats-go {
margin-left: -4px;
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
}
&:hover {
background: var(--tb-line-soft, rgba(0, 0, 0, 0.05));
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
.mat-icon {
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
}
&:focus-visible {
outline: 2px solid var(--ai-focus);
outline-offset: 2px;
}
}
.tb-ai-compose-row.open .tb-ai-chats-btn {
max-width: 0;
margin-left: -8px;
padding: 0;
opacity: 0;
visibility: hidden;
transition: max-width .2s ease, padding .2s ease, margin .2s ease, opacity .1s ease, visibility 0s .2s;
}
@container (max-width: 480px) {
.tb-ai-chats-btn {
width: 50px;
padding: 0;
justify-content: center;
.tb-ai-chats-t, .tb-ai-chats-go {
display: none;
}
}
}
@media (prefers-reduced-motion: reduce) {
.tb-ai-chats-btn {
transition: none;
}
}

55
ui-ngx/src/app/modules/home/pages/home-links/home/components/ai-assistant-home.component.ts

@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, HostListener, inject, signal, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
import { TranslateService } from '@ngx-translate/core';
import { AiPromptMessage } from '@shared/models/ai-chat.models';
import { AiAssistantPanelService } from '@core/services/ai-assistant-panel.service';
import { AiPromptInputComponent } from '@home/components/ai/ai-prompt-input.component';
@Component({
selector: 'tb-ai-assistant-home',
template: `
<div class="tb-ai-compose-row" [class.open]="composerFocused() || !!composerRef?.hasText()">
<tb-ai-prompt-input #composerRef class="tb-ai-home-composer" [slim]="true"
(focusin)="composerFocused.set(true)" (focusout)="composerFocused.set(false)"
[placeholder]="'home.ai.placeholder' | translate"
(messageSent)="send($event)"></tb-ai-prompt-input>
<a class="tb-ai-chats-btn" routerLink="/ai-assistant">
<mat-icon aria-hidden="true">forum</mat-icon>
<span class="tb-ai-chats-t">{{ 'home.ai.chats' | translate }}</span>
<mat-icon class="tb-ai-chats-go" aria-hidden="true">chevron_right</mat-icon>
</a>
</div>
`,
styleUrls: ['./ai-assistant-home.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AiAssistantHomeComponent {
@ViewChild(AiPromptInputComponent) composer: AiPromptInputComponent;
readonly composerFocused = signal(false);
private router = inject(Router);
private panelService = inject(AiAssistantPanelService);
private dialog = inject(MatDialog);
private translate = inject(TranslateService);
send(prompt: AiPromptMessage): void {
this.panelService.handOff(prompt);
this.router.navigateByUrl('/ai-assistant');
}
@HostListener('document:keydown', ['$event'])
onSlash(event: KeyboardEvent): void {
if (event.key !== '/' || event.metaKey || event.ctrlKey || event.altKey || event.defaultPrevented || this.dialog.openDialogs.length
|| (event.target as HTMLElement)?.closest?.('input, textarea, select, [contenteditable]')) {
return;
}
event.preventDefault();
this.composer?.focus();
}
}

16
ui-ngx/src/app/modules/home/pages/home-links/home/components/alarms-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-alarms-home',
template: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AlarmsHomeComponent {
readonly card = HOME_CARDS[HomeCardId.ALARMS];
}

16
ui-ngx/src/app/modules/home/pages/home-links/home/components/api-usage-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-api-usage-home',
template: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ApiUsageHomeComponent {
readonly card = HOME_CARDS[HomeCardId.USAGE];
}

73
ui-ngx/src/app/modules/home/pages/home-links/home/components/customize-home-dialog.component.scss

@ -0,0 +1,73 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
.tb-customize-home-panel .mat-mdc-dialog-surface {
border-radius: 14px;
}
.tb-customize-home {
display: flex;
flex-direction: column;
gap: 8px;
box-sizing: border-box;
width: min(360px, calc(100vw - 32px));
padding: 20px 20px 16px 24px;
h2 {
margin: 0;
font: 500 17px/24px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
.tb-sections {
display: flex;
flex-direction: column;
margin: 0 -8px;
}
.tb-section-row {
display: flex;
align-items: center;
gap: 12px;
height: 40px;
padding: 0 8px;
border-radius: 8px;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
cursor: pointer;
&:hover {
background: rgba(0, 0, 0, 0.04);
}
input {
flex: none;
width: 18px;
height: 18px;
margin: 0;
accent-color: var(--tb-primary-500);
cursor: pointer;
}
.mat-icon {
flex: none;
width: 20px;
height: 20px;
font-size: 20px;
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
}
}
.tb-customize-actions {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
.mdc-button {
height: 36px;
padding: 0 14px;
border-radius: 8px;
}
}
}

65
ui-ngx/src/app/modules/home/pages/home-links/home/components/customize-home-dialog.component.ts

@ -0,0 +1,65 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, computed, inject, ViewEncapsulation } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { MAT_DIALOG_DATA, MatDialogRef } 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';
export interface CustomizeHomeDialogData {
cards: HomeCardId[];
}
@Component({
selector: 'tb-customize-home-dialog',
template: `
<div class="tb-customize-home" role="dialog" aria-labelledby="tb-customize-home-title">
<h2 id="tb-customize-home-title">{{ 'home.customize.title' | translate }}</h2>
<div class="tb-sections" role="group" [attr.aria-label]="'home.customize.cards' | translate">
@for (row of rows(); track row.card.id) {
<label class="tb-section-row">
<input type="checkbox" [checked]="row.shown" (change)="toggle(row.card.id, $any($event.target).checked)">
<mat-icon aria-hidden="true">{{ row.card.icon }}</mat-icon>
<span class="tb-section-name">{{ row.card.name | translate }}</span>
</label>
}
</div>
<div class="tb-customize-actions">
@if (anyHidden()) {
<button mat-button type="button" (click)="showAll()">{{ 'home.customize.show-all' | translate }}</button>
}
<span class="flex-1"></span>
<button mat-flat-button color="primary" type="button" (click)="dialogRef.close()">{{ 'action.done' | translate }}</button>
</div>
</div>
`,
styleUrls: ['./customize-home-dialog.component.scss'],
encapsulation: ViewEncapsulation.None,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CustomizeHomeDialogComponent {
readonly dialogRef = inject(MatDialogRef<CustomizeHomeDialogComponent>);
private data = inject<CustomizeHomeDialogData>(MAT_DIALOG_DATA);
private store = inject(Store<AppState>);
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]))));
}
}

16
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: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DashboardsHomeComponent {
readonly card = HOME_CARDS[HomeCardId.DASHBOARDS];
}

16
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: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DevicesActivityHomeComponent {
readonly card = HOME_CARDS[HomeCardId.ACTIVITY];
}

16
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: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DevicesHomeComponent {
readonly card = HOME_CARDS[HomeCardId.DEVICES];
}

16
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: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class GetStartedHomeComponent {
readonly card = HOME_CARDS[HomeCardId.GET_STARTED];
}

152
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);
}
}

70
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: `
<section class="tb-home-card" [class.hideable]="hideable()" [attr.data-home-card]="card().id" [style.min-height.px]="card().height"
[attr.aria-label]="card().name | translate">
<div class="tb-home-card-header" [class.expanded]="expanded()">
@if (card().link) {
<a class="tb-home-card-title link" [routerLink]="card().link">
<mat-icon class="tb-home-card-icon">{{ card().icon }}</mat-icon>
<span>{{ card().name | translate }}</span>
</a>
} @else {
<span class="tb-home-card-title">
<mat-icon class="tb-home-card-icon">{{ card().icon }}</mat-icon>
<span>{{ card().name | translate }}</span>
</span>
}
<div class="tb-home-card-actions">
@if (hideable() && !expanded()) {
<button mat-icon-button type="button" class="tb-home-card-hide"
[matTooltip]="'home.customize.hide' | translate: {name: (card().name | translate)}" matTooltipPosition="above"
[attr.aria-label]="'home.customize.hide' | translate: {name: (card().name | translate)}" (click)="hide()">
<mat-icon>visibility_off</mat-icon>
</button>
}
<ng-content select="[homeCardActions]"></ng-content>
</div>
</div>
<ng-content></ng-content>
</section>
`,
styleUrls: ['./home-card.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class HomeCardComponent {
card = input.required<HomeCardDefinition>();
hideable = input(false);
expanded = input(false);
private store = inject(Store<AppState>);
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})));
}
}

70
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;
}

65
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: `
<footer class="tb-home-foot">
@if (hidden().length) {
<div class="tb-hidden-cards" role="group" [attr.aria-label]="'home.customize.show-on-home' | translate">
<span class="tb-hidden-lbl">{{ 'home.customize.show-on-home' | translate }}</span>
@for (card of hidden(); track card.id) {
<button type="button" class="tb-foot-btn" (click)="show(card.id)">
<mat-icon aria-hidden="true">{{ card.icon }}</mat-icon>
<span>{{ card.name | translate }}</span>
</button>
}
</div>
}
<button type="button" class="tb-foot-btn tb-customize-btn" aria-haspopup="dialog" (click)="customize()">
<mat-icon aria-hidden="true">settings</mat-icon>
<span>{{ 'home.customize.title' | translate }}</span>
</button>
</footer>
`,
styleUrls: ['./home-cards-footer.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class HomeCardsFooterComponent {
cards = input.required<HomeCardId[]>();
private store = inject(Store<AppState>);
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, CustomizeHomeDialogData>(CustomizeHomeDialogComponent, {
panelClass: 'tb-customize-home-panel',
autoFocus: 'first-tabbable',
data: {cards: this.cards()}
});
}
}

166
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;
}
}
}

133
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: `
<div class="tb-hscroll" [class.at-start]="atStart()" [class.at-end]="atEnd()" [class.fits]="fits()" [class.dragging]="dragging()">
<div class="tb-hscroll-view" [style.--arrow-y.px]="arrowY()">
<div #track class="tb-hscroll-track" role="group" [attr.aria-label]="label()" (scroll)="sync()">
<ng-content></ng-content>
</div>
<button type="button" class="tb-hscroll-btn prev" tabindex="-1" aria-hidden="true" (click)="step(-1)">
<mat-icon>chevron_left</mat-icon>
</button>
<button type="button" class="tb-hscroll-btn next" tabindex="-1" aria-hidden="true" (click)="step(1)">
<mat-icon>chevron_right</mat-icon>
</button>
</div>
<div #bar class="tb-hscroll-bar" aria-hidden="true" (pointerdown)="press($event)">
<i [style.width.px]="thumbWidth()" [style.transform]="'translateX(' + thumbX() + 'px)'"></i>
</div>
</div>
`,
styleUrls: ['./home-hscroll.component.scss'],
encapsulation: ViewEncapsulation.None,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class HomeHscrollComponent implements AfterViewInit {
label = input<string>();
@ViewChild('track', {static: true}) trackRef: ElementRef<HTMLElement>;
@ViewChild('bar', {static: true}) barRef: ElementRef<HTMLElement>;
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<number | null>(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();
}
}

105
ui-ngx/src/app/modules/home/pages/home-links/home/components/iot-hub-home.component.html

@ -0,0 +1,105 @@
<!--
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
SPDX-License-Identifier: BUSL-1.1
-->
<tb-home-card [card]="card" [hideable]="true" [expanded]="searching()">
<ng-container homeCardActions>
@if (searching()) {
<label class="tb-iot-hub-search" [class.has-text]="!!query().trim()" (focusout)="onSearchFocusOut($event)">
<mat-icon aria-hidden="true">search</mat-icon>
<input #searchInput type="search" class="tb-search-input" [placeholder]="'home.iot-hub.search' | translate"
[attr.aria-label]="'home.iot-hub.search' | translate" [value]="query()"
(input)="query.set($any($event.target).value)" (keydown)="onSearchKeydown($event)">
<button mat-icon-button type="button" class="tb-search-clear" [matTooltip]="'action.clear' | translate"
[attr.aria-label]="'action.clear' | translate" (click)="clearSearch()">
<mat-icon>close</mat-icon>
</button>
<button mat-icon-button type="button" class="tb-search-go" [matTooltip]="'home.iot-hub.open-results' | translate"
[attr.aria-label]="'home.iot-hub.open-results' | translate" (click)="search()">
<mat-icon>arrow_forward</mat-icon>
</button>
</label>
} @else {
<button #searchOpener mat-icon-button type="button" class="tb-iot-hub-find" aria-expanded="false"
[matTooltip]="'home.iot-hub.search' | translate" matTooltipPosition="above"
[attr.aria-label]="'home.iot-hub.search' | translate" (click)="openSearch()">
<mat-icon>search</mat-icon>
</button>
}
</ng-container>
@if (failed()) {
<p class="tb-iot-hub-unavailable">{{ 'home.iot-hub.unavailable' | translate }}</p>
} @else {
<div class="tb-iot-hub-row">
<a class="tb-iot-hub-row-title" routerLink="/iot-hub/solution-templates">{{ 'home.iot-hub.templates' | translate }}</a>
<tb-home-hscroll [label]="'home.iot-hub.templates' | translate">
@for (tile of templates(); track tile.item.id; let first = $first) {
<button type="button" class="tb-iot-hub-card" (click)="open(tile.item)">
<span class="tb-iot-hub-card-image" [style.background]="tile.tint" [attr.data-hscroll-anchor]="first ? '' : null">
@if (tile.image) {
<img [src]="tile.image" alt="" loading="lazy" (error)="tile.image = null">
}
@if (isInstalled(tile.item)) {
<mat-icon class="tb-iot-hub-card-installed" role="img"
[attr.aria-label]="'iot-hub.installed' | translate"
[matTooltip]="'iot-hub.installed' | translate" matTooltipPosition="left" [matTooltipShowDelay]="0">check_circle</mat-icon>
}
</span>
<span class="tb-iot-hub-card-label">
<span class="tb-iot-hub-card-name" [title]="tile.item.name">{{ tile.item.name }}</span>
@if (tile.meta) {
<span class="tb-iot-hub-card-meta">{{ tile.meta }}</span>
}
</span>
</button>
} @empty {
@if (!loaded()) {
@for (n of [1, 2, 3, 4]; track n) {
<span class="tb-iot-hub-card placeholder"><span class="tb-iot-hub-card-image"></span></span>
}
}
}
</tb-home-hscroll>
</div>
<div class="tb-iot-hub-row">
<a class="tb-iot-hub-row-title" routerLink="/iot-hub/devices">{{ 'home.iot-hub.device-library' | translate }}</a>
<tb-home-hscroll [label]="'home.iot-hub.device-library' | translate">
@for (tile of devices(); track tile.item.id) {
<button type="button" class="tb-iot-hub-device" (click)="open(tile.item)">
<span class="tb-iot-hub-device-thumb" [style.background]="tile.tint">
@if (tile.image) {
<img [src]="tile.image" alt="" loading="lazy" (error)="tile.image = null">
}
</span>
<span class="tb-iot-hub-device-text">
<b>{{ tile.item.name }}</b>
<small>{{ tile.meta }}</small>
</span>
</button>
}
@if (deviceTotal()) {
<button type="button" class="tb-iot-hub-device tb-iot-hub-all" (click)="browse('devices')">
<span class="tb-iot-hub-device-thumb"><mat-icon>arrow_forward</mat-icon></span>
<span class="tb-iot-hub-device-text">
<b>{{ 'home.iot-hub.all-devices' | translate: {count: deviceTotal()} }}</b>
<small>{{ 'home.iot-hub.device-library' | translate }}</small>
</span>
</button>
}
</tb-home-hscroll>
</div>
}
<div class="tb-iot-hub-row">
<div class="tb-iot-hub-row-title plain">{{ 'home.iot-hub.also' | translate }}</div>
<nav class="tb-iot-hub-kinds" [attr.aria-label]="'home.iot-hub.also' | translate">
@for (kind of kinds; track kind.type) {
<a class="tb-iot-hub-kind" [routerLink]="['/iot-hub', kind.route]">
<mat-icon aria-hidden="true">{{ kind.icon }}</mat-icon>
<span>{{ kind.name | translate }}</span>
</a>
}
</nav>
</div>
</tb-home-card>

361
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);
}
}
}

198
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<HubTile[]>([]);
readonly devices = signal<HubTile[]>([]);
readonly deviceTotal = signal(0);
readonly loaded = signal(false);
readonly failed = signal(false);
readonly searching = signal(false);
readonly query = signal('');
@ViewChild('searchInput') searchInput: ElementRef<HTMLInputElement>;
@ViewChild('searchOpener', {read: ElementRef}) searchOpener: ElementRef<HTMLElement>;
private router = inject(Router);
private api = inject(IotHubApiService);
private actions = inject(IotHubActionsService);
private installedTemplates: IotHubInstalledItem[] = [];
private installedDeviceCounts: Record<string, number> = {};
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);
}
}

16
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: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MobileAppHomeComponent {
readonly card = HOME_CARDS[HomeCardId.MOBILE_APP];
}

16
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: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class NotificationsHomeComponent {
readonly card = HOME_CARDS[HomeCardId.NOTIFICATIONS];
}

16
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: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class QuickLinksHomeComponent {
readonly card = HOME_CARDS[HomeCardId.QUICK_LINKS];
}

65
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);
}

157
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<string, unknown>;
card?: HomeCardId;
link?: string;
}
@Component({
selector: 'tb-status-line-home',
template: `
@if (parts().length) {
<div class="tb-status-line" [class]="kind()">
@for (part of parts(); track part.key; let first = $first) {
<span class="tb-pill">
@if (first) {
@if (kind() === 'crit') {
<tb-ai-sev-mark severity="CRITICAL"></tb-ai-sev-mark>
} @else {
<span class="tb-status-dot"></span>
}
}
@if (part.link) {
<a class="tb-status-link" href="#" (click)="$event.preventDefault(); open(part)">{{ part.key | translate: part.params }}</a>
} @else {
<span>{{ part.key | translate: part.params }}</span>
}
</span>
}
</div>
}
`,
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<AppState>);
private readonly customer = getCurrentAuthUser(this.store)?.authority === Authority.CUSTOMER_USER;
private critical = signal<number | null>(null);
private active = signal<number | null>(null);
private devices = signal<number | null>(null);
private inactive = signal<number | null>(null);
private subscribers: TelemetrySubscriber[] = [];
readonly parts = computed<StatusPart[]>(() => {
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<StatusKind>(() => 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<number | null>, 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<number | null>, 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;
}
}

72
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;
}
}

42
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) {
<div class="tb-ai-attn-block">
<div class="tb-ai-attn-h" id="tb-ai-attn-h">{{ 'home.ai.waiting' | translate }}</div>
<div class="tb-ai-attn" role="group" aria-labelledby="tb-ai-attn-h">
@for (chat of shown(); track chat.id) {
<a class="tb-chat-pill" routerLink="/ai-assistant" [queryParams]="{chatId: chat.id}" [matTooltip]="chats.tipOf(chat)"
matTooltipPosition="below">
<span class="tb-ai-status-mark" [class]="chats.levelOf(chat)" aria-hidden="true"></span>
<span class="tb-chat-pill-t">{{ chat.title || ('ai-assistant.new-chat' | translate) }}</span>
</a>
}
</div>
</div>
}
`,
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();
}
}

49
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;
}
}

35
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: `
<div class="tb-home-kicker">{{ today | date: 'EEEE d MMMM' }}</div>
<h1 class="tb-greeting" [class.with-spark]="spark()">
@if (spark()) {
<tb-ai-mark class="tb-greet-spark" size="44"></tb-ai-mark>
}
<span>{{ (name ? 'home.greeting.' + daypart + '-name' : 'home.greeting.' + daypart) | translate: {name} }}</span>
</h1>
`,
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<AppState>));
return (auth?.userDetails?.firstName || auth?.authUser?.firstName || '').trim().split(/\s+/)[0] || null;
})();
}

27
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, HomeCardDefinition> = {
[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;

20
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: `
<div class="tb-home">
<div class="tb-home-head">
<tb-welcome-home></tb-welcome-home>
<tb-status-line-home></tb-status-line-home>
</div>
</div>
`,
styleUrls: ['./tenant-admin-home.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CustomerUserHomeComponent {
}

69
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);
}
}

47
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) {
<div class="tb-home-sky" aria-hidden="true"></div>
}
@switch (authority) {
@case (Authority.SYS_ADMIN) {
<tb-sys-admin-home></tb-sys-admin-home>
}
@case (Authority.TENANT_ADMIN) {
<tb-tenant-admin-home></tb-tenant-admin-home>
}
@case (Authority.CUSTOMER_USER) {
<tb-customer-user-home></tb-customer-user-home>
}
}
`,
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<AppState>))?.authority;
readonly aiSky = inject(TourService).aiAvailable();
readonly tenantBrand = getComputedStyle(document.body).getPropertyValue('--tb-primary-500')
.trim().toLowerCase() !== DEFAULT_PRIMARY;
}

19
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: `
<div class="tb-home">
<div class="tb-home-head">
<tb-welcome-home></tb-welcome-home>
</div>
</div>
`,
styleUrls: ['./tenant-admin-home.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class SysAdminHomeComponent {
}

65
ui-ngx/src/app/modules/home/pages/home-links/home/pages/tenant-admin-home.component.html

@ -0,0 +1,65 @@
<!--
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
SPDX-License-Identifier: BUSL-1.1
-->
<ng-template #homeCard let-id>
@switch (id) {
@case (HomeCardId.IOT_HUB) {
<tb-iot-hub-home></tb-iot-hub-home>
}
@case (HomeCardId.ALARMS) {
<tb-alarms-home></tb-alarms-home>
}
@case (HomeCardId.DASHBOARDS) {
<tb-dashboards-home></tb-dashboards-home>
}
@case (HomeCardId.DEVICES) {
<tb-devices-home></tb-devices-home>
}
@case (HomeCardId.ACTIVITY) {
<tb-devices-activity-home></tb-devices-activity-home>
}
@case (HomeCardId.GET_STARTED) {
<tb-get-started-home></tb-get-started-home>
}
@case (HomeCardId.NOTIFICATIONS) {
<tb-notifications-home></tb-notifications-home>
}
@case (HomeCardId.QUICK_LINKS) {
<tb-quick-links-home></tb-quick-links-home>
}
@case (HomeCardId.USAGE) {
<tb-api-usage-home></tb-api-usage-home>
}
@case (HomeCardId.MOBILE_APP) {
<tb-mobile-app-home></tb-mobile-app-home>
}
}
</ng-template>
<div class="tb-home">
<div class="tb-home-head">
<tb-welcome-home [spark]="aiAvailable"></tb-welcome-home>
<tb-status-line-home></tb-status-line-home>
</div>
<div class="tb-home-grid" [class.with-hero]="aiAvailable">
@if (aiAvailable) {
<div class="tb-grid-hero">
<tb-ai-assistant-home></tb-ai-assistant-home>
<tb-waiting-ai-chats-home></tb-waiting-ai-chats-home>
</div>
}
<div class="tb-col tb-col-main">
@for (id of mainCards(); track id) {
<ng-container [ngTemplateOutlet]="homeCard" [ngTemplateOutletContext]="{$implicit: id}"></ng-container>
}
</div>
<div class="tb-col tb-col-side">
@for (id of sideCards(); track id) {
<ng-container [ngTemplateOutlet]="homeCard" [ngTemplateOutletContext]="{$implicit: id}"></ng-container>
}
</div>
</div>
<tb-home-cards-footer [cards]="cards"></tb-home-cards-footer>
</div>

99
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;
}
}

35
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<AppState>).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)));
}

16
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<Record<AiTourStep, number>>;
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<Record<HomeCardId, boolean>>;
export const initialUserSettings: UserSettings = {
openedMenuSections: []
};

56
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",

Loading…
Cancel
Save