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,13 +8,20 @@ module.exports = {
nameSpace: '/'
},
// 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: {
// 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: {
ssl: false,
host: 'dspace7-internal.atmire.com',
port: 80,
// NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript
nameSpace: '/rest/api'
},
// Caching settings
cache: {
// NOTE: how long should objects be cached for by default

View File

@@ -6,8 +6,6 @@ import { FacetValue } from '../../search-service/facet-value.model';
import { SearchFilterService } from './search-filter.service';
import { Observable } from 'rxjs/Observable';
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.

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({},
this.searchOptions.pagination,
{ currentPage: page, pageSize: pageSize, pageSizeOptions: pageSizeOptions}
);
const sort = Object.assign({},
this.searchOptions.sort,
{ direction: sortDirection, field: params.sortField }
{ direction: sortDirection, field: sortField }
);
this.updateSearchResults({

View File

@@ -35,7 +35,6 @@ import { SearchQueryResponse } from './search-query-response.model';
import { PageInfo } from '../../core/shared/page-info.model';
import { getSearchResultFor } from './search-result-element-decorator';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { NormalizedItem } from '../../core/cache/models/normalized-item.model';
function shuffle(array: any[]) {
let i = 0;
@@ -93,7 +92,6 @@ export class SearchService extends HALEndpointService implements OnDestroy {
constructor(protected responseCache: ResponseCacheService,
protected requestService: RequestService,
private itemDataService: ItemDataService,
@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
private routeService: RouteService,
private route: ActivatedRoute,
@@ -122,6 +120,16 @@ export class SearchService extends HALEndpointService implements OnDestroy {
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)) {
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">
<h5>{{ 'search.sidebar.settings.sort-by' | translate}}</h5>
<select class="form-control" (change)="reloadOrder($event)">
<option *ngFor="let direction of (sortDirections | dsKeys); let currentElementIndex = index"
[value]="currentElementIndex"
[selected]="direction === searchOptions.sort? 'selected': null">
{{direction.value}}
<option *ngFor="let sortDirection of (sortDirections | dsKeys)"
[value]="sortDirection.value"
[selected]="sortDirection.value === direction? 'selected': null">
{{sortDirection.key}}
</option>
</select>
</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>
<select class="form-control" (change)="reloadRPP($event)">
<option *ngFor="let item of pageSizeOptions" [value]="item"
[selected]="item === searchOptions.pagination.pageSize ? 'selected': null">
{{item}}
<option *ngFor="let pageSizeOption of pageSizeOptions" [value]="pageSizeOption"
[selected]="pageSizeOption === pageSize ? 'selected': null">
{{pageSizeOption}}
</option>
</select>
</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 { SearchOptions, ViewMode } from '../search-options.model';
import { SortDirection } from '../../core/cache/models/sort-options.model';
@@ -7,7 +7,7 @@ import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
@Component({
selector: 'ds-search-settings',
styleUrls: ['./search-settings.component.scss'],
templateUrl: './search-settings.component.html',
templateUrl: './search-settings.component.html'
})
export class SearchSettingsComponent implements OnInit {
@@ -48,7 +48,7 @@ export class SearchSettingsComponent implements OnInit {
this.scope = params.scope;
this.page = +params.page || this.searchOptions.pagination.currentPage;
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) {
this.pageSizeOptions = this.gridPageSizeOptions;
} else {

View File

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

View File

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

View File

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

View File

@@ -5,11 +5,13 @@ import { ObjectCacheService } from './object-cache.service';
import { CacheableObject } from './object-cache.reducer';
import { AddToObjectCacheAction, RemoveFromObjectCacheAction } from './object-cache.actions';
import { CoreState } from '../core.reducers';
import { ResourceType } from '../shared/resource-type';
class TestClass implements CacheableObject {
constructor(
public self: string,
public foo: string
public foo: string,
public type = ResourceType.Item
) { }
test(): string {
@@ -65,7 +67,7 @@ describe('ObjectCacheService', () => {
let testObj: any;
// 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.foo).toBe('bar');
// this only works if testObj is an instance of TestClass
@@ -76,7 +78,7 @@ describe('ObjectCacheService', () => {
spyOn(store, 'select').and.returnValue(Observable.of(invalidCacheEntry));
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);
subscription.unsubscribe();
});
@@ -87,7 +89,7 @@ describe('ObjectCacheService', () => {
spyOn(service, 'getBySelfLink').and.returnValue(Observable.of(new TestClass(selfLink, 'bar')));
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].foo).toBe('bar');
expect(testObjs[0].test()).toBe('bar' + selfLink);

View File

@@ -121,7 +121,7 @@ export class ObjectCacheService {
* The type of the objects to get
* @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(
selfLinks.map((selfLink: string) => this.getBySelfLink<T>(selfLink))
);

View File

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

View File

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

View File

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

View File

@@ -3,7 +3,6 @@ import { Observable } from 'rxjs/Observable';
import { GlobalConfig } from '../../../config';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { CacheableObject } from '../cache/object-cache.reducer';
import { ResponseCacheService } from '../cache/response-cache.service';
import { CoreState } from '../core.reducers';
import { GenericConstructor } from '../shared/generic-constructor';
@@ -23,10 +22,6 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
protected abstract linkPath: string;
protected abstract EnvConfig: GlobalConfig;
constructor(protected normalizedResourceType: GenericConstructor<TNormalized>,) {
super();
}
public abstract getScopedEndpoint(scope: string): 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)) {
let direction = 'asc';
if (options.sort.direction === 1) {
direction = 'desc';
}
args.push(`sort=${options.sort.field},${direction}`);
args.push(`sort=${options.sort.field},${options.sort.direction}`);
}
if (isNotEmpty(args)) {
@@ -75,7 +66,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
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 {

View File

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

View File

@@ -12,7 +12,7 @@
<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>
<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>

View File

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

View File

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