[ADF-3794] Update individual rows without reloading DocumentList (#4213)

* reload table cells on node updates

* update unit tests

* update dynamic columns

* fix value type

* fix tests

* update code as per review

* update variable name

* test fixes, core automation service

* fix test
This commit is contained in:
Denys Vuika
2019-03-27 11:38:37 +00:00
committed by Eugenio Romano
parent e85e634685
commit e75335a06d
19 changed files with 584 additions and 282 deletions

View File

@@ -23,7 +23,7 @@ import { ChartsModule } from 'ng2-charts';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppConfigService, TRANSLATION_PROVIDER, DebugAppConfigService, CoreModule } from '@alfresco/adf-core'; import { AppConfigService, TRANSLATION_PROVIDER, DebugAppConfigService, CoreModule, CoreAutomationService } from '@alfresco/adf-core';
import { ExtensionsModule } from '@alfresco/adf-extensions'; import { ExtensionsModule } from '@alfresco/adf-extensions';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { MaterialModule } from './material.module'; import { MaterialModule } from './material.module';
@@ -172,7 +172,8 @@ import { NestedMenuPositionDirective } from './components/app-layout/cloud/direc
source: 'resources/lazy-loading' source: 'resources/lazy-loading'
} }
}, },
PreviewService PreviewService,
CoreAutomationService
], ],
entryComponents: [ entryComponents: [
VersionManagerDialogAdapterComponent, VersionManagerDialogAdapterComponent,
@@ -180,4 +181,8 @@ import { NestedMenuPositionDirective } from './components/app-layout/cloud/direc
], ],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })
export class AppModule {} export class AppModule {
constructor(automationService: CoreAutomationService) {
automationService.setup();
}
}

View File

