From dab8ec628f63e0fb3ea03c97527d8d1d861e75dc Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Tue, 24 Nov 2026 12:30:48 +0200 Subject: [PATCH] feat: the Home Mobile app card on the old mobile app QR code widget's settings: the deep link's QR code refreshed at its ttl, the store badges and the label as the merged settings place them, and the card left out of Home while the QR code is not set to show on the home page --- .../components/mobile-app-home.component.html | 41 ++++++ .../components/mobile-app-home.component.scss | 138 ++++++++++++++++++ .../components/mobile-app-home.component.ts | 67 ++++++++- .../home/pages/home-page/home-cards.models.ts | 2 +- .../pages/tenant-admin-home.component.html | 2 +- .../pages/tenant-admin-home.component.ts | 18 ++- .../assets/locale/locale.constant-en_US.json | 5 + 7 files changed, 263 insertions(+), 10 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.scss diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.html b/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.html new file mode 100644 index 0000000000..17433da81d --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.html @@ -0,0 +1,41 @@ + + + @if (settings()) { +
+
+ + @if (badges()) { + + } +
+ @if (label()) { +
{{ label() }}
+ } +
+ } +
diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.scss b/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.scss new file mode 100644 index 0000000000..d3f32b8d7d --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.scss @@ -0,0 +1,138 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +:host { + display: block; + min-width: 0; + container: tb-mobile-app-home / inline-size; +} + +.tb-app-widget { + display: flex; + flex-direction: column; + align-items: center; + gap: 10px; +} + +.tb-app-widget-row { + display: flex; + align-items: center; + justify-content: center; + gap: 12px; +} + +.badges-left .tb-app-widget-row { + flex-direction: row-reverse; +} + +.tb-app-qr { + flex: none; + box-sizing: border-box; + width: 96px; + height: 96px; + padding: 4px; + border-radius: 6px; + background: #fff; + + ::ng-deep svg { + display: block; + width: 100%; + height: 100%; + } +} + +.tb-store-badges { + display: flex; + flex-direction: column; + gap: 8px; +} + +.tb-store-badge { + display: inline-flex; + flex: none; + align-items: center; + gap: 8px; + box-sizing: border-box; + width: 136px; + height: 40px; + padding: 0 12px 0 10px; + border: 1px solid #a6a6a6; + border-radius: 7px; + background: #000; + color: #fff; + text-decoration: none; + white-space: nowrap; + transition: background-color .2s ease, border-color .2s ease; + + &:hover { + border-color: #c8c8c8; + background: #1f1f1f; + color: #fff; + } + + &:focus-visible { + outline: 2px solid var(--tb-primary-500); + outline-offset: 2px; + } +} + +.tb-store-mark { + display: flex; + flex: none; + align-items: center; + justify-content: center; + width: 24px; + height: 24px; + + svg { + display: block; + width: 22px; + height: 22px; + } +} + +.apple .tb-store-mark svg { + width: 24px; + height: 24px; + margin-top: -2px; +} + +.tb-store-text { + display: flex; + flex-direction: column; + gap: 1px; + font-family: var(--tb-font, Roboto, sans-serif); + text-align: left; + + small { + font-size: 10px; + line-height: 11px; + letter-spacing: 0.1px; + opacity: 0.92; + } + + b { + font-size: 16px; + font-weight: 500; + line-height: 18px; + letter-spacing: -0.1px; + } +} + +.play .tb-store-text small { + font-size: 9px; + letter-spacing: 0.5px; + text-transform: uppercase; +} + +.tb-app-widget-label { + font: 400 14px/20px var(--tb-font, Roboto, sans-serif); + letter-spacing: 0.2px; + text-align: center; + color: var(--tb-ink-60, rgba(0, 0, 0, 0.6)); +} + +@container tb-mobile-app-home (max-width: 290px) { + .tb-store-badges { + display: none; + } +} diff --git a/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.ts index 889a8e2f62..4def500228 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.ts @@ -1,16 +1,79 @@ // SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. // SPDX-License-Identifier: BUSL-1.1 -import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, signal } from '@angular/core'; +import { MobileApplicationService } from '@core/http/mobile-application.service'; +import { UtilsService } from '@core/services/utils.service'; +import { unwrapModule } from '@core/utils'; +import { BadgePosition, QrCodeSettings } from '@shared/models/mobile-app.models'; +import { MINUTE } from '@shared/models/time/time.models'; import { HomeCardId } from '@shared/models/user-settings.models'; import { HOME_CARDS } from '@home/pages/home-page/home-cards.models'; @Component({ selector: 'tb-mobile-app-home', - template: ``, + templateUrl: './mobile-app-home.component.html', + styleUrls: ['./mobile-app-home.component.scss'], standalone: false, changeDetection: ChangeDetectionStrategy.OnPush }) export class MobileAppHomeComponent { readonly card = HOME_CARDS[HomeCardId.MOBILE_APP]; + + private mobileAppService = inject(MobileApplicationService); + private utils = inject(UtilsService); + + readonly settings = signal(null); + + readonly qrCode = signal(''); + + readonly badges = computed(() => { + const settings = this.settings(); + return !!settings?.qrCodeConfig?.badgeEnabled && (settings.iosEnabled || settings.androidEnabled); + }); + + readonly badgesLeft = computed(() => this.settings()?.qrCodeConfig?.badgePosition === BadgePosition.LEFT); + + readonly label = computed(() => { + const config = this.settings()?.qrCodeConfig; + return config?.qrCodeLabelEnabled ? config.qrCodeLabel : ''; + }); + + private deepLink = ''; + private deepLinkTimer: ReturnType | null = null; + private destroyed = false; + + constructor() { + this.mobileAppService.getMergedMobileAppSettings().subscribe(settings => this.settings.set(settings)); + this.loadDeepLink(); + inject(DestroyRef).onDestroy(() => { + this.destroyed = true; + clearTimeout(this.deepLinkTimer); + }); + } + + openDeepLink(): void { + if (this.deepLink && window.matchMedia('(pointer: coarse)').matches) { + window.open(this.deepLink, '_blank'); + } + } + + private loadDeepLink(): void { + clearTimeout(this.deepLinkTimer); + this.mobileAppService.getMobileAppDeepLink().subscribe(link => { + if (this.destroyed) { + return; + } + this.deepLink = link; + import('qrcode').then(QRCode => unwrapModule(QRCode).toString(link, {type: 'svg', margin: 0}, (_error: Error, svg: string) => { + if (!this.destroyed) { + this.qrCode.set(svg); + } + })); + const ttl = Number(this.utils.getQueryParam('ttl', link)) * MINUTE; + if (ttl > 0) { + this.deepLinkTimer = setTimeout(() => this.loadDeepLink(), ttl); + } + }); + } } diff --git a/ui-ngx/src/app/modules/home/pages/home-page/home-cards.models.ts b/ui-ngx/src/app/modules/home/pages/home-page/home-cards.models.ts index e825fd1ecd..8c8287546f 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/home-cards.models.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/home-cards.models.ts @@ -21,7 +21,7 @@ export const HOME_CARDS: Record = { 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', height: 225} + [HomeCardId.MOBILE_APP]: {id: HomeCardId.MOBILE_APP, icon: 'phone_iphone', name: 'home.cards.mobile-app'} }; export const isHomeCardShown = (settings: HomeCardsSettings, id: HomeCardId): boolean => settings?.[id] !== false; diff --git a/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.html b/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.html index b2b9ba9e55..cc65b28885 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.html @@ -62,5 +62,5 @@ } - + diff --git a/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts b/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts index 7556dbc08e..395d33a9d7 100644 --- a/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts @@ -4,7 +4,7 @@ import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/c import { toSignal } from '@angular/core/rxjs-interop'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; -import { selectHomeCards } from '@core/auth/auth.selectors'; +import { selectHomeCards, selectMobileQrEnabled } from '@core/auth/auth.selectors'; import { TourService } from '@core/services/tour.service'; import { UserPermissionsService } from '@core/http/user-permissions.service'; import { Operation, Resource } from '@shared/models/security.models'; @@ -25,16 +25,22 @@ export class TenantAdminHomeComponent { readonly HomeCardId = HomeCardId; - private readonly sideCardIds = inject(UserPermissionsService).hasGenericPermission(Resource.ALL, Operation.READ) - ? SIDE_CARDS : SIDE_CARDS.filter(id => id !== HomeCardId.USAGE); + private readonly store = inject(Store); - readonly cards = [...MAIN_CARDS, ...this.sideCardIds]; + private readonly usageAccess = inject(UserPermissionsService).hasGenericPermission(Resource.ALL, Operation.READ); + + private readonly mobileQrEnabled = toSignal(this.store.select(selectMobileQrEnabled), {initialValue: false}); + + private readonly sideCardIds = computed(() => SIDE_CARDS.filter(id => + (id !== HomeCardId.USAGE || this.usageAccess) && (id !== HomeCardId.MOBILE_APP || this.mobileQrEnabled()))); + + readonly cards = computed(() => [...MAIN_CARDS, ...this.sideCardIds()]); readonly aiAvailable = inject(TourService).aiAvailable(); - private settings = toSignal(inject(Store).select(selectHomeCards), {initialValue: {}}); + private settings = toSignal(this.store.select(selectHomeCards), {initialValue: {}}); readonly mainCards = computed(() => MAIN_CARDS.filter(id => isHomeCardShown(this.settings(), id))); - readonly sideCards = computed(() => this.sideCardIds.filter(id => isHomeCardShown(this.settings(), id))); + readonly sideCards = computed(() => this.sideCardIds().filter(id => isHomeCardShown(this.settings(), id))); } diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 097c478e5f..120238f2ac 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -8752,6 +8752,11 @@ "of-limit": "{{percent}}% of limit", "no-limit": "No limit" }, + "mobile-app": { + "qr": "QR code to connect the mobile app", + "download-on-the": "Download on the", + "get-it-on": "Get it on" + }, "list": { "show-more": "Show more", "show-all": "Show all",