]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/stateful-tab.directive.ts
cf6f27e9592d473073ef838b974f2233ba46908b
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / directives / stateful-tab.directive.ts
1 import { Directive, Host, HostListener, Input, OnInit, Optional } from '@angular/core';
2
3 import { NgbNav, NgbNavChangeEvent } from '@ng-bootstrap/ng-bootstrap';
4
5 @Directive({
6 selector: '[cdStatefulTab]'
7 })
8 export class StatefulTabDirective implements OnInit {
9 @Input()
10 cdStatefulTab: string;
11
12 private localStorage = window.localStorage;
13
14 constructor(@Optional() @Host() private nav: NgbNav) {}
15
16 ngOnInit() {
17 // Is an activate tab identifier stored in the local storage?
18 const activeId = this.localStorage.getItem(`tabset_${this.cdStatefulTab}`);
19 if (activeId) {
20 this.nav.select(activeId);
21 }
22 }
23
24 @HostListener('navChange', ['$event'])
25 onNavChange(event: NgbNavChangeEvent) {
26 // Store the current active tab identifier in the local storage.
27 if (this.cdStatefulTab && event.nextId) {
28 this.localStorage.setItem(`tabset_${this.cdStatefulTab}`, event.nextId);
29 }
30 }
31 }