Browse Source

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

pull/16848/head
Igor Kulikov 1 week ago
parent
commit
dab8ec628f
  1. 41
      ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.html
  2. 138
      ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.scss
  3. 67
      ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.ts
  4. 2
      ui-ngx/src/app/modules/home/pages/home-page/home-cards.models.ts
  5. 2
      ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.html
  6. 18
      ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.ts
  7. 5
      ui-ngx/src/assets/locale/locale.constant-en_US.json

41
ui-ngx/src/app/modules/home/pages/home-page/components/mobile-app-home.component.html

@ -0,0 +1,41 @@
<!--
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
SPDX-License-Identifier: BUSL-1.1
-->
<tb-home-card [card]="card" [hideable]="true">
@if (settings()) {
<div class="tb-app-widget" [class.badges-left]="badgesLeft()">
<div class="tb-app-widget-row">
<div class="tb-app-qr" role="img" [attr.aria-label]="'home.mobile-app.qr' | translate"
[innerHTML]="qrCode() | safe: 'html'" (click)="openDeepLink()"></div>
@if (badges()) {
<div class="tb-store-badges">
@if (settings().iosEnabled) {
<a class="tb-store-badge apple" [href]="settings().appStoreLink" target="_blank" rel="noopener noreferrer"
[attr.aria-label]="'widgets.mobile-app-qr-code.download-on-the-app-store' | translate">
<span class="tb-store-mark">
<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701"/></svg>
</span>
<span class="tb-store-text"><small>{{ 'home.mobile-app.download-on-the' | translate }}</small><b>App Store</b></span>
</a>
}
@if (settings().androidEnabled) {
<a class="tb-store-badge play" [href]="settings().googlePlayLink" target="_blank" rel="noopener noreferrer"
[attr.aria-label]="'widgets.mobile-app-qr-code.get-it-on-google-play' | translate">
<span class="tb-store-mark">
<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="#ffd500" d="M22.018 13.298l-3.919 2.218-3.515-3.493 3.543-3.521 3.891 2.202a1.49 1.49 0 0 1 0 2.594z"/><path fill="#00c3ff" d="M1.337.924a1.486 1.486 0 0 0-.112.568v21.017c0 .217.045.419.124.6l11.155-11.087L1.337.924z"/><path fill="#00f076" d="M13.544 10.989l3.258-3.238L3.45.195a1.466 1.466 0 0 0-.946-.179l11.04 10.973z"/><path fill="#ff3a44" d="M13.544 13.056l-11 10.933c.298.036.612-.016.906-.183l13.324-7.54-3.23-3.21z"/></svg>
</span>
<span class="tb-store-text"><small>{{ 'home.mobile-app.get-it-on' | translate }}</small><b>Google Play</b></span>
</a>
}
</div>
}
</div>
@if (label()) {
<div class="tb-app-widget-label">{{ label() }}</div>
}
</div>
}
</tb-home-card>

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

67
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: `<tb-home-card [card]="card"></tb-home-card>`,
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<QrCodeSettings | null>(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<typeof setTimeout> | 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);
}
});
}
}

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

@ -21,7 +21,7 @@ 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', 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;

2
ui-ngx/src/app/modules/home/pages/home-page/pages/tenant-admin-home.component.html

@ -62,5 +62,5 @@
}
</div>
</div>
<tb-home-cards-footer [cards]="cards"></tb-home-cards-footer>
<tb-home-cards-footer [cards]="cards()"></tb-home-cards-footer>
</div>

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

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

Loading…
Cancel
Save