/* * Copyright (C) 2022 The Android Open Source Project * * 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 {CdkVirtualScrollViewport} from '@angular/cdk/scrolling'; import {Component, ElementRef, Inject, Input, ViewChild} from '@angular/core'; import {MatSelectChange} from '@angular/material/select'; import {Events} from './events'; import {UiData} from './ui_data'; @Component({ selector: 'viewer-protolog', template: `
Log level {{ level }}
Tags {{ tag }}
Source files {{ file }}
Search text
{{ message.time }}
{{ message.level }}
{{ message.tag }}
{{ message.at }}
{{ message.text }}
`, styles: [ ` .container { padding: 16px; box-sizing: border-box; display: flex; flex-direction: column; } .filters { display: flex; flex-direction: row; margin-top: 16px; } .scroll-messages { height: 100%; flex: 1; } .message { display: flex; flex-direction: row; overflow-wrap: anywhere; } .message.current-message { background-color: #365179; color: white; } .time { flex: 2; } .log-level { flex: 1; } .filters .log-level { flex: 3; } .tag { flex: 2; } .source-file { flex: 4; } .text { flex: 10; } .filters div { margin: 4px; } .message div { margin: 4px; } mat-form-field { width: 100%; } `, ], }) export class ViewerProtologComponent { constructor(@Inject(ElementRef) elementRef: ElementRef) { this.elementRef = elementRef; } @Input() set inputData(data: UiData) { this.uiData = data; if (this.uiData.currentMessageIndex !== undefined && this.scrollComponent) { this.scrollComponent.scrollToIndex(this.uiData.currentMessageIndex); } } onLogLevelsChange(event: MatSelectChange) { this.emitEvent(Events.LogLevelsFilterChanged, event.value); } onTagsChange(event: MatSelectChange) { this.emitEvent(Events.TagsFilterChanged, event.value); } onSourceFilesChange(event: MatSelectChange) { this.emitEvent(Events.SourceFilesFilterChanged, event.value); } onSearchStringChange() { this.emitEvent(Events.SearchStringFilterChanged, this.searchString); } isCurrentMessage(index: number): boolean { return index === this.uiData.currentMessageIndex; } private emitEvent(event: string, data: any) { const customEvent = new CustomEvent(event, { bubbles: true, detail: data, }); this.elementRef.nativeElement.dispatchEvent(customEvent); } @ViewChild(CdkVirtualScrollViewport) scrollComponent!: CdkVirtualScrollViewport; uiData: UiData = UiData.EMPTY; private searchString = ''; private elementRef: ElementRef; }