Skip to content

Commit

Permalink
ACS-8404: Update application settings service (#3988)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika authored Aug 22, 2024
1 parent 360970d commit 11f51af
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 40 deletions.
8 changes: 1 addition & 7 deletions app/src/app.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"logo": "assets/images/app-logo.svg",
"copyright": "APP.COPYRIGHT"
},
"viewer.maxRetries": 1,
"pagination": {
"size": 25,
"supportedPageSizes": [25, 50, 100]
Expand All @@ -54,10 +53,6 @@
"defaultDateTimeFormat": "MMM d, y, h:mm",
"defaultLocale": "en"
},
"adf-version-manager": {
"allowComments": true,
"allowDownload": true
},
"sideNav": {
"preserveState": true,
"expandedSidenav": true
Expand Down Expand Up @@ -330,7 +325,6 @@
"downloadPromptDelay": 50,
"downloadPromptReminderDelay": 30,
"enableFileAutoDownload": true,
"fileAutoDownloadSizeThresholdInMB": 15,
"closeButtonPosition": "right"
"fileAutoDownloadSizeThresholdInMB": 15
}
}
2 changes: 1 addition & 1 deletion app/src/app/components/login/app-login.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<adf-login
[copyrightText]="'application.copyright' | adfAppConfig | translate"
[copyrightText]="settings.appCopyright | translate"
successRoute="/personal-files"
logoImageUrl="./assets/images/alfresco-logo.svg"
backgroundImageUrl="./assets/images/Wallpaper-BG-generic.svg"
Expand Down
11 changes: 7 additions & 4 deletions app/src/app/components/login/app-login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { AppConfigPipe, LoginComponent } from '@alfresco/adf-core';
import { Component, ViewEncapsulation } from '@angular/core';
import { LoginComponent } from '@alfresco/adf-core';
import { Component, inject, ViewEncapsulation } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { AppSettingsService } from '@alfresco/aca-shared';

