Browse Source

feat: the system administrator Home with Customize Home: the status line's system pills (CPU, RAM or disk load, license limits near 85%, no tenants, features not configured) with its space reserved while it loads; the product release card when an update is available, hidden for the visit with Undo; Get started's seven steps done from the tenant count and the features info, optional steps skipped in the getting started settings, closed through the home cards settings; Install's live entity counts and configured features; Activity with messages alone; Quick links with the documentation defaults; System and License as frames; features info fetched once for the page; the AI panel only where AI is available; the home dashboard resolver without the system administrator dashboard

pull/16848/head
Igor Kulikov 1 week ago
parent
commit
2322c1071f
  1. 2
      ui-ngx/src/app/modules/home/home.component.html
  2. 2
      ui-ngx/src/app/modules/home/home.component.ts
  3. 6
      ui-ngx/src/app/modules/home/pages/home-page/components/devices-activity-home.component.html
  4. 8
      ui-ngx/src/app/modules/home/pages/home-page/components/devices-activity-home.component.scss
  5. 25
      ui-ngx/src/app/modules/home/pages/home-page/components/devices-activity-home.component.ts
  6. 84
      ui-ngx/src/app/modules/home/pages/home-page/components/get-started-sys-admin-home.component.html
  7. 303
      ui-ngx/src/app/modules/home/pages/home-page/components/get-started-sys-admin-home.component.scss
  8. 188
      ui-ngx/src/app/modules/home/pages/home-page/components/get-started-sys-admin-home.component.ts
  9. 2
      ui-ngx/src/app/modules/home/pages/home-page/components/home-card.component.scss
  10. 45
      ui-ngx/src/app/modules/home/pages/home-page/components/install-items-home.component.html
  11. 157
      ui-ngx/src/app/modules/home/pages/home-page/components/install-items-home.component.scss
  12. 84
      ui-ngx/src/app/modules/home/pages/home-page/components/install-items-home.component.ts
  13. 16
      ui-ngx/src/app/modules/home/pages/home-page/components/license-home.component.ts
  14. 33
      ui-ngx/src/app/modules/home/pages/home-page/components/product-release-home.component.html
  15. 161
      ui-ngx/src/app/modules/home/pages/home-page/components/product-release-home.component.scss
  16. 57
      ui-ngx/src/app/modules/home/pages/home-page/components/product-release-home.component.ts
  17. 18
      ui-ngx/src/app/modules/home/pages/home-page/components/status-line-home.component.scss
  18. 237
      ui-ngx/src/app/modules/home/pages/home-page/components/status-line-home.component.ts
  19. 16
      ui-ngx/src/app/modules/home/pages/home-page/components/system-status-home.component.ts
  20. 7
      ui-ngx/src/app/modules/home/pages/home-page/home-cards.models.ts
  21. 97
      ui-ngx/src/app/modules/home/pages/home-page/home-page-routing.module.ts
  22. 12
      ui-ngx/src/app/modules/home/pages/home-page/home-page.module.ts
  23. 84
      ui-ngx/src/app/modules/home/pages/home-page/pages/sys-admin-home.component.ts
  24. 10
      ui-ngx/src/app/modules/home/pages/home-page/quick-links.models.ts
  25. 16
      ui-ngx/src/app/modules/home/pages/home-page/sys-admin-home.service.ts
  26. 8
      ui-ngx/src/app/shared/models/user-settings.models.ts
  27. 100
      ui-ngx/src/assets/locale/locale.constant-en_US.json

2
ui-ngx/src/app/modules/home/home.component.html

