Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (54 sloc) 2.1 KB
import * as _ from 'lodash'
import {Component} from '@angular/core'
import {Observable} from 'rxjs/Observable'
import {Subscription} from 'rxjs/Subscription'
import {AppStore} from '../../services/app-store'
import {AppStoreSubscriber, IAppStoreSubscriber} from '../../decorators/app-store-subscriber'
import {sortImages, ImageSortBy} from '../../actions/image-list-actions'
@Component({
selector: 'image-detail-list',
template: `
<div class="row expanded">
<div class="small-12 columns">
<image-detail-table
[tableData]="imageList"
[sortBy]="sortBy"
[isAscending]="isAscending"
(toggleTitleSort)="sortByTitle()"
(toggleSizeSort)="sortBySize()"
(toggleDateSort)="sortByDate()"
></image-detail-table>
</div>
</div>
`
})
@AppStoreSubscriber()
export class ImageDetailList implements IAppStoreSubscriber {
public imageList: any[];
private sortBy: ImageSortBy;
private isAscending: boolean = true;
constructor(private appStore: AppStore) {
}
public onInitAppStoreSubscription(source: Observable<any>): Subscription {
return source
.subscribe((state: any) => {
this.sortBy = state.imageData.sortBy;
this.isAscending = state.imageData.isAscending;
this.imageList = _.map(state.imageData.displayedItems, (v: any) => {
return state.imageData.dataSet[v]
})
})
}
public sortByTitle() {
this.appStore.dispatch(sortImages(ImageSortBy.title, this.sortAscending(ImageSortBy.title)))
}
public sortBySize() {
this.appStore.dispatch(sortImages(ImageSortBy.size, this.sortAscending(ImageSortBy.size)))
}
public sortByDate() {
this.appStore.dispatch(sortImages(ImageSortBy.date, this.sortAscending(ImageSortBy.date)))
}
private sortAscending(requestedSortBy: ImageSortBy) {
return this.sortBy === requestedSortBy ? !this.isAscending : true
}
}
You can’t perform that action at this time.