mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-10767] Separate core card view logic from content-services and add documentation to reflect the changes (#7952)
This commit is contained in:
@@ -18,11 +18,12 @@
|
||||
import { MinimalNode } from '@alfresco/js-api';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AlfrescoApiService, CardViewUpdateService, NodesApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { AlfrescoApiService, NodesApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { EMPTY, of } from 'rxjs';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
import { NodeAspectService } from './node-aspect.service';
|
||||
import { DialogAspectListService } from './dialog-aspect-list.service';
|
||||
import { CardViewContentUpdateService } from '../../services/card-view-content-update.service';
|
||||
|
||||
describe('NodeAspectService', () => {
|
||||
|
||||
@@ -30,7 +31,7 @@ describe('NodeAspectService', () => {
|
||||
let nodeAspectService: NodeAspectService;
|
||||
let nodeApiService: NodesApiService;
|
||||
let alfrescoApiService: AlfrescoApiService;
|
||||
let cardViewUpdateService: CardViewUpdateService;
|
||||
let cardViewContentUpdateService: CardViewContentUpdateService;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
@@ -44,7 +45,7 @@ describe('NodeAspectService', () => {
|
||||
nodeAspectService = TestBed.inject(NodeAspectService);
|
||||
nodeApiService = TestBed.inject(NodesApiService);
|
||||
alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
cardViewUpdateService = TestBed.inject(CardViewUpdateService);
|
||||
cardViewContentUpdateService = TestBed.inject(CardViewContentUpdateService);
|
||||
});
|
||||
|
||||
it('should call openAspectListDialog with correct parameters when selectorAutoFocusedOnClose is passed', () => {
|
||||
@@ -89,7 +90,7 @@ describe('NodeAspectService', () => {
|
||||
});
|
||||
|
||||
it('should send and update node aspect once the node has been updated', async () => {
|
||||
await cardViewUpdateService.updatedAspect$.subscribe((nodeUpdated) => {
|
||||
await cardViewContentUpdateService.updatedAspect$.subscribe((nodeUpdated) => {
|
||||
expect(nodeUpdated.id).toBe('fake-node-id');
|
||||
expect(nodeUpdated.aspectNames).toEqual(['a', 'b', 'c']);
|
||||
});
|
||||
|
@@ -16,8 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AlfrescoApiService, CardViewUpdateService, NodesApiService } from '@alfresco/adf-core';
|
||||
import { AlfrescoApiService, NodesApiService } from '@alfresco/adf-core';
|
||||
import { DialogAspectListService } from './dialog-aspect-list.service';
|
||||
import { CardViewContentUpdateService } from '../../services/card-view-content-update.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -27,14 +28,14 @@ export class NodeAspectService {
|
||||
constructor(private alfrescoApiService: AlfrescoApiService,
|
||||
private nodesApiService: NodesApiService,
|
||||
private dialogAspectListService: DialogAspectListService,
|
||||
private cardViewUpdateService: CardViewUpdateService) {
|
||||
private cardViewContentUpdateService: CardViewContentUpdateService) {
|
||||
}
|
||||
|
||||
updateNodeAspects(nodeId: string, selectorAutoFocusedOnClose?: string) {
|
||||
this.dialogAspectListService.openAspectListDialog(nodeId, selectorAutoFocusedOnClose).subscribe((aspectList) => {
|
||||
this.nodesApiService.updateNode(nodeId, { aspectNames: [...aspectList] }).subscribe((updatedNode) => {
|
||||
this.alfrescoApiService.nodeUpdated.next(updatedNode);
|
||||
this.cardViewUpdateService.updateNodeAspect(updatedNode);
|
||||
this.cardViewContentUpdateService.updateNodeAspect(updatedNode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@@ -22,19 +22,20 @@ import { MinimalNode, Node } from '@alfresco/js-api';
|
||||
import { ContentMetadataComponent } from './content-metadata.component';
|
||||
import { ContentMetadataService } from '../../services/content-metadata.service';
|
||||
import {
|
||||
CardViewBaseItemModel, CardViewComponent, CardViewUpdateService, NodesApiService,
|
||||
CardViewBaseItemModel, CardViewComponent, NodesApiService,
|
||||
LogService, setupTestBed
|
||||
} from '@alfresco/adf-core';
|
||||
import { throwError, of } from 'rxjs';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { mockGroupProperties } from './mock-data';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CardViewContentUpdateService } from '../../../services/card-view-content-update.service';
|
||||
|
||||
describe('ContentMetadataComponent', () => {
|
||||
let component: ContentMetadataComponent;
|
||||
let fixture: ComponentFixture<ContentMetadataComponent>;
|
||||
let contentMetadataService: ContentMetadataService;
|
||||
let updateService: CardViewUpdateService;
|
||||
let updateService: CardViewContentUpdateService;
|
||||
let nodesApiService: NodesApiService;
|
||||
let node: Node;
|
||||
let folderNode: Node;
|
||||
@@ -52,7 +53,7 @@ describe('ContentMetadataComponent', () => {
|
||||
fixture = TestBed.createComponent(ContentMetadataComponent);
|
||||
component = fixture.componentInstance;
|
||||
contentMetadataService = TestBed.inject(ContentMetadataService);
|
||||
updateService = TestBed.inject(CardViewUpdateService);
|
||||
updateService = TestBed.inject(CardViewContentUpdateService);
|
||||
nodesApiService = TestBed.inject(NodesApiService);
|
||||
|
||||
node = {
|
||||
|
@@ -22,7 +22,6 @@ import {
|
||||
CardViewItem,
|
||||
NodesApiService,
|
||||
LogService,
|
||||
CardViewUpdateService,
|
||||
AlfrescoApiService,
|
||||
TranslationService,
|
||||
AppConfigService,
|
||||
@@ -32,6 +31,7 @@ import {
|
||||
import { ContentMetadataService } from '../../services/content-metadata.service';
|
||||
import { CardViewGroup, PresetConfig } from '../../interfaces/content-metadata.interfaces';
|
||||
import { takeUntil, debounceTime, catchError, map } from 'rxjs/operators';
|
||||
import { CardViewContentUpdateService } from '../../../services/card-view-content-update.service';
|
||||
|
||||
const DEFAULT_SEPARATOR = ', ';
|
||||
|
||||
@@ -97,7 +97,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
|
||||
|
||||
constructor(
|
||||
private contentMetadataService: ContentMetadataService,
|
||||
private cardViewUpdateService: CardViewUpdateService,
|
||||
private cardViewContentUpdateService: CardViewContentUpdateService,
|
||||
private nodesApiService: NodesApiService,
|
||||
private logService: LogService,
|
||||
private alfrescoApiService: AlfrescoApiService,
|
||||
@@ -110,7 +110,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.cardViewUpdateService.itemUpdated$
|
||||
this.cardViewContentUpdateService.itemUpdated$
|
||||
.pipe(
|
||||
debounceTime(500),
|
||||
takeUntil(this.onDestroy$))
|
||||
@@ -122,7 +122,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
|
||||
}
|
||||
);
|
||||
|
||||
this.cardViewUpdateService.updatedAspect$.pipe(
|
||||
this.cardViewContentUpdateService.updatedAspect$.pipe(
|
||||
debounceTime(500),
|
||||
takeUntil(this.onDestroy$))
|
||||
.subscribe((node) => this.loadProperties(node));
|
||||
@@ -201,14 +201,14 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
|
||||
private updateNode() {
|
||||
this.nodesApiService.updateNode(this.node.id, this.changedProperties).pipe(
|
||||
catchError((err) => {
|
||||
this.cardViewUpdateService.updateElement(this.targetProperty);
|
||||
this.cardViewContentUpdateService.updateElement(this.targetProperty);
|
||||
this.handleUpdateError(err);
|
||||
return of(null);
|
||||
}))
|
||||
.subscribe((updatedNode) => {
|
||||
if (updatedNode) {
|
||||
if (this.hasContentTypeChanged(this.changedProperties)) {
|
||||
this.cardViewUpdateService.updateNodeAspect(this.node);
|
||||
this.cardViewContentUpdateService.updateNodeAspect(this.node);
|
||||
}
|
||||
this.revertChanges();
|
||||
Object.assign(this.node, updatedNode);
|
||||
|
@@ -0,0 +1,29 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CardViewBaseItemModel, UpdateNotification } from '@alfresco/adf-core';
|
||||
import { MinimalNode } from '@alfresco/js-api';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
export interface BaseCardViewContentUpdate {
|
||||
itemUpdated$: Subject<UpdateNotification>;
|
||||
updatedAspect$: Subject<MinimalNode>;
|
||||
|
||||
update(property: CardViewBaseItemModel, newValue: any);
|
||||
updateElement(notification: CardViewBaseItemModel);
|
||||
updateNodeAspect(node: MinimalNode);
|
||||
}
|
@@ -20,4 +20,5 @@ export * from './library-entity.interface';
|
||||
export * from './restore-message-model.interface';
|
||||
export * from './library-membership-error-event.interface';
|
||||
export * from './library-membership-toggle-event.interface';
|
||||
export * from './base-card-view-content-update.interface';
|
||||
|
||||
|
@@ -0,0 +1,38 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { MinimalNode } from '@alfresco/js-api';
|
||||
import { fakeAsync, TestBed } from '@angular/core/testing';
|
||||
import { CardViewContentUpdateService } from './card-view-content-update.service';
|
||||
|
||||
describe('CardViewContentUpdateService', () => {
|
||||
|
||||
let cardViewContentUpdateService: CardViewContentUpdateService;
|
||||
|
||||
beforeEach(() => {
|
||||
cardViewContentUpdateService = TestBed.inject(CardViewContentUpdateService);
|
||||
});
|
||||
|
||||
it('should send updated node when aspect changed', fakeAsync(() => {
|
||||
const fakeNode: MinimalNode = { id: 'Bigfoot'} as MinimalNode;
|
||||
cardViewContentUpdateService.updatedAspect$.subscribe((node: MinimalNode) => {
|
||||
expect(node.id).toBe('Bigfoot');
|
||||
});
|
||||
|
||||
cardViewContentUpdateService.updateNodeAspect(fakeNode);
|
||||
}));
|
||||
});
|
@@ -0,0 +1,58 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { UpdateNotification, CardViewBaseItemModel, CardViewUpdateService } from '@alfresco/adf-core';
|
||||
import { MinimalNode } from '@alfresco/js-api';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { BaseCardViewContentUpdate } from '../interfaces/base-card-view-content-update.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CardViewContentUpdateService implements BaseCardViewContentUpdate {
|
||||
|
||||
itemUpdated$ = new Subject<UpdateNotification>();
|
||||
|
||||
updatedAspect$ = new Subject<MinimalNode>();
|
||||
|
||||
constructor(private cardViewUpdateService: CardViewUpdateService) {
|
||||
this.linkVariables();
|
||||
}
|
||||
|
||||
update(property: CardViewBaseItemModel, newValue: any) {
|
||||
this.cardViewUpdateService.update(property, newValue);
|
||||
}
|
||||
|
||||
updateElement(notification: CardViewBaseItemModel) {
|
||||
this.cardViewUpdateService.updateElement(notification);
|
||||
}
|
||||
|
||||
updateNodeAspect(node: MinimalNode) {
|
||||
this.updatedAspect$.next(node);
|
||||
}
|
||||
|
||||
private linkVariables() {
|
||||
this.linkItemUpdated();
|
||||
}
|
||||
|
||||
private linkItemUpdated() {
|
||||
this.cardViewUpdateService.itemUpdated$.subscribe(res => {
|
||||
this.itemUpdated$.next(res);
|
||||
});
|
||||
}
|
||||
}
|
18
lib/content-services/src/lib/services/index.ts
Normal file
18
lib/content-services/src/lib/services/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './public-api';
|
18
lib/content-services/src/lib/services/public-api.ts
Normal file
18
lib/content-services/src/lib/services/public-api.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './card-view-content-update.service';
|
@@ -38,5 +38,6 @@ export * from './lib/content-type/index';
|
||||
export * from './lib/new-version-uploader';
|
||||
export * from './lib/interfaces/index';
|
||||
export * from './lib/version-compatibility/index';
|
||||
export * from './lib/services/index';
|
||||
|
||||
export * from './lib/content.module';
|
||||
|
Reference in New Issue
Block a user