15 changed files with 1212 additions and 155 deletions
@ -0,0 +1,117 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
|
|||
// SPDX-License-Identifier: BUSL-1.1
|
|||
import { inject, Injectable } from '@angular/core'; |
|||
import { MatDialog } from '@angular/material/dialog'; |
|||
import { select, Store } from '@ngrx/store'; |
|||
import { take } from 'rxjs/operators'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { selectUserSettingsProperty } from '@core/auth/auth.selectors'; |
|||
import { AddonType, createManageSubscriptionUrl, PlanUiType, SubscriptionInfo, UsageItemType } from '@shared/models/subscription.models'; |
|||
import { |
|||
LicenseHandOffCase, |
|||
LicenseHandOffDialogComponent, |
|||
LicenseHandOffDialogData |
|||
} from '@home/components/license/license-hand-off-dialog.component'; |
|||
|
|||
const LIMIT_WARN = 0.85; |
|||
|
|||
const ADD_ITEMS: Partial<Record<UsageItemType, Record<string, number>>> = { |
|||
[UsageItemType.DEVICES]: {extraDeviceCount: 100}, |
|||
[UsageItemType.EDGES]: {extraEdgeCount: 1}, |
|||
[UsageItemType.PROD_INSTANCES]: {extraInstanceCount: 1}, |
|||
[UsageItemType.AI_CREDITS]: {extraAiCreditsCount: 5}, |
|||
[UsageItemType.AGENTS]: {extraAgentCount: 1} |
|||
}; |
|||
|
|||
const ADD_ADDONS: Partial<Record<AddonType, Record<string, boolean>>> = { |
|||
[AddonType.EDGE]: {edgeEnabled: true}, |
|||
[AddonType.TRENDZ]: {trendzEnabled: true}, |
|||
[AddonType.PROFESSIONAL_UPGRADE]: {professionalUpgradeEnabled: true} |
|||
}; |
|||
|
|||
export const licenseLimitWarn = (count: number, max: number): boolean => !!count && !!max && count / max >= LIMIT_WARN; |
|||
|
|||
export const licenseLimitCritical = (count: number, max: number): boolean => !!count && !!max && count >= max; |
|||
|
|||
export const licenseMeterWidth = (count: number, max: number): number => count > 0 && max > 0 ? Math.min(count / max, 1) * 100 : 0; |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root' |
|||
}) |
|||
export class LicenseActionsService { |
|||
|
|||
private store = inject(Store<AppState>); |
|||
private dialog = inject(MatDialog); |
|||
|
|||
manageLicense(info: SubscriptionInfo): void { |
|||
this.openPortal(info, LicenseHandOffCase.MANAGE_LICENSE, null, null, createManageSubscriptionUrl(info)); |
|||
} |
|||
|
|||
addItems(info: SubscriptionInfo, itemType: UsageItemType): void { |
|||
const items = ADD_ITEMS[itemType]; |
|||
if (items) { |
|||
this.openPortal(info, LicenseHandOffCase.ADD_ITEMS, itemType, null, createManageSubscriptionUrl(info, items)); |
|||
} |
|||
} |
|||
|
|||
addAddOn(info: SubscriptionInfo, addonType: AddonType): void { |
|||
const items = ADD_ADDONS[addonType]; |
|||
if (items) { |
|||
this.openPortal(info, LicenseHandOffCase.ADD_ADDON, null, addonType, createManageSubscriptionUrl(info, items)); |
|||
} |
|||
} |
|||
|
|||
upgradePlanForItems(info: SubscriptionInfo, itemType: UsageItemType): void { |
|||
let targetPlan = PlanUiType.TbPilot; |
|||
if (itemType === UsageItemType.DEVICES) { |
|||
switch (info.planUiType) { |
|||
case PlanUiType.TbCommercialSmall: |
|||
targetPlan = PlanUiType.TbPilot; |
|||
break; |
|||
case PlanUiType.TbPilot: |
|||
targetPlan = PlanUiType.TbStartup; |
|||
break; |
|||
default: |
|||
targetPlan = PlanUiType.TbBusiness; |
|||
} |
|||
} |
|||
this.upgradePlan(info, itemType, null, targetPlan); |
|||
} |
|||
|
|||
upgradePlanForAddon(info: SubscriptionInfo, addonType: AddonType): void { |
|||
this.upgradePlan(info, null, addonType, PlanUiType.TbPilot); |
|||
} |
|||
|
|||
private upgradePlan(info: SubscriptionInfo, itemType: UsageItemType, addonType: AddonType, targetPlan: PlanUiType): void { |
|||
const url = `${info.licenseServerEndpoint}/?changeSubscriptionPlan=true&subscriptionId=${info.subscriptionId}&planUiType=${targetPlan}`; |
|||
this.openPortal(info, itemType ? LicenseHandOffCase.UPGRADE_PLAN_FOR_ITEMS : LicenseHandOffCase.UPGRADE_PLAN_FOR_ADDON, |
|||
itemType, addonType, url); |
|||
} |
|||
|
|||
private openPortal(info: SubscriptionInfo, handOffCase: LicenseHandOffCase, itemType: UsageItemType, addonType: AddonType, |
|||
url: string): void { |
|||
this.store.pipe(select(selectUserSettingsProperty('notDisplayLicenseHandOff')), take(1)).subscribe((skipDialog: boolean) => { |
|||
if (skipDialog) { |
|||
window.open(url, '_blank'); |
|||
return; |
|||
} |
|||
this.dialog.open<LicenseHandOffDialogComponent, LicenseHandOffDialogData, boolean>(LicenseHandOffDialogComponent, { |
|||
disableClose: true, |
|||
autoFocus: false, |
|||
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
|||
data: { |
|||
case: handOffCase, |
|||
isPerpetual: info.perpetual, |
|||
isCeGrant: info.communityGrantLicense, |
|||
itemType, |
|||
addonType, |
|||
planName: info.subscriptionPlanName |
|||
} |
|||
}).afterClosed().subscribe(result => { |
|||
if (result) { |
|||
window.open(url, '_blank'); |
|||
} |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,166 @@ |
|||
<!-- |
|||
|
|||
SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
|||
SPDX-License-Identifier: BUSL-1.1 |
|||
|
|||
--> |
|||
<tb-home-card [card]="cardDefinition()"> |
|||
<ng-container homeCardActions> |
|||
@if (managed() && updatedAgo()) { |
|||
<span class="tb-license-updated"> |
|||
<span [matTooltip]="'home.license.updated-tooltip' | translate">{{ 'subscription.updated-ago' | translate: {ago: updatedAgo()} }}</span> |
|||
<button mat-icon-button type="button" class="tb-license-refresh" [disabled]="refreshing()" |
|||
[matTooltip]="'action.update' | translate" [attr.aria-label]="'action.update' | translate" (click)="refresh()"> |
|||
<mat-icon [class.spinning]="refreshing()">refresh</mat-icon> |
|||
</button> |
|||
</span> |
|||
} |
|||
</ng-container> |
|||
@if (info(); as license) { |
|||
<div class="tb-license-band" [class]="kind()"> |
|||
<span class="tb-license-mark" [class.with-hue]="markHue()" [class.development]="license.development"> |
|||
<img src="/assets/license/tb-license-mark.svg" alt width="72" height="72"> |
|||
@if (license.offline) { |
|||
<i class="tb-license-offline" [matTooltip]="'subscription.offline-mode' | translate"> |
|||
<mat-icon>cloud_off</mat-icon> |
|||
</i> |
|||
} |
|||
</span> |
|||
<div class="tb-license-id"> |
|||
<small>{{ (license.development ? 'home.license.development-mode' : license.perpetual ? 'subscription.perpetual-license' : 'subscription.subscription') | translate }}</small> |
|||
<b>{{ license.subscriptionPlanName }}</b> |
|||
@if (license.development) { |
|||
<span>{{ 'home.license.development-line' | translate }}</span> |
|||
} @else if (license.perpetual) { |
|||
@if (license.endTs) { |
|||
<span>{{ 'subscription.updates-and-support-until' | translate: {date: license.endTs | date: 'd MMMM yyyy'} }}</span> |
|||
} |
|||
} @else if (license.upcomingInvoiceDate) { |
|||
<span [innerHTML]="('subscription.next-charge-and-due-date' | translate: { |
|||
total: license.upcomingInvoiceAmountDue | tbCurrency: {short: true}, |
|||
date: license.upcomingInvoiceDate | date: 'd MMMM', |
|||
dueDate: license.endTs | date: 'd MMMM'}) | safe: 'html'"></span> |
|||
} |
|||
</div> |
|||
@if (managed()) { |
|||
<div class="tb-license-manage"> |
|||
<button mat-stroked-button type="button" class="tb-license-button" (click)="manageLicense()"> |
|||
{{ 'subscription.manage-license' | translate }} |
|||
</button> |
|||
</div> |
|||
} |
|||
</div> |
|||
<div class="tb-license-body" [class.offer]="offer()"> |
|||
@if (limitGroups().length) { |
|||
<div class="tb-license-limits"> |
|||
@for (group of limitGroups(); track group.id) { |
|||
<div class="tb-license-head"><mat-icon>{{ group.icon }}</mat-icon>{{ group.label | translate }}</div> |
|||
@for (row of group.rows; track row.itemType) { |
|||
<div class="tb-license-limit" [class]="row.tone"> |
|||
<span class="tb-license-limit-name">{{ row.label | translate }}</span> |
|||
@if (row.max) { |
|||
<span class="tb-license-limit-counts" [matTooltip]="'home.license.of-limit' | translate: {percent: row.percent}"> |
|||
{{ row.used | shortNumber: {roundDown: true} }} / {{ row.max | shortNumber: {roundDown: true} }} |
|||
@if (row.tone) { |
|||
<span class="tb-home-sr-only">{{ (row.tone === 'critical' ? 'home.license.at-limit' : 'home.license.of-limit') | translate: {percent: row.percent} }}</span> |
|||
} |
|||
</span> |
|||
} @else { |
|||
<span class="tb-license-limit-counts none">{{ 'subscription.not-included' | translate }}</span> |
|||
} |
|||
<span class="tb-license-meter"><i [style.width.%]="row.width"></i></span> |
|||
@if (row.action === 'add') { |
|||
<button mat-button color="primary" type="button" class="tb-license-button" (click)="limitAction(row)"> |
|||
<mat-icon>add</mat-icon>{{ row.addLabel | translate }} |
|||
</button> |
|||
} @else if (row.action === 'upgrade') { |
|||
<button mat-button color="primary" type="button" class="tb-license-button" (click)="limitAction(row)"> |
|||
<mat-icon>arrow_upward</mat-icon>{{ 'subscription.upgrade-plan' | translate }} |
|||
</button> |
|||
} @else if (row.max) { |
|||
<span class="tb-license-pct">{{ row.percent }}%</span> |
|||
} @else { |
|||
<span class="tb-license-pct"></span> |
|||
} |
|||
</div> |
|||
} |
|||
} |
|||
</div> |
|||
} |
|||
@switch (offer()) { |
|||
@case ('pe-pack') { |
|||
<div class="tb-license-pack"> |
|||
<div class="tb-license-pack-head"> |
|||
<img src="/assets/license/tb-pro-mark.svg" alt width="56" height="56"> |
|||
<div class="tb-license-pack-id"> |
|||
<b>{{ 'subscription.pe-pack' | translate }}</b> |
|||
<span>{{ 'subscription.pe-pack-desc' | translate }}</span> |
|||
</div> |
|||
<button mat-flat-button color="primary" type="button" class="tb-license-button" (click)="addProfessionalPack()"> |
|||
{{ 'subscription.add-to-license' | translate }} |
|||
</button> |
|||
</div> |
|||
<ng-container *ngTemplateOutlet="offers; context: {$implicit: pePackOffers}"></ng-container> |
|||
</div> |
|||
} |
|||
@case ('production') { |
|||
<div class="tb-license-pack"> |
|||
<div class="tb-license-pack-head bare"> |
|||
<div class="tb-license-pack-id"> |
|||
<b>{{ 'home.license.go-to-production' | translate }}</b> |
|||
</div> |
|||
<button mat-flat-button color="primary" type="button" class="tb-license-button" (click)="seePlans()"> |
|||
{{ 'home.license.see-plans' | translate }} |
|||
</button> |
|||
</div> |
|||
<ng-container *ngTemplateOutlet="offers; context: {$implicit: productionOffers}"></ng-container> |
|||
</div> |
|||
} |
|||
@default { |
|||
<div class="tb-license-addons-group"> |
|||
<div class="tb-license-head"><mat-icon>extension</mat-icon>{{ 'subscription.add-ons' | translate }}</div> |
|||
<ul class="tb-license-addons"> |
|||
@for (addon of addons(); track addon.type) { |
|||
<li> |
|||
<span class="tb-license-addon-name">{{ addon.label | translate }}</span> |
|||
@switch (addon.state) { |
|||
@case ('included') { |
|||
<span class="tb-license-addon-state included"><mat-icon>check_circle</mat-icon>{{ 'subscription.included' | translate }}</span> |
|||
} |
|||
@case ('add') { |
|||
<button mat-button color="primary" type="button" class="tb-license-button" (click)="addonAction(addon)"> |
|||
<mat-icon>add</mat-icon>{{ 'subscription.add-to-license' | translate }} |
|||
</button> |
|||
} |
|||
@case ('upgrade') { |
|||
<button mat-button color="primary" type="button" class="tb-license-button" (click)="addonAction(addon)"> |
|||
<mat-icon>arrow_upward</mat-icon>{{ 'subscription.upgrade-plan' | translate }} |
|||
</button> |
|||
} |
|||
@case ('not-included') { |
|||
<span class="tb-license-addon-state">{{ 'subscription.not-included' | translate }}</span> |
|||
} |
|||
@default { |
|||
<span class="tb-license-addon-state">{{ 'home.license.not-in-license' | translate }}</span> |
|||
} |
|||
} |
|||
</li> |
|||
} |
|||
</ul> |
|||
</div> |
|||
} |
|||
} |
|||
</div> |
|||
} |
|||
</tb-home-card> |
|||
|
|||
<ng-template #offers let-items> |
|||
<ul class="tb-license-pack-grid"> |
|||
@for (item of items; track item.icon) { |
|||
<li> |
|||
<mat-icon>{{ item.icon }}</mat-icon> |
|||
<span><b>{{ item.title | translate }}</b><small>{{ item.text | translate }}</small></span> |
|||
</li> |
|||
} |
|||
</ul> |
|||
</ng-template> |
|||
@ -0,0 +1,546 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. |
|||
// SPDX-License-Identifier: BUSL-1.1 |
|||
:host { |
|||
display: block; |
|||
min-width: 0; |
|||
container: tb-license / inline-size; |
|||
} |
|||
|
|||
.tb-home-sr-only { |
|||
position: absolute; |
|||
width: 1px; |
|||
height: 1px; |
|||
overflow: hidden; |
|||
clip: rect(0 0 0 0); |
|||
white-space: nowrap; |
|||
} |
|||
|
|||
.tb-license-updated { |
|||
display: inline-flex; |
|||
align-items: center; |
|||
gap: 2px; |
|||
margin-right: -8px; |
|||
font: 400 13px/18px var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6)); |
|||
|
|||
> span { |
|||
white-space: nowrap; |
|||
} |
|||
} |
|||
|
|||
.tb-license-refresh.mat-mdc-icon-button.mat-mdc-button-base { |
|||
--mdc-icon-button-state-layer-size: 32px; |
|||
--mat-icon-button-state-layer-size: 32px; |
|||
display: inline-flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
width: 32px; |
|||
height: 32px; |
|||
padding: 0; |
|||
color: var(--tb-ink-54, rgba(0, 0, 0, 0.54)); |
|||
|
|||
.mat-icon { |
|||
width: 20px; |
|||
height: 20px; |
|||
font-size: 20px; |
|||
|
|||
&.spinning { |
|||
animation: tb-license-spin 1s linear infinite; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@keyframes tb-license-spin { |
|||
to { |
|||
transform: rotate(360deg); |
|||
} |
|||
} |
|||
|
|||
.tb-license-band { |
|||
--tb-license-holo: color-mix(in srgb, var(--tb-primary-500) 14%, transparent); |
|||
position: relative; |
|||
isolation: isolate; |
|||
display: flex; |
|||
align-items: center; |
|||
gap: 20px; |
|||
margin: 0 calc(-1 * var(--tb-home-card-padding, 20px)) 8px; |
|||
padding: 24px var(--tb-home-card-padding, 20px); |
|||
|
|||
&::before { |
|||
content: ""; |
|||
position: absolute; |
|||
inset: 0; |
|||
z-index: -1; |
|||
pointer-events: none; |
|||
background: |
|||
radial-gradient(50% 70% at 50% 0%, rgb(255 255 255 / 0.7), rgb(255 255 255 / 0) 70%), |
|||
linear-gradient(105deg, var(--tb-license-holo) 0%, rgb(0 150 220 / 0.10) 22%, rgb(150 120 240 / 0.09) 42%, |
|||
rgb(255 170 130 / 0.08) 60%, rgb(0 190 170 / 0.09) 78%, var(--tb-license-holo) 100%); |
|||
background-size: 100% 100%, 220% 100%; |
|||
-webkit-mask-image: linear-gradient(180deg, #000 0%, #000 55%, transparent 100%); |
|||
mask-image: linear-gradient(180deg, #000 0%, #000 55%, transparent 100%); |
|||
animation: tb-license-holo 18s ease-in-out both; |
|||
} |
|||
|
|||
&.grant { |
|||
--tb-license-holo: rgb(21 96 180 / 0.14); |
|||
} |
|||
|
|||
&.development::before { |
|||
animation: none; |
|||
background: radial-gradient(circle at 1px 1px, rgb(15 36 32 / 0.09) 1px, transparent 1.5px) 0 0 / 12px 12px, rgba(0, 0, 0, 0.03); |
|||
} |
|||
} |
|||
|
|||
@keyframes tb-license-holo { |
|||
from { |
|||
background-position: 0 0, 0% 0; |
|||
} |
|||
to { |
|||
background-position: 0 0, 100% 0; |
|||
} |
|||
} |
|||
|
|||
@media (prefers-reduced-motion: reduce) { |
|||
.tb-license-band::before { |
|||
animation: none; |
|||
} |
|||
} |
|||
|
|||
.tb-license-mark { |
|||
position: relative; |
|||
display: block; |
|||
flex: none; |
|||
width: 72px; |
|||
height: 72px; |
|||
margin: -6px; |
|||
|
|||
img { |
|||
display: block; |
|||
width: 100%; |
|||
height: 100%; |
|||
} |
|||
|
|||
&.development img { |
|||
filter: grayscale(1); |
|||
opacity: 0.72; |
|||
} |
|||
|
|||
&.with-hue::after { |
|||
content: ""; |
|||
position: absolute; |
|||
inset: 0; |
|||
background: var(--tb-noncommercial, #1560b4); |
|||
mix-blend-mode: hue; |
|||
pointer-events: none; |
|||
-webkit-mask: url(/assets/license/tb-license-mark.svg) center / 100% 100% no-repeat; |
|||
mask: url(/assets/license/tb-license-mark.svg) center / 100% 100% no-repeat; |
|||
} |
|||
} |
|||
|
|||
.tb-license-offline { |
|||
position: absolute; |
|||
top: -2px; |
|||
right: -2px; |
|||
z-index: 1; |
|||
display: flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
width: 24px; |
|||
height: 24px; |
|||
border-radius: 50%; |
|||
background: #fff; |
|||
box-shadow: 0 1px 3px rgba(15, 36, 32, 0.22); |
|||
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); |
|||
|
|||
.mat-icon { |
|||
width: 16px; |
|||
height: 16px; |
|||
font-size: 16px; |
|||
} |
|||
} |
|||
|
|||
.tb-license-id { |
|||
display: flex; |
|||
flex: 1; |
|||
flex-direction: column; |
|||
gap: 2px; |
|||
min-width: 0; |
|||
|
|||
small { |
|||
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)); |
|||
} |
|||
|
|||
> b { |
|||
font: 500 20px/28px var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-ink, rgba(0, 0, 0, 0.87)); |
|||
} |
|||
|
|||
> span { |
|||
font: 400 13px/18px var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); |
|||
|
|||
::ng-deep b { |
|||
font-weight: 500; |
|||
} |
|||
} |
|||
} |
|||
|
|||
.tb-license-manage { |
|||
display: flex; |
|||
flex: none; |
|||
flex-direction: column; |
|||
align-items: flex-end; |
|||
gap: 4px; |
|||
} |
|||
|
|||
.tb-license-button.mdc-button { |
|||
height: 32px; |
|||
padding: 0 16px; |
|||
border-radius: 4px; |
|||
white-space: nowrap; |
|||
|
|||
&.mat-mdc-outlined-button { |
|||
background: var(--tb-surface, #fff); |
|||
} |
|||
|
|||
.mat-icon { |
|||
width: 18px; |
|||
height: 18px; |
|||
margin: 0 8px 0 -4px; |
|||
font-size: 18px; |
|||
} |
|||
} |
|||
|
|||
.tb-license-body { |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
} |
|||
|
|||
.tb-license-head { |
|||
display: flex; |
|||
align-items: center; |
|||
gap: 6px; |
|||
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)); |
|||
|
|||
.mat-icon { |
|||
flex: none; |
|||
width: 16px; |
|||
height: 16px; |
|||
font-size: 16px; |
|||
color: var(--tb-ink-38, rgba(0, 0, 0, 0.38)); |
|||
} |
|||
} |
|||
|
|||
.tb-license-limits { |
|||
display: grid; |
|||
grid-template-columns: max-content max-content minmax(48px, 1fr) max-content; |
|||
align-items: center; |
|||
gap: 8px 12px; |
|||
min-width: 0; |
|||
max-width: 560px; |
|||
|
|||
> .tb-license-head { |
|||
grid-column: 1 / -1; |
|||
margin-top: 16px; |
|||
|
|||
&:first-child { |
|||
margin-top: 0; |
|||
} |
|||
} |
|||
} |
|||
|
|||
.tb-license-limit { |
|||
display: contents; |
|||
|
|||
> * { |
|||
display: flex; |
|||
align-items: center; |
|||
min-height: 32px; |
|||
} |
|||
|
|||
> .tb-license-meter { |
|||
display: block; |
|||
min-height: 0; |
|||
} |
|||
|
|||
> .tb-license-button { |
|||
justify-self: start; |
|||
min-height: 0; |
|||
margin-left: -8px; |
|||
} |
|||
} |
|||
|
|||
.tb-license-limit-name { |
|||
font: 400 14px/20px var(--tb-font, Roboto, sans-serif); |
|||
letter-spacing: 0.2px; |
|||
white-space: nowrap; |
|||
color: var(--tb-ink, rgba(0, 0, 0, 0.87)); |
|||
} |
|||
|
|||
.tb-license-limit-counts { |
|||
font: 400 14px/20px var(--tb-font, Roboto, sans-serif); |
|||
letter-spacing: 0.2px; |
|||
white-space: nowrap; |
|||
font-variant-numeric: tabular-nums; |
|||
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); |
|||
} |
|||
|
|||
.tb-license-limit-counts.none { |
|||
font-size: 13px; |
|||
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6)); |
|||
} |
|||
|
|||
.tb-license-meter { |
|||
height: 8px; |
|||
overflow: hidden; |
|||
border-radius: 2px; |
|||
background: rgba(0, 0, 0, 0.08); |
|||
|
|||
> i { |
|||
display: block; |
|||
height: 100%; |
|||
border-radius: 2px; |
|||
background: var(--tb-primary-500); |
|||
} |
|||
} |
|||
|
|||
.tb-license-pct { |
|||
font: 400 13px/18px var(--tb-font, Roboto, sans-serif); |
|||
font-variant-numeric: tabular-nums; |
|||
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6)); |
|||
} |
|||
|
|||
.tb-license-limit.near { |
|||
.tb-license-limit-counts { |
|||
color: #955400; |
|||
} |
|||
|
|||
.tb-license-meter { |
|||
background: rgb(255 167 38 / 0.16); |
|||
|
|||
> i { |
|||
background: #b26500; |
|||
} |
|||
} |
|||
} |
|||
|
|||
.tb-license-limit.critical { |
|||
.tb-license-limit-counts { |
|||
color: var(--tb-sev-critical, #D12730); |
|||
} |
|||
|
|||
.tb-license-meter { |
|||
background: rgba(209, 39, 48, 0.06); |
|||
|
|||
> i { |
|||
background: var(--tb-sev-critical, #D12730); |
|||
} |
|||
} |
|||
} |
|||
|
|||
.tb-license-addons-group { |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 8px; |
|||
min-width: 0; |
|||
} |
|||
|
|||
.tb-license-addons { |
|||
display: grid; |
|||
grid-template-columns: max-content max-content; |
|||
align-items: center; |
|||
gap: 8px 16px; |
|||
margin: 0; |
|||
padding: 0; |
|||
list-style: none; |
|||
|
|||
li { |
|||
display: contents; |
|||
font: 400 14px/20px var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-ink, rgba(0, 0, 0, 0.87)); |
|||
|
|||
> * { |
|||
display: flex; |
|||
align-items: center; |
|||
min-height: 32px; |
|||
} |
|||
|
|||
> .tb-license-button { |
|||
justify-self: start; |
|||
min-height: 0; |
|||
} |
|||
} |
|||
} |
|||
|
|||
.tb-license-addon-name { |
|||
min-width: 0; |
|||
overflow: hidden; |
|||
white-space: nowrap; |
|||
text-overflow: ellipsis; |
|||
} |
|||
|
|||
.tb-license-addon-state { |
|||
display: inline-flex; |
|||
align-items: center; |
|||
gap: 4px; |
|||
padding-left: 8px; |
|||
font: 400 13px/18px var(--tb-font, Roboto, sans-serif); |
|||
white-space: nowrap; |
|||
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6)); |
|||
|
|||
&.included { |
|||
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); |
|||
} |
|||
|
|||
.mat-icon { |
|||
width: 18px; |
|||
height: 18px; |
|||
font-size: 18px; |
|||
color: var(--tb-primary-500); |
|||
} |
|||
} |
|||
|
|||
.tb-license-pack { |
|||
min-width: 0; |
|||
padding: 12px 14px 14px; |
|||
border-radius: 10px; |
|||
background: |
|||
linear-gradient(180deg, rgb(255 255 255 / 0) 35%, var(--tb-surface, #fff) 100%), |
|||
radial-gradient(120% 110% at 0% 0%, rgb(255 255 255 / 0.9) 0%, rgb(255 255 255 / 0) 58%), |
|||
linear-gradient(115deg, rgb(0 105 92 / 0.11) 0%, rgb(0 105 92 / 0.06) 38%, rgb(0 88 196 / 0.065) 72%, rgb(0 51 202 / 0.10) 100%); |
|||
} |
|||
|
|||
.tb-license-pack-head { |
|||
display: flex; |
|||
align-items: center; |
|||
gap: 10px; |
|||
margin: -4px 0 10px -4px; |
|||
|
|||
img { |
|||
flex: none; |
|||
} |
|||
|
|||
&.bare { |
|||
margin: 0 0 12px; |
|||
} |
|||
} |
|||
|
|||
.tb-license-pack-id { |
|||
display: flex; |
|||
flex: 1; |
|||
flex-direction: column; |
|||
gap: 2px; |
|||
min-width: 0; |
|||
|
|||
b { |
|||
font: 500 15px/20px var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-ink, rgba(0, 0, 0, 0.87)); |
|||
} |
|||
|
|||
span { |
|||
font: 400 13px/18px var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-ink-76, rgba(0, 0, 0, 0.76)); |
|||
} |
|||
} |
|||
|
|||
.tb-license-pack-grid { |
|||
display: grid; |
|||
grid-template-columns: repeat(2, minmax(0, 1fr)); |
|||
gap: 8px; |
|||
margin: 0; |
|||
padding: 0; |
|||
list-style: none; |
|||
|
|||
li { |
|||
display: flex; |
|||
gap: 9px; |
|||
padding: 10px 12px 11px; |
|||
border-radius: 8px; |
|||
background: var(--tb-surface, #fff); |
|||
box-shadow: 0 0 0 1px rgb(0 105 92 / 0.06), 0 1px 2px rgba(15, 36, 32, 0.04); |
|||
|
|||
> .mat-icon { |
|||
flex: none; |
|||
width: 20px; |
|||
height: 20px; |
|||
margin-top: 1px; |
|||
font-size: 20px; |
|||
color: #023e36; |
|||
} |
|||
|
|||
> span { |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 2px; |
|||
min-width: 0; |
|||
} |
|||
} |
|||
|
|||
b { |
|||
font: 500 13px/18px var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-ink, rgba(0, 0, 0, 0.87)); |
|||
} |
|||
|
|||
small { |
|||
font: 400 12px/16px var(--tb-font, Roboto, sans-serif); |
|||
color: var(--tb-text-secondary, rgba(0, 0, 0, 0.6)); |
|||
} |
|||
} |
|||
|
|||
@container tb-license (min-width: 640px) { |
|||
.tb-license-body:not(.offer) { |
|||
display: grid; |
|||
grid-template-columns: minmax(0, 1fr) max-content; |
|||
align-items: start; |
|||
column-gap: 40px; |
|||
} |
|||
|
|||
.tb-license-body:not(.offer) .tb-license-limits { |
|||
max-width: none; |
|||
} |
|||
} |
|||
|
|||
@container tb-license (max-width: 460px) { |
|||
.tb-license-limits { |
|||
grid-template-columns: max-content max-content minmax(48px, 1fr); |
|||
} |
|||
|
|||
.tb-license-limit { |
|||
> .tb-license-button { |
|||
grid-column: 1 / -1; |
|||
} |
|||
|
|||
> .tb-license-pct { |
|||
display: none; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@container tb-license (max-width: 420px) { |
|||
.tb-license-band { |
|||
flex-wrap: wrap; |
|||
} |
|||
|
|||
.tb-license-manage { |
|||
flex-basis: 100%; |
|||
flex-direction: row; |
|||
justify-content: space-between; |
|||
align-items: center; |
|||
} |
|||
|
|||
.tb-license-pack-grid { |
|||
grid-template-columns: minmax(0, 1fr); |
|||
} |
|||
|
|||
.tb-license-pack-head { |
|||
flex-wrap: wrap; |
|||
} |
|||
} |
|||
@ -1,16 +1,328 @@ |
|||
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
|
|||
// SPDX-License-Identifier: BUSL-1.1
|
|||
import { ChangeDetectionStrategy, Component } from '@angular/core'; |
|||
import { ChangeDetectionStrategy, Component, computed, DestroyRef, ElementRef, inject, signal } from '@angular/core'; |
|||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { interval } from 'rxjs'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { getCurrentAuthState } from '@core/auth/auth.selectors'; |
|||
import { AdminService } from '@core/http/admin.service'; |
|||
import { DateAgoPipe } from '@shared/pipe/date-ago.pipe'; |
|||
import { HomeCardId } from '@shared/models/user-settings.models'; |
|||
import { |
|||
AddonType, |
|||
addonTypeTranslationMap, |
|||
PlanUiType, |
|||
SubscriptionInfo, |
|||
usageAddItemTypeTranslationMap, |
|||
UsageItemType, |
|||
usageItemTypeTranslationMap |
|||
} from '@shared/models/subscription.models'; |
|||
import { HOME_CARDS } from '@home/pages/home-page/home-cards.models'; |
|||
import { |
|||
LicenseActionsService, |
|||
licenseLimitCritical, |
|||
licenseLimitWarn, |
|||
licenseMeterWidth |
|||
} from '@home/components/license/license-actions.service'; |
|||
|
|||
const LOADING_HEIGHT = 398; |
|||
const HEIGHT_KEY = 'tb-home-license-height'; |
|||
|
|||
const storedHeight = (): number => { |
|||
try { |
|||
return Number(localStorage.getItem(HEIGHT_KEY)) || LOADING_HEIGHT; |
|||
} catch { |
|||
return LOADING_HEIGHT; |
|||
} |
|||
}; |
|||
|
|||
const AGO_REFRESH_MS = 30_000; |
|||
|
|||
const PLANS_URL = 'https://thingsboard.io/pricing/?product=thingsboard-pe'; |
|||
|
|||
const TONED_ITEMS = [UsageItemType.DEVICES, UsageItemType.ASSETS, UsageItemType.AI_CREDITS]; |
|||
|
|||
type LimitTone = 'critical' | 'near' | null; |
|||
|
|||
type LimitAction = 'add' | 'upgrade' | null; |
|||
|
|||
interface LicenseLimit { |
|||
itemType: UsageItemType; |
|||
label: string; |
|||
used: number; |
|||
max: number; |
|||
percent: number; |
|||
width: number; |
|||
tone: LimitTone; |
|||
action: LimitAction; |
|||
addLabel: string; |
|||
} |
|||
|
|||
interface LicenseLimitGroup { |
|||
id: string; |
|||
label: string; |
|||
icon: string; |
|||
rows: LicenseLimit[]; |
|||
} |
|||
|
|||
type AddonState = 'included' | 'not-included' | 'add' | 'upgrade' | 'not-in-license'; |
|||
|
|||
interface LicenseAddon { |
|||
type: AddonType; |
|||
label: string; |
|||
state: AddonState; |
|||
} |
|||
|
|||
interface LicenseOffer { |
|||
icon: string; |
|||
title: string; |
|||
text: string; |
|||
} |
|||
|
|||
const PE_PACK_OFFERS: LicenseOffer[] = [ |
|||
{icon: 'brush', title: 'subscription.white-labeling', text: 'subscription.white-labeling-promo'}, |
|||
{icon: 'integration_instructions', title: 'subscription.integrations', text: 'subscription.integrations-promo'}, |
|||
{icon: 'schedule', title: 'subscription.scheduler', text: 'subscription.scheduler-promo'}, |
|||
{icon: 'assessment', title: 'subscription.reports', text: 'subscription.reports-promo'} |
|||
]; |
|||
|
|||
const PRODUCTION_OFFERS: LicenseOffer[] = [ |
|||
{icon: 'rocket_launch', title: 'home.license.production-use', text: 'home.license.production-use-text'}, |
|||
{icon: 'brush', title: 'subscription.white-labeling', text: 'subscription.white-labeling-promo'}, |
|||
{icon: 'auto_awesome', title: 'subscription.ai-credits', text: 'home.license.ai-credits-text'}, |
|||
{icon: 'extension', title: 'subscription.add-ons', text: 'home.license.add-ons-text'} |
|||
]; |
|||
|
|||
@Component({ |
|||
selector: 'tb-license-home', |
|||
template: `<tb-home-card [card]="card"></tb-home-card>`, |
|||
templateUrl: './license-home.component.html', |
|||
styleUrls: ['./license-home.component.scss'], |
|||
standalone: false, |
|||
changeDetection: ChangeDetectionStrategy.OnPush |
|||
}) |
|||
export class LicenseHomeComponent { |
|||
|
|||
readonly card = HOME_CARDS[HomeCardId.LICENSE]; |
|||
private adminService = inject(AdminService); |
|||
private dateAgoPipe = inject(DateAgoPipe); |
|||
private licenseActions = inject(LicenseActionsService); |
|||
private aiEnabled = getCurrentAuthState(inject(Store<AppState>)).aiEnabled; |
|||
|
|||
readonly pePackOffers = PE_PACK_OFFERS; |
|||
readonly productionOffers = PRODUCTION_OFFERS; |
|||
|
|||
readonly info = signal<SubscriptionInfo | null>(null); |
|||
readonly refreshing = signal(false); |
|||
private readonly now = signal(Date.now()); |
|||
|
|||
readonly cardDefinition = computed(() => { |
|||
const card = HOME_CARDS[HomeCardId.LICENSE]; |
|||
return this.info() ? card : {...card, height: storedHeight()}; |
|||
}); |
|||
|
|||
readonly kind = computed(() => { |
|||
const info = this.info(); |
|||
if (!info) { |
|||
return null; |
|||
} |
|||
if (info.development) { |
|||
return 'development'; |
|||
} |
|||
if (info.communityGrantLicense) { |
|||
return 'grant'; |
|||
} |
|||
return info.perpetual ? 'perpetual' : 'subscription'; |
|||
}); |
|||
|
|||
readonly markHue = computed(() => { |
|||
switch (this.info()?.planUiType) { |
|||
case PlanUiType.TbNonCommercial: |
|||
case PlanUiType.TbNonCommercialOffline: |
|||
case PlanUiType.TbCommunityGrant: |
|||
return true; |
|||
default: |
|||
return false; |
|||
} |
|||
}); |
|||
|
|||
readonly managed = computed(() => { |
|||
const info = this.info(); |
|||
return !!info && !info.offline && !info.nonProduction; |
|||
}); |
|||
|
|||
readonly updatedAgo = computed(() => { |
|||
this.now(); |
|||
const dataTs = this.info()?.dataTs; |
|||
return dataTs ? this.dateAgoPipe.transform(dataTs, {applyAgo: true, long: true, textPart: true}) : null; |
|||
}); |
|||
|
|||
readonly limitGroups = computed<LicenseLimitGroup[]>(() => { |
|||
const info = this.info(); |
|||
if (!info || info.development) { |
|||
return []; |
|||
} |
|||
const groups: LicenseLimitGroup[] = []; |
|||
const entities = [ |
|||
this.limit(info, UsageItemType.DEVICES, info.devicesCount, info.maxDevices, info.planExtraDeviceEnabled), |
|||
this.limit(info, UsageItemType.ASSETS, info.assetsCount, info.maxAssets, false) |
|||
].filter(row => !!row); |
|||
if (entities.length) { |
|||
groups.push({id: 'entities', label: 'home.license.devices-and-assets', icon: 'memory', rows: entities}); |
|||
} |
|||
const installations = [ |
|||
info.maxInstances > 0 ? |
|||
this.limit(info, UsageItemType.PROD_INSTANCES, info.instancesCount, info.maxInstances, info.planExtraInstanceEnabled) : null, |
|||
info.edgeEnabled ? this.limit(info, UsageItemType.EDGES, info.edgesCount, info.maxEdges, info.planExtraEdgeEnabled) : null, |
|||
info.maxAgents > 0 || info.planExtraAgentEnabled ? |
|||
this.limit(info, UsageItemType.AGENTS, info.agentsCount, info.maxAgents, info.planExtraAgentEnabled) : null |
|||
].filter(row => !!row); |
|||
if (installations.length) { |
|||
groups.push({id: 'installations', label: 'home.license.installations', icon: 'lan', rows: installations}); |
|||
} |
|||
if (this.aiEnabled && !info.offline && info.maxAiCredits > 0) { |
|||
const credits = this.limit(info, UsageItemType.AI_CREDITS, info.usedAiCredits, info.maxAiCredits, info.planExtraAiCreditsEnabled, |
|||
'home.license.this-month'); |
|||
groups.push({id: 'credits', label: 'subscription.ai-credits', icon: 'auto_awesome', rows: [credits]}); |
|||
} |
|||
return groups; |
|||
}); |
|||
|
|||
readonly offer = computed<'pe-pack' | 'production' | null>(() => { |
|||
const info = this.info(); |
|||
if (!info) { |
|||
return null; |
|||
} |
|||
if (info.development) { |
|||
return 'production'; |
|||
} |
|||
return info.communityGrantLicense && !info.whiteLabelingEnabled ? 'pe-pack' : null; |
|||
}); |
|||
|
|||
readonly addons = computed<LicenseAddon[]>(() => { |
|||
const info = this.info(); |
|||
if (!info || this.offer()) { |
|||
return []; |
|||
} |
|||
const addons: LicenseAddon[] = []; |
|||
if (!info.communityGrantLicense || info.whiteLabelingEnabled) { |
|||
addons.push(this.addon(info, AddonType.WHITE_LABELING, info.whiteLabelingEnabled, false)); |
|||
} |
|||
if (!info.perpetual || info.planEdgeEnabled) { |
|||
addons.push(this.addon(info, AddonType.EDGE, info.edgeEnabled, info.planEdgeEnabled)); |
|||
} |
|||
if (!info.perpetual || info.planTrendzEnabled) { |
|||
addons.push(this.addon(info, AddonType.TRENDZ, info.trendzEnabled, info.planTrendzEnabled)); |
|||
} |
|||
if (info.communityGrantLicense && info.whiteLabelingEnabled) { |
|||
addons.push(this.addon(info, AddonType.PROFESSIONAL_UPGRADE, true, false)); |
|||
} |
|||
return addons; |
|||
}); |
|||
|
|||
constructor() { |
|||
const destroyRef = inject(DestroyRef); |
|||
this.adminService.getSubscriptionInfo({ignoreLoading: true}).pipe(takeUntilDestroyed(destroyRef)) |
|||
.subscribe(info => this.info.set(info)); |
|||
interval(AGO_REFRESH_MS).pipe(takeUntilDestroyed(destroyRef)).subscribe(() => this.now.set(Date.now())); |
|||
const host = inject<ElementRef<HTMLElement>>(ElementRef); |
|||
const observer = new ResizeObserver(() => this.rememberHeight(host.nativeElement)); |
|||
observer.observe(host.nativeElement); |
|||
destroyRef.onDestroy(() => observer.disconnect()); |
|||
} |
|||
|
|||
refresh(): void { |
|||
this.refreshing.set(true); |
|||
this.adminService.refreshLicense({ignoreLoading: true}).subscribe({ |
|||
next: info => { |
|||
this.info.set(info); |
|||
this.refreshing.set(false); |
|||
}, |
|||
error: () => this.refreshing.set(false) |
|||
}); |
|||
} |
|||
|
|||
manageLicense(): void { |
|||
this.licenseActions.manageLicense(this.info()); |
|||
} |
|||
|
|||
limitAction(row: LicenseLimit): void { |
|||
if (row.action === 'add') { |
|||
this.licenseActions.addItems(this.info(), row.itemType); |
|||
} else if (row.action === 'upgrade') { |
|||
this.licenseActions.upgradePlanForItems(this.info(), row.itemType); |
|||
} |
|||
} |
|||
|
|||
addonAction(addon: LicenseAddon): void { |
|||
if (addon.state === 'add') { |
|||
this.licenseActions.addAddOn(this.info(), addon.type); |
|||
} else if (addon.state === 'upgrade') { |
|||
this.licenseActions.upgradePlanForAddon(this.info(), addon.type); |
|||
} |
|||
} |
|||
|
|||
addProfessionalPack(): void { |
|||
this.licenseActions.addAddOn(this.info(), AddonType.PROFESSIONAL_UPGRADE); |
|||
} |
|||
|
|||
seePlans(): void { |
|||
window.open(PLANS_URL, '_blank'); |
|||
} |
|||
|
|||
private rememberHeight(element: HTMLElement): void { |
|||
const height = Math.round(element.getBoundingClientRect().height); |
|||
if (!this.info() || !height) { |
|||
return; |
|||
} |
|||
try { |
|||
localStorage.setItem(HEIGHT_KEY, String(height)); |
|||
} catch { |
|||
return; |
|||
} |
|||
} |
|||
|
|||
private limit(info: SubscriptionInfo, itemType: UsageItemType, used: number, max: number, addEnabled: boolean, |
|||
label = usageItemTypeTranslationMap.get(itemType)): LicenseLimit | null { |
|||
if (max == null || max < 0) { |
|||
return null; |
|||
} |
|||
const count = used ?? 0; |
|||
let tone: LimitTone = null; |
|||
if (max > 0 && count > max) { |
|||
tone = 'critical'; |
|||
} else if (TONED_ITEMS.includes(itemType)) { |
|||
tone = licenseLimitCritical(count, max) ? 'critical' : licenseLimitWarn(count, max) ? 'near' : null; |
|||
} |
|||
let action: LimitAction = null; |
|||
if ((tone || max === 0) && !info.offline && itemType !== UsageItemType.ASSETS) { |
|||
action = addEnabled ? 'add' : !info.perpetual ? 'upgrade' : null; |
|||
} |
|||
return { |
|||
itemType, |
|||
label, |
|||
used: count, |
|||
max, |
|||
percent: max > 0 ? Math.round(count / max * 100) : 0, |
|||
width: licenseMeterWidth(count, max), |
|||
tone, |
|||
action, |
|||
addLabel: usageAddItemTypeTranslationMap.get(itemType) |
|||
}; |
|||
} |
|||
|
|||
private addon(info: SubscriptionInfo, type: AddonType, enabled: boolean, addEnabled: boolean): LicenseAddon { |
|||
let state: AddonState; |
|||
if (enabled) { |
|||
state = 'included'; |
|||
} else if (info.offline) { |
|||
state = 'not-included'; |
|||
} else if (addEnabled) { |
|||
state = 'add'; |
|||
} else if (!info.perpetual) { |
|||
state = 'upgrade'; |
|||
} else { |
|||
state = 'not-in-license'; |
|||
} |
|||
return {type, label: addonTypeTranslationMap.get(type), state}; |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue