[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

@@ -15,44 +15,84 @@
* 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({
selector: 'adf-library-role-column',
template: `
<span title="{{ displayText | translate }}">
{{ displayText | translate }}
</span>
`,
host: { class: 'adf-library-role-column' }
selector: 'adf-library-role-column',
template: `
<span title="{{ (displayText$ | async) | translate }}">
{{ (displayText$ | async) | translate }}
</span>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-library-role-column' }
})
export class LibraryRoleColumnComponent implements OnInit {
@Input()
context: any;
export class LibraryRoleColumnComponent implements OnInit, OnDestroy {
@Input()
context: any;
displayText: string;
displayText$ = new BehaviorSubject<string>('');
ngOnInit() {
const node = this.context.row.node;
if (node && node.entry) {
const role: string = node.entry.role;
switch (role) {
case 'SiteManager':
this.displayText = 'LIBRARY.ROLE.MANAGER';
break;
case 'SiteCollaborator':
this.displayText = 'LIBRARY.ROLE.COLLABORATOR';
break;
case 'SiteContributor':
this.displayText = 'LIBRARY.ROLE.CONTRIBUTOR';
break;
case 'SiteConsumer':
this.displayText = 'LIBRARY.ROLE.CONSUMER';
break;
default:
this.displayText = '';
break;
}
private sub: Subscription;
constructor(private api: AlfrescoApiService) {}
ngOnInit() {
this.updateValue();
this.sub = this.api.nodeUpdated.subscribe((node: Node) => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
if (entry === node) {
row.node = { entry };
this.updateValue();
}
}
});
}
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;
}
}
}
}