[AAE-8201] - Add a way to hide libraries and secondary navbar sections (#2492)

* [AAE-8201] - Add a way to hide libraries and secondary navbar sections

* Add new variable

* Rename variable for toggling content service sections

* Fix lint errors

* Remove unnecessary or condition
This commit is contained in:
arditdomi
2022-04-06 14:20:10 +01:00
committed by GitHub
parent 9f0f4cc61f
commit bacd9e5c10
11 changed files with 137 additions and 4 deletions

View File

@@ -7,7 +7,8 @@
"authType": "${APP_CONFIG_AUTH_TYPE}",
"loginRoute": "login",
"plugins":{
"aosPlugin" : ${APP_CONFIG_PLUGIN_AOS}
"aosPlugin" : ${APP_CONFIG_PLUGIN_AOS},
"contentService": ${APP_CONFIG_CONTENT_SERVICE}
},
"oauth2": {
"host": "${APP_CONFIG_OAUTH2_HOST}",

View File

@@ -54,6 +54,7 @@ import { LanguagePickerComponent } from '../components/common/language-picker/la
import { LogoutComponent } from '../components/common/logout/logout.component';
import { AppExtensionService, ExtensionsDataLoaderGuard } from '@alfresco/aca-shared';
import { PreviewComponent } from '../components/preview/preview.component';
import { ContentServiceExtensionService } from '../services/content-service-extension.service';
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export function setupExtensions(service: AppExtensionService): () => void {
@@ -71,7 +72,7 @@ export class CoreExtensionsModule {
{
provide: APP_INITIALIZER,
useFactory: setupExtensions,
deps: [AppExtensionService],
deps: [AppExtensionService, ContentServiceExtensionService],
multi: true
}
]
@@ -181,7 +182,8 @@ export class CoreExtensionsModule {
'repository.isQuickShareEnabled': rules.hasQuickShareEnabled,
'user.isAdmin': rules.isAdmin,
'app.canShowLogout': rules.canShowLogout
'app.canShowLogout': rules.canShowLogout,
'app.isContentServiceEnabled': rules.isContentServiceEnabled
});
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright © 2005 - 2021 Alfresco Software, Ltd. All rights reserved.
*
* License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an
* agreement is prohibited.
*/
import { ContentServiceExtensionService } from './content-service-extension.service';
import { AppConfigService, AppConfigServiceMock, setupTestBed } from '@alfresco/adf-core';
import { TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { HttpClientModule } from '@angular/common/http';
describe('ContentServiceExtensionService', () => {
let service: ContentServiceExtensionService;
let appConfig: AppConfigService;
setupTestBed({
imports: [HttpClientModule],
providers: [{ provide: AppConfigService, useClass: AppConfigServiceMock }]
});
beforeEach(() => {
service = TestBed.inject(ContentServiceExtensionService);
appConfig = TestBed.inject(AppConfigService);
appConfig.config = Object.assign(appConfig.config, {
plugins: {
contentService: true
}
});
appConfig.load();
appConfig.onLoad = of(appConfig.config);
});
it('should set the content service to true when it is false in local storage and enabled in the app config', () => {
localStorage.setItem('contentService', 'false');
service.updateContentServiceAvailability();
expect(localStorage.getItem('contentService')).toEqual('true');
});
it('should set the content service to false in local storage when it is false in the app config', () => {
appConfig.config.plugins.contentService = false;
appConfig.load();
appConfig.onLoad = of(appConfig.config);
service.updateContentServiceAvailability();
expect(localStorage.getItem('contentService')).toEqual('false');
});
afterEach(() => {
localStorage.clear();
});
});

View File

@@ -0,0 +1,42 @@
/*
* Copyright © 2005 - 2021 Alfresco Software, Ltd. All rights reserved.
*
* License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an
* agreement is prohibited.
*/
import { Injectable } from '@angular/core';
import { AppConfigService } from '@alfresco/adf-core';
import { take } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class ContentServiceExtensionService {
constructor(private appConfigService: AppConfigService) {
this.updateContentServiceAvailability();
}
updateContentServiceAvailability() {
this.appConfigService.onLoad.pipe(take(1)).subscribe((config) => {
if (config.plugins && config.plugins.contentService === false) {
this.disableContentServices();
} else {
this.enableContentServices();
}
});
}
private disableContentServices() {
if (localStorage) {
localStorage.setItem('contentService', 'false');
}
}
private enableContentServices() {
if (localStorage && localStorage.getItem('contentService') === 'false') {
localStorage.setItem('contentService', 'true');
}
}
}

View File

@@ -241,6 +241,9 @@
"icon": "library_books",
"title": "APP.BROWSE.LIBRARIES.SIDENAV_LINK.LABEL",
"description": "APP.BROWSE.LIBRARIES.SIDENAV_LINK.TOOLTIP",
"rules": {
"visible": "app.isContentServiceEnabled"
},
"children": [
{
"id": "app.navbar.libraries.favorite",
@@ -262,6 +265,9 @@
},
{
"id": "app.navbar.secondary",
"rules": {
"visible": "app.isContentServiceEnabled"
},
"items": [
{
"id": "app.navbar.shared",