import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { FeatureFlagService } from './feature-flag.service'; export interface IFeatureFlagViewItem { name: string; local: boolean; master: boolean; isLocalLocked: boolean; } @Component({ templateUrl: './feature-flag.component.html', styleUrls: ['./feature-flag.component.scss'] }) export class FeatureFlagViewComponent implements OnInit { flags: IFeatureFlagViewItem[] = []; private readonly ENABLE_FF_MANAGER_KEY: string = 'ffManager'; constructor(private router: Router, private ffService: FeatureFlagService) {} ngOnInit() { if (!localStorage.getItem(this.ENABLE_FF_MANAGER_KEY)) { this.router.navigate(['']); } for (const flagName in this.ffService) { if (typeof this.ffService[flagName] === 'boolean') { const masterFlag = this.ffService.getMasterFlag(flagName); const localFlag = this.ffService.getLocalFlag(flagName); if (typeof localFlag === 'boolean') { this.flags.push({ name: flagName, local: this.ffService[flagName], master: masterFlag, isLocalLocked: true }); } else { this.flags.push({ name: flagName, local: this.ffService[flagName], master: masterFlag, isLocalLocked: false }); } } } } toggleFlag(flag: IFeatureFlagViewItem) { if (!flag.isLocalLocked) { return; } flag.local = !flag.local; this.ffService.setLocalFlag(flag.name, flag.local); } toggleLock(flag: IFeatureFlagViewItem) { if (flag.isLocalLocked) { flag.local = flag.master; flag.isLocalLocked = false; this.ffService.removeLocalFlag(flag.name); } else { this.ffService.setLocalFlag(flag.name, flag.local); flag.isLocalLocked = true; } } }