From acf85577ee650d2de561f5274aec92067f84a3a1 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Wed, 7 Mar 2018 11:44:08 +0100 Subject: [PATCH] fixed AoT build and search settings --- config/environment.default.js | 21 ++++++++++++------- .../search-filter/search-filter.component.ts | 2 -- src/app/+search-page/search-page.component.ts | 5 +++-- .../search-service/search.service.ts | 12 +++++++++-- .../search-settings.component.html | 16 +++++++------- .../search-settings.component.ts | 6 +++--- .../builders/remote-data-build.service.ts | 8 +++---- .../core/cache/models/sort-options.model.ts | 7 +++---- src/app/core/cache/object-cache.reducer.ts | 2 +- .../core/cache/object-cache.service.spec.ts | 10 +++++---- src/app/core/cache/object-cache.service.ts | 2 +- src/app/core/config/config.service.ts | 6 +----- src/app/core/data/collection-data.service.ts | 2 +- src/app/core/data/comcol-data.service.spec.ts | 7 +++---- src/app/core/data/community-data.service.ts | 2 +- src/app/core/data/data.service.ts | 13 ++---------- src/app/core/data/item-data.service.ts | 2 +- .../pagination/pagination.component.html | 2 +- .../shared/pagination/pagination.component.ts | 4 ++-- src/app/shared/utils/enum-keys-pipe.ts | 2 ++ 20 files changed, 66 insertions(+), 65 deletions(-) diff --git a/config/environment.default.js b/config/environment.default.js index ad7be69b9e..39628c5a68 100644 --- a/config/environment.default.js +++ b/config/environment.default.js @@ -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 diff --git a/src/app/+search-page/search-filters/search-filter/search-filter.component.ts b/src/app/+search-page/search-filters/search-filter/search-filter.component.ts index 08d72da984..ddb21236c5 100644 --- a/src/app/+search-page/search-filters/search-filter/search-filter.component.ts +++ b/src/app/+search-page/search-filters/search-filter/search-filter.component.ts @@ -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. diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 389db140e3..9c5c9a7462 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -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({ diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index e3a1ccc11b..f343adc38b 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -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(); } diff --git a/src/app/+search-page/search-settings/search-settings.component.html b/src/app/+search-page/search-settings/search-settings.component.html index 4ee0812602..b0d3294e30 100644 --- a/src/app/+search-page/search-settings/search-settings.component.html +++ b/src/app/+search-page/search-settings/search-settings.component.html @@ -2,21 +2,21 @@
{{ 'search.sidebar.settings.sort-by' | translate}}
-
+
{{ 'search.sidebar.settings.rpp' | translate}}
diff --git a/src/app/+search-page/search-settings/search-settings.component.ts b/src/app/+search-page/search-settings/search-settings.component.ts index ad6aeb21dd..bc1fb096fd 100644 --- a/src/app/+search-page/search-settings/search-settings.component.ts +++ b/src/app/+search-page/search-settings/search-settings.component.ts @@ -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 { diff --git a/src/app/core/cache/builders/remote-data-build.service.ts b/src/app/core/cache/builders/remote-data-build.service.ts index 45eb6cb46a..af2c80c9aa 100644 --- a/src/app/core/cache/builders/remote-data-build.service.ts +++ b/src/app/core/cache/builders/remote-data-build.service.ts @@ -109,8 +109,7 @@ export class RemoteDataBuildService { }); } - buildList(hrefObs: string | Observable, - normalizedType: GenericConstructor): Observable>> { + buildList(hrefObs: string | Observable): Observable>> { 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(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]); } diff --git a/src/app/core/cache/models/sort-options.model.ts b/src/app/core/cache/models/sort-options.model.ts index ad639bf853..751b72b399 100644 --- a/src/app/core/cache/models/sort-options.model.ts +++ b/src/app/core/cache/models/sort-options.model.ts @@ -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) { } } diff --git a/src/app/core/cache/object-cache.reducer.ts b/src/app/core/cache/object-cache.reducer.ts index 1ae3a190a4..3a1830e14a 100644 --- a/src/app/core/cache/object-cache.reducer.ts +++ b/src/app/core/cache/object-cache.reducer.ts @@ -20,7 +20,7 @@ export enum DirtyType { export interface CacheableObject { uuid?: string; self: string; - type: ResourceType; + type?: ResourceType; // isNew: boolean; // dirtyType: DirtyType; // hasDirtyAttributes: boolean; diff --git a/src/app/core/cache/object-cache.service.spec.ts b/src/app/core/cache/object-cache.service.spec.ts index 2cf7eebd0a..86b8a3efdf 100644 --- a/src/app/core/cache/object-cache.service.spec.ts +++ b/src/app/core/cache/object-cache.service.spec.ts @@ -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); diff --git a/src/app/core/cache/object-cache.service.ts b/src/app/core/cache/object-cache.service.ts index b747880dc3..9344f4d5f0 100644 --- a/src/app/core/cache/object-cache.service.ts +++ b/src/app/core/cache/object-cache.service.ts @@ -121,7 +121,7 @@ export class ObjectCacheService { * The type of the objects to get * @return Observable> */ - getList(selfLinks: string[], type: GenericConstructor): Observable { + getList(selfLinks: string[]): Observable { return Observable.combineLatest( selfLinks.map((selfLink: string) => this.getBySelfLink(selfLink)) ); diff --git a/src/app/core/config/config.service.ts b/src/app/core/config/config.service.ts index a8c2bc46bf..f1750bca84 100644 --- a/src/app/core/config/config.service.ts +++ b/src/app/core/config/config.service.ts @@ -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)) { diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts index a0f246aedc..a675b7254d 100644 --- a/src/app/core/data/collection-data.service.ts +++ b/src/app/core/data/collection-data.service.ts @@ -24,6 +24,6 @@ export class CollectionDataService extends ComColDataService { @@ -33,7 +32,7 @@ class TestService extends ComColDataService { protected cds: CommunityDataService, protected objectCache: ObjectCacheService ) { - super(NormalizedTestObject); + super(); } } /* tslint:enable:max-classes-per-file */ diff --git a/src/app/core/data/community-data.service.ts b/src/app/core/data/community-data.service.ts index dce67e936f..4cb44f4296 100644 --- a/src/app/core/data/community-data.service.ts +++ b/src/app/core/data/community-data.service.ts @@ -24,6 +24,6 @@ export class CommunityDataService extends ComColDataService protected abstract linkPath: string; protected abstract EnvConfig: GlobalConfig; - constructor(protected normalizedResourceType: GenericConstructor,) { - super(); - } - public abstract getScopedEndpoint(scope: string): Observable protected getFindAllHref(endpoint, options: FindAllOptions = {}): Observable { @@ -49,11 +44,7 @@ export abstract class DataService } 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 this.requestService.configure(request); }); - return this.rdbService.buildList(hrefObs, this.normalizedResourceType) as Observable>>; + return this.rdbService.buildList(hrefObs) as Observable>>; } getFindByIDHref(endpoint, resourceID): string { diff --git a/src/app/core/data/item-data.service.ts b/src/app/core/data/item-data.service.ts index 155ba357c6..0e6fcbfd33 100644 --- a/src/app/core/data/item-data.service.ts +++ b/src/app/core/data/item-data.service.ts @@ -27,7 +27,7 @@ export class ItemDataService extends DataService { @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, private bs: BrowseService ) { - super(NormalizedItem); + super(); } public getScopedEndpoint(scopeID: string): Observable { diff --git a/src/app/shared/pagination/pagination.component.html b/src/app/shared/pagination/pagination.component.html index 062209f4bb..0ad812a6b6 100644 --- a/src/app/shared/pagination/pagination.component.html +++ b/src/app/shared/pagination/pagination.component.html @@ -12,7 +12,7 @@ - +
diff --git a/src/app/shared/pagination/pagination.component.ts b/src/app/shared/pagination/pagination.component.ts index e2af2fd06c..2fa70ddd18 100644 --- a/src/app/shared/pagination/pagination.component.ts +++ b/src/app/shared/pagination/pagination.component.ts @@ -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; diff --git a/src/app/shared/utils/enum-keys-pipe.ts b/src/app/shared/utils/enum-keys-pipe.ts index 45683c3323..82893b886f 100644 --- a/src/app/shared/utils/enum-keys-pipe.ts +++ b/src/app/shared/utils/enum-keys-pipe.ts @@ -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;