ACS-8404: Introduce App Settings service (#3939)

This commit is contained in:
Denys Vuika
2024-07-16 15:23:13 -04:00
committed by GitHub
parent cbbb733551
commit 32112392c6
14 changed files with 324 additions and 880 deletions
@@ -24,11 +24,11 @@
import { Component, inject, OnInit, ViewEncapsulation } from '@angular/core';
import { DEV_MODE_TOKEN } from './dev-mode.tokens';
import { AboutModule, AppConfigService, AuthenticationService, RepositoryInfo } from '@alfresco/adf-core';
import { AboutModule, AuthenticationService, RepositoryInfo } from '@alfresco/adf-core';
import { DiscoveryApiService } from '@alfresco/adf-content-services';
import { PACKAGE_JSON } from './package-json.token';
import { TranslateModule } from '@ngx-translate/core';
import { AppExtensionService, PageLayoutComponent } from '@alfresco/aca-shared';
import { AppExtensionService, AppSettingsService, PageLayoutComponent } from '@alfresco/aca-shared';
import { RouterModule } from '@angular/router';
import { MatIconModule } from '@angular/material/icon';
import { CommonModule } from '@angular/common';
@@ -45,14 +45,14 @@ import { MatButtonModule } from '@angular/material/button';
export class AboutComponent implements OnInit {
private authService = inject(AuthenticationService);
private appExtensions = inject(AppExtensionService);
private appSettings = inject(AppSettingsService);
private discovery = inject(DiscoveryApiService);
private appConfigService = inject(AppConfigService);
public packageJson? = inject(PACKAGE_JSON, { optional: true });
public dev = inject(DEV_MODE_TOKEN);
extensions$ = this.appExtensions.references$;
repository: RepositoryInfo = null;
landingPage = this.appConfigService.get('landingPage', '/personal-files');
landingPage = this.appSettings.landingPage;
ngOnInit(): void {
if (this.authService.isEcmLoggedIn()) {
@@ -1,28 +0,0 @@
/*!
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
export interface MimeType {
label: string;
value: string;
}
@@ -28,7 +28,6 @@ import { CoreTestingModule } from '@alfresco/adf-core';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { tagMock, mimeTypeMock, simpleConditionUnknownFieldMock, categoriesListMock } from '../../mock/conditions.mock';
import { MimeType } from './rule-mime-types';
import { CategoryService, TagService } from '@alfresco/adf-content-services';
import { of } from 'rxjs';
import { RuleSimpleCondition } from '../../model/rule-simple-condition.model';
@@ -38,6 +37,7 @@ import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatSelectHarness } from '@angular/material/select/testing';
import { MatAutocompleteHarness } from '@angular/material/autocomplete/testing';
import { AlfrescoMimeType } from '@alfresco/aca-shared';
describe('RuleSimpleConditionUiComponent', () => {
let fixture: ComponentFixture<RuleSimpleConditionUiComponent>;
@@ -100,7 +100,7 @@ describe('RuleSimpleConditionUiComponent', () => {
});
it('should hide the comparator select box if the type of the field is mimeType', async () => {
fixture.componentInstance.mimeTypes = [{ value: '', label: '' } as MimeType];
fixture.componentInstance.mimeTypes = [{ value: '', label: '' } as AlfrescoMimeType];
fixture.detectChanges();
const comparatorFormField = getByDataAutomationId('comparator-form-field').nativeElement;
@@ -152,7 +152,7 @@ describe('RuleSimpleConditionUiComponent', () => {
});
it('should provide select option when mimeType is selected and value filled', () => {
const mockMimeTypes: MimeType[] = [
const mockMimeTypes: AlfrescoMimeType[] = [
{
value: 'video/3gpp',
label: '3G Video'
@@ -22,13 +22,11 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, forwardRef, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, forwardRef, inject, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { AbstractControl, ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
import { RuleSimpleCondition } from '../../model/rule-simple-condition.model';
import { comparatorHiddenForConditionFieldType, RuleConditionField, ruleConditionFields } from './rule-condition-fields';
import { RuleConditionComparator, ruleConditionComparators } from './rule-condition-comparators';
import { AppConfigService } from '@alfresco/adf-core';
import { MimeType } from './rule-mime-types';
import { AsyncPipe, CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { MatFormFieldModule } from '@angular/material/form-field';
@@ -41,6 +39,7 @@ import { Subject, Subscription } from 'rxjs';
import { MatOptionModule } from '@angular/material/core';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { CategoryEntry } from '@alfresco/js-api';
import { AlfrescoMimeType, AppSettingsService } from '@alfresco/aca-shared';
interface AutoCompleteOption {
displayLabel: string;
@@ -77,21 +76,24 @@ const AUTOCOMPLETE_OPTIONS_DEBOUNCE_TIME = 500;
]
})
export class RuleSimpleConditionUiComponent implements OnInit, ControlValueAccessor, OnDestroy {
private appSettings = inject(AppSettingsService);
private categoryService = inject(CategoryService);
private tagService = inject(TagService);
form = new FormGroup({
field: new FormControl('cm:name'),
comparator: new FormControl('equals'),
parameter: new FormControl()
});
mimeTypes: MimeType[] = [];
mimeTypes: AlfrescoMimeType[] = [];
autoCompleteOptions: AutoCompleteOption[] = [];
showLoadingSpinner: boolean;
private onDestroy$ = new Subject<void>();
private autoCompleteOptionsSubscription: Subscription;
private _readOnly = false;
@Input()
get readOnly(): boolean {
return this._readOnly;
@@ -107,9 +109,10 @@ export class RuleSimpleConditionUiComponent implements OnInit, ControlValueAcces
(condition) => !((this.disabledTags && condition.name === 'tag') || (this.disabledCategories && condition.name === 'category'))
);
constructor(config: AppConfigService, private categoryService: CategoryService, private tagService: TagService) {
this.mimeTypes = config.get<Array<MimeType>>('mimeTypes');
constructor() {
this.mimeTypes = this.appSettings.mimeTypes;
}
get isSelectedFieldKnown(): boolean {
const selectedFieldName = this.form.get('field').value;
return this.fields.findIndex((field: RuleConditionField) => selectedFieldName === field.name) > -1;
@@ -24,7 +24,7 @@
import { TestBed } from '@angular/core/testing';
import { AosEditOnlineService } from './aos-extension.service';
import { AppConfigService, AuthenticationService, AuthModule, LogService, NotificationService } from '@alfresco/adf-core';
import { AppConfigService, AuthenticationService, AuthModule, NotificationService } from '@alfresco/adf-core';
import { LibTestingModule } from '@alfresco/aca-shared';
import { MatSnackBarModule } from '@angular/material/snack-bar';
@@ -37,8 +37,7 @@ describe('AosEditOnlineService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [LibTestingModule, MatSnackBarModule, AuthModule.forRoot()],
providers: [{ provide: LogService, useValue: { error() {} } }]
imports: [LibTestingModule, MatSnackBarModule, AuthModule.forRoot()]
});
aosEditOnlineService = TestBed.inject(AosEditOnlineService);
@@ -23,10 +23,11 @@
*/
/* cspell:disable */
import { AppConfigService, AuthenticationService, LogService, NotificationService } from '@alfresco/adf-core';
import { AuthenticationService, NotificationService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { getFileExtension, supportedExtensions } from '@alfresco/aca-shared/rules';
import { AppSettingsService } from '@alfresco/aca-shared';
export interface IAosEditOnlineService {
onActionEditOnlineAos(node: Node): void;
@@ -38,9 +39,8 @@ export interface IAosEditOnlineService {
export class AosEditOnlineService implements IAosEditOnlineService {
constructor(
private authenticationService: AuthenticationService,
private appConfigService: AppConfigService,
private notificationService: NotificationService,
private logService: LogService
private appSettings: AppSettingsService,
private notificationService: NotificationService
) {}
onActionEditOnlineAos(node: Node): void {
@@ -77,7 +77,6 @@ export class AosEditOnlineService implements IAosEditOnlineService {
}
private onAlreadyLockedNotification(nodeId: string, lockOwner: string) {
this.logService.error('Document already locked by another user');
this.notificationService.showError(`AOS.ERRORS.ALREADY_LOCKED`, null, {
nodeId,
lockOwner
@@ -89,7 +88,7 @@ export class AosEditOnlineService implements IAosEditOnlineService {
}
private triggerEditOnlineAos(node: Node): void {
const aosHost = this.appConfigService.get('aosHost');
const aosHost = this.appSettings.aosHost;
let url: string;
const pathElements = (node.path?.elements || []).map((segment) => segment.name);
@@ -110,13 +109,11 @@ export class AosEditOnlineService implements IAosEditOnlineService {
const protocolHandler = this.getProtocolForFileExtension(fileExtension);
if (protocolHandler === undefined) {
this.logService.error('Protocol handler missing');
this.notificationService.showError(`AOS.ERRORS.MISSING_PROTOCOL_HANDLER`, null, { nodeName: node.name });
return;
}
if (!this.isWindows() && !this.isMacOs()) {
this.logService.error('Unsupported platform');
this.notificationService.showError('AOS.ERRORS.UNSUPPORTED_PLATFORM');
} else {
this.openByUrl(protocolHandler, url);
@@ -23,28 +23,26 @@
*/
import { HomeComponent } from './home.component';
import { AppConfigService, AppConfigServiceMock } from '@alfresco/adf-core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import { RouterTestingModule } from '@angular/router/testing';
import { AppSettingsService } from '@alfresco/aca-shared';
describe('HomeComponent', () => {
let appConfig: AppConfigService;
let appSettings: AppSettingsService;
let fixture: ComponentFixture<HomeComponent>;
let router: Router;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientModule, RouterTestingModule, HomeComponent],
providers: [{ provide: AppConfigService, useClass: AppConfigServiceMock }]
imports: [HttpClientModule, RouterTestingModule, HomeComponent]
});
appSettings = TestBed.inject(AppSettingsService);
spyOnProperty(appSettings, 'landingPage', 'get').and.returnValue('/my-mock-landing-page');
fixture = TestBed.createComponent(HomeComponent);
router = TestBed.inject(Router);
appConfig = TestBed.inject(AppConfigService);
appConfig.config = Object.assign(appConfig.config, {
landingPage: '/my-mock-landing-page'
});
});
it('should navigate to the landing page from the app config', () => {
@@ -53,12 +51,4 @@ describe('HomeComponent', () => {
expect(navigateSpy).toHaveBeenCalledWith('/my-mock-landing-page');
});
it('should navigate to personal files by default when there is no landingPage defined', () => {
appConfig.config = {};
const navigateSpy = spyOn(router, 'navigateByUrl');
fixture.detectChanges();
expect(navigateSpy).toHaveBeenCalledWith('/personal-files');
});
});
@@ -22,9 +22,9 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, inject, OnInit, ViewEncapsulation } from '@angular/core';
import { Router } from '@angular/router';
import { AppConfigService } from '@alfresco/adf-core';
import { AppSettingsService } from '@alfresco/aca-shared';
@Component({
standalone: true,
@@ -32,12 +32,10 @@ import { AppConfigService } from '@alfresco/adf-core';
encapsulation: ViewEncapsulation.None
})
export class HomeComponent implements OnInit {
readonly DEFAULT_LANDING_PAGE = '/personal-files';
constructor(private appConfig: AppConfigService, private router: Router) {}
private appSettings = inject(AppSettingsService);
private router = inject(Router);
ngOnInit() {
const landingPage = this.appConfig.get('landingPage', this.DEFAULT_LANDING_PAGE);
this.router.navigateByUrl(landingPage);
this.router.navigateByUrl(this.appSettings.landingPage);
}
}
@@ -26,9 +26,8 @@ import { Component, EventEmitter, inject, OnDestroy, OnInit, Output, ViewEncapsu
import { Store } from '@ngrx/store';
import { Subject } from 'rxjs';
import { AppStore, getAppName, getLogoPath } from '@alfresco/aca-shared/store';
import { AppConfigService } from '@alfresco/adf-core';
import { ContentActionRef } from '@alfresco/adf-extensions';
import { AppExtensionService, ToolbarComponent } from '@alfresco/aca-shared';
import { AppExtensionService, AppSettingsService, ToolbarComponent } from '@alfresco/aca-shared';
import { takeUntil } from 'rxjs/operators';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
@@ -45,12 +44,12 @@ import { RouterModule } from '@angular/router';
export class SidenavHeaderComponent implements OnInit, OnDestroy {
private onDestroy$ = new Subject<boolean>();
private store = inject<Store<AppStore>>(Store);
private appConfigService = inject(AppConfigService);
private appSettings = inject(AppSettingsService);
private appExtensions = inject(AppExtensionService);
appName$ = this.store.select(getAppName);
logo$ = this.store.select(getLogoPath);
landingPage = this.appConfigService.get('landingPage', '/personal-files');
landingPage = this.appSettings.landingPage;
actions: Array<ContentActionRef> = [];
@Output()