27 changed files with 1652 additions and 126 deletions
@ -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> |
|||
@ -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; |
|||
} |
|||
} |
|||
@ -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})); |
|||
} |
|||
} |
|||
@ -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> |
|||
@ -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; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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())); |
|||
} |
|||
} |
|||
@ -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]; |
|||
} |
|||
@ -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> |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
@ -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]; |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
|
|||
@ -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) |
|||
); |
|||
} |
|||
Loading…
Reference in new issue