diff --git a/ui-ngx/src/app/modules/common/modules-map.ts b/ui-ngx/src/app/modules/common/modules-map.ts index 40172e2667..beba4c5d40 100644 --- a/ui-ngx/src/app/modules/common/modules-map.ts +++ b/ui-ngx/src/app/modules/common/modules-map.ts @@ -300,6 +300,7 @@ import * as QueueFormComponent from '@home/components/queue/queue-form.component import * as AssetProfileComponent from '@home/components/profile/asset-profile.component'; import * as AssetProfileDialogComponent from '@home/components/profile/asset-profile-dialog.component'; import * as AssetProfileAutocompleteComponent from '@home/components/profile/asset-profile-autocomplete.component'; +import * as RuleChainSelectComponent from '@shared/components/rule-chain/rule-chain-select.component'; import { IModulesMap } from '@modules/common/modules-map.models'; @@ -418,6 +419,7 @@ class ModulesMap implements IModulesMap { '@shared/components/time/quick-time-interval.component': QuickTimeIntervalComponent, '@shared/components/dashboard-select.component': DashboardSelectComponent, '@shared/components/dashboard-select-panel.component': DashboardSelectPanelComponent, + '@shared/components/rule-chain/rule-chain-select.component': RuleChainSelectComponent, '@shared/components/time/datetime-period.component': DatetimePeriodComponent, '@shared/components/time/datetime.component': DatetimeComponent, '@shared/components/time/timezone-select.component': TimezoneSelectComponent, diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html index efb4851bd8..85dd8df688 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html @@ -21,49 +21,42 @@ - - - menu - - + + + + - - search - + + search + + + close + - - close - - - chevron_left - @@ -164,6 +157,14 @@ + + chevron_right + + + + {{ruleChain.name}} + + diff --git a/ui-ngx/src/app/shared/components/rule-chain/rule-chain-select.component.scss b/ui-ngx/src/app/shared/components/rule-chain/rule-chain-select.component.scss new file mode 100644 index 0000000000..05b2c8e92f --- /dev/null +++ b/ui-ngx/src/app/shared/components/rule-chain/rule-chain-select.component.scss @@ -0,0 +1,38 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +:host { + min-width: 52px; + width: 100%; + padding: 0 6px; + .mat-mdc-select { + display: flex; + max-width: 300px; + height: 48px; + min-height: 100%; + pointer-events: all; + } +} + +:host ::ng-deep { + .mat-mdc-select { + .mat-mdc-select-value { + max-width: 282px; + } + .mat-mdc-select-arrow { + width: 24px; + } + } +} diff --git a/ui-ngx/src/app/shared/components/rule-chain/rule-chain-select.component.ts b/ui-ngx/src/app/shared/components/rule-chain/rule-chain-select.component.ts new file mode 100644 index 0000000000..a2d02c1c46 --- /dev/null +++ b/ui-ngx/src/app/shared/components/rule-chain/rule-chain-select.component.ts @@ -0,0 +1,117 @@ +/// +/// Copyright © 2016-2023 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { Component, ElementRef, forwardRef, Inject, Input, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; +import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; +import { Observable } from 'rxjs'; +import { PageLink } from '@shared/models/page/page-link'; +import { map, share } from 'rxjs/operators'; +import { PageData } from '@shared/models/page/page-data'; +import { Store } from '@ngrx/store'; +import { AppState } from '@app/core/core.state'; +import { coerceBooleanProperty } from '@angular/cdk/coercion'; +import { TooltipPosition } from '@angular/material/tooltip'; +import { CdkOverlayOrigin, Overlay } from '@angular/cdk/overlay'; +import { BreakpointObserver } from '@angular/cdk/layout'; +import { DOCUMENT } from '@angular/common'; +import { WINDOW } from '@core/services/window.service'; +import { RuleChain, RuleChainType } from '@shared/models/rule-chain.models'; +import { RuleChainService } from '@core/http/rule-chain.service'; + +// @dynamic +@Component({ + selector: 'tb-rule-chain-select', + templateUrl: './rule-chain-select.component.html', + styleUrls: ['./rule-chain-select.component.scss'], + providers: [{ + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => RuleChainSelectComponent), + multi: true + }] +}) +export class RuleChainSelectComponent implements ControlValueAccessor, OnInit { + + @Input() + tooltipPosition: TooltipPosition = 'above'; + + private requiredValue: boolean; + get required(): boolean { + return this.requiredValue; + } + @Input() + set required(value: boolean) { + this.requiredValue = coerceBooleanProperty(value); + } + + @Input() + disabled: boolean; + + ruleChains$: Observable>; + + ruleChainId: string | null; + + @ViewChild('ruleChainSelectPanelOrigin') ruleChainSelectPanelOrigin: CdkOverlayOrigin; + + private propagateChange = (v: any) => { }; + + constructor(private store: Store, + private ruleChainService: RuleChainService, + private overlay: Overlay, + private breakpointObserver: BreakpointObserver, + private viewContainerRef: ViewContainerRef, + private nativeElement: ElementRef, + @Inject(DOCUMENT) private document: Document, + @Inject(WINDOW) private window: Window) { + } + + registerOnChange(fn: any): void { + this.propagateChange = fn; + } + + registerOnTouched(fn: any): void { + } + + ngOnInit() { + + const pageLink = new PageLink(100); + + this.ruleChains$ = this.getRuleChains(pageLink).pipe( + map((pageData) => pageData.data), + share() + ); + } + + setDisabledState(isDisabled: boolean): void { + this.disabled = isDisabled; + } + + writeValue(value: string | null): void { + this.ruleChainId = value; + } + + ruleChainIdChanged() { + this.updateView(); + } + + private updateView() { + this.propagateChange(this.ruleChainId); + } + + private getRuleChains(pageLink: PageLink): Observable> { + return this.ruleChainService.getRuleChains(pageLink, RuleChainType.CORE, {ignoreLoading: true}); + } + +} diff --git a/ui-ngx/src/app/shared/shared.module.ts b/ui-ngx/src/app/shared/shared.module.ts index 9bd9006399..6b6aa5a5a4 100644 --- a/ui-ngx/src/app/shared/shared.module.ts +++ b/ui-ngx/src/app/shared/shared.module.ts @@ -189,6 +189,7 @@ import { } from '@shared/layout/layout.directives'; import { ColorPickerComponent } from '@shared/components/color-picker/color-picker.component'; import { ShortNumberPipe } from '@shared/pipe/short-number.pipe'; +import { RuleChainSelectComponent } from '@shared/components/rule-chain/rule-chain-select.component'; export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService) { return markedOptionsService; @@ -356,7 +357,8 @@ export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService) GtMdLgLayoutAlignDirective, GtMdLgLayoutGapDirective, GtMdLgShowHideDirective, - ColorPickerComponent + ColorPickerComponent, + RuleChainSelectComponent ], imports: [ CommonModule, @@ -580,7 +582,8 @@ export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService) GtMdLgLayoutAlignDirective, GtMdLgLayoutGapDirective, GtMdLgShowHideDirective, - ColorPickerComponent + ColorPickerComponent, + RuleChainSelectComponent ] }) export class SharedModule { } 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 bcaa4a183f..9ab9284a59 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3325,6 +3325,7 @@ "events": "Events", "search": "Search nodes", "open-node-library": "Open node library", + "close-node-library": "Close node library", "add": "Add rule node", "name": "Name", "name-required": "Name is required.",