2019-08-12 19:34:23 +03:00
|
|
|
///
|
2023-01-31 10:43:56 +02:00
|
|
|
/// Copyright © 2016-2023 The Thingsboard Authors
|
2019-08-12 19:34:23 +03:00
|
|
|
///
|
|
|
|
|
/// 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.
|
|
|
|
|
///
|
|
|
|
|
|
2021-05-26 13:49:30 +03:00
|
|
|
import { ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, Output } from '@angular/core';
|
2019-08-12 19:34:23 +03:00
|
|
|
import { PageComponent } from '@shared/components/page.component';
|
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
import { AppState } from '@core/core.state';
|
2020-04-28 12:04:21 +03:00
|
|
|
import { FormGroup } from '@angular/forms';
|
2021-05-26 13:49:30 +03:00
|
|
|
import { Subscription } from 'rxjs';
|
2019-08-12 19:34:23 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'tb-details-panel',
|
|
|
|
|
templateUrl: './details-panel.component.html',
|
|
|
|
|
styleUrls: ['./details-panel.component.scss']
|
|
|
|
|
})
|
2021-05-26 13:49:30 +03:00
|
|
|
export class DetailsPanelComponent extends PageComponent implements OnDestroy {
|
2019-08-12 19:34:23 +03:00
|
|
|
|
|
|
|
|
@Input() headerHeightPx = 100;
|
|
|
|
|
@Input() headerTitle = '';
|
|
|
|
|
@Input() headerSubtitle = '';
|
|
|
|
|
@Input() isReadOnly = false;
|
|
|
|
|
@Input() isAlwaysEdit = false;
|
2021-03-04 19:38:30 +02:00
|
|
|
@Input() isShowSearch = false;
|
|
|
|
|
@Input() backgroundColor = '#FFF';
|
2019-09-25 19:37:29 +03:00
|
|
|
|
2021-05-26 13:49:30 +03:00
|
|
|
private theFormValue: FormGroup;
|
|
|
|
|
private formSubscription: Subscription = null;
|
2019-09-25 19:37:29 +03:00
|
|
|
|
|
|
|
|
@Input()
|
2020-04-27 10:39:18 +03:00
|
|
|
set theForm(value: FormGroup) {
|
2021-05-26 13:49:30 +03:00
|
|
|
if (this.theFormValue !== value) {
|
|
|
|
|
if (this.formSubscription !== null) {
|
|
|
|
|
this.formSubscription.unsubscribe();
|
|
|
|
|
this.formSubscription = null;
|
|
|
|
|
}
|
|
|
|
|
this.theFormValue = value;
|
|
|
|
|
if (this.theFormValue !== null) {
|
|
|
|
|
this.formSubscription = this.theFormValue.valueChanges.subscribe(() => this.cd.detectChanges());
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
|
2020-04-27 10:39:18 +03:00
|
|
|
get theForm(): FormGroup {
|
2019-09-25 19:37:29 +03:00
|
|
|
return this.theFormValue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-12 19:34:23 +03:00
|
|
|
@Output()
|
|
|
|
|
closeDetails = new EventEmitter<void>();
|
|
|
|
|
@Output()
|
|
|
|
|
toggleDetailsEditMode = new EventEmitter<boolean>();
|
|
|
|
|
@Output()
|
|
|
|
|
applyDetails = new EventEmitter<void>();
|
2021-03-04 19:38:30 +02:00
|
|
|
@Output()
|
|
|
|
|
closeSearch = new EventEmitter<void>();
|
2019-08-12 19:34:23 +03:00
|
|
|
|
|
|
|
|
isEditValue = false;
|
2021-03-04 19:38:30 +02:00
|
|
|
showSearchPane = false;
|
2019-08-12 19:34:23 +03:00
|
|
|
|
|
|
|
|
@Output()
|
|
|
|
|
isEditChange = new EventEmitter<boolean>();
|
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
|
get isEdit() {
|
2019-09-25 19:37:29 +03:00
|
|
|
return this.isAlwaysEdit || this.isEditValue;
|
2019-08-12 19:34:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set isEdit(val: boolean) {
|
|
|
|
|
this.isEditValue = val;
|
|
|
|
|
this.isEditChange.emit(this.isEditValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-26 13:49:30 +03:00
|
|
|
constructor(protected store: Store<AppState>,
|
|
|
|
|
private cd: ChangeDetectorRef) {
|
2019-08-12 19:34:23 +03:00
|
|
|
super(store);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-26 13:49:30 +03:00
|
|
|
ngOnDestroy() {
|
|
|
|
|
if (this.formSubscription !== null) {
|
|
|
|
|
this.formSubscription.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
super.ngOnDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-12 19:34:23 +03:00
|
|
|
onCloseDetails() {
|
|
|
|
|
this.closeDetails.emit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onToggleDetailsEditMode() {
|
|
|
|
|
if (!this.isAlwaysEdit) {
|
|
|
|
|
this.isEdit = !this.isEdit;
|
|
|
|
|
}
|
|
|
|
|
this.toggleDetailsEditMode.emit(this.isEditValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onApplyDetails() {
|
2019-09-25 19:37:29 +03:00
|
|
|
if (this.theForm && this.theForm.valid) {
|
2019-08-12 19:34:23 +03:00
|
|
|
this.applyDetails.emit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 19:38:30 +02:00
|
|
|
onToggleSearch() {
|
|
|
|
|
this.showSearchPane = !this.showSearchPane;
|
|
|
|
|
if (!this.showSearchPane) {
|
|
|
|
|
this.closeSearch.emit();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-12 19:34:23 +03:00
|
|
|
}
|