blob: 033df494e8a7ce449a6d99d5c70b3aeb22487750 [file] [log] [blame]
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {EventType, PluginApi} from '../../../api/plugin';
import {AdminPluginApi, MenuLink} from '../../../api/admin';
import {ReportingService} from '../../../services/gr-reporting/gr-reporting';
/**
* GrAdminApi class.
*
* Defines common methods to register / retrieve menu links.
*/
export class GrAdminApi implements AdminPluginApi {
// TODO(TS): maybe define as enum if its a limited set
private menuLinks: MenuLink[] = [];
constructor(
private readonly reporting: ReportingService,
private readonly plugin: PluginApi
) {
this.reporting.trackApi(this.plugin, 'admin', 'constructor');
this.plugin.on(EventType.ADMIN_MENU_LINKS, this);
}
addMenuLink(text: string, url: string, capability?: string) {
this.reporting.trackApi(this.plugin, 'admin', 'addMenuLink');
this.menuLinks.push({text, url, capability: capability || null});
}
getMenuLinks(): MenuLink[] {
this.reporting.trackApi(this.plugin, 'admin', 'getMenuLinks');
return this.menuLinks.slice(0);
}
}