Browse Source

Merge pull request #16148 from ShvaykaD/feature/iot-hub-search-relevance

IoT Hub: show the hero search popup as one ranked list, and give the search page filters
pull/16134/merge
Vladyslav Prykhodko 1 month ago
committed by GitHub
parent
commit
daaad2ca28
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 40
      ui-ngx/src/app/core/http/iot-hub-api.service.ts
  2. 6
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html
  3. 48
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts
  4. 30
      ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss
  5. 24
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html
  6. 47
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts
  7. 3
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts
  8. 31
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html
  9. 63
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss
  10. 60
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts
  11. 3
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html
  12. 14
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts
  13. 6
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts
  14. 160
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html
  15. 160
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss
  16. 297
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts
  17. 26
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts
  18. 4
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-alarm-rules-unavailable-page.component.ts
  19. 3
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html
  20. 83
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html
  21. 128
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss
  22. 119
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts
  23. 99
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss
  24. 52
      ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts
  25. 101
      ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts
  26. 4
      ui-ngx/src/assets/locale/locale.constant-en_US.json

40
ui-ngx/src/app/core/http/iot-hub-api.service.ts

@ -6,7 +6,11 @@ import { Store } from '@ngrx/store';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { PageData } from '@shared/models/page/page-data'; import { PageData } from '@shared/models/page/page-data';
import { PageLink } from '@shared/models/page/page-link'; import { PageLink } from '@shared/models/page/page-link';
import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import {
MpItemVersionQuery,
MpItemVersionQueryOptions,
MpItemVersionView
} from '@shared/models/iot-hub/iot-hub-version.models';
import { CreatorView } from '@shared/models/iot-hub/iot-hub-creator.models'; import { CreatorView } from '@shared/models/iot-hub/iot-hub-creator.models';
import { IotHubInstalledItem, InstallItemVersionResult, InstallPlan, InstallPlanResult, UpdateItemVersionResult, ItemPublishedVersionInfo } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubInstalledItem, InstallItemVersionResult, InstallPlan, InstallPlanResult, UpdateItemVersionResult, ItemPublishedVersionInfo } from '@shared/models/iot-hub/iot-hub-installed-item.models';
import { ItemType, ItemTypeFilterInfo, WidgetCategory } from '@shared/models/iot-hub/iot-hub-item.models'; import { ItemType, ItemTypeFilterInfo, WidgetCategory } from '@shared/models/iot-hub/iot-hub-item.models';
@ -69,30 +73,38 @@ export class IotHubApiService {
} }
public getPublishedVersions(query: MpItemVersionQuery, config?: IotHubRequestConfig): Observable<PageData<MpItemVersionView>> { public getPublishedVersions(query: MpItemVersionQuery, config?: IotHubRequestConfig): Observable<PageData<MpItemVersionView>> {
if (query.options.tbVersion == null) { this.applyPlatformFilters(query.options);
query.options.tbVersion = tbVersionToInt(env.tbVersion);
}
if (query.options.peOnly == null) {
query.options.peOnly = false;
}
return this.http.get<PageData<MpItemVersionView>>( return this.http.get<PageData<MpItemVersionView>>(
`${this.baseUrl}/api/versions/published${query.toQuery()}`, `${this.baseUrl}/api/versions/published${query.toQuery()}`,
{ params: this.buildParams(config) } { params: this.buildParams(config) }
); );
} }
/** What this platform can install: no PE-only items, nothing built for a newer ThingsBoard. */
private platformScope(): { peOnly: boolean; tbVersion: number } {
return { peOnly: false, tbVersion: tbVersionToInt(env.tbVersion) };
}
/** Fills in the platform scope wherever the caller did not set it. */
private applyPlatformFilters(options: MpItemVersionQueryOptions): void {
const scope = this.platformScope();
options.tbVersion ??= scope.tbVersion;
options.peOnly ??= scope.peOnly;
}
private platformScopeParams(): string[] {
const scope = this.platformScope();
return [`peOnly=${scope.peOnly}`, `tbVersion=${scope.tbVersion}`];
}
public getFilterInfo(itemType: ItemType, config?: IotHubRequestConfig): Observable<ItemTypeFilterInfo> { public getFilterInfo(itemType: ItemType, config?: IotHubRequestConfig): Observable<ItemTypeFilterInfo> {
const url = `${this.baseUrl}/api/item-listing/filterInfo/${itemType}` const url = `${this.baseUrl}/api/item-listing/filterInfo/${itemType}?${this.platformScopeParams().join('&')}`;
+ `?peOnly=false&tbVersion=${tbVersionToInt(env.tbVersion)}`;
return this.http.get<ItemTypeFilterInfo>(url, { params: this.buildParams(config) }); return this.http.get<ItemTypeFilterInfo>(url, { params: this.buildParams(config) });
} }
public getWidgetCategories(textSearch?: string, scadaFirst?: boolean, creatorVerified?: boolean, public getWidgetCategories(textSearch?: string, scadaFirst?: boolean, creatorVerified?: boolean,
config?: IotHubRequestConfig): Observable<WidgetCategory[]> { config?: IotHubRequestConfig): Observable<WidgetCategory[]> {
const queryParams: string[] = [ const queryParams: string[] = this.platformScopeParams();
`peOnly=false`,
`tbVersion=${tbVersionToInt(env.tbVersion)}`
];
if (textSearch?.trim()) { if (textSearch?.trim()) {
queryParams.push(`textSearch=${encodeURIComponent(textSearch.trim())}`); queryParams.push(`textSearch=${encodeURIComponent(textSearch.trim())}`);
} }
@ -135,7 +147,7 @@ export class IotHubApiService {
public getListingItemVersion(slug: string, config?: IotHubRequestConfig): Observable<MpItemVersionView> { public getListingItemVersion(slug: string, config?: IotHubRequestConfig): Observable<MpItemVersionView> {
const queryParams = [ const queryParams = [
'ce=true', 'ce=true',
`tbVersion=${tbVersionToInt(env.tbVersion)}` `tbVersion=${this.platformScope().tbVersion}`
]; ];
return this.http.get<MpItemVersionView>( return this.http.get<MpItemVersionView>(
`${this.baseUrl}/api/listings/public/by-slug/${encodeURIComponent(slug)}/item-version?${queryParams.join('&')}`, `${this.baseUrl}/api/listings/public/by-slug/${encodeURIComponent(slug)}/item-version?${queryParams.join('&')}`,

6
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html

@ -80,12 +80,12 @@
} }
@if (selectWidgetMode === 'iotHub' && iotHubSubMode !== 'default') { @if (selectWidgetMode === 'iotHub' && iotHubSubMode !== 'default') {
<button mat-button type="button" class="tb-widget-select-sort" [matMenuTriggerFor]="sortMenu"> <button mat-button type="button" class="tb-widget-select-sort" [matMenuTriggerFor]="sortMenu">
{{ iotHubSortOptions[iotHubSelectedSortIndex].label | translate }} {{ iotHubSelectedSort.label | translate }}
<mat-icon iconPositionEnd>arrow_drop_down</mat-icon> <mat-icon iconPositionEnd>arrow_drop_down</mat-icon>
</button> </button>
<mat-menu #sortMenu="matMenu"> <mat-menu #sortMenu="matMenu">
@for (option of iotHubSortOptions; track option.value; let i = $index) { @for (option of iotHubSortOptions; track option.value) {
<button mat-menu-item (click)="onIotHubSortChange(i)">{{ option.label | translate }}</button> <button mat-menu-item (click)="onIotHubSortChange(option)">{{ option.label | translate }}</button>
} }
</mat-menu> </mat-menu>
} }

48
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts

@ -21,7 +21,14 @@ import { ItemSizeStrategy } from '@shared/components/grid/scroll-grid.component'
import { coerceBoolean } from '@shared/decorators/coercion'; import { coerceBoolean } from '@shared/decorators/coercion';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { MpItemVersionQuery, MpItemVersionView, widgetTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models'; import { MpItemVersionQuery, MpItemVersionView, widgetTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models';
import { ItemType, FilterParamInfo, WidgetCategory } from '@shared/models/iot-hub/iot-hub-item.models'; import {
FilterParamInfo,
IOT_HUB_SORT_OPTIONS,
ItemType,
RELEVANCE_SORT_PROPERTY,
SortOption,
WidgetCategory
} from '@shared/models/iot-hub/iot-hub-item.models';
import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubApiService } from '@core/http/iot-hub-api.service';
import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
@ -34,16 +41,13 @@ import {
} from '@home/components/iot-hub/iot-hub-utils'; } from '@home/components/iot-hub/iot-hub-utils';
import { IotHubBuiltInService } from '@home/components/iot-hub/iot-hub-built-in.service'; import { IotHubBuiltInService } from '@home/components/iot-hub/iot-hub-built-in.service';
/** The Installed list is sorted locally, and only the Hub can rank by relevance. */
const INSTALLED_SORT_OPTIONS = IOT_HUB_SORT_OPTIONS.filter(o => o.value !== RELEVANCE_SORT_PROPERTY);
type selectWidgetMode = 'installed' | 'iotHub'; type selectWidgetMode = 'installed' | 'iotHub';
type installedSubMode = 'default' | 'allWidgets'; type installedSubMode = 'default' | 'allWidgets';
type iotHubSubMode = 'default' | 'allWidgets' | 'installed' | 'category'; type iotHubSubMode = 'default' | 'allWidgets' | 'installed' | 'category';
interface WidgetSelectSortOption {
value: string;
label: string;
direction: Direction;
}
const LOGICAL_ALL_WIDGETS = '__logical_all_widgets__'; const LOGICAL_ALL_WIDGETS = '__logical_all_widgets__';
const LOGICAL_INSTALLED_FROM_IOT_HUB = '__logical_installed_from_iot_hub__'; const LOGICAL_INSTALLED_FROM_IOT_HUB = '__logical_installed_from_iot_hub__';
@ -88,12 +92,7 @@ export class DashboardWidgetSelectComponent {
includeDeprecated = false; includeDeprecated = false;
searchFocused = false; searchFocused = false;
iotHubSortOptions: WidgetSelectSortOption[] = [ private iotHubSelectedSortValue = IOT_HUB_SORT_OPTIONS[0].value;
{ value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC },
{ value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC },
{ value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC }
];
iotHubSelectedSortIndex = 0;
@Input() @Input()
aliasController: IAliasController; aliasController: IAliasController;
@ -305,7 +304,7 @@ export class DashboardWidgetSelectComponent {
this.iotHubWidgetsFetchFunction = (pageSize, page, filter) => { this.iotHubWidgetsFetchFunction = (pageSize, page, filter) => {
const search = typeof filter === 'string' ? filter.split('|')[0] : filter; const search = typeof filter === 'string' ? filter.split('|')[0] : filter;
const sort = this.iotHubSortOptions[this.iotHubSelectedSortIndex]; const sort = this.iotHubSelectedSort;
const sortOrder: SortOrder = { property: sort.value, direction: sort.direction }; const sortOrder: SortOrder = { property: sort.value, direction: sort.direction };
const pageLink = new PageLink(pageSize, page, search || null, sortOrder); const pageLink = new PageLink(pageSize, page, search || null, sortOrder);
const effectiveCategories = this.iotHubSelectedCategory const effectiveCategories = this.iotHubSelectedCategory
@ -583,9 +582,22 @@ export class DashboardWidgetSelectComponent {
this.reloadIotHubWidgets(); this.reloadIotHubWidgets();
} }
onIotHubSortChange(index: number): void { get iotHubSortOptions(): SortOption[] {
if (this.iotHubSelectedSortIndex !== index) { return this.iotHubSubMode === 'installed' ? INSTALLED_SORT_OPTIONS : IOT_HUB_SORT_OPTIONS;
this.iotHubSelectedSortIndex = index; }
/** The chosen sort, or the list's first option where the chosen one is not offered. */
get iotHubSelectedSort(): SortOption {
const options = this.iotHubSortOptions;
return options.find(o => o.value === this.iotHubSelectedSortValue) ?? options[0];
}
onIotHubSortChange(option: SortOption): void {
// Store the choice even when it is already the effective sort (the Installed list's fallback
// for relevance), so it survives a switch back to the IoT Hub list; reload only on a change.
const effective = this.iotHubSelectedSort.value;
this.iotHubSelectedSortValue = option.value;
if (effective !== option.value) {
this.installedWidgetVersions = null; this.installedWidgetVersions = null;
this.reloadIotHubWidgets(); this.reloadIotHubWidgets();
} }
@ -866,7 +878,7 @@ export class DashboardWidgetSelectComponent {
} }
private sortInstalledVersions(versions: MpItemVersionView[]): MpItemVersionView[] { private sortInstalledVersions(versions: MpItemVersionView[]): MpItemVersionView[] {
const sort = this.iotHubSortOptions[this.iotHubSelectedSortIndex]; const sort = this.iotHubSelectedSort;
const sign = sort.direction === Direction.ASC ? 1 : -1; const sign = sort.direction === Direction.ASC ? 1 : -1;
const copy = [...versions]; const copy = [...versions];
copy.sort((a, b) => { copy.sort((a, b) => {

30
ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss

@ -119,3 +119,33 @@
pointer-events: none; pointer-events: none;
} }
} }
// Scroll area whose thumb shows only while the container is hovered (the filter panels').
@mixin tb-iot-hub-hover-scrollbar {
&::-webkit-scrollbar {
width: 6px;
}
&::-webkit-scrollbar-track {
background-color: transparent;
}
&::-webkit-scrollbar-thumb {
background-color: transparent;
border-radius: 3px;
}
&:hover {
&::-webkit-scrollbar-track {
background-color: rgba(0, 0, 0, 0.04);
}
&::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.2);
&:hover {
background-color: rgba(0, 0, 0, 0.35);
}
}
}
}

24
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html

@ -50,8 +50,8 @@
} }
</div> </div>
} }
<div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(subtypeOptions, 'subtype').length > 8" <div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(subtypeOptions, 'subtype').length > scrollThreshold"
(mouseenter)="getFilteredItems(subtypeOptions, 'subtype').length > 8 && (filterItemsHovered = true)" (mouseenter)="getFilteredItems(subtypeOptions, 'subtype').length > scrollThreshold && (filterItemsHovered = true)"
(mouseleave)="filterItemsHovered = false"> (mouseleave)="filterItemsHovered = false">
@for (opt of getFilteredItems(subtypeOptions, 'subtype'); track opt.key) { @for (opt of getFilteredItems(subtypeOptions, 'subtype'); track opt.key) {
<mat-checkbox [checked]="isSubtypeActive(opt.key)" <mat-checkbox [checked]="isSubtypeActive(opt.key)"
@ -85,8 +85,8 @@
} }
</div> </div>
} }
<div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(vendorOptions, 'vendor').length > 8" <div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(vendorOptions, 'vendor').length > scrollThreshold"
(mouseenter)="getFilteredItems(vendorOptions, 'vendor').length > 8 && (filterItemsHovered = true)" (mouseenter)="getFilteredItems(vendorOptions, 'vendor').length > scrollThreshold && (filterItemsHovered = true)"
(mouseleave)="filterItemsHovered = false"> (mouseleave)="filterItemsHovered = false">
@for (group of getGroupedFilterItems(vendorOptions, 'vendor'); track group.label) { @for (group of getGroupedFilterItems(vendorOptions, 'vendor'); track group.label) {
@if (group.label) { @if (group.label) {
@ -121,8 +121,8 @@
} }
</div> </div>
} }
<div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(hardwareTypeOptions, 'hardwareType').length > 8" <div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(hardwareTypeOptions, 'hardwareType').length > scrollThreshold"
(mouseenter)="getFilteredItems(hardwareTypeOptions, 'hardwareType').length > 8 && (filterItemsHovered = true)" (mouseenter)="getFilteredItems(hardwareTypeOptions, 'hardwareType').length > scrollThreshold && (filterItemsHovered = true)"
(mouseleave)="filterItemsHovered = false"> (mouseleave)="filterItemsHovered = false">
@for (ht of getFilteredItems(hardwareTypeOptions, 'hardwareType'); track ht.key) { @for (ht of getFilteredItems(hardwareTypeOptions, 'hardwareType'); track ht.key) {
<mat-checkbox [checked]="isHardwareTypeActive(ht.key)" <mat-checkbox [checked]="isHardwareTypeActive(ht.key)"
@ -152,8 +152,8 @@
} }
</div> </div>
} }
<div class="tb-iot-hub-filter-items" [class.scrollable]="allConnectivityCount > 8" <div class="tb-iot-hub-filter-items" [class.scrollable]="allConnectivityCount > scrollThreshold"
(mouseenter)="allConnectivityCount > 8 && (filterItemsHovered = true)" (mouseenter)="allConnectivityCount > scrollThreshold && (filterItemsHovered = true)"
(mouseleave)="filterItemsHovered = false"> (mouseleave)="filterItemsHovered = false">
@for (group of getFilteredConnectivityGroups('connectivity'); track group.group) { @for (group of getFilteredConnectivityGroups('connectivity'); track group.group) {
<div class="tb-iot-hub-filter-group-label">{{ group.group }}</div> <div class="tb-iot-hub-filter-group-label">{{ group.group }}</div>
@ -189,8 +189,8 @@
} }
</div> </div>
} }
<div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(categoryOptions, 'category').length > 8" <div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(categoryOptions, 'category').length > scrollThreshold"
(mouseenter)="getFilteredItems(categoryOptions, 'category').length > 8 && (filterItemsHovered = true)" (mouseenter)="getFilteredItems(categoryOptions, 'category').length > scrollThreshold && (filterItemsHovered = true)"
(mouseleave)="filterItemsHovered = false"> (mouseleave)="filterItemsHovered = false">
@for (cat of getFilteredItems(categoryOptions, 'category'); track cat.key) { @for (cat of getFilteredItems(categoryOptions, 'category'); track cat.key) {
<mat-checkbox [checked]="isCategoryActive(cat.key)" <mat-checkbox [checked]="isCategoryActive(cat.key)"
@ -224,8 +224,8 @@
} }
</div> </div>
} }
<div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(useCaseOptions, 'useCase').length > 8" <div class="tb-iot-hub-filter-items" [class.scrollable]="getFilteredItems(useCaseOptions, 'useCase').length > scrollThreshold"
(mouseenter)="getFilteredItems(useCaseOptions, 'useCase').length > 8 && (filterItemsHovered = true)" (mouseenter)="getFilteredItems(useCaseOptions, 'useCase').length > scrollThreshold && (filterItemsHovered = true)"
(mouseleave)="filterItemsHovered = false"> (mouseleave)="filterItemsHovered = false">
@for (group of getGroupedFilterItems(useCaseOptions, 'useCase'); track group.label) { @for (group of getGroupedFilterItems(useCaseOptions, 'useCase'); track group.label) {
@if (group.label) { @if (group.label) {

47
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts

@ -4,23 +4,29 @@ import { AfterViewInit, Component, ElementRef, EventEmitter, Input, NgZone, OnDe
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { debounceTime, takeUntil } from 'rxjs/operators'; import { debounceTime, takeUntil } from 'rxjs/operators';
import { PageLink } from '@shared/models/page/page-link'; import { PageLink } from '@shared/models/page/page-link';
import { Direction, SortOrder } from '@shared/models/page/sort-order'; import { SortOrder } from '@shared/models/page/sort-order';
import { PageData } from '@shared/models/page/page-data'; import { PageData } from '@shared/models/page/page-data';
import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models';
import { ItemType, FilterParamInfo, CREATOR_VISIBLE_ITEM_TYPES } from '@shared/models/iot-hub/iot-hub-item.models'; import {
CREATOR_VISIBLE_ITEM_TYPES,
FilterParamInfo,
IOT_HUB_SORT_OPTIONS,
isCompactItemType,
ItemType
} from '@shared/models/iot-hub/iot-hub-item.models';
import { widgetTypeTranslations, cfTypeTranslations, ruleChainTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models'; import { widgetTypeTranslations, cfTypeTranslations, ruleChainTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models';
import { IotHubInstalledItem, DeviceInstalledItemDescriptor } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubInstalledItem, DeviceInstalledItemDescriptor } from '@shared/models/iot-hub/iot-hub-installed-item.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubApiService } from '@core/http/iot-hub-api.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service';
import { filterIotHubItemsBySearch, groupIotHubFilterItems, IotHubFilterGroup } from '@home/components/iot-hub/iot-hub-utils'; import {
filterIotHubItemsBySearch,
interface SortOption { groupIotHubFilterItems,
value: string; IOT_HUB_FILTER_SCROLL_THRESHOLD,
label: string; IotHubFilterGroup,
direction: Direction; measureGridColumns
} } from '@home/components/iot-hub/iot-hub-utils';
@Component({ @Component({
selector: 'tb-iot-hub-browse', selector: 'tb-iot-hub-browse',
@ -43,6 +49,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy
} }
readonly ItemType = ItemType; readonly ItemType = ItemType;
readonly scrollThreshold = IOT_HUB_FILTER_SCROLL_THRESHOLD;
@Input() creatorId: string; @Input() creatorId: string;
@Input() embedded = false; @Input() embedded = false;
@ -78,9 +85,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy
} }
get isCompactType(): boolean { get isCompactType(): boolean {
return this._activeType === ItemType.CALCULATED_FIELD return isCompactItemType(this._activeType);
|| this._activeType === ItemType.ALARM_RULE
|| this._activeType === ItemType.RULE_CHAIN;
} }
get searchPlaceholderKey(): string { get searchPlaceholderKey(): string {
@ -130,11 +135,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy
activeVendors = new Set<string>(); activeVendors = new Set<string>();
verifiedCreatorsOnly = false; verifiedCreatorsOnly = false;
sortOptions: SortOption[] = [ readonly sortOptions = IOT_HUB_SORT_OPTIONS;
{ value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC },
{ value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC },
{ value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC }
];
typeTabs: { type: ItemType; label: string }[] = CREATOR_VISIBLE_ITEM_TYPES.map(t => ({ typeTabs: { type: ItemType; label: string }[] = CREATOR_VISIBLE_ITEM_TYPES.map(t => ({
type: t, type: t,
@ -221,17 +222,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy
if (!el) { if (!el) {
return this.probeCols; return this.probeCols;
} }
// Force layout so `grid-template-columns` resolves to pixel tracks, not `repeat(...)`. return measureGridColumns(el);
void el.offsetWidth;
const tracks = getComputedStyle(el).gridTemplateColumns;
if (!tracks || tracks === 'none') {
return 1;
}
if (tracks.startsWith('repeat(')) {
const match = tracks.match(/^repeat\(\s*(\d+)\s*,/);
return match ? parseInt(match[1], 10) : 1;
}
return Math.max(1, tracks.trim().split(/\s+/).filter(t => t.length > 0).length);
} }
private adjustPageSize(): void { private adjustPageSize(): void {

3
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts

@ -14,6 +14,7 @@ import { TbIotHubUnpublishedWarningDialogComponent } from './iot-hub-unpublished
import { TbDeviceInstallDialogComponent } from './device-install-dialog/device-install-dialog.component'; import { TbDeviceInstallDialogComponent } from './device-install-dialog/device-install-dialog.component';
import { InstallFormRendererComponent } from './device-install-dialog/install-form-renderer/install-form-renderer.component'; import { InstallFormRendererComponent } from './device-install-dialog/install-form-renderer/install-form-renderer.component';
import { TbIotHubSearchComponent } from './iot-hub-search.component'; import { TbIotHubSearchComponent } from './iot-hub-search.component';
import { TbIotHubFacetListComponent } from './iot-hub-facet-list.component';
import { TbIotHubInstalledItemsTableComponent } from './iot-hub-installed-items-table.component'; import { TbIotHubInstalledItemsTableComponent } from './iot-hub-installed-items-table.component';
import { TbIotHubInstalledItemsDialogComponent } from './iot-hub-installed-items-dialog.component'; import { TbIotHubInstalledItemsDialogComponent } from './iot-hub-installed-items-dialog.component';
import { TbPeConnectivityMethodPromptComponent } from './pe-connectivity-method-prompt.component'; import { TbPeConnectivityMethodPromptComponent } from './pe-connectivity-method-prompt.component';
@ -36,6 +37,7 @@ import { IotHubItemLinkModule } from './iot-hub-item-link-card/iot-hub-item-link
TbIotHubUnpublishedWarningDialogComponent, TbIotHubUnpublishedWarningDialogComponent,
TbDeviceInstallDialogComponent, TbDeviceInstallDialogComponent,
TbIotHubSearchComponent, TbIotHubSearchComponent,
TbIotHubFacetListComponent,
TbIotHubInstalledItemsTableComponent, TbIotHubInstalledItemsTableComponent,
TbIotHubInstalledItemsDialogComponent, TbIotHubInstalledItemsDialogComponent,
TbPeConnectivityMethodPromptComponent, TbPeConnectivityMethodPromptComponent,
@ -64,6 +66,7 @@ import { IotHubItemLinkModule } from './iot-hub-item-link-card/iot-hub-item-link
TbIotHubUnpublishedWarningDialogComponent, TbIotHubUnpublishedWarningDialogComponent,
TbDeviceInstallDialogComponent, TbDeviceInstallDialogComponent,
TbIotHubSearchComponent, TbIotHubSearchComponent,
TbIotHubFacetListComponent,
TbIotHubInstalledItemsTableComponent, TbIotHubInstalledItemsTableComponent,
TbIotHubInstalledItemsDialogComponent, TbIotHubInstalledItemsDialogComponent,
TbPeConnectivityMethodPromptComponent, TbPeConnectivityMethodPromptComponent,

31
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html

@ -0,0 +1,31 @@
<!--
SPDX-FileCopyrightText: Copyright The Thingsboard Authors
SPDX-License-Identifier: Apache-2.0
-->
<mat-expansion-panel [expanded]="expanded" class="tb-iot-hub-facet-panel">
<mat-expansion-panel-header>
<mat-panel-title>{{ label | translate }}</mat-panel-title>
</mat-expansion-panel-header>
@if (searchable) {
<div class="tb-iot-hub-facet-search">
<mat-icon>search</mat-icon>
<input [placeholder]="'iot-hub.search' | translate" [ngModel]="search" (ngModelChange)="onSearchChange($event)">
@if (search) {
<button mat-icon-button class="tb-iot-hub-facet-search-clear" (click)="onSearchChange('')">
<mat-icon>close</mat-icon>
</button>
}
</div>
}
<div class="tb-iot-hub-facet-items" [class.scrollable]="scrollable">
@for (key of visibleOptions; track key) {
<mat-checkbox [checked]="isSelected(key)" (change)="onToggle(key)">
{{ labelFor(key) }}
</mat-checkbox>
}
</div>
</mat-expansion-panel>

63
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss

@ -0,0 +1,63 @@
// SPDX-FileCopyrightText: Copyright The Thingsboard Authors
// SPDX-License-Identifier: Apache-2.0
@import "./iot-hub-common";
// Matches the type pages' filter panel, minus its rail indent.
.tb-iot-hub-facet-panel.mat-expansion-panel {
box-shadow: none;
border-radius: 0;
background: transparent;
// Text is indented by --tb-facet-indent (set by the host); the rules between facets are not.
.mat-expansion-panel-header {
padding: 8px 16px 8px var(--tb-facet-indent, 16px);
height: 48px;
min-height: 48px;
}
::ng-deep .mat-expansion-panel-header-title {
font-size: 14px;
font-weight: 500;
color: rgba(0, 0, 0, 0.87);
}
::ng-deep .mat-expansion-panel-body {
padding: 0 8px 8px var(--tb-facet-indent, 16px);
}
mat-checkbox {
display: block;
overflow: hidden;
&:hover {
background: rgba(0, 0, 0, 0.04);
}
}
.tb-iot-hub-facet-items {
// Capped only when long enough to scroll.
&.scrollable {
max-height: 280px;
overflow-y: auto;
}
@include tb-iot-hub-hover-scrollbar;
}
.tb-iot-hub-facet-search {
@include tb-iot-hub-search-container;
margin: 4px 8px 8px 0;
mat-icon {
@include tb-iot-hub-search-icon(rgba(0, 0, 0, 0.54));
}
input {
@include tb-iot-hub-search-input-text(0.2px);
}
.tb-iot-hub-facet-search-clear.mat-mdc-icon-button {
@include tb-iot-hub-search-clear;
}
}
}

60
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts

@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: Copyright The Thingsboard Authors
// SPDX-License-Identifier: Apache-2.0
import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { filterByLabel, IOT_HUB_FILTER_SCROLL_THRESHOLD } from '@home/components/iot-hub/iot-hub-utils';
/**
* One checkbox facet of a filter panel: a title, the option keys, and the set of keys currently
* selected. Presentational only - the host decides what a toggle means.
*/
@Component({
selector: 'tb-iot-hub-facet-list',
standalone: false,
templateUrl: './iot-hub-facet-list.component.html',
styleUrls: ['./iot-hub-facet-list.component.scss']
})
export class TbIotHubFacetListComponent implements OnChanges {
/** Translation key for the facet's heading. */
@Input() label: string;
@Input() options: string[] = [];
/** Keys the host has selected. The host hands over a new Set on every toggle. */
@Input() selected = new Set<string>();
/** Turns an option key into what the user reads. */
@Input() labelFor: (key: string) => string = (key) => key;
@Input() expanded = true;
@Output() toggled = new EventEmitter<string>();
search = '';
searchable = false;
visibleOptions: string[] = [];
scrollable = false;
ngOnChanges(): void {
this.searchable = this.options.length > IOT_HUB_FILTER_SCROLL_THRESHOLD;
this.applySearch();
}
onSearchChange(search: string): void {
this.search = search;
this.applySearch();
}
isSelected(key: string): boolean {
return this.selected.has(key);
}
onToggle(key: string): void {
this.toggled.emit(key);
}
private applySearch(): void {
this.visibleOptions = filterByLabel(this.options, this.search, this.labelFor);
this.scrollable = this.visibleOptions.length > IOT_HUB_FILTER_SCROLL_THRESHOLD;
}
}

3
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html

@ -78,7 +78,8 @@
<img [src]="previewUrl" alt="" class="tb-iot-hub-preview-image"> <img [src]="previewUrl" alt="" class="tb-iot-hub-preview-image">
} @else { } @else {
<div class="tb-iot-hub-preview-placeholder"> <div class="tb-iot-hub-preview-placeholder">
<tb-icon>{{ getPlaceholderIcon() }}</tb-icon> <!-- The item's own colour, standing in for the compact card's coloured square. -->
<tb-icon [style.color]="item.color || null">{{ getPlaceholderIcon() }}</tb-icon>
</div> </div>
} }
</div> </div>

14
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts

@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, Input, Output } from '@angular/core';
import { MpItemVersionView, cfTypeTranslations, cfTypeIcons, ruleChainTypeTranslations, widgetTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models'; import { MpItemVersionView, cfTypeTranslations, cfTypeIcons, ruleChainTypeTranslations, widgetTypeTranslations } from '@shared/models/iot-hub/iot-hub-version.models';
import { getItemTypeIcon, ItemType } from '@shared/models/iot-hub/iot-hub-item.models'; import { getItemTypeIcon, isCompactItemType, ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubApiService } from '@core/http/iot-hub-api.service';
@ -23,6 +23,11 @@ export class TbIotHubItemCardComponent {
@Input() showTypeChip = true; @Input() showTypeChip = true;
@Input() showSubtype = false; @Input() showSubtype = false;
@Input() mode: 'default' | 'add' = 'default'; @Input() mode: 'default' | 'add' = 'default';
/**
* `auto`: compact row for the types with nothing to preview (single-type grids widen their
* cells for it). `preview`: the tall card for every type, for grids that mix types.
*/
@Input() layout: 'auto' | 'preview' = 'auto';
@Output() cardClick = new EventEmitter<MpItemVersionView>(); @Output() cardClick = new EventEmitter<MpItemVersionView>();
@Output() creatorClick = new EventEmitter<string>(); @Output() creatorClick = new EventEmitter<string>();
@Output() installClick = new EventEmitter<MpItemVersionView>(); @Output() installClick = new EventEmitter<MpItemVersionView>();
@ -47,9 +52,10 @@ export class TbIotHubItemCardComponent {
} }
isCompactLayout(): boolean { isCompactLayout(): boolean {
return this.item.type === ItemType.CALCULATED_FIELD if (this.layout === 'preview') {
|| this.item.type === ItemType.ALARM_RULE return false;
|| this.item.type === ItemType.RULE_CHAIN; }
return isCompactItemType(this.item.type);
} }
getPreviewUrl(): string | null { getPreviewUrl(): string | null {

6
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts

@ -7,7 +7,7 @@ import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { DialogComponent } from '@shared/components/dialog.component'; import { DialogComponent } from '@shared/components/dialog.component';
import { MpItemVersionView, cfTypeTranslations, cfTypeIcons, ruleChainTypeTranslations, widgetTypeTranslations, NodeInfo } from '@shared/models/iot-hub/iot-hub-version.models'; import { MpItemVersionView, cfTypeTranslations, cfTypeIcons, ruleChainTypeTranslations, widgetTypeTranslations, NodeInfo } from '@shared/models/iot-hub/iot-hub-version.models';
import { getItemTypeIcon, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; import { getItemTypeIcon, isCompactItemType, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models';
import { getInstalledItemUrl, IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { getInstalledItemUrl, IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubApiService } from '@core/http/iot-hub-api.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -87,9 +87,7 @@ export class TbIotHubItemDetailDialogComponent extends DialogComponent<TbIotHubI
} }
isCompactLayout(): boolean { isCompactLayout(): boolean {
return this.item.type === ItemType.CALCULATED_FIELD return isCompactItemType(this.item.type);
|| this.item.type === ItemType.ALARM_RULE
|| this.item.type === ItemType.RULE_CHAIN;
} }
getPreviewUrl(): string | null { getPreviewUrl(): string | null {

160
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.html

@ -4,14 +4,26 @@
SPDX-License-Identifier: Apache-2.0 SPDX-License-Identifier: Apache-2.0
--> -->
<div class="mb-10 flex items-baseline gap-4 lt-md:mb-4"> <div class="tb-search-pad mb-10 flex items-baseline gap-4 lt-md:mb-4">
<ng-content></ng-content> <ng-content></ng-content>
<span class="tb-search-results-count tb-search-results-count-mobile"> <span class="tb-search-results-count tb-search-results-count-mobile">
{{ 'iot-hub.results-count' | translate:{ count: totalElements } }} {{ 'iot-hub.results-count' | translate:{ count: totalElements } }}
</span> </span>
</div> </div>
<!-- Search + Sort row --> <!-- Hidden probe — we read its computed grid-template-columns to detect the current column count. -->
<div class="flex items-center gap-4"> <div #cardGridProbe class="tb-search-card-grid tb-search-card-grid-probe" aria-hidden="true"></div>
<!-- Filter + Search + Sort row -->
<div class="tb-search-pad flex items-center gap-4">
@if (showFilters) {
<button mat-stroked-button class="tb-search-filter-btn" (click)="filtersOpen = !filtersOpen">
<mat-icon>filter_alt</mat-icon>
{{ 'iot-hub.filter' | translate }}
@if (activeFilterCount > 0) {
<span class="tb-search-filter-count">{{ activeFilterCount }}</span>
}
</button>
}
<div class="tb-search-input-field flex flex-1 items-center"> <div class="tb-search-input-field flex flex-1 items-center">
<input class="tb-search-input" <input class="tb-search-input"
[placeholder]="searchPlaceholderKey | translate" [placeholder]="searchPlaceholderKey | translate"
@ -43,7 +55,7 @@
</div> </div>
<!-- Results count + Pagination (shown when results exist) --> <!-- Results count + Pagination (shown when results exist) -->
<div class="tb-search-pagination-row" [class.lt-md:!hidden]="totalElements === 0"> <div class="tb-search-pagination-row tb-search-pad" [class.lt-md:!hidden]="totalElements === 0">
<span class="tb-search-results-count"> <span class="tb-search-results-count">
{{ 'iot-hub.results-count' | translate:{ count: totalElements } }} {{ 'iot-hub.results-count' | translate:{ count: totalElements } }}
</span> </span>
@ -76,62 +88,98 @@
<div class="tb-search-divider"></div> <div class="tb-search-divider"></div>
<div class="relative min-h-0"> <!-- Facets, rendered once and projected into the sidebar or the drawer -->
<ng-template #facetPanel>
<div class="tb-results-container"> <div class="tb-search-facets">
<!-- Error --> @if (activeFilterCount > 0) {
@if (hasError) { <button mat-button color="primary" class="tb-search-facets-clear" (click)="clearFilters()">
<div class="tb-search-empty flex flex-col items-center py-10"> {{ 'iot-hub.clear-filters' | translate }}
<div class="tb-no-service-bg"></div> </button>
<h3>{{ 'iot-hub.network-server-unavailable' | translate }}</h3>
<p>{{ 'iot-hub.network-server-unavailable-text' | translate }}</p>
<button mat-flat-button color="primary" (click)="retryLoadResults()">
{{ 'iot-hub.try-again' | translate }}
</button>
</div>
} }
<tb-iot-hub-facet-list label="iot-hub.item-type"
<!-- No results --> [options]="typeOptions"
@if (!hasError && totalElements === 0 && searchText?.trim()) { [selected]="activeTypes"
<div class="tb-search-empty flex flex-col items-center py-10"> [labelFor]="getTypeLabel"
<div class="tb-no-data-bg"></div> (toggled)="onTypeToggle($event)">
<h3>{{ 'iot-hub.no-items-found' | translate }}</h3> </tb-iot-hub-facet-list>
<p>{{ 'iot-hub.try-adjusting-search' | translate }}</p> @if (categoryOptions.length > 0) {
</div> <!-- Closed by default: these run to dozens of options. -->
<tb-iot-hub-facet-list label="iot-hub.category"
[expanded]="false"
[options]="categoryOptions"
[selected]="activeCategories"
(toggled)="onCategoryToggle($event)">
</tb-iot-hub-facet-list>
} }
@if (useCaseOptions.length > 0) {
<tb-iot-hub-facet-list label="iot-hub.use-case"
[expanded]="false"
[options]="useCaseOptions"
[selected]="activeUseCases"
(toggled)="onUseCaseToggle($event)">
</tb-iot-hub-facet-list>
}
</div>
</ng-template>
<!-- Results grouped by type --> <div class="relative min-h-0 flex-1">
@if (resultGroups.length > 0) {
<div class="tb-search-categories"> <!-- A flex row, not mat-drawer-container, which let a tall facet list overflow the card. -->
@for (group of resultGroups; track group.type) { <div class="tb-search-layout">
<div class="tb-search-section"> @if (showFilters) {
<!-- Section header --> <aside class="tb-search-facets-desktop" [class.opened]="filtersOpen">
<button mat-button class="tb-search-section-header" (click)="navigateToType(group.type)"> <div class="tb-search-facets-header flex items-center justify-between">
{{ getTypeLabel(group.type) }} <span>{{ 'iot-hub.filter' | translate }}</span>
<mat-icon>chevron_right</mat-icon> <button mat-icon-button (click)="filtersOpen = false">
</button> <mat-icon>close</mat-icon>
<!-- Card grid --> </button>
<div class="tb-search-card-grid" [class.tb-search-card-grid-compact]="isCompactType(group.type)"> </div>
@for (item of group.items; track item.id) { <ng-container *ngTemplateOutlet="facetPanel"></ng-container>
<tb-iot-hub-item-card </aside>
[item]="item"
[installedItem]="getInstalledItem(item)"
[installedItemsCount]="getInstalledItemsCount(item)"
[showTypeChip]="false"
[showSubtype]="false"
[showCreator]="showCreator"
(cardClick)="openItemDetail($event)"
(creatorClick)="navigateToCreator($event)"
(installClick)="installItem($event)"
(updateClick)="updateItem($event)"
(deleteClick)="deleteInstalledItem($event)">
</tb-iot-hub-item-card>
}
</div>
</div>
}
</div>
} }
<div class="tb-results-container">
<!-- Error -->
@if (hasError) {
<div class="tb-search-empty flex flex-col items-center py-10">
<div class="tb-no-service-bg"></div>
<h3>{{ 'iot-hub.network-server-unavailable' | translate }}</h3>
<p>{{ 'iot-hub.network-server-unavailable-text' | translate }}</p>
<button mat-flat-button color="primary" (click)="retryLoadResults()">
{{ 'iot-hub.try-again' | translate }}
</button>
</div>
}
<!-- No results -->
@if (!hasError && totalElements === 0 && searchText?.trim()) {
<div class="tb-search-empty flex flex-col items-center py-10">
<div class="tb-no-data-bg"></div>
<h3>{{ 'iot-hub.no-items-found' | translate }}</h3>
<p>{{ 'iot-hub.try-adjusting-search' | translate }}</p>
</div>
}
<!-- Results -->
@if (results.length > 0) {
<div class="tb-search-card-grid">
@for (item of results; track item.id) {
<tb-iot-hub-item-card
layout="preview"
[item]="item"
[installedItem]="getInstalledItem(item)"
[installedItemsCount]="getInstalledItemsCount(item)"
[showCreator]="showCreator"
(cardClick)="openItemDetail($event)"
(creatorClick)="navigateToCreator($event)"
(installClick)="installItem($event)"
(updateClick)="updateItem($event)"
(deleteClick)="deleteInstalledItem($event)">
</tb-iot-hub-item-card>
}
</div>
}
</div>
</div> </div>
<!-- Loading --> <!-- Loading -->

160
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss

@ -8,6 +8,13 @@
flex-direction: column; flex-direction: column;
} }
// Full bleed: content rows pad themselves in by --tb-search-side-pad; the divider and the filter
// rail reach the edge.
.tb-search-pad {
padding-left: var(--tb-search-side-pad, 0px);
padding-right: var(--tb-search-side-pad, 0px);
}
.tb-search-results-count-mobile { .tb-search-results-count-mobile {
display: none; display: none;
margin-left: auto; margin-left: auto;
@ -143,69 +150,113 @@
overflow: auto; overflow: auto;
} }
// Categories / sections // Card grid
.tb-search-categories { .tb-search-card-grid {
display: flex; display: grid;
flex-direction: column; grid-template-columns: repeat(5, 1fr);
gap: 48px; gap: 20px;
// Zero-height probe for the column count; needs display: grid and a width to resolve tracks.
&.tb-search-card-grid-probe {
width: 100%;
height: 0;
gap: 0;
overflow: hidden;
visibility: hidden;
pointer-events: none;
}
} }
// Section header // Filter button, with the active count
.tb-search-section-header { .tb-search-filter-btn {
font-size: 18px; flex-shrink: 0;
font-weight: 500; }
line-height: 24px;
color: rgba(0, 0, 0, 0.87); .tb-search-filter-count {
padding: 0; margin-left: 6px;
margin-bottom: 12px; min-width: 18px;
height: 18px;
padding: 0 5px;
border-radius: 9px;
background: rgba(0, 0, 0, 0.08);
font-size: 12px;
line-height: 18px;
font-variant-numeric: tabular-nums;
}
mat-icon { // Facet sidebar beside the grid. Both columns scroll inside the given height, so neither grows
font-size: 24px; // past the card.
width: 24px; .tb-search-layout {
height: 24px; display: flex;
gap: 24px;
height: 100%;
min-height: 0;
.tb-results-container {
flex: 1;
min-width: 0;
// Only on the right: the gap to the rail already separates it on the left.
padding-right: var(--tb-search-side-pad, 0px);
} }
} }
// Card grid .tb-search-facets-desktop {
.tb-search-card-grid { width: 232px;
display: grid; flex-shrink: 0;
grid-template-columns: repeat(5, 1fr); border-right: 1px solid rgba(0, 0, 0, 0.12);
gap: 20px;
&.tb-search-card-grid-compact { // Starts at the card's edge so the rules across it reach it; each facet indents its own text.
grid-template-columns: repeat(3, 1fr); --tb-facet-indent: var(--tb-search-side-pad, 16px);
align-self: stretch;
height: 100%;
overflow-y: auto;
padding-top: 20px;
@include tb-iot-hub-hover-scrollbar;
}
// The close button and heading belong to the narrow layout only.
.tb-search-facets-header {
display: none;
height: 48px;
font-size: 16px;
font-weight: 500;
}
.tb-search-facets {
display: flex;
flex-direction: column;
padding-bottom: 24px;
// A flush rule between filter sections, as on the type pages.
tb-iot-hub-facet-list + tb-iot-hub-facet-list {
border-top: 1px solid rgba(0, 0, 0, 0.12);
} }
} }
.tb-search-facets-clear {
align-self: flex-start;
margin-left: calc(var(--tb-facet-indent, 16px) - 16px);
}
// Responsive // Responsive
@media #{$mat-gt-xxl} { @media #{$mat-gt-xxl} {
.tb-search-card-grid { .tb-search-card-grid {
grid-template-columns: repeat(6, 1fr); grid-template-columns: repeat(6, 1fr);
&.tb-search-card-grid-compact {
grid-template-columns: repeat(4, 1fr);
}
} }
} }
@media #{$mat-lt-xl} { @media #{$mat-lt-xl} {
.tb-search-card-grid { .tb-search-card-grid {
grid-template-columns: repeat(4, 1fr); grid-template-columns: repeat(4, 1fr);
&.tb-search-card-grid-compact {
grid-template-columns: repeat(3, 1fr);
}
} }
} }
@media #{$mat-lt-xmd} { @media #{$mat-lt-xmd} {
.tb-search-card-grid { .tb-search-card-grid {
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
&.tb-search-card-grid-compact {
grid-template-columns: repeat(2, 1fr);
}
} }
} }
@ -228,10 +279,6 @@
.tb-search-card-grid { .tb-search-card-grid {
grid-template-columns: repeat(2, 1fr); grid-template-columns: repeat(2, 1fr);
&.tb-search-card-grid-compact {
grid-template-columns: repeat(1, 1fr);
}
} }
} }
@ -268,3 +315,36 @@
margin-left: 0; margin-left: 0;
} }
} }
// Below this width the sidebar collapses and the Filter button opens it above the results.
@media #{$mat-lt-lg} {
.tb-search-layout {
flex-direction: column;
}
.tb-search-facets-desktop {
display: none;
// Above the results it is content, not a rail, so it is padded in like the rows above.
width: 100%;
height: auto;
max-height: 60vh;
border-right: none;
border-bottom: 1px solid rgba(0, 0, 0, 0.12);
padding-right: 0;
&.opened {
display: block;
}
}
.tb-search-facets-header {
display: flex;
}
}
// The sidebar is shown, so there is nothing for the button to open.
@media #{$mat-gt-md} {
.tb-search-filter-btn {
display: none;
}
}

