59695: Browse-By-Starts-With components and switcher

This commit is contained in:
Kristof De Langhe
2019-02-11 17:30:05 +01:00
parent 8e9116f14f
commit b956dbfe08
14 changed files with 102 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Component, EventEmitter, Injector, Input, OnInit, Output } from '@angular/core';
import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list';
import { PaginationComponentOptions } from '../pagination/pagination-component-options.model';
@@ -6,6 +6,12 @@ import { SortDirection, SortOptions } from '../../core/cache/models/sort-options
import { fadeIn, fadeInOut } from '../animations/fade';
import { Observable } from 'rxjs';
import { ListableObject } from '../object-collection/shared/listable-object.model';
import { getStartsWithComponent } from './browse-by-starts-with/browse-by-starts-with-decorator';
export enum BrowseByStartsWithType {
text = 'Text',
date = 'Date'
}
@Component({
selector: 'ds-browse-by',
@@ -19,7 +25,7 @@ import { ListableObject } from '../object-collection/shared/listable-object.mode
/**
* Component to display a browse-by page for any ListableObject
*/
export class BrowseByComponent {
export class BrowseByComponent implements OnInit {
/**
* The i18n message to display as title
*/
@@ -40,6 +46,10 @@ export class BrowseByComponent {
*/
@Input() sortConfig: SortOptions;
@Input() type = BrowseByStartsWithType.text;
@Input() startsWithOptions = [];
@Input() enableArrows = false;
@Input() hideGear = false;
@@ -52,11 +62,17 @@ export class BrowseByComponent {
@Output() sortDirectionChange = new EventEmitter<SortDirection>();
objectInjector: Injector;
/**
* Declare SortDirection enumeration to use it in the template
*/
public sortDirections = SortDirection;
public constructor(private injector: Injector) {
}
goPrev() {
this.prev.emit(true);
}
@@ -75,4 +91,15 @@ export class BrowseByComponent {
this.sortDirectionChange.emit(direction);
}
getStartsWithComponent() {
return getStartsWithComponent(this.type);
}
ngOnInit(): void {
this.objectInjector = Injector.create({
providers: [{ provide: 'startsWithOptions', useFactory: () => (this.startsWithOptions), deps:[] }],
parent: this.injector
});
}
}