-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from kayvanbree/feature/direct-service-communi…
…cations-for-lists Feature/direct service communications for lists
- Loading branch information
Showing
41 changed files
with
392 additions
and
743 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
12 changes: 6 additions & 6 deletions
12
...entity-list/entity-list.component.spec.ts → ...ist/virtual-scroll-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/app/components/virtual-scroll-list/virtual-scroll-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {Component, EventEmitter, Input, OnChanges, OnInit, Output} from '@angular/core'; | ||
import {SpotifyEntityModel} from '../../store/models/spotify-entity.model'; | ||
import {DataSource} from '@angular/cdk/table'; | ||
import {PagedDataSource} from '../../datasources/paged-data-source'; | ||
|
||
@Component({ | ||
selector: 'app-virtual-scroll-list', | ||
templateUrl: './virtual-scroll-list.component.html', | ||
styleUrls: ['./virtual-scroll-list.component.scss'] | ||
}) | ||
export class VirtualScrollListComponent implements OnInit, OnChanges { | ||
/** | ||
* The dataSource this list subscribes to | ||
*/ | ||
@Input() dataSource: PagedDataSource<SpotifyEntityModel>; | ||
|
||
/** | ||
* The displayed colums. | ||
* Columns that can be used: | ||
* - image | ||
* - album-image | ||
* - name | ||
* - popularity | ||
* - album | ||
* - artist | ||
* - duration | ||
* - saved | ||
*/ | ||
@Input() public columns: string[] = ['name']; | ||
|
||
/** | ||
* Emits an event containing the row object and the ids of the rest of the page | ||
*/ | ||
@Output() public rowDoubleClick = new EventEmitter<{ | ||
id: string, | ||
context: string[] | ||
}>(); | ||
|
||
public ngOnInit(): void { | ||
this.dataSource.openPage(0); | ||
} | ||
|
||
public ngOnChanges(): void { | ||
this.dataSource.openPage(0); | ||
} | ||
|
||
public onPageChange(event): void { | ||
this.dataSource.openPage(event.pageIndex); | ||
} | ||
|
||
public onRowClick(event: SpotifyEntityModel) { | ||
this.rowDoubleClick.emit({ | ||
id: event.id, | ||
context: this.dataSource.getIds(), | ||
}); | ||
} | ||
|
||
public trackBy(index, item) { | ||
return item.id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {TrackModel} from '../store/models/track.model'; | ||
import {CollectionViewer} from '@angular/cdk/collections'; | ||
import {BehaviorSubject, Observable} from 'rxjs'; | ||
import {PagedDataSource} from './paged-data-source'; | ||
import {SpotifyEntityModel} from '../store/models/spotify-entity.model'; | ||
import {SpotifyEntityService} from '../store/providers/spotify-entity.service'; | ||
|
||
export class EntityDataSource extends PagedDataSource<SpotifyEntityModel> { | ||
private entities = []; | ||
|
||
private subject = new BehaviorSubject<SpotifyEntityModel[]>(this.entities); | ||
private observable = this.subject.asObservable(); | ||
|
||
constructor( | ||
private entityService: SpotifyEntityService, | ||
private ids: string[], | ||
public type: string, | ||
public pageSize: number, | ||
) { | ||
super(); | ||
this.total = ids.length > 0 ? ids.length : 0; | ||
} | ||
|
||
connect(collectionViewer: CollectionViewer): Observable<TrackModel[] | ReadonlyArray<SpotifyEntityModel>> { | ||
return this.observable; | ||
} | ||
|
||
disconnect(collectionViewer: CollectionViewer): void { | ||
this.subject.complete(); | ||
} | ||
|
||
public openPage(page): void { | ||
const start = page * this.pageSize; | ||
const end = start + this.pageSize; | ||
const pageIds = this.ids.slice(start, end); | ||
this.entityService.getEntities(pageIds, this.type, this.pageSize).subscribe((value: any) => { | ||
this.entities = value[this.type + 's']; | ||
this.subject.next(this.entities); | ||
}); | ||
} | ||
|
||
public getIds(): string[] { | ||
return this.ids; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {BehaviorSubject, Observable} from 'rxjs'; | ||
import {SpotifyEntityModel} from '../store/models/spotify-entity.model'; | ||
import {SpotifyEntityService} from '../store/providers/spotify-entity.service'; | ||
import {PagedDataSource} from './paged-data-source'; | ||
import {CollectionViewer} from '@angular/cdk/collections'; | ||
import {TrackModel} from '../store/models/track.model'; | ||
|
||
export class NestedEntityDataSource extends PagedDataSource<SpotifyEntityModel> { | ||
private entities = []; | ||
|
||
private subject = new BehaviorSubject<SpotifyEntityModel[]>(this.entities); | ||
private observable = this.subject.asObservable(); | ||
|
||
constructor( | ||
private entityService: SpotifyEntityService, | ||
private id: string, | ||
private parentType: string, | ||
public type: string, | ||
public pageSize: number, | ||
) { | ||
super(); | ||
} | ||
|
||
connect(collectionViewer: CollectionViewer): Observable<TrackModel[] | ReadonlyArray<SpotifyEntityModel>> { | ||
return this.observable; | ||
} | ||
|
||
disconnect(collectionViewer: CollectionViewer): void { | ||
this.subject.complete(); | ||
} | ||
|
||
public openPage(page): void { | ||
this.entityService.getNestedEntities(this.id, this.parentType, this.type, page, this.pageSize).subscribe((value: any) => { | ||
this.entities = value.items; | ||
this.total = value.total; | ||
this.subject.next(this.entities); | ||
}); | ||
} | ||
|
||
public getIds(): string[] { | ||
return this.entities.map(x => x.id); | ||
} | ||
} |
Oops, something went wrong.