mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4125] simplify extension load in extension module (#4214)
* add extension load in extension module * add viewer extensions * fix license header * fix node passed in the viewer extension * fix node passed in the viewer extension * startup factory extension * startup factory extension * fix script * fix beta tag build * fix build * fix build * refactoring configuration files * extension using map * fix build * fix config * fix test * fix test
This commit is contained in:
@@ -1106,7 +1106,6 @@
|
||||
},
|
||||
"categories": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
@@ -52,10 +52,12 @@ import { startupServiceFactory } from './services/startup-service-factory';
|
||||
import { SortingPickerModule } from './sorting-picker/sorting-picker.module';
|
||||
import { IconModule } from './icon/icon.module';
|
||||
import { TranslateLoaderService } from './services/translate-loader.service';
|
||||
import { ExtensionsModule } from '@alfresco/adf-extensions';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
TranslateModule,
|
||||
ExtensionsModule.forChild(),
|
||||
AboutModule,
|
||||
ViewerModule,
|
||||
SidenavLayoutModule,
|
||||
|
@@ -627,14 +627,14 @@ describe('FormComponent', () => {
|
||||
|
||||
it('should parse form from json', () => {
|
||||
let form = formComponent.parseForm({
|
||||
id: '<id>',
|
||||
id: 1,
|
||||
fields: [
|
||||
{ id: 'field1', type: FormFieldTypes.CONTAINER }
|
||||
]
|
||||
});
|
||||
|
||||
expect(form).toBeDefined();
|
||||
expect(form.id).toBe('<id>');
|
||||
expect(form.id).toBe(1);
|
||||
expect(form.fields.length).toBe(1);
|
||||
expect(form.fields[0].id).toBe('field1');
|
||||
});
|
||||
@@ -642,7 +642,7 @@ describe('FormComponent', () => {
|
||||
it('should provide outcomes for form definition', () => {
|
||||
spyOn(formComponent, 'getFormDefinitionOutcomes').and.callThrough();
|
||||
|
||||
let form = formComponent.parseForm({ id: '<id>' });
|
||||
let form = formComponent.parseForm({ id: 1 });
|
||||
expect(formComponent.getFormDefinitionOutcomes).toHaveBeenCalledWith(form);
|
||||
});
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
"entryFile": "./public-api.ts",
|
||||
"flatModuleFile": "adf-core",
|
||||
"umdModuleIds": {
|
||||
"@alfresco/js-api": "@alfresco/js-ap",
|
||||
"@alfresco/js-api": "@alfresco/js-api",
|
||||
"minimatch": "minimatch-browser",
|
||||
"@angular/platform-browser/animations": "@angular/platform-browser/animations",
|
||||
"@angular/material": "@angular/material",
|
||||
@@ -23,7 +23,8 @@
|
||||
"moment": "moment",
|
||||
"moment-es6": "moment-es6",
|
||||
"moment/src/moment": "moment/src/moment",
|
||||
"@ngx-translate/core": "@ngx-translate/core"
|
||||
"@ngx-translate/core": "@ngx-translate/core",
|
||||
"rxjs": "rxjs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,46 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": false,
|
||||
"noLib": false,
|
||||
"allowUnreachableCode": false,
|
||||
"allowUnusedLabels": false,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitReturns": false,
|
||||
"noImplicitUseStrict": false,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"removeComments": true,
|
||||
"declaration": true,
|
||||
"outDir": "../dist/core/",
|
||||
"baseUrl": "./",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"paths": {
|
||||
"@alfresco/adf-process-services": [
|
||||
"../process-services"
|
||||
],
|
||||
"@alfresco/adf-content-services": [
|
||||
"../content-services"
|
||||
]
|
||||
},
|
||||
"lib": [
|
||||
"es2016",
|
||||
"dom"
|
||||
],
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"noUnusedLocals": true
|
||||
},
|
||||
"exclude": [
|
||||
"demo",
|
||||
"node_modules",
|
||||
"dist"
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"strictMetadataEmit": false,
|
||||
"skipTemplateCodegen": true
|
||||
}
|
||||
}
|
6
lib/core/tsconfig.lib.json
Normal file
6
lib/core/tsconfig.lib.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../dist/core/"
|
||||
}
|
||||
}
|
6
lib/core/tsconfig.spec.json
Normal file
6
lib/core/tsconfig.spec.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../tsconfig.spec.json",
|
||||
"files": [
|
||||
"test.ts"
|
||||
]
|
||||
}
|
@@ -76,7 +76,7 @@
|
||||
mat-icon-button
|
||||
title="{{ 'ADF_VIEWER.ACTIONS.DOWNLOAD' | translate }}"
|
||||
data-automation-id="adf-toolbar-download"
|
||||
[adfNodeDownload]="node">
|
||||
[adfNodeDownload]="nodeEntry">
|
||||
<mat-icon>file_download</mat-icon>
|
||||
</button>
|
||||
|
||||
@@ -169,6 +169,7 @@
|
||||
<div *ngIf="!isLoading" class="adf-viewer-main" fxFlexOrder="1" fxFlex="1 1 auto">
|
||||
<div class="adf-viewer-layout-content adf-viewer__fullscreen-container">
|
||||
<div class="adf-viewer-content-container" [ngSwitch]="viewerType">
|
||||
|
||||
<ng-container *ngSwitchCase="'pdf'">
|
||||
<adf-pdf-viewer [thumbnailsTemplate]="thumbnailsTemplate" [allowThumbnails]="allowThumbnails" [blobFile]="blobFile" [urlFile]="urlFileContent" [nameFile]="displayName"></adf-pdf-viewer>
|
||||
</ng-container>
|
||||
@@ -195,8 +196,22 @@
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngSwitchCase="'custom'">
|
||||
|
||||
<ng-container *ngFor="let ext of viewerExtensions">
|
||||
<adf-preview-extension
|
||||
*ngIf="extension === ext.fileExtension"
|
||||
[id]="ext.component"
|
||||
[node]="nodeEntry.entry"
|
||||
[url]="urlFileContent"
|
||||
[extension]="extension"
|
||||
[attr.data-automation-id]="ext.component">
|
||||
</adf-preview-extension>
|
||||
</ng-container>
|
||||
|
||||
<span class="adf-viewer-custom-content" *ngFor="let extensionTemplate of extensionTemplates">
|
||||
<ng-template *ngIf="extensionTemplate.isVisible" [ngTemplateOutlet]="extensionTemplate.template" [ngTemplateOutletContext]="{ urlFileContent: urlFileContent, extension:extension }">
|
||||
<ng-template *ngIf="extensionTemplate.isVisible"
|
||||
[ngTemplateOutlet]="extensionTemplate.template"
|
||||
[ngTemplateOutletContext]="{ urlFileContent: urlFileContent, extension:extension }">
|
||||
</ng-template>
|
||||
</span>
|
||||
</ng-container>
|
||||
|
@@ -600,10 +600,10 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
it('should get and assign node for download', (done) => {
|
||||
const node = { id: 'fake-node' };
|
||||
component.nodeId = '12';
|
||||
component.urlFile = '';
|
||||
const displayName = 'the-name';
|
||||
const node = new NodeEntry({ entry: { name: displayName, id: '12', content: { mimeType: 'txt' } } });
|
||||
const nodeDetails = { name: displayName, id: '12', content: { mimeType: 'txt' } };
|
||||
const contentUrl = '/content/url/path';
|
||||
const alfrescoApiInstanceMock = {
|
||||
@@ -618,7 +618,7 @@ describe('ViewerComponent', () => {
|
||||
component.ngOnChanges(null);
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(component.node).toBe(node);
|
||||
expect(component.nodeEntry).toBe(node);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@@ -31,6 +31,7 @@ import { ViewerSidebarComponent } from './viewer-sidebar.component';
|
||||
import { ViewerToolbarComponent } from './viewer-toolbar.component';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { ViewUtilService } from '../services/view-util.service';
|
||||
import { ExtensionService, ViewerExtensionRef } from '@alfresco/adf-extensions';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-viewer',
|
||||
@@ -201,7 +202,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
|
||||
viewerType = 'unknown';
|
||||
isLoading = false;
|
||||
node: NodeEntry;
|
||||
nodeEntry: NodeEntry;
|
||||
|
||||
extensionTemplates: { template: TemplateRef<any>, isVisible: boolean }[] = [];
|
||||
externalExtensions: string[] = [];
|
||||
@@ -211,6 +212,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
sidebarRightTemplateContext: { node: Node } = { node: null };
|
||||
sidebarLeftTemplateContext: { node: Node } = { node: null };
|
||||
fileTitle: string;
|
||||
viewerExtensions: Array<ViewerExtensionRef> = [];
|
||||
|
||||
private cacheBusterNumber;
|
||||
|
||||
@@ -220,7 +222,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
private extensions = {
|
||||
image: ['png', 'jpg', 'jpeg', 'gif', 'bpm', 'svg'],
|
||||
media: ['wav', 'mp4', 'mp3', 'webm', 'ogg'],
|
||||
text: ['txt', 'xml', 'js', 'html', 'json', 'ts', 'css', 'md'],
|
||||
text: ['txt', 'xml', 'html', 'json', 'ts', 'css', 'md'],
|
||||
pdf: ['pdf']
|
||||
};
|
||||
|
||||
@@ -236,6 +238,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
private viewUtils: ViewUtilService,
|
||||
private logService: LogService,
|
||||
private location: Location,
|
||||
private extensionService: ExtensionService,
|
||||
private el: ElementRef) {
|
||||
}
|
||||
|
||||
@@ -247,6 +250,15 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
this.subscriptions.push(
|
||||
this.apiService.nodeUpdated.subscribe((node) => this.onNodeUpdated(node))
|
||||
);
|
||||
|
||||
this.extensionLoad();
|
||||
}
|
||||
|
||||
private extensionLoad() {
|
||||
this.viewerExtensions = this.extensionService.getFeature('viewer.content');
|
||||
this.viewerExtensions.forEach((currentViewerExtension: ViewerExtensionRef) => {
|
||||
this.externalExtensions.push(currentViewerExtension.fileExtension);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
@@ -280,7 +292,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
} else if (this.nodeId) {
|
||||
this.apiService.nodesApi.getNode(this.nodeId, { include: ['allowableOperations'] }).then(
|
||||
(node: NodeEntry) => {
|
||||
this.node = node;
|
||||
this.nodeEntry = node;
|
||||
this.setUpNodeFile(node.entry).then(() => {
|
||||
this.isLoading = false;
|
||||
});
|
||||
|
@@ -21,6 +21,8 @@ import { TranslateModule } from '@ngx-translate/core';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
import { ExtensionsModule } from '@alfresco/adf-extensions';
|
||||
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { ToolbarModule } from '../toolbar/toolbar.module';
|
||||
import { PipeModule } from '../pipes/pipe.module';
|
||||
@@ -43,6 +45,7 @@ import { DirectiveModule } from '../directives/directive.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
ExtensionsModule,
|
||||
CommonModule,
|
||||
MaterialModule,
|
||||
TranslateModule.forChild(),
|
||||
|
Reference in New Issue
Block a user