297
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts

@ -1,33 +1,29 @@
// SPDX-FileCopyrightText: Copyright The Thingsboard Authors // SPDX-FileCopyrightText: Copyright The Thingsboard Authors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core'; import { Component, OnInit, OnDestroy, Input, Output, EventEmitter, ViewChild, ElementRef, NgZone } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { forkJoin, Subject, Subscription } from 'rxjs'; import { forkJoin, of, Subject, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; import { catchError, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
import { PageLink } from '@shared/models/page/page-link'; import { PageLink } from '@shared/models/page/page-link';
import { Direction, SortOrder } from '@shared/models/page/sort-order'; import { SortOrder } from '@shared/models/page/sort-order';
import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models';
import { ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; import { PageData } from '@shared/models/page/page-data';
import {
CROSS_TYPE_ITEM_TYPES,
FilterParamInfo,
IOT_HUB_SORT_OPTIONS,
ItemType,
itemTypeTranslations
} from '@shared/models/iot-hub/iot-hub-item.models';
import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubApiService } from '@core/http/iot-hub-api.service';
import { IotHubActionsService } from './iot-hub-actions.service'; import { IotHubActionsService } from './iot-hub-actions.service';
import { measureGridColumns } from './iot-hub-utils';
interface SearchResultGroup { /** A page is whole rows of the grid, and never fewer than MIN_PAGE_SIZE cards. */
type: ItemType; const ROWS_PER_PAGE = 3;
items: MpItemVersionView[]; const MIN_PAGE_SIZE = 12;
}
interface SortOption {
value: string;
label: string;
direction: Direction;
}
const TYPE_ORDER: ItemType[] = [
ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, ItemType.WIDGET,
ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN
];
@Component({ @Component({
selector: 'tb-iot-hub-search', selector: 'tb-iot-hub-search',
@ -37,32 +33,50 @@ const TYPE_ORDER: ItemType[] = [
}) })
export class TbIotHubSearchComponent implements OnInit, OnDestroy { export class TbIotHubSearchComponent implements OnInit, OnDestroy {
readonly ItemType = ItemType;
@Input() searchText = ''; @Input() searchText = '';
@Input() creatorId: string; @Input() creatorId: string;
@Input() showCreator = true; @Input() showCreator = true;
/** Off on the creator profile, which is already scoped to one creator. */
@Input() showFilters = true;
@Output() searchTextChange = new EventEmitter<string>(); @Output() searchTextChange = new EventEmitter<string>();
get searchPlaceholderKey(): string { get searchPlaceholderKey(): string {
return this.creatorId ? 'iot-hub.search-published-items' : 'iot-hub.search'; return this.creatorId ? 'iot-hub.search-published-items' : 'iot-hub.search';
} }
resultGroups: SearchResultGroup[] = []; results: MpItemVersionView[] = [];
totalElements = 0; totalElements = 0;
isLoading = false; isLoading = false;
hasError = false; hasError = false;
private retryTimer: any = null; private retryTimer: any = null;
pageSize = 15;
pageIndex = 0; pageIndex = 0;
pageSizeOptions = [15, 30, 60];
sortOptions: SortOption[] = [ /** A hidden element carrying the real grid's classes, so the column count comes from the CSS. */
{ value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC }, @ViewChild('cardGridProbe', { static: true }) cardGridProbe!: ElementRef<HTMLElement>;
{ value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC }, cols = 5;
{ value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC } pageSize = MIN_PAGE_SIZE;
]; private resizeObserver?: ResizeObserver;
private resizeSubject = new Subject<void>();
private resizeSubscription?: Subscription;
get pageSizeOptions(): number[] {
const base = Math.max(MIN_PAGE_SIZE, this.cols * ROWS_PER_PAGE);
return [base, base * 2, base * 4];
}
// Filter panel state. An empty set means "no filter".
/** Narrow widths only: the facet panel is a block above the results, not a sidebar. */
filtersOpen = false;
readonly typeOptions: string[] = CROSS_TYPE_ITEM_TYPES;
categoryOptions: string[] = [];
useCaseOptions: string[] = [];
activeTypes = new Set<string>();
activeCategories = new Set<string>();
activeUseCases = new Set<string>();
readonly sortOptions = IOT_HUB_SORT_OPTIONS;
selectedSortIndex = 0; selectedSortIndex = 0;
installedWidgets: IotHubInstalledItem[] = []; installedWidgets: IotHubInstalledItem[] = [];
@ -74,16 +88,30 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
private searchSubject = new Subject<string>(); private searchSubject = new Subject<string>();
private searchSubscription: Subscription; private searchSubscription: Subscription;
/** Every reload goes through here, so a newer request cancels an older one still in flight. */
private loadSubject = new Subject<void>();
private loadSubscription: Subscription;
constructor( constructor(
private router: Router, private router: Router,
private translate: TranslateService, private translate: TranslateService,
private iotHubApiService: IotHubApiService, private iotHubApiService: IotHubApiService,
private iotHubActions: IotHubActionsService private iotHubActions: IotHubActionsService,
private zone: NgZone
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
this.measureCols();
this.observeGridWidth();
if (this.showFilters) {
this.loadFilterInfo();
}
this.loadInstalledItems(); this.loadInstalledItems();
this.loadSubscription = this.loadSubject.pipe(
switchMap(() => this.fetchResults(this.searchText || '').pipe(
catchError(() => of(null))
))
).subscribe(result => this.applyResult(result));
this.searchSubscription = this.searchSubject.pipe( this.searchSubscription = this.searchSubject.pipe(
debounceTime(300), debounceTime(300),
distinctUntilChanged() distinctUntilChanged()
@ -96,6 +124,125 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
ngOnDestroy(): void { ngOnDestroy(): void {
this.searchSubscription?.unsubscribe(); this.searchSubscription?.unsubscribe();
this.loadSubscription?.unsubscribe();
this.resizeSubscription?.unsubscribe();
this.resizeObserver?.disconnect();
}
// Filters
getTypeLabel = (key: string): string => {
const translationKey = itemTypeTranslations.get(key as ItemType);
return translationKey ? this.translate.instant(translationKey + '-plural') : key;
};
onTypeToggle(key: string): void {
this.activeTypes = this.toggled(this.activeTypes, key);
this.reloadFromFirstPage();
}
onCategoryToggle(key: string): void {
this.activeCategories = this.toggled(this.activeCategories, key);
this.reloadFromFirstPage();
}
onUseCaseToggle(key: string): void {
this.activeUseCases = this.toggled(this.activeUseCases, key);
this.reloadFromFirstPage();
}
get activeFilterCount(): number {
return this.activeTypes.size + this.activeCategories.size + this.activeUseCases.size;
}
clearFilters(): void {
if (this.activeFilterCount === 0) {
return;
}
this.activeTypes = new Set<string>();
this.activeCategories = new Set<string>();
this.activeUseCases = new Set<string>();
this.reloadFromFirstPage();
}
/** A new Set rather than a mutation, so the facet list's @Input sees the change. */
private toggled(set: Set<string>, key: string): Set<string> {
const next = new Set(set);
if (!next.delete(key)) {
next.add(key);
}
return next;
}
private reloadFromFirstPage(): void {
this.pageIndex = 0;
this.loadResults();
}
/**
* filterInfo answers per item type, so the six answers are merged. Each request has its own
* catchError: one type failing costs that type's options, not the panel.
*/
private loadFilterInfo(): void {
const config = { ignoreLoading: true, ignoreErrors: true };
forkJoin(
CROSS_TYPE_ITEM_TYPES.map(type =>
this.iotHubApiService.getFilterInfo(type, config).pipe(catchError(() => of(null)))
)
).subscribe({
next: infos => {
this.categoryOptions = this.mergeFacet(infos.map(i => i?.categories));
this.useCaseOptions = this.mergeFacet(infos.map(i => i?.useCases));
}
});
}
/** Keys that have items in any of the per-type answers, sorted. */
private mergeFacet(lists: (FilterParamInfo[] | undefined)[]): string[] {
const keys = new Set<string>();
for (const list of lists) {
for (const option of list || []) {
if (option.totalItems > 0) {
keys.add(option.key);
}
}
}
return [...keys].sort((a, b) => a.localeCompare(b));
}
// Column count -> page size
private observeGridWidth(): void {
const el = this.cardGridProbe?.nativeElement;
if (!el || typeof ResizeObserver === 'undefined') {
return;
}
this.resizeSubscription = this.resizeSubject.pipe(debounceTime(150)).subscribe(() => {
const before = this.pageSizeOptions[0];
// Keep the same first item in view, not the same page number.
const firstItem = this.pageIndex * this.pageSize;
this.measureCols();
if (this.pageSizeOptions[0] === before) {
return;
}
this.pageSize = this.pageSizeOptions[0];
this.pageIndex = Math.floor(firstItem / this.pageSize);
this.loadResults();
});
// zone.js does not patch ResizeObserver; without zone.run the reload would not render.
this.resizeObserver = new ResizeObserver(() => this.zone.run(() => this.resizeSubject.next()));
this.resizeObserver.observe(el);
}
private measureCols(): void {
const el = this.cardGridProbe?.nativeElement;
if (!el) {
return;
}
this.cols = measureGridColumns(el);
if (!this.pageSizeOptions.includes(this.pageSize)) {
this.pageSize = this.pageSizeOptions[0];
}
} }
onSearchInput(): void { onSearchInput(): void {
@ -158,35 +305,6 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
this.loadResults(); this.loadResults();
} }
// Type helpers
isCompactType(type: ItemType): boolean {
return type === ItemType.CALCULATED_FIELD
|| type === ItemType.ALARM_RULE
|| type === ItemType.RULE_CHAIN;
}
getTypeLabel(type: ItemType): string {
const key = itemTypeTranslations.get(type);
return key ? this.translate.instant(key + '-plural') : type;
}
getTypeRoute(type: ItemType): string {
switch (type) {
case ItemType.WIDGET: return 'widgets';
case ItemType.SOLUTION_TEMPLATE: return 'solution-templates';
case ItemType.CALCULATED_FIELD: return 'calculated-fields';
case ItemType.ALARM_RULE: return 'alarm-rules';
case ItemType.RULE_CHAIN: return 'rule-chains';
case ItemType.DEVICE: return 'devices';
default: return 'widgets';
}
}
navigateToType(type: ItemType): void {
const search = this.searchText?.trim() || undefined;
void this.router.navigate(['/iot-hub', this.getTypeRoute(type)], { queryParams: { search } });
}
// Installed items // Installed items
getInstalledItem(item: MpItemVersionView): IotHubInstalledItem | undefined { getInstalledItem(item: MpItemVersionView): IotHubInstalledItem | undefined {
switch (item.type) { switch (item.type) {
@ -270,52 +388,39 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
clearTimeout(this.retryTimer); clearTimeout(this.retryTimer);
this.retryTimer = null; this.retryTimer = null;
} }
// hasError stays as-is until a request succeeds.
this.isLoading = true; this.isLoading = true;
// hasError stays as-is until the request actually succeeds this.loadSubject.next();
// (cleared in the `next` callback below). }
this.fetchResults(this.searchText || '').subscribe({
next: result => { /** A null result is a failed request. */
this.applyResults(result.data, result.totalElements); private applyResult(result: PageData<MpItemVersionView> | null): void {
this.hasError = false; this.isLoading = false;
}, if (result) {
error: () => { this.totalElements = result.totalElements;
this.isLoading = false; this.results = result.data;
this.hasError = true; this.hasError = false;
this.resultGroups = []; } else {
this.totalElements = 0; this.hasError = true;
} this.results = [];
}); this.totalElements = 0;
}
} }
private fetchResults(text: string) { private fetchResults(text: string) {
const sort = this.sortOptions[this.selectedSortIndex]; const sort = this.sortOptions[this.selectedSortIndex];
const sortOrder: SortOrder = { property: sort.value, direction: sort.direction }; const sortOrder: SortOrder = { property: sort.value, direction: sort.direction };
const pageLink = new PageLink(this.pageSize, this.pageIndex, text.trim() || null, sortOrder); const pageLink = new PageLink(this.pageSize, this.pageIndex, text.trim() || null, sortOrder);
const query = new MpItemVersionQuery(pageLink, { creatorId: this.creatorId || undefined }); const query = new MpItemVersionQuery(pageLink, {
creatorId: this.creatorId || undefined,
// No type selected means every type the platform surfaces (the Hub also holds dashboards).
types: this.activeTypes.size ? [...this.activeTypes] : CROSS_TYPE_ITEM_TYPES,
categories: this.activeCategories.size ? [...this.activeCategories] : undefined,
useCases: this.activeUseCases.size ? [...this.activeUseCases] : undefined
});
return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true, ignoreErrors: true }); return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true, ignoreErrors: true });
} }
private applyResults(data: MpItemVersionView[], totalElements: number): void {
this.totalElements = totalElements;
this.resultGroups = this.groupResults(data);
this.isLoading = false;
}
private groupResults(items: MpItemVersionView[]): SearchResultGroup[] {
const groupMap = new Map<ItemType, MpItemVersionView[]>();
for (const item of items) {
let list = groupMap.get(item.type);
if (!list) {
list = [];
groupMap.set(item.type, list);
}
list.push(item);
}
return TYPE_ORDER
.filter(type => groupMap.has(type))
.map(type => ({ type, items: groupMap.get(type) }));
}
private loadInstalledItems(): void { private loadInstalledItems(): void {
const config = { ignoreLoading: true }; const config = { ignoreLoading: true };
const pageLink = new PageLink(10000, 0); const pageLink = new PageLink(10000, 0);

26
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts

@ -6,6 +6,8 @@ import { IotHubApiService } from '@core/http/iot-hub-api.service';
export const IOT_HUB_FILTER_GROUPING_THRESHOLD = 11; export const IOT_HUB_FILTER_GROUPING_THRESHOLD = 11;
export const IOT_HUB_FILTER_POPULAR_LIMIT = 10; export const IOT_HUB_FILTER_POPULAR_LIMIT = 10;
/** Above this many options a filter list scrolls, and the search page's facet gets a search box. */
export const IOT_HUB_FILTER_SCROLL_THRESHOLD = 8;
/** /**
* Primary action offered for an IoT Hub item: * Primary action offered for an IoT Hub item:
@ -62,12 +64,30 @@ export interface IotHubFilterGroup {
items: FilterParamInfo[]; items: FilterParamInfo[];
} }
export function filterIotHubItemsBySearch(items: FilterParamInfo[], search: string): FilterParamInfo[] { export function filterByLabel<T>(items: T[], search: string, labelOf: (item: T) => string): T[] {
const normalized = (search || '').toLowerCase(); const normalized = (search || '').trim().toLowerCase();
if (!normalized) { if (!normalized) {
return items; return items;
} }
return items.filter(item => item.key.toLowerCase().includes(normalized)); return items.filter(item => labelOf(item).toLowerCase().includes(normalized));
}
export function filterIotHubItemsBySearch(items: FilterParamInfo[], search: string): FilterParamInfo[] {
return filterByLabel(items, search, item => item.key);
}
/** Column count of a CSS grid, from its computed tracks (`repeat(...)` before first layout). */
export function measureGridColumns(el: HTMLElement): number {
void el.offsetWidth;
const tracks = getComputedStyle(el).gridTemplateColumns;
if (!tracks || tracks === 'none') {
return 1;
}
if (tracks.startsWith('repeat(')) {
const match = tracks.match(/^repeat\(\s*(\d+)\s*,/);
return match ? parseInt(match[1], 10) : 1;
}
return Math.max(1, tracks.trim().split(/\s+/).filter(t => t.length > 0).length);
} }
export function groupIotHubFilterItems(items: FilterParamInfo[], search: string): IotHubFilterGroup[] { export function groupIotHubFilterItems(items: FilterParamInfo[], search: string): IotHubFilterGroup[] {

4
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-alarm-rules-unavailable-page.component.ts

@ -3,6 +3,7 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { environment as env } from '@env/environment'; import { environment as env } from '@env/environment';
import { ItemType, itemTypeColors } from '@shared/models/iot-hub/iot-hub-item.models';
@Component({ @Component({
selector: 'tb-iot-hub-alarm-rules-unavailable-page', selector: 'tb-iot-hub-alarm-rules-unavailable-page',
@ -12,8 +13,7 @@ import { environment as env } from '@env/environment';
}) })
export class TbIotHubAlarmRulesUnavailablePageComponent { export class TbIotHubAlarmRulesUnavailablePageComponent {
// Same colour as the ALARM_RULE HeroTypeConfig entry on the home page. readonly alarmRulesColor = itemTypeColors[ItemType.ALARM_RULE];
readonly alarmRulesColor = '#d66f2e';
readonly currentTbVersion: string = env.tbVersion; readonly currentTbVersion: string = env.tbVersion;

3
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html

@ -96,7 +96,8 @@
<div class="tb-creator-divider"></div> <div class="tb-creator-divider"></div>
<!-- Right: published items --> <!-- Right: published items -->
<tb-iot-hub-search class="tb-creator-items" [creatorId]="creatorId" [showCreator]="false"> <tb-iot-hub-search class="tb-creator-items" [creatorId]="creatorId" [showCreator]="false"
[showFilters]="false">
<h3 class="tb-creator-items-heading"> <h3 class="tb-creator-items-heading">
{{ 'iot-hub.published-items' | translate }} ({{ creator.publishedCount }}) {{ 'iot-hub.published-items' | translate }} ({{ creator.publishedCount }})
</h3> </h3>

83
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html

@ -54,13 +54,13 @@
[matAutocomplete]="searchAuto" [matAutocomplete]="searchAuto"
(input)="onSearchInput()" (input)="onSearchInput()"
(focus)="onSearchFocus()" (focus)="onSearchFocus()"
(keyup.enter)="onSearch()"> (keydown.enter)="onSearchEnter($event)">
@if (searchText) { @if (searchText) {
<button matSuffix mat-icon-button (click)="clearSearch()"> <button matSuffix mat-icon-button (click)="clearSearch()">
<mat-icon>close</mat-icon> <mat-icon>close</mat-icon>
</button> </button>
} }
<button matSuffix mat-icon-button (click)="$event.stopPropagation(); onSearch()"> <button matSuffix mat-icon-button (click)="$event.stopPropagation(); seeAllResults()">
<mat-icon>search</mat-icon> <mat-icon>search</mat-icon>
</button> </button>
</mat-form-field> </mat-form-field>
@ -72,6 +72,13 @@
<mat-option [disabled]="true" class="tb-search-popup-loading"> <mat-option [disabled]="true" class="tb-search-popup-loading">
<mat-spinner diameter="24"></mat-spinner> <mat-spinner diameter="24"></mat-spinner>
</mat-option> </mat-option>
} @else if (searchFailed) {
<mat-option [disabled]="true" class="tb-search-popup-no-results">
<div class="tb-search-popup-no-results-content">
<mat-icon>cloud_off</mat-icon>
<span>{{ 'iot-hub.network-server-unavailable' | translate }}</span>
</div>
</mat-option>
} @else if (searchResults.length === 0 && searchLoaded) { } @else if (searchResults.length === 0 && searchLoaded) {
<mat-option [disabled]="true" class="tb-search-popup-no-results"> <mat-option [disabled]="true" class="tb-search-popup-no-results">
<div class="tb-search-popup-no-results-content"> <div class="tb-search-popup-no-results-content">
@ -84,39 +91,55 @@
</div> </div>
</mat-option> </mat-option>
} @else { } @else {
@for (group of searchResultGroups; track group.type) { @for (item of searchResults; track item.id) {
<mat-optgroup [label]="getSearchGroupLabel(group.type)"> <mat-option class="tb-search-popup-item" [value]="searchText"
@for (item of group.items; track item.id) { (onSelectionChange)="onRowSelected($event, item)">
<mat-option [value]="searchText" (click)="openItemDetail(item)"> <!-- One 99x56 frame for every row, so names line up. -->
@if (isCompactType(item.type)) { <div class="tb-search-popup-thumbnail">
<div class="tb-search-popup-icon-square" [style.background]="item.color || '#048ad3'"> @if (isCompactType(item.type)) {
<tb-icon class="tb-search-popup-icon-inner">{{ getCompactIcon(item) }}</tb-icon> <div class="tb-search-popup-icon-square" [style.background]="item.color || '#048ad3'">
</div> <tb-icon class="tb-search-popup-icon-inner">{{ getCompactIcon(item) }}</tb-icon>
} @else { </div>
<div class="tb-search-popup-thumbnail"> } @else if (getItemImage(item); as imgUrl) {
@if (getItemImage(item); as imgUrl) { <img [src]="imgUrl" alt="">
<img [src]="imgUrl" alt=""> } @else {
<tb-icon class="tb-search-popup-thumb-placeholder">{{ getItemTypeIcon(item.type) }}</tb-icon>
}
</div>
<div class="tb-search-popup-text">
<span class="tb-search-popup-name">{{ item.name }}</span>
<span class="tb-search-popup-meta">
<span class="tb-search-popup-type" [style.--tb-search-popup-type-color]="getItemTypeColor(item.type)">
<tb-icon>{{ getItemTypeIcon(item.type) }}</tb-icon>
{{ getItemTypeLabel(item.type) }}
</span>
@if (item.creatorDisplayName) {
<span class="tb-search-popup-author">
@if (item.creatorVerified) {
<mat-icon class="tb-search-popup-verified">verified</mat-icon>
} @else { } @else {
<tb-icon class="tb-search-popup-thumb-placeholder">{{ getItemTypeIcon(item.type) }}</tb-icon> <mat-icon>person</mat-icon>
} }
</div> <span class="tb-search-popup-author-name">{{ item.creatorDisplayName }}</span>
}
<div class="tb-search-popup-text">
<span class="tb-search-popup-name">{{ item.name }}</span>
<span class="tb-search-popup-author">
<mat-icon>person</mat-icon>
{{ item.creatorDisplayName }}
</span> </span>
</div> }
</mat-option> </span>
} </div>
</mat-optgroup> </mat-option>
} }
} }
<div class="tb-search-popup-footer" role="button" tabindex="0" <mat-option class="tb-search-popup-footer" [value]="searchText"
(click)="seeAllResults()" (keyup.enter)="seeAllResults()"> (onSelectionChange)="onFooterSelected($event)">
{{ 'iot-hub.see-all-results' | translate }} @if (searchText?.trim(); as query) {
</div> @if (searchTotal > searchResults.length) {
{{ 'iot-hub.see-all-results-for' | translate:{ count: searchTotal, search: query } }}
} @else {
{{ 'iot-hub.see-results-for' | translate:{ search: query } }}
}
} @else {
{{ 'iot-hub.see-all-results' | translate }}
}
</mat-option>
</mat-autocomplete> </mat-autocomplete>
</div> </div>
</div> </div>

128
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss

@ -220,36 +220,14 @@
0 114px 46px 0 rgba(0, 0, 0, 0.01), 0 114px 46px 0 rgba(0, 0, 0, 0.01),
0 178px 50px 0 rgba(0, 0, 0, 0); 0 178px 50px 0 rgba(0, 0, 0, 0);
// Section group — 12px gap between groups // Shared by every row; each row kind below is selected by its own class.
.mat-mdc-optgroup + .mat-mdc-optgroup .mat-mdc-optgroup-label { .mat-mdc-option {
margin-top: 12px;
}
// Section title — Design: 14px Medium, 0.25 tracking, black-tertiary, 4px V / 16px H
.mat-mdc-optgroup .mat-mdc-optgroup-label {
padding: 4px 16px;
min-height: 28px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
letter-spacing: 0.25px;
color: rgba(0, 0, 0, 0.54);
white-space: nowrap;
.mdc-list-item__primary-text { .mdc-list-item__primary-text {
font-size: 14px; display: flex;
font-weight: 500; align-items: center;
line-height: 20px; gap: 16px;
letter-spacing: 0.25px; width: 100%;
color: rgba(0, 0, 0, 0.54);
} }
}
// Item row — Design: 8px V / 16px H, 16px gap, centered
.mat-mdc-optgroup .mat-mdc-option:not(.mat-mdc-option-multiple) {
padding: 8px 16px;
min-height: auto;
height: auto;
&:hover:not(.mdc-list-item--disabled), &:hover:not(.mdc-list-item--disabled),
&.mat-mdc-option-active:not(.mdc-list-item--disabled) { &.mat-mdc-option-active:not(.mdc-list-item--disabled) {
@ -259,13 +237,13 @@
.mat-icon, tb-icon { .mat-icon, tb-icon {
margin-right: 0; margin-right: 0;
} }
}
.mdc-list-item__primary-text { // Item row — Design: 8px V / 16px H, 16px gap, centered
display: flex; .mat-mdc-option.tb-search-popup-item {
align-items: center; padding: 8px 16px;
gap: 16px; min-height: auto;
width: 100%; height: auto;
}
} }
// Thumbnail — Design: 99px x 56px, 4px radius, 1px border, 4% bg // Thumbnail — Design: 99px x 56px, 4px radius, 1px border, 4% bg
@ -295,11 +273,11 @@
color: rgba(0, 0, 0, 0.38); color: rgba(0, 0, 0, 0.38);
} }
// Icon square — Design: 56x56, 4.667px radius, colored bg // Icon tile for an item with no screenshot, centred in the thumbnail frame: 36x36, colored bg
.tb-search-popup-icon-square { .tb-search-popup-icon-square {
width: 56px; width: 36px;
height: 56px; height: 36px;
border-radius: 4.667px; border-radius: 6px;
flex-shrink: 0; flex-shrink: 0;
display: flex; display: flex;
align-items: center; align-items: center;
@ -307,9 +285,9 @@
} }
.tb-search-popup-icon-inner { .tb-search-popup-icon-inner {
font-size: 28px; font-size: 22px;
width: 28px; width: 22px;
height: 28px; height: 22px;
color: white !important; color: white !important;
--tb-icon-color: white; --tb-icon-color: white;
} }
@ -346,13 +324,63 @@
letter-spacing: 0.25px; letter-spacing: 0.25px;
color: rgba(0, 0, 0, 0.54); color: rgba(0, 0, 0, 0.54);
white-space: nowrap; white-space: nowrap;
min-width: 0;
mat-icon { mat-icon {
flex-shrink: 0;
font-size: 16px; font-size: 16px;
width: 16px; width: 16px;
height: 16px; height: 16px;
margin-right: 0; margin-right: 0;
color: rgba(0, 0, 0, 0.54); color: rgba(0, 0, 0, 0.54);
// Same teal the IoT Hub item cards give a verified creator.
&.tb-search-popup-verified {
color: #00695c;
}
}
}
// Shares the meta row with the item type, so a long name is cut rather than overflowing.
.tb-search-popup-author-name {
overflow: hidden;
text-overflow: ellipsis;
}
// Meta row: the item type, a middle dot, then the author - "Widget · pinkevych.d".
.tb-search-popup-meta {
display: flex;
align-items: center;
gap: 4px;
min-width: 0;
}
// Item type in its colour, darkened so the paler ones stay legible.
.tb-search-popup-type {
display: flex;
align-items: center;
gap: 4px;
flex-shrink: 0;
font-size: 12px;
font-weight: 500;
line-height: 16px;
letter-spacing: 0.25px;
color: color-mix(in srgb, var(--tb-search-popup-type-color) 75%, #000);
white-space: nowrap;
tb-icon {
font-size: 14px;
width: 14px;
height: 14px;
line-height: 14px;
color: inherit;
}
// No author, nothing to separate from.
&:not(:last-child)::after {
content: '·';
font-weight: 700;
color: rgba(0, 0, 0, 0.54);
} }
} }
@ -370,6 +398,7 @@
.tb-search-popup-no-results { .tb-search-popup-no-results {
pointer-events: none; pointer-events: none;
opacity: 1 !important; opacity: 1 !important;
padding: 8px 16px;
} }
.tb-search-popup-no-results-content { .tb-search-popup-no-results-content {
@ -391,26 +420,31 @@
} }
// Footer — Design: 40px h, 8px V / 16px H, 1px top border, tb-primary text // Footer — Design: 40px h, 8px V / 16px H, 1px top border, tb-primary text
.tb-search-popup-footer { .mat-mdc-option.tb-search-popup-footer {
position: sticky; position: sticky;
bottom: 0; bottom: 0;
z-index: 1;
border-top: 1px solid rgba(0, 0, 0, 0.12); border-top: 1px solid rgba(0, 0, 0, 0.12);
height: 40px; height: 40px;
min-height: 40px; min-height: 40px;
padding: 8px 16px; padding: 8px 16px;
display: flex;
align-items: center;
justify-content: flex-start;
font-size: 14px; font-size: 14px;
font-weight: 500; font-weight: 500;
line-height: 20px; line-height: 20px;
letter-spacing: 0.25px; letter-spacing: 0.25px;
color: $tb-primary-color; color: $tb-primary-color;
cursor: pointer;
background: white; background: white;
white-space: nowrap; white-space: nowrap;
&:hover { .mdc-list-item__primary-text {
justify-content: flex-start;
font: inherit;
letter-spacing: inherit;
color: inherit;
}
&:hover:not(.mdc-list-item--disabled),
&.mat-mdc-option-active:not(.mdc-list-item--disabled) {
background: #f5f5f5; background: #f5f5f5;
} }
} }

119
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts

@ -3,14 +3,25 @@
import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/core'; import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { MatAutocompleteTrigger } from '@angular/material/autocomplete'; import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
import { MatOptionSelectionChange } from '@angular/material/core';
import { BreakpointObserver } from '@angular/cdk/layout'; import { BreakpointObserver } from '@angular/cdk/layout';
import { forkJoin, Subject, Subscription } from 'rxjs'; import { forkJoin, of, Subject, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; import { catchError, debounceTime, switchMap } from 'rxjs/operators';
import { MediaBreakpoints } from '@shared/models/constants'; import { MediaBreakpoints } from '@shared/models/constants';
import { PageLink } from '@shared/models/page/page-link'; import { PageLink } from '@shared/models/page/page-link';
import { Direction, SortOrder } from '@shared/models/page/sort-order'; import { Direction, SortOrder } from '@shared/models/page/sort-order';
import { PageData } from '@shared/models/page/page-data';
import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models'; import { MpItemVersionQuery, MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models';
import { getItemTypeIcon, ItemType, itemTypeTranslations } from '@shared/models/iot-hub/iot-hub-item.models'; import {
CROSS_TYPE_ITEM_TYPES,
getItemTypeColor,
isCompactItemType,
getItemTypeIcon,
ItemType,
itemTypeColors,
itemTypeTranslations,
RELEVANCE_SORT_PROPERTY
} from '@shared/models/iot-hub/iot-hub-item.models';
import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubInstalledItem } from '@shared/models/iot-hub/iot-hub-installed-item.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubApiService } from '@core/http/iot-hub-api.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -32,15 +43,8 @@ interface HeroTypeConfig {
icon: string; icon: string;
} }
interface SearchResultGroup { /** Rows the search popup shows: page 0 of the search page's own request. */
type: ItemType; const SEARCH_POPUP_PAGE_SIZE = 10;
items: MpItemVersionView[];
}
const SEARCH_GROUP_ORDER: ItemType[] = [
ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, ItemType.WIDGET,
ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN
];
@Component({ @Component({
selector: 'tb-iot-hub-home', selector: 'tb-iot-hub-home',
@ -51,12 +55,15 @@ const SEARCH_GROUP_ORDER: ItemType[] = [
export class TbIotHubHomeComponent implements OnInit, OnDestroy { export class TbIotHubHomeComponent implements OnInit, OnDestroy {
readonly ItemType = ItemType; readonly ItemType = ItemType;
readonly isCompactType = isCompactItemType;
searchText = ''; searchText = '';
searchResults: MpItemVersionView[] = []; searchResults: MpItemVersionView[] = [];
searchResultGroups: SearchResultGroup[] = []; /** Everything the search matched, for the footer's "See all N results". */
searchTotal = 0;
searchLoaded = false; searchLoaded = false;
searchLoading = false; searchLoading = false;
searchFailed = false;
@ViewChild(MatAutocompleteTrigger) searchAutoTrigger: MatAutocompleteTrigger; @ViewChild(MatAutocompleteTrigger) searchAutoTrigger: MatAutocompleteTrigger;
@ViewChild('searchInput', {read: ElementRef}) searchInputRef: ElementRef; @ViewChild('searchInput', {read: ElementRef}) searchInputRef: ElementRef;
private searchSubject = new Subject<string>(); private searchSubject = new Subject<string>();
@ -65,27 +72,27 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
heroTypes: HeroTypeConfig[] = [ heroTypes: HeroTypeConfig[] = [
{ {
type: ItemType.DEVICE, labelKey: 'item.type-device-plural', color: '#4b63cc', type: ItemType.DEVICE, labelKey: 'item.type-device-plural', color: itemTypeColors[ItemType.DEVICE],
icon: 'assets/iot-hub/hero-device-cluster.svg' icon: 'assets/iot-hub/hero-device-cluster.svg'
}, },
{ {
type: ItemType.SOLUTION_TEMPLATE, labelKey: 'item.type-solution-template-plural', color: '#2b6bb4', type: ItemType.SOLUTION_TEMPLATE, labelKey: 'item.type-solution-template-plural', color: itemTypeColors[ItemType.SOLUTION_TEMPLATE],
icon: 'assets/iot-hub/hero-solution-template-cluster.svg' icon: 'assets/iot-hub/hero-solution-template-cluster.svg'
}, },
{ {
type: ItemType.WIDGET, labelKey: 'item.type-widget-plural', color: '#2c9755', type: ItemType.WIDGET, labelKey: 'item.type-widget-plural', color: itemTypeColors[ItemType.WIDGET],
icon: 'assets/iot-hub/hero-widget-cluster.svg' icon: 'assets/iot-hub/hero-widget-cluster.svg'
}, },
{ {
type: ItemType.CALCULATED_FIELD, labelKey: 'item.type-calculated-field-plural', color: '#3cb4e0', type: ItemType.CALCULATED_FIELD, labelKey: 'item.type-calculated-field-plural', color: itemTypeColors[ItemType.CALCULATED_FIELD],
icon: 'assets/iot-hub/hero-calculated-field-cluster.svg' icon: 'assets/iot-hub/hero-calculated-field-cluster.svg'
}, },
{ {
type: ItemType.ALARM_RULE, labelKey: 'item.type-alarm-rule-plural', color: '#d66f2e', type: ItemType.ALARM_RULE, labelKey: 'item.type-alarm-rule-plural', color: itemTypeColors[ItemType.ALARM_RULE],
icon: 'assets/iot-hub/hero-alarm-rule-cluster.svg' icon: 'assets/iot-hub/hero-alarm-rule-cluster.svg'
}, },
{ {
type: ItemType.RULE_CHAIN, labelKey: 'item.type-rule-chain-plural', color: '#a95ae2', type: ItemType.RULE_CHAIN, labelKey: 'item.type-rule-chain-plural', color: itemTypeColors[ItemType.RULE_CHAIN],
icon: 'assets/iot-hub/hero-rule-chain-cluster.svg' icon: 'assets/iot-hub/hero-rule-chain-cluster.svg'
} }
]; ];
@ -153,17 +160,23 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
}); });
this.searchSubscription = this.searchSubject.pipe( this.searchSubscription = this.searchSubject.pipe(
debounceTime(300), debounceTime(300),
distinctUntilChanged(),
switchMap(text => { switchMap(text => {
this.searchLoading = true; this.searchLoading = true;
const sortOrder: SortOrder = { property: 'totalInstallCount', direction: Direction.DESC }; const trimmed = text.trim();
const pageLink = new PageLink(10, 0, text.trim() || null, sortOrder); // One list ranked across every type the platform surfaces. With an empty field relevance
const query = new MpItemVersionQuery(pageLink); // is served as the install count.
return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true }); const sortOrder: SortOrder = { property: RELEVANCE_SORT_PROPERTY, direction: Direction.DESC };
const pageLink = new PageLink(SEARCH_POPUP_PAGE_SIZE, 0, trimmed || null, sortOrder);
const query = new MpItemVersionQuery(pageLink, { types: CROSS_TYPE_ITEM_TYPES });
// A failure must not end the subscription.
return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true }).pipe(
catchError(() => of(null as PageData<MpItemVersionView>))
);
}) })
).subscribe(result => { ).subscribe(page => {
this.searchResults = result.data; this.searchFailed = !page;
this.searchResultGroups = this.groupSearchResults(result.data); this.searchResults = page?.data ?? [];
this.searchTotal = page?.totalElements ?? 0;
this.searchLoaded = true; this.searchLoaded = true;
this.searchLoading = false; this.searchLoading = false;
}); });
@ -227,7 +240,26 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
setTimeout(() => this.searchAutoTrigger?.openPanel()); setTimeout(() => this.searchAutoTrigger?.openPanel());
} }
onSearch(): void { onRowSelected(event: MatOptionSelectionChange, item: MpItemVersionView): void {
if (event.isUserInput) {
this.openItemDetail(item);
}
}
onFooterSelected(event: MatOptionSelectionChange): void {
if (event.isUserInput) {
this.seeAllResults();
}
}
/**
* Enter in the field opens the search page - unless the autocomplete has just used this press
* to select a highlighted row, which it marks with preventDefault before this handler runs.
*/
onSearchEnter(event: KeyboardEvent): void {
if (event.defaultPrevented || event.isComposing) {
return;
}
this.seeAllResults(); this.seeAllResults();
} }
@ -237,12 +269,6 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
void this.router.navigate(['/iot-hub/search'], { queryParams: { search } }); void this.router.navigate(['/iot-hub/search'], { queryParams: { search } });
} }
isCompactType(type: ItemType): boolean {
return type === ItemType.CALCULATED_FIELD
|| type === ItemType.ALARM_RULE
|| type === ItemType.RULE_CHAIN;
}
getCompactIcon(item: MpItemVersionView): string { getCompactIcon(item: MpItemVersionView): string {
return item.icon || getItemTypeIcon(item.type); return item.icon || getItemTypeIcon(item.type);
} }
@ -255,9 +281,13 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
return getItemTypeIcon(type); return getItemTypeIcon(type);
} }
getSearchGroupLabel(type: ItemType): string { getItemTypeColor(type: ItemType): string {
return getItemTypeColor(type);
}
getItemTypeLabel(type: ItemType): string {
const key = itemTypeTranslations.get(type); const key = itemTypeTranslations.get(type);
return key ? this.translate.instant(key + '-plural') : type; return key ? this.translate.instant(key) : type;
} }
navigateToBrowse(type: ItemType): void { navigateToBrowse(type: ItemType): void {
@ -522,21 +552,4 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
}); });
} }
private groupSearchResults(items: MpItemVersionView[]): SearchResultGroup[] {
const groupMap = new Map<ItemType, MpItemVersionView[]>();
for (const item of items) {
if (!SEARCH_GROUP_ORDER.includes(item.type)) {
continue;
}
let list = groupMap.get(item.type);
if (!list) {
list = [];
groupMap.set(item.type, list);
}
list.push(item);
}
return SEARCH_GROUP_ORDER
.filter(type => groupMap.has(type))
.map(type => ({ type, items: groupMap.get(type) }));
}
} }

