Skip to content

Commit

Permalink
refactor service
Browse files Browse the repository at this point in the history
  • Loading branch information
ntqdinh-axonivy committed Jul 23, 2024
1 parent 59a5c1f commit bf1e43f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions marketplace-ui/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@if(!isDesignerViewer()){
@if(!cookieManagementService.isDesignerEnv()){
<header class="d-flex align-items-center">
<div class="container">
<app-header></app-header>
Expand All @@ -10,7 +10,7 @@
<router-outlet />
</div>
</main>
@if(!isDesignerViewer()){
@if(!cookieManagementService.isDesignerEnv()){
<footer>
<div class="container">
<app-footer></app-footer>
Expand Down
16 changes: 5 additions & 11 deletions marketplace-ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Component, inject, signal } from '@angular/core';
import { Component, inject } from '@angular/core';
import {
RouterOutlet,
ActivatedRoute,
Router,
NavigationEnd,
ActivatedRoute
} from '@angular/router';
import { FooterComponent } from './shared/components/footer/footer.component';
import { HeaderComponent } from './shared/components/header/header.component';
Expand All @@ -19,21 +17,17 @@ import { CookieManagementService } from './cookie.management.service';
})
export class AppComponent {
loadingService = inject(LoadingService);
isDesignerViewer = signal(false);
cookieManagementService = inject( CookieManagementService);

constructor(
private router: Router,
private route: ActivatedRoute,
private readonly cookieManagementService: CookieManagementService
) { }

ngOnInit(): void {
this.cookieManagementService.getNavigationEndEvents().subscribe(() => {
if (this.cookieManagementService.isBrowserHaveDesignerEnvCookie()) {
this.isDesignerViewer.set(true);
} else {
if (!this.cookieManagementService.isDesignerEnv()) {
this.route.queryParams.subscribe(params => {
this.cookieManagementService.checkCookieForDesignerEnv(params, this.isDesignerViewer);
this.cookieManagementService.checkCookieForDesignerEnv(params);
this.cookieManagementService.checkCookieForDesignerVersion(params);
})
}
Expand Down
14 changes: 9 additions & 5 deletions marketplace-ui/src/app/cookie.management.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { Injectable, signal } from '@angular/core';
import { Injectable, Signal, signal } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
import { DESIGNER_COOKIE_VARIABLE } from './shared/constants/common.constant';
import {
Expand All @@ -13,6 +13,7 @@ import { filter } from 'rxjs/operators';
providedIn: 'root'
})
export class CookieManagementService {
private isDesigner = signal(false);
constructor(private cookieService: CookieService, private router: Router) { }

checkCookieForDesignerVersion(params: Params) {
Expand All @@ -22,16 +23,19 @@ export class CookieManagementService {
}
}

checkCookieForDesignerEnv(params: Params, isDesignerViewerSignal: any) {
checkCookieForDesignerEnv(params: Params) {
const ivyViewerParam = params[DESIGNER_COOKIE_VARIABLE.ivyViewerParamName];
if (ivyViewerParam == DESIGNER_COOKIE_VARIABLE.defaultDesignerViewer) {
this.cookieService.set(DESIGNER_COOKIE_VARIABLE.ivyViewerParamName, ivyViewerParam);
isDesignerViewerSignal.set(true);
this.isDesigner.set(true);
}
}

isBrowserHaveDesignerEnvCookie() {
return this.cookieService.get(DESIGNER_COOKIE_VARIABLE.ivyViewerParamName) == DESIGNER_COOKIE_VARIABLE.defaultDesignerViewer;
isDesignerEnv() {
if(!this.isDesigner()) {
this.isDesigner.set(this.cookieService.get(DESIGNER_COOKIE_VARIABLE.ivyViewerParamName) == DESIGNER_COOKIE_VARIABLE.defaultDesignerViewer);
}
return this.isDesigner();
}

getNavigationEndEvents(): Observable<NavigationEnd> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ProductDetailVersionActionComponent implements AfterViewInit {
tooltipTriggerList.forEach(
tooltipTriggerEl => new Tooltip(tooltipTriggerEl)
);
this.isDesignerEnvironment.set(this.cookieService.isBrowserHaveDesignerEnvCookie());
this.isDesignerEnvironment.set(this.cookieService.isDesignerEnv());
}

onShowVersions() {
Expand Down

0 comments on commit bf1e43f

Please sign in to comment.