mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
revert changes (#3387)
This commit is contained in:
committed by
Denys Vuika
parent
591bec5bdd
commit
c5936e7db0
@@ -110,7 +110,6 @@
|
|||||||
</button>
|
</button>
|
||||||
<button mat-icon-button
|
<button mat-icon-button
|
||||||
[disabled]="!documentList.selection.length"
|
[disabled]="!documentList.selection.length"
|
||||||
(toggle)="documentList.reload()"
|
|
||||||
#favorite="adfFavorite"
|
#favorite="adfFavorite"
|
||||||
[adf-node-favorite]="documentList.selection"
|
[adf-node-favorite]="documentList.selection"
|
||||||
matTooltip="{{ 'DOCUMENT_LIST.TOOLBAR.FAVORITES' | translate }}">
|
matTooltip="{{ 'DOCUMENT_LIST.TOOLBAR.FAVORITES' | translate }}">
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SimpleChange } from '@angular/core';
|
||||||
import { fakeAsync, tick } from '@angular/core/testing';
|
import { fakeAsync, tick } from '@angular/core/testing';
|
||||||
import { NodeFavoriteDirective } from './node-favorite.directive';
|
import { NodeFavoriteDirective } from './node-favorite.directive';
|
||||||
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
|
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
|
||||||
@@ -31,7 +32,139 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
directive = new NodeFavoriteDirective( alfrescoApiService);
|
directive = new NodeFavoriteDirective( alfrescoApiService);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toggle node as favorite', () => {
|
describe('selection input change event', () => {
|
||||||
|
it('should not call markFavoritesNodes() if input list is empty', () => {
|
||||||
|
spyOn(directive, 'markFavoritesNodes');
|
||||||
|
|
||||||
|
const change = new SimpleChange(null, [], true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
|
||||||
|
expect(directive.markFavoritesNodes).not.toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call markFavoritesNodes() on input change', () => {
|
||||||
|
spyOn(directive, 'markFavoritesNodes');
|
||||||
|
|
||||||
|
let selection = [{ entry: { id: '1', name: 'name1' } }];
|
||||||
|
|
||||||
|
let change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
|
||||||
|
expect(directive.markFavoritesNodes).toHaveBeenCalledWith(selection);
|
||||||
|
|
||||||
|
selection = [
|
||||||
|
{ entry: { id: '1', name: 'name1' } },
|
||||||
|
{ entry: { id: '2', name: 'name2' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
|
||||||
|
expect(directive.markFavoritesNodes).toHaveBeenCalledWith(selection);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reset favorites if selection is empty', fakeAsync(() => {
|
||||||
|
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
|
let selection = [
|
||||||
|
{ entry: { id: '1', name: 'name1' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
let change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(directive.hasFavorites()).toBe(true);
|
||||||
|
|
||||||
|
change = new SimpleChange(null, [], true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(directive.hasFavorites()).toBe(false);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('markFavoritesNodes()', () => {
|
||||||
|
let favoritesApiSpy;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
favoritesApiSpy = spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite')
|
||||||
|
.and.returnValue(Promise.resolve());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should check each selected node if it is a favorite', fakeAsync(() => {
|
||||||
|
const selection = [
|
||||||
|
{ entry: { id: '1', name: 'name1' } },
|
||||||
|
{ entry: { id: '2', name: 'name2' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
let change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
|
||||||
|
tick();
|
||||||
|
expect(favoritesApiSpy.calls.count()).toBe(2);
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not check processed node when another is unselected', fakeAsync(() => {
|
||||||
|
let selection = [
|
||||||
|
{ entry: { id: '1', name: 'name1' } },
|
||||||
|
{ entry: { id: '2', name: 'name2' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
let change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
|
||||||
|
tick();
|
||||||
|
expect(directive.favorites.length).toBe(2);
|
||||||
|
expect(favoritesApiSpy.calls.count()).toBe(2);
|
||||||
|
|
||||||
|
favoritesApiSpy.calls.reset();
|
||||||
|
|
||||||
|
selection = [
|
||||||
|
{ entry: { id: '2', name: 'name2' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
|
||||||
|
tick();
|
||||||
|
expect(directive.favorites.length).toBe(1);
|
||||||
|
expect(favoritesApiSpy).not.toHaveBeenCalled();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not check processed nodes when another is selected', fakeAsync(() => {
|
||||||
|
let selection = [
|
||||||
|
{ entry: { id: '1', name: 'name1' } },
|
||||||
|
{ entry: { id: '2', name: 'name2' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
let change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(directive.favorites.length).toBe(2);
|
||||||
|
expect(favoritesApiSpy.calls.count()).toBe(2);
|
||||||
|
|
||||||
|
favoritesApiSpy.calls.reset();
|
||||||
|
|
||||||
|
selection = [
|
||||||
|
{ entry: { id: '1', name: 'name1' } },
|
||||||
|
{ entry: { id: '2', name: 'name2' } },
|
||||||
|
{ entry: { id: '3', name: 'name3' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(directive.favorites.length).toBe(3);
|
||||||
|
expect(favoritesApiSpy.calls.count()).toBe(1);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toggleFavorite()', () => {
|
||||||
let removeFavoriteSpy;
|
let removeFavoriteSpy;
|
||||||
let addFavoriteSpy;
|
let addFavoriteSpy;
|
||||||
|
|
||||||
@@ -46,7 +179,8 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not perform action if favorites collection is empty', fakeAsync(() => {
|
it('should not perform action if favorites collection is empty', fakeAsync(() => {
|
||||||
directive.selection = [];
|
let change = new SimpleChange(null, [], true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
directive.toggleFavorite();
|
directive.toggleFavorite();
|
||||||
@@ -58,7 +192,7 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
it('should call addFavorite() if none is a favorite', () => {
|
it('should call addFavorite() if none is a favorite', () => {
|
||||||
addFavoriteSpy.and.returnValue(Promise.resolve());
|
addFavoriteSpy.and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
directive.selection = [
|
directive.favorites = [
|
||||||
{ entry: { id: '1', name: 'name1', isFavorite: false } },
|
{ entry: { id: '1', name: 'name1', isFavorite: false } },
|
||||||
{ entry: { id: '2', name: 'name2', isFavorite: false } }
|
{ entry: { id: '2', name: 'name2', isFavorite: false } }
|
||||||
];
|
];
|
||||||
@@ -71,7 +205,7 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
it('should call addFavorite() on node that is not a favorite in selection', () => {
|
it('should call addFavorite() on node that is not a favorite in selection', () => {
|
||||||
addFavoriteSpy.and.returnValue(Promise.resolve());
|
addFavoriteSpy.and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
directive.selection = [
|
directive.favorites = [
|
||||||
{ entry: { id: '1', name: 'name1', isFile: true, isFolder: false, isFavorite: false } },
|
{ entry: { id: '1', name: 'name1', isFile: true, isFolder: false, isFavorite: false } },
|
||||||
{ entry: { id: '2', name: 'name2', isFile: true, isFolder: false, isFavorite: true } }
|
{ entry: { id: '2', name: 'name2', isFile: true, isFolder: false, isFavorite: true } }
|
||||||
];
|
];
|
||||||
@@ -88,7 +222,7 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
it('should call removeFavoriteSite() if all are favorites', () => {
|
it('should call removeFavoriteSite() if all are favorites', () => {
|
||||||
removeFavoriteSpy.and.returnValue(Promise.resolve());
|
removeFavoriteSpy.and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
directive.selection = [
|
directive.favorites = [
|
||||||
{ entry: { id: '1', name: 'name1', isFavorite: true } },
|
{ entry: { id: '1', name: 'name1', isFavorite: true } },
|
||||||
{ entry: { id: '2', name: 'name2', isFavorite: true } }
|
{ entry: { id: '2', name: 'name2', isFavorite: true } }
|
||||||
];
|
];
|
||||||
@@ -102,7 +236,7 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
removeFavoriteSpy.and.returnValue(Promise.resolve());
|
removeFavoriteSpy.and.returnValue(Promise.resolve());
|
||||||
spyOn(directive.toggle, 'emit');
|
spyOn(directive.toggle, 'emit');
|
||||||
|
|
||||||
directive.selection = [
|
directive.favorites = [
|
||||||
{ entry: { id: '1', name: 'name1', isFavorite: true } }
|
{ entry: { id: '1', name: 'name1', isFavorite: true } }
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -116,7 +250,7 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
addFavoriteSpy.and.returnValue(Promise.resolve());
|
addFavoriteSpy.and.returnValue(Promise.resolve());
|
||||||
spyOn(directive.toggle, 'emit');
|
spyOn(directive.toggle, 'emit');
|
||||||
|
|
||||||
directive.selection = [
|
directive.favorites = [
|
||||||
{ entry: { id: '1', name: 'name1', isFavorite: false } }
|
{ entry: { id: '1', name: 'name1', isFavorite: false } }
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -130,7 +264,7 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
removeFavoriteSpy.and.returnValue(Promise.reject('error'));
|
removeFavoriteSpy.and.returnValue(Promise.reject('error'));
|
||||||
spyOn(directive.error, 'emit');
|
spyOn(directive.error, 'emit');
|
||||||
|
|
||||||
directive.selection = [
|
directive.favorites = [
|
||||||
{ entry: { id: '1', name: 'name1', isFavorite: true } }
|
{ entry: { id: '1', name: 'name1', isFavorite: true } }
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -144,7 +278,7 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
addFavoriteSpy.and.returnValue(Promise.reject('error'));
|
addFavoriteSpy.and.returnValue(Promise.reject('error'));
|
||||||
spyOn(directive.error, 'emit');
|
spyOn(directive.error, 'emit');
|
||||||
|
|
||||||
directive.selection = [
|
directive.favorites = [
|
||||||
{ entry: { id: '1', name: 'name1', isFavorite: false } }
|
{ entry: { id: '1', name: 'name1', isFavorite: false } }
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -153,11 +287,67 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
|
|
||||||
expect(directive.error.emit).toHaveBeenCalledWith('error');
|
expect(directive.error.emit).toHaveBeenCalledWith('error');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should set isFavorites items to false', fakeAsync(() => {
|
||||||
|
removeFavoriteSpy.and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
|
directive.favorites = [
|
||||||
|
{ entry: { id: '1', name: 'name1', isFavorite: true } }
|
||||||
|
];
|
||||||
|
|
||||||
|
directive.toggleFavorite();
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(directive.hasFavorites()).toBe(false);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should set isFavorites items to true', fakeAsync(() => {
|
||||||
|
addFavoriteSpy.and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
|
directive.favorites = [
|
||||||
|
{ entry: { id: '1', name: 'name1', isFavorite: false } }
|
||||||
|
];
|
||||||
|
|
||||||
|
directive.toggleFavorite();
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(directive.hasFavorites()).toBe(true);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getFavorite()', () => {
|
||||||
|
it('should process node as favorite', fakeAsync(() => {
|
||||||
|
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
|
const selection = [
|
||||||
|
{ entry: { id: '1', name: 'name1' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
let change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(directive.favorites[0].entry.isFavorite).toBe(true);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not process node as favorite', fakeAsync(() => {
|
||||||
|
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.reject({}));
|
||||||
|
|
||||||
|
const selection = [
|
||||||
|
{ entry: { id: '1', name: 'name1' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
let change = new SimpleChange(null, selection, true);
|
||||||
|
directive.ngOnChanges({'selection': change});
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(directive.favorites[0].entry.isFavorite).toBe(false);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('hasFavorites()', () => {
|
describe('hasFavorites()', () => {
|
||||||
it('should return false when favorites collection is empty', () => {
|
it('should return false when favorites collection is empty', () => {
|
||||||
directive.selection = [];
|
directive.favorites = [];
|
||||||
|
|
||||||
const hasFavorites = directive.hasFavorites();
|
const hasFavorites = directive.hasFavorites();
|
||||||
|
|
||||||
@@ -165,7 +355,7 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return false when some are not favorite', () => {
|
it('should return false when some are not favorite', () => {
|
||||||
directive.selection = [
|
directive.favorites = [
|
||||||
{ entry: { id: '1', name: 'name1', isFavorite: true } },
|
{ entry: { id: '1', name: 'name1', isFavorite: true } },
|
||||||
{ entry: { id: '2', name: 'name2', isFavorite: false } }
|
{ entry: { id: '2', name: 'name2', isFavorite: false } }
|
||||||
];
|
];
|
||||||
@@ -176,7 +366,7 @@ describe('NodeFavoriteDirective', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('return true when all are favorite', () => {
|
it('return true when all are favorite', () => {
|
||||||
directive.selection = [
|
directive.favorites = [
|
||||||
{ entry: { id: '1', name: 'name1', isFavorite: true } },
|
{ entry: { id: '1', name: 'name1', isFavorite: true } },
|
||||||
{ entry: { id: '2', name: 'name2', isFavorite: true } }
|
{ entry: { id: '2', name: 'name2', isFavorite: true } }
|
||||||
];
|
];
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
/* tslint:disable:no-input-rename */
|
/* tslint:disable:no-input-rename */
|
||||||
|
|
||||||
import { Directive, EventEmitter, HostListener, Input, Output } from '@angular/core';
|
import { Directive, EventEmitter, HostListener, Input, OnChanges, Output } from '@angular/core';
|
||||||
import { FavoriteBody, MinimalNodeEntity } from 'alfresco-js-api';
|
import { FavoriteBody, MinimalNodeEntity } from 'alfresco-js-api';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
||||||
@@ -28,7 +28,9 @@ import 'rxjs/observable/forkJoin';
|
|||||||
selector: '[adf-node-favorite]',
|
selector: '[adf-node-favorite]',
|
||||||
exportAs: 'adfFavorite'
|
exportAs: 'adfFavorite'
|
||||||
})
|
})
|
||||||
export class NodeFavoriteDirective {
|
export class NodeFavoriteDirective implements OnChanges {
|
||||||
|
favorites: any[] = [];
|
||||||
|
|
||||||
/** Array of nodes to toggle as favorites. */
|
/** Array of nodes to toggle as favorites. */
|
||||||
@Input('adf-node-favorite')
|
@Input('adf-node-favorite')
|
||||||
selection: MinimalNodeEntity[] = [];
|
selection: MinimalNodeEntity[] = [];
|
||||||
@@ -47,15 +49,25 @@ export class NodeFavoriteDirective {
|
|||||||
constructor(private alfrescoApiService: AlfrescoApiService) {
|
constructor(private alfrescoApiService: AlfrescoApiService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleFavorite() {
|
ngOnChanges(changes) {
|
||||||
if (!this.selection.length) {
|
if (!changes.selection.currentValue.length) {
|
||||||
|
this.favorites = [];
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const every = this.selection.every((selected) => selected.entry.isFavorite);
|
this.markFavoritesNodes(changes.selection.currentValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleFavorite() {
|
||||||
|
if (!this.favorites.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const every = this.favorites.every((selected) => selected.entry.isFavorite);
|
||||||
|
|
||||||
if (every) {
|
if (every) {
|
||||||
const batch = this.selection.map((selected) => {
|
const batch = this.favorites.map((selected) => {
|
||||||
// shared files have nodeId
|
// shared files have nodeId
|
||||||
const id = selected.entry.nodeId || selected.entry.id;
|
const id = selected.entry.nodeId || selected.entry.id;
|
||||||
|
|
||||||
@@ -63,30 +75,83 @@ export class NodeFavoriteDirective {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Observable.forkJoin(batch).subscribe(
|
Observable.forkJoin(batch).subscribe(
|
||||||
() => this.toggle.emit(),
|
() => {
|
||||||
|
this.favorites.map(selected => selected.entry.isFavorite = false);
|
||||||
|
this.toggle.emit();
|
||||||
|
},
|
||||||
error => this.error.emit(error)
|
error => this.error.emit(error)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!every) {
|
if (!every) {
|
||||||
const notFavorite = this.selection.filter((node) => !node.entry.isFavorite);
|
const notFavorite = this.favorites.filter((node) => !node.entry.isFavorite);
|
||||||
const body: FavoriteBody[] = notFavorite.map((node) => this.createFavoriteBody(node));
|
const body: FavoriteBody[] = notFavorite.map((node) => this.createFavoriteBody(node));
|
||||||
|
|
||||||
Observable
|
Observable.fromPromise(this.alfrescoApiService.favoritesApi.addFavorite('-me-', <any> body))
|
||||||
.fromPromise(this.alfrescoApiService.favoritesApi.addFavorite('-me-', <any> body))
|
|
||||||
.subscribe(
|
.subscribe(
|
||||||
() => this.toggle.emit(),
|
() => {
|
||||||
|
notFavorite.map(selected => selected.entry.isFavorite = true);
|
||||||
|
this.toggle.emit();
|
||||||
|
},
|
||||||
error => this.error.emit(error)
|
error => this.error.emit(error)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markFavoritesNodes(selection: MinimalNodeEntity[]) {
|
||||||
|
if (selection.length <= this.favorites.length) {
|
||||||
|
const newFavorites = this.reduce(this.favorites, selection);
|
||||||
|
this.favorites = newFavorites;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = this.diff(selection, this.favorites);
|
||||||
|
const batch = this.getProcessBatch(result);
|
||||||
|
|
||||||
|
Observable.forkJoin(batch).subscribe((data) => {
|
||||||
|
this.favorites.push(...data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
hasFavorites(): boolean {
|
hasFavorites(): boolean {
|
||||||
if (!this.selection.length) {
|
if (this.favorites && !this.favorites.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.selection.every((selected) => selected.entry.isFavorite);
|
return this.favorites.every((selected) => selected.entry.isFavorite);
|
||||||
|
}
|
||||||
|
|
||||||
|
private getProcessBatch(selection): any[] {
|
||||||
|
return selection.map((selected: MinimalNodeEntity) => this.getFavorite(selected));
|
||||||
|
}
|
||||||
|
|
||||||
|
private getFavorite(selected: MinimalNodeEntity): Observable<any> {
|
||||||
|
const { name, isFile, isFolder } = selected.entry;
|
||||||
|
// shared files have nodeId
|
||||||
|
const id = (<any> selected).entry.nodeId || selected.entry.id;
|
||||||
|
|
||||||
|
const promise = this.alfrescoApiService.favoritesApi.getFavorite('-me-', id);
|
||||||
|
|
||||||
|
return Observable.from(promise)
|
||||||
|
.map(() => ({
|
||||||
|
entry: {
|
||||||
|
id,
|
||||||
|
isFolder,
|
||||||
|
isFile,
|
||||||
|
name,
|
||||||
|
isFavorite: true
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.catch(() => {
|
||||||
|
return Observable.of({
|
||||||
|
entry: {
|
||||||
|
id,
|
||||||
|
isFolder,
|
||||||
|
isFile,
|
||||||
|
name,
|
||||||
|
isFavorite: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private createFavoriteBody(node): FavoriteBody {
|
private createFavoriteBody(node): FavoriteBody {
|
||||||
@@ -111,4 +176,16 @@ export class NodeFavoriteDirective {
|
|||||||
|
|
||||||
return node.entry.isFile ? 'file' : 'folder';
|
return node.entry.isFile ? 'file' : 'folder';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private diff(list, patch): any[] {
|
||||||
|
const ids = patch.map(item => item.entry.id);
|
||||||
|
|
||||||
|
return list.filter(item => ids.includes(item.entry.id) ? null : item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private reduce(patch, comparator): any[] {
|
||||||
|
const ids = comparator.map(item => item.entry.id);
|
||||||
|
|
||||||
|
return patch.filter(item => ids.includes(item.entry.id) ? item : null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user