diff --git a/ui-ngx/src/app/core/http/iot-hub-api.service.ts b/ui-ngx/src/app/core/http/iot-hub-api.service.ts index 2074976126..70f97ed061 100644 --- a/ui-ngx/src/app/core/http/iot-hub-api.service.ts +++ b/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 { PageData } from '@shared/models/page/page-data'; 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 { 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'; @@ -69,30 +73,38 @@ export class IotHubApiService { } public getPublishedVersions(query: MpItemVersionQuery, config?: IotHubRequestConfig): Observable> { - if (query.options.tbVersion == null) { - query.options.tbVersion = tbVersionToInt(env.tbVersion); - } - if (query.options.peOnly == null) { - query.options.peOnly = false; - } + this.applyPlatformFilters(query.options); return this.http.get>( `${this.baseUrl}/api/versions/published${query.toQuery()}`, { 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 { - const url = `${this.baseUrl}/api/item-listing/filterInfo/${itemType}` - + `?peOnly=false&tbVersion=${tbVersionToInt(env.tbVersion)}`; + const url = `${this.baseUrl}/api/item-listing/filterInfo/${itemType}?${this.platformScopeParams().join('&')}`; return this.http.get(url, { params: this.buildParams(config) }); } public getWidgetCategories(textSearch?: string, scadaFirst?: boolean, creatorVerified?: boolean, config?: IotHubRequestConfig): Observable { - const queryParams: string[] = [ - `peOnly=false`, - `tbVersion=${tbVersionToInt(env.tbVersion)}` - ]; + const queryParams: string[] = this.platformScopeParams(); if (textSearch?.trim()) { queryParams.push(`textSearch=${encodeURIComponent(textSearch.trim())}`); } @@ -135,7 +147,7 @@ export class IotHubApiService { public getListingItemVersion(slug: string, config?: IotHubRequestConfig): Observable { const queryParams = [ 'ce=true', - `tbVersion=${tbVersionToInt(env.tbVersion)}` + `tbVersion=${this.platformScope().tbVersion}` ]; return this.http.get( `${this.baseUrl}/api/listings/public/by-slug/${encodeURIComponent(slug)}/item-version?${queryParams.join('&')}`, diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html index 2dccec902f..01bdcf0979 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.html @@ -80,12 +80,12 @@ } @if (selectWidgetMode === 'iotHub' && iotHubSubMode !== 'default') { - @for (option of iotHubSortOptions; track option.value; let i = $index) { - + @for (option of iotHubSortOptions; track option.value) { + } } diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts index e6331f9a66..ac335b9a16 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts +++ b/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 { TranslateService } from '@ngx-translate/core'; 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 { IotHubApiService } from '@core/http/iot-hub-api.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'; 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 installedSubMode = 'default' | 'allWidgets'; type iotHubSubMode = 'default' | 'allWidgets' | 'installed' | 'category'; -interface WidgetSelectSortOption { - value: string; - label: string; - direction: Direction; -} - const LOGICAL_ALL_WIDGETS = '__logical_all_widgets__'; const LOGICAL_INSTALLED_FROM_IOT_HUB = '__logical_installed_from_iot_hub__'; @@ -88,12 +92,7 @@ export class DashboardWidgetSelectComponent { includeDeprecated = false; searchFocused = false; - iotHubSortOptions: WidgetSelectSortOption[] = [ - { 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; + private iotHubSelectedSortValue = IOT_HUB_SORT_OPTIONS[0].value; @Input() aliasController: IAliasController; @@ -305,7 +304,7 @@ export class DashboardWidgetSelectComponent { this.iotHubWidgetsFetchFunction = (pageSize, page, 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 pageLink = new PageLink(pageSize, page, search || null, sortOrder); const effectiveCategories = this.iotHubSelectedCategory @@ -583,9 +582,22 @@ export class DashboardWidgetSelectComponent { this.reloadIotHubWidgets(); } - onIotHubSortChange(index: number): void { - if (this.iotHubSelectedSortIndex !== index) { - this.iotHubSelectedSortIndex = index; + get iotHubSortOptions(): SortOption[] { + return this.iotHubSubMode === 'installed' ? INSTALLED_SORT_OPTIONS : IOT_HUB_SORT_OPTIONS; + } + + /** 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.reloadIotHubWidgets(); } @@ -866,7 +878,7 @@ export class DashboardWidgetSelectComponent { } private sortInstalledVersions(versions: MpItemVersionView[]): MpItemVersionView[] { - const sort = this.iotHubSortOptions[this.iotHubSelectedSortIndex]; + const sort = this.iotHubSelectedSort; const sign = sort.direction === Direction.ASC ? 1 : -1; const copy = [...versions]; copy.sort((a, b) => { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss b/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss index d247f20112..b6264d6ce3 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss @@ -119,3 +119,33 @@ 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); + } + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html index 740be1f42d..e7215607ba 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.html @@ -50,8 +50,8 @@ } } -
@for (opt of getFilteredItems(subtypeOptions, 'subtype'); track opt.key) { } -
@for (group of getGroupedFilterItems(vendorOptions, 'vendor'); track group.label) { @if (group.label) { @@ -121,8 +121,8 @@ }
} -
@for (ht of getFilteredItems(hardwareTypeOptions, 'hardwareType'); track ht.key) { } -
@for (group of getFilteredConnectivityGroups('connectivity'); track group.group) {
{{ group.group }}
@@ -189,8 +189,8 @@ }
} -
@for (cat of getFilteredItems(categoryOptions, 'category'); track cat.key) { } -
@for (group of getGroupedFilterItems(useCaseOptions, 'useCase'); track group.label) { @if (group.label) { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts index caa4920eff..d311ab325d 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts +++ b/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 { debounceTime, takeUntil } from 'rxjs/operators'; 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 { 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 { IotHubInstalledItem, DeviceInstalledItemDescriptor } from '@shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { TranslateService } from '@ngx-translate/core'; import { ActivatedRoute, Router } from '@angular/router'; import { IotHubActionsService } from '@home/components/iot-hub/iot-hub-actions.service'; -import { filterIotHubItemsBySearch, groupIotHubFilterItems, IotHubFilterGroup } from '@home/components/iot-hub/iot-hub-utils'; - -interface SortOption { - value: string; - label: string; - direction: Direction; -} +import { + filterIotHubItemsBySearch, + groupIotHubFilterItems, + IOT_HUB_FILTER_SCROLL_THRESHOLD, + IotHubFilterGroup, + measureGridColumns +} from '@home/components/iot-hub/iot-hub-utils'; @Component({ selector: 'tb-iot-hub-browse', @@ -43,6 +49,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy } readonly ItemType = ItemType; + readonly scrollThreshold = IOT_HUB_FILTER_SCROLL_THRESHOLD; @Input() creatorId: string; @Input() embedded = false; @@ -78,9 +85,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy } get isCompactType(): boolean { - return this._activeType === ItemType.CALCULATED_FIELD - || this._activeType === ItemType.ALARM_RULE - || this._activeType === ItemType.RULE_CHAIN; + return isCompactItemType(this._activeType); } get searchPlaceholderKey(): string { @@ -130,11 +135,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy activeVendors = new Set(); verifiedCreatorsOnly = false; - sortOptions: SortOption[] = [ - { 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 } - ]; + readonly sortOptions = IOT_HUB_SORT_OPTIONS; typeTabs: { type: ItemType; label: string }[] = CREATOR_VISIBLE_ITEM_TYPES.map(t => ({ type: t, @@ -221,17 +222,7 @@ export class TbIotHubBrowseComponent implements OnInit, AfterViewInit, OnDestroy if (!el) { return this.probeCols; } - // Force layout so `grid-template-columns` resolves to pixel tracks, not `repeat(...)`. - 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); + return measureGridColumns(el); } private adjustPageSize(): void { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts index 53e2493651..00ce18b4c0 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-components.module.ts +++ b/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 { InstallFormRendererComponent } from './device-install-dialog/install-form-renderer/install-form-renderer.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 { TbIotHubInstalledItemsDialogComponent } from './iot-hub-installed-items-dialog.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, TbDeviceInstallDialogComponent, TbIotHubSearchComponent, + TbIotHubFacetListComponent, TbIotHubInstalledItemsTableComponent, TbIotHubInstalledItemsDialogComponent, TbPeConnectivityMethodPromptComponent, @@ -64,6 +66,7 @@ import { IotHubItemLinkModule } from './iot-hub-item-link-card/iot-hub-item-link TbIotHubUnpublishedWarningDialogComponent, TbDeviceInstallDialogComponent, TbIotHubSearchComponent, + TbIotHubFacetListComponent, TbIotHubInstalledItemsTableComponent, TbIotHubInstalledItemsDialogComponent, TbPeConnectivityMethodPromptComponent, diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html new file mode 100644 index 0000000000..658ed108df --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.html @@ -0,0 +1,31 @@ + + + + {{ label | translate }} + + + @if (searchable) { + + } + +
+ @for (key of visibleOptions; track key) { + + {{ labelFor(key) }} + + } +
+
diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss new file mode 100644 index 0000000000..494b251eb2 --- /dev/null +++ b/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; + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.ts new file mode 100644 index 0000000000..fb62675145 --- /dev/null +++ b/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(); + + /** Turns an option key into what the user reads. */ + @Input() labelFor: (key: string) => string = (key) => key; + + @Input() expanded = true; + + @Output() toggled = new EventEmitter(); + + 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; + } +} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html index 4187b431d3..fee3e1a296 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.html @@ -78,7 +78,8 @@ } @else {
- {{ getPlaceholderIcon() }} + + {{ getPlaceholderIcon() }}
}
diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts index 22a4eaf323..123de28c3f 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-card.component.ts +++ b/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 import { Component, EventEmitter, Input, Output } from '@angular/core'; 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 { TranslateService } from '@ngx-translate/core'; import { IotHubApiService } from '@core/http/iot-hub-api.service'; @@ -23,6 +23,11 @@ export class TbIotHubItemCardComponent { @Input() showTypeChip = true; @Input() showSubtype = false; @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(); @Output() creatorClick = new EventEmitter(); @Output() installClick = new EventEmitter(); @@ -47,9 +52,10 @@ export class TbIotHubItemCardComponent { } isCompactLayout(): boolean { - return this.item.type === ItemType.CALCULATED_FIELD - || this.item.type === ItemType.ALARM_RULE - || this.item.type === ItemType.RULE_CHAIN; + if (this.layout === 'preview') { + return false; + } + return isCompactItemType(this.item.type); } getPreviewUrl(): string | null { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts index 41b5d77814..4cae7cb542 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts +++ b/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 { DialogComponent } from '@shared/components/dialog.component'; 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 { IotHubApiService } from '@core/http/iot-hub-api.service'; import { TranslateService } from '@ngx-translate/core'; @@ -87,9 +87,7 @@ export class TbIotHubItemDetailDialogComponent extends DialogComponent -
+
{{ 'iot-hub.results-count' | translate:{ count: totalElements } }}
- -
+ + + + +
+ @if (showFilters) { + + }
-
+
{{ 'iot-hub.results-count' | translate:{ count: totalElements } }} @@ -76,62 +88,98 @@
-
- -
- - @if (hasError) { -
-
-

{{ 'iot-hub.network-server-unavailable' | translate }}

-

{{ 'iot-hub.network-server-unavailable-text' | translate }}

- -
+ + +
+ @if (activeFilterCount > 0) { + } - - - @if (!hasError && totalElements === 0 && searchText?.trim()) { -
-
-

{{ 'iot-hub.no-items-found' | translate }}

-

{{ 'iot-hub.try-adjusting-search' | translate }}

-
+ + + @if (categoryOptions.length > 0) { + + + } + @if (useCaseOptions.length > 0) { + + + } +
+
- - @if (resultGroups.length > 0) { -
- @for (group of resultGroups; track group.type) { -
- - - -
- @for (item of group.items; track item.id) { - - - } -
-
- } -
+
+ + +
+ @if (showFilters) { + } + +
+ + @if (hasError) { +
+
+

{{ 'iot-hub.network-server-unavailable' | translate }}

+

{{ 'iot-hub.network-server-unavailable-text' | translate }}

+ +
+ } + + + @if (!hasError && totalElements === 0 && searchText?.trim()) { +
+
+

{{ 'iot-hub.no-items-found' | translate }}

+

{{ 'iot-hub.try-adjusting-search' | translate }}

+
+ } + + + @if (results.length > 0) { +
+ @for (item of results; track item.id) { + + + } +
+ } +
diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss index 4b43ad5b3c..ff79875722 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss @@ -8,6 +8,13 @@ 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 { display: none; margin-left: auto; @@ -143,69 +150,113 @@ overflow: auto; } -// Categories / sections -.tb-search-categories { - display: flex; - flex-direction: column; - gap: 48px; +// Card grid +.tb-search-card-grid { + display: grid; + grid-template-columns: repeat(5, 1fr); + 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 -.tb-search-section-header { - font-size: 18px; - font-weight: 500; - line-height: 24px; - color: rgba(0, 0, 0, 0.87); - padding: 0; - margin-bottom: 12px; +// Filter button, with the active count +.tb-search-filter-btn { + flex-shrink: 0; +} + +.tb-search-filter-count { + margin-left: 6px; + 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 { - font-size: 24px; - width: 24px; - height: 24px; +// Facet sidebar beside the grid. Both columns scroll inside the given height, so neither grows +// past the card. +.tb-search-layout { + 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-card-grid { - display: grid; - grid-template-columns: repeat(5, 1fr); - gap: 20px; +.tb-search-facets-desktop { + width: 232px; + flex-shrink: 0; + border-right: 1px solid rgba(0, 0, 0, 0.12); - &.tb-search-card-grid-compact { - grid-template-columns: repeat(3, 1fr); + // Starts at the card's edge so the rules across it reach it; each facet indents its own text. + --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 @media #{$mat-gt-xxl} { .tb-search-card-grid { grid-template-columns: repeat(6, 1fr); - - &.tb-search-card-grid-compact { - grid-template-columns: repeat(4, 1fr); - } } } @media #{$mat-lt-xl} { .tb-search-card-grid { grid-template-columns: repeat(4, 1fr); - - &.tb-search-card-grid-compact { - grid-template-columns: repeat(3, 1fr); - } } } @media #{$mat-lt-xmd} { .tb-search-card-grid { 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 { grid-template-columns: repeat(2, 1fr); - - &.tb-search-card-grid-compact { - grid-template-columns: repeat(1, 1fr); - } } } @@ -268,3 +315,36 @@ 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; + } +} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts index f915be77e1..2ce6a552c7 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.ts +++ b/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-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 { TranslateService } from '@ngx-translate/core'; -import { forkJoin, Subject, Subscription } from 'rxjs'; -import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; +import { forkJoin, of, Subject, Subscription } from 'rxjs'; +import { catchError, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; 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 { 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 { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubActionsService } from './iot-hub-actions.service'; +import { measureGridColumns } from './iot-hub-utils'; -interface SearchResultGroup { - type: ItemType; - items: MpItemVersionView[]; -} - -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 -]; +/** A page is whole rows of the grid, and never fewer than MIN_PAGE_SIZE cards. */ +const ROWS_PER_PAGE = 3; +const MIN_PAGE_SIZE = 12; @Component({ selector: 'tb-iot-hub-search', @@ -37,32 +33,50 @@ const TYPE_ORDER: ItemType[] = [ }) export class TbIotHubSearchComponent implements OnInit, OnDestroy { - readonly ItemType = ItemType; - @Input() searchText = ''; @Input() creatorId: string; @Input() showCreator = true; + /** Off on the creator profile, which is already scoped to one creator. */ + @Input() showFilters = true; @Output() searchTextChange = new EventEmitter(); get searchPlaceholderKey(): string { return this.creatorId ? 'iot-hub.search-published-items' : 'iot-hub.search'; } - resultGroups: SearchResultGroup[] = []; + results: MpItemVersionView[] = []; totalElements = 0; isLoading = false; hasError = false; private retryTimer: any = null; - pageSize = 15; pageIndex = 0; - pageSizeOptions = [15, 30, 60]; - sortOptions: SortOption[] = [ - { 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 } - ]; + /** A hidden element carrying the real grid's classes, so the column count comes from the CSS. */ + @ViewChild('cardGridProbe', { static: true }) cardGridProbe!: ElementRef; + cols = 5; + pageSize = MIN_PAGE_SIZE; + private resizeObserver?: ResizeObserver; + private resizeSubject = new Subject(); + 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(); + activeCategories = new Set(); + activeUseCases = new Set(); + + readonly sortOptions = IOT_HUB_SORT_OPTIONS; selectedSortIndex = 0; installedWidgets: IotHubInstalledItem[] = []; @@ -74,16 +88,30 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { private searchSubject = new Subject(); private searchSubscription: Subscription; + /** Every reload goes through here, so a newer request cancels an older one still in flight. */ + private loadSubject = new Subject(); + private loadSubscription: Subscription; constructor( private router: Router, private translate: TranslateService, private iotHubApiService: IotHubApiService, - private iotHubActions: IotHubActionsService + private iotHubActions: IotHubActionsService, + private zone: NgZone ) {} ngOnInit(): void { + this.measureCols(); + this.observeGridWidth(); + if (this.showFilters) { + this.loadFilterInfo(); + } 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( debounceTime(300), distinctUntilChanged() @@ -96,6 +124,125 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { ngOnDestroy(): void { 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(); + this.activeCategories = new Set(); + this.activeUseCases = new Set(); + this.reloadFromFirstPage(); + } + + /** A new Set rather than a mutation, so the facet list's @Input sees the change. */ + private toggled(set: Set, key: string): Set { + 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(); + 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 { @@ -158,35 +305,6 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { 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 getInstalledItem(item: MpItemVersionView): IotHubInstalledItem | undefined { switch (item.type) { @@ -270,52 +388,39 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy { clearTimeout(this.retryTimer); this.retryTimer = null; } + // hasError stays as-is until a request succeeds. this.isLoading = true; - // hasError stays as-is until the request actually succeeds - // (cleared in the `next` callback below). - this.fetchResults(this.searchText || '').subscribe({ - next: result => { - this.applyResults(result.data, result.totalElements); - this.hasError = false; - }, - error: () => { - this.isLoading = false; - this.hasError = true; - this.resultGroups = []; - this.totalElements = 0; - } - }); + this.loadSubject.next(); + } + + /** A null result is a failed request. */ + private applyResult(result: PageData | null): void { + this.isLoading = false; + if (result) { + this.totalElements = result.totalElements; + this.results = result.data; + this.hasError = false; + } else { + this.hasError = true; + this.results = []; + this.totalElements = 0; + } } private fetchResults(text: string) { const sort = this.sortOptions[this.selectedSortIndex]; const sortOrder: SortOrder = { property: sort.value, direction: sort.direction }; 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 }); } - 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(); - 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 { const config = { ignoreLoading: true }; const pageLink = new PageLink(10000, 0); diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts index f9c67aeb5e..27cef3aecd 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts +++ b/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_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: @@ -62,12 +64,30 @@ export interface IotHubFilterGroup { items: FilterParamInfo[]; } -export function filterIotHubItemsBySearch(items: FilterParamInfo[], search: string): FilterParamInfo[] { - const normalized = (search || '').toLowerCase(); +export function filterByLabel(items: T[], search: string, labelOf: (item: T) => string): T[] { + const normalized = (search || '').trim().toLowerCase(); if (!normalized) { 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[] { diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-alarm-rules-unavailable-page.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-alarm-rules-unavailable-page.component.ts index c648eeb14a..f8ec79e525 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-alarm-rules-unavailable-page.component.ts +++ b/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 { Router } from '@angular/router'; import { environment as env } from '@env/environment'; +import { ItemType, itemTypeColors } from '@shared/models/iot-hub/iot-hub-item.models'; @Component({ selector: 'tb-iot-hub-alarm-rules-unavailable-page', @@ -12,8 +13,7 @@ import { environment as env } from '@env/environment'; }) export class TbIotHubAlarmRulesUnavailablePageComponent { - // Same colour as the ALARM_RULE HeroTypeConfig entry on the home page. - readonly alarmRulesColor = '#d66f2e'; + readonly alarmRulesColor = itemTypeColors[ItemType.ALARM_RULE]; readonly currentTbVersion: string = env.tbVersion; diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html index d91164a6c3..42f92fc3d1 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-creator-profile.component.html @@ -96,7 +96,8 @@
- +

{{ 'iot-hub.published-items' | translate }} ({{ creator.publishedCount }})

diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index cf4007b511..b2b785ceae 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -54,13 +54,13 @@ [matAutocomplete]="searchAuto" (input)="onSearchInput()" (focus)="onSearchFocus()" - (keyup.enter)="onSearch()"> + (keydown.enter)="onSearchEnter($event)"> @if (searchText) { } - @@ -72,6 +72,13 @@ + } @else if (searchFailed) { + +
+ cloud_off + {{ 'iot-hub.network-server-unavailable' | translate }} +
+
} @else if (searchResults.length === 0 && searchLoaded) {
@@ -84,39 +91,55 @@
} @else { - @for (group of searchResultGroups; track group.type) { - - @for (item of group.items; track item.id) { - - @if (isCompactType(item.type)) { -
- {{ getCompactIcon(item) }} -
- } @else { -
- @if (getItemImage(item); as imgUrl) { - + @for (item of searchResults; track item.id) { + + +
+ @if (isCompactType(item.type)) { +
+ {{ getCompactIcon(item) }} +
+ } @else if (getItemImage(item); as imgUrl) { + + } @else { + {{ getItemTypeIcon(item.type) }} + } +
+
+ {{ item.name }} + + + {{ getItemTypeIcon(item.type) }} + {{ getItemTypeLabel(item.type) }} + + @if (item.creatorDisplayName) { + + @if (item.creatorVerified) { + verified } @else { - {{ getItemTypeIcon(item.type) }} + person } -
- } -
- {{ item.name }} - - person - {{ item.creatorDisplayName }} + {{ item.creatorDisplayName }} -
-
- } - + } + +
+
} } - + + @if (searchText?.trim(); as query) { + @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 }} + } +
diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss index de032d8f1a..7440403390 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss +++ b/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 178px 50px 0 rgba(0, 0, 0, 0); - // Section group — 12px gap between groups - .mat-mdc-optgroup + .mat-mdc-optgroup .mat-mdc-optgroup-label { - 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; - + // Shared by every row; each row kind below is selected by its own class. + .mat-mdc-option { .mdc-list-item__primary-text { - font-size: 14px; - font-weight: 500; - line-height: 20px; - letter-spacing: 0.25px; - color: rgba(0, 0, 0, 0.54); + display: flex; + align-items: center; + gap: 16px; + width: 100%; } - } - - // 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), &.mat-mdc-option-active:not(.mdc-list-item--disabled) { @@ -259,13 +237,13 @@ .mat-icon, tb-icon { margin-right: 0; } + } - .mdc-list-item__primary-text { - display: flex; - align-items: center; - gap: 16px; - width: 100%; - } + // Item row — Design: 8px V / 16px H, 16px gap, centered + .mat-mdc-option.tb-search-popup-item { + padding: 8px 16px; + min-height: auto; + height: auto; } // Thumbnail — Design: 99px x 56px, 4px radius, 1px border, 4% bg @@ -295,11 +273,11 @@ 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 { - width: 56px; - height: 56px; - border-radius: 4.667px; + width: 36px; + height: 36px; + border-radius: 6px; flex-shrink: 0; display: flex; align-items: center; @@ -307,9 +285,9 @@ } .tb-search-popup-icon-inner { - font-size: 28px; - width: 28px; - height: 28px; + font-size: 22px; + width: 22px; + height: 22px; color: white !important; --tb-icon-color: white; } @@ -346,13 +324,63 @@ letter-spacing: 0.25px; color: rgba(0, 0, 0, 0.54); white-space: nowrap; + min-width: 0; mat-icon { + flex-shrink: 0; font-size: 16px; width: 16px; height: 16px; margin-right: 0; 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 { pointer-events: none; opacity: 1 !important; + padding: 8px 16px; } .tb-search-popup-no-results-content { @@ -391,26 +420,31 @@ } // 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; bottom: 0; + z-index: 1; border-top: 1px solid rgba(0, 0, 0, 0.12); height: 40px; min-height: 40px; padding: 8px 16px; - display: flex; - align-items: center; - justify-content: flex-start; font-size: 14px; font-weight: 500; line-height: 20px; letter-spacing: 0.25px; color: $tb-primary-color; - cursor: pointer; background: white; 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; } } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index 8164b1bdef..0d987e8a83 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/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 { Router } from '@angular/router'; import { MatAutocompleteTrigger } from '@angular/material/autocomplete'; +import { MatOptionSelectionChange } from '@angular/material/core'; import { BreakpointObserver } from '@angular/cdk/layout'; -import { forkJoin, Subject, Subscription } from 'rxjs'; -import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; +import { forkJoin, of, Subject, Subscription } from 'rxjs'; +import { catchError, debounceTime, switchMap } from 'rxjs/operators'; import { MediaBreakpoints } from '@shared/models/constants'; import { PageLink } from '@shared/models/page/page-link'; 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 { 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 { IotHubApiService } from '@core/http/iot-hub-api.service'; import { TranslateService } from '@ngx-translate/core'; @@ -32,15 +43,8 @@ interface HeroTypeConfig { icon: string; } -interface SearchResultGroup { - type: ItemType; - items: MpItemVersionView[]; -} - -const SEARCH_GROUP_ORDER: ItemType[] = [ - ItemType.DEVICE, ItemType.SOLUTION_TEMPLATE, ItemType.WIDGET, - ItemType.CALCULATED_FIELD, ItemType.ALARM_RULE, ItemType.RULE_CHAIN -]; +/** Rows the search popup shows: page 0 of the search page's own request. */ +const SEARCH_POPUP_PAGE_SIZE = 10; @Component({ selector: 'tb-iot-hub-home', @@ -51,12 +55,15 @@ const SEARCH_GROUP_ORDER: ItemType[] = [ export class TbIotHubHomeComponent implements OnInit, OnDestroy { readonly ItemType = ItemType; + readonly isCompactType = isCompactItemType; searchText = ''; searchResults: MpItemVersionView[] = []; - searchResultGroups: SearchResultGroup[] = []; + /** Everything the search matched, for the footer's "See all N results". */ + searchTotal = 0; searchLoaded = false; searchLoading = false; + searchFailed = false; @ViewChild(MatAutocompleteTrigger) searchAutoTrigger: MatAutocompleteTrigger; @ViewChild('searchInput', {read: ElementRef}) searchInputRef: ElementRef; private searchSubject = new Subject(); @@ -65,27 +72,27 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { 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' }, { - 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' }, { - 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' }, { - 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' }, { - 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' }, { - 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' } ]; @@ -153,17 +160,23 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { }); this.searchSubscription = this.searchSubject.pipe( debounceTime(300), - distinctUntilChanged(), switchMap(text => { this.searchLoading = true; - const sortOrder: SortOrder = { property: 'totalInstallCount', direction: Direction.DESC }; - const pageLink = new PageLink(10, 0, text.trim() || null, sortOrder); - const query = new MpItemVersionQuery(pageLink); - return this.iotHubApiService.getPublishedVersions(query, { ignoreLoading: true }); + const trimmed = text.trim(); + // One list ranked across every type the platform surfaces. With an empty field relevance + // is served as the install count. + 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)) + ); }) - ).subscribe(result => { - this.searchResults = result.data; - this.searchResultGroups = this.groupSearchResults(result.data); + ).subscribe(page => { + this.searchFailed = !page; + this.searchResults = page?.data ?? []; + this.searchTotal = page?.totalElements ?? 0; this.searchLoaded = true; this.searchLoading = false; }); @@ -227,7 +240,26 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { 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(); } @@ -237,12 +269,6 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { 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 { return item.icon || getItemTypeIcon(item.type); } @@ -255,9 +281,13 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { return getItemTypeIcon(type); } - getSearchGroupLabel(type: ItemType): string { + getItemTypeColor(type: ItemType): string { + return getItemTypeColor(type); + } + + getItemTypeLabel(type: ItemType): string { const key = itemTypeTranslations.get(type); - return key ? this.translate.instant(key + '-plural') : type; + return key ? this.translate.instant(key) : type; } navigateToBrowse(type: ItemType): void { @@ -522,21 +552,4 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { }); } - private groupSearchResults(items: MpItemVersionView[]): SearchResultGroup[] { - const groupMap = new Map(); - 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) })); - } } diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss index 1e617fb1f3..5766a46a4c 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search-page.component.scss @@ -8,12 +8,17 @@ 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 .tb-search-back-btn { align-self: flex-start; - margin-top: 40px; - margin-left: 123px; + margin-left: -8px; } // Title @@ -30,100 +35,24 @@ 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 { flex: 1; min-height: 0; - padding-left: 123px; - padding-right: 123px; - - ::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; - } - } - } + --tb-search-side-pad: var(--tb-search-page-pad); + margin-left: calc(-1 * var(--tb-search-page-pad)); + margin-right: calc(-1 * var(--tb-search-page-pad)); } @media #{$mat-lt-lg} { - .tb-search-back-btn { - margin-top: 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; - } - } + .tb-search-page { + --tb-search-page-pad: 24px; } } @media #{$mat-lt-sm} { .tb-search-page { + --tb-search-page-pad: 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; - } - } - } } diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts index 2b822a5030..23c5738f1f 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-item.models.ts @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: Copyright The Thingsboard Authors // SPDX-License-Identifier: Apache-2.0 +import { Direction } from '@shared/models/page/sort-order'; + export enum ItemType { WIDGET = 'WIDGET', SOLUTION_TEMPLATE = 'SOLUTION_TEMPLATE', @@ -36,6 +38,22 @@ export const itemTypeIcons: Record = { export const getItemTypeIcon = (type?: string | null): string => 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 = { + [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. */ @@ -48,6 +66,40 @@ export const CREATOR_VISIBLE_ITEM_TYPES: ItemType[] = [ 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 { key: string; totalItems: number; diff --git a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts index e726fe4b39..a1f5b3077c 100644 --- a/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts +++ b/ui-ngx/src/app/shared/models/iot-hub/iot-hub-version.models.ts @@ -118,7 +118,10 @@ export interface ListingItemVersionNotFound { } export interface MpItemVersionQueryOptions { + /** Single item type, for a surface pinned to one (the type pages, the add-item dialog). */ type?: string; + /** Several item types at once, sent as a repeated `type` parameter. */ + types?: string[]; peOnly?: boolean; creatorId?: string; categories?: string[]; @@ -135,54 +138,62 @@ export interface MpItemVersionQueryOptions { 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 { constructor(public pageLink: PageLink, public options: MpItemVersionQueryOptions = {}) {} public toQuery(): string { - let query = this.pageLink.toQuery(); - 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; + return this.pageLink.toQuery() + filtersToQuery(this.options); } } diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 5e71c56e0c..7974f825fc 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3706,6 +3706,8 @@ "search": "Search...", "search-published-items": "Search published items...", "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-items-available": "No items available", "search-results": "Search results", @@ -3728,6 +3730,7 @@ "type": "Type", "items-per-page": "Items per page", "filter": "Filter", + "clear-filters": "Clear filters", "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-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-rule-chains": "Search rule chains...", "search-devices": "Search devices...", + "sort-most-relevant": "Most relevant", "sort-most-installed": "Most installed", "sort-newest": "Newest", "sort-name": "Name (A-Z)",