16 changed files with 531 additions and 94 deletions
@ -0,0 +1,44 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 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. |
|||
|
|||
--> |
|||
<div class="tb-select-map-entity-panel" [formGroup]="selectEntityFormGroup"> |
|||
<mat-form-field class="mat-block" appearance="outline" hideRequiredMarker> |
|||
<mat-label>{{ (selectEntityFormGroup.get('entity').value ? 'entity.entity' : 'widgets.maps.data-layer.select-entity') | translate }}</mat-label> |
|||
<mat-select formControlName="entity"> |
|||
<mat-option *ngFor="let entity of entities" [value]="entity"> |
|||
{{ entity.entity.entityDisplayName }} |
|||
</mat-option> |
|||
</mat-select> |
|||
<mat-hint translate>widgets.maps.data-layer.select-entity-hint</mat-hint> |
|||
</mat-form-field> |
|||
<div class="tb-select-map-entity-panel-buttons"> |
|||
<span class="flex-1"></span> |
|||
<button mat-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="cancel()"> |
|||
{{ 'action.cancel' | translate }} |
|||
</button> |
|||
<button mat-raised-button |
|||
color="primary" |
|||
type="button" |
|||
(click)="selectEntity()" |
|||
[disabled]="selectEntityFormGroup.invalid || !selectEntityFormGroup.dirty"> |
|||
{{ 'action.select' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,39 @@ |
|||
/** |
|||
* Copyright © 2016-2024 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 '../../../../../../../../scss/constants'; |
|||
|
|||
.tb-select-map-entity-panel { |
|||
width: 320px; |
|||
max-width: 90vw; |
|||
display: flex; |
|||
flex-direction: column; |
|||
gap: 16px; |
|||
@media #{$mat-xs} { |
|||
width: 90vw; |
|||
} |
|||
.mat-mdc-form-field-hint-wrapper { |
|||
padding: 0; |
|||
} |
|||
.tb-select-map-entity-panel-buttons { |
|||
height: 40px; |
|||
display: flex; |
|||
flex-direction: row; |
|||
gap: 16px; |
|||
justify-content: flex-end; |
|||
align-items: flex-end; |
|||
} |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 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, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|||
import { UnplacedMapDataItem } from '@home/components/widget/lib/maps/data-layer/map-data-layer'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-select-map-entity-panel', |
|||
templateUrl: './select-map-entity-panel.component.html', |
|||
providers: [], |
|||
styleUrls: ['./select-map-entity-panel.component.scss'], |
|||
encapsulation: ViewEncapsulation.None |
|||
}) |
|||
export class SelectMapEntityPanelComponent extends PageComponent implements OnInit { |
|||
|
|||
@Input() |
|||
entities: UnplacedMapDataItem[]; |
|||
|
|||
@Output() |
|||
entitySelected = new EventEmitter<UnplacedMapDataItem>(); |
|||
|
|||
selectEntityFormGroup: UntypedFormGroup; |
|||
|
|||
selectedEntity: UnplacedMapDataItem = null; |
|||
|
|||
constructor(private fb: UntypedFormBuilder, |
|||
protected store: Store<AppState>, |
|||
private popover: TbPopoverComponent) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.selectEntityFormGroup = this.fb.group( |
|||
{ |
|||
entity: ['', Validators.required] |
|||
} |
|||
); |
|||
this.popover.tbDestroy.subscribe(() => { |
|||
this.entitySelected.emit(this.selectedEntity); |
|||
}); |
|||
} |
|||
|
|||
cancel() { |
|||
this.popover.hide(); |
|||
} |
|||
|
|||
selectEntity() { |
|||
this.selectedEntity = this.selectEntityFormGroup.value.entity; |
|||
this.popover.hide(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue