reload on events (#808)

This commit is contained in:
Cilibiu Bogdan
2018-11-16 17:51:40 +02:00
committed by Suzana Dirla
parent ca67da3657
commit 8b1b7a78cc
3 changed files with 54 additions and 17 deletions
@@ -15,7 +15,7 @@
<app-page-layout-content>
<div class="main-content">
<adf-document-list #documentList acaDocumentList [display]="documentDisplayMode$ | async" [node]="favoriteList"
<adf-document-list #documentList acaDocumentList [display]="documentDisplayMode$ | async" [node]="list"
[loading]="dataIsLoading" selectionMode="single" [navigate]="false" [sorting]="[ 'title', 'asc' ]"
(node-dblclick)="navigateTo($event.detail?.node)" (name-click)="navigateTo($event.detail?.node)">
@@ -39,6 +39,7 @@ import { FavoriteLibrariesComponent } from './favorite-libraries.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { ContentApiService } from '../../services/content-api.service';
import { ExperimentalDirective } from '../../directives/experimental.directive';
import { ContentManagementService } from '../../services/content-management.service';
import { EffectsModule } from '@ngrx/effects';
import { LibraryEffects } from '../../store/effects';
import { of } from 'rxjs';
@@ -50,6 +51,7 @@ describe('LibrariesComponent', () => {
let contentApiService: ContentApiService;
let router: Router;
let page;
let contentManagementService;
beforeEach(() => {
page = {
@@ -73,6 +75,7 @@ describe('LibrariesComponent', () => {
AppConfigPipe,
ExperimentalDirective
],
providers: [ContentManagementService],
schemas: [NO_ERRORS_SCHEMA]
});
@@ -81,6 +84,7 @@ describe('LibrariesComponent', () => {
alfrescoApi = TestBed.get(AlfrescoApiService);
contentApiService = TestBed.get(ContentApiService);
contentManagementService = TestBed.get(ContentManagementService);
alfrescoApi.reset();
router = TestBed.get(Router);
@@ -99,9 +103,9 @@ describe('LibrariesComponent', () => {
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(
of(page)
);
fixture.autoDetectChanges();
fixture.detectChanges();
expect(component.favoriteList).toEqual(page);
expect(component.list).toEqual(page);
expect(component.dataIsLoading).toBe(false);
}));
});
@@ -121,4 +125,28 @@ describe('LibrariesComponent', () => {
expect(router.navigate).toHaveBeenCalledWith(['libraries', 'libraryId']);
});
});
describe('Reload on actions', () => {
beforeEach(() => {
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(
of(page)
);
fixture.detectChanges();
});
it('should reload on libraryDeleted action', () => {
contentManagementService.libraryDeleted.next();
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled();
});
it('should reload on libraryUpdated action', () => {
contentManagementService.libraryUpdated.next();
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled();
});
it('should reload on favoriteLibraryToggle action', () => {
contentManagementService.favoriteLibraryToggle.next();
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled();
});
});
});
@@ -39,7 +39,7 @@ import { PageComponent } from '../page.component';
})
export class FavoriteLibrariesComponent extends PageComponent
implements OnInit {
favoriteList: FavoritePaging;
list: FavoritePaging;
dataIsLoading = true;
isSmallScreen = false;
columns: any[] = [];
@@ -57,21 +57,12 @@ export class FavoriteLibrariesComponent extends PageComponent
ngOnInit() {
super.ngOnInit();
this.contentApiService.getFavoriteLibraries().subscribe(
(favoriteLibraries: FavoritePaging) => {
this.favoriteList = favoriteLibraries;
this.dataIsLoading = false;
},
() => {
this.favoriteList = null;
this.dataIsLoading = false;
}
);
this.getList();
this.subscriptions = this.subscriptions.concat([
this.content.libraryDeleted.subscribe(() => this.reload()),
this.content.libraryUpdated.subscribe(() => this.reload()),
this.content.favoriteLibraryToggle.subscribe(() => this.reload()),
this.content.libraryDeleted.subscribe(() => this.reloadList()),
this.content.libraryUpdated.subscribe(() => this.reloadList()),
this.content.favoriteLibraryToggle.subscribe(() => this.reloadList()),
this.breakpointObserver
.observe([Breakpoints.HandsetPortrait, Breakpoints.HandsetLandscape])
@@ -87,4 +78,22 @@ export class FavoriteLibrariesComponent extends PageComponent
this.store.dispatch(new NavigateLibraryAction(node.entry.guid));
}
}
private getList() {
this.contentApiService.getFavoriteLibraries().subscribe(
(favoriteLibraries: FavoritePaging) => {
this.list = favoriteLibraries;
this.dataIsLoading = false;
},
() => {
this.list = null;
this.dataIsLoading = false;
}
);
}
private reloadList() {
this.reload();
this.getList();
}
}