99
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss

@ -8,12 +8,17 @@
height: 100%; height: 100%;
} }
// Same frame as the type pages: one even padding on the card, and the search component pulled
// out to the card's edges by the same amount, so the rail, heading and grid line up.
.tb-search-page {
--tb-search-page-pad: 40px;
padding: var(--tb-search-page-pad) var(--tb-search-page-pad) calc(var(--tb-search-page-pad) + 8px);
}
// Back button // Back button
.tb-search-back-btn { .tb-search-back-btn {
align-self: flex-start; align-self: flex-start;
margin-top: 40px; margin-left: -8px;
margin-left: 123px;
} }
// Title // Title
@ -30,100 +35,24 @@
color: rgba(0, 0, 0, 0.54); color: rgba(0, 0, 0, 0.54);
} }
// Full bleed; it pads its own rows back in through --tb-search-side-pad.
tb-iot-hub-search { tb-iot-hub-search {
flex: 1; flex: 1;
min-height: 0; min-height: 0;
padding-left: 123px; --tb-search-side-pad: var(--tb-search-page-pad);
padding-right: 123px; margin-left: calc(-1 * var(--tb-search-page-pad));
margin-right: calc(-1 * var(--tb-search-page-pad));
::ng-deep {
.tb-search-divider {
margin-left: -123px;
margin-right: -123px;
}
.tb-results-container {
padding-right: 123px;
padding-bottom: 40px;
margin-right: -123px;
}
}
}
// Responsive
@media #{$mat-lt-xxl} {
.tb-search-back-btn {
margin-left: 40px;
}
tb-iot-hub-search {
padding-left: 40px;
padding-right: 40px;
::ng-deep {
.tb-search-divider {
margin-left: -40px;
margin-right: -40px;
}
.tb-results-container {
padding-right: 40px;
margin-right: -40px;
}
}
}
} }
@media #{$mat-lt-lg} { @media #{$mat-lt-lg} {
.tb-search-back-btn { .tb-search-page {
margin-top: 24px; --tb-search-page-pad: 24px;
margin-left: 24px;
}
tb-iot-hub-search {
padding-left: 24px;
padding-right: 24px;
::ng-deep {
.tb-search-divider {
margin-left: -24px;
margin-right: -24px;
}
.tb-results-container {
padding-right: 24px;
padding-bottom: 24px;
margin-right: -24px;
}
}
} }
} }
@media #{$mat-lt-sm} { @media #{$mat-lt-sm} {
.tb-search-page { .tb-search-page {
--tb-search-page-pad: 16px;
gap: 16px; gap: 16px;
} }
.tb-search-back-btn {
margin-top: 16px;
margin-left: 16px;
}
tb-iot-hub-search {
padding-left: 16px;
padding-right: 16px;
::ng-deep {
.tb-search-divider {
margin-left: -16px;
margin-right: -16px;
}
.tb-results-container {
padding-right: 16px;
padding-bottom: 16px;
margin-right: -16px;
}
}
}
} }

