Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added prototype for view service #438

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/app/auth/settings/account-settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
</div>
</div>
</div>
<div class="box p-4">
<mat-slide-toggle
(change)="adminSlideToggleChange($event)"
[(ngModel)]="adminPrivelegesOn"
color="primary"
class="mat-elevation-z0"
>
<span class="ps-2"> Admin priveleges</span>
</mat-slide-toggle>
</div>
</div>
<div
class="d-flex layout layout--flowRow-until-md layout--sidebar-position-start layout--sidebarPosition-flowRow-start"
Expand Down
16 changes: 16 additions & 0 deletions src/app/auth/settings/account-settings.component.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
@import "var";

:host {
::ng-deep {
.mat-slide-toggle {
.mat-slide-toggle-ripple {
position: relative;
}
}

.mdc-switch {
.mdc-switch__ripple {
display: none;
}
}
}
}

.p-responsive {
padding: 0 60px;

Expand Down
20 changes: 20 additions & 0 deletions src/app/auth/settings/account-settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { MaybeNull, MaybeUndefined } from "src/app/common/app.types";
import { Observable } from "rxjs";
import { LoggedUserService } from "../logged-user.service";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { MatSlideToggleChange } from "@angular/material/slide-toggle";
import { LocalStorageService } from "src/app/services/local-storage.service";

@Component({
selector: "app-settings",
Expand All @@ -23,12 +25,15 @@ export class AccountSettingsComponent extends BaseComponent implements OnInit {

public activeTab: AccountSettingsTabs = AccountSettingsTabs.PROFILE;
public user$: Observable<MaybeNull<AccountFragment>>;
public adminPrivelegesOn: boolean = false;
zaychenko-sergei marked this conversation as resolved.
Show resolved Hide resolved

private router = inject(Router);
private route = inject(ActivatedRoute);
private loggedUserService = inject(LoggedUserService);
private localStorageService = inject(LocalStorageService);

public ngOnInit(): void {
this.initAdminSlideToggle();
this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
Expand All @@ -46,6 +51,14 @@ export class AccountSettingsComponent extends BaseComponent implements OnInit {
return `/${ProjectLinks.URL_SETTINGS}/${tab}`;
}

public isAdmin(): boolean {
return this.loggedUserService.isAdmin;
}

public adminSlideToggleChange(event: MatSlideToggleChange): void {
this.localStorageService.setAdminPriveleges(event.checked);
}

private extractActiveTabFromRoute(): void {
const categoryParam: MaybeUndefined<string> = this.route.snapshot.params[
ProjectLinks.URL_PARAM_CATEGORY
Expand All @@ -61,4 +74,11 @@ export class AccountSettingsComponent extends BaseComponent implements OnInit {

this.activeTab = AccountSettingsTabs.PROFILE;
}

private initAdminSlideToggle(): void {
const flag = this.localStorageService.adminPriveleges;
if (flag) {
this.adminPrivelegesOn = flag;
}
}
}
2 changes: 2 additions & 0 deletions src/app/common/app.values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default class AppValues {
public static readonly LOCAL_STORAGE_LOGIN_CALLBACK_URL = "login_callback_url";
public static readonly LOCAL_STORAGE_LOGIN_REDIRECT_URL = "login_redirect_url";
public static readonly LOCAL_STORAGE_ACCOUNT_ID = "account_id";
public static readonly LOCAL_STORAGE_ADMIN_PRIVELEGES = "admin_priveleges";

public static readonly SESSION_STORAGE_SIDE_PANEL_VISIBLE = "side_panel_visible";
public static readonly DEFAULT_USER_DISPLAY_NAME = "anonymous";
public static readonly DEFAULT_AVATAR_URL = "https://avatars.githubusercontent.com/u/11951648?v=4";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
data-test-id="navigateToFlows"
value="flows"
[class.active-link]="isDatasetViewTypeFlows"
*ngIf="shouldAllowSettingsTab"
*ngIf="shouldAllowFlowsTab"
>
<a [routerLink]="[datasetLink]" [queryParams]="{ tab: DatasetViewTypeEnum.Flows }" class="menu-link">
<div class="d-flex align-items-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { DatasetViewTypeEnum } from "../dataset-view.interface";
import { SideNavHelper } from "../../common/sidenav.helper";
import { isMobileView, promiseWithCatch } from "src/app/common/app.helpers";
import { DatasetBasicsFragment, DatasetPermissionsFragment } from "src/app/api/kamu.graphql.interface";
import { DatasetPermissionsService } from "../dataset.permissions.service";
import { ElementsViewService, EnumViewActions } from "src/app/services/elements-view.service";

@Component({
selector: "app-dataset-view-menu",
Expand All @@ -36,7 +36,7 @@ export class DatasetViewMenuComponent implements OnInit, AfterViewInit {

private sideNavHelper: SideNavHelper;

private datasetPermissionsServices = inject(DatasetPermissionsService);
private elementsViewService = inject(ElementsViewService);
private widgetHeightService = inject(WidgetHeightService);

public ngAfterViewInit(): void {
Expand Down Expand Up @@ -85,7 +85,14 @@ export class DatasetViewMenuComponent implements OnInit, AfterViewInit {
}

public get shouldAllowSettingsTab(): boolean {
return this.datasetPermissionsServices.shouldAllowSettingsTab(this.datasetPermissions);
return this.elementsViewService.executeAction(
EnumViewActions.SHOW_SETTINGS_TAB_ACTION,
this.datasetPermissions,
);
}

public get shouldAllowFlowsTab(): boolean {
return this.elementsViewService.executeAction(EnumViewActions.SHOW_FLOWS_TAB_ACTION, this.datasetPermissions);
zaychenko-sergei marked this conversation as resolved.
Show resolved Hide resolved
}

public get datasetLink(): string {
Expand Down
10 changes: 6 additions & 4 deletions src/app/dataset-view/dataset.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { DatasetInfo } from "../interface/navigation.interface";
import { promiseWithCatch } from "../common/app.helpers";
import { DatasetRequestBySql } from "../interface/dataset.interface";
import { MaybeNull, MaybeUndefined } from "../common/app.types";
import { DatasetPermissionsService } from "./dataset.permissions.service";
import { ReplaySubject, Subject, of } from "rxjs";
import { LineageGraphNodeData, LineageGraphNodeKind } from "./additional-components/lineage-component/lineage-model";
import _ from "lodash";
import { BaseDatasetDataComponent } from "../common/base-dataset-data.component";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { ElementsViewService, EnumViewActions } from "../services/elements-view.service";

@Component({
selector: "app-dataset",
Expand All @@ -30,9 +30,9 @@ export class DatasetComponent extends BaseDatasetDataComponent implements OnInit

private mainDatasetQueryComplete$: Subject<DatasetInfo> = new ReplaySubject<DatasetInfo>(1 /* bufferSize */);

private datasetPermissionsServices = inject(DatasetPermissionsService);
private router = inject(Router);
private cdr = inject(ChangeDetectorRef);
private elementsViewService = inject(ElementsViewService);

public ngOnInit(): void {
const urlDatasetInfo = this.getDatasetInfoFromUrl();
Expand Down Expand Up @@ -123,7 +123,7 @@ export class DatasetComponent extends BaseDatasetDataComponent implements OnInit
takeUntilDestroyed(this.destroyRef),
)
.subscribe((datasetPermissions: DatasetPermissionsFragment) => {
if (this.datasetPermissionsServices.shouldAllowFlowsTab(datasetPermissions)) {
if (this.elementsViewService.executeAction(EnumViewActions.SHOW_FLOWS_TAB_ACTION, datasetPermissions)) {
this.datasetViewType = DatasetViewTypeEnum.Flows;
} else {
this.datasetViewType = DatasetViewTypeEnum.Overview;
Expand Down Expand Up @@ -197,7 +197,9 @@ export class DatasetComponent extends BaseDatasetDataComponent implements OnInit
takeUntilDestroyed(this.destroyRef),
)
.subscribe((datasetPermissions: DatasetPermissionsFragment) => {
if (this.datasetPermissionsServices.shouldAllowSettingsTab(datasetPermissions)) {
if (
this.elementsViewService.executeAction(EnumViewActions.SHOW_SETTINGS_TAB_ACTION, datasetPermissions)
) {
this.datasetViewType = DatasetViewTypeEnum.Settings;
} else {
this.datasetViewType = DatasetViewTypeEnum.Overview;
Expand Down
16 changes: 16 additions & 0 deletions src/app/services/elements-view.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { ElementsViewService } from './elements-view.service';

describe('ElementsViewService', () => {
let service: ElementsViewService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ElementsViewService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
35 changes: 35 additions & 0 deletions src/app/services/elements-view.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { LocalStorageService } from "src/app/services/local-storage.service";
import { inject, Injectable } from "@angular/core";
import { DatasetPermissionsFragment } from "../api/kamu.graphql.interface";
import { LoggedUserService } from "../auth/logged-user.service";
import { DatasetPermissionsService } from "../dataset-view/dataset.permissions.service";

@Injectable({
providedIn: "root",
})
export class ElementsViewService {
private loggedUserService = inject(LoggedUserService);
private datasetPermissionsService = inject(DatasetPermissionsService);
private localStorageService = inject(LocalStorageService);

private get isAdminPrivelegesOn(): boolean {
return this.loggedUserService.isAdmin && (this.localStorageService.adminPriveleges ?? false);
}

public executeAction(action: EnumViewActions, datasetPermissions: DatasetPermissionsFragment | null): boolean {
if (action === EnumViewActions.SHOW_FLOWS_TAB_ACTION && datasetPermissions) {
return this.isAdminPrivelegesOn || this.datasetPermissionsService.shouldAllowFlowsTab(datasetPermissions);
}
if (action === EnumViewActions.SHOW_SETTINGS_TAB_ACTION && datasetPermissions) {
return (
this.isAdminPrivelegesOn || this.datasetPermissionsService.shouldAllowSettingsTab(datasetPermissions)
);
zaychenko-sergei marked this conversation as resolved.
Show resolved Hide resolved
}
return false;
}
zaychenko-sergei marked this conversation as resolved.
Show resolved Hide resolved
}

export enum EnumViewActions {
SHOW_FLOWS_TAB_ACTION = "showFlowsTabAction",
SHOW_SETTINGS_TAB_ACTION = "showSettingsTabAction",
}
11 changes: 11 additions & 0 deletions src/app/services/local-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export class LocalStorageService {
return localStorage.getItem(AppValues.LOCAL_STORAGE_LOGIN_REDIRECT_URL);
}

public get adminPriveleges(): boolean | null {
const flag = localStorage.getItem(AppValues.LOCAL_STORAGE_ADMIN_PRIVELEGES);
if (flag) {
return Boolean(JSON.parse(flag));
} else return null;
}

public setAdminPriveleges(flag: boolean) {
localStorage.setItem(AppValues.LOCAL_STORAGE_ADMIN_PRIVELEGES, JSON.stringify(flag));
}

public setRedirectAfterLoginUrl(url: string | null) {
if (url) {
localStorage.setItem(AppValues.LOCAL_STORAGE_LOGIN_REDIRECT_URL, url);
Expand Down
Loading