OpenSlides/client/src/app/core/services/main-menu.service.ts

62 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
/**
* This represents one entry in the main menu
*/
export interface MainMenuEntry {
/**
* The route for the router to navigate to on click.
*/
route: string;
/**
* The display string to be shown.
*/
displayName: string;
/**
* The font awesom icon to display.
*/
icon: string;
/**
* For sorting the entries.
*/
weight: number;
/**
* The permission to see the entry.
*/
permission: string;
}
/**
* Collects main menu entries and provides them to the main menu component.
*/
@Injectable({
providedIn: 'root'
})
export class MainMenuService {
/**
* A list of sorted entries.
*/
private _entries: MainMenuEntry[] = [];
/**
* Make the entries public.
*/
public get entries(): MainMenuEntry[] {
return this._entries;
}
public constructor() {}
/**
* Adds entries to the mainmenu.
* @param entries The entries to add
*/
public registerEntries(entries: MainMenuEntry[]): void {
this._entries.push(...entries);
this._entries = this._entries.sort((a, b) => a.weight - b.weight);
}
}