@ -118,7 +118,7 @@
</div>
</div>
</div>
@if (authState.aiEnabled) {
@if (aiAvailable) {
<tb-ai-assistant-panel></tb-ai-assistant-panel>
}
</mat-sidenav-content>

2
ui-ngx/src/app/modules/home/home.component.ts

@ -74,6 +74,8 @@ export class HomeComponent extends PageComponent implements AfterViewInit, OnIni
private tourService = inject(TourService);
readonly aiAvailable = this.tourService.aiAvailable();
constructor(protected store: Store<AppState>,
@Inject(WINDOW) private window: Window,
private activeComponentService: ActiveComponentService,

6
ui-ngx/src/app/modules/home/pages/home-page/components/devices-activity-home.component.html

@ -7,7 +7,7 @@
<tb-home-card [card]="card">
<span homeCardTitleExtra class="tb-activity-period">{{ 'home.activity.period' | translate }}</span>
<ng-container homeCardActions>
@if (loaded() && !empty()) {
@if (loaded() && !empty() && series.length > 1) {
<tb-home-toggle class="tb-activity-toggle" [options]="tabOptions" [value]="tab()" [label]="'home.activity.series' | translate"
(valueChange)="setTab($event)"></tb-home-toggle>
}
@ -15,10 +15,10 @@
@if (empty()) {
<div class="tb-home-setup-empty">
<span class="tb-home-setup-empty-glyph" aria-hidden="true"><mat-icon>show_chart</mat-icon></span>
<div class="tb-home-setup-empty-title">{{ 'home.activity.none' | translate }}</div>
<div class="tb-home-setup-empty-title">{{ (sysAdmin ? 'home.activity.no-messages' : 'home.activity.none') | translate }}</div>
</div>
} @else {
<div class="tb-activity-pair" [attr.data-tab]="tab()">
<div class="tb-activity-pair" [class.single]="series.length === 1" [attr.data-tab]="tab()">
@for (series of series; track series.id) {
<div class="tb-activity-series" [attr.data-series]="series.id">
<div class="tb-activity-name">{{ series.label | translate }}</div>

8
ui-ngx/src/app/modules/home/pages/home-page/components/devices-activity-home.component.scss

@ -54,3 +54,11 @@
display: block;
}
}
.tb-activity-pair.single {
display: block;
.tb-activity-name {
display: block;
}
}

25
ui-ngx/src/app/modules/home/pages/home-page/components/devices-activity-home.component.ts

@ -16,6 +16,10 @@ import {
} from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/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 * as echarts from 'echarts/core';
import tinycolor from 'tinycolor2';
import { CallbackDataParams } from 'echarts/types/dist/shared';
@ -38,7 +42,8 @@ type ActivitySeries = 'devices' | 'messages';
const DAY = 86400000;
const DAYS = 30;
const LABEL_STEP = 7;
const SCALE_STEPS = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000];
const SCALE_STEPS = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000,
1e6, 2e6, 5e6, 1e7, 2e7, 5e7, 1e8, 2e8, 5e8, 1e9];
const startOfFirstDay = (now: number): number => {
const date = new Date(now - (DAYS - 1) * DAY);
@ -89,9 +94,11 @@ export class DevicesActivityHomeComponent implements AfterViewInit {
readonly card = HOME_CARDS[HomeCardId.ACTIVITY];
readonly series = SERIES;
readonly sysAdmin = getCurrentAuthUser(inject(Store<AppState>))?.authority === Authority.SYS_ADMIN;
readonly tabOptions: HomeToggleOption<ActivitySeries>[] = SERIES.map(series => ({value: series.id, label: series.label}));
readonly series = this.sysAdmin ? SERIES.filter(series => series.id === 'messages') : SERIES;
readonly tabOptions: HomeToggleOption<ActivitySeries>[] = this.series.map(series => ({value: series.id, label: series.label}));
private telemetryWsService = inject(TelemetryWebsocketService);
private zone = inject(NgZone);
@ -101,13 +108,13 @@ export class DevicesActivityHomeComponent implements AfterViewInit {
private injector = inject(Injector);
private host = inject<ElementRef<HTMLElement>>(ElementRef);
readonly tab = signal<ActivitySeries>('devices');
readonly tab = signal<ActivitySeries>(this.series[0].id);
private readonly data = signal<Record<ActivitySeries, [number, number][]> | null>(null);
readonly loaded = computed(() => this.data() !== null);
readonly empty = computed(() => {
const data = this.data();
return !!data && SERIES.every(series => !data[series.id].some(point => point[1] > 0));
return !!data && this.series.every(series => !data[series.id].some(point => point[1] > 0));
});
private readonly devicesChart = viewChild<ElementRef<HTMLElement>>('devicesChart');
@ -163,7 +170,7 @@ export class DevicesActivityHomeComponent implements AfterViewInit {
this.startTs = startOfFirstDay(this.endTs);
this.historyLoaded = false;
SERIES.forEach(series => this.raw[series.id].clear());
const keys = SERIES.map(series => series.key);
const keys = this.series.map(series => series.key);
const cmd = new EntityDataCmd();
cmd.query = {
entityFilter: {type: AliasFilterType.apiUsageState},
@ -187,7 +194,7 @@ export class DevicesActivityHomeComponent implements AfterViewInit {
subscriber.entityData$.subscribe(update => {
const entities = update.data?.data ?? update.update ?? [];
entities.forEach(entity => {
SERIES.forEach(series => {
this.series.forEach(series => {
(entity.timeseries?.[series.key] ?? []).forEach(value => this.put(series.id, value.ts, value.value));
const latest = entity.latest?.[EntityKeyType.TIME_SERIES]?.[series.key];
if (latest?.ts) {
@ -272,7 +279,7 @@ export class DevicesActivityHomeComponent implements AfterViewInit {
}
echartsModule.init();
const color = getComputedStyle(this.host.nativeElement).getPropertyValue('--tb-primary-500').trim() || '#305680';
SERIES.forEach(series => {
this.series.forEach(series => {
const element = (series.id === 'devices' ? this.devicesChart() : this.messagesChart())?.nativeElement;
if (!element) {
return;
@ -343,7 +350,7 @@ export class DevicesActivityHomeComponent implements AfterViewInit {
axisLabel: {
...AXIS_LABEL,
margin: 8,
formatter: (value: number) => value >= 1000 ? `${value / 1000}k` : `${value}`
formatter: (value: number) => value >= 1e6 ? `${value / 1e6}M` : value >= 1000 ? `${value / 1000}k` : `${value}`
}
}],
series: [{

84
ui-ngx/src/app/modules/home/pages/home-page/components/get-started-sys-admin-home.component.html

@ -0,0 +1,84 @@
<!--
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
SPDX-License-Identifier: BUSL-1.1
-->
<tb-home-card [card]="cardDefinition()" [hideable]="true" [countText]="progress()">
@if (loaded()) {
<div class="tb-sgs-bar" role="progressbar" [attr.aria-label]="cardDefinition().name | translate" aria-valuemin="0"
[attr.aria-valuemax]="total" [attr.aria-valuenow]="doneCount()">
<i [style.width.%]="doneCount() / total * 100"></i>
</div>
<div class="tb-sgs-steps">
@for (group of groups; track group.label) {
<div class="tb-sgs-group">{{ group.label | translate }}</div>
<ol class="tb-sgs-list">
@for (step of group.steps; track step.key) {
@let stepState = state(step);
<li [class.done]="stepState === 'done' || stepState === 'skipped'" [class.skipped]="stepState === 'skipped'"
[class.open]="open() === step">
<div class="tb-sgs-row">
<span class="tb-sgs-mark" aria-hidden="true">
@if (stepState === 'done') {
<mat-icon>check</mat-icon>
} @else if (stepState === 'skipped') {
<mat-icon>remove</mat-icon>
} @else {
{{ number(step) }}
}
</span>
<button type="button" class="tb-sgs-title" [attr.aria-current]="open() === step ? 'step' : null"
[attr.aria-expanded]="open() === step" (click)="toggle(step)">
<span class="tb-sgs-title-text">{{ 'home.get-started-sys-admin.' + step.key + '.title' | translate }}</span>
@switch (stepState) {
@case ('done') {
<span class="tb-sgs-state">{{ (step.key === 'tenant' ? 'home.get-started-sys-admin.tenants' : 'home.get-started-sys-admin.configured')
| translate: {count: tenantCount()} }}</span>
}
@case ('skipped') {
<span class="tb-sgs-state">{{ 'home.get-started-sys-admin.skipped' | translate }}</span>
}
}
</button>
</div>
@if (open() === step) {
<div class="tb-sgs-body">
<div class="tb-sgs-head">
<span class="tb-sgs-head-n">{{ 'home.get-started.step-of' | translate: {step: number(step), total: total} }}</span>
<span class="tb-sgs-head-t">{{ 'home.get-started-sys-admin.' + step.key + '.title' | translate }}</span>
</div>
<p>{{ 'home.get-started-sys-admin.' + step.key + '.text' | translate }}
<a class="tb-sgs-guide" [href]="docUrl(step)" target="_blank" rel="noopener">{{ 'home.get-started.guide' | translate }}<mat-icon aria-hidden="true">north_east</mat-icon><span class="tb-home-sr-only">{{ 'home.dashboards.opens-new-tab' | translate }}</span></a>
</p>
<div class="tb-sgs-actions">
@if (stepState === 'done') {
<a mat-stroked-button class="tb-sgs-action" [routerLink]="step.link" [queryParams]="step.queryParams">
{{ 'home.get-started-sys-admin.' + step.key + '.action' | translate }}</a>
} @else {
<a mat-flat-button color="primary" class="tb-sgs-action" [routerLink]="step.link" [queryParams]="step.queryParams">
{{ 'home.get-started-sys-admin.' + step.key + '.action' | translate }}</a>
}
<span class="tb-sgs-spacer"></span>
@if (!step.needed && stepState !== 'done') {
<button mat-button type="button" class="tb-sgs-skip" (click)="skip(step)">
{{ (stepState === 'skipped' ? 'home.get-started-sys-admin.undo-skip' : 'home.get-started-sys-admin.skip') | translate }}
</button>
}
</div>
</div>
}
</li>
}
</ol>
}
</div>
@if (finished()) {
<div class="tb-sgs-finish">
<span>{{ (doneCount() === total ? 'home.get-started-sys-admin.finished' : 'home.get-started-sys-admin.finished-skipped')
| translate: {count: total - doneCount()} }}</span>
<button mat-stroked-button type="button" class="tb-sgs-close" (click)="close()">{{ 'action.close' | translate }}</button>
</div>
}
}
</tb-home-card>

303
ui-ngx/src/app/modules/home/pages/home-page/components/get-started-sys-admin-home.component.scss

@ -0,0 +1,303 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
@use './home-table';
:host {
--tb-home-card-gap: 8px;
--tb-home-card-hideable-top: 20px;
--tb-home-card-hideable-header: 36px;
display: block;
min-width: 0;
container: tb-get-started-sys-admin / inline-size;
}
.tb-sgs-bar {
height: 4px;
margin-top: -6px;
overflow: hidden;
border-radius: 2px;
background: rgba(0, 0, 0, 0.08);
> i {
display: block;
height: 100%;
border-radius: 2px;
background: var(--tb-ok, #198038);
}
}
.tb-sgs-group {
margin: 10px 0 2px;
font: 500 12px/16px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.5px;
text-transform: uppercase;
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
&:first-child {
margin-top: 0;
}
}
.tb-sgs-list {
display: grid;
gap: 2px;
margin: 0 -8px;
padding: 0;
list-style: none;
li {
min-width: 0;
border-radius: 10px;
&.open {
background: rgba(0, 0, 0, 0.03);
}
}
}
.tb-sgs-row {
display: flex;
align-items: center;
gap: 10px;
padding: 0 8px;
}
.tb-sgs-mark {
display: inline-flex;
flex: none;
align-items: center;
justify-content: center;
box-sizing: border-box;
width: 22px;
height: 22px;
border: 1px solid var(--tb-ink-38, rgba(0, 0, 0, 0.38));
border-radius: 50%;
background: #fff;
font: 500 12px/1 var(--tb-font, Roboto, sans-serif);
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
.mat-icon {
width: 16px;
height: 16px;
font-size: 16px;
color: inherit;
}
}
li.done .tb-sgs-mark {
border-color: transparent;
background: var(--tb-ok-tint, rgba(25, 128, 56, 0.08));
color: var(--tb-ok, #198038);
}
li.skipped .tb-sgs-mark {
background: rgba(0, 0, 0, 0.05);
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
}
.tb-sgs-title {
display: flex;
flex: 1;
align-items: center;
justify-content: space-between;
gap: 8px;
min-width: 0;
height: 36px;
margin: 0;
padding: 0;
border: 0;
border-radius: 6px;
background: none;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
text-align: left;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
cursor: pointer;
&:focus-visible {
outline: 2px solid var(--tb-primary-500);
outline-offset: 2px;
}
}
.tb-sgs-title-text {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
li.open .tb-sgs-title {
font-weight: 500;
}
li.done:not(.open) .tb-sgs-title {
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-sgs-state {
flex: none;
font: 400 12px/16px var(--tb-font, Roboto, sans-serif);
white-space: nowrap;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-sgs-body {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 8px;
min-width: 0;
padding: 0 12px 8px 40px;
p {
margin: 0;
font: 400 13px/18px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
}
.tb-sgs-head {
display: none;
}
.tb-sgs-guide {
border-radius: 4px;
font-weight: 500;
text-decoration: underline;
text-decoration-thickness: 1px;
text-underline-offset: 3px;
text-decoration-color: transparent;
white-space: nowrap;
color: var(--tb-primary-500);
transition: text-decoration-color .15s ease;
&, &:hover, &:focus, &:active {
border-bottom: none;
}
&:hover {
text-decoration-color: currentColor;
}
.mat-icon {
width: 14px;
height: 14px;
margin-left: 2px;
font-size: 14px;
line-height: 14px;
vertical-align: -2px;
}
}
.tb-sgs-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 4px 8px;
}
.tb-sgs-spacer {
flex: 1 1 auto;
min-width: 0;
}
.tb-sgs-action.mdc-button {
height: 32px;
padding: 0 16px;
border-radius: 4px;
}
.tb-sgs-action.mat-mdc-outlined-button {
--mdc-outlined-button-outline-color: rgba(0, 0, 0, 0.1);
--mat-outlined-button-outline-color: rgba(0, 0, 0, 0.1);
--mdc-outlined-button-label-text-color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
--mat-outlined-button-label-text-color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
background: #fff;
}
.tb-sgs-skip.mat-mdc-button, .tb-sgs-close.mat-mdc-outlined-button {
--mdc-text-button-label-text-color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
--mat-text-button-label-text-color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
--mdc-outlined-button-label-text-color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
--mat-outlined-button-label-text-color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
height: 32px;
}
.tb-sgs-skip.mat-mdc-button {
margin-right: -8px;
padding: 0 8px;
}
.tb-sgs-finish {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
font: 400 13px/18px var(--tb-font, Roboto, sans-serif);
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
}
.tb-sgs-close.mat-mdc-outlined-button {
flex: none;
padding: 0 16px;
border-radius: 4px;
}
@container tb-get-started-sys-admin (min-width: 600px) {
.tb-sgs-steps {
position: relative;
padding-right: 54%;
}
.tb-sgs-body {
position: absolute;
top: 0;
right: 0;
bottom: 0;
display: flex;
flex-direction: column;
gap: 12px;
box-sizing: border-box;
width: calc(54% - 16px);
padding: 14px 16px;
border-radius: 10px;
background: rgba(0, 0, 0, 0.03);
p {
max-width: 52ch;
font-size: 14px;
line-height: 22px;
letter-spacing: 0.1px;
}
}
.tb-sgs-head {
display: flex;
flex-direction: column;
gap: 2px;
}
.tb-sgs-head-n {
font: 400 12px/16px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.4px;
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
}
.tb-sgs-head-t {
font: 500 16px/24px var(--tb-font, Roboto, sans-serif);
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
.tb-sgs-actions {
margin-top: auto;
padding-top: 4px;
}
.tb-sgs-action.mdc-button, .tb-sgs-skip.mat-mdc-button {
height: 36px;
}
li.open .tb-sgs-title-text {
white-space: normal;
}
}

188
ui-ngx/src/app/modules/home/pages/home-page/components/get-started-sys-admin-home.component.ts

@ -0,0 +1,188 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import {
ChangeDetectionStrategy,
Component,
computed,
DestroyRef,
ElementRef,
inject,
NgZone,
signal
} from '@angular/core';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { AppState } from '@core/core.state';
import { ActionPreferencesUpdateHomeCards } from '@core/auth/auth.actions';
import { UserSettingsService } from '@core/http/user-settings.service';
import { WhiteLabelingService } from '@core/http/white-labeling.service';
import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service';
import { EntityCountCmd, TelemetrySubscriber } from '@shared/models/telemetry/telemetry.models';
import { AliasFilterType } from '@shared/models/alias.models';
import { EntityType } from '@shared/models/entity-type.models';
import { FeaturesInfo } from '@shared/models/settings.models';
import { HomeCardId } from '@shared/models/user-settings.models';
import { HOME_CARDS } from '@home/pages/home-page/home-cards.models';
import { SysAdminHomeService } from '@home/pages/home-page/sys-admin-home.service';
type SysAdminStepKey = 'tenant' | 'email' | 'sms' | 'wl' | '2fa' | 'oauth' | 'slack';
export interface SysAdminStep {
key: SysAdminStepKey;
needed: boolean;
link: string;
queryParams?: Record<string, string>;
guide: string;
feature?: keyof FeaturesInfo;
}
const STEPS: SysAdminStep[] = [
{key: 'tenant', needed: true, link: '/tenants', queryParams: {action: 'add'}, guide: 'user-guide/multi-tenancy/'},
{key: 'email', needed: true, link: '/settings/outgoing-mail', guide: 'user-guide/ui/mail-settings/', feature: 'emailEnabled'},
{key: 'sms', needed: false, link: '/settings/notifications', guide: 'user-guide/ui/sms-provider-settings/', feature: 'smsEnabled'},
{key: 'wl', needed: false, link: '/white-labeling/whiteLabel', guide: 'user-guide/white-labeling/', feature: 'whiteLabelingEnabled'},
{key: '2fa', needed: false, link: '/security-settings/2fa', guide: 'user-guide/security/two-factor-authentication/',
feature: 'twoFaEnabled'},
{key: 'oauth', needed: false, link: '/security-settings/oauth2', guide: 'user-guide/security/oauth-2-support/', feature: 'oauthEnabled'},
{key: 'slack', needed: false, link: '/settings/notifications', guide: 'user-guide/ui/slack-settings/', feature: 'notificationEnabled'}
];
const LOADING_HEIGHT = 398;
const HEIGHT_KEY = 'tb-home-get-started-sys-admin-height';
const storedHeight = (): number => {
try {
return Number(localStorage.getItem(HEIGHT_KEY)) || LOADING_HEIGHT;
} catch {
return LOADING_HEIGHT;
}
};
export type StepState = 'done' | 'skipped' | 'todo';
@Component({
selector: 'tb-get-started-sys-admin-home',
templateUrl: './get-started-sys-admin-home.component.html',
styleUrls: ['./get-started-sys-admin-home.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class GetStartedSysAdminHomeComponent {
private readonly card = HOME_CARDS[HomeCardId.GET_STARTED_SYS_ADMIN];
readonly total = STEPS.length;
readonly groups = [
{label: 'home.get-started-sys-admin.before-tenants', steps: STEPS.filter(step => step.needed)},
{label: 'home.get-started-sys-admin.when-needed', steps: STEPS.filter(step => !step.needed)}
];
private store = inject(Store<AppState>);
private translate = inject(TranslateService);
private userSettingsService = inject(UserSettingsService);
private readonly docs = inject(WhiteLabelingService).getDocsUrl();
private readonly tenants = signal<number | null>(null);
private readonly features = signal<FeaturesInfo | null>(null);
private readonly skipped = signal<string[] | null>(null);
private readonly selected = signal<SysAdminStepKey | '-' | null>(null);
readonly loaded = computed(() => this.tenants() !== null && this.features() !== null && this.skipped() !== null);
readonly cardDefinition = computed(() => this.loaded() ? this.card : {...this.card, height: storedHeight()});
readonly states = computed<Record<SysAdminStepKey, StepState>>(() => {
const features = this.features();
const skipped = this.skipped() ?? [];
return Object.fromEntries(STEPS.map(step => {
const done = step.key === 'tenant' ? !!this.tenants() : !!features?.[step.feature];
let state: StepState = 'todo';
if (done) {
state = 'done';
} else if (!step.needed && skipped.includes(step.key)) {
state = 'skipped';
}
return [step.key, state];
})) as Record<SysAdminStepKey, StepState>;
});
readonly doneCount = computed(() => STEPS.filter(step => this.states()[step.key] === 'done').length);
readonly progress = computed(() => this.doneCount()
? this.translate.instant('home.get-started-sys-admin.progress', {done: this.doneCount(), total: STEPS.length}) : null);
readonly finished = computed(() => this.loaded() && STEPS.every(step => ['done', 'skipped'].includes(this.states()[step.key])));
readonly open = computed<SysAdminStep | null>(() => {
const selected = this.selected();
if (selected === '-') {
return null;
}
return STEPS.find(step => step.key === selected) ?? STEPS.find(step => this.states()[step.key] === 'todo') ?? null;
});
readonly tenantCount = computed(() => this.tenants() ?? 0);
constructor() {
const config = {ignoreErrors: true, ignoreLoading: true};
inject(SysAdminHomeService).featuresInfo$.subscribe(features => this.features.set(features ?? {} as FeaturesInfo));
this.userSettingsService.getGettingStarted(config).pipe(catchError(() => of(null)))
.subscribe(settings => this.skipped.set(settings?.skipped ?? []));
const cmd = new EntityCountCmd();
cmd.query = {entityFilter: {type: AliasFilterType.entityType, entityType: EntityType.TENANT}};
const subscriber = new TelemetrySubscriber(inject(TelemetryWebsocketService), inject(NgZone));
subscriber.subscriptionCommands.push(cmd);
subscriber.entityCount$.subscribe(update => this.tenants.set(update.count ?? 0));
subscriber.subscribe();
const host = inject<ElementRef<HTMLElement>>(ElementRef);
const observer = new ResizeObserver(() => this.rememberHeight(host.nativeElement));
observer.observe(host.nativeElement);
inject(DestroyRef).onDestroy(() => {
subscriber.unsubscribe();
observer.disconnect();
});
}
state(step: SysAdminStep): StepState {
return this.states()[step.key];
}
number(step: SysAdminStep): number {
return STEPS.indexOf(step) + 1;
}
docUrl(step: SysAdminStep): string {
return this.docs + step.guide;
}
toggle(step: SysAdminStep): void {
this.selected.set(this.open() === step ? '-' : step.key);
}
skip(step: SysAdminStep): void {
const skipped = this.skipped() ?? [];
const next = skipped.includes(step.key) ? skipped.filter(key => key !== step.key) : [...skipped, step.key];
this.skipped.set(next);
this.selected.set(null);
this.userSettingsService.updateGettingStarted({skipped: next}).subscribe();
}
private rememberHeight(element: HTMLElement): void {
const height = Math.round(element.getBoundingClientRect().height);
if (!this.loaded() || !height) {
return;
}
try {
localStorage.setItem(HEIGHT_KEY, String(height));
} catch {
return;
}
}
close(): void {
this.store.dispatch(new ActionPreferencesUpdateHomeCards({[HomeCardId.GET_STARTED_SYS_ADMIN]: false}));
}
}

2
ui-ngx/src/app/modules/home/pages/home-page/components/home-card.component.scss

@ -111,7 +111,7 @@
padding-top: var(--tb-home-card-hideable-top, 16px);
.tb-home-card-header {
min-height: 32px;
min-height: var(--tb-home-card-hideable-header, 32px);
flex-wrap: nowrap;
}
}

45
ui-ngx/src/app/modules/home/pages/home-page/components/install-items-home.component.html

@ -0,0 +1,45 @@
<!--
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
SPDX-License-Identifier: BUSL-1.1
-->
<tb-home-card [card]="card">
<ng-container homeCardActions>
<a mat-button color="primary" class="tb-install-add" routerLink="/tenants" [queryParams]="{action: 'add'}">
<mat-icon>add</mat-icon>{{ 'home.install.add-tenant' | translate }}
</a>
</ng-container>
<div class="tb-install-counts">
@for (item of counts; track item.entityType) {
@let count = item.count();
@if (item.link && count) {
<a class="tb-home-tile" [routerLink]="item.link">
<span class="tb-home-tile-label">{{ item.label | translate }}</span>
<span class="tb-home-tile-count">{{ count | shortNumber }}</span>
</a>
} @else {
<div class="tb-home-tile static" [class.zero]="count === 0">
<span class="tb-home-tile-label">{{ item.label | translate }}</span>
<span class="tb-home-tile-count">{{ count === null ? '–' : (count | shortNumber) }}</span>
</div>
}
}
</div>
@if (withFeatures() && features().length) {
<div class="tb-install-head">
<span>{{ 'home.install.features' | translate }}</span>
<span class="tb-install-head-count">{{ 'home.install.features-count' | translate: {on: configured(), total: features().length} }}</span>
</div>
<div class="tb-install-features" role="list">
@for (feature of features(); track feature.key) {
<a class="tb-install-feature" role="listitem" [class.on]="feature.on" [routerLink]="feature.link"
[matTooltip]="(feature.on ? 'widgets.configured-features.feature-configured' : 'widgets.configured-features.feature-not-configured') | translate">
<mat-icon class="tb-install-feature-icon">{{ feature.on ? 'check_circle' : 'radio_button_unchecked' }}</mat-icon>
<span class="tb-install-feature-text">{{ feature.label | translate }}</span>
<span class="tb-home-sr-only">{{ (feature.on ? 'home.install.configured' : 'home.install.not-configured') | translate }}</span>
</a>
}
</div>
}
</tb-home-card>

157
ui-ngx/src/app/modules/home/pages/home-page/components/install-items-home.component.scss

@ -0,0 +1,157 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
@use './home-tiles';
@use './home-table';
:host {
display: block;
min-width: 0;
container: tb-install-home / inline-size;
}
.tb-install-add.mat-mdc-button {
&, &:hover, &:focus, &:active {
border-bottom: none;
}
.mat-icon {
margin-right: 6px;
}
}
.tb-install-counts {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
.tb-home-tile.tb-home-tile {
width: auto;
max-width: none;
height: 60px;
padding: 5px 10px;
text-decoration: none;
&, &:hover, &:focus, &:active {
border-bottom-style: solid;
}
&.static {
cursor: default;
&:hover {
border-color: rgba(0, 0, 0, 0.10);
}
}
&.zero {
border-style: dashed;
background: transparent;
&:hover {
border-style: dashed;
}
.tb-home-tile-label {
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
}
}
}
}
@container tb-install-home (max-width: 440px) {
.tb-install-counts {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
.tb-install-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 8px;
margin-top: 4px;
font: 500 12px/16px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.5px;
text-transform: uppercase;
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54));
}
.tb-install-head-count {
letter-spacing: 0.25px;
text-transform: none;
font-variant-numeric: tabular-nums;
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6));
}
.tb-install-features {
display: grid;
grid-template-columns: minmax(0, 1fr);
margin: 0 -8px;
}
.tb-install-feature {
display: flex;
align-items: center;
gap: 12px;
box-sizing: border-box;
min-width: 0;
height: 40px;
padding: 0 8px;
border: none;
border-radius: 6px;
text-decoration: none;
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
&:hover {
border: none;
background: rgba(0, 0, 0, 0.04);
}
&:focus-visible {
outline: 2px solid var(--tb-primary-500);
outline-offset: -2px;
}
}
.tb-install-feature-icon.mat-icon {
flex: none;
width: 20px;
height: 20px;
font-size: 20px;
color: var(--tb-ink-38, rgba(0, 0, 0, 0.38));
}
.tb-install-feature.on .tb-install-feature-icon.mat-icon {
color: var(--tb-primary-500);
}
.tb-install-feature-text {
min-width: 0;
overflow: hidden;
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.2px;
white-space: nowrap;
text-overflow: ellipsis;
}
@container tb-install-home (min-width: 260px) {
.tb-install-features {
grid-template-columns: repeat(2, minmax(0, 1fr));
column-gap: 12px;
clip-path: inset(1px -8px 0 -8px);
> .tb-install-feature {
position: relative;
&::before {
content: "";
position: absolute;
top: 0;
right: 8px;
left: 8px;
border-top: 1px solid var(--tb-line-soft, rgba(0, 0, 0, 0.05));
pointer-events: none;
}
}
}
}

84
ui-ngx/src/app/modules/home/pages/home-page/components/install-items-home.component.ts

@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, input, NgZone, signal, WritableSignal } from '@angular/core';
import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service';
import { EntityCountCmd, TelemetrySubscriber } from '@shared/models/telemetry/telemetry.models';
import { AliasFilterType } from '@shared/models/alias.models';
import { EntityType } from '@shared/models/entity-type.models';
import { FeaturesInfo } from '@shared/models/settings.models';
import { HomeCardId } from '@shared/models/user-settings.models';
import { HOME_CARDS } from '@home/pages/home-page/home-cards.models';
import { SysAdminHomeService } from '@home/pages/home-page/sys-admin-home.service';
interface InstallCount {
label: string;
entityType: EntityType;
link?: string;
count: WritableSignal<number | null>;
}
interface InstallFeature {
label: string;
key: keyof FeaturesInfo;
link: string;
}
const FEATURES: InstallFeature[] = [
{label: 'home.install.white-labeling', key: 'whiteLabelingEnabled', link: '/white-labeling/whiteLabel'},
{label: 'home.install.mail-server', key: 'emailEnabled', link: '/settings/outgoing-mail'},
{label: 'home.install.sms-provider', key: 'smsEnabled', link: '/settings/notifications'},
{label: 'home.install.slack', key: 'notificationEnabled', link: '/settings/notifications'},
{label: 'home.install.oauth', key: 'oauthEnabled', link: '/security-settings/oauth2'},
{label: 'home.install.two-fa', key: 'twoFaEnabled', link: '/security-settings/2fa'}
];
@Component({
selector: 'tb-install-items-home',
templateUrl: './install-items-home.component.html',
styleUrls: ['./install-items-home.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class InstallItemsHomeComponent {
withFeatures = input(true);
readonly card = HOME_CARDS[HomeCardId.INSTALL_ITEMS];
readonly counts: InstallCount[] = [
{label: 'home.install.tenants', entityType: EntityType.TENANT, link: '/tenants', count: signal(null)},
{label: 'home.install.tenant-profiles', entityType: EntityType.TENANT_PROFILE, link: '/tenantProfiles', count: signal(null)},
{label: 'home.install.users', entityType: EntityType.USER, count: signal(null)},
{label: 'home.install.customers', entityType: EntityType.CUSTOMER, count: signal(null)},
{label: 'home.install.dashboards', entityType: EntityType.DASHBOARD, count: signal(null)},
{label: 'home.install.integrations', entityType: EntityType.INTEGRATION, count: signal(null)}
];
private readonly featuresInfo = signal<FeaturesInfo | null>(null);
readonly features = computed(() => {
const info = this.featuresInfo();
if (!info) {
return [];
}
return FEATURES.map(feature => ({...feature, on: !!info[feature.key]}));
});
readonly configured = computed(() => this.features().filter(feature => feature.on).length);
constructor() {
inject(SysAdminHomeService).featuresInfo$.subscribe(info => this.featuresInfo.set(info));
const telemetryWsService = inject(TelemetryWebsocketService);
const zone = inject(NgZone);
const subscribers = this.counts.map(item => {
const cmd = new EntityCountCmd();
cmd.query = {entityFilter: {type: AliasFilterType.entityType, entityType: item.entityType}};
const subscriber = new TelemetrySubscriber(telemetryWsService, zone);
subscriber.subscriptionCommands.push(cmd);
subscriber.entityCount$.subscribe(update => item.count.set(update.count ?? 0));
subscriber.subscribe();
return subscriber;
});
inject(DestroyRef).onDestroy(() => subscribers.forEach(subscriber => subscriber.unsubscribe()));
}
}

16
ui-ngx/src/app/modules/home/pages/home-page/components/license-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-page/home-cards.models';
@Component({
selector: 'tb-license-home',
template: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class LicenseHomeComponent {
readonly card = HOME_CARDS[HomeCardId.LICENSE];
}

33
ui-ngx/src/app/modules/home/pages/home-page/components/product-release-home.component.html

@ -0,0 +1,33 @@
<!--
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
SPDX-License-Identifier: BUSL-1.1
-->
@if (shown()) {
<section class="tb-release" data-home-card="productRelease" [attr.aria-label]="'home.release.available' | translate">
<span class="tb-release-mark" aria-hidden="true">
<img src="/assets/license/tb-license-mark.svg" alt width="56" height="56">
<span class="tb-release-badge"><mat-icon>arrow_upward</mat-icon></span>
</span>
<div class="tb-release-body">
<h2 class="tb-release-title">{{ 'home.release.title' | translate: {version: update().latestVersion} }}</h2>
<p class="tb-release-line">
{{ 'home.release.read-notes' | translate }}
<a [href]="update().latestVersionReleaseNotesUrl" target="_blank" rel="noopener noreferrer">{{ 'home.release.notes' | translate }}</a>
</p>
<div class="tb-release-phone">
<a mat-flat-button color="primary" class="tb-release-upgrade" [href]="update().upgradeInstructionsUrl" target="_blank"
rel="noopener noreferrer">{{ 'home.release.upgrade' | translate }}</a>
</div>
</div>
<div class="tb-release-actions">
<a mat-flat-button color="primary" class="tb-release-upgrade" [href]="update().upgradeInstructionsUrl" target="_blank"
rel="noopener noreferrer">{{ 'home.release.upgrade' | translate }}</a>
<button mat-icon-button type="button" class="tb-release-hide" [matTooltip]="'home.release.hide' | translate"
[attr.aria-label]="'home.release.hide' | translate" (click)="hide()">
<mat-icon>close</mat-icon>
</button>
</div>
</section>
}

161
ui-ngx/src/app/modules/home/pages/home-page/components/product-release-home.component.scss

@ -0,0 +1,161 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
:host {
display: contents;
}
.tb-release {
position: relative;
display: flex;
align-items: center;
gap: 16px;
box-sizing: border-box;
min-width: 0;
padding: 20px;
border-radius: 12px;
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.2px;
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
}
.tb-release-mark {
position: relative;
display: inline-block;
flex: none;
width: 56px;
height: 56px;
> img {
display: block;
width: 100%;
height: 100%;
}
}
.tb-release-badge {
position: absolute;
top: -2px;
right: -2px;
display: flex;
align-items: center;
justify-content: center;
width: 34%;
height: 34%;
border-radius: 50%;
background: var(--tb-primary-500);
box-shadow: 0 0 0 2px var(--tb-surface, #fff);
.mat-icon {
width: auto;
height: auto;
font-size: 13px;
line-height: 1;
color: var(--tb-surface, #fff);
}
}
.tb-release-body {
display: flex;
flex: 1;
flex-direction: column;
min-width: 0;
}
.tb-release-title {
margin: 0;
font: 600 16px/24px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.15px;
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
}
.tb-release-line {
margin: 0;
font-size: 14px;
line-height: 20px;
letter-spacing: 0.2px;
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
a {
font-weight: 500;
white-space: nowrap;
text-decoration: none;
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76));
border-bottom: 1px solid var(--tb-ink-12, rgba(0, 0, 0, 0.12));
&:hover {
color: var(--tb-ink, rgba(0, 0, 0, 0.87));
border-bottom-color: currentColor;
}
}
}
.tb-release-actions {
display: flex;
flex: none;
align-items: center;
gap: 4px;
margin-right: -8px;
}
.tb-release-upgrade.mdc-button {
height: 32px;
padding: 0 16px;
border-radius: 4px;
}
.tb-release-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-text-secondary, rgba(0, 0, 0, 0.6));
.mat-icon {
width: 20px;
height: 20px;
font-size: 20px;
}
}
.tb-release-phone {
display: none;
}
@media (max-width: 599px) {
.tb-release {
align-items: flex-start;
gap: 12px;
padding-right: 44px;
}
.tb-release-mark {
width: 40px;
height: 40px;
.tb-release-badge .mat-icon {
font-size: 10px;
}
}
.tb-release-actions {
position: absolute;
top: 8px;
right: 8px;
margin: 0;
> .tb-release-upgrade {
display: none;
}
}
.tb-release-phone {
display: flex;
margin-top: 10px;
}
}

57
ui-ngx/src/app/modules/home/pages/home-page/components/product-release-home.component.ts

@ -0,0 +1,57 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { AdminService } from '@core/http/admin.service';
import { ToastNotificationService } from '@core/services/toast-notification.service';
import { UpdateMessage } from '@shared/models/settings.models';
const UNDO_MS = 6000;
let hiddenVersion: string | null = null;
@Component({
selector: 'tb-product-release-home',
templateUrl: './product-release-home.component.html',
styleUrls: ['./product-release-home.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ProductReleaseHomeComponent {
private translate = inject(TranslateService);
private toast = inject(ToastNotificationService);
readonly update = signal<UpdateMessage | null>(null);
private readonly hidden = signal<string | null>(hiddenVersion);
readonly shown = computed(() => {
const update = this.update();
return !!update?.updateAvailable && this.hidden() !== update.latestVersion;
});
constructor() {
inject(AdminService).checkUpdates({ignoreErrors: true, ignoreLoading: true}).subscribe(update => this.update.set(update));
}
hide(): void {
const version = this.update().latestVersion;
this.setHidden(version);
this.toast.dispatchNotification({
message: this.translate.instant('home.release.hidden', {version}),
type: 'info',
duration: UNDO_MS,
horizontalPosition: 'right',
verticalPosition: 'bottom',
panelClass: 'tb-home-toast',
actionLabel: this.translate.instant('home.customize.undo'),
onAction: () => this.setHidden(null)
});
}
private setHidden(version: string | null): void {
hiddenVersion = version;
this.hidden.set(version);
}
}

18
ui-ngx/src/app/modules/home/pages/home-page/components/status-line-home.component.scss

@ -63,3 +63,21 @@
.warn .tb-status-dot {
background: rgb(246, 103, 22);
}
.tb-status-line-reserved {
min-height: 32px;
}
.tb-status-line-in {
animation: tb-status-line-in .2s ease both;
@media (prefers-reduced-motion: reduce) {
animation: none;
}
}
@keyframes tb-status-line-in {
from {
opacity: 0;
}
}

237
ui-ngx/src/app/modules/home/pages/home-page/components/status-line-home.component.ts

@ -1,34 +1,64 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, NgZone, signal, WritableSignal } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, DestroyRef, effect, 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 { AlarmCountCmd, EntityCountCmd, EntityDataCmd, 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';
import { AdminService } from '@core/http/admin.service';
import { SysAdminHomeService } from '@home/pages/home-page/sys-admin-home.service';
import { TranslateService } from '@ngx-translate/core';
import { FeaturesInfo } from '@shared/models/settings.models';
import { SubscriptionInfo } from '@shared/models/subscription.models';
import { of } from 'rxjs';
import { catchError, take } from 'rxjs/operators';
type StatusKind = 'crit' | 'warn' | 'ok';
interface StatusPart {
key: string;
params?: Record<string, unknown>;
card?: HomeCardId;
cards?: HomeCardId[];
link?: string;
}
type SystemMetric = 'cpu' | 'ram' | 'disk';
interface SystemLoad {
metric: SystemMetric;
value: number;
services: string[];
}
interface ClusterService {
serviceId: string;
cpuUsage: number;
memoryUsage: number;
discUsage: number;
}
const SYSTEM_KEYS = ['cpuUsage', 'memoryUsage', 'discUsage', 'clusterMode', 'clusterSystemData'];
const METRIC_KEYS: Record<SystemMetric, 'cpuUsage' | 'memoryUsage' | 'discUsage'> = {cpu: 'cpuUsage', ram: 'memoryUsage', disk: 'discUsage'};
const METRIC_NAMES: Record<SystemMetric, string> = {cpu: 'CPU', ram: 'RAM', disk: 'Disk'};
const LICENSE_NEAR = 0.85;
const WARN_LOAD = 75;
const CRIT_LOAD = 85;
const loadLevel = (value: number): StatusKind => value > CRIT_LOAD ? 'crit' : value > WARN_LOAD ? 'warn' : 'ok';
@Component({
selector: 'tb-status-line-home',
template: `
@if (parts().length) {
<div class="tb-status-line" [class]="kind()">
<div class="tb-status-line tb-status-line-in" [class]="kind()">
@for (part of parts(); track part.key; let first = $first) {
<span class="tb-pill">
@if (first) {
@ -38,7 +68,7 @@ interface StatusPart {
<span class="tb-status-dot"></span>
}
}
@if (part.link) {
@if (part.link || part.cards) {
<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>
@ -46,6 +76,8 @@ interface StatusPart {
</span>
}
</div>
} @else if (reserve && !resolved()) {
<div class="tb-status-line tb-status-line-reserved" aria-hidden="true"></div>
}
`,
styleUrls: ['./status-line-home.component.scss'],
@ -59,7 +91,20 @@ export class StatusLineHomeComponent {
private router = inject(Router);
private store = inject(Store<AppState>);
private readonly customer = getCurrentAuthUser(this.store)?.authority === Authority.CUSTOMER_USER;
private translate = inject(TranslateService);
private readonly authority = getCurrentAuthUser(this.store)?.authority;
private readonly customer = this.authority === Authority.CUSTOMER_USER;
readonly sysAdmin = this.authority === Authority.SYS_ADMIN;
private readonly shownKey = `tb-home-status-line:${getCurrentAuthUser(this.store)?.userId}`;
readonly reserve = this.authority !== Authority.TENANT_ADMIN || this.wasShown();
private systemLoad = signal<SystemLoad | null>(null);
private subscription = signal<SubscriptionInfo | null | undefined>(undefined);
private features = signal<FeaturesInfo | null | undefined>(undefined);
private tenants = signal<number | null>(null);
private critical = signal<number | null>(null);
private active = signal<number | null>(null);
@ -68,7 +113,15 @@ export class StatusLineHomeComponent {
private subscribers: TelemetrySubscriber[] = [];
readonly parts = computed<StatusPart[]>(() => {
readonly parts = computed<StatusPart[]>(() => this.sysAdmin ? this.sysAdminParts() : this.tenantParts());
readonly resolved = computed(() => this.sysAdmin
? !!this.systemLoad() && this.subscription() !== undefined && this.tenants() !== null
: [this.critical(), this.active(), this.devices(), this.inactive()].every(value => value !== null));
readonly kind = computed<StatusKind>(() => this.sysAdmin ? this.sysAdminKind() : this.critical() ? 'crit' : this.inactive() ? 'warn' : 'ok');
private tenantParts(): StatusPart[] {
const critical = this.critical();
const active = this.active();
const devices = this.devices();
@ -81,23 +134,96 @@ export class StatusLineHomeComponent {
}
const parts: StatusPart[] = [];
if (critical) {
parts.push({key: 'home.status.critical-alarms', params: {count: critical}, card: HomeCardId.ALARMS, link: '/alarms'});
parts.push({key: 'home.status.critical-alarms', params: {count: critical}, cards: [HomeCardId.ALARMS], link: '/alarms'});
} else if (active) {
parts.push({key: 'home.status.active-alarms', params: {count: active}, card: HomeCardId.ALARMS, link: '/alarms'});
parts.push({key: 'home.status.active-alarms', params: {count: active}, cards: [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'});
parts.push({key: 'home.status.inactive-devices', params: {count: inactive}, cards: [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;
});
}
private sysAdminParts(): StatusPart[] {
const load = this.systemLoad();
const subscription = this.subscription();
const features = this.features();
const tenants = this.tenants();
if (!load || subscription === undefined || tenants === null) {
return [];
}
const parts: StatusPart[] = [];
if (loadLevel(load.value) === 'ok') {
parts.push({key: 'home.status.system-ok'});
} else {
const params = {name: METRIC_NAMES[load.metric], value: Math.round(load.value)};
if (!load.services.length) {
parts.push({key: 'home.status.system-high', params, cards: [HomeCardId.SYSTEM_STATUS]});
} else if (load.services.length === 1) {
parts.push({key: 'home.status.system-high-on', params: {...params, service: load.services[0]}, cards: [HomeCardId.SYSTEM_STATUS]});
} else {
parts.push({key: 'home.status.system-high-services', params: {...params, count: load.services.length}, cards: [HomeCardId.SYSTEM_STATUS]});
}
}
const near = this.licenseNear(subscription);
if (near.length) {
parts.push({key: 'home.status.license-near', params: {items: near.join(', ')}, cards: [HomeCardId.LICENSE], link: '/license'});
}
if (!tenants) {
parts.push({key: 'home.status.no-tenants', cards: [HomeCardId.GET_STARTED_SYS_ADMIN], link: '/tenants'});
} else if (features) {
const off = [features.whiteLabelingEnabled, features.emailEnabled,
features.smsEnabled, features.notificationEnabled, features.oauthEnabled, features.twoFaEnabled].filter(enabled => !enabled).length;
if (off) {
parts.push({key: 'home.status.features-off', params: {count: off},
cards: [HomeCardId.GET_STARTED_SYS_ADMIN, HomeCardId.INSTALL_ITEMS]});
}
}
return parts;
}
readonly kind = computed<StatusKind>(() => this.critical() ? 'crit' : this.inactive() ? 'warn' : 'ok');
private sysAdminKind(): StatusKind {
const load = this.systemLoad();
const level = load ? loadLevel(load.value) : 'ok';
if (level === 'crit') {
return 'crit';
}
const subscription = this.subscription();
return level === 'warn' || (subscription && this.licenseNear(subscription).length) ? 'warn' : 'ok';
}
private licenseNear(subscription: SubscriptionInfo | null): string[] {
if (!subscription) {
return [];
}
const items: [string, number, number][] = [
['home.status.license-devices', subscription.devicesCount, subscription.maxDevices],
['home.status.license-assets', subscription.assetsCount, subscription.maxAssets],
['home.status.license-ai-credits', subscription.usedAiCredits, subscription.maxAiCredits]
];
return items.filter(([, used, max]) => max > 0 && (used ?? 0) / max >= LICENSE_NEAR)
.map(([key, used, max]) => this.translate.instant(key, {percent: Math.round(used / max * 100)}));
}
constructor() {
inject(DestroyRef).onDestroy(() => this.subscribers.forEach(subscriber => subscriber.unsubscribe()));
effect(() => {
if (this.resolved()) {
this.rememberShown(this.parts().length > 0);
}
});
if (this.sysAdmin) {
this.watchSysAdmin();
} else {
this.watchTenant();
}
}
private watchTenant(): void {
this.store.select(selectPersistDeviceStateToTelemetry).pipe(take(1)).subscribe(persisted => {
const activeKeyType = persisted ? EntityKeyType.TIME_SERIES : EntityKeyType.SERVER_ATTRIBUTE;
this.countAlarms(this.critical, [AlarmSeverity.CRITICAL]);
@ -113,11 +239,26 @@ export class StatusLineHomeComponent {
}
}]);
});
inject(DestroyRef).onDestroy(() => this.subscribers.forEach(subscriber => subscriber.unsubscribe()));
}
private wasShown(): boolean {
try {
return localStorage.getItem(this.shownKey) === '1';
} catch {
return false;
}
}
private rememberShown(shown: boolean): void {
try {
localStorage.setItem(this.shownKey, shown ? '1' : '0');
} catch {
return;
}
}
open(part: StatusPart): void {
const card = part.card ? document.querySelector(`[data-home-card="${part.card}"]`) : null;
const card = (part.cards ?? []).map(id => document.querySelector(`[data-home-card="${id}"]`)).find(element => !!element);
if (card) {
card.scrollIntoView({behavior: 'smooth', block: 'center'});
} else if (part.link) {
@ -137,10 +278,74 @@ export class StatusLineHomeComponent {
subscriber.subscribe();
}
private watchSysAdmin(): void {
const adminService = inject(AdminService);
const config = {ignoreErrors: true, ignoreLoading: true};
adminService.getSubscriptionInfo(config).pipe(catchError(() => of(null))).subscribe(info => this.subscription.set(info));
const sysAdminHome = inject(SysAdminHomeService, {optional: true});
(sysAdminHome ? sysAdminHome.featuresInfo$ : adminService.getFeaturesInfo(config).pipe(catchError(() => of(null))))
.subscribe(info => this.features.set(info));
this.countEntities(this.tenants, EntityType.TENANT);
const keys = SYSTEM_KEYS.map(key => ({type: EntityKeyType.TIME_SERIES, key}));
const cmd = new EntityDataCmd();
cmd.query = {
entityFilter: {type: AliasFilterType.apiUsageState},
pageLink: {page: 0, pageSize: 1},
entityFields: [],
latestValues: keys
};
cmd.latestCmd = {keys};
const values: Record<string, string> = {};
const subscriber = new TelemetrySubscriber(this.telemetryWsService, this.zone);
subscriber.subscriptionCommands.push(cmd);
this.subscribers.push(subscriber);
subscriber.entityData$.subscribe(update => {
const entity = (update.data?.data ?? update.update ?? [])[0];
SYSTEM_KEYS.forEach(key => {
const latest = entity?.latest?.[EntityKeyType.TIME_SERIES]?.[key];
if (latest?.ts) {
values[key] = latest.value;
}
});
if (entity || update.data) {
this.systemLoad.set(this.toSystemLoad(values));
}
});
subscriber.subscribe();
}
private toSystemLoad(values: Record<string, string>): SystemLoad {
const metrics = Object.keys(METRIC_KEYS) as SystemMetric[];
if (values.clusterMode === 'true' && values.clusterSystemData) {
let services: ClusterService[] = [];
try {
services = JSON.parse(values.clusterSystemData);
} catch {
services = [];
}
if (services.length) {
const loads = metrics.flatMap(metric => services.map(service =>
({metric, value: Number(service[METRIC_KEYS[metric]]) || 0, service: service.serviceId})));
const worst = loads.reduce((top, load) => load.value > top.value ? load : top);
return {
metric: worst.metric,
value: worst.value,
services: loads.filter(load => load.metric === worst.metric && load.value === worst.value).map(load => load.service)
};
}
}
return metrics.map(metric => ({metric, value: Number(values[METRIC_KEYS[metric]]) || 0, services: []}))
.reduce((top, load) => load.value > top.value ? load : top);
}
private countDevices(target: WritableSignal<number | null>, keyFilters?: KeyFilter[]): void {
this.countEntities(target, EntityType.DEVICE, keyFilters);
}
private countEntities(target: WritableSignal<number | null>, entityType: EntityType, keyFilters?: KeyFilter[]): void {
const cmd = new EntityCountCmd();
cmd.query = {
entityFilter: {type: AliasFilterType.entityType, entityType: EntityType.DEVICE},
entityFilter: {type: AliasFilterType.entityType, entityType},
keyFilters
};
const subscriber = this.subscribe(cmd);

16
ui-ngx/src/app/modules/home/pages/home-page/components/system-status-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-page/home-cards.models';
@Component({
selector: 'tb-system-status-home',
template: `<tb-home-card [card]="card"></tb-home-card>`,
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class SystemStatusHomeComponent {
readonly card = HOME_CARDS[HomeCardId.SYSTEM_STATUS];
}

7
ui-ngx/src/app/modules/home/pages/home-page/home-cards.models.ts

@ -21,7 +21,12 @@ export const HOME_CARDS: Record<HomeCardId, HomeCardDefinition> = {
link: '/notification/inbox'},
[HomeCardId.QUICK_LINKS]: {id: HomeCardId.QUICK_LINKS, icon: 'link', name: 'home.cards.quick-links'},
[HomeCardId.USAGE]: {id: HomeCardId.USAGE, icon: 'data_usage', name: 'home.cards.usage', link: '/usage'},
[HomeCardId.MOBILE_APP]: {id: HomeCardId.MOBILE_APP, icon: 'phone_iphone', name: 'home.cards.mobile-app'}
[HomeCardId.MOBILE_APP]: {id: HomeCardId.MOBILE_APP, icon: 'phone_iphone', name: 'home.cards.mobile-app'},
[HomeCardId.PRODUCT_RELEASE]: {id: HomeCardId.PRODUCT_RELEASE, icon: 'new_releases', name: 'home.cards.product-release', height: 100},
[HomeCardId.GET_STARTED_SYS_ADMIN]: {id: HomeCardId.GET_STARTED_SYS_ADMIN, icon: 'rocket_launch', name: 'home.cards.get-started'},
[HomeCardId.SYSTEM_STATUS]: {id: HomeCardId.SYSTEM_STATUS, icon: 'dns', name: 'home.cards.system-status', height: 304},
[HomeCardId.LICENSE]: {id: HomeCardId.LICENSE, icon: 'verified', name: 'home.cards.license', link: '/license', height: 398},
[HomeCardId.INSTALL_ITEMS]: {id: HomeCardId.INSTALL_ITEMS, icon: 'domain', name: 'home.cards.install-items'}
};
export const isHomeCardShown = (settings: HomeCardsSettings, id: HomeCardId): boolean => settings?.[id] !== false;

97
ui-ngx/src/app/modules/home/pages/home-page/home-page-routing.module.ts

@ -9,89 +9,14 @@ import { Authority } from '@shared/models/authority.enum';
import { mergeMap, Observable, of } from 'rxjs';
import { HomeDashboard } from '@shared/models/dashboard.models';
import { DashboardService } from '@core/http/dashboard.service';
import { select, Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { catchError, first, map } from 'rxjs/operators';
import {
getCurrentAuthUser,
selectHomeDashboardParams,
selectMobileQrEnabled,
selectPersistDeviceStateToTelemetry
} from '@core/auth/auth.selectors';
import { EntityKeyType } from '@shared/models/query/query.models';
import { ResourcesService } from '@core/services/resources.service';
import { isDefinedAndNotNull } from '@core/utils';
import { MenuId } from '@core/services/menu.models';
import { MenuService } from '@core/services/menu.service';
const sysAdminHomePageJson = '/assets/dashboard/sys_admin_home_page.json';
// const customerUserHomePageJson = '/assets/dashboard/customer_user_home_page.json';
const getHomeDashboard = (store: Store<AppState>, resourcesService: ResourcesService) => {
const authority = getCurrentAuthUser(store).authority;
switch (authority) {
case Authority.SYS_ADMIN:
return applySystemParametersToHomeDashboard(store, resourcesService.loadJsonResource(sysAdminHomePageJson), authority);
// case Authority.CUSTOMER_USER:
// return applySystemParametersToHomeDashboard(store, resourcesService.loadJsonResource(customerUserHomePageJson), authority);
default:
return of(null);
}
};
const applySystemParametersToHomeDashboard = (store: Store<AppState>,
dashboard$: Observable<HomeDashboard>,
authority: Authority): Observable<HomeDashboard> => {
let selectParams$: Observable<{persistDeviceStateToTelemetry?: boolean; mobileQrEnabled?: boolean}>;
switch (authority) {
case Authority.SYS_ADMIN:
selectParams$ = store.pipe(
select(selectMobileQrEnabled),
map(mobileQrEnabled => ({mobileQrEnabled}))
);
break;
case Authority.TENANT_ADMIN:
selectParams$ = store.pipe(select(selectHomeDashboardParams));
break;
case Authority.CUSTOMER_USER:
selectParams$ = store.pipe(
select(selectPersistDeviceStateToTelemetry),
map(persistDeviceStateToTelemetry => ({persistDeviceStateToTelemetry}))
);
break;
}
return selectParams$.pipe(
mergeMap((params) => dashboard$.pipe(
map((dashboard) => {
if (params.persistDeviceStateToTelemetry) {
for (const filterId of Object.keys(dashboard.configuration.filters)) {
if (['Active Devices', 'Inactive Devices'].includes(dashboard.configuration.filters[filterId].filter)) {
dashboard.configuration.filters[filterId].keyFilters[0].key.type = EntityKeyType.TIME_SERIES;
}
}
}
if (isDefinedAndNotNull(params.mobileQrEnabled)) {
for (const widgetId of Object.keys(dashboard.configuration.widgets)) {
if (dashboard.configuration.widgets[widgetId].config.title === 'Select show mobile QR code') {
dashboard.configuration.widgets[widgetId].config.settings.markdownTextFunction =
(dashboard.configuration.widgets[widgetId].config.settings.markdownTextFunction as string)
.replace(/\${mobileQrEnabled:([^}]+)}/, `\${mobileQrEnabled:${String(params.mobileQrEnabled)}}`);
break;
}
}
}
dashboard.hideDashboardToolbar = true;
dashboard.isSystemDashboard = true;
return dashboard;
})
))
);
};
const getHomeDashboard = (): Observable<HomeDashboard> => of(null);
const resolveMenuHomeDashboard = (menuService: MenuService,
dashboardService: DashboardService,
resourcesService: ResourcesService,
store: Store<AppState>): Observable<HomeDashboard> =>
dashboardService: DashboardService): Observable<HomeDashboard> =>
menuService.menuSections().pipe(first()).pipe(
mergeMap((sections) => {
const homeSection = sections.find(s => s.id === MenuId.home);
@ -101,36 +26,32 @@ const resolveMenuHomeDashboard = (menuService: MenuService,
...dashboard,
hideDashboardToolbar: homeSection.homeHideDashboardToolbar
})),
catchError(() => getHomeDashboard(store, resourcesService))
catchError(() => getHomeDashboard())
);
} else {
return getHomeDashboard(store, resourcesService);
return getHomeDashboard();
}
})
);
const resolveHomeDashboard = (menuService: MenuService,
dashboardService: DashboardService,
resourcesService: ResourcesService,
store: Store<AppState>): Observable<HomeDashboard> =>
dashboardService: DashboardService): Observable<HomeDashboard> =>
dashboardService.getHomeDashboard().pipe(
mergeMap((dashboard) => {
if (!dashboard) {
return resolveMenuHomeDashboard(menuService, dashboardService, resourcesService, store);
return resolveMenuHomeDashboard(menuService, dashboardService);
}
return of(dashboard);
}),
catchError(() => resolveMenuHomeDashboard(menuService, dashboardService, resourcesService, store))
catchError(() => resolveMenuHomeDashboard(menuService, dashboardService))
);
export const homeDashboardResolver: ResolveFn<HomeDashboard> = (
_route: ActivatedRouteSnapshot,
_state: RouterStateSnapshot,
menuService = inject(MenuService),
dashboardService = inject(DashboardService),
resourcesService = inject(ResourcesService),
store: Store<AppState> = inject(Store<AppState>)
): Observable<HomeDashboard> => resolveHomeDashboard(menuService, dashboardService, resourcesService, store);
dashboardService = inject(DashboardService)
): Observable<HomeDashboard> => resolveHomeDashboard(menuService, dashboardService);
const routes: Routes = [
{

12
ui-ngx/src/app/modules/home/pages/home-page/home-page.module.ts

@ -34,6 +34,11 @@ import { HomeHscrollComponent } from '@home/pages/home-page/components/home-hscr
import { HomeToggleComponent } from '@home/pages/home-page/components/home-toggle.component';
import { HomeListFooterComponent } from '@home/pages/home-page/components/home-list-footer.component';
import { AiStartHomeComponent } from '@home/pages/home-page/components/ai-start-home.component';
import { ProductReleaseHomeComponent } from '@home/pages/home-page/components/product-release-home.component';
import { GetStartedSysAdminHomeComponent } from '@home/pages/home-page/components/get-started-sys-admin-home.component';
import { SystemStatusHomeComponent } from '@home/pages/home-page/components/system-status-home.component';
import { LicenseHomeComponent } from '@home/pages/home-page/components/license-home.component';
import { InstallItemsHomeComponent } from '@home/pages/home-page/components/install-items-home.component';
import { AiModule } from '@home/components/ai/ai.module';
@NgModule({
@ -64,7 +69,12 @@ import { AiModule } from '@home/components/ai/ai.module';
HomeHscrollComponent,
HomeToggleComponent,
HomeListFooterComponent,
AiStartHomeComponent
AiStartHomeComponent,
ProductReleaseHomeComponent,
GetStartedSysAdminHomeComponent,
SystemStatusHomeComponent,
LicenseHomeComponent,
InstallItemsHomeComponent
],
imports: [
CommonModule,

84
ui-ngx/src/app/modules/home/pages/home-page/pages/sys-admin-home.component.ts

@ -1,19 +1,101 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component } from '@angular/core';
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, selectMobileQrEnabled } from '@core/auth/auth.selectors';
import { HomeCardId } from '@shared/models/user-settings.models';
import { isHomeCardShown } from '@home/pages/home-page/home-cards.models';
import { SysAdminHomeService } from '@home/pages/home-page/sys-admin-home.service';
const MAIN_CARDS = [HomeCardId.GET_STARTED_SYS_ADMIN, HomeCardId.SYSTEM_STATUS, HomeCardId.LICENSE, HomeCardId.ACTIVITY];
const SIDE_CARDS = [HomeCardId.NOTIFICATIONS, HomeCardId.INSTALL_ITEMS, HomeCardId.QUICK_LINKS, HomeCardId.MOBILE_APP];
@Component({
selector: 'tb-sys-admin-home',
template: `
<ng-template #homeCard let-id>
@switch (id) {
@case (HomeCardId.GET_STARTED_SYS_ADMIN) {
<tb-get-started-sys-admin-home></tb-get-started-sys-admin-home>
}
@case (HomeCardId.SYSTEM_STATUS) {
<tb-system-status-home></tb-system-status-home>
}
@case (HomeCardId.LICENSE) {
<tb-license-home></tb-license-home>
}
@case (HomeCardId.ACTIVITY) {
<tb-devices-activity-home></tb-devices-activity-home>
}
@case (HomeCardId.NOTIFICATIONS) {
<tb-notifications-home></tb-notifications-home>
}
@case (HomeCardId.INSTALL_ITEMS) {
<tb-install-items-home [withFeatures]="!getStartedShown()"></tb-install-items-home>
}
@case (HomeCardId.QUICK_LINKS) {
<tb-quick-links-home></tb-quick-links-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></tb-welcome-home>
<tb-status-line-home></tb-status-line-home>
</div>
<div class="tb-home-grid">
<div class="tb-col tb-col-main">
<tb-product-release-home></tb-product-release-home>
@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>
`,
styleUrls: ['./tenant-admin-home.component.scss'],
providers: [SysAdminHomeService],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class SysAdminHomeComponent {
readonly HomeCardId = HomeCardId;
private readonly store = inject(Store<AppState>);
private readonly settings = toSignal(this.store.select(selectHomeCards), {initialValue: {}});
private readonly mobileQrEnabled = toSignal(this.store.select(selectMobileQrEnabled), {initialValue: false});
readonly getStartedShown = computed(() => isHomeCardShown(this.settings(), HomeCardId.GET_STARTED_SYS_ADMIN));
readonly cards = computed(() => [...MAIN_CARDS, ...SIDE_CARDS].filter(id => this.available(id)));
readonly mainCards = computed(() => MAIN_CARDS.filter(id => this.shown(id)));
readonly sideCards = computed(() => SIDE_CARDS.filter(id => this.shown(id)));
constructor() {
inject(SysAdminHomeService).featuresInfo$.subscribe();
}
private available(id: HomeCardId): boolean {
return id !== HomeCardId.MOBILE_APP || this.mobileQrEnabled();
}
private shown(id: HomeCardId): boolean {
return this.available(id) && isHomeCardShown(this.settings(), id);
}
}

10
ui-ngx/src/app/modules/home/pages/home-page/quick-links.models.ts

@ -37,7 +37,15 @@ export const defaultQuickLinks = (authority: Authority, docsUrl: string, transla
const web = (id: string, name: string, icon: string, link: string) => ({[QUICK_WEB_LINK_PREFIX + id]: {name, icon, link}});
switch (authority) {
case Authority.SYS_ADMIN:
return {links: ['tenants', 'tenant_profiles']};
return {
links: ['getting-started', 'tenant-profiles', 'api', 'widgets-library'].map(id => QUICK_WEB_LINK_PREFIX + id),
webLinks: {
...web('getting-started', translate('home.quick-links.getting-started'), 'rocket_launch', docsUrl + 'getting-started/'),
...web('tenant-profiles', translate('home.quick-links.tenant-profiles'), 'account_box', docsUrl + 'user-guide/tenant-profiles/'),
...web('api', translate('home.quick-links.api'), 'api', docsUrl + 'apis-and-sdks/'),
...web('widgets-library', translate('home.quick-links.widgets-library'), 'widgets', docsUrl + 'reference/widgets/widget-library/')
}
};
case Authority.CUSTOMER_USER:
return {
links: ['assets', 'entity_views', 'notification_inbox', QUICK_WEB_LINK_PREFIX + 'user-guide'],

16
ui-ngx/src/app/modules/home/pages/home-page/sys-admin-home.service.ts

@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
import { inject, Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { catchError, shareReplay } from 'rxjs/operators';
import { AdminService } from '@core/http/admin.service';
import { FeaturesInfo } from '@shared/models/settings.models';
@Injectable()
export class SysAdminHomeService {
readonly featuresInfo$: Observable<FeaturesInfo | null> = inject(AdminService).getFeaturesInfo({ignoreErrors: true, ignoreLoading: true}).pipe(
catchError(() => of(null)),
shareReplay(1)
);
}

8
ui-ngx/src/app/shared/models/user-settings.models.ts

@ -35,7 +35,12 @@ export enum HomeCardId {
NOTIFICATIONS = 'notifications',
QUICK_LINKS = 'quickLinks',
USAGE = 'usage',
MOBILE_APP = 'mobileApp'
MOBILE_APP = 'mobileApp',
PRODUCT_RELEASE = 'productRelease',
GET_STARTED_SYS_ADMIN = 'getStartedSysAdmin',
SYSTEM_STATUS = 'systemStatus',
LICENSE = 'license',
INSTALL_ITEMS = 'installItems'
}
export type HomeCardsSettings = Partial<Record<HomeCardId, boolean>>;
@ -72,6 +77,7 @@ export interface QuickLinks {
export interface GettingStarted {
maxSelectedIndex?: number;
lastSelectedIndex?: number;
skipped?: string[];
}
export interface AbstractUserDashboardInfo {

100
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -8545,7 +8545,17 @@
"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"
"nothing-assigned": "No devices or dashboards assigned to you yet",
"system-ok": "CPU, RAM and disk under 75%",
"system-high": "{{name}} at {{value}}%",
"system-high-on": "{{name}} at {{value}}% on {{service}}",
"system-high-services": "{{name}} at {{value}}% on {{count}} services",
"license-near": "License: {{items}}",
"license-devices": "devices {{percent}}%",
"license-assets": "assets {{percent}}%",
"license-ai-credits": "AI credits {{percent}}%",
"no-tenants": "No tenants yet",
"features-off": "{ count, plural, =1 {1 feature not configured} other {# features not configured} }"
},
"greeting": {
"morning": "Good morning",
@ -8565,7 +8575,11 @@
"notifications": "Notifications",
"quick-links": "Quick links",
"usage": "Usage",
"mobile-app": "Mobile app"
"mobile-app": "Mobile app",
"product-release": "Product release",
"system-status": "System",
"license": "License",
"install-items": "Install"
},
"alarms": {
"whose": "Whose alarms",
@ -8661,7 +8675,8 @@
"devices": "Active devices",
"messages": "Messages",
"today": "Today",
"none": "No activity yet"
"none": "No activity yet",
"no-messages": "No messages from devices yet"
},
"get-started": {
"progress": "{{done}} of {{total}}",
@ -8723,6 +8738,10 @@
"opens-new-tab": "(opens in a new tab)",
"documentation": "Documentation",
"user-guide": "User guide",
"getting-started": "Getting started",
"tenant-profiles": "Tenant profiles",
"api": "API",
"widgets-library": "Widgets library",
"add-title": "Add quick link",
"edit-web-link": "Edit web link",
"link-type": "Link type",
@ -8757,6 +8776,81 @@
"download-on-the": "Download on the",
"get-it-on": "Get it on"
},
"release": {
"available": "Update available",
"title": "ThingsBoard {{version}} is available",
"read-notes": "Read the release notes before upgrading.",
"notes": "Release notes",
"upgrade": "Upgrade",
"hide": "Hide",
"hidden": "{{version}} hidden"
},
"get-started-sys-admin": {
"before-tenants": "Before tenants sign in",
"when-needed": "When you need them",
"progress": "{{done}} of {{total}}",
"tenants": "{ count, plural, =1 {1 tenant} other {# tenants} }",
"configured": "Configured",
"skipped": "Skipped",
"skip": "Skip",
"undo-skip": "Undo skip",
"finished": "Every step is done. Install's Features takes this place.",
"finished-skipped": "{{count}} skipped. Install's Features takes this place; each stays there to set up.",
"tenant": {
"title": "Create a tenant and its administrator",
"text": "A tenant owns devices and assets; its administrators create and manage its devices, assets, customers and dashboards.",
"action": "Add tenant"
},
"email": {
"title": "Mail server",
"text": "Mail server configuration is essential for user activation, password recovery, and alarm notification delivery.",
"action": "Open Mail server"
},
"sms": {
"title": "SMS provider",
"text": "Configure SMS providers to notify the customers about the alarms via SMS.",
"action": "Open Notifications settings"
},
"wl": {
"title": "White labeling",
"text": "Customize your company's or product's logo and color scheme without coding and without restarting the service.",
"action": "Open White labeling"
},
"2fa": {
"title": "Two-factor authentication (2FA)",
"text": "Improve security of the platform accounts with two-factor authentication.",
"action": "Open Two-factor authentication"
},
"oauth": {
"title": "OAuth 2.0 single sign-on",
"text": "Simplify login for the tenant and customer users with Single Sign-On functionality via OAuth 2.0.",
"action": "Open OAuth 2.0"
},
"slack": {
"title": "Slack",
"text": "Distribute notifications to the tenant and customer users via Slack according to the notification rules you set.",
"action": "Open Notifications settings"
}
},
"install": {
"add-tenant": "Add tenant",
"tenants": "Tenants",
"tenant-profiles": "Tenant profiles",
"users": "Users",
"customers": "Customers",
"dashboards": "Dashboards",
"integrations": "Integrations",
"features": "Features",
"features-count": "{{on}} of {{total}}",
"white-labeling": "White labeling",
"mail-server": "Mail server",
"sms-provider": "SMS provider",
"slack": "Slack",
"oauth": "OAuth 2.0",
"two-fa": "2FA",
"configured": "configured",
"not-configured": "not configured"
},
"list": {
"show-more": "Show more",
"show-all": "Show all",

Loading…
Cancel
Save