ACS-8251: migrate Extensions library to Standalone (#9842)

This commit is contained in:
Denys Vuika
2024-06-20 08:52:30 -04:00
committed by GitHub
parent 45e921a382
commit 9a544307d4
32 changed files with 465 additions and 572 deletions

View File

@@ -22,7 +22,9 @@ import { By } from '@angular/platform-browser';
import { TranslateModule } from '@ngx-translate/core';
@Component({
template: `<div tabindex="0" adf-auto-focus> Test</div>`
standalone: true,
imports: [AutoFocusDirective],
template: ` <div tabindex="0" adf-auto-focus>Test</div>`
})
class AutoFocusTestComponent {}
@@ -31,13 +33,7 @@ describe('AutoFocusDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot()
],
declarations: [
AutoFocusDirective,
AutoFocusTestComponent
]
imports: [TranslateModule.forRoot(), AutoFocusDirective, AutoFocusTestComponent]
});
fixture = TestBed.createComponent(AutoFocusTestComponent);
});

View File

@@ -18,14 +18,15 @@
import { AfterContentInit, Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[adf-auto-focus]'
standalone: true,
selector: '[adf-auto-focus]'
})
export class AutoFocusDirective implements AfterContentInit {
public constructor(private el: ElementRef) {}
public constructor(private el: ElementRef) {}
public ngAfterContentInit() {
setTimeout(() => {
this.el.nativeElement.focus();
}, 100);
}
public ngAfterContentInit() {
setTimeout(() => {
this.el.nativeElement.focus();
}, 100);
}
}

View File

