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

ACS-8404: Introduce App Settings service #3939

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
805 changes: 0 additions & 805 deletions app/src/app.config.json

Large diffs are not rendered by default.

25 changes: 8 additions & 17 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,21 @@ module.exports = () => {
],
files: [
{
pattern:
'./node_modules/@alfresco/adf-core/bundles/assets/adf-core/i18n/en.json',
pattern: './node_modules/@alfresco/adf-core/bundles/assets/adf-core/i18n/en.json',
watched: false,
served: true,
included: false
},
{
pattern:
'./node_modules/@alfresco/adf-content-services/bundles/assets/adf-content-services/i18n/en.json',
pattern: './node_modules/@alfresco/adf-content-services/bundles/assets/adf-content-services/i18n/en.json',
watched: false,
served: true,
included: false
}
],
proxies: {
'/assets/adf-core/i18n/en-GB.json':
'/base/node_modules/@alfresco/adf-core/bundles/assets/adf-core/i18n/en.json',
'/assets/adf-core/i18n/en.json':
'/base/node_modules/@alfresco/adf-core/bundles/assets/adf-core/i18n/en.json',
'/assets/adf-core/i18n/en-GB.json': '/base/node_modules/@alfresco/adf-core/bundles/assets/adf-core/i18n/en.json',
'/assets/adf-core/i18n/en.json': '/base/node_modules/@alfresco/adf-core/bundles/assets/adf-core/i18n/en.json',
'/assets/adf-content-services/i18n/en.json':
'/base/node_modules/@alfresco/adf-content-services/bundles/assets/adf-content-services/i18n/en.json',
'/assets/adf-content-services/i18n/en-GB.json':
Expand All @@ -49,10 +45,10 @@ module.exports = () => {
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false, // leave Jasmine Spec Runner output visible in browser
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true, // removes the duplicated traces
suppressAll: true // removes the duplicated traces
},

coverageReporter: {
Expand All @@ -63,7 +59,7 @@ module.exports = () => {
global: {
statements: 75,
branches: 67,
functions: 73,
functions: 72,
lines: 74
}
}
Expand All @@ -78,12 +74,7 @@ module.exports = () => {
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--remote-debugging-port=9222'
]
flags: ['--no-sandbox', '--headless', '--disable-gpu', '--remote-debugging-port=9222']
}
},
singleRun: true,
Expand Down
8 changes: 4 additions & 4 deletions projects/aca-content/about/src/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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>;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand Down
13 changes: 5 additions & 8 deletions projects/aca-content/ms-office/src/aos-extension.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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');
});
});
12 changes: 5 additions & 7 deletions projects/aca-content/src/lib/components/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@
* 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,
template: '',
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,4 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

export interface MimeType {
label: string;
value: string;
}
export * from './mime-types';
Loading
Loading