2021-02-13 10:22:04 +00:00
|
|
|
import { AfterViewInit, Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
2020-01-27 18:40:18 +00:00
|
|
|
import { Events, MessageBus } from 'protocol';
|
2020-02-04 15:34:34 +00:00
|
|
|
import { DirectiveExplorerComponent } from './directive-explorer/directive-explorer.component';
|
2020-04-02 23:23:03 +00:00
|
|
|
import { ApplicationEnvironment } from '../application-environment';
|
2020-05-07 03:21:32 +00:00
|
|
|
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
|
2020-05-08 22:12:17 +00:00
|
|
|
import { TabUpdate } from './tab-update';
|
2020-08-08 20:43:42 +00:00
|
|
|
import { Theme, ThemeService } from '../theme-service';
|
|
|
|
|
import { Subscription } from 'rxjs';
|
2021-02-13 10:22:04 +00:00
|
|
|
import { MatTabNav } from '@angular/material/tabs';
|
2021-02-07 13:15:42 +00:00
|
|
|
import { RouterTreeComponent } from './router-tree/router-tree.component';
|
|
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
|
import { RouterConfirmDialogComponent } from './router-tree/router-confirm-dialog/router-confirm-dialog.component';
|
2020-01-27 18:40:18 +00:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ng-devtools-tabs',
|
|
|
|
|
templateUrl: './devtools-tabs.component.html',
|
2020-03-29 03:28:36 +00:00
|
|
|
styleUrls: ['./devtools-tabs.component.scss'],
|
2020-01-27 18:40:18 +00:00
|
|
|
})
|
2021-02-13 10:22:04 +00:00
|
|
|
export class DevToolsTabsComponent implements OnInit, OnDestroy, AfterViewInit {
|
2020-01-29 17:10:57 +00:00
|
|
|
@Input() angularVersion: string | undefined = undefined;
|
2020-02-06 22:41:19 +00:00
|
|
|
@ViewChild(DirectiveExplorerComponent) directiveExplorer: DirectiveExplorerComponent;
|
2021-02-13 10:22:04 +00:00
|
|
|
@ViewChild('navBar', { static: true }) navbar: MatTabNav;
|
2021-02-07 13:15:42 +00:00
|
|
|
@ViewChild('routerTree', { static: false }) routerTree: RouterTreeComponent;
|
2021-02-13 10:22:04 +00:00
|
|
|
|
|
|
|
|
tabs = ['Components', 'Profiler'];
|
2021-02-07 13:15:42 +00:00
|
|
|
activeTab: 'Components' | 'Profiler' | 'Router Tree' = 'Components';
|
2020-01-27 18:40:18 +00:00
|
|
|
|
2020-08-08 20:43:42 +00:00
|
|
|
inspectorRunning = false;
|
2021-02-07 13:15:42 +00:00
|
|
|
routerTreeEnabled = false;
|
2020-08-08 20:43:42 +00:00
|
|
|
|
|
|
|
|
private _currentThemeSubscription: Subscription;
|
|
|
|
|
currentTheme: Theme;
|
|
|
|
|
|
2020-05-08 22:12:17 +00:00
|
|
|
constructor(
|
|
|
|
|
public tabUpdate: TabUpdate,
|
2020-06-02 16:11:15 +00:00
|
|
|
public themeService: ThemeService,
|
2020-05-08 22:12:17 +00:00
|
|
|
private _messageBus: MessageBus<Events>,
|
2021-02-07 13:15:42 +00:00
|
|
|
private _applicationEnvironment: ApplicationEnvironment,
|
|
|
|
|
private _dialog: MatDialog
|
2020-05-08 22:12:17 +00:00
|
|
|
) {}
|
2020-04-02 23:23:03 +00:00
|
|
|
|
2020-08-08 20:43:42 +00:00
|
|
|
ngOnInit(): void {
|
|
|
|
|
this._currentThemeSubscription = this.themeService.currentTheme.subscribe((theme) => (this.currentTheme = theme));
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-13 10:22:04 +00:00
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
this.navbar.disablePagination = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 20:43:42 +00:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
this._currentThemeSubscription.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 23:23:03 +00:00
|
|
|
get latestSHA(): string {
|
|
|
|
|
return this._applicationEnvironment.environment.process.env.LATEST_SHA;
|
|
|
|
|
}
|
2020-03-18 00:48:29 +00:00
|
|
|
|
2021-02-07 13:15:42 +00:00
|
|
|
onTabChange(tab: 'Profiler' | 'Components' | 'Router Tree'): void {
|
2021-02-13 10:22:04 +00:00
|
|
|
this.activeTab = tab;
|
|
|
|
|
this.tabUpdate.notify();
|
2021-02-07 13:15:42 +00:00
|
|
|
if (tab === 'Router Tree') {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.routerTree.render();
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-02-13 10:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-29 00:29:23 +00:00
|
|
|
toggleInspector(): void {
|
2020-02-06 22:41:19 +00:00
|
|
|
this.toggleInspectorState();
|
|
|
|
|
this.emitInspectorEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emitInspectorEvent(): void {
|
2020-01-27 18:40:18 +00:00
|
|
|
if (this.inspectorRunning) {
|
2020-03-18 00:48:29 +00:00
|
|
|
this._messageBus.emit('inspectorStart');
|
2021-02-13 10:22:04 +00:00
|
|
|
this.activeTab = 'Components';
|
2020-01-27 18:40:18 +00:00
|
|
|
} else {
|
2020-03-18 00:48:29 +00:00
|
|
|
this._messageBus.emit('inspectorEnd');
|
2020-04-14 22:27:59 +00:00
|
|
|
this._messageBus.emit('removeHighlightOverlay');
|
2020-01-27 18:40:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 22:41:19 +00:00
|
|
|
toggleInspectorState(): void {
|
|
|
|
|
this.inspectorRunning = !this.inspectorRunning;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-29 00:29:23 +00:00
|
|
|
refresh(): void {
|
2020-02-06 22:41:19 +00:00
|
|
|
this.directiveExplorer.refresh();
|
2020-01-27 18:40:18 +00:00
|
|
|
}
|
2020-05-07 03:21:32 +00:00
|
|
|
|
|
|
|
|
toggleTimingAPI(change: MatSlideToggleChange): void {
|
|
|
|
|
change.checked ? this._messageBus.emit('enableTimingAPI') : this._messageBus.emit('disableTimingAPI');
|
|
|
|
|
}
|
2021-02-07 13:15:42 +00:00
|
|
|
|
|
|
|
|
toggleRouterTree(change: MatSlideToggleChange): void {
|
|
|
|
|
if (change.checked) {
|
|
|
|
|
this.tabs = ['Components', 'Profiler', 'Router Tree'];
|
|
|
|
|
this.routerTreeEnabled = true;
|
|
|
|
|
} else {
|
|
|
|
|
if (this.activeTab === 'Router Tree') {
|
|
|
|
|
const dialogRef = this._dialog.open(RouterConfirmDialogComponent);
|
|
|
|
|
dialogRef.afterClosed().subscribe((result) => {
|
|
|
|
|
if (result) {
|
|
|
|
|
this.routerTreeEnabled = false;
|
|
|
|
|
this.tabs = ['Components', 'Profiler'];
|
|
|
|
|
this.activeTab = 'Components';
|
|
|
|
|
} else {
|
|
|
|
|
this.routerTreeEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.routerTreeEnabled = false;
|
|
|
|
|
this.tabs = ['Components', 'Profiler'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-27 18:40:18 +00:00
|
|
|
}
|