@Component({
standalone: true,
imports: [LoginComponent, TranslateModule, AppConfigPipe],
imports: [LoginComponent, TranslateModule],
templateUrl: './app-login.component.html',
encapsulation: ViewEncapsulation.None
})
export class AppLoginComponent {}
export class AppLoginComponent {
settings = inject(AppSettingsService);
}
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = () => {
global: {
statements: 75,
branches: 65,
functions: 70,
functions: 69,
lines: 74
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,21 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component, Input, OnChanges, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, inject, Input, OnChanges, OnInit, ViewEncapsulation } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { CommonModule } from '@angular/common';
import { VersionManagerModule } from '@alfresco/adf-content-services';
import { MatIconModule } from '@angular/material/icon';
import { TranslateModule } from '@ngx-translate/core';
import { AppConfigPipe } from '@alfresco/adf-core';
import { AppSettingsService } from '@alfresco/aca-shared';

@Component({
standalone: true,
imports: [CommonModule, VersionManagerModule, MatIconModule, TranslateModule, AppConfigPipe],
imports: [CommonModule, VersionManagerModule, MatIconModule, TranslateModule],
selector: 'app-versions-tab',
template: `
<ng-container *ngIf="isFileSelected; else empty">
<adf-version-manager
[showComments]="'adf-version-manager.allowComments' | adfAppConfig : true"
[allowDownload]="'adf-version-manager.allowDownload' | adfAppConfig : true"
[node]="node"
>
<adf-version-manager [showComments]="settings.uploadAllowComments" [allowDownload]="settings.uploadAllowDownload" [node]="node">
</adf-version-manager>
</ng-container>
Expand All @@ -54,6 +50,8 @@ import { AppConfigPipe } from '@alfresco/adf-core';
encapsulation: ViewEncapsulation.None
})
export class VersionsTabComponent implements OnInit, OnChanges {
settings = inject(AppSettingsService);

@Input()
node: Node;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,10 @@ describe('ContentManagementService', () => {

it('should open dialog with NewVersionUploaderService', () => {
contentManagementService.versionUpdateDialog(fakeNode, fakeFile);
const expectedParams = [{ node: fakeNode, file: fakeFile, currentVersion: { id: '1.0' }, title: 'VERSION.DIALOG.TITLE' }, { width: '600px' }];
const expectedParams = [
{ node: fakeNode, file: fakeFile, currentVersion: { id: '1.0' }, title: 'VERSION.DIALOG.TITLE', showComments: true, allowDownload: true },
{ width: '600px' }
];
expect(spyOnOpenUploadNewVersionDialog).toHaveBeenCalledOnceWith(...expectedParams);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {
DocumentListService,
FolderDialogComponent,
LibraryDialogComponent,
NewVersionUploaderData,
NewVersionUploaderDataAction,
NewVersionUploaderDialogData,
NewVersionUploaderService,
Expand Down Expand Up @@ -152,17 +151,20 @@ export class ContentManagementService {
}
}

versionUpdateDialog(node, file) {
versionUpdateDialog(node: Node, file: File) {
this.contentApi.getNodeVersions(node.id).subscribe(({ list }) => {
const newVersionUploaderDialogData: NewVersionUploaderDialogData = {
const newVersionUploaderDialogData = {
node,
file,
currentVersion: list.entries[0].entry,
title: 'VERSION.DIALOG.TITLE'
};
title: 'VERSION.DIALOG.TITLE',
showComments: this.appSettingsService.uploadAllowComments,
allowDownload: this.appSettingsService.uploadAllowDownload
} as NewVersionUploaderDialogData;
const dialogConfig: MatDialogConfig = { width: '600px' };

this.newVersionUploaderService.openUploadNewVersionDialog(newVersionUploaderDialogData, dialogConfig).subscribe(
(data: NewVersionUploaderData) => {
(data) => {
if (data.action === NewVersionUploaderDataAction.upload) {
if (data.newVersion.value.entry.properties['cm:lockType'] === 'WRITE_LOCK') {
this.store.dispatch(new UnlockWriteAction(data.newVersion.value));
Expand Down Expand Up @@ -573,7 +575,7 @@ export class ContentManagementService {
this.newVersionUploaderService
.openUploadNewVersionDialog(newVersionUploaderDialogData, { width: '630px', role: 'dialog' }, focusedElementOnCloseSelector)
.subscribe({
next: (newVersionUploaderData: NewVersionUploaderData) => {
next: (newVersionUploaderData) => {
switch (newVersionUploaderData.action) {
case NewVersionUploaderDataAction.refresh:
this.store.dispatch(new RefreshPreviewAction(newVersionUploaderData.node));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ describe('UploadEffects', () => {
detail: {
files: [
{
file: new FileModel({
file: {
name: 'Fake New file',
type: 'image/png',
lastModified: 1589273450599,
size: 1351,
slice: null
} as File),
} as File,
entry: new FileModel({
name: 'Fake New file',
type: 'image/png',
Expand Down Expand Up @@ -274,7 +274,7 @@ describe('UploadEffects', () => {
id: '1bf8a8f7-18ac-4eef-919d-61d952eaa179',
allowableOperations: ['delete', 'update', 'updatePermissions'],
isFavorite: false
}
} as any
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ngClass]="{
'aca-right_side--hide': !showRightSide
}"
[maxRetries]="'viewer.maxRetries' | adfAppConfig"
[maxRetries]="settings.viewerMaxRetries"
[nodeId]="nodeId"
[versionId]="versionId"
[allowNavigate]="navigateMultiple"
Expand All @@ -14,7 +14,7 @@
[allowFullScreen]="false"
[overlayMode]="true"
[hideInfoButton]="true"
[closeButtonPosition]="'viewer.closeButtonPosition' | adfAppConfig: 'right'"
[closeButtonPosition]="settings.viewerCloseButtonPosition"
(showViewerChange)="onViewerVisibilityChanged()"
[canNavigateBefore]="!!previousNodeId"
[canNavigateNext]="!!nextNodeId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
} from '@alfresco/aca-shared';
import { Store } from '@ngrx/store';
import { Node } from '@alfresco/js-api';
import { AcaViewerModule } from '../../viewer.module';

const apiError = `{
"error": {
Expand Down Expand Up @@ -68,7 +67,7 @@ describe('AcaViewerComponent', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [LibTestingModule, AcaViewerModule],
imports: [LibTestingModule, AcaViewerComponent],
providers: [
{ provide: DocumentBasePageService, useValue: DocumentBasePageServiceMock },
{ provide: DiscoveryApiService, useValue: discoveryApiServiceMockValue },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import {
AppExtensionService,
AppHookService,
AppSettingsService,
ContentApiService,
InfoDrawerComponent,
ToolbarComponent,
Expand All @@ -45,25 +46,36 @@ import { ContentActionRef, SelectionState } from '@alfresco/adf-extensions';
import { Node, VersionEntry, VersionsApi } from '@alfresco/js-api';
import { Component, HostListener, inject, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute, PRIMARY_OUTLET, Router } from '@angular/router';
import { AlfrescoApiService, AppConfigPipe, ViewerModule } from '@alfresco/adf-core';
import { AlfrescoApiService, ViewerOpenWithComponent, ViewerSidebarComponent, ViewerToolbarActionsComponent } from '@alfresco/adf-core';
import { Store } from '@ngrx/store';
import { from, Observable, Subject } from 'rxjs';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { Actions, ofType } from '@ngrx/effects';
import { AlfrescoViewerModule, DocumentListService, NodesApiService, UploadService } from '@alfresco/adf-content-services';
import { AlfrescoViewerComponent, DocumentListService, NodesApiService, UploadService } from '@alfresco/adf-content-services';
import { CommonModule } from '@angular/common';
import { ViewerService } from '../../services/viewer.service';

@Component({
standalone: true,
imports: [CommonModule, ViewerModule, AlfrescoViewerModule, InfoDrawerComponent, ToolbarMenuItemComponent, ToolbarComponent, AppConfigPipe],
imports: [
CommonModule,
InfoDrawerComponent,
ToolbarMenuItemComponent,
ToolbarComponent,
AlfrescoViewerComponent,
ViewerToolbarActionsComponent,
ViewerOpenWithComponent,
ViewerSidebarComponent
],
selector: 'aca-viewer',
templateUrl: './viewer.component.html',
styleUrls: ['./viewer.component.scss'],
encapsulation: ViewEncapsulation.None,
host: { class: 'app-viewer' }
})
export class AcaViewerComponent implements OnInit, OnDestroy {
settings = inject(AppSettingsService);

private documentListService = inject(DocumentListService);

private _versionsApi: VersionsApi;
Expand Down
37 changes: 36 additions & 1 deletion projects/aca-shared/src/lib/services/app-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@
*/

import { inject, Injectable } from '@angular/core';
import { AppConfigService } from '@alfresco/adf-core';
import { AppConfigService, CloseButtonPosition } from '@alfresco/adf-core';
import { AlfrescoMimeType, DefaultMimeTypes } from '../constants/mime-types';

@Injectable({ providedIn: 'root' })
export class AppSettingsService {
private appConfig = inject(AppConfigService);

/**
* Get the application copyright text from the app settings.
*/
get appCopyright(): string {
return this.appConfig.get<string>('application.copyright', '');
}

/**
* Get the AOS (Alfresco Office Services) host URL from the app settings.
*/
Expand Down Expand Up @@ -98,6 +105,34 @@ export class AppSettingsService {
return result;
}

/**
* Get the viewer close button position from the app settings.
*/
get viewerCloseButtonPosition(): CloseButtonPosition {
return this.appConfig.get('viewer.closeButtonPosition', CloseButtonPosition.Right);
}

/**
* Get the viewer max retries from the app settings.
*/
get viewerMaxRetries(): number {
return this.appConfig.get<number>('viewer.maxRetries', 1);
}

/**
* Enabled state of the comment feature for upload dialog
*/
get uploadAllowComments(): boolean {
return this.appConfig.get<boolean>('adf-version-manager.allowComments', true);
}

/**
* Enabled state of the download feature for upload dialog
*/
get uploadAllowDownload(): boolean {
return this.appConfig.get<boolean>('adf-version-manager.allowDownload', true);
}

/**
* Gets the enablement of the file auto tryDownload feature from the app settings.
*/
Expand Down

0 comments on commit 11f51af

Please sign in to comment.