/*
* 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 {Component, EventEmitter, Input, Output} from '@angular/core';
import {assertDefined} from 'common/assert_utils';
import {
EnableConfiguration,
SelectionConfiguration,
TraceConfiguration,
TraceConfigurationMap,
} from 'trace_collection/trace_collection_utils';
@Component({
selector: 'trace-config',
template: `
Trace targets
{{ this.traceConfig[traceKey].name }}
{{ this.traceConfig[traceKey].name }} configuration
0"
class="enable-config-opt">
{{ enableConfig.name }}
0"
class="selection-config-opt">
{{ selectionConfig.name }}
{{
option
}}
`,
styles: [
`
.checkboxes {
display: grid;
grid-template-columns: repeat(3, 1fr);
column-gap: 10px;
}
.enable-config-opt,
.selection-config-opt {
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 10px;
}
`,
],
})
export class TraceConfigComponent {
objectKeys = Object.keys;
@Input() traceConfig: TraceConfigurationMap | undefined;
@Output() readonly traceConfigChange =
new EventEmitter();
advancedConfigTraces() {
const advancedConfigs: string[] = [];
Object.keys(assertDefined(this.traceConfig)).forEach((traceKey: string) => {
if (assertDefined(this.traceConfig)[traceKey].config) {
advancedConfigs.push(traceKey);
}
});
return advancedConfigs;
}
traceEnableConfigs(trace: TraceConfiguration): EnableConfiguration[] {
if (trace.config) {
return trace.config.enableConfigs;
} else {
return [];
}
}
traceSelectionConfigs(trace: TraceConfiguration): SelectionConfiguration[] {
if (trace.config) {
return trace.config.selectionConfigs;
} else {
return [];
}
}
someTraces(trace: TraceConfiguration): boolean {
return (
!trace.run &&
this.traceEnableConfigs(trace).filter((trace) => trace.enabled).length > 0
);
}
changeRunTrace(run: boolean, trace: TraceConfiguration): void {
trace.run = run;
}
}