@@ -17,37 +17,39 @@
/* eslint-disable @angular-eslint/no-input-rename */
import { ChangeDetectorRef, Directive, ElementRef, Host, Inject, Input, OnChanges, Optional, Renderer2, SimpleChanges } from '@angular/core';
import { ChangeDetectorRef, Directive, ElementRef, Host, Inject, Input, OnChanges, Optional, Renderer2, SimpleChanges } from '@angular/core';
import { NodeEntry } from '@alfresco/js-api';
import { EXTENDIBLE_COMPONENT } from '@alfresco/adf-core';
import { ContentService } from '../common/services/content.service';
import { NodeAllowableOperationSubject } from '../interfaces/node-allowable-operation-subject.interface';
@Directive({
standalone: true,
selector: '[adf-check-allowable-operation]'
})
export class CheckAllowableOperationDirective implements OnChanges {
/**
* Node permission to check (create, delete, update, updatePermissions,
* !create, !delete, !update, !updatePermissions).
*/
@Input('adf-check-allowable-operation')
permission: string = null;
permission: string = null;
/** Nodes to check permission for. */
@Input('adf-nodes')
nodes: NodeEntry[] = [];
constructor(private elementRef: ElementRef,
private renderer: Renderer2,
private contentService: ContentService,
private changeDetector: ChangeDetectorRef,
constructor(
private elementRef: ElementRef,
private renderer: Renderer2,
private contentService: ContentService,
private changeDetector: ChangeDetectorRef,
@Host()
@Optional()
@Inject(EXTENDIBLE_COMPONENT) private parentComponent?: NodeAllowableOperationSubject) {
}
@Host()
@Optional()
@Inject(EXTENDIBLE_COMPONENT)
private parentComponent?: NodeAllowableOperationSubject
) {}
ngOnChanges(changes: SimpleChanges) {
if (changes.nodes && !changes.nodes.firstChange) {

View File

@@ -15,11 +15,7 @@
* limitations under the License.
*/
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { MaterialModule } from '../material.module';
import { TranslateModule } from '@ngx-translate/core';
import { NodeLockDirective } from './node-lock.directive';
import { NodeCounterComponent, NodeCounterDirective } from './node-counter.directive';
import { AutoFocusDirective } from './auto-focus.directive';
@@ -31,37 +27,23 @@ import { NodeFavoriteDirective } from './node-favorite.directive';
import { NodeRestoreDirective } from './node-restore.directive';
import { NodeDownloadDirective } from './node-download.directive';
export const CONTENT_DIRECTIVES = [
NodeLockDirective,
NodeCounterDirective,
NodeCounterComponent,
AutoFocusDirective,
CheckAllowableOperationDirective,
LibraryFavoriteDirective,
LibraryMembershipDirective,
NodeDeleteDirective,
NodeFavoriteDirective,
NodeRestoreDirective,
NodeDownloadDirective
];
/** @deprecated import CONTENT_DIRECTIVES or standalone directives instead */
@NgModule({
imports: [
CommonModule,
MaterialModule,
TranslateModule
],
declarations: [
NodeLockDirective,
NodeCounterDirective,
NodeCounterComponent,
AutoFocusDirective,
CheckAllowableOperationDirective,
LibraryFavoriteDirective,
LibraryMembershipDirective,
NodeDeleteDirective,
NodeFavoriteDirective,
NodeRestoreDirective,
NodeDownloadDirective
],
exports: [
NodeLockDirective,
NodeCounterDirective,
AutoFocusDirective,
CheckAllowableOperationDirective,
LibraryFavoriteDirective,
LibraryMembershipDirective,
NodeDeleteDirective,
NodeFavoriteDirective,
NodeRestoreDirective,
NodeDownloadDirective
]
imports: [...CONTENT_DIRECTIVES],
exports: [...CONTENT_DIRECTIVES]
})
export class ContentDirectiveModule {
}
export class ContentDirectiveModule {}

View File

@@ -22,8 +22,10 @@ import { CoreTestingModule } from '@alfresco/adf-core';
import { LibraryEntity } from '../interfaces/library-entity.interface';
@Component({
standalone: true,
imports: [LibraryFavoriteDirective],
selector: 'app-test-component',
template: ` <button #favoriteLibrary="favoriteLibrary" [adf-favorite-library]="selection">Favorite</button> `
template: `<button #favoriteLibrary="favoriteLibrary" [adf-favorite-library]="selection">Favorite</button>`
})
class TestComponent {
@ViewChild('favoriteLibrary', { static: true })
@@ -39,8 +41,7 @@ describe('LibraryFavoriteDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [CoreTestingModule],
declarations: [TestComponent, LibraryFavoriteDirective]
imports: [CoreTestingModule, LibraryFavoriteDirective, TestComponent]
});
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;

View File

@@ -21,6 +21,7 @@ import { AlfrescoApiService } from '@alfresco/adf-core';
import { LibraryEntity } from '../interfaces/library-entity.interface';
@Directive({
standalone: true,
selector: '[adf-favorite-library]',
exportAs: 'favoriteLibrary'
})

View File

@@ -25,6 +25,7 @@ import { VersionCompatibilityService } from '../version-compatibility/version-co
import { SitesService } from '../common/services/sites.service';
@Directive({
standalone: true,
selector: '[adf-library-membership]',
exportAs: 'libraryMembership'
})

View File

@@ -22,6 +22,8 @@ import { By } from '@angular/platform-browser';
import { TranslateModule } from '@ngx-translate/core';
@Component({
standalone: true,
imports: [NodeCounterDirective],
template: `<div [adf-node-counter]="count"></div>`
})
class TestComponent {
@@ -33,14 +35,7 @@ describe('NodeCounterDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot()
],
declarations: [
NodeCounterDirective,
NodeCounterComponent,
TestComponent
]
imports: [TranslateModule.forRoot(), NodeCounterDirective, NodeCounterComponent, TestComponent]
});
fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();

View File

@@ -16,8 +16,10 @@
*/
import { Directive, Input, Component, OnInit, OnChanges, ViewContainerRef } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
@Directive({
standalone: true,
selector: '[adf-node-counter]'
})
export class NodeCounterDirective implements OnInit, OnChanges {
@@ -42,6 +44,8 @@ export class NodeCounterDirective implements OnInit, OnChanges {
}
@Component({
standalone: true,
imports: [TranslateModule],
selector: 'adf-node-counter',
template: ` <div>{{ 'NODE_COUNTER.SELECTED_COUNT' | translate : { count: counter } }}</div> `
})

View File

@@ -23,7 +23,7 @@ import { CoreTestingModule } from '@alfresco/adf-core';
import { ContentDirectiveModule } from './content-directive.module';
@Component({
template: ` <div id="delete-component" [adf-delete]="selection" (delete)="onDelete()"></div>`
template: `<div id="delete-component" [adf-delete]="selection" (delete)="onDelete()"></div>`
})
class TestComponent {
selection = [];
@@ -35,7 +35,7 @@ class TestComponent {
}
@Component({
template: ` <div id="delete-component" [adf-check-allowable-operation]="selection" [adf-delete]="selection" (delete)="onDelete($event)"></div>`
template: `<div id="delete-component" [adf-check-allowable-operation]="selection" [adf-delete]="selection" (delete)="onDelete($event)"></div>`
})
class TestWithPermissionsComponent {
selection = [];

View File

@@ -46,6 +46,7 @@ interface ProcessStatus {
}
@Directive({
standalone: true,
selector: '[adf-delete]'
})
export class NodeDeleteDirective implements OnChanges {
@@ -61,13 +62,13 @@ export class NodeDeleteDirective implements OnChanges {
@Output()
delete: EventEmitter<any> = new EventEmitter();
_trashcanApi: TrashcanApi;
private _trashcanApi: TrashcanApi;
get trashcanApi(): TrashcanApi {
this._trashcanApi = this._trashcanApi ?? new TrashcanApi(this.alfrescoApiService.getInstance());
return this._trashcanApi;
}
_nodesApi: NodesApi;
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.alfrescoApiService.getInstance());
return this._nodesApi;

View File

@@ -25,11 +25,12 @@ import { ContentApi, NodeEntry, VersionEntry } from '@alfresco/js-api';
* Directive selectors without adf- prefix will be deprecated on 3.0.0
*/
@Directive({
standalone: true,
// eslint-disable-next-line @angular-eslint/directive-selector
selector: '[adfNodeDownload]'
})
export class NodeDownloadDirective {
_contentApi: ContentApi;
private _contentApi: ContentApi;
get contentApi(): ContentApi {
this._contentApi = this._contentApi ?? new ContentApi(this.apiService.getInstance());
return this._contentApi;

View File

@@ -24,6 +24,7 @@ import { catchError, map } from 'rxjs/operators';
import { AlfrescoApiService } from '@alfresco/adf-core';
@Directive({
standalone: true,
selector: '[adf-node-favorite]',
exportAs: 'adfFavorite'
})

View File

@@ -24,15 +24,15 @@ import { AllowableOperationsEnum } from '../common/models/allowable-operations.e
import { ContentNodeDialogService } from '../content-node-selector/content-node-dialog.service';
@Directive({
standalone: true,
selector: '[adf-node-lock]'
})
export class NodeLockDirective implements AfterViewInit {
/** Node to lock/unlock. */
@Input('adf-node-lock')
node: Node;
@HostListener('click', [ '$event' ])
@HostListener('click', ['$event'])
onClick(event) {
event.stopPropagation();
this.contentNodeDialogService.openLockNodeDialog(this.node);

View File

@@ -18,20 +18,20 @@
/* eslint-disable @angular-eslint/component-selector, @angular-eslint/no-input-rename */
import { Directive, EventEmitter, HostListener, Input, Output } from '@angular/core';
import {
TrashcanApi, DeletedNodeEntry, DeletedNodesPaging } from '@alfresco/js-api';
import { TrashcanApi, DeletedNodeEntry, DeletedNodesPaging } from '@alfresco/js-api';
import { Observable, forkJoin, from, of } from 'rxjs';
import { tap, mergeMap, map, catchError } from 'rxjs/operators';
import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
import { RestoreMessageModel } from '../interfaces/restore-message-model.interface';
@Directive({
standalone: true,
selector: '[adf-restore]'
})
export class NodeRestoreDirective {
private readonly restoreProcessStatus;
_trashcanApi: TrashcanApi;
private _trashcanApi: TrashcanApi;
get trashcanApi(): TrashcanApi {
this._trashcanApi = this._trashcanApi ?? new TrashcanApi(this.alfrescoApiService.getInstance());
return this._trashcanApi;
@@ -50,8 +50,7 @@ export class NodeRestoreDirective {
this.recover(this.selection);
}
constructor(private alfrescoApiService: AlfrescoApiService,
private translation: TranslationService) {
constructor(private alfrescoApiService: AlfrescoApiService, private translation: TranslationService) {
this.restoreProcessStatus = this.processStatus();
}
@@ -63,28 +62,28 @@ export class NodeRestoreDirective {
const nodesWithPath = this.getNodesWithPath(selection);
if (selection.length && nodesWithPath.length) {
this.restoreNodesBatch(nodesWithPath)
.pipe(
tap((restoredNodes) => {
const status = this.processStatus(restoredNodes);
this.restoreNodesBatch(nodesWithPath).pipe(
tap((restoredNodes) => {
const status = this.processStatus(restoredNodes);
this.restoreProcessStatus.fail.push(...status.fail);
this.restoreProcessStatus.success.push(...status.success);
}),
mergeMap(() => this.getDeletedNodes())
)
.subscribe((deletedNodesList) => {
const { entries: nodeList } = deletedNodesList.list;
const { fail: restoreErrorNodes } = this.restoreProcessStatus;
const selectedNodes = this.diff(restoreErrorNodes, selection, false);
const remainingNodes = this.diff(selectedNodes, nodeList);
this.restoreProcessStatus.fail.push(...status.fail);
this.restoreProcessStatus.success.push(...status.success);
}),
mergeMap(() => this.getDeletedNodes())
)
.subscribe((deletedNodesList) => {
const { entries: nodeList } = deletedNodesList.list;
const { fail: restoreErrorNodes } = this.restoreProcessStatus;
const selectedNodes = this.diff(restoreErrorNodes, selection, false);
const remainingNodes = this.diff(selectedNodes, nodeList);
if (!remainingNodes.length) {
this.notification();
} else {
this.recover(remainingNodes);
}
});
if (!remainingNodes.length) {
this.notification();
} else {
this.recover(remainingNodes);
}
});
} else {
this.restoreProcessStatus.fail.push(...selection);
this.notification();
@@ -117,7 +116,7 @@ export class NodeRestoreDirective {
entry
})),
catchError((error) => {
const { statusCode } = (JSON.parse(error.message)).error;
const { statusCode } = JSON.parse(error.message).error;
return of({
status: 0,
@@ -145,10 +144,10 @@ export class NodeRestoreDirective {
fail: [],
success: [],
get someFailed() {
return !!(this.fail.length);
return !!this.fail.length;
},
get someSucceeded() {
return !!(this.success.length);
return !!this.success.length;
},
get oneFailed() {
return this.fail.length === 1;
@@ -168,58 +167,43 @@ export class NodeRestoreDirective {
}
};
return data.reduce(
(acc, node) => {
if (node.status) {
acc.success.push(node);
} else {
acc.fail.push(node);
}
return data.reduce((acc, node) => {
if (node.status) {
acc.success.push(node);
} else {
acc.fail.push(node);
}
return acc;
},
status
);
return acc;
}, status);
}
private getRestoreMessage(): string | null {
const { restoreProcessStatus: status } = this;
if (status.someFailed && !status.oneFailed) {
return this.translation.instant(
'CORE.RESTORE_NODE.PARTIAL_PLURAL',
{
// eslint-disable-next-line id-blacklist
number: status.fail.length
}
);
return this.translation.instant('CORE.RESTORE_NODE.PARTIAL_PLURAL', {
// eslint-disable-next-line id-blacklist
number: status.fail.length
});
}
if (status.oneFailed && status.fail[0].statusCode) {
if (status.fail[0].statusCode === 409) {
return this.translation.instant(
'CORE.RESTORE_NODE.NODE_EXISTS',
{
name: status.fail[0].entry.name
}
);
return this.translation.instant('CORE.RESTORE_NODE.NODE_EXISTS', {
name: status.fail[0].entry.name
});
} else {
return this.translation.instant(
'CORE.RESTORE_NODE.GENERIC',
{
name: status.fail[0].entry.name
}
);
return this.translation.instant('CORE.RESTORE_NODE.GENERIC', {
name: status.fail[0].entry.name
});
}
}
if (status.oneFailed && !status.fail[0].statusCode) {
return this.translation.instant(
'CORE.RESTORE_NODE.LOCATION_MISSING',
{
name: status.fail[0].entry.name
}
);
return this.translation.instant('CORE.RESTORE_NODE.LOCATION_MISSING', {
name: status.fail[0].entry.name
});
}
if (status.allSucceeded && !status.oneSucceeded) {
@@ -227,12 +211,9 @@ export class NodeRestoreDirective {
}
if (status.allSucceeded && status.oneSucceeded) {
return this.translation.instant(
'CORE.RESTORE_NODE.SINGULAR',
{
name: status.success[0].entry.name
}
);
return this.translation.instant('CORE.RESTORE_NODE.SINGULAR', {
name: status.success[0].entry.name
});
}
return null;
@@ -244,7 +225,7 @@ export class NodeRestoreDirective {
const message = this.getRestoreMessage();
this.reset();
const action = (status.oneSucceeded && !status.someFailed) ? this.translation.instant('CORE.RESTORE_NODE.VIEW') : '';
const action = status.oneSucceeded && !status.someFailed ? this.translation.instant('CORE.RESTORE_NODE.VIEW') : '';
let path;
if (status.success && status.success.length > 0) {

View File

@@ -15,37 +15,12 @@
* limitations under the License.
*/
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ExtensionsModule } from '@alfresco/adf-extensions';
import { MaterialModule } from '../material.module';
import { A11yModule } from '@angular/cdk/a11y';
import { AlfrescoViewerComponent } from './components/alfresco-viewer.component';
import { CoreModule } from '@alfresco/adf-core';
import { ContentDirectiveModule } from '../directives';
/** @deprecated import AlfrescoViewerComponent instead */
@NgModule({
imports: [
CoreModule,
CommonModule,
MaterialModule,
TranslateModule,
FormsModule,
ReactiveFormsModule,
A11yModule,
ExtensionsModule,
ContentDirectiveModule
],
declarations: [
AlfrescoViewerComponent
],
exports: [
AlfrescoViewerComponent
]
imports: [AlfrescoViewerComponent],
exports: [AlfrescoViewerComponent]
})
export class AlfrescoViewerModule {
}
export class AlfrescoViewerModule {}

View File

@@ -34,6 +34,7 @@ import {
CloseButtonPosition,
Track,
ViewerComponent,
ViewerModule,
ViewerMoreActionsComponent,
ViewerOpenWithComponent,
ViewerSidebarComponent,
@@ -51,9 +52,16 @@ import { NodesApiService } from '../../common/services/nodes-api.service';
import { UploadService } from '../../common/services/upload.service';
import { FileModel } from '../../common/models/file.model';
import { NodeActionsService } from '../../document-list';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { NodeDownloadDirective } from '../../directives';
@Component({
selector: 'adf-alfresco-viewer',
standalone: true,
imports: [CommonModule, TranslateModule, MatButtonModule, MatIconModule, ViewerModule, NodeDownloadDirective],
templateUrl: './alfresco-viewer.component.html',
styleUrls: ['./alfresco-viewer.component.scss'],
host: { class: 'adf-alfresco-viewer' },
@@ -115,7 +123,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
/**
* If `true` then show the Viewer as a full page over the current content.
* Otherwise fit inside the parent div.
* Otherwise, fit inside the parent div.
*/
@Input()
overlayMode = false;
@@ -211,25 +219,25 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
sidebarRightTemplateContext: { node: Node } = { node: null };
sidebarLeftTemplateContext: { node: Node } = { node: null };
_sharedLinksApi: SharedlinksApi;
private _sharedLinksApi: SharedlinksApi;
get sharedLinksApi(): SharedlinksApi {
this._sharedLinksApi = this._sharedLinksApi ?? new SharedlinksApi(this.apiService.getInstance());
return this._sharedLinksApi;
}
_versionsApi: VersionsApi;
private _versionsApi: VersionsApi;
get versionsApi(): VersionsApi {
this._versionsApi = this._versionsApi ?? new VersionsApi(this.apiService.getInstance());
return this._versionsApi;
}
_nodesApi: NodesApi;
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
return this._nodesApi;
}
_contentApi: ContentApi;
private _contentApi: ContentApi;
get contentApi(): ContentApi {
this._contentApi = this._contentApi ?? new ContentApi(this.apiService.getInstance());
return this._contentApi;