@@ -214,10 +214,6 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
@Optional() private route: ActivatedRoute, @Optional() private route: ActivatedRoute,
public authenticationService: AuthenticationService, public authenticationService: AuthenticationService,
public alfrescoApiService: AlfrescoApiService) { public alfrescoApiService: AlfrescoApiService) {
this.alfrescoApiService.nodeUpdated.subscribe(() => {
this.documentList.reload();
});
} }
showFile(event) { showFile(event) {

View File

@@ -15,13 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { browser } from 'protractor';
import { LoginPage } from '../../pages/adf/loginPage'; import { LoginPage } from '../../pages/adf/loginPage';
import { ViewerPage } from '../../pages/adf/viewerPage'; import { ViewerPage } from '../../pages/adf/viewerPage';
import { MetadataViewPage } from '../../pages/adf/metadataViewPage'; import { MetadataViewPage } from '../../pages/adf/metadataViewPage';
import { NavigationBarPage } from '../../pages/adf/navigationBarPage'; import { NavigationBarPage } from '../../pages/adf/navigationBarPage';
import { ConfigEditorPage } from '../../pages/adf/configEditorPage';
import { AcsUserModel } from '../../models/ACS/acsUserModel'; import { AcsUserModel } from '../../models/ACS/acsUserModel';
import { FileModel } from '../../models/ACS/fileModel'; import { FileModel } from '../../models/ACS/fileModel';
@@ -33,6 +30,7 @@ import { AlfrescoApiCompatibility as AlfrescoApi } from '@alfresco/js-api';
import { UploadActions } from '../../actions/ACS/upload.actions'; import { UploadActions } from '../../actions/ACS/upload.actions';
import { ContentServicesPage } from '../../pages/adf/contentServicesPage'; import { ContentServicesPage } from '../../pages/adf/contentServicesPage';
import { check } from '../../util/material'; import { check } from '../../util/material';
import { setConfigField } from '../../proxy';
describe('Aspect oriented config', () => { describe('Aspect oriented config', () => {
@@ -40,7 +38,6 @@ describe('Aspect oriented config', () => {
const viewerPage = new ViewerPage(); const viewerPage = new ViewerPage();
const metadataViewPage = new MetadataViewPage(); const metadataViewPage = new MetadataViewPage();
const navigationBarPage = new NavigationBarPage(); const navigationBarPage = new NavigationBarPage();
const configEditorPage = new ConfigEditorPage();
const contentServicesPage = new ContentServicesPage(); const contentServicesPage = new ContentServicesPage();
const modelOneName = 'modelOne', emptyAspectName = 'emptyAspect'; const modelOneName = 'modelOne', emptyAspectName = 'emptyAspect';
const defaultModel = 'cm', defaultEmptyPropertiesAspect = 'taggable', aspectName = 'Taggable'; const defaultModel = 'cm', defaultEmptyPropertiesAspect = 'taggable', aspectName = 'Taggable';
@@ -53,7 +50,6 @@ describe('Aspect oriented config', () => {
}); });
beforeAll(async (done) => { beforeAll(async (done) => {
const uploadActions = new UploadActions(); const uploadActions = new UploadActions();
this.alfrescoJsApi = new AlfrescoApi({ this.alfrescoJsApi = new AlfrescoApi({
@@ -92,35 +88,33 @@ describe('Aspect oriented config', () => {
done(); done();
}); });
beforeEach(async (done) => {
navigationBarPage.clickConfigEditorButton();
configEditorPage.clickClearButton();
done();
});
afterEach(async (done) => { afterEach(async (done) => {
viewerPage.clickCloseButton(); viewerPage.clickCloseButton();
contentServicesPage.checkAcsContainer(); contentServicesPage.checkAcsContainer();
browser.refresh();
contentServicesPage.checkAcsContainer();
done(); done();
}); });
it('[C261117] Should be possible restrict the display properties of one an aspect', () => { it('[C261117] Should be possible restrict the display properties of one an aspect', async () => {
configEditorPage.enterBigConfigurationText('{ "presets": {' + await setConfigField('content-metadata', JSON.stringify({
' "default": [{' + presets: {
' "title": "IMAGE",' + default: [
' "items": [' + {
' {' + title: 'IMAGE',
' "aspect": "exif:exif", "properties": [ "exif:pixelXDimension", "exif:pixelYDimension", "exif:isoSpeedRatings"]' + items: [
' }' + {
' ]' + aspect: 'exif:exif',
' }]' + properties: [
' }' + 'exif:pixelXDimension',
' }'); 'exif:pixelYDimension',
'exif:isoSpeedRatings'
configEditorPage.clickSaveButton(); ]
}
]
}
]
}
}));
navigationBarPage.clickContentServicesButton(); navigationBarPage.clickContentServicesButton();
@@ -141,19 +135,17 @@ describe('Aspect oriented config', () => {
metadataViewPage.checkPropertyIsVisible('properties.exif:isoSpeedRatings', 'textitem'); metadataViewPage.checkPropertyIsVisible('properties.exif:isoSpeedRatings', 'textitem');
}); });
it('[C260185] Should ignore not existing aspect when present in the configuration', () => { it('[C260185] Should ignore not existing aspect when present in the configuration', async () => {
configEditorPage.enterBigConfigurationText(' {' + await setConfigField('content-metadata', JSON.stringify({
' "presets": {' + presets: {
' "default": {' + default: {
' "exif:exif": "*",' + 'exif:exif': '*',
' "cm:versionable": "*",' + 'cm:versionable': '*',
' "not:exists": "*"' + 'not:exists': '*'
' }' + }
' }' + }
' }'); }));
configEditorPage.clickSaveButton();
navigationBarPage.clickContentServicesButton(); navigationBarPage.clickContentServicesButton();
@@ -170,11 +162,9 @@ describe('Aspect oriented config', () => {
metadataViewPage.checkMetadataGroupIsNotPresent('exists'); metadataViewPage.checkMetadataGroupIsNotPresent('exists');
}); });
it('[C260183] Should show all the aspect if the content-metadata configuration is NOT provided', () => { it('[C260183] Should show all the aspect if the content-metadata configuration is NOT provided', async () => {
configEditorPage.enterBigConfigurationText('{ }'); await setConfigField('content-metadata', '{}');
configEditorPage.clickSaveButton();
navigationBarPage.clickContentServicesButton(); navigationBarPage.clickContentServicesButton();
@@ -190,15 +180,13 @@ describe('Aspect oriented config', () => {
metadataViewPage.checkMetadataGroupIsPresent('Versionable'); metadataViewPage.checkMetadataGroupIsPresent('Versionable');
}); });
it('[C260182] Should show all the aspects if the default configuration contains the star symbol', () => { it('[C260182] Should show all the aspects if the default configuration contains the star symbol', async () => {
configEditorPage.enterBigConfigurationText('{' + await setConfigField('content-metadata', JSON.stringify({
' "presets": {' + presets: {
' "default": "*"' + default: '*'
' }' + }
'}'); }));
configEditorPage.clickSaveButton();
navigationBarPage.clickContentServicesButton(); navigationBarPage.clickContentServicesButton();
@@ -215,9 +203,9 @@ describe('Aspect oriented config', () => {
metadataViewPage.checkMetadataGroupIsPresent('Versionable'); metadataViewPage.checkMetadataGroupIsPresent('Versionable');
}); });
it('[C268899] Should be possible use a Translation key as Title of a metadata group', () => { it('[C268899] Should be possible use a Translation key as Title of a metadata group', async () => {
configEditorPage.enterBigConfigurationText('{' + await setConfigField('content-metadata', '{' +
' "presets": {' + ' "presets": {' +
' "default": [' + ' "default": [' +
' {' + ' {' +
@@ -242,8 +230,6 @@ describe('Aspect oriented config', () => {
' }' + ' }' +
'}'); '}');
configEditorPage.clickSaveButton();
navigationBarPage.clickContentServicesButton(); navigationBarPage.clickContentServicesButton();
viewerPage.viewFile(pngFileModel.name); viewerPage.viewFile(pngFileModel.name);
@@ -262,9 +248,9 @@ describe('Aspect oriented config', () => {
}); });
it('[C279968] Should be possible use a custom preset', () => { it('[C279968] Should be possible use a custom preset', async () => {
configEditorPage.enterBigConfigurationText('{' + await setConfigField('content-metadata', '{' +
' "presets": {' + ' "presets": {' +
' "custom-preset": {' + ' "custom-preset": {' +
' "exif:exif": "*",' + ' "exif:exif": "*",' +
@@ -273,8 +259,6 @@ describe('Aspect oriented config', () => {
' }' + ' }' +
'}'); '}');
configEditorPage.clickSaveButton();
navigationBarPage.clickContentServicesButton(); navigationBarPage.clickContentServicesButton();
viewerPage.viewFile(pngFileModel.name); viewerPage.viewFile(pngFileModel.name);
@@ -294,9 +278,9 @@ describe('Aspect oriented config', () => {
metadataViewPage.checkMetadataGroupIsPresent('Versionable'); metadataViewPage.checkMetadataGroupIsPresent('Versionable');
}); });
it('[C299186] The aspect without properties is not displayed', () => { it('[C299186] The aspect without properties is not displayed', async () => {
configEditorPage.enterBigConfigurationText('{' + await setConfigField('content-metadata', '{' +
' "presets": { "' + modelOneName + ' "presets": { "' + modelOneName +
' ": { "' + modelOneName + ':' + emptyAspectName + ' ": { "' + modelOneName + ':' + emptyAspectName +
' ":"*"' + ' ":"*"' +
@@ -304,8 +288,6 @@ describe('Aspect oriented config', () => {
' }' + ' }' +
'}'); '}');
configEditorPage.clickSaveButton();
navigationBarPage.clickContentServicesButton(); navigationBarPage.clickContentServicesButton();
viewerPage.viewFile(pngFileModel.name); viewerPage.viewFile(pngFileModel.name);
@@ -319,9 +301,9 @@ describe('Aspect oriented config', () => {
metadataViewPage.checkMetadataGroupIsNotPresent(emptyAspectName); metadataViewPage.checkMetadataGroupIsNotPresent(emptyAspectName);
}); });
it('[C299187] The aspect with empty properties is displayed when edit', () => { it('[C299187] The aspect with empty properties is displayed when edit', async () => {
configEditorPage.enterBigConfigurationText('{' + await setConfigField('content-metadata', '{' +
' "presets": { "' + defaultModel + ' "presets": { "' + defaultModel +
' ": { "' + defaultModel + ':' + defaultEmptyPropertiesAspect + ' ": { "' + defaultModel + ':' + defaultEmptyPropertiesAspect +
' ":"*"' + ' ":"*"' +
@@ -329,8 +311,6 @@ describe('Aspect oriented config', () => {
' }' + ' }' +
'}'); '}');
configEditorPage.clickSaveButton();
navigationBarPage.clickContentServicesButton(); navigationBarPage.clickContentServicesButton();
viewerPage.viewFile(pngFileModel.name); viewerPage.viewFile(pngFileModel.name);

View File

@@ -32,6 +32,7 @@ import dateFormat = require('dateformat');
import { AlfrescoApiCompatibility as AlfrescoApi } from '@alfresco/js-api'; import { AlfrescoApiCompatibility as AlfrescoApi } from '@alfresco/js-api';
import { UploadActions } from '../../actions/ACS/upload.actions'; import { UploadActions } from '../../actions/ACS/upload.actions';
import { NavigationBarPage } from '../../pages/adf/navigationBarPage'; import { NavigationBarPage } from '../../pages/adf/navigationBarPage';
import { setConfigField } from '../../proxy';
describe('Metadata component', () => { describe('Metadata component', () => {
@@ -95,6 +96,16 @@ describe('Metadata component', () => {
describe('Viewer Metadata', () => { describe('Viewer Metadata', () => {
beforeAll(async() => {
await setConfigField('content-metadata', JSON.stringify({
presets: {
default: {
'exif:exif': '*'
}
}
}));
});
beforeEach(async (done) => { beforeEach(async (done) => {
viewerPage.viewFile(pngFileModel.name); viewerPage.viewFile(pngFileModel.name);
viewerPage.checkFileIsLoaded(); viewerPage.checkFileIsLoaded();
@@ -194,9 +205,10 @@ describe('Metadata component', () => {
await metadataViewPage.clickUpdatePropertyIcon('properties.cm:description'); await metadataViewPage.clickUpdatePropertyIcon('properties.cm:description');
expect(metadataViewPage.getPropertyText('properties.cm:description')).toEqual('example description'); expect(metadataViewPage.getPropertyText('properties.cm:description')).toEqual('example description');
viewerPage.clickCloseButton(); await viewerPage.clickCloseButton();
contentServicesPage.waitForTableBody();
viewerPage.viewFile('exampleText.png'); viewerPage.viewFile(resources.Files.ADF_DOCUMENTS.PNG.file_name);
viewerPage.clickInfoButton(); viewerPage.clickInfoButton();
viewerPage.checkInfoSideBarIsDisplayed(); viewerPage.checkInfoSideBarIsDisplayed();
metadataViewPage.clickOnPropertiesTab(); metadataViewPage.clickOnPropertiesTab();
@@ -260,6 +272,7 @@ describe('Metadata component', () => {
browser.controlFlow().execute(async () => { browser.controlFlow().execute(async () => {
await metadataViewPage.editIconClick(); await metadataViewPage.editIconClick();
metadataViewPage.clickEditPropertyIcons('properties.exif:software'); metadataViewPage.clickEditPropertyIcons('properties.exif:software');
metadataViewPage.enterPropertyText('properties.exif:software', 'test custom text software'); metadataViewPage.enterPropertyText('properties.exif:software', 'test custom text software');
await metadataViewPage.clickUpdatePropertyIcon('properties.exif:software'); await metadataViewPage.clickUpdatePropertyIcon('properties.exif:software');
@@ -303,6 +316,7 @@ describe('Metadata component', () => {
browser.controlFlow().execute(async () => { browser.controlFlow().execute(async () => {
await metadataViewPage.editIconClick(); await metadataViewPage.editIconClick();
metadataViewPage.clickEditPropertyIcons('name'); metadataViewPage.clickEditPropertyIcons('name');
metadataViewPage.enterPropertyText('name', 'newnameFolder'); metadataViewPage.enterPropertyText('name', 'newnameFolder');
await metadataViewPage.clickClearPropertyIcon('name'); await metadataViewPage.clickClearPropertyIcon('name');

24
e2e/proxy.ts Normal file
View File

@@ -0,0 +1,24 @@
/*!
* @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 { browser } from 'protractor';
export async function setConfigField(field: string, value: string) {
return browser.executeScript(
`window.adf.setConfigField('${field}', '${value}');`
);
}

View File

@@ -16,75 +16,112 @@
*/ */
import { import {
Component, Component,
ChangeDetectionStrategy, ChangeDetectionStrategy,
ViewEncapsulation, ViewEncapsulation,
OnInit, OnInit,
Input, Input,
ElementRef ElementRef,
OnDestroy
} from '@angular/core'; } from '@angular/core';
import { NodeEntry } from '@alfresco/js-api'; import { NodeEntry, Node, Site } from '@alfresco/js-api';
import { ShareDataRow } from '../../data/share-data-row.model'; import { ShareDataRow } from '../../data/share-data-row.model';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { BehaviorSubject, Subscription } from 'rxjs';
@Component({ @Component({
selector: 'adf-library-name-column', selector: 'adf-library-name-column',
template: ` template: `
<span title="{{ displayTooltip }}" (click)="onClick()"> <span title="{{ displayTooltip$ | async }}" (click)="onClick()">
{{ displayText }} {{ displayText$ | async }}
</span> </span>
`, `,
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
host: { class: 'adf-datatable-cell adf-datatable-link adf-library-name-column' } host: {
class: 'adf-datatable-cell adf-datatable-link adf-library-name-column'
}
}) })
export class LibraryNameColumnComponent implements OnInit { export class LibraryNameColumnComponent implements OnInit, OnDestroy {
@Input() @Input()
context: any; context: any;
displayTooltip: string; displayTooltip$ = new BehaviorSubject<string>('');
displayText: string; displayText$ = new BehaviorSubject<string>('');
node: NodeEntry; node: NodeEntry;
constructor(private element: ElementRef) {} private sub: Subscription;
ngOnInit() { constructor(
this.node = this.context.row.node; private element: ElementRef,
const rows: Array<ShareDataRow> = this.context.data.rows || []; private alfrescoApiService: AlfrescoApiService
if (this.node && this.node.entry) { ) {}
this.displayText = this.makeLibraryTitle(this.node.entry, rows);
this.displayTooltip = this.makeLibraryTooltip(this.node.entry); ngOnInit() {
this.updateValue();
this.sub = this.alfrescoApiService.nodeUpdated.subscribe(
(node: Node) => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
if (entry === node) {
row.node = { entry };
this.updateValue();
}
}
}
);
} }
}
onClick() { protected updateValue() {
this.element.nativeElement.dispatchEvent( this.node = this.context.row.node;
new CustomEvent('name-click', { const rows: Array<ShareDataRow> = this.context.data.rows || [];
bubbles: true, if (this.node && this.node.entry) {
detail: { this.displayText$.next(
node: this.node this.makeLibraryTitle(<any> this.node.entry, rows)
);
this.displayTooltip$.next(this.makeLibraryTooltip(this.node.entry));
} }
})
);
}
makeLibraryTooltip(library: any): string {
const { description, title } = library;
return description || title || '';
}
makeLibraryTitle(library: any, rows: Array<ShareDataRow>): string {
const entries = rows.map((r: ShareDataRow) => r.node.entry);
const { title, id } = library;
let isDuplicate = false;
if (entries) {
isDuplicate = entries.some((entry: any) => {
return entry.id !== id && entry.title === title;
});
} }
return isDuplicate ? `${title} (${id})` : `${title}`; onClick() {
} this.element.nativeElement.dispatchEvent(
new CustomEvent('name-click', {
bubbles: true,
detail: {
node: this.node
}
})
);
}
makeLibraryTooltip(library: any): string {
const { description, title } = library;
return description || title || '';
}
makeLibraryTitle(library: Site, rows: Array<ShareDataRow>): string {
const entries = rows.map((row: ShareDataRow) => row.node.entry);
const { title, id } = library;
let isDuplicate = false;
if (entries) {
isDuplicate = entries.some((entry: any) => {
return entry.id !== id && entry.title === title;
});
}
return isDuplicate ? `${title} (${id})` : `${title}`;
}
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
this.sub = null;
}
}
} }

View File

@@ -39,39 +39,59 @@ describe('LibraryNameColumnComponent', () => {
component.context = { component.context = {
row: { node: { entry: { role: 'SiteManager' } } } row: { node: { entry: { role: 'SiteManager' } } }
}; };
let value = '';
component.displayText$.subscribe((val) => value = val);
fixture.detectChanges(); fixture.detectChanges();
expect(component.displayText).toBe('LIBRARY.ROLE.MANAGER'); expect(value).toBe('LIBRARY.ROLE.MANAGER');
}); });
it('should render Collaborator', () => { it('should render Collaborator', () => {
component.context = { component.context = {
row: { node: { entry: { role: 'SiteCollaborator' } } } row: { node: { entry: { role: 'SiteCollaborator' } } }
}; };
let value = '';
component.displayText$.subscribe((val) => value = val);
fixture.detectChanges(); fixture.detectChanges();
expect(component.displayText).toBe('LIBRARY.ROLE.COLLABORATOR'); expect(value).toBe('LIBRARY.ROLE.COLLABORATOR');
}); });
it('should render Contributor', () => { it('should render Contributor', () => {
component.context = { component.context = {
row: { node: { entry: { role: 'SiteContributor' } } } row: { node: { entry: { role: 'SiteContributor' } } }
}; };
let value = '';
component.displayText$.subscribe((val) => value = val);
fixture.detectChanges(); fixture.detectChanges();
expect(component.displayText).toBe('LIBRARY.ROLE.CONTRIBUTOR'); expect(value).toBe('LIBRARY.ROLE.CONTRIBUTOR');
}); });
it('should render Consumer', () => { it('should render Consumer', () => {
component.context = { component.context = {
row: { node: { entry: { role: 'SiteConsumer' } } } row: { node: { entry: { role: 'SiteConsumer' } } }
}; };
let value = '';
component.displayText$.subscribe((val) => value = val);
fixture.detectChanges(); fixture.detectChanges();
expect(component.displayText).toBe('LIBRARY.ROLE.CONSUMER'); expect(value).toBe('LIBRARY.ROLE.CONSUMER');
}); });
it('should not render text for unknown', () => { it('should not render text for unknown', () => {
component.context = { component.context = {
row: { node: { entry: { role: 'ROLE' } } } row: { node: { entry: { role: 'ROLE' } } }
}; };
let value = '';
component.displayText$.subscribe((val) => value = val);
fixture.detectChanges(); fixture.detectChanges();
expect(component.displayText).toBe(''); expect(value).toBe('');
}); });
}); });

View File

@@ -15,44 +15,84 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, OnInit, Input } from '@angular/core'; import {
Component,
OnInit,
Input,
ChangeDetectionStrategy,
ViewEncapsulation,
OnDestroy
} from '@angular/core';
import { Subscription, BehaviorSubject } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Node, SiteEntry, Site } from '@alfresco/js-api';
import { ShareDataRow } from '../../data/share-data-row.model';
@Component({ @Component({
selector: 'adf-library-role-column', selector: 'adf-library-role-column',
template: ` template: `
<span title="{{ displayText | translate }}"> <span title="{{ (displayText$ | async) | translate }}">
{{ displayText | translate }} {{ (displayText$ | async) | translate }}
</span> </span>
`, `,
host: { class: 'adf-library-role-column' } changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-library-role-column' }
}) })
export class LibraryRoleColumnComponent implements OnInit { export class LibraryRoleColumnComponent implements OnInit, OnDestroy {
@Input() @Input()
context: any; context: any;
displayText: string; displayText$ = new BehaviorSubject<string>('');
ngOnInit() { private sub: Subscription;
const node = this.context.row.node;
if (node && node.entry) { constructor(private api: AlfrescoApiService) {}
const role: string = node.entry.role;
switch (role) { ngOnInit() {
case 'SiteManager': this.updateValue();
this.displayText = 'LIBRARY.ROLE.MANAGER';
break; this.sub = this.api.nodeUpdated.subscribe((node: Node) => {
case 'SiteCollaborator': const row: ShareDataRow = this.context.row;
this.displayText = 'LIBRARY.ROLE.COLLABORATOR'; if (row) {
break; const { entry } = row.node;
case 'SiteContributor':
this.displayText = 'LIBRARY.ROLE.CONTRIBUTOR'; if (entry === node) {
break; row.node = { entry };
case 'SiteConsumer': this.updateValue();
this.displayText = 'LIBRARY.ROLE.CONSUMER'; }
break; }
default: });
this.displayText = ''; }
break;
} protected updateValue() {
const node: SiteEntry = this.context.row.node;
if (node && node.entry) {
const role: string = node.entry.role;
switch (role) {
case Site.RoleEnum.SiteManager:
this.displayText$.next('LIBRARY.ROLE.MANAGER');
break;
case Site.RoleEnum.SiteCollaborator:
this.displayText$.next('LIBRARY.ROLE.COLLABORATOR');
break;
case Site.RoleEnum.SiteContributor:
this.displayText$.next('LIBRARY.ROLE.CONTRIBUTOR');
break;
case Site.RoleEnum.SiteConsumer:
this.displayText$.next('LIBRARY.ROLE.CONSUMER');
break;
default:
this.displayText$.next('');
break;
}
}
}
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
this.sub = null;
}
} }
}
} }

View File

@@ -15,42 +15,73 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Subscription, BehaviorSubject } from 'rxjs';
import { Node, Site, SiteEntry } from '@alfresco/js-api';
import { ShareDataRow } from '../../data/share-data-row.model';
@Component({ @Component({
selector: 'adf-library-status-column', selector: 'adf-library-status-column',
template: ` template: `
<span title="{{ displayText | translate }}"> <span title="{{ (displayText$ | async) | translate }}">
{{ displayText | translate }} {{ (displayText$ | async) | translate }}
</span> </span>
`, `,
host: { class: 'adf-library-status-column' } host: { class: 'adf-library-status-column' }
}) })
export class LibraryStatusColumnComponent implements OnInit { export class LibraryStatusColumnComponent implements OnInit, OnDestroy {
@Input() @Input()
context: any; context: any;
displayText: string; displayText$ = new BehaviorSubject<string>('');
ngOnInit() { private sub: Subscription;
const node = this.context.row.node;
if (node && node.entry) {
const visibility: string = node.entry.visibility;
switch (visibility.toUpperCase()) { constructor(private api: AlfrescoApiService) {}
case 'PUBLIC':
this.displayText = 'LIBRARY.VISIBILITY.PUBLIC'; ngOnInit() {
break; this.updateValue();
case 'PRIVATE':
this.displayText = 'LIBRARY.VISIBILITY.PRIVATE'; this.sub = this.api.nodeUpdated.subscribe((node: Node) => {
break; const row: ShareDataRow = this.context.row;
case 'MODERATED': if (row) {
this.displayText = 'LIBRARY.VISIBILITY.MODERATED'; const { entry } = row.node;
break;
default: if (entry === node) {
this.displayText = 'UNKNOWN'; row.node = { entry };
break; this.updateValue();
} }
}
});
}
protected updateValue() {
const node: SiteEntry = this.context.row.node;
if (node && node.entry) {
const visibility: string = node.entry.visibility;
switch (visibility) {
case Site.VisibilityEnum.PUBLIC:
this.displayText$.next('LIBRARY.VISIBILITY.PUBLIC');
break;
case Site.VisibilityEnum.PRIVATE:
this.displayText$.next('LIBRARY.VISIBILITY.PRIVATE');
break;
case Site.VisibilityEnum.MODERATED:
this.displayText$.next('LIBRARY.VISIBILITY.MODERATED');
break;
default:
this.displayText$.next('UNKNOWN');
break;
}
}
}
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
this.sub = null;
}
} }
}
} }

View File

@@ -16,50 +16,81 @@
*/ */
import { import {
Component, Component,
Input, Input,
OnInit, OnInit,
ChangeDetectionStrategy, ChangeDetectionStrategy,
ViewEncapsulation, ViewEncapsulation,
ElementRef ElementRef,
OnDestroy
} from '@angular/core'; } from '@angular/core';
import { NodeEntry } from '@alfresco/js-api'; import { NodeEntry } from '@alfresco/js-api';
import { BehaviorSubject, Subscription } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api';
import { ShareDataRow } from '../../data/share-data-row.model';
@Component({ @Component({
selector: 'adf-name-column', selector: 'adf-name-column',
template: ` template: `
<span title="{{ node | adfNodeNameTooltip }}" (click)="onClick()"> <span title="{{ node | adfNodeNameTooltip }}" (click)="onClick()">
{{ displayText }} {{ displayText$ | async }}
</span> </span>
`, `,
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
host: { class: 'adf-datatable-cell adf-datatable-link adf-name-column' } host: { class: 'adf-datatable-cell adf-datatable-link adf-name-column' }
}) })
export class NameColumnComponent implements OnInit { export class NameColumnComponent implements OnInit, OnDestroy {
@Input() @Input()
context: any; context: any;
displayText: string; displayText$ = new BehaviorSubject<string>('');
node: NodeEntry; node: NodeEntry;
constructor(private element: ElementRef) {} private sub: Subscription;
ngOnInit() { constructor(private element: ElementRef, private alfrescoApiService: AlfrescoApiService) {}
this.node = this.context.row.node;
if (this.node && this.node.entry) { ngOnInit() {
this.displayText = this.node.entry.name || this.node.entry.id; this.updateValue();
this.sub = this.alfrescoApiService.nodeUpdated.subscribe((node: Node) => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
if (entry === node) {
row.node = { entry };
this.updateValue();
}
}
});
} }
}
onClick() { protected updateValue() {
this.element.nativeElement.dispatchEvent( this.node = this.context.row.node;
new CustomEvent('name-click', {
bubbles: true, if (this.node && this.node.entry) {
detail: { this.displayText$.next(this.node.entry.name || this.node.entry.id);
node: this.node
} }
}) }
);
} onClick() {
this.element.nativeElement.dispatchEvent(
new CustomEvent('name-click', {
bubbles: true,
detail: {
node: this.node
}
})
);
}
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
this.sub = null;
}
}
} }

View File

@@ -32,6 +32,11 @@ export class ShareDataRow implements DataRow {
return this.obj; return this.obj;
} }
set node(value: NodeEntry) {
this.obj = value;
this.cache = {};
}
constructor(private obj: NodeEntry, constructor(private obj: NodeEntry,
private contentService: ContentService, private contentService: ContentService,
private permissionsStyle: PermissionStyleModel[], private permissionsStyle: PermissionStyleModel[],

View File

@@ -16,15 +16,18 @@
*/ */
import { DateCellComponent } from './date-cell.component'; import { DateCellComponent } from './date-cell.component';
import { Subject } from 'rxjs';
describe('DataTableCellComponent', () => { describe('DataTableCellComponent', () => {
it('should use medium format by default', () => { it('should use medium format by default', () => {
const component = new DateCellComponent(null); const component = new DateCellComponent(null, null);
expect(component.format).toBe('medium'); expect(component.format).toBe('medium');
}); });
it('should use column format', () => { it('should use column format', () => {
const component = new DateCellComponent(null); const component = new DateCellComponent(null, <any> {
nodeUpdated: new Subject<any>()
});
component.column = { component.column = {
key: 'created', key: 'created',
type: 'date', type: 'date',

View File

@@ -15,23 +15,38 @@
* limitations under the License. * limitations under the License.
*/ */
import { ChangeDetectionStrategy, Component, Input, OnInit, ViewEncapsulation } from '@angular/core'; import {
ChangeDetectionStrategy,
Component,
Input,
OnInit,
ViewEncapsulation,
OnDestroy
} from '@angular/core';
import { DataColumn } from '../../data/data-column.model'; import { DataColumn } from '../../data/data-column.model';
import { DataRow } from '../../data/data-row.model'; import { DataRow } from '../../data/data-row.model';
import { DataTableAdapter } from '../../data/datatable-adapter'; import { DataTableAdapter } from '../../data/datatable-adapter';
import { AlfrescoApiService } from '../../../services/alfresco-api.service';
import { Subscription, BehaviorSubject } from 'rxjs';
import { Node } from '@alfresco/js-api';
@Component({ @Component({
selector: 'adf-datatable-cell', selector: 'adf-datatable-cell',
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
template: ` template: `
<ng-container> <ng-container>
<span [attr.aria-label]="value" [title]="tooltip" class="adf-datatable-cell-value">{{value}}</span> <span
</ng-container>`, [attr.aria-label]="value$ | async"
[title]="tooltip"
class="adf-datatable-cell-value"
>{{ value$ | async }}</span
>
</ng-container>
`,
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
host: { class: 'adf-datatable-cell' } host: { class: 'adf-datatable-cell' }
}) })
export class DataTableCellComponent implements OnInit { export class DataTableCellComponent implements OnInit, OnDestroy {
@Input() @Input()
data: DataTableAdapter; data: DataTableAdapter;
@@ -41,20 +56,46 @@ export class DataTableCellComponent implements OnInit {
@Input() @Input()
row: DataRow; row: DataRow;
@Input() value$ = new BehaviorSubject<any>('');
value: any;
@Input() @Input()
tooltip: string; tooltip: string;
private sub: Subscription;
constructor(protected alfrescoApiService: AlfrescoApiService) {}
ngOnInit() { ngOnInit() {
if (!this.value && this.column && this.column.key && this.row && this.data) { this.updateValue();
this.value = this.data.getValue(this.row, this.column);
this.sub = this.alfrescoApiService.nodeUpdated.subscribe((node: Node) => {
if (this.row) {
const { entry } = this.row['node'];
if (entry === node) {
this.row['node'] = { entry };
this.updateValue();
}
}
});
}
protected updateValue() {
if (this.column && this.column.key && this.row && this.data) {
const value = this.data.getValue(this.row, this.column);
this.value$.next(value);
if (!this.tooltip) { if (!this.tooltip) {
this.tooltip = this.value; this.tooltip = value;
} }
} }
} }
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
this.sub = null;
}
}
} }

View File

@@ -21,19 +21,27 @@ import {
UserPreferencesService, UserPreferencesService,
UserPreferenceValues UserPreferenceValues
} from '../../../services/user-preferences.service'; } from '../../../services/user-preferences.service';
import { AlfrescoApiService } from '../../../services/alfresco-api.service';
@Component({ @Component({
selector: 'adf-date-cell', selector: 'adf-date-cell',
template: ` template: `
<ng-container> <ng-container>
<span title="{{ tooltip | date:'medium' }}" *ngIf="format === 'timeAgo' else standard_date" [attr.aria-label]=" value | adfTimeAgo: currentLocale "> <span
{{ value | adfTimeAgo: currentLocale }} [attr.aria-label]="value$ | async | adfTimeAgo: currentLocale"
title="{{ tooltip | date: 'medium' }}"
*ngIf="format === 'timeAgo'; else standard_date"
>
{{ value$ | async | adfTimeAgo: currentLocale }}
</span> </span>
</ng-container> </ng-container>
<ng-template #standard_date> <ng-template #standard_date>
<span [attr.aria-label]=" value | date:format " title="{{ tooltip | date:format }}"> <span
{{ value | date:format }} title="{{ tooltip | date: format }}"
[attr.aria-label]="value$ | async | date: format"
>
{{ value$ | async | date: format }}
</span> </span>
</ng-template> </ng-template>
`, `,
@@ -41,7 +49,7 @@ import {
host: { class: 'adf-date-cell' } host: { class: 'adf-date-cell' }
}) })
export class DateCellComponent extends DataTableCellComponent { export class DateCellComponent extends DataTableCellComponent {
currentLocale; currentLocale: string;
get format(): string { get format(): string {
if (this.column) { if (this.column) {
@@ -50,8 +58,11 @@ export class DateCellComponent extends DataTableCellComponent {
return 'medium'; return 'medium';
} }
constructor(userPreferenceService: UserPreferencesService) { constructor(
super(); userPreferenceService: UserPreferencesService,
alfrescoApiService: AlfrescoApiService
) {
super(alfrescoApiService);
if (userPreferenceService) { if (userPreferenceService) {
userPreferenceService userPreferenceService

View File

@@ -17,15 +17,24 @@
import { Component, ViewEncapsulation } from '@angular/core'; import { Component, ViewEncapsulation } from '@angular/core';
import { DataTableCellComponent } from './datatable-cell.component'; import { DataTableCellComponent } from './datatable-cell.component';
import { AlfrescoApiService } from '../../../services/alfresco-api.service';
@Component({ @Component({
selector: 'adf-filesize-cell', selector: 'adf-filesize-cell',
template: ` template: `
<ng-container> <ng-container>
<span [attr.aria-label]=" value | adfFileSize " [title]="tooltip">{{ value | adfFileSize }}</span> <span
[title]="tooltip"
[attr.aria-label]="value$ | async | adfFileSize"
>{{ value$ | async | adfFileSize }}</span
>
</ng-container> </ng-container>
`, `,
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
host: { class: 'adf-filesize-cell' } host: { class: 'adf-filesize-cell' }
}) })
export class FileSizeCellComponent extends DataTableCellComponent {} export class FileSizeCellComponent extends DataTableCellComponent {
constructor(alfrescoApiService: AlfrescoApiService) {
super(alfrescoApiService);
}
}

View File

@@ -69,12 +69,6 @@ describe('LocationCellComponent', () => {
fixture.destroy(); fixture.destroy();
}); });
it('should set displayText', () => {
fixture.detectChanges();
expect(component.displayText).toBe('location');
});
it('should set tooltip', () => { it('should set tooltip', () => {
fixture.detectChanges(); fixture.detectChanges();
@@ -87,24 +81,32 @@ describe('LocationCellComponent', () => {
expect(component.link).toEqual([ columnData.format , rowData.path.elements[2].id ]); expect(component.link).toEqual([ columnData.format , rowData.path.elements[2].id ]);
}); });
it('should not setup cell when path has no data', () => { it('should not setup cell when path has no data', (done) => {
rowData.path = {}; rowData.path = {};
fixture.detectChanges(); fixture.detectChanges();
expect(component.displayText).toBe('');
expect(component.tooltip).toBeUndefined(); expect(component.tooltip).toBeUndefined();
expect(component.link).toEqual([]); expect(component.link).toEqual([]);
component.value$.subscribe((value) => {
expect(value).toBe('');
done();
});
}); });
it('should not setup cell when path is missing required properties', () => { it('should not setup cell when path is missing required properties', (done) => {
rowData.path = { someProp: '' }; rowData.path = { someProp: '' };
fixture.detectChanges(); fixture.detectChanges();
expect(component.displayText).toBe('');
expect(component.tooltip).toBeUndefined(); expect(component.tooltip).toBeUndefined();
expect(component.link).toEqual([]); expect(component.link).toEqual([]);
component.value$.subscribe((value) => {
expect(value).toBe('');
done();
});
}); });
it('should not setup cell when path data is missing one of the property', () => { it('should not setup cell when path data is missing one of the property', () => {
@@ -112,9 +114,15 @@ describe('LocationCellComponent', () => {
name: 'some-name' name: 'some-name'
}; };
let value = '';
component.value$.subscribe((val) => {
value = val;
});
fixture.detectChanges(); fixture.detectChanges();
expect(component.displayText).toBe(''); expect(value).toBe('');
expect(component.tooltip).toBeUndefined(); expect(component.tooltip).toBeUndefined();
expect(component.link).toEqual([]); expect(component.link).toEqual([]);
@@ -124,7 +132,7 @@ describe('LocationCellComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
expect(component.displayText).toBe(''); expect(value).toBe('');
expect(component.tooltip).toBeUndefined(); expect(component.tooltip).toBeUndefined();
expect(component.link).toEqual([]); expect(component.link).toEqual([]);
}); });

View File

@@ -15,9 +15,16 @@
* limitations under the License. * limitations under the License.
*/ */
import { ChangeDetectionStrategy, Component, Input, OnInit, ViewEncapsulation } from '@angular/core'; import {
ChangeDetectionStrategy,
Component,
Input,
OnInit,
ViewEncapsulation
} from '@angular/core';
import { PathInfoEntity } from '@alfresco/js-api'; import { PathInfoEntity } from '@alfresco/js-api';
import { DataTableCellComponent } from './datatable-cell.component'; import { DataTableCellComponent } from './datatable-cell.component';
import { AlfrescoApiService } from '../../../services/alfresco-api.service';
@Component({ @Component({
selector: 'adf-location-cell', selector: 'adf-location-cell',
@@ -25,7 +32,7 @@ import { DataTableCellComponent } from './datatable-cell.component';
template: ` template: `
<ng-container> <ng-container>
<a href="" [title]="tooltip" [routerLink]="link"> <a href="" [title]="tooltip" [routerLink]="link">
{{ displayText }} {{ value$ | async }}
</a> </a>
</ng-container> </ng-container>
`, `,
@@ -33,28 +40,30 @@ import { DataTableCellComponent } from './datatable-cell.component';
host: { class: 'adf-location-cell' } host: { class: 'adf-location-cell' }
}) })
export class LocationCellComponent extends DataTableCellComponent implements OnInit { export class LocationCellComponent extends DataTableCellComponent implements OnInit {
@Input() @Input()
link: any[]; link: any[];
@Input() constructor(alfrescoApiService: AlfrescoApiService) {
displayText: string = ''; super(alfrescoApiService);
}
/** @override */ /** @override */
ngOnInit() { ngOnInit() {
if (!this.value && this.column && this.column.key && this.row && this.data) { if (this.column && this.column.key && this.row && this.data) {
const path: PathInfoEntity = this.data.getValue(this.row, this.column); const path: PathInfoEntity = this.data.getValue(
this.row,
this.column
);
if (path && path.name && path.elements) { if (path && path.name && path.elements) {
this.value = path; this.value$.next(path.name.split('/').pop());
this.displayText = path.name.split('/').pop();
if (!this.tooltip) { if (!this.tooltip) {
this.tooltip = path.name; this.tooltip = path.name;
} }
const parent = path.elements[path.elements.length - 1]; const parent = path.elements[path.elements.length - 1];
this.link = [ this.column.format, parent.id ]; this.link = [this.column.format, parent.id];
} }
} }
} }

View File

@@ -0,0 +1,37 @@
/*!
* @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 { Injectable } from '@angular/core';
import { AppConfigService } from '../app-config/app-config.service';
@Injectable({
providedIn: 'root'
})
export class CoreAutomationService {
constructor(private appConfigService: AppConfigService) {
}
setup() {
const adfProxy = window['adf'] || {};
adfProxy.setConfigField = (field: string, value: string) => {
this.appConfigService.config[field] = JSON.parse(value);
};
window['adf'] = adfProxy;
}
}

View File

@@ -53,3 +53,4 @@ export * from './login-dialog.service';
export * from './external-alfresco-api.service'; export * from './external-alfresco-api.service';
export * from './jwt-helper.service'; export * from './jwt-helper.service';
export * from './download-zip.service'; export * from './download-zip.service';
export * from './automation.service';