52
ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts

@ -1,5 +1,7 @@
// SPDX-FileCopyrightText: Copyright The Thingsboard Authors // SPDX-FileCopyrightText: Copyright The Thingsboard Authors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { Direction } from '@shared/models/page/sort-order';
export enum ItemType { export enum ItemType {
WIDGET = 'WIDGET', WIDGET = 'WIDGET',
SOLUTION_TEMPLATE = 'SOLUTION_TEMPLATE', SOLUTION_TEMPLATE = 'SOLUTION_TEMPLATE',
@ -36,6 +38,22 @@ export const itemTypeIcons: Record<string, string> = {
export const getItemTypeIcon = (type?: string | null): string => export const getItemTypeIcon = (type?: string | null): string =>
type && itemTypeIcons[type] ? itemTypeIcons[type] : 'category'; type && itemTypeIcons[type] ? itemTypeIcons[type] : 'category';
/** Colour for a type with no colour of its own. */
export const DEFAULT_ITEM_TYPE_COLOR = '#5f6368';
/** Colour per item type, wherever an item's type is marked with one. */
export const itemTypeColors: Record<string, string> = {
[ItemType.WIDGET]: '#2c9755',
[ItemType.SOLUTION_TEMPLATE]: '#2b6bb4',
[ItemType.CALCULATED_FIELD]: '#3cb4e0',
[ItemType.RULE_CHAIN]: '#a95ae2',
[ItemType.ALARM_RULE]: '#d66f2e',
[ItemType.DEVICE]: '#4b63cc'
};
export const getItemTypeColor = (type?: string | null): string =>
type && itemTypeColors[type] ? itemTypeColors[type] : DEFAULT_ITEM_TYPE_COLOR;
/** /**
* Item types discoverable to creators in the marketplace UI. * Item types discoverable to creators in the marketplace UI.
*/ */
@ -48,6 +66,40 @@ export const CREATOR_VISIBLE_ITEM_TYPES: ItemType[] = [
ItemType.RULE_CHAIN, ItemType.RULE_CHAIN,
]; ];
/** Item types a cross-type surface (search page, popup) shows, in display order. */
export const CROSS_TYPE_ITEM_TYPES: ItemType[] = [
ItemType.DEVICE,
ItemType.SOLUTION_TEMPLATE,
ItemType.WIDGET,
ItemType.CALCULATED_FIELD,
ItemType.ALARM_RULE,
ItemType.RULE_CHAIN,
];
/** Types drawn as a coloured icon tile rather than a screenshot. */
export const isCompactItemType = (type?: string | null): boolean =>
type === ItemType.CALCULATED_FIELD || type === ItemType.ALARM_RULE || type === ItemType.RULE_CHAIN;
/** Sort property served by relevance ranking. */
export const RELEVANCE_SORT_PROPERTY = 'relevance';
export interface SortOption {
value: string;
label: string;
direction: Direction;
}
/**
* The sort menu of every IoT Hub surface with a search field; the first entry is the default.
* Relevance stays the default with an empty field, where it orders by install count.
*/
export const IOT_HUB_SORT_OPTIONS: SortOption[] = [
{ value: RELEVANCE_SORT_PROPERTY, label: 'iot-hub.sort-most-relevant', direction: Direction.DESC },
{ value: 'totalInstallCount', label: 'iot-hub.sort-most-installed', direction: Direction.DESC },
{ value: 'publishedTime', label: 'iot-hub.sort-newest', direction: Direction.DESC },
{ value: 'name', label: 'iot-hub.sort-name', direction: Direction.ASC }
];
export interface FilterParamInfo { export interface FilterParamInfo {
key: string; key: string;
totalItems: number; totalItems: number;

101
ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts

@ -118,7 +118,10 @@ export interface ListingItemVersionNotFound {
} }
export interface MpItemVersionQueryOptions { export interface MpItemVersionQueryOptions {
/** Single item type, for a surface pinned to one (the type pages, the add-item dialog). */
type?: string; type?: string;
/** Several item types at once, sent as a repeated `type` parameter. */
types?: string[];
peOnly?: boolean; peOnly?: boolean;
creatorId?: string; creatorId?: string;
categories?: string[]; categories?: string[];
@ -135,54 +138,62 @@ export interface MpItemVersionQueryOptions {
creatorVerified?: boolean; creatorVerified?: boolean;
} }
/** Every filter, as `&name=value` pairs. */
function filtersToQuery(o: MpItemVersionQueryOptions): string {
let query = '';
if (o.type) {
query += `&type=${encodeURIComponent(o.type)}`;
}
if (o.types?.length) {
query += o.types.map(t => `&type=${encodeURIComponent(t)}`).join('');
}
if (o.peOnly != null) {
query += `&peOnly=${o.peOnly}`;
}
if (o.creatorId) {
query += `&creatorId=${encodeURIComponent(o.creatorId)}`;
}
if (o.categories?.length) {
query += o.categories.map(c => `&categories=${encodeURIComponent(c)}`).join('');
}
if (o.useCases?.length) {
query += o.useCases.map(u => `&useCases=${encodeURIComponent(u)}`).join('');
}
if (o.cfTypes?.length) {
query += o.cfTypes.map(t => `&cfTypes=${encodeURIComponent(t)}`).join('');
}
if (o.widgetTypes?.length) {
query += o.widgetTypes.map(t => `&widgetTypes=${encodeURIComponent(t)}`).join('');
}
if (o.ruleChainTypes?.length) {
query += o.ruleChainTypes.map(t => `&ruleChainTypes=${encodeURIComponent(t)}`).join('');
}
if (o.tbVersion != null) {
query += `&tbVersion=${o.tbVersion}`;
}
if (o.hardwareTypes?.length) {
query += o.hardwareTypes.map(ht => `&hardwareTypes=${encodeURIComponent(ht)}`).join('');
}
if (o.connectivity?.length) {
query += o.connectivity.map(c => `&connectivity=${encodeURIComponent(c)}`).join('');
}
if (o.vendors?.length) {
query += o.vendors.map(v => `&vendors=${encodeURIComponent(v)}`).join('');
}
if (o.scadaFirst != null) {
query += `&scadaFirst=${o.scadaFirst}`;
}
if (o.creatorVerified) {
query += `&creatorVerified=true`;
}
return query;
}
/** A paged read: the filters, and the page to cut out of them. */
export class MpItemVersionQuery { export class MpItemVersionQuery {
constructor(public pageLink: PageLink, public options: MpItemVersionQueryOptions = {}) {} constructor(public pageLink: PageLink, public options: MpItemVersionQueryOptions = {}) {}
public toQuery(): string { public toQuery(): string {
let query = this.pageLink.toQuery(); return this.pageLink.toQuery() + filtersToQuery(this.options);
const o = this.options;
if (o.type) {
query += `&type=${o.type}`;
}
if (o.peOnly != null) {
query += `&peOnly=${o.peOnly}`;
}
if (o.creatorId) {
query += `&creatorId=${o.creatorId}`;
}
if (o.categories?.length) {
query += o.categories.map(c => `&categories=${encodeURIComponent(c)}`).join('');
}
if (o.useCases?.length) {
query += o.useCases.map(u => `&useCases=${encodeURIComponent(u)}`).join('');
}
if (o.cfTypes?.length) {
query += o.cfTypes.map(t => `&cfTypes=${encodeURIComponent(t)}`).join('');
}
if (o.widgetTypes?.length) {
query += o.widgetTypes.map(t => `&widgetTypes=${encodeURIComponent(t)}`).join('');
}
if (o.ruleChainTypes?.length) {
query += o.ruleChainTypes.map(t => `&ruleChainTypes=${encodeURIComponent(t)}`).join('');
}
if (o.tbVersion != null) {
query += `&tbVersion=${o.tbVersion}`;
}
if (o.hardwareTypes?.length) {
query += o.hardwareTypes.map(ht => `&hardwareTypes=${encodeURIComponent(ht)}`).join('');
}
if (o.connectivity?.length) {
query += o.connectivity.map(c => `&connectivity=${encodeURIComponent(c)}`).join('');
}
if (o.vendors?.length) {
query += o.vendors.map(v => `&vendors=${encodeURIComponent(v)}`).join('');
}
if (o.scadaFirst != null) {
query += `&scadaFirst=${o.scadaFirst}`;
}
if (o.creatorVerified) {
query += `&creatorVerified=true`;
}
return query;
} }
} }

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

@ -3706,6 +3706,8 @@
"search": "Search...", "search": "Search...",
"search-published-items": "Search published items...", "search-published-items": "Search published items...",
"see-all-results": "See all results", "see-all-results": "See all results",
"see-all-results-for": "See all {{ count }} results for \"{{ search }}\"",
"see-results-for": "See results for \"{{ search }}\"",
"no-search-results": "No results found for '{{ search }}'", "no-search-results": "No results found for '{{ search }}'",
"no-items-available": "No items available", "no-items-available": "No items available",
"search-results": "Search results", "search-results": "Search results",
@ -3728,6 +3730,7 @@
"type": "Type", "type": "Type",
"items-per-page": "Items per page", "items-per-page": "Items per page",
"filter": "Filter", "filter": "Filter",
"clear-filters": "Clear filters",
"available": "Available", "available": "Available",
"items-page-desc-widgets": "Jumpstart your IoT journey with pre-configured widgets designed for your industry. Deploy proven architectures instantly and focus your energy on what matters: your unique business logic.", "items-page-desc-widgets": "Jumpstart your IoT journey with pre-configured widgets designed for your industry. Deploy proven architectures instantly and focus your energy on what matters: your unique business logic.",
"items-page-desc-solution-templates": "Complete IoT solution packages with dashboards, rule chains, and device configurations. Get started with proven architectures.", "items-page-desc-solution-templates": "Complete IoT solution packages with dashboards, rule chains, and device configurations. Get started with proven architectures.",
@ -3768,6 +3771,7 @@
"search-alarm-rules": "Search alarm rules...", "search-alarm-rules": "Search alarm rules...",
"search-rule-chains": "Search rule chains...", "search-rule-chains": "Search rule chains...",
"search-devices": "Search devices...", "search-devices": "Search devices...",
"sort-most-relevant": "Most relevant",
"sort-most-installed": "Most installed", "sort-most-installed": "Most installed",
"sort-newest": "Newest", "sort-newest": "Newest",
"sort-name": "Name (A-Z)", "sort-name": "Name (A-Z)",

Loading…
Cancel
Save