fixed AoT build and search settings

This commit is contained in:
Lotte Hofstede
2018-03-07 11:44:08 +01:00
parent b8f4769f1e
commit acf85577ee
20 changed files with 66 additions and 65 deletions

View File

@@ -8,12 +8,19 @@ module.exports = {
nameSpace: '/' nameSpace: '/'
}, },
// The REST API server settings. // The REST API server settings.
// rest: {
// ssl: true,
// host: 'dspace7.4science.it',
// port: 443,
// // NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript
// nameSpace: '/dspace-spring-rest/api'
// },
rest: { rest: {
ssl: true, ssl: false,
host: 'dspace7.4science.it', host: 'dspace7-internal.atmire.com',
port: 443, port: 80,
// NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript // NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript
nameSpace: '/dspace-spring-rest/api' nameSpace: '/rest/api'
}, },
// Caching settings // Caching settings
cache: { cache: {

View File

@@ -6,8 +6,6 @@ import { FacetValue } from '../../search-service/facet-value.model';
import { SearchFilterService } from './search-filter.service'; import { SearchFilterService } from './search-filter.service';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { slide } from '../../../shared/animations/slide'; import { slide } from '../../../shared/animations/slide';
import { RouteService } from '../../../shared/route.service';
import { first } from 'rxjs/operator/first';
/** /**
* This component renders a simple item page. * This component renders a simple item page.

View File

@@ -89,14 +89,15 @@ export class SearchPageComponent implements OnInit, OnDestroy {
} }
} }
const sortDirection = +params.sortDirection || this.searchOptions.sort.direction; const sortDirection = params.sortDirection || this.searchOptions.sort.direction;
const sortField = params.sortField || this.searchOptions.sort.field;
const pagination = Object.assign({}, const pagination = Object.assign({},
this.searchOptions.pagination, this.searchOptions.pagination,
{ currentPage: page, pageSize: pageSize, pageSizeOptions: pageSizeOptions} { currentPage: page, pageSize: pageSize, pageSizeOptions: pageSizeOptions}
); );
const sort = Object.assign({}, const sort = Object.assign({},
this.searchOptions.sort, this.searchOptions.sort,
{ direction: sortDirection, field: params.sortField } { direction: sortDirection, field: sortField }
); );
this.updateSearchResults({ this.updateSearchResults({

View File

@@ -35,7 +35,6 @@ import { SearchQueryResponse } from './search-query-response.model';
import { PageInfo } from '../../core/shared/page-info.model'; import { PageInfo } from '../../core/shared/page-info.model';
import { getSearchResultFor } from './search-result-element-decorator'; import { getSearchResultFor } from './search-result-element-decorator';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model'; import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { NormalizedItem } from '../../core/cache/models/normalized-item.model';
function shuffle(array: any[]) { function shuffle(array: any[]) {
let i = 0; let i = 0;
@@ -93,7 +92,6 @@ export class SearchService extends HALEndpointService implements OnDestroy {
constructor(protected responseCache: ResponseCacheService, constructor(protected responseCache: ResponseCacheService,
protected requestService: RequestService, protected requestService: RequestService,
private itemDataService: ItemDataService,
@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
private routeService: RouteService, private routeService: RouteService,
private route: ActivatedRoute, private route: ActivatedRoute,
@@ -122,6 +120,16 @@ export class SearchService extends HALEndpointService implements OnDestroy {
args.push(`scope=${scopeId}`); args.push(`scope=${scopeId}`);
} }
if (isNotEmpty(searchOptions)) {
if (isNotEmpty(searchOptions.sort)) {
args.push(`sort=${searchOptions.sort.field},${searchOptions.sort.direction}`);
}
if (isNotEmpty(searchOptions.pagination)) {
args.push(`page=${searchOptions.pagination.currentPage}`);
args.push(`size=${searchOptions.pagination.pageSize}`);
}
}
if (isNotEmpty(args)) { if (isNotEmpty(args)) {
url = new URLCombiner(url, `?${args.join('&')}`).toString(); url = new URLCombiner(url, `?${args.join('&')}`).toString();
} }

View File

@@ -2,21 +2,21 @@
<div *ngIf="[searchOptions].sort" class="setting-option result-order-settings mb-3 p-3"> <div *ngIf="[searchOptions].sort" class="setting-option result-order-settings mb-3 p-3">
<h5>{{ 'search.sidebar.settings.sort-by' | translate}}</h5> <h5>{{ 'search.sidebar.settings.sort-by' | translate}}</h5>
<select class="form-control" (change)="reloadOrder($event)"> <select class="form-control" (change)="reloadOrder($event)">
<option *ngFor="let direction of (sortDirections | dsKeys); let currentElementIndex = index" <option *ngFor="let sortDirection of (sortDirections | dsKeys)"
[value]="currentElementIndex" [value]="sortDirection.value"
[selected]="direction === searchOptions.sort? 'selected': null"> [selected]="sortDirection.value === direction? 'selected': null">
{{direction.value}} {{sortDirection.key}}
</option> </option>
</select> </select>
</div> </div>
<div *ngIf="searchOptions.pagination.pageSize" class="setting-option page-size-settings mb-3 p-3"> <div class="setting-option page-size-settings mb-3 p-3">
<h5>{{ 'search.sidebar.settings.rpp' | translate}}</h5> <h5>{{ 'search.sidebar.settings.rpp' | translate}}</h5>
<select class="form-control" (change)="reloadRPP($event)"> <select class="form-control" (change)="reloadRPP($event)">
<option *ngFor="let item of pageSizeOptions" [value]="item" <option *ngFor="let pageSizeOption of pageSizeOptions" [value]="pageSizeOption"
[selected]="item === searchOptions.pagination.pageSize ? 'selected': null"> [selected]="pageSizeOption === pageSize ? 'selected': null">
{{item}} {{pageSizeOption}}
</option> </option>
</select> </select>
</div> </div>

View File

@@ -1,4 +1,4 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { SearchService } from '../search-service/search.service'; import { SearchService } from '../search-service/search.service';
import { SearchOptions, ViewMode } from '../search-options.model'; import { SearchOptions, ViewMode } from '../search-options.model';
import { SortDirection } from '../../core/cache/models/sort-options.model'; import { SortDirection } from '../../core/cache/models/sort-options.model';
@@ -7,7 +7,7 @@ import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
@Component({ @Component({
selector: 'ds-search-settings', selector: 'ds-search-settings',
styleUrls: ['./search-settings.component.scss'], styleUrls: ['./search-settings.component.scss'],
templateUrl: './search-settings.component.html', templateUrl: './search-settings.component.html'
}) })
export class SearchSettingsComponent implements OnInit { export class SearchSettingsComponent implements OnInit {
@@ -48,7 +48,7 @@ export class SearchSettingsComponent implements OnInit {
this.scope = params.scope; this.scope = params.scope;
this.page = +params.page || this.searchOptions.pagination.currentPage; this.page = +params.page || this.searchOptions.pagination.currentPage;
this.pageSize = +params.pageSize || this.searchOptions.pagination.pageSize; this.pageSize = +params.pageSize || this.searchOptions.pagination.pageSize;
this.direction = +params.sortDirection || this.searchOptions.sort.direction; this.direction = params.sortDirection || this.searchOptions.sort.direction;
if (params.view === ViewMode.Grid) { if (params.view === ViewMode.Grid) {
this.pageSizeOptions = this.gridPageSizeOptions; this.pageSizeOptions = this.gridPageSizeOptions;
} else { } else {

View File

@@ -109,8 +109,7 @@ export class RemoteDataBuildService {
}); });
} }
buildList<TNormalized extends NormalizedObject, TDomain>(hrefObs: string | Observable<string>, buildList<TNormalized extends NormalizedObject, TDomain>(hrefObs: string | Observable<string>): Observable<RemoteData<TDomain[] | PaginatedList<TDomain>>> {
normalizedType: GenericConstructor<TNormalized>): Observable<RemoteData<TDomain[] | PaginatedList<TDomain>>> {
if (typeof hrefObs === 'string') { if (typeof hrefObs === 'string') {
hrefObs = Observable.of(hrefObs); hrefObs = Observable.of(hrefObs);
} }
@@ -124,7 +123,7 @@ export class RemoteDataBuildService {
.filter((entry: ResponseCacheEntry) => entry.response.isSuccessful) .filter((entry: ResponseCacheEntry) => entry.response.isSuccessful)
.map((entry: ResponseCacheEntry) => (entry.response as DSOSuccessResponse).resourceSelfLinks) .map((entry: ResponseCacheEntry) => (entry.response as DSOSuccessResponse).resourceSelfLinks)
.flatMap((resourceUUIDs: string[]) => { .flatMap((resourceUUIDs: string[]) => {
return this.objectCache.getList(resourceUUIDs, normalizedType) return this.objectCache.getList(resourceUUIDs)
.map((normList: TNormalized[]) => { .map((normList: TNormalized[]) => {
return normList.map((normalized: TNormalized) => { return normList.map((normalized: TNormalized) => {
return this.build<TNormalized, TDomain>(normalized); return this.build<TNormalized, TDomain>(normalized);
@@ -166,7 +165,6 @@ export class RemoteDataBuildService {
relationships.forEach((relationship: string) => { relationships.forEach((relationship: string) => {
if (hasValue(normalized[relationship])) { if (hasValue(normalized[relationship])) {
const { resourceType, isList } = getRelationMetadata(normalized, relationship); const { resourceType, isList } = getRelationMetadata(normalized, relationship);
const resourceConstructor = NormalizedObjectFactory.getConstructor(resourceType);
if (Array.isArray(normalized[relationship])) { if (Array.isArray(normalized[relationship])) {
normalized[relationship].forEach((href: string) => { normalized[relationship].forEach((href: string) => {
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), href)) this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), href))
@@ -189,7 +187,7 @@ export class RemoteDataBuildService {
// in that case only 1 href will be stored in the normalized obj (so the isArray above fails), // in that case only 1 href will be stored in the normalized obj (so the isArray above fails),
// but it should still be built as a list // but it should still be built as a list
if (isList) { if (isList) {
links[relationship] = this.buildList(normalized[relationship], resourceConstructor); links[relationship] = this.buildList(normalized[relationship]);
} else { } else {
links[relationship] = this.buildSingle(normalized[relationship]); links[relationship] = this.buildSingle(normalized[relationship]);
} }

View File

@@ -1,11 +1,10 @@
export enum SortDirection { export enum SortDirection {
Ascending, Ascending = 'ASC',
Descending Descending = 'DESC'
} }
export class SortOptions { export class SortOptions {
constructor(public field: string = 'dc.title', public direction: SortDirection = SortDirection.Ascending) {
constructor(public field: string = 'name', public direction: SortDirection = SortDirection.Ascending) {
} }
} }

View File

@@ -20,7 +20,7 @@ export enum DirtyType {
export interface CacheableObject { export interface CacheableObject {
uuid?: string; uuid?: string;
self: string; self: string;
type: ResourceType; type?: ResourceType;
// isNew: boolean; // isNew: boolean;
// dirtyType: DirtyType; // dirtyType: DirtyType;
// hasDirtyAttributes: boolean; // hasDirtyAttributes: boolean;

View File

@@ -5,11 +5,13 @@ import { ObjectCacheService } from './object-cache.service';
import { CacheableObject } from './object-cache.reducer'; import { CacheableObject } from './object-cache.reducer';
import { AddToObjectCacheAction, RemoveFromObjectCacheAction } from './object-cache.actions'; import { AddToObjectCacheAction, RemoveFromObjectCacheAction } from './object-cache.actions';
import { CoreState } from '../core.reducers'; import { CoreState } from '../core.reducers';
import { ResourceType } from '../shared/resource-type';
class TestClass implements CacheableObject { class TestClass implements CacheableObject {
constructor( constructor(
public self: string, public self: string,
public foo: string public foo: string,
public type = ResourceType.Item
) { } ) { }
test(): string { test(): string {
@@ -65,7 +67,7 @@ describe('ObjectCacheService', () => {
let testObj: any; let testObj: any;
// due to the implementation of spyOn above, this subscribe will be synchronous // due to the implementation of spyOn above, this subscribe will be synchronous
service.getBySelfLink(selfLink, TestClass).take(1).subscribe((o) => testObj = o); service.getBySelfLink(selfLink).take(1).subscribe((o) => testObj = o);
expect(testObj.self).toBe(selfLink); expect(testObj.self).toBe(selfLink);
expect(testObj.foo).toBe('bar'); expect(testObj.foo).toBe('bar');
// this only works if testObj is an instance of TestClass // this only works if testObj is an instance of TestClass
@@ -76,7 +78,7 @@ describe('ObjectCacheService', () => {
spyOn(store, 'select').and.returnValue(Observable.of(invalidCacheEntry)); spyOn(store, 'select').and.returnValue(Observable.of(invalidCacheEntry));
let getObsHasFired = false; let getObsHasFired = false;
const subscription = service.getBySelfLink(selfLink, TestClass).subscribe((o) => getObsHasFired = true); const subscription = service.getBySelfLink(selfLink).subscribe((o) => getObsHasFired = true);
expect(getObsHasFired).toBe(false); expect(getObsHasFired).toBe(false);
subscription.unsubscribe(); subscription.unsubscribe();
}); });
@@ -87,7 +89,7 @@ describe('ObjectCacheService', () => {
spyOn(service, 'getBySelfLink').and.returnValue(Observable.of(new TestClass(selfLink, 'bar'))); spyOn(service, 'getBySelfLink').and.returnValue(Observable.of(new TestClass(selfLink, 'bar')));
let testObjs: any[]; let testObjs: any[];
service.getList([selfLink, selfLink], TestClass).take(1).subscribe((arr) => testObjs = arr); service.getList([selfLink, selfLink]).take(1).subscribe((arr) => testObjs = arr);
expect(testObjs[0].self).toBe(selfLink); expect(testObjs[0].self).toBe(selfLink);
expect(testObjs[0].foo).toBe('bar'); expect(testObjs[0].foo).toBe('bar');
expect(testObjs[0].test()).toBe('bar' + selfLink); expect(testObjs[0].test()).toBe('bar' + selfLink);

View File

@@ -121,7 +121,7 @@ export class ObjectCacheService {
* The type of the objects to get * The type of the objects to get
* @return Observable<Array<T>> * @return Observable<Array<T>>
*/ */
getList<T extends NormalizedObject>(selfLinks: string[], type: GenericConstructor<T>): Observable<T[]> { getList<T extends NormalizedObject>(selfLinks: string[]): Observable<T[]> {
return Observable.combineLatest( return Observable.combineLatest(
selfLinks.map((selfLink: string) => this.getBySelfLink<T>(selfLink)) selfLinks.map((selfLink: string) => this.getBySelfLink<T>(selfLink))
); );

View File

@@ -58,11 +58,7 @@ export abstract class ConfigService extends HALEndpointService {
} }
if (hasValue(options.sort)) { if (hasValue(options.sort)) {
let direction = 'asc'; args.push(`sort=${options.sort.field},${options.sort.direction}`);
if (options.sort.direction === 1) {
direction = 'desc';
}
args.push(`sort=${options.sort.field},${direction}`);
} }
if (isNotEmpty(args)) { if (isNotEmpty(args)) {

View File

@@ -24,6 +24,6 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
protected cds: CommunityDataService, protected cds: CommunityDataService,
protected objectCache: ObjectCacheService protected objectCache: ObjectCacheService
) { ) {
super(NormalizedCollection); super();
} }
} }

View File

@@ -5,7 +5,6 @@ import { GlobalConfig } from '../../../config';
import { getMockRequestService } from '../../shared/mocks/mock-request.service'; import { getMockRequestService } from '../../shared/mocks/mock-request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { NormalizedCommunity } from '../cache/models/normalized-community.model'; import { NormalizedCommunity } from '../cache/models/normalized-community.model';
import { CacheableObject } from '../cache/object-cache.reducer';
import { ObjectCacheService } from '../cache/object-cache.service'; import { ObjectCacheService } from '../cache/object-cache.service';
import { ResponseCacheService } from '../cache/response-cache.service'; import { ResponseCacheService } from '../cache/response-cache.service';
import { CoreState } from '../core.reducers'; import { CoreState } from '../core.reducers';
@@ -13,12 +12,12 @@ import { ComColDataService } from './comcol-data.service';
import { CommunityDataService } from './community-data.service'; import { CommunityDataService } from './community-data.service';
import { FindByIDRequest } from './request.models'; import { FindByIDRequest } from './request.models';
import { RequestService } from './request.service'; import { RequestService } from './request.service';
import { NormalizedObject } from '../cache/models/normalized-object.model';
const LINK_NAME = 'test'; const LINK_NAME = 'test';
/* tslint:disable:max-classes-per-file */ /* tslint:disable:max-classes-per-file */
class NormalizedTestObject implements CacheableObject { class NormalizedTestObject extends NormalizedObject {
self: string;
} }
class TestService extends ComColDataService<NormalizedTestObject, any> { class TestService extends ComColDataService<NormalizedTestObject, any> {
@@ -33,7 +32,7 @@ class TestService extends ComColDataService<NormalizedTestObject, any> {
protected cds: CommunityDataService, protected cds: CommunityDataService,
protected objectCache: ObjectCacheService protected objectCache: ObjectCacheService
) { ) {
super(NormalizedTestObject); super();
} }
} }
/* tslint:enable:max-classes-per-file */ /* tslint:enable:max-classes-per-file */

