2019-08-09 19:13:18 +03:00
|
|
|
///
|
2024-01-09 10:46:16 +02:00
|
|
|
/// Copyright © 2016-2024 The Thingsboard Authors
|
2019-08-09 19:13:18 +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.
|
|
|
|
|
///
|
|
|
|
|
|
2023-08-14 13:30:24 +03:00
|
|
|
import { AfterViewInit, Component, ElementRef, Inject, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
2024-01-23 15:27:53 +02:00
|
|
|
import { skip, startWith, Subject } from 'rxjs';
|
2023-02-14 15:33:35 +02:00
|
|
|
import { Store } from '@ngrx/store';
|
2023-08-14 13:30:24 +03:00
|
|
|
import { debounceTime, distinctUntilChanged, takeUntil } from 'rxjs/operators';
|
2019-08-09 19:13:18 +03:00
|
|
|
|
|
|
|
|
import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout';
|
|
|
|
|
import { PageComponent } from '@shared/components/page.component';
|
|
|
|
|
import { AppState } from '@core/core.state';
|
2023-02-14 15:33:35 +02:00
|
|
|
import { getCurrentAuthState } from '@core/auth/auth.selectors';
|
2019-08-09 19:13:18 +03:00
|
|
|
import { MediaBreakpoints } from '@shared/models/constants';
|
2021-12-06 12:54:48 +02:00
|
|
|
import screenfull from 'screenfull';
|
2020-02-10 13:15:29 +02:00
|
|
|
import { MatSidenav } from '@angular/material/sidenav';
|
2019-11-15 12:22:14 +02:00
|
|
|
import { AuthState } from '@core/auth/auth.models';
|
|
|
|
|
import { WINDOW } from '@core/services/window.service';
|
2020-04-02 11:01:13 +03:00
|
|
|
import { instanceOfSearchableComponent, ISearchableComponent } from '@home/models/searchable-component.models';
|
2023-02-09 19:13:44 +02:00
|
|
|
import { ActiveComponentService } from '@core/services/active-component.service';
|
|
|
|
|
import { RouterTabsComponent } from '@home/components/router-tabs.component';
|
2023-08-14 13:30:24 +03:00
|
|
|
import { FormBuilder } from '@angular/forms';
|
2024-01-23 11:20:36 +02:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
import { isDefined, isDefinedAndNotNull } from '@core/utils';
|
2019-08-09 19:13:18 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'tb-home',
|
|
|
|
|
templateUrl: './home.component.html',
|
|
|
|
|
styleUrls: ['./home.component.scss']
|
|
|
|
|
})
|
2023-08-14 13:30:24 +03:00
|
|
|
export class HomeComponent extends PageComponent implements AfterViewInit, OnInit, OnDestroy {
|
2019-08-09 19:13:18 +03:00
|
|
|
|
2019-11-15 12:22:14 +02:00
|
|
|
authState: AuthState = getCurrentAuthState(this.store);
|
|
|
|
|
|
|
|
|
|
forceFullscreen = this.authState.forceFullscreen;
|
|
|
|
|
|
2019-09-19 20:10:52 +03:00
|
|
|
activeComponent: any;
|
2019-12-12 19:55:17 +02:00
|
|
|
searchableComponent: ISearchableComponent;
|
2019-09-19 20:10:52 +03:00
|
|
|
|
2020-02-04 15:14:17 +02:00
|
|
|
sidenavMode: 'over' | 'push' | 'side' = 'side';
|
2019-08-09 19:13:18 +03:00
|
|
|
sidenavOpened = true;
|
|
|
|
|
|
2020-10-08 11:45:50 +03:00
|
|
|
logo = 'assets/logo_title_white.svg';
|
2019-08-09 19:13:18 +03:00
|
|
|
|
2020-02-10 13:10:14 +02:00
|
|
|
@ViewChild('sidenav')
|
2019-08-09 19:13:18 +03:00
|
|
|
sidenav: MatSidenav;
|
|
|
|
|
|
2020-02-10 13:10:14 +02:00
|
|
|
@ViewChild('searchInput') searchInputField: ElementRef;
|
2019-12-12 19:55:17 +02:00
|
|
|
|
2020-02-27 12:16:58 +02:00
|
|
|
fullscreenEnabled = screenfull.isEnabled;
|
2019-08-09 19:13:18 +03:00
|
|
|
|
2019-12-12 19:55:17 +02:00
|
|
|
searchEnabled = false;
|
|
|
|
|
showSearch = false;
|
2023-08-14 13:30:24 +03:00
|
|
|
textSearch = this.fb.control('', {nonNullable: true});
|
2019-12-12 19:55:17 +02:00
|
|
|
|
2023-02-09 19:13:44 +02:00
|
|
|
hideLoadingBar = false;
|
|
|
|
|
|
2023-08-14 13:30:24 +03:00
|
|
|
private destroy$ = new Subject<void>();
|
|
|
|
|
|
2019-08-09 19:13:18 +03:00
|
|
|
constructor(protected store: Store<AppState>,
|
2019-11-15 12:22:14 +02:00
|
|
|
@Inject(WINDOW) private window: Window,
|
2023-02-09 19:13:44 +02:00
|
|
|
private activeComponentService: ActiveComponentService,
|
2024-01-23 11:20:36 +02:00
|
|
|
private fb: FormBuilder,
|
|
|
|
|
public breakpointObserver: BreakpointObserver) {
|
2019-08-09 19:13:18 +03:00
|
|
|
super(store);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
|
|
const isGtSm = this.breakpointObserver.isMatched(MediaBreakpoints['gt-sm']);
|
|
|
|
|
this.sidenavMode = isGtSm ? 'side' : 'over';
|
|
|
|
|
this.sidenavOpened = isGtSm;
|
|
|
|
|
|
|
|
|
|
this.breakpointObserver
|
|
|
|
|
.observe(MediaBreakpoints['gt-sm'])
|
2023-08-14 13:30:24 +03:00
|
|
|
.pipe(takeUntil(this.destroy$))
|
2019-08-09 19:13:18 +03:00
|
|
|
.subscribe((state: BreakpointState) => {
|
|
|
|
|
if (state.matches) {
|
|
|
|
|
this.sidenavMode = 'side';
|
|
|
|
|
this.sidenavOpened = true;
|
|
|
|
|
} else {
|
|
|
|
|
this.sidenavMode = 'over';
|
|
|
|
|
this.sidenavOpened = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 13:30:24 +03:00
|
|
|
ngOnDestroy() {
|
|
|
|
|
this.destroy$.next();
|
|
|
|
|
this.destroy$.complete();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-12 19:55:17 +02:00
|
|
|
ngAfterViewInit() {
|
2023-08-14 13:30:24 +03:00
|
|
|
this.textSearch.valueChanges.pipe(
|
|
|
|
|
debounceTime(150),
|
|
|
|
|
startWith(''),
|
|
|
|
|
distinctUntilChanged((a: string, b: string) => a.trim() === b.trim()),
|
|
|
|
|
skip(1),
|
|
|
|
|
takeUntil(this.destroy$)
|
2023-08-15 11:42:18 +03:00
|
|
|
).subscribe(value => this.searchTextUpdated(value.trim()));
|
2019-12-12 19:55:17 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-09 19:13:18 +03:00
|
|
|
sidenavClicked() {
|
|
|
|
|
if (this.sidenavMode === 'over') {
|
|
|
|
|
this.sidenav.toggle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleFullscreen() {
|
2020-02-27 12:16:58 +02:00
|
|
|
if (screenfull.isEnabled) {
|
2019-08-09 19:13:18 +03:00
|
|
|
screenfull.toggle();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isFullscreen() {
|
|
|
|
|
return screenfull.isFullscreen;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 12:22:14 +02:00
|
|
|
goBack() {
|
|
|
|
|
this.window.history.back();
|
|
|
|
|
}
|
2019-12-12 19:55:17 +02:00
|
|
|
|
|
|
|
|
activeComponentChanged(activeComponent: any) {
|
2023-03-14 13:37:09 +02:00
|
|
|
this.activeComponentService.setCurrentActiveComponent(activeComponent);
|
2023-02-17 12:39:08 +02:00
|
|
|
if (!this.activeComponent) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.updateActiveComponent(activeComponent);
|
|
|
|
|
}, 0);
|
|
|
|
|
} else {
|
|
|
|
|
this.updateActiveComponent(activeComponent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updateActiveComponent(activeComponent: any) {
|
2019-12-12 19:55:17 +02:00
|
|
|
this.showSearch = false;
|
2024-01-23 11:20:36 +02:00
|
|
|
this.hideLoadingBar = false;
|
2023-08-14 13:30:24 +03:00
|
|
|
this.textSearch.reset('', {emitEvent: false});
|
2019-12-12 19:55:17 +02:00
|
|
|
this.activeComponent = activeComponent;
|
2024-01-23 11:20:36 +02:00
|
|
|
let showLoadingBar: boolean;
|
2024-02-05 12:57:22 +02:00
|
|
|
if (isDefined(this.activeComponent.activatedRoute?.snapshot?.data?.showMainLoadingBar)) {
|
|
|
|
|
showLoadingBar = this.activeComponent.activatedRoute.snapshot.data.showMainLoadingBar;
|
|
|
|
|
} else if (isDefined(this.activeComponent?.showMainLoadingBar)) {
|
|
|
|
|
showLoadingBar = this.activeComponent.showMainLoadingBar;
|
2024-01-23 11:20:36 +02:00
|
|
|
}
|
|
|
|
|
if (activeComponent && activeComponent instanceof RouterTabsComponent) {
|
|
|
|
|
this.hideLoadingBar = isDefinedAndNotNull(showLoadingBar) ? !showLoadingBar : true;
|
2024-02-05 12:57:22 +02:00
|
|
|
} else if (activeComponent && activeComponent instanceof PageComponent && isDefinedAndNotNull(showLoadingBar)) {
|
2024-01-23 11:20:36 +02:00
|
|
|
this.hideLoadingBar = !showLoadingBar;
|
|
|
|
|
}
|
2019-12-12 19:55:17 +02:00
|
|
|
if (this.activeComponent && instanceOfSearchableComponent(this.activeComponent)) {
|
|
|
|
|
this.searchEnabled = true;
|
|
|
|
|
this.searchableComponent = this.activeComponent;
|
|
|
|
|
} else {
|
|
|
|
|
this.searchEnabled = false;
|
|
|
|
|
this.searchableComponent = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
displaySearchMode(): boolean {
|
|
|
|
|
return this.searchEnabled && this.showSearch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openSearch() {
|
|
|
|
|
if (this.searchEnabled) {
|
|
|
|
|
this.showSearch = true;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.searchInputField.nativeElement.focus();
|
|
|
|
|
this.searchInputField.nativeElement.setSelectionRange(0, 0);
|
|
|
|
|
}, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeSearch() {
|
|
|
|
|
if (this.searchEnabled) {
|
|
|
|
|
this.showSearch = false;
|
2023-08-14 13:30:24 +03:00
|
|
|
if (this.textSearch.value.length) {
|
|
|
|
|
this.textSearch.reset();
|
2019-12-12 19:55:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 13:30:24 +03:00
|
|
|
private searchTextUpdated(searchText: string) {
|
2019-12-12 19:55:17 +02:00
|
|
|
if (this.searchableComponent) {
|
2023-08-15 11:42:18 +03:00
|
|
|
this.searchableComponent.onSearchTextUpdated(searchText);
|
2019-12-12 19:55:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-08-09 19:13:18 +03:00
|
|
|
}
|