View File

@@ -24,6 +24,6 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
protected objectCache: ObjectCacheService protected objectCache: ObjectCacheService
) { ) {
super(NormalizedCommunity); super();
} }
} }

View File

@@ -3,7 +3,6 @@ import { Observable } from 'rxjs/Observable';
import { GlobalConfig } from '../../../config'; import { GlobalConfig } from '../../../config';
import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { CacheableObject } from '../cache/object-cache.reducer';
import { ResponseCacheService } from '../cache/response-cache.service'; import { ResponseCacheService } from '../cache/response-cache.service';
import { CoreState } from '../core.reducers'; import { CoreState } from '../core.reducers';
import { GenericConstructor } from '../shared/generic-constructor'; import { GenericConstructor } from '../shared/generic-constructor';
@@ -23,10 +22,6 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
protected abstract linkPath: string; protected abstract linkPath: string;
protected abstract EnvConfig: GlobalConfig; protected abstract EnvConfig: GlobalConfig;
constructor(protected normalizedResourceType: GenericConstructor<TNormalized>,) {
super();
}
public abstract getScopedEndpoint(scope: string): Observable<string> public abstract getScopedEndpoint(scope: string): Observable<string>
protected getFindAllHref(endpoint, options: FindAllOptions = {}): Observable<string> { protected getFindAllHref(endpoint, options: FindAllOptions = {}): Observable<string> {
@@ -49,11 +44,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
} }
if (hasValue(options.sort)) { if (hasValue(options.sort)) {
let direction = 'asc'; args.push(`sort=${options.sort.field},${options.sort.direction}`);
if (options.sort.direction === 1) {
direction = 'desc';
}
args.push(`sort=${options.sort.field},${direction}`);
} }
if (isNotEmpty(args)) { if (isNotEmpty(args)) {
@@ -75,7 +66,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
this.requestService.configure(request); this.requestService.configure(request);
}); });
return this.rdbService.buildList<TNormalized, TDomain>(hrefObs, this.normalizedResourceType) as Observable<RemoteData<PaginatedList<TDomain>>>; return this.rdbService.buildList<TNormalized, TDomain>(hrefObs) as Observable<RemoteData<PaginatedList<TDomain>>>;
} }
getFindByIDHref(endpoint, resourceID): string { getFindByIDHref(endpoint, resourceID): string {

View File

@@ -27,7 +27,7 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
private bs: BrowseService private bs: BrowseService
) { ) {
super(NormalizedItem); super();
} }
public getScopedEndpoint(scopeID: string): Observable<string> { public getScopedEndpoint(scopeID: string): Observable<string> {

View File

@@ -12,7 +12,7 @@
<h6 class="dropdown-header">{{ 'pagination.results-per-page' | translate}}</h6> <h6 class="dropdown-header">{{ 'pagination.results-per-page' | translate}}</h6>
<button class="dropdown-item" *ngFor="let item of pageSizeOptions" (click)="doPageSizeChange(item)"><i [ngClass]="{'invisible': item != pageSize}" class="fa fa-check" aria-hidden="true"></i> {{item}} </button> <button class="dropdown-item" *ngFor="let item of pageSizeOptions" (click)="doPageSizeChange(item)"><i [ngClass]="{'invisible': item != pageSize}" class="fa fa-check" aria-hidden="true"></i> {{item}} </button>
<h6 class="dropdown-header">{{ 'pagination.sort-direction' | translate}}</h6> <h6 class="dropdown-header">{{ 'pagination.sort-direction' | translate}}</h6>
<button class="dropdown-item" *ngFor="let direction of (sortDirections | dsKeys)" (click)="doSortDirectionChange(direction.key)"><i [ngClass]="{'invisible': direction.key != sortDirection}" class="fa fa-check" aria-hidden="true"></i> {{direction.value}} </button> <button class="dropdown-item" *ngFor="let direction of (sortDirections | dsKeys)" (click)="doSortDirectionChange(direction.value)"><i [ngClass]="{'invisible': direction.value !== sortDirection}" class="fa fa-check" aria-hidden="true"></i> {{direction.key}} </button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -399,8 +399,8 @@ export class PaginationComponent implements OnDestroy, OnInit {
} }
const sortDirection = this.currentQueryParams.sortDirection; const sortDirection = this.currentQueryParams.sortDirection;
if (this.sortDirection !== +sortDirection) { if (this.sortDirection !== sortDirection) {
this.setSortDirection(+sortDirection); this.setSortDirection(sortDirection);
} }
const sortField = this.currentQueryParams.sortField; const sortField = this.currentQueryParams.sortField;

View File

@@ -7,6 +7,8 @@ export class EnumKeysPipe implements PipeTransform {
for (const enumMember in value) { for (const enumMember in value) {
if (!isNaN(parseInt(enumMember, 10))) { if (!isNaN(parseInt(enumMember, 10))) {
keys.push({ key: +enumMember, value: value[enumMember] }); keys.push({ key: +enumMember, value: value[enumMember] });
} else {
keys.push({ key: enumMember, value: value[enumMember] });
} }
} }
return keys; return keys;