From 01f26bd8c25194e4fa7011dc1dd9e9d558b55f93 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 26 Oct 2017 15:04:03 +0200 Subject: [PATCH 01/77] Add config endpoint service --- src/app/core/cache/response-cache.models.ts | 10 ++ src/app/core/config/config.service.ts | 137 ++++++++++++++++++ .../submission-definitions-config.service.ts | 21 +++ .../config/submission-forms-config.service.ts | 21 +++ .../submission-sections-config.service.ts | 21 +++ src/app/core/core.module.ts | 8 + .../data/config-response-parsing.service.ts | 36 +++++ src/app/core/data/request.models.ts | 11 ++ .../dspace-rest-v2-response.model.ts | 1 + .../shared/config/config-object-factory.ts | 30 ++++ .../config-submission-definitions.model.ts | 15 ++ .../config/config-submission-forms.model.ts | 10 ++ .../config/config-submission-section.model.ts | 16 ++ src/app/core/shared/config/config-type.ts | 12 ++ src/app/core/shared/config/config.model.ts | 15 ++ 15 files changed, 364 insertions(+) create mode 100644 src/app/core/config/config.service.ts create mode 100644 src/app/core/config/submission-definitions-config.service.ts create mode 100644 src/app/core/config/submission-forms-config.service.ts create mode 100644 src/app/core/config/submission-sections-config.service.ts create mode 100644 src/app/core/data/config-response-parsing.service.ts create mode 100644 src/app/core/shared/config/config-object-factory.ts create mode 100644 src/app/core/shared/config/config-submission-definitions.model.ts create mode 100644 src/app/core/shared/config/config-submission-forms.model.ts create mode 100644 src/app/core/shared/config/config-submission-section.model.ts create mode 100644 src/app/core/shared/config/config-type.ts create mode 100644 src/app/core/shared/config/config.model.ts diff --git a/src/app/core/cache/response-cache.models.ts b/src/app/core/cache/response-cache.models.ts index 8444a86490..96c1e66f83 100644 --- a/src/app/core/cache/response-cache.models.ts +++ b/src/app/core/cache/response-cache.models.ts @@ -1,5 +1,6 @@ import { RequestError } from '../data/request.models'; import { PageInfo } from '../shared/page-info.model'; +import { ConfigObject } from '../shared/config/config.model'; /* tslint:disable:max-classes-per-file */ export class RestResponse { @@ -41,4 +42,13 @@ export class ErrorResponse extends RestResponse { this.errorMessage = error.message; } } + +export class ConfigSuccessResponse extends RestResponse { + constructor( + public configDefinition: ConfigObject[], + public statusCode: string + ) { + super(true, statusCode); + } +} /* tslint:enable:max-classes-per-file */ diff --git a/src/app/core/config/config.service.ts b/src/app/core/config/config.service.ts new file mode 100644 index 0000000000..dc689c6e4e --- /dev/null +++ b/src/app/core/config/config.service.ts @@ -0,0 +1,137 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; + +import { RequestService } from '../data/request.service'; +import { ResponseCacheService } from '../cache/response-cache.service'; +import { GlobalConfig } from '../../../config/global-config.interface'; +import { ConfigSuccessResponse, EndpointMap, RootSuccessResponse } from '../cache/response-cache.models'; +import { ConfigRequest, FindAllOptions, RestRequest, RootEndpointRequest } from '../data/request.models'; +import { ResponseCacheEntry } from '../cache/response-cache.reducer'; +import { hasValue, isNotEmpty } from '../../shared/empty.util'; +import { ConfigObject } from '../shared/config/config.model'; + +@Injectable() +export abstract class ConfigService { + protected request: ConfigRequest; + protected abstract responseCache: ResponseCacheService; + protected abstract requestService: RequestService; + protected abstract linkName: string; + protected abstract EnvConfig: GlobalConfig; + protected abstract browseEndpoint: string; + + protected getConfig(request: RestRequest): Observable { + return this.responseCache.get(request.href) + .map((entry: ResponseCacheEntry) => entry.response) + .filter((response: ConfigSuccessResponse) => isNotEmpty(response) && isNotEmpty(response.configDefinition)) + .map((response: ConfigSuccessResponse) => response.configDefinition) + .distinctUntilChanged(); + } + + protected getConfigByIDHref(endpoint, resourceID): string { + return `${endpoint}/${resourceID}`; + } + + protected getConfigSearchHref(endpoint, options: FindAllOptions = {}): string { + let result; + const args = []; + + if (hasValue(options.scopeID)) { + result = `${endpoint}/${this.browseEndpoint}` + args.push(`uuid=${options.scopeID}`); + } else { + result = endpoint; + } + + if (hasValue(options.currentPage) && typeof options.currentPage === 'number') { + /* TODO: this is a temporary fix for the pagination start index (0 or 1) discrepancy between the rest and the frontend respectively */ + args.push(`page=${options.currentPage - 1}`); + } + + if (hasValue(options.elementsPerPage)) { + args.push(`size=${options.elementsPerPage}`); + } + + if (hasValue(options.sort)) { + let direction = 'asc'; + if (options.sort.direction === 1) { + direction = 'desc'; + } + args.push(`sort=${options.sort.field},${direction}`); + } + + if (isNotEmpty(args)) { + result = `${result}?${args.join('&')}`; + } + return result; + } + + protected getEndpointMap(): Observable { + const request = new RootEndpointRequest(this.EnvConfig); + setTimeout(() => { + this.requestService.configure(request); + }, 0); + return this.responseCache.get(request.href) + .map((entry: ResponseCacheEntry) => entry.response) + .filter((response: RootSuccessResponse) => isNotEmpty(response) && isNotEmpty(response.endpointMap)) + .map((response: RootSuccessResponse) => response.endpointMap) + .distinctUntilChanged(); + } + + public getConfigAll(): Observable { + return this.getEndpoint() + .filter((href: string) => isNotEmpty(href)) + .distinctUntilChanged() + .map((endpointURL: string) => new ConfigRequest(endpointURL)) + .do((request: RestRequest) => { + setTimeout(() => { + this.requestService.configure(request); + }, 0); + }) + .flatMap((request: RestRequest) => this.getConfig(request)) + .distinctUntilChanged(); + } + + public getConfigByHref(href: string): Observable { + const request = new ConfigRequest(href); + this.requestService.configure(request); + + return this.getConfig(request); + } + + public getConfigById(id: string): Observable { + return this.getEndpoint() + .map((endpoint: string) => this.getConfigByIDHref(endpoint, id)) + .filter((href: string) => isNotEmpty(href)) + .distinctUntilChanged() + .map((endpointURL: string) => new ConfigRequest(endpointURL)) + .do((request: RestRequest) => { + setTimeout(() => { + this.requestService.configure(request); + }, 0); + }) + .flatMap((request: RestRequest) => this.getConfig(request)) + .distinctUntilChanged(); + } + + public getConfigBySearch(options: FindAllOptions = {}): Observable { + return this.getEndpoint() + .map((endpoint: string) => this.getConfigSearchHref(endpoint, options)) + .filter((href: string) => isNotEmpty(href)) + .distinctUntilChanged() + .map((endpointURL: string) => new ConfigRequest(endpointURL)) + .do((request: RestRequest) => { + setTimeout(() => { + this.requestService.configure(request); + }, 0); + }) + .flatMap((request: RestRequest) => this.getConfig(request)) + .distinctUntilChanged(); + } + + public getEndpoint(): Observable { + return this.getEndpointMap() + .map((map: EndpointMap) => map[this.linkName]) + .distinctUntilChanged(); + } + +} diff --git a/src/app/core/config/submission-definitions-config.service.ts b/src/app/core/config/submission-definitions-config.service.ts new file mode 100644 index 0000000000..4857569236 --- /dev/null +++ b/src/app/core/config/submission-definitions-config.service.ts @@ -0,0 +1,21 @@ +import { Inject, Injectable } from '@angular/core'; + +import { ConfigService } from './config.service'; +import { ResponseCacheService } from '../cache/response-cache.service'; +import { RequestService } from '../data/request.service'; +import { GLOBAL_CONFIG } from '../../../config'; +import { GlobalConfig } from '../../../config/global-config.interface'; + +@Injectable() +export class SubmissionDefinitionsConfigService extends ConfigService { + protected linkName = 'submissiondefinitions'; + protected browseEndpoint = 'search/findByCollection'; + + constructor( + protected responseCache: ResponseCacheService, + protected requestService: RequestService, + @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig) { + super(); + } + +} diff --git a/src/app/core/config/submission-forms-config.service.ts b/src/app/core/config/submission-forms-config.service.ts new file mode 100644 index 0000000000..5e992146ee --- /dev/null +++ b/src/app/core/config/submission-forms-config.service.ts @@ -0,0 +1,21 @@ +import { Inject, Injectable } from '@angular/core'; + +import { ConfigService } from './config.service'; +import { ResponseCacheService } from '../cache/response-cache.service'; +import { RequestService } from '../data/request.service'; +import { GLOBAL_CONFIG } from '../../../config'; +import { GlobalConfig } from '../../../config/global-config.interface'; + +@Injectable() +export class SubmissionFormsConfigService extends ConfigService { + protected linkName = 'submissionforms'; + protected browseEndpoint = ''; + + constructor( + protected responseCache: ResponseCacheService, + protected requestService: RequestService, + @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig) { + super(); + } + +} diff --git a/src/app/core/config/submission-sections-config.service.ts b/src/app/core/config/submission-sections-config.service.ts new file mode 100644 index 0000000000..96a8557e9c --- /dev/null +++ b/src/app/core/config/submission-sections-config.service.ts @@ -0,0 +1,21 @@ +import { Inject, Injectable } from '@angular/core'; + +import { ConfigService } from './config.service'; +import { ResponseCacheService } from '../cache/response-cache.service'; +import { RequestService } from '../data/request.service'; +import { GLOBAL_CONFIG } from '../../../config'; +import { GlobalConfig } from '../../../config/global-config.interface'; + +@Injectable() +export class SubmissionSectionsConfigService extends ConfigService { + protected linkName = 'submissionsections'; + protected browseEndpoint = ''; + + constructor( + protected responseCache: ResponseCacheService, + protected requestService: RequestService, + @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig) { + super(); + } + +} diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index b782f1d4fc..7289c47a80 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -30,6 +30,10 @@ import { ResponseCacheService } from './cache/response-cache.service'; import { RootResponseParsingService } from './data/root-response-parsing.service'; import { ServerResponseService } from '../shared/server-response.service'; import { NativeWindowFactory, NativeWindowService } from '../shared/window.service'; +import { SubmissionDefinitionsConfigService } from './config/submission-definitions-config.service'; +import { ConfigResponseParsingService } from './data/config-response-parsing.service'; +import { SubmissionFormsConfigService } from './config/submission-forms-config.service'; +import { SubmissionSectionsConfigService } from './config/submission-sections-config.service'; const IMPORTS = [ CommonModule, @@ -61,6 +65,10 @@ const PROVIDERS = [ ResponseCacheService, RootResponseParsingService, ServerResponseService, + ConfigResponseParsingService, + SubmissionDefinitionsConfigService, + SubmissionFormsConfigService, + SubmissionSectionsConfigService, { provide: NativeWindowService, useFactory: NativeWindowFactory } ]; diff --git a/src/app/core/data/config-response-parsing.service.ts b/src/app/core/data/config-response-parsing.service.ts new file mode 100644 index 0000000000..1eb4da2131 --- /dev/null +++ b/src/app/core/data/config-response-parsing.service.ts @@ -0,0 +1,36 @@ +import { Injectable } from '@angular/core'; + +import { ResponseParsingService } from './parsing.service'; +import { RestRequest } from './request.models'; +import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model'; +import { ConfigSuccessResponse, ErrorResponse, RestResponse } from '../cache/response-cache.models'; +import { isNotEmpty } from '../../shared/empty.util'; +import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer'; +import { ConfigObjectFactory } from '../shared/config/config-object-factory'; + +@Injectable() +export class ConfigResponseParsingService implements ResponseParsingService { + + parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { + if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) { + let configDefinition; + if (isNotEmpty(data.payload._embedded) && Array.isArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]])) { + const type = Object.keys(data.payload._embedded)[0]; + const serializer = new DSpaceRESTv2Serializer(ConfigObjectFactory.getConstructor(type)); + configDefinition = serializer.deserializeArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]]); + + } else { + const serializer = new DSpaceRESTv2Serializer(ConfigObjectFactory.getConstructor(data.payload.type)); + configDefinition = serializer.deserialize(data.payload); + } + return new ConfigSuccessResponse(configDefinition, data.statusCode); + } else { + return new ErrorResponse( + Object.assign( + new Error('Unexpected response from config endpoint'), + {statusText: data.statusCode} + ) + ); + } + } +} diff --git a/src/app/core/data/request.models.ts b/src/app/core/data/request.models.ts index 8c415e71ef..127fcd834e 100644 --- a/src/app/core/data/request.models.ts +++ b/src/app/core/data/request.models.ts @@ -5,6 +5,7 @@ import { RESTURLCombiner } from '../url-combiner/rest-url-combiner'; import { DSOResponseParsingService } from './dso-response-parsing.service'; import { ResponseParsingService } from './parsing.service'; import { RootResponseParsingService } from './root-response-parsing.service'; +import { ConfigResponseParsingService } from './config-response-parsing.service'; /* tslint:disable:max-classes-per-file */ export class RestRequest { @@ -53,6 +54,16 @@ export class RootEndpointRequest extends RestRequest { } } +export class ConfigRequest extends RestRequest { + constructor(href: string) { + super(href); + } + + getResponseParser(): GenericConstructor { + return ConfigResponseParsingService; + } +} + export class RequestError extends Error { statusText: string; } diff --git a/src/app/core/dspace-rest-v2/dspace-rest-v2-response.model.ts b/src/app/core/dspace-rest-v2/dspace-rest-v2-response.model.ts index 01af2a2c2b..cb39fc718e 100644 --- a/src/app/core/dspace-rest-v2/dspace-rest-v2-response.model.ts +++ b/src/app/core/dspace-rest-v2/dspace-rest-v2-response.model.ts @@ -1,5 +1,6 @@ export interface DSpaceRESTV2Response { payload: { + [name: string]: string; _embedded?: any; _links?: any; page?: any; diff --git a/src/app/core/shared/config/config-object-factory.ts b/src/app/core/shared/config/config-object-factory.ts new file mode 100644 index 0000000000..4f56a84812 --- /dev/null +++ b/src/app/core/shared/config/config-object-factory.ts @@ -0,0 +1,30 @@ + +import { GenericConstructor } from '../../shared/generic-constructor'; + +import { SubmissionSectionModel } from './config-submission-section.model'; +import { SubmissionFormsModel } from './config-submission-forms.model'; +import { SubmissionDefinitionsModel } from './config-submission-definitions.model'; +import { ConfigType } from './config-type'; +import { ConfigObject } from './config.model'; + +export class ConfigObjectFactory { + public static getConstructor(type): GenericConstructor { + switch (type) { + case ConfigType.SubmissionDefinition: + case ConfigType.SubmissionDefinitions: { + return SubmissionDefinitionsModel + } + case ConfigType.SubmissionForm: + case ConfigType.SubmissionForms: { + return SubmissionFormsModel + } + case ConfigType.SubmissionSection: + case ConfigType.SubmissionSections: { + return SubmissionSectionModel + } + default: { + return undefined; + } + } + } +} diff --git a/src/app/core/shared/config/config-submission-definitions.model.ts b/src/app/core/shared/config/config-submission-definitions.model.ts new file mode 100644 index 0000000000..271ab7281b --- /dev/null +++ b/src/app/core/shared/config/config-submission-definitions.model.ts @@ -0,0 +1,15 @@ +import { autoserialize, inheritSerialization } from 'cerialize'; +import { ConfigObject } from './config.model'; +import { SubmissionSectionModel } from './config-submission-section.model'; +import { RemoteData } from '../../data/remote-data'; + +@inheritSerialization(ConfigObject) +export class SubmissionDefinitionsModel extends ConfigObject { + + @autoserialize + isDefault: boolean; + + @autoserialize + sections: RemoteData; + +} diff --git a/src/app/core/shared/config/config-submission-forms.model.ts b/src/app/core/shared/config/config-submission-forms.model.ts new file mode 100644 index 0000000000..0b094091a7 --- /dev/null +++ b/src/app/core/shared/config/config-submission-forms.model.ts @@ -0,0 +1,10 @@ +import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize'; +import { ConfigObject } from './config.model'; + +@inheritSerialization(ConfigObject) +export class SubmissionFormsModel extends ConfigObject { + + @autoserialize + fields: any[]; + +} diff --git a/src/app/core/shared/config/config-submission-section.model.ts b/src/app/core/shared/config/config-submission-section.model.ts new file mode 100644 index 0000000000..17bd6e3beb --- /dev/null +++ b/src/app/core/shared/config/config-submission-section.model.ts @@ -0,0 +1,16 @@ +import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize'; +import { ConfigObject } from './config.model'; + +@inheritSerialization(ConfigObject) +export class SubmissionSectionModel extends ConfigObject { + + @autoserialize + header: string; + + @autoserialize + mandatory: boolean; + + @autoserialize + sectionType: string; + +} diff --git a/src/app/core/shared/config/config-type.ts b/src/app/core/shared/config/config-type.ts new file mode 100644 index 0000000000..d4d88b8a60 --- /dev/null +++ b/src/app/core/shared/config/config-type.ts @@ -0,0 +1,12 @@ +/** + * TODO replace with actual string enum after upgrade to TypeScript 2.4: + * https://github.com/Microsoft/TypeScript/pull/15486 + */ +export enum ConfigType { + SubmissionDefinitions = 'submissiondefinitions', + SubmissionDefinition = 'submissiondefinition', + SubmissionForm = 'submissionform', + SubmissionForms = 'submissionforms', + SubmissionSections = 'submissionsections', + SubmissionSection = 'submissionsection' +} diff --git a/src/app/core/shared/config/config.model.ts b/src/app/core/shared/config/config.model.ts new file mode 100644 index 0000000000..e41e2742a2 --- /dev/null +++ b/src/app/core/shared/config/config.model.ts @@ -0,0 +1,15 @@ +import { autoserialize, autoserializeAs } from 'cerialize'; + +export abstract class ConfigObject { + + @autoserialize + public name: string; + + @autoserialize + public type: string; + + @autoserialize + public _links: { + [name: string]: string + } +} From 380faf8468ff52b88009313bc3a38cdec06dfb02 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 7 Nov 2017 14:40:57 +0100 Subject: [PATCH 02/77] Refactor config-response-parsing.service --- .../core/data/config-response-parsing.service.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/app/core/data/config-response-parsing.service.ts b/src/app/core/data/config-response-parsing.service.ts index 1eb4da2131..243c639149 100644 --- a/src/app/core/data/config-response-parsing.service.ts +++ b/src/app/core/data/config-response-parsing.service.ts @@ -14,15 +14,17 @@ export class ConfigResponseParsingService implements ResponseParsingService { parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) { let configDefinition; + let payload; + let type; if (isNotEmpty(data.payload._embedded) && Array.isArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]])) { - const type = Object.keys(data.payload._embedded)[0]; - const serializer = new DSpaceRESTv2Serializer(ConfigObjectFactory.getConstructor(type)); - configDefinition = serializer.deserializeArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]]); - + type = Object.keys(data.payload._embedded)[0]; + payload = data.payload._embedded[Object.keys(data.payload._embedded)[0]]; } else { - const serializer = new DSpaceRESTv2Serializer(ConfigObjectFactory.getConstructor(data.payload.type)); - configDefinition = serializer.deserialize(data.payload); + type = data.payload.type; + payload = [data.payload]; } + const serializer = new DSpaceRESTv2Serializer(ConfigObjectFactory.getConstructor(type)); + configDefinition = serializer.deserializeArray(payload); return new ConfigSuccessResponse(configDefinition, data.statusCode); } else { return new ErrorResponse( From 067a95fc88bf5afe1b90cb3c0dd9faf2c964f8c7 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Wed, 8 Nov 2017 10:02:15 +0100 Subject: [PATCH 03/77] Parse embedded data --- src/app/core/cache/response-cache.models.ts | 3 +- src/app/core/config/config-data.ts | 13 ++ src/app/core/config/config.service.ts | 53 +++---- .../data/base-response-parsing.service.ts | 135 +++++++++++++++++ .../data/config-response-parsing.service.ts | 37 +++-- .../core/data/dso-response-parsing.service.ts | 143 ++---------------- .../config-submission-definitions.model.ts | 7 +- src/app/core/shared/config/config-type.ts | 2 + src/app/core/shared/config/config.model.ts | 6 + 9 files changed, 217 insertions(+), 182 deletions(-) create mode 100644 src/app/core/config/config-data.ts create mode 100644 src/app/core/data/base-response-parsing.service.ts diff --git a/src/app/core/cache/response-cache.models.ts b/src/app/core/cache/response-cache.models.ts index ed2bd3ab77..06fc26aa67 100644 --- a/src/app/core/cache/response-cache.models.ts +++ b/src/app/core/cache/response-cache.models.ts @@ -56,7 +56,8 @@ export class ErrorResponse extends RestResponse { export class ConfigSuccessResponse extends RestResponse { constructor( public configDefinition: ConfigObject[], - public statusCode: string + public statusCode: string, + public pageInfo?: PageInfo ) { super(true, statusCode); } diff --git a/src/app/core/config/config-data.ts b/src/app/core/config/config-data.ts new file mode 100644 index 0000000000..efcdb7eed4 --- /dev/null +++ b/src/app/core/config/config-data.ts @@ -0,0 +1,13 @@ +import { PageInfo } from '../shared/page-info.model'; +import { ConfigObject } from '../shared/config/config.model'; + +/** + * A class to represent the data retrieved by a configuration service + */ +export class ConfigData { + constructor( + public pageInfo: PageInfo, + public payload: ConfigObject[] + ) { + } +} diff --git a/src/app/core/config/config.service.ts b/src/app/core/config/config.service.ts index dc689c6e4e..8cc590e1ae 100644 --- a/src/app/core/config/config.service.ts +++ b/src/app/core/config/config.service.ts @@ -1,17 +1,19 @@ import { Injectable } from '@angular/core'; + import { Observable } from 'rxjs/Observable'; import { RequestService } from '../data/request.service'; import { ResponseCacheService } from '../cache/response-cache.service'; import { GlobalConfig } from '../../../config/global-config.interface'; -import { ConfigSuccessResponse, EndpointMap, RootSuccessResponse } from '../cache/response-cache.models'; -import { ConfigRequest, FindAllOptions, RestRequest, RootEndpointRequest } from '../data/request.models'; +import { ConfigSuccessResponse, ErrorResponse, RestResponse } from '../cache/response-cache.models'; +import { ConfigRequest, FindAllOptions, RestRequest } from '../data/request.models'; import { ResponseCacheEntry } from '../cache/response-cache.reducer'; import { hasValue, isNotEmpty } from '../../shared/empty.util'; -import { ConfigObject } from '../shared/config/config.model'; +import { HALEndpointService } from '../shared/hal-endpoint.service'; +import { ConfigData } from './config-data'; @Injectable() -export abstract class ConfigService { +export abstract class ConfigService extends HALEndpointService { protected request: ConfigRequest; protected abstract responseCache: ResponseCacheService; protected abstract requestService: RequestService; @@ -19,12 +21,17 @@ export abstract class ConfigService { protected abstract EnvConfig: GlobalConfig; protected abstract browseEndpoint: string; - protected getConfig(request: RestRequest): Observable { - return this.responseCache.get(request.href) + protected getConfig(request: RestRequest): Observable { + const [successResponse, errorResponse] = this.responseCache.get(request.href) .map((entry: ResponseCacheEntry) => entry.response) + .partition((response: RestResponse) => response.isSuccessful); + return Observable.merge( + errorResponse.flatMap((response: ErrorResponse) => + Observable.throw(new Error(`Couldn't retrieve the config`))), + successResponse .filter((response: ConfigSuccessResponse) => isNotEmpty(response) && isNotEmpty(response.configDefinition)) - .map((response: ConfigSuccessResponse) => response.configDefinition) - .distinctUntilChanged(); + .map((response: ConfigSuccessResponse) => new ConfigData(response.pageInfo, response.configDefinition)) + .distinctUntilChanged()); } protected getConfigByIDHref(endpoint, resourceID): string { @@ -36,7 +43,7 @@ export abstract class ConfigService { const args = []; if (hasValue(options.scopeID)) { - result = `${endpoint}/${this.browseEndpoint}` + result = `${endpoint}/${this.browseEndpoint}`; args.push(`uuid=${options.scopeID}`); } else { result = endpoint; @@ -65,19 +72,7 @@ export abstract class ConfigService { return result; } - protected getEndpointMap(): Observable { - const request = new RootEndpointRequest(this.EnvConfig); - setTimeout(() => { - this.requestService.configure(request); - }, 0); - return this.responseCache.get(request.href) - .map((entry: ResponseCacheEntry) => entry.response) - .filter((response: RootSuccessResponse) => isNotEmpty(response) && isNotEmpty(response.endpointMap)) - .map((response: RootSuccessResponse) => response.endpointMap) - .distinctUntilChanged(); - } - - public getConfigAll(): Observable { + public getConfigAll(): Observable { return this.getEndpoint() .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() @@ -91,16 +86,16 @@ export abstract class ConfigService { .distinctUntilChanged(); } - public getConfigByHref(href: string): Observable { + public getConfigByHref(href: string): Observable { const request = new ConfigRequest(href); this.requestService.configure(request); return this.getConfig(request); } - public getConfigById(id: string): Observable { + public getConfigByName(name: string): Observable { return this.getEndpoint() - .map((endpoint: string) => this.getConfigByIDHref(endpoint, id)) + .map((endpoint: string) => this.getConfigByIDHref(endpoint, name)) .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() .map((endpointURL: string) => new ConfigRequest(endpointURL)) @@ -113,7 +108,7 @@ export abstract class ConfigService { .distinctUntilChanged(); } - public getConfigBySearch(options: FindAllOptions = {}): Observable { + public getConfigBySearch(options: FindAllOptions = {}): Observable { return this.getEndpoint() .map((endpoint: string) => this.getConfigSearchHref(endpoint, options)) .filter((href: string) => isNotEmpty(href)) @@ -128,10 +123,4 @@ export abstract class ConfigService { .distinctUntilChanged(); } - public getEndpoint(): Observable { - return this.getEndpointMap() - .map((map: EndpointMap) => map[this.linkName]) - .distinctUntilChanged(); - } - } diff --git a/src/app/core/data/base-response-parsing.service.ts b/src/app/core/data/base-response-parsing.service.ts new file mode 100644 index 0000000000..d8a4221420 --- /dev/null +++ b/src/app/core/data/base-response-parsing.service.ts @@ -0,0 +1,135 @@ +import { hasNoValue, hasValue, isNotEmpty } from '../../shared/empty.util'; +import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer'; +import { CacheableObject } from '../cache/object-cache.reducer'; +import { PageInfo } from '../shared/page-info.model'; +import { ObjectCacheService } from '../cache/object-cache.service'; +import { GlobalConfig } from '../../../config/global-config.interface'; +import { NormalizedObject } from '../cache/models/normalized-object.model'; +import { GenericConstructor } from '../shared/generic-constructor'; + +function isObjectLevel(halObj: any) { + return isNotEmpty(halObj._links) && hasValue(halObj._links.self); +} + +function isPaginatedResponse(halObj: any) { + return isNotEmpty(halObj.page) && hasValue(halObj._embedded); +} + +/* tslint:disable:max-classes-per-file */ + +class ProcessRequestDTO { + [key: string]: ObjectDomain[] +} + +export abstract class BaseResponseParsingService { + protected abstract EnvConfig: GlobalConfig; + protected abstract objectCache: ObjectCacheService; + protected abstract objectFactory: any; + protected abstract toCache: boolean; + + protected process(data: any, requestHref: string): ProcessRequestDTO { + + if (isNotEmpty(data)) { + if (isPaginatedResponse(data)) { + return this.process(data._embedded, requestHref); + } else if (isObjectLevel(data)) { + return { topLevel: this.deserializeAndCache(data, requestHref) }; + } else { + const result = new ProcessRequestDTO(); + if (Array.isArray(data)) { + result.topLevel = []; + data.forEach((datum) => { + if (isPaginatedResponse(datum)) { + const obj = this.process(datum, requestHref); + result.topLevel = [...result.topLevel, ...this.flattenSingleKeyObject(obj)]; + } else { + result.topLevel = [...result.topLevel, ...this.deserializeAndCache(datum, requestHref)]; + } + }); + } else { + Object.keys(data) + .filter((property) => data.hasOwnProperty(property)) + .filter((property) => hasValue(data[property])) + .forEach((property) => { + if (isPaginatedResponse(data[property])) { + const obj = this.process(data[property], requestHref); + result[property] = this.flattenSingleKeyObject(obj); + } else { + result[property] = this.deserializeAndCache(data[property], requestHref); + } + }); + } + return result; + } + } + } + + protected deserializeAndCache(obj, requestHref: string): ObjectDomain[] { + if (Array.isArray(obj)) { + let result = []; + obj.forEach((o) => result = [...result, ...this.deserializeAndCache(o, requestHref)]); + return result; + } + + const type: ObjectType = obj.type; + if (hasValue(type)) { + const normObjConstructor = this.objectFactory.getConstructor(type) as GenericConstructor; + + if (hasValue(normObjConstructor)) { + const serializer = new DSpaceRESTv2Serializer(normObjConstructor); + + let processed; + if (isNotEmpty(obj._embedded)) { + processed = this.process(obj._embedded, requestHref); + } + const normalizedObj: any = serializer.deserialize(obj); + + if (isNotEmpty(processed)) { + const processedList = {}; + Object.keys(processed).forEach((key) => { + processedList[key] = processed[key].map((no: NormalizedObject) => (this.toCache) ? no.self : no); + }); + Object.assign(normalizedObj, processedList); + } + + if (this.toCache) { + this.addToObjectCache(normalizedObj, requestHref); + } + return [normalizedObj] as any; + + } else { + // TODO: move check to Validator? + // throw new Error(`The server returned an object with an unknown a known type: ${type}`); + return []; + } + + } else { + // TODO: move check to Validator + // throw new Error(`The server returned an object without a type: ${JSON.stringify(obj)}`); + return []; + } + } + + protected addToObjectCache(co: CacheableObject, requestHref: string): void { + if (hasNoValue(co) || hasNoValue(co.self)) { + throw new Error('The server returned an invalid object'); + } + this.objectCache.add(co, this.EnvConfig.cache.msToLive, requestHref); + } + + protected processPageInfo(pageObj: any): PageInfo { + if (isNotEmpty(pageObj)) { + return new DSpaceRESTv2Serializer(PageInfo).deserialize(pageObj); + } else { + return undefined; + } + } + + protected flattenSingleKeyObject(obj: any): any { + const keys = Object.keys(obj); + if (keys.length !== 1) { + throw new Error(`Expected an object with a single key, got: ${JSON.stringify(obj)}`); + } + return obj[keys[0]]; + } +} diff --git a/src/app/core/data/config-response-parsing.service.ts b/src/app/core/data/config-response-parsing.service.ts index 243c639149..90e6dc055e 100644 --- a/src/app/core/data/config-response-parsing.service.ts +++ b/src/app/core/data/config-response-parsing.service.ts @@ -1,31 +1,35 @@ -import { Injectable } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { ResponseParsingService } from './parsing.service'; import { RestRequest } from './request.models'; import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model'; import { ConfigSuccessResponse, ErrorResponse, RestResponse } from '../cache/response-cache.models'; import { isNotEmpty } from '../../shared/empty.util'; -import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer'; import { ConfigObjectFactory } from '../shared/config/config-object-factory'; +import { ConfigObject } from '../shared/config/config.model'; +import { ConfigType } from '../shared/config/config-type'; +import { BaseResponseParsingService } from './base-response-parsing.service'; +import { GLOBAL_CONFIG } from '../../../config'; +import { GlobalConfig } from '../../../config/global-config.interface'; +import { ObjectCacheService } from '../cache/object-cache.service'; + @Injectable() -export class ConfigResponseParsingService implements ResponseParsingService { +export class ConfigResponseParsingService extends BaseResponseParsingService implements ResponseParsingService { + + protected objectFactory = ConfigObjectFactory; + protected toCache = false; + + constructor( + @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, + protected objectCache: ObjectCacheService, + ) { super(); + } parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) { - let configDefinition; - let payload; - let type; - if (isNotEmpty(data.payload._embedded) && Array.isArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]])) { - type = Object.keys(data.payload._embedded)[0]; - payload = data.payload._embedded[Object.keys(data.payload._embedded)[0]]; - } else { - type = data.payload.type; - payload = [data.payload]; - } - const serializer = new DSpaceRESTv2Serializer(ConfigObjectFactory.getConstructor(type)); - configDefinition = serializer.deserializeArray(payload); - return new ConfigSuccessResponse(configDefinition, data.statusCode); + const configDefinition = this.process(data.payload, request.href); + return new ConfigSuccessResponse(configDefinition[Object.keys(configDefinition)[0]], data.statusCode, this.processPageInfo(data.payload.page)); } else { return new ErrorResponse( Object.assign( @@ -35,4 +39,5 @@ export class ConfigResponseParsingService implements ResponseParsingService { ); } } + } diff --git a/src/app/core/data/dso-response-parsing.service.ts b/src/app/core/data/dso-response-parsing.service.ts index b7929498f1..11590d0431 100644 --- a/src/app/core/data/dso-response-parsing.service.ts +++ b/src/app/core/data/dso-response-parsing.service.ts @@ -1,149 +1,34 @@ -import { ObjectCacheService } from '../cache/object-cache.service'; import { Inject, Injectable } from '@angular/core'; + +import { ObjectCacheService } from '../cache/object-cache.service'; import { GlobalConfig } from '../../../config/global-config.interface'; import { GLOBAL_CONFIG } from '../../../config'; import { NormalizedObject } from '../cache/models/normalized-object.model'; -import { hasNoValue, hasValue, isNotEmpty } from '../../shared/empty.util'; import { ResourceType } from '../shared/resource-type'; import { NormalizedObjectFactory } from '../cache/models/normalized-object-factory'; -import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer'; -import { CacheableObject } from '../cache/object-cache.reducer'; import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model'; import { RestResponse, DSOSuccessResponse } from '../cache/response-cache.models'; import { RestRequest } from './request.models'; -import { PageInfo } from '../shared/page-info.model'; + import { ResponseParsingService } from './parsing.service'; - -function isObjectLevel(halObj: any) { - return isNotEmpty(halObj._links) && hasValue(halObj._links.self); -} - -function isPaginatedResponse(halObj: any) { - return isNotEmpty(halObj.page) && hasValue(halObj._embedded); -} - -function flattenSingleKeyObject(obj: any): any { - const keys = Object.keys(obj); - if (keys.length !== 1) { - throw new Error(`Expected an object with a single key, got: ${JSON.stringify(obj)}`); - } - return obj[keys[0]]; -} - -/* tslint:disable:max-classes-per-file */ -class ProcessRequestDTO { - [key: string]: NormalizedObject[] -} +import { BaseResponseParsingService } from './base-response-parsing.service'; @Injectable() -export class DSOResponseParsingService implements ResponseParsingService { +export class DSOResponseParsingService extends BaseResponseParsingService implements ResponseParsingService { + + protected objectFactory = NormalizedObjectFactory; + protected toCache = true; + constructor( - @Inject(GLOBAL_CONFIG) private EnvConfig: GlobalConfig, - private objectCache: ObjectCacheService, - ) { + @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, + protected objectCache: ObjectCacheService, + ) { super(); } parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { - const processRequestDTO = this.process(data.payload, request.href); - const selfLinks = flattenSingleKeyObject(processRequestDTO).map((no) => no.self); + const processRequestDTO = this.process(data.payload, request.href); + const selfLinks = this.flattenSingleKeyObject(processRequestDTO).map((no) => no.self); return new DSOSuccessResponse(selfLinks, data.statusCode, this.processPageInfo(data.payload.page)) } - protected process(data: any, requestHref: string): ProcessRequestDTO { - - if (isNotEmpty(data)) { - if (isPaginatedResponse(data)) { - return this.process(data._embedded, requestHref); - } else if (isObjectLevel(data)) { - return { topLevel: this.deserializeAndCache(data, requestHref) }; - } else { - const result = new ProcessRequestDTO(); - if (Array.isArray(data)) { - result.topLevel = []; - data.forEach((datum) => { - if (isPaginatedResponse(datum)) { - const obj = this.process(datum, requestHref); - result.topLevel = [...result.topLevel, ...flattenSingleKeyObject(obj)]; - } else { - result.topLevel = [...result.topLevel, ...this.deserializeAndCache(datum, requestHref)]; - } - }); - } else { - Object.keys(data) - .filter((property) => data.hasOwnProperty(property)) - .filter((property) => hasValue(data[property])) - .forEach((property) => { - if (isPaginatedResponse(data[property])) { - const obj = this.process(data[property], requestHref); - result[property] = flattenSingleKeyObject(obj); - } else { - result[property] = this.deserializeAndCache(data[property], requestHref); - } - }); - } - return result; - } - } - } - - protected deserializeAndCache(obj, requestHref: string): NormalizedObject[] { - if (Array.isArray(obj)) { - let result = []; - obj.forEach((o) => result = [...result, ...this.deserializeAndCache(o, requestHref)]) - return result; - } - - const type: ResourceType = obj.type; - if (hasValue(type)) { - const normObjConstructor = NormalizedObjectFactory.getConstructor(type); - - if (hasValue(normObjConstructor)) { - const serializer = new DSpaceRESTv2Serializer(normObjConstructor); - - let processed; - if (isNotEmpty(obj._embedded)) { - processed = this.process(obj._embedded, requestHref); - } - const normalizedObj = serializer.deserialize(obj); - - if (isNotEmpty(processed)) { - const linksOnly = {}; - Object.keys(processed).forEach((key) => { - linksOnly[key] = processed[key].map((no: NormalizedObject) => no.self); - }); - Object.assign(normalizedObj, linksOnly); - } - - this.addToObjectCache(normalizedObj, requestHref); - return [normalizedObj]; - - } else { - // TODO: move check to Validator? - // throw new Error(`The server returned an object with an unknown a known type: ${type}`); - return []; - } - - } else { - // TODO: move check to Validator - // throw new Error(`The server returned an object without a type: ${JSON.stringify(obj)}`); - return []; - } - } - - protected addToObjectCache(co: CacheableObject, requestHref: string): void { - if (hasNoValue(co) || hasNoValue(co.self)) { - throw new Error('The server returned an invalid object'); - } - this.objectCache.add(co, this.EnvConfig.cache.msToLive, requestHref); - } - - protected processPageInfo(pageObj: any): PageInfo { - if (isNotEmpty(pageObj)) { - return new DSpaceRESTv2Serializer(PageInfo).deserialize(pageObj); - } else { - return undefined; - } - } - } -/* tslint:enable:max-classes-per-file */ diff --git a/src/app/core/shared/config/config-submission-definitions.model.ts b/src/app/core/shared/config/config-submission-definitions.model.ts index 271ab7281b..8249d2b118 100644 --- a/src/app/core/shared/config/config-submission-definitions.model.ts +++ b/src/app/core/shared/config/config-submission-definitions.model.ts @@ -1,7 +1,6 @@ -import { autoserialize, inheritSerialization } from 'cerialize'; +import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize'; import { ConfigObject } from './config.model'; import { SubmissionSectionModel } from './config-submission-section.model'; -import { RemoteData } from '../../data/remote-data'; @inheritSerialization(ConfigObject) export class SubmissionDefinitionsModel extends ConfigObject { @@ -9,7 +8,7 @@ export class SubmissionDefinitionsModel extends ConfigObject { @autoserialize isDefault: boolean; - @autoserialize - sections: RemoteData; + @autoserializeAs(SubmissionSectionModel) + sections: SubmissionSectionModel[]; } diff --git a/src/app/core/shared/config/config-type.ts b/src/app/core/shared/config/config-type.ts index d4d88b8a60..ab0a18e516 100644 --- a/src/app/core/shared/config/config-type.ts +++ b/src/app/core/shared/config/config-type.ts @@ -2,6 +2,8 @@ * TODO replace with actual string enum after upgrade to TypeScript 2.4: * https://github.com/Microsoft/TypeScript/pull/15486 */ +import { ResourceType } from '../resource-type'; + export enum ConfigType { SubmissionDefinitions = 'submissiondefinitions', SubmissionDefinition = 'submissiondefinition', diff --git a/src/app/core/shared/config/config.model.ts b/src/app/core/shared/config/config.model.ts index e41e2742a2..8d86f317e1 100644 --- a/src/app/core/shared/config/config.model.ts +++ b/src/app/core/shared/config/config.model.ts @@ -12,4 +12,10 @@ export abstract class ConfigObject { public _links: { [name: string]: string } + + /** + * The link to the rest endpoint where this config object can be found + */ + @autoserialize + self: string; } From 362525c6ea4469ff3b4bafae109c11297945b1d3 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Fri, 10 Nov 2017 12:04:04 +0100 Subject: [PATCH 04/77] Remove setTimeout --- src/app/core/config/config.service.ts | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/app/core/config/config.service.ts b/src/app/core/config/config.service.ts index 8cc590e1ae..a1a674d10a 100644 --- a/src/app/core/config/config.service.ts +++ b/src/app/core/config/config.service.ts @@ -12,7 +12,6 @@ import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { ConfigData } from './config-data'; -@Injectable() export abstract class ConfigService extends HALEndpointService { protected request: ConfigRequest; protected abstract responseCache: ResponseCacheService; @@ -77,11 +76,7 @@ export abstract class ConfigService extends HALEndpointService { .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() .map((endpointURL: string) => new ConfigRequest(endpointURL)) - .do((request: RestRequest) => { - setTimeout(() => { - this.requestService.configure(request); - }, 0); - }) + .do((request: RestRequest) => this.requestService.configure(request)) .flatMap((request: RestRequest) => this.getConfig(request)) .distinctUntilChanged(); } @@ -99,11 +94,7 @@ export abstract class ConfigService extends HALEndpointService { .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() .map((endpointURL: string) => new ConfigRequest(endpointURL)) - .do((request: RestRequest) => { - setTimeout(() => { - this.requestService.configure(request); - }, 0); - }) + .do((request: RestRequest) => this.requestService.configure(request)) .flatMap((request: RestRequest) => this.getConfig(request)) .distinctUntilChanged(); } @@ -114,11 +105,7 @@ export abstract class ConfigService extends HALEndpointService { .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() .map((endpointURL: string) => new ConfigRequest(endpointURL)) - .do((request: RestRequest) => { - setTimeout(() => { - this.requestService.configure(request); - }, 0); - }) + .do((request: RestRequest) => this.requestService.configure(request)) .flatMap((request: RestRequest) => this.getConfig(request)) .distinctUntilChanged(); } From a37b2da6a660943859f4f1cc5cfe752a7b36b8e8 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Sun, 12 Nov 2017 19:38:27 +0100 Subject: [PATCH 05/77] Add unit tests --- src/app/core/config/config.service.spec.ts | 103 +++++++++ src/app/core/config/config.service.ts | 12 +- src/app/core/data/comcol-data.service.spec.ts | 12 +- .../config-response-parsing.service.spec.ts | 212 ++++++++++++++++++ .../data/config-response-parsing.service.ts | 2 +- src/app/core/data/request.service.ts | 1 - 6 files changed, 328 insertions(+), 14 deletions(-) create mode 100644 src/app/core/config/config.service.spec.ts create mode 100644 src/app/core/data/config-response-parsing.service.spec.ts diff --git a/src/app/core/config/config.service.spec.ts b/src/app/core/config/config.service.spec.ts new file mode 100644 index 0000000000..c0d02be82a --- /dev/null +++ b/src/app/core/config/config.service.spec.ts @@ -0,0 +1,103 @@ +import { cold, getTestScheduler, hot } from 'jasmine-marbles'; +import { TestScheduler } from 'rxjs/Rx'; +import { GlobalConfig } from '../../../config'; +import { ResponseCacheService } from '../cache/response-cache.service'; +import { ConfigService } from './config.service'; +import { RequestService } from '../data/request.service'; +import { ConfigRequest, FindAllOptions } from '../data/request.models'; + +const LINK_NAME = 'test'; +const BROWSE = 'search/findByCollection'; + +class TestService extends ConfigService { + protected linkName = LINK_NAME; + protected browseEndpoint = BROWSE; + + constructor( + protected responseCache: ResponseCacheService, + protected requestService: RequestService, + protected EnvConfig: GlobalConfig + ) { + super(); + } +} + +describe('ConfigService', () => { + let scheduler: TestScheduler; + let service: TestService; + let responseCache: ResponseCacheService; + let requestService: RequestService; + + const envConfig = {} as GlobalConfig; + const findOptions: FindAllOptions = new FindAllOptions(); + + const scopeName = 'traditional'; + const scopeID = 'd9d30c0c-69b7-4369-8397-ca67c888974d'; + const configEndpoint = 'https://rest.api/config'; + const serviceEndpoint = `${configEndpoint}/${LINK_NAME}`; + const scopedEndpoint = `${serviceEndpoint}/${scopeName}`; + const searchEndpoint = `${serviceEndpoint}/${BROWSE}?uuid=${scopeID}`; + + function initMockRequestService(): RequestService { + return jasmine.createSpyObj('requestService', ['configure']); + } + + function initMockResponseCacheService(isSuccessful: boolean): ResponseCacheService { + return jasmine.createSpyObj('responseCache', { + get: cold('c-', { + c: { response: { isSuccessful } } + }) + }); + } + + function initTestService(): TestService { + return new TestService( + responseCache, + requestService, + envConfig + ); + } + + beforeEach(() => { + responseCache = initMockResponseCacheService(true); + requestService = initMockRequestService(); + service = initTestService(); + scheduler = getTestScheduler(); + spyOn(service, 'getEndpoint').and + .returnValue(hot('--a-', { a: serviceEndpoint })); + }); + + describe('getConfigByHref', () => { + + it('should configure a new ConfigRequest', () => { + const expected = new ConfigRequest(scopedEndpoint); + scheduler.schedule(() => service.getConfigByHref(scopedEndpoint).subscribe()); + scheduler.flush(); + + expect(requestService.configure).toHaveBeenCalledWith(expected); + }); + }); + + describe('getConfigByName', () => { + + it('should configure a new ConfigRequest', () => { + const expected = new ConfigRequest(scopedEndpoint); + scheduler.schedule(() => service.getConfigByName(scopeName).subscribe()); + scheduler.flush(); + + expect(requestService.configure).toHaveBeenCalledWith(expected); + }); + }); + + describe('getConfigBySearch', () => { + + it('should configure a new ConfigRequest', () => { + findOptions.scopeID = scopeID; + const expected = new ConfigRequest(searchEndpoint); + scheduler.schedule(() => service.getConfigBySearch(findOptions).subscribe()); + scheduler.flush(); + + expect(requestService.configure).toHaveBeenCalledWith(expected); + }); + }); +}); diff --git a/src/app/core/config/config.service.ts b/src/app/core/config/config.service.ts index a1a674d10a..55c4055ed7 100644 --- a/src/app/core/config/config.service.ts +++ b/src/app/core/config/config.service.ts @@ -28,13 +28,13 @@ export abstract class ConfigService extends HALEndpointService { errorResponse.flatMap((response: ErrorResponse) => Observable.throw(new Error(`Couldn't retrieve the config`))), successResponse - .filter((response: ConfigSuccessResponse) => isNotEmpty(response) && isNotEmpty(response.configDefinition)) - .map((response: ConfigSuccessResponse) => new ConfigData(response.pageInfo, response.configDefinition)) - .distinctUntilChanged()); + .filter((response: ConfigSuccessResponse) => isNotEmpty(response) && isNotEmpty(response.configDefinition)) + .map((response: ConfigSuccessResponse) => new ConfigData(response.pageInfo, response.configDefinition)) + .distinctUntilChanged()); } - protected getConfigByIDHref(endpoint, resourceID): string { - return `${endpoint}/${resourceID}`; + protected getConfigByNameHref(endpoint, resourceName): string { + return `${endpoint}/${resourceName}`; } protected getConfigSearchHref(endpoint, options: FindAllOptions = {}): string { @@ -90,7 +90,7 @@ export abstract class ConfigService extends HALEndpointService { public getConfigByName(name: string): Observable { return this.getEndpoint() - .map((endpoint: string) => this.getConfigByIDHref(endpoint, name)) + .map((endpoint: string) => this.getConfigByNameHref(endpoint, name)) .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() .map((endpointURL: string) => new ConfigRequest(endpointURL)) diff --git a/src/app/core/data/comcol-data.service.spec.ts b/src/app/core/data/comcol-data.service.spec.ts index be7949826f..0d78a9fa8d 100644 --- a/src/app/core/data/comcol-data.service.spec.ts +++ b/src/app/core/data/comcol-data.service.spec.ts @@ -66,7 +66,7 @@ describe('ComColDataService', () => { return jasmine.createSpyObj('requestService', ['configure']); } - function initMockResponceCacheService(isSuccessful: boolean): ResponseCacheService { + function initMockResponseCacheService(isSuccessful: boolean): ResponseCacheService { return jasmine.createSpyObj('responseCache', { get: cold('c-', { c: { response: { isSuccessful } } @@ -107,7 +107,7 @@ describe('ComColDataService', () => { cds = initMockCommunityDataService(); requestService = initMockRequestService(); objectCache = initMockObjectCacheService(); - responseCache = initMockResponceCacheService(true); + responseCache = initMockResponseCacheService(true); service = initTestService(); const expected = new FindByIDRequest(communityEndpoint, scopeID); @@ -123,7 +123,7 @@ describe('ComColDataService', () => { cds = initMockCommunityDataService(); requestService = initMockRequestService(); objectCache = initMockObjectCacheService(); - responseCache = initMockResponceCacheService(true); + responseCache = initMockResponseCacheService(true); service = initTestService(); }); @@ -146,7 +146,7 @@ describe('ComColDataService', () => { cds = initMockCommunityDataService(); requestService = initMockRequestService(); objectCache = initMockObjectCacheService(); - responseCache = initMockResponceCacheService(false); + responseCache = initMockResponseCacheService(false); service = initTestService(); }); @@ -163,12 +163,12 @@ describe('ComColDataService', () => { cds = initMockCommunityDataService(); requestService = initMockRequestService(); objectCache = initMockObjectCacheService(); - responseCache = initMockResponceCacheService(true); + responseCache = initMockResponseCacheService(true); service = initTestService(); }); it('should return this.getEndpoint()', () => { - spyOn(service, 'getEndpoint').and.returnValue(cold('--e-', { e: serviceEndpoint })) + spyOn(service, 'getEndpoint').and.returnValue(cold('--e-', { e: serviceEndpoint })); const result = service.getScopedEndpoint(undefined); const expected = cold('--f-', { f: serviceEndpoint }); diff --git a/src/app/core/data/config-response-parsing.service.spec.ts b/src/app/core/data/config-response-parsing.service.spec.ts new file mode 100644 index 0000000000..62291548a7 --- /dev/null +++ b/src/app/core/data/config-response-parsing.service.spec.ts @@ -0,0 +1,212 @@ +import { ConfigSuccessResponse, ErrorResponse } from '../cache/response-cache.models'; +import { ConfigResponseParsingService } from './config-response-parsing.service'; +import { ObjectCacheService } from '../cache/object-cache.service'; +import { GlobalConfig } from '../../../config/global-config.interface'; +import { ConfigRequest } from './request.models'; + +import { Store } from '@ngrx/store'; +import { CoreState } from '../core.reducers'; +import { SubmissionDefinitionsModel } from '../shared/config/config-submission-definitions.model'; +import { SubmissionSectionModel } from '../shared/config/config-submission-section.model'; + +describe('ConfigResponseParsingService', () => { + let service: ConfigResponseParsingService; + + const EnvConfig = {} as GlobalConfig; + const store = {} as Store; + const objectCacheService = new ObjectCacheService(store); + + beforeEach(() => { + service = new ConfigResponseParsingService(EnvConfig, objectCacheService); + }); + + describe('parse', () => { + const validRequest = new ConfigRequest('https://rest.api/config/submissiondefinitions/traditional'); + + const validResponse = { + payload: { + id:'traditional', + name:'traditional', + type:'submissiondefinition', + isDefault:true, + _links:{ + sections:{ + href:'https://rest.api/config/submissiondefinitions/traditional/sections' + },self:{ + href:'https://rest.api/config/submissiondefinitions/traditional' + } + }, + _embedded:{ + sections:{ + page:{ + number:0, + size:4, + totalPages:1,totalElements:4 + }, + _embedded:[ + { + id:'traditionalpageone',header:'submit.progressbar.describe.stepone', + mandatory:true, + sectionType:'submission-form', + type:'submissionsection', + _links:{ + self:{ + href:'https://rest.api/config/submissionsections/traditionalpageone' + }, + config:{ + href:'https://rest.api/config/submissionforms/traditionalpageone' + } + } + }, { + id:'traditionalpagetwo', + header:'submit.progressbar.describe.steptwo', + mandatory:true, + sectionType:'submission-form', + type:'submissionsection', + _links:{ + self:{ + href:'https://rest.api/config/submissionsections/traditionalpagetwo' + }, + config:{ + href:'https://rest.api/config/submissionforms/traditionalpagetwo' + } + } + }, { + id:'upload', + header:'submit.progressbar.upload', + mandatory:false, + sectionType:'upload', + type:'submissionsection', + _links:{ + self:{ + href:'https://rest.api/config/submissionsections/upload' + }, + config: { + href:'https://rest.api/config/submissionuploads/upload' + } + } + }, { + id:'license', + header:'submit.progressbar.license', + mandatory:true, + sectionType:'license', + visibility:{ + main:null, + other:'READONLY' + }, + type:'submissionsection', + _links:{ + self:{ + href:'https://rest.api/config/submissionsections/license' + } + } + } + ], + _links:{ + self:'https://rest.api/config/submissiondefinitions/traditional/sections' + } + } + } + }, + statusCode:'200' + }; + + const invalidResponse1 = { + payload: {}, + statusCode:'200' + }; + + const invalidResponse2 = { + payload: { + id:'traditional', + name:'traditional', + type:'submissiondefinition', + isDefault:true, + _links:{}, + _embedded:{ + sections:{ + page:{ + number:0, + size:4, + totalPages:1,totalElements:4 + }, + _embedded:[{},{}], + _links:{ + self:'https://rest.api/config/submissiondefinitions/traditional/sections' + } + } + } + }, + statusCode:'200' + }; + + const invalidResponse3 = { + payload: { + _links: { self: { href: 'https://rest.api/config/submissiondefinitions/traditional' } }, + page: { size: 20, totalElements: 2, totalPages: 1, number: 0 } + }, statusCode: '500' + }; + + const definitions = [ + Object.assign(new SubmissionDefinitionsModel(), { + isDefault: true, + name: 'traditional', + type: 'submissiondefinition', + _links: {}, + sections: [ + Object.assign(new SubmissionSectionModel(), { + header: 'submit.progressbar.describe.stepone', + mandatory: true, + sectionType: 'submission-form', + type: 'submissionsection', + _links: {} + }), + Object.assign(new SubmissionSectionModel(), { + header: 'submit.progressbar.describe.steptwo', + mandatory: true, + sectionType: 'submission-form', + type: 'submissionsection', + _links: {} + }), + Object.assign(new SubmissionSectionModel(), { + header: 'submit.progressbar.upload', + mandatory: false, + sectionType: 'upload', + type: 'submissionsection', + _links: {} + }), + Object.assign(new SubmissionSectionModel(), { + header: 'submit.progressbar.license', + mandatory: true, + sectionType: 'license', + type: 'submissionsection', + _links: {} + }) + ] + }) + ]; + + it('should return a ConfigSuccessResponse if data contains a valid config endpoint response', () => { + const response = service.parse(validRequest, validResponse); + expect(response.constructor).toBe(ConfigSuccessResponse); + }); + + it('should return an ErrorResponse if data contains an invalid config endpoint response', () => { + const response1 = service.parse(validRequest, invalidResponse1); + const response2 = service.parse(validRequest, invalidResponse2); + expect(response1.constructor).toBe(ErrorResponse); + expect(response2.constructor).toBe(ErrorResponse); + }); + + it('should return an ErrorResponse if data contains a statuscode other than 200', () => { + const response = service.parse(validRequest, invalidResponse3); + expect(response.constructor).toBe(ErrorResponse); + }); + + it('should return a ConfigSuccessResponse with the ConfigDefinitions in data', () => { + const response = service.parse(validRequest, validResponse); + expect((response as any).configDefinition).toEqual(definitions); + }); + + }); +}); diff --git a/src/app/core/data/config-response-parsing.service.ts b/src/app/core/data/config-response-parsing.service.ts index 90e6dc055e..69be4bbc02 100644 --- a/src/app/core/data/config-response-parsing.service.ts +++ b/src/app/core/data/config-response-parsing.service.ts @@ -27,7 +27,7 @@ export class ConfigResponseParsingService extends BaseResponseParsingService imp } parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { - if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) { + if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && data.statusCode === '200') { const configDefinition = this.process(data.payload, request.href); return new ConfigSuccessResponse(configDefinition[Object.keys(configDefinition)[0]], data.statusCode, this.processPageInfo(data.payload.page)); } else { diff --git a/src/app/core/data/request.service.ts b/src/app/core/data/request.service.ts index 3036c7be21..0eee771a52 100644 --- a/src/app/core/data/request.service.ts +++ b/src/app/core/data/request.service.ts @@ -26,7 +26,6 @@ export function requestStateSelector(): MemoizedSelector Date: Fri, 24 Nov 2017 15:47:11 +0100 Subject: [PATCH 06/77] Update config-submission-section.model --- .../core/shared/config/config-submission-section.model.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/core/shared/config/config-submission-section.model.ts b/src/app/core/shared/config/config-submission-section.model.ts index 17bd6e3beb..0eb9daaeab 100644 --- a/src/app/core/shared/config/config-submission-section.model.ts +++ b/src/app/core/shared/config/config-submission-section.model.ts @@ -13,4 +13,10 @@ export class SubmissionSectionModel extends ConfigObject { @autoserialize sectionType: string; + @autoserialize + visibility: { + main: any, + other: any + } + } From b36498727f5209296085a007c7f7cdb80c73024f Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Fri, 24 Nov 2017 15:49:16 +0100 Subject: [PATCH 07/77] Remove empty line --- src/app/core/core.module.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index e001d83bd7..f4c7e2bbcc 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -32,7 +32,6 @@ import { ServerResponseService } from '../shared/server-response.service'; import { NativeWindowFactory, NativeWindowService } from '../shared/window.service'; import { BrowseService } from './browse/browse.service'; import { BrowseResponseParsingService } from './data/browse-response-parsing.service'; - import { ConfigResponseParsingService } from './data/config-response-parsing.service'; import { RouteService } from '../shared/route.service'; import { SubmissionDefinitionsConfigService } from './config/submission-definitions-config.service'; @@ -71,7 +70,6 @@ const PROVIDERS = [ ServerResponseService, BrowseResponseParsingService, BrowseService, - ConfigResponseParsingService, RouteService, SubmissionDefinitionsConfigService, From 2ea8a561ffdd715d7667c8b4163c9f066e397e59 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Fri, 24 Nov 2017 16:04:09 +0100 Subject: [PATCH 08/77] 130: added tests for object-list component --- src/app/object-list/object-list.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/object-list/object-list.component.html b/src/app/object-list/object-list.component.html index b97524d58c..0d488b5298 100644 --- a/src/app/object-list/object-list.component.html +++ b/src/app/object-list/object-list.component.html @@ -8,7 +8,7 @@ (pageChange)="onPageChange($event)" (pageSizeChange)="onPageSizeChange($event)" (sortDirectionChange)="onSortDirectionChange($event)" - (sortFieldChange)="onSortDirectionChange($event)" + (sortFieldChange)="onSortFieldChange($event)" (paginationChange)="onPaginationChange($event)">
  • From 532b1413445cb2a921835305443c58bce3c052c9 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Fri, 24 Nov 2017 16:06:19 +0100 Subject: [PATCH 09/77] 130: added tests for object-list component --- .../object-list/object-list.component.spec.ts | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/app/object-list/object-list.component.spec.ts diff --git a/src/app/object-list/object-list.component.spec.ts b/src/app/object-list/object-list.component.spec.ts new file mode 100644 index 0000000000..77a5351920 --- /dev/null +++ b/src/app/object-list/object-list.component.spec.ts @@ -0,0 +1,151 @@ +import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; +import { ObjectListComponent } from './object-list.component'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; + +fdescribe('ObjectListComponent', () => { + let comp: ObjectListComponent; + let fixture: ComponentFixture; + const testEvent = {test: 'test'} + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [], + declarations: [ObjectListComponent], + schemas: [NO_ERRORS_SCHEMA] + }).overrideComponent(ObjectListComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ObjectListComponent); + comp = fixture.componentInstance; // SearchPageComponent test instance + fixture.detectChanges(); + }); + + describe('when the pageChange output on the pagination is triggered', () => { + beforeEach(() => { + spyOn(comp, 'onPageChange'); + const paginationEl = fixture.debugElement.query(By.css('ds-pagination')); + paginationEl.triggerEventHandler('pageChange', testEvent); + }); + + it('should call onPageChange on the component', () => { + expect(comp.onPageChange).toHaveBeenCalledWith(testEvent); + }); + }); + + describe('when the pageSizeChange output on the pagination is triggered', () => { + beforeEach(() => { + spyOn(comp, 'onPageSizeChange'); + const paginationEl = fixture.debugElement.query(By.css('ds-pagination')); + paginationEl.triggerEventHandler('pageSizeChange', testEvent); + }); + + it('should call onPageSizeChange on the component', () => { + expect(comp.onPageSizeChange).toHaveBeenCalledWith(testEvent); + }); + }); + + describe('when the sortDirectionChange output on the pagination is triggered', () => { + beforeEach(() => { + spyOn(comp, 'onSortDirectionChange'); + const paginationEl = fixture.debugElement.query(By.css('ds-pagination')); + paginationEl.triggerEventHandler('sortDirectionChange', testEvent); + }); + + it('should call onSortDirectionChange on the component', () => { + expect(comp.onSortDirectionChange).toHaveBeenCalledWith(testEvent); + }); + }); + + describe('when the sortFieldChange output on the pagination is triggered', () => { + beforeEach(() => { + spyOn(comp, 'onSortFieldChange'); + const paginationEl = fixture.debugElement.query(By.css('ds-pagination')); + paginationEl.triggerEventHandler('sortFieldChange', testEvent); + }); + + it('should call onSortFieldChange on the component', () => { + expect(comp.onSortFieldChange).toHaveBeenCalledWith(testEvent); + }); + }); + + describe('when the paginationChange output on the pagination is triggered', () => { + beforeEach(() => { + spyOn(comp, 'onPaginationChange'); + const paginationEl = fixture.debugElement.query(By.css('ds-pagination')); + paginationEl.triggerEventHandler('paginationChange', testEvent); + }); + + it('should call onPaginationChange on the component', () => { + expect(comp.onPaginationChange).toHaveBeenCalledWith(testEvent); + }); + }); + + describe('when onPageChange is triggered with an event', () => { + beforeEach(() => { + spyOn(comp.pageChange, 'emit'); + comp.onPageChange(testEvent); + }); + + it('should emit the value from the pageChange EventEmitter', fakeAsync(() => { + tick(1); + expect(comp.pageChange.emit).toHaveBeenCalled(); + expect(comp.pageChange.emit).toHaveBeenCalledWith(testEvent); + })); + }); + + describe('when onPageSizeChange is triggered with an event', () => { + beforeEach(() => { + spyOn(comp.pageSizeChange, 'emit'); + comp.onPageSizeChange(testEvent); + }); + + it('should emit the value from the pageSizeChange EventEmitter', fakeAsync(() => { + tick(1); + expect(comp.pageSizeChange.emit).toHaveBeenCalled(); + expect(comp.pageSizeChange.emit).toHaveBeenCalledWith(testEvent); + })); + }); + + describe('when onSortDirectionChange is triggered with an event', () => { + beforeEach(() => { + spyOn(comp.sortDirectionChange, 'emit'); + comp.onSortDirectionChange(testEvent); + }); + + it('should emit the value from the sortDirectionChange EventEmitter', fakeAsync(() => { + tick(1); + expect(comp.sortDirectionChange.emit).toHaveBeenCalled(); + expect(comp.sortDirectionChange.emit).toHaveBeenCalledWith(testEvent); + })); + }); + + describe('when onSortFieldChange is triggered with an event', () => { + beforeEach(() => { + spyOn(comp.sortFieldChange, 'emit'); + comp.onSortFieldChange(testEvent); + }); + + it('should emit the value from the sortFieldChange EventEmitter', fakeAsync(() => { + tick(1); + expect(comp.sortFieldChange.emit).toHaveBeenCalled(); + expect(comp.sortFieldChange.emit).toHaveBeenCalledWith(testEvent); + })); + }); + + describe('when onPaginationChange is triggered with an event', () => { + beforeEach(() => { + spyOn(comp.paginationChange, 'emit'); + comp.onPaginationChange(testEvent); + }); + + it('should emit the value from the paginationChange EventEmitter', fakeAsync(() => { + tick(1); + expect(comp.paginationChange.emit).toHaveBeenCalled(); + expect(comp.paginationChange.emit).toHaveBeenCalledWith(testEvent); + })); + }); +}); From ad6d42cd42a84c7d3aba0eeac02ed56fcf9dba10 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Mon, 27 Nov 2017 12:39:36 +0100 Subject: [PATCH 10/77] Fix config-response-parsing.service.spec --- .../config-response-parsing.service.spec.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/app/core/data/config-response-parsing.service.spec.ts b/src/app/core/data/config-response-parsing.service.spec.ts index 62291548a7..46e6d61f8f 100644 --- a/src/app/core/data/config-response-parsing.service.spec.ts +++ b/src/app/core/data/config-response-parsing.service.spec.ts @@ -48,6 +48,10 @@ describe('ConfigResponseParsingService', () => { id:'traditionalpageone',header:'submit.progressbar.describe.stepone', mandatory:true, sectionType:'submission-form', + visibility:{ + main:null, + other:'READONLY' + }, type:'submissionsection', _links:{ self:{ @@ -62,6 +66,10 @@ describe('ConfigResponseParsingService', () => { header:'submit.progressbar.describe.steptwo', mandatory:true, sectionType:'submission-form', + visibility:{ + main:null, + other:'READONLY' + }, type:'submissionsection', _links:{ self:{ @@ -76,6 +84,10 @@ describe('ConfigResponseParsingService', () => { header:'submit.progressbar.upload', mandatory:false, sectionType:'upload', + visibility:{ + main:null, + other:'READONLY' + }, type:'submissionsection', _links:{ self:{ @@ -158,6 +170,10 @@ describe('ConfigResponseParsingService', () => { header: 'submit.progressbar.describe.stepone', mandatory: true, sectionType: 'submission-form', + visibility:{ + main:null, + other:'READONLY' + }, type: 'submissionsection', _links: {} }), @@ -165,6 +181,10 @@ describe('ConfigResponseParsingService', () => { header: 'submit.progressbar.describe.steptwo', mandatory: true, sectionType: 'submission-form', + visibility:{ + main:null, + other:'READONLY' + }, type: 'submissionsection', _links: {} }), @@ -172,6 +192,10 @@ describe('ConfigResponseParsingService', () => { header: 'submit.progressbar.upload', mandatory: false, sectionType: 'upload', + visibility:{ + main:null, + other:'READONLY' + }, type: 'submissionsection', _links: {} }), @@ -179,6 +203,10 @@ describe('ConfigResponseParsingService', () => { header: 'submit.progressbar.license', mandatory: true, sectionType: 'license', + visibility:{ + main:null, + other:'READONLY' + }, type: 'submissionsection', _links: {} }) From 6592d7615426618814dd0bd0e104de5e18cf1e48 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Tue, 28 Nov 2017 13:20:14 +0100 Subject: [PATCH 11/77] 130: added tests for request reducer --- src/app/core/data/request.reducer.spec.ts | 146 ++++++++++++++++++ .../object-list/object-list.component.spec.ts | 2 +- 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 src/app/core/data/request.reducer.spec.ts diff --git a/src/app/core/data/request.reducer.spec.ts b/src/app/core/data/request.reducer.spec.ts new file mode 100644 index 0000000000..4ae3757e89 --- /dev/null +++ b/src/app/core/data/request.reducer.spec.ts @@ -0,0 +1,146 @@ +import * as deepFreeze from 'deep-freeze'; + +import { requestReducer, RequestState } from './request.reducer'; +import { + RequestCompleteAction, RequestConfigureAction, RequestExecuteAction +} from './request.actions'; +import { RestRequest } from './request.models'; + +class NullAction extends RequestCompleteAction { + type = null; + payload = null; + + constructor() { + super(null); + } +} + +describe('requestReducer', () => { + const link1 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/567a639f-f5ff-4126-807c-b7d0910808c8'; + const link2 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/1911e8a4-6939-490c-b58b-a5d70f8d91fb'; + const testState: RequestState = { + [link1]: { + request: new RestRequest(link1), + requestPending: false, + responsePending: false, + completed: false + } + }; + deepFreeze(testState); + + it('should return the current state when no valid actions have been made', () => { + const action = new NullAction(); + const newState = requestReducer(testState, action); + + expect(newState).toEqual(testState); + }); + + it('should start with an empty cache', () => { + const action = new NullAction(); + const initialState = requestReducer(undefined, action); + + expect(initialState).toEqual(Object.create(null)); + }); + + it('should add the new RestRequest and set \'requestPending\' to true, \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to an CONFIGURE action', () => { + const state = testState; + const request = new RestRequest(link2); + + const action = new RequestConfigureAction(request); + const newState = requestReducer(state, action); + + expect(newState[link2].request.href).toEqual(link2); + expect(newState[link2].requestPending).toEqual(true); + expect(newState[link2].responsePending).toEqual(false); + expect(newState[link2].completed).toEqual(false); + }); + + it('should set \'requestPending\' to false, \'responsePending\' to false and leave \'completed\' untouched for the given RestRequest in the state, in response to an EXECUTE action', () => { + const state = testState; + + const action = new RequestExecuteAction(link1); + const newState = requestReducer(state, action); + + expect(newState[link1].request.href).toEqual(link1); + expect(newState[link1].requestPending).toEqual(false); + expect(newState[link1].responsePending).toEqual(true); + expect(newState[link1].completed).toEqual(state[link1].completed); + }); + it('should leave \'requestPending\' untouched, set \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to an COMPLETE action', () => { + const state = testState; + + const action = new RequestCompleteAction(link1); + const newState = requestReducer(state, action); + + expect(newState[link1].request.href).toEqual(link1); + expect(newState[link1].requestPending).toEqual(state[link1].requestPending); + expect(newState[link1].responsePending).toEqual(false); + expect(newState[link1].completed).toEqual(true); + }); + + // + // it('should overwrite an object in the cache in response to an ADD action if it already exists', () => { + // const objectToCache = { self: selfLink1, foo: 'baz', somethingElse: true }; + // const timeAdded = new Date().getTime(); + // const msToLive = 900000; + // const requestHref = 'https://rest.api/endpoint/selfLink1'; + // const action = new AddToObjectCacheAction(objectToCache, timeAdded, msToLive, requestHref); + // const newState = requestReducer(testState, action); + // + // /* tslint:disable:no-string-literal */ + // expect(newState[selfLink1].data['foo']).toBe('baz'); + // expect(newState[selfLink1].data['somethingElse']).toBe(true); + // /* tslint:enable:no-string-literal */ + // }); + // + // it('should perform the ADD action without affecting the previous state', () => { + // const state = Object.create(null); + // const objectToCache = { self: selfLink1 }; + // const timeAdded = new Date().getTime(); + // const msToLive = 900000; + // const requestHref = 'https://rest.api/endpoint/selfLink1'; + // const action = new AddToObjectCacheAction(objectToCache, timeAdded, msToLive, requestHref); + // deepFreeze(state); + // + // requestReducer(state, action); + // }); + // + // it('should remove the specified object from the cache in response to the REMOVE action', () => { + // const action = new RemoveFromObjectCacheAction(selfLink1); + // const newState = requestReducer(testState, action); + // + // expect(testState[selfLink1]).not.toBeUndefined(); + // expect(newState[selfLink1]).toBeUndefined(); + // }); + // + // it("shouldn't do anything in response to the REMOVE action for an object that isn't cached", () => { + // const wrongKey = "this isn't cached"; + // const action = new RemoveFromObjectCacheAction(wrongKey); + // const newState = requestReducer(testState, action); + // + // expect(testState[wrongKey]).toBeUndefined(); + // expect(newState).toEqual(testState); + // }); + // + // it('should perform the REMOVE action without affecting the previous state', () => { + // const action = new RemoveFromObjectCacheAction(selfLink1); + // // testState has already been frozen above + // requestReducer(testState, action); + // }); + // + // it('should set the timestamp of all objects in the cache in response to a RESET_TIMESTAMPS action', () => { + // const newTimestamp = new Date().getTime(); + // const action = new ResetObjectCacheTimestampsAction(newTimestamp); + // const newState = requestReducer(testState, action); + // Object.keys(newState).forEach((key) => { + // expect(newState[key].timeAdded).toEqual(newTimestamp); + // }); + // }); + // + // it('should perform the RESET_TIMESTAMPS action without affecting the previous state', () => { + // const action = new ResetObjectCacheTimestampsAction(new Date().getTime()); + // // testState has already been frozen above + // requestReducer(testState, action); + // }); + +}); diff --git a/src/app/object-list/object-list.component.spec.ts b/src/app/object-list/object-list.component.spec.ts index 77a5351920..7e0b704a19 100644 --- a/src/app/object-list/object-list.component.spec.ts +++ b/src/app/object-list/object-list.component.spec.ts @@ -3,7 +3,7 @@ import { ObjectListComponent } from './object-list.component'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; -fdescribe('ObjectListComponent', () => { +describe('ObjectListComponent', () => { let comp: ObjectListComponent; let fixture: ComponentFixture; const testEvent = {test: 'test'} From 553d1d6ffd770947ce3130a21896b1bb8ce5bd7f Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Tue, 28 Nov 2017 15:00:28 +0100 Subject: [PATCH 12/77] 130: tests for uuid index reducer --- src/app/core/data/request.reducer.spec.ts | 72 +------------------ src/app/core/index/uuid-index.reducer.spec.ts | 56 +++++++++++++++ 2 files changed, 59 insertions(+), 69 deletions(-) create mode 100644 src/app/core/index/uuid-index.reducer.spec.ts diff --git a/src/app/core/data/request.reducer.spec.ts b/src/app/core/data/request.reducer.spec.ts index 4ae3757e89..d9a58b4107 100644 --- a/src/app/core/data/request.reducer.spec.ts +++ b/src/app/core/data/request.reducer.spec.ts @@ -35,14 +35,14 @@ describe('requestReducer', () => { expect(newState).toEqual(testState); }); - it('should start with an empty cache', () => { + it('should start with an empty state', () => { const action = new NullAction(); const initialState = requestReducer(undefined, action); expect(initialState).toEqual(Object.create(null)); }); - it('should add the new RestRequest and set \'requestPending\' to true, \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to an CONFIGURE action', () => { + it('should add the new RestRequest and set \'requestPending\' to true, \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to a CONFIGURE action', () => { const state = testState; const request = new RestRequest(link2); @@ -66,7 +66,7 @@ describe('requestReducer', () => { expect(newState[link1].responsePending).toEqual(true); expect(newState[link1].completed).toEqual(state[link1].completed); }); - it('should leave \'requestPending\' untouched, set \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to an COMPLETE action', () => { + it('should leave \'requestPending\' untouched, set \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to a COMPLETE action', () => { const state = testState; const action = new RequestCompleteAction(link1); @@ -77,70 +77,4 @@ describe('requestReducer', () => { expect(newState[link1].responsePending).toEqual(false); expect(newState[link1].completed).toEqual(true); }); - - // - // it('should overwrite an object in the cache in response to an ADD action if it already exists', () => { - // const objectToCache = { self: selfLink1, foo: 'baz', somethingElse: true }; - // const timeAdded = new Date().getTime(); - // const msToLive = 900000; - // const requestHref = 'https://rest.api/endpoint/selfLink1'; - // const action = new AddToObjectCacheAction(objectToCache, timeAdded, msToLive, requestHref); - // const newState = requestReducer(testState, action); - // - // /* tslint:disable:no-string-literal */ - // expect(newState[selfLink1].data['foo']).toBe('baz'); - // expect(newState[selfLink1].data['somethingElse']).toBe(true); - // /* tslint:enable:no-string-literal */ - // }); - // - // it('should perform the ADD action without affecting the previous state', () => { - // const state = Object.create(null); - // const objectToCache = { self: selfLink1 }; - // const timeAdded = new Date().getTime(); - // const msToLive = 900000; - // const requestHref = 'https://rest.api/endpoint/selfLink1'; - // const action = new AddToObjectCacheAction(objectToCache, timeAdded, msToLive, requestHref); - // deepFreeze(state); - // - // requestReducer(state, action); - // }); - // - // it('should remove the specified object from the cache in response to the REMOVE action', () => { - // const action = new RemoveFromObjectCacheAction(selfLink1); - // const newState = requestReducer(testState, action); - // - // expect(testState[selfLink1]).not.toBeUndefined(); - // expect(newState[selfLink1]).toBeUndefined(); - // }); - // - // it("shouldn't do anything in response to the REMOVE action for an object that isn't cached", () => { - // const wrongKey = "this isn't cached"; - // const action = new RemoveFromObjectCacheAction(wrongKey); - // const newState = requestReducer(testState, action); - // - // expect(testState[wrongKey]).toBeUndefined(); - // expect(newState).toEqual(testState); - // }); - // - // it('should perform the REMOVE action without affecting the previous state', () => { - // const action = new RemoveFromObjectCacheAction(selfLink1); - // // testState has already been frozen above - // requestReducer(testState, action); - // }); - // - // it('should set the timestamp of all objects in the cache in response to a RESET_TIMESTAMPS action', () => { - // const newTimestamp = new Date().getTime(); - // const action = new ResetObjectCacheTimestampsAction(newTimestamp); - // const newState = requestReducer(testState, action); - // Object.keys(newState).forEach((key) => { - // expect(newState[key].timeAdded).toEqual(newTimestamp); - // }); - // }); - // - // it('should perform the RESET_TIMESTAMPS action without affecting the previous state', () => { - // const action = new ResetObjectCacheTimestampsAction(new Date().getTime()); - // // testState has already been frozen above - // requestReducer(testState, action); - // }); - }); diff --git a/src/app/core/index/uuid-index.reducer.spec.ts b/src/app/core/index/uuid-index.reducer.spec.ts new file mode 100644 index 0000000000..7b96096604 --- /dev/null +++ b/src/app/core/index/uuid-index.reducer.spec.ts @@ -0,0 +1,56 @@ +import * as deepFreeze from 'deep-freeze'; + +import { uuidIndexReducer, UUIDIndexState } from './uuid-index.reducer'; +import { AddToUUIDIndexAction, RemoveHrefFromUUIDIndexAction } from './uuid-index.actions'; + +class NullAction extends AddToUUIDIndexAction { + type = null; + payload = null; + + constructor() { + super(null, null); + } +} + +describe('requestReducer', () => { + const link1 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/567a639f-f5ff-4126-807c-b7d0910808c8'; + const link2 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/1911e8a4-6939-490c-b58b-a5d70f8d91fb'; + const uuid1 = '567a639f-f5ff-4126-807c-b7d0910808c8'; + const uuid2 = '1911e8a4-6939-490c-b58b-a5d70f8d91fb'; + const testState: UUIDIndexState = { + [uuid1]: link1 + }; + deepFreeze(testState); + + it('should return the current state when no valid actions have been made', () => { + const action = new NullAction(); + const newState = uuidIndexReducer(testState, action); + + expect(newState).toEqual(testState); + }); + + it('should start with an empty state', () => { + const action = new NullAction(); + const initialState = uuidIndexReducer(undefined, action); + + expect(initialState).toEqual(Object.create(null)); + }); + + it('should add the \'uuid\' with the corresponding \'href\' to the state, in response to an ADD action', () => { + const state = testState; + + const action = new AddToUUIDIndexAction(uuid2, link2); + const newState = uuidIndexReducer(state, action); + + expect(newState[uuid2]).toEqual(link2); + }); + + it('should remove the given \'href\' from it\'s corresponding \'uuid\' in the state, in response to a REMOVE_HREF action', () => { + const state = testState; + + const action = new RemoveHrefFromUUIDIndexAction(link1); + const newState = uuidIndexReducer(state, action); + + expect(newState[uuid1]).toBeUndefined(); + }); +}); From 909845ebc0731c75ae287ce101d0e696e27fa98f Mon Sep 17 00:00:00 2001 From: courtneypattison Date: Tue, 28 Nov 2017 15:33:35 -0800 Subject: [PATCH 13/77] Run Travis using headless Chrome addon --- .travis.yml | 15 ++------------- karma.conf.js | 9 --------- package.json | 3 ++- protractor.conf.js | 5 ++++- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index bc539060e7..0a9ae4754f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,7 @@ sudo: required dist: trusty addons: - apt: - sources: - - google-chrome - packages: - - google-chrome-stable + - chrome: stable language: node_js @@ -24,14 +20,7 @@ before_install: install: - travis_retry yarn install -before_script: - - travis_wait yarn run lint - - travis_wait yarn run build - - export CHROME_BIN=chromium-browser - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start - - sleep 3 - script: + - yarn run build - yarn run ci - cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js diff --git a/karma.conf.js b/karma.conf.js index e43191d8ee..073ce7040b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -146,11 +146,6 @@ module.exports = function (config) { ], customLaunchers: { - // Continuous integraation with Chrome - launcher - 'ChromeTravisCi': { - base: 'Chrome', - flags: ['--no-sandbox'] - }, // Remote Selenium Server with Chrome - launcher 'SeleniumChrome': { base: 'WebDriver', @@ -173,9 +168,5 @@ module.exports = function (config) { }; - if (process.env.TRAVIS) { - configuration.browsers = ['ChromeTravisCi']; - } - config.set(configuration); }; diff --git a/package.json b/package.json index 2f74dd6cb8..e32a9af765 100644 --- a/package.json +++ b/package.json @@ -55,11 +55,12 @@ "debug:server": "node-nightly --inspect --debug-brk dist/server.js", "debug:build": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js", "debug:build:prod": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js --env.aot --env.client --env.server -p", - "ci": "yarn run lint && yarn run build:aot && yarn run test && npm-run-all -p -r server e2e", + "ci": "yarn run lint && yarn run build:aot && yarn run test:headless && npm-run-all -p -r server e2e", "protractor": "node node_modules/protractor/bin/protractor", "pree2e": "yarn run webdriver:update", "e2e": "yarn run protractor", "test": "karma start --single-run", + "test:headless": "karma start --single-run --browsers ChromeHeadless", "test:watch": "karma start --no-single-run --auto-watch", "webdriver:start": "node node_modules/protractor/bin/webdriver-manager start --seleniumPort 4444", "webdriver:update": "node node_modules/protractor/bin/webdriver-manager update --standalone", diff --git a/protractor.conf.js b/protractor.conf.js index 618a5efc08..2949702a0a 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -31,7 +31,10 @@ exports.config = { capabilities: { 'browserName': 'chrome', 'version': '', - 'platform': 'ANY' + 'platform': 'ANY', + 'chromeOptions': { + 'args': [ '--headless', '--disable-gpu' ] + } }, // ----------------------------------------------------------------- // Browser and Capabilities: Firefox From 4b94f8bb4d5994904912f30377545491981c92e0 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Wed, 29 Nov 2017 15:36:54 +0100 Subject: [PATCH 14/77] 130: more core tests --- .../core/cache/object-cache.effects.spec.ts | 38 +++ .../{data => cache}/object-cache.effects.ts | 2 +- .../core/cache/response-cache.effects.spec.ts | 38 +++ .../response-cache.effects.ts} | 4 +- .../core/cache/response-cache.reducer.spec.ts | 317 ++++++------------ .../core/cache/response-cache.service.spec.ts | 222 +++++------- src/app/core/cache/response-cache.service.ts | 3 +- src/app/core/core.effects.ts | 6 +- 8 files changed, 269 insertions(+), 361 deletions(-) create mode 100644 src/app/core/cache/object-cache.effects.spec.ts rename src/app/core/{data => cache}/object-cache.effects.ts (89%) create mode 100644 src/app/core/cache/response-cache.effects.spec.ts rename src/app/core/{data/request-cache.effects.ts => cache/response-cache.effects.ts} (85%) diff --git a/src/app/core/cache/object-cache.effects.spec.ts b/src/app/core/cache/object-cache.effects.spec.ts new file mode 100644 index 0000000000..48241c2c4f --- /dev/null +++ b/src/app/core/cache/object-cache.effects.spec.ts @@ -0,0 +1,38 @@ +import { TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { provideMockActions } from '@ngrx/effects/testing'; +import { cold, hot } from 'jasmine-marbles'; +import { ObjectCacheEffects } from './object-cache.effects'; +import { ResetObjectCacheTimestampsAction } from './object-cache.actions'; +import { StoreActionTypes } from '../../store.actions'; + +describe('ObjectCacheEffects', () => { + let cacheEffects: ObjectCacheEffects; + let actions: Observable; + const timestamp = 10000; + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + ObjectCacheEffects, + provideMockActions(() => actions), + // other providers + ], + }); + + cacheEffects = TestBed.get(ObjectCacheEffects); + }); + + describe('fixTimestampsOnRehydrate$', () => { + + it('should return a RESET_TIMESTAMPS action in response to an REHYDRATE action to a new route', () => { + spyOn(Date.prototype, 'getTime').and.callFake(() => { + return timestamp; + }); + actions = hot('--a-', { a: { type: StoreActionTypes.REHYDRATE, payload: {} } }); + + const expected = cold('--b-', { b: new ResetObjectCacheTimestampsAction(new Date().getTime()) }); + + expect(cacheEffects.fixTimestampsOnRehydrate).toBeObservable(expected); + }); + }); +}); diff --git a/src/app/core/data/object-cache.effects.ts b/src/app/core/cache/object-cache.effects.ts similarity index 89% rename from src/app/core/data/object-cache.effects.ts rename to src/app/core/cache/object-cache.effects.ts index a0018d2b58..019c792973 100644 --- a/src/app/core/data/object-cache.effects.ts +++ b/src/app/core/cache/object-cache.effects.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { Actions, Effect } from '@ngrx/effects'; import { StoreActionTypes } from '../../store.actions'; -import { ResetObjectCacheTimestampsAction } from '../cache/object-cache.actions'; +import { ResetObjectCacheTimestampsAction } from './object-cache.actions'; @Injectable() export class ObjectCacheEffects { diff --git a/src/app/core/cache/response-cache.effects.spec.ts b/src/app/core/cache/response-cache.effects.spec.ts new file mode 100644 index 0000000000..422b8bf181 --- /dev/null +++ b/src/app/core/cache/response-cache.effects.spec.ts @@ -0,0 +1,38 @@ +import { TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { provideMockActions } from '@ngrx/effects/testing'; +import { cold, hot } from 'jasmine-marbles'; +import { StoreActionTypes } from '../../store.actions'; +import { ResponseCacheEffects } from './response-cache.effects'; +import { ResetResponseCacheTimestampsAction } from './response-cache.actions'; + +describe('ResponseCacheEffects', () => { + let cacheEffects: ResponseCacheEffects; + let actions: Observable; + const timestamp = 10000; + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + ResponseCacheEffects, + provideMockActions(() => actions), + // other providers + ], + }); + + cacheEffects = TestBed.get(ResponseCacheEffects); + }); + + describe('fixTimestampsOnRehydrate$', () => { + + it('should return a RESET_TIMESTAMPS action in response to an REHYDRATE action to a new route', () => { + spyOn(Date.prototype, 'getTime').and.callFake(() => { + return timestamp; + }); + actions = hot('--a-', { a: { type: StoreActionTypes.REHYDRATE, payload: {} } }); + + const expected = cold('--b-', { b: new ResetResponseCacheTimestampsAction(new Date().getTime()) }); + + expect(cacheEffects.fixTimestampsOnRehydrate).toBeObservable(expected); + }); + }); +}); diff --git a/src/app/core/data/request-cache.effects.ts b/src/app/core/cache/response-cache.effects.ts similarity index 85% rename from src/app/core/data/request-cache.effects.ts rename to src/app/core/cache/response-cache.effects.ts index a9c1c24957..d340750797 100644 --- a/src/app/core/data/request-cache.effects.ts +++ b/src/app/core/cache/response-cache.effects.ts @@ -1,11 +1,11 @@ import { Injectable } from '@angular/core'; import { Actions, Effect } from '@ngrx/effects'; -import { ResetResponseCacheTimestampsAction } from '../cache/response-cache.actions'; +import { ResetResponseCacheTimestampsAction } from './response-cache.actions'; import { StoreActionTypes } from '../../store.actions'; @Injectable() -export class RequestCacheEffects { +export class ResponseCacheEffects { /** * When the store is rehydrated in the browser, set all cache diff --git a/src/app/core/cache/response-cache.reducer.spec.ts b/src/app/core/cache/response-cache.reducer.spec.ts index 613b62f30f..9037b20030 100644 --- a/src/app/core/cache/response-cache.reducer.spec.ts +++ b/src/app/core/cache/response-cache.reducer.spec.ts @@ -4,8 +4,9 @@ import { responseCacheReducer, ResponseCacheState } from './response-cache.reduc import { ResponseCacheRemoveAction, - ResetResponseCacheTimestampsAction + ResetResponseCacheTimestampsAction, ResponseCacheAddAction } from './response-cache.actions'; +import { RestResponse } from './response-cache.models'; class NullAction extends ResponseCacheRemoveAction { type = null; @@ -16,212 +17,108 @@ class NullAction extends ResponseCacheRemoveAction { } } -// describe('responseCacheReducer', () => { -// const keys = ['125c17f89046283c5f0640722aac9feb', 'a06c3006a41caec5d635af099b0c780c']; -// const services = [new OpaqueToken('service1'), new OpaqueToken('service2')]; -// const msToLive = 900000; -// const uuids = [ -// '9e32a2e2-6b91-4236-a361-995ccdc14c60', -// '598ce822-c357-46f3-ab70-63724d02d6ad', -// 'be8325f7-243b-49f4-8a4b-df2b793ff3b5' -// ]; -// const resourceID = '9978'; -// const paginationOptions = { 'resultsPerPage': 10, 'currentPage': 1 }; -// const sortOptions = { 'field': 'id', 'direction': 0 }; -// const testState = { -// [keys[0]]: { -// 'key': keys[0], -// 'service': services[0], -// 'resourceUUIDs': [uuids[0], uuids[1]], -// 'isLoading': false, -// 'paginationOptions': paginationOptions, -// 'sortOptions': sortOptions, -// 'timeAdded': new Date().getTime(), -// 'msToLive': msToLive -// }, -// [keys[1]]: { -// 'key': keys[1], -// 'service': services[1], -// 'resourceID': resourceID, -// 'resourceUUIDs': [uuids[2]], -// 'isLoading': false, -// 'timeAdded': new Date().getTime(), -// 'msToLive': msToLive -// } -// }; -// deepFreeze(testState); -// const errorState: {} = { -// [keys[0]]: { -// errorMessage: 'error', -// resourceUUIDs: uuids -// } -// }; -// deepFreeze(errorState); -// -// -// it('should return the current state when no valid actions have been made', () => { -// const action = new NullAction(); -// const newState = responseCacheReducer(testState, action); -// -// expect(newState).toEqual(testState); -// }); -// -// it('should start with an empty cache', () => { -// const action = new NullAction(); -// const initialState = responseCacheReducer(undefined, action); -// -// expect(initialState).toEqual(Object.create(null)); -// }); -// -// describe('FIND_BY_ID', () => { -// const action = new ResponseCacheFindByIDAction(keys[0], services[0], resourceID); -// -// it('should perform the action without affecting the previous state', () => { -// //testState has already been frozen above -// responseCacheReducer(testState, action); -// }); -// -// it('should add the request to the cache', () => { -// const state = Object.create(null); -// const newState = responseCacheReducer(state, action); -// expect(newState[keys[0]].key).toBe(keys[0]); -// expect(newState[keys[0]].service).toEqual(services[0]); -// expect(newState[keys[0]].resourceID).toBe(resourceID); -// }); -// -// it('should set responsePending to true', () => { -// const state = Object.create(null); -// const newState = responseCacheReducer(state, action); -// expect(newState[keys[0]].responsePending).toBe(true); -// }); -// -// it('should remove any previous error message or resourceUUID for the request', () => { -// const newState = responseCacheReducer(errorState, action); -// expect(newState[keys[0]].resourceUUIDs.length).toBe(0); -// expect(newState[keys[0]].errorMessage).toBeUndefined(); -// }); -// }); -// -// describe('FIND_ALL', () => { -// const action = new ResponseCacheFindAllAction(keys[0], services[0], resourceID, paginationOptions, sortOptions); -// -// it('should perform the action without affecting the previous state', () => { -// //testState has already been frozen above -// responseCacheReducer(testState, action); -// }); -// -// it('should add the request to the cache', () => { -// const state = Object.create(null); -// const newState = responseCacheReducer(state, action); -// expect(newState[keys[0]].key).toBe(keys[0]); -// expect(newState[keys[0]].service).toEqual(services[0]); -// expect(newState[keys[0]].scopeID).toBe(resourceID); -// expect(newState[keys[0]].paginationOptions).toEqual(paginationOptions); -// expect(newState[keys[0]].sortOptions).toEqual(sortOptions); -// }); -// -// it('should set responsePending to true', () => { -// const state = Object.create(null); -// const newState = responseCacheReducer(state, action); -// expect(newState[keys[0]].responsePending).toBe(true); -// }); -// -// it('should remove any previous error message or resourceUUIDs for the request', () => { -// const newState = responseCacheReducer(errorState, action); -// expect(newState[keys[0]].resourceUUIDs.length).toBe(0); -// expect(newState[keys[0]].errorMessage).toBeUndefined(); -// }); -// }); -// -// describe('SUCCESS', () => { -// const successUUIDs = [uuids[0], uuids[2]]; -// const successTimeAdded = new Date().getTime(); -// const successMsToLive = 5; -// const action = new ResponseCacheSuccessAction(keys[0], successUUIDs, successTimeAdded, successMsToLive); -// -// it('should perform the action without affecting the previous state', () => { -// //testState has already been frozen above -// responseCacheReducer(testState, action); -// }); -// -// it('should add the response to the cached request', () => { -// const newState = responseCacheReducer(testState, action); -// expect(newState[keys[0]].resourceUUIDs).toBe(successUUIDs); -// expect(newState[keys[0]].timeAdded).toBe(successTimeAdded); -// expect(newState[keys[0]].msToLive).toBe(successMsToLive); -// }); -// -// it('should set responsePending to false', () => { -// const newState = responseCacheReducer(testState, action); -// expect(newState[keys[0]].responsePending).toBe(false); -// }); -// -// it('should remove any previous error message for the request', () => { -// const newState = responseCacheReducer(errorState, action); -// expect(newState[keys[0]].errorMessage).toBeUndefined(); -// }); -// }); -// -// describe('ERROR', () => { -// const errorMsg = 'errorMsg'; -// const action = new ResponseCacheErrorAction(keys[0], errorMsg); -// -// it('should perform the action without affecting the previous state', () => { -// //testState has already been frozen above -// responseCacheReducer(testState, action); -// }); -// -// it('should set an error message for the request', () => { -// const newState = responseCacheReducer(errorState, action); -// expect(newState[keys[0]].errorMessage).toBe(errorMsg); -// }); -// -// it('should set responsePending to false', () => { -// const newState = responseCacheReducer(testState, action); -// expect(newState[keys[0]].responsePending).toBe(false); -// }); -// }); -// -// describe('REMOVE', () => { -// it('should perform the action without affecting the previous state', () => { -// const action = new ResponseCacheRemoveAction(keys[0]); -// //testState has already been frozen above -// responseCacheReducer(testState, action); -// }); -// -// it('should remove the specified request from the cache', () => { -// const action = new ResponseCacheRemoveAction(keys[0]); -// const newState = responseCacheReducer(testState, action); -// expect(testState[keys[0]]).not.toBeUndefined(); -// expect(newState[keys[0]]).toBeUndefined(); -// }); -// -// it('shouldn't do anything when the specified key isn't cached', () => { -// const wrongKey = 'this isn't cached'; -// const action = new ResponseCacheRemoveAction(wrongKey); -// const newState = responseCacheReducer(testState, action); -// expect(testState[wrongKey]).toBeUndefined(); -// expect(newState).toEqual(testState); -// }); -// }); -// -// describe('RESET_TIMESTAMPS', () => { -// const newTimeStamp = new Date().getTime(); -// const action = new ResetResponseCacheTimestampsAction(newTimeStamp); -// -// it('should perform the action without affecting the previous state', () => { -// //testState has already been frozen above -// responseCacheReducer(testState, action); -// }); -// -// it('should set the timestamp of all requests in the cache', () => { -// const newState = responseCacheReducer(testState, action); -// Object.keys(newState).forEach((key) => { -// expect(newState[key].timeAdded).toEqual(newTimeStamp); -// }); -// }); -// -// }); -// -// -// }); +describe('responseCacheReducer', () => { + const keys = ['125c17f89046283c5f0640722aac9feb', 'a06c3006a41caec5d635af099b0c780c']; + const msToLive = 900000; + const uuids = [ + '9e32a2e2-6b91-4236-a361-995ccdc14c60', + '598ce822-c357-46f3-ab70-63724d02d6ad', + 'be8325f7-243b-49f4-8a4b-df2b793ff3b5' + ]; + const testState: ResponseCacheState = { + [keys[0]]: { + key: keys[0], + response: new RestResponse(true, '200'), + timeAdded: new Date().getTime(), + msToLive: msToLive + }, + [keys[1]]: { + key: keys[1], + response: new RestResponse(true, '200'), + timeAdded: new Date().getTime(), + msToLive: msToLive + } + }; + deepFreeze(testState); + const errorState: {} = { + [keys[0]]: { + errorMessage: 'error', + resourceUUIDs: uuids + } + }; + deepFreeze(errorState); + + it('should return the current state when no valid actions have been made', () => { + const action = new NullAction(); + const newState = responseCacheReducer(testState, action); + + expect(newState).toEqual(testState); + }); + + it('should start with an empty cache', () => { + const action = new NullAction(); + const initialState = responseCacheReducer(undefined, action); + + expect(initialState).toEqual(Object.create(null)); + }); + + describe('ADD', () => { + const addTimeAdded = new Date().getTime(); + const addMsToLive = 5; + const addResponse = new RestResponse(true, '200'); + const action = new ResponseCacheAddAction(keys[0], addResponse, addTimeAdded, addMsToLive); + + it('should perform the action without affecting the previous state', () => { + // testState has already been frozen above + responseCacheReducer(testState, action); + }); + + it('should add the response to the cached request', () => { + const newState = responseCacheReducer(testState, action); + expect(newState[keys[0]].timeAdded).toBe(addTimeAdded); + expect(newState[keys[0]].msToLive).toBe(addMsToLive); + expect(newState[keys[0]].response).toBe(addResponse); + }); + }); + + describe('REMOVE', () => { + it('should perform the action without affecting the previous state', () => { + const action = new ResponseCacheRemoveAction(keys[0]); + // testState has already been frozen above + responseCacheReducer(testState, action); + }); + + it('should remove the specified request from the cache', () => { + const action = new ResponseCacheRemoveAction(keys[0]); + const newState = responseCacheReducer(testState, action); + expect(testState[keys[0]]).not.toBeUndefined(); + expect(newState[keys[0]]).toBeUndefined(); + }); + + it('shouldn\'t do anything when the specified key isn\'t cached', () => { + const wrongKey = 'this isn\'t cached'; + const action = new ResponseCacheRemoveAction(wrongKey); + const newState = responseCacheReducer(testState, action); + expect(testState[wrongKey]).toBeUndefined(); + expect(newState).toEqual(testState); + }); + }); + + describe('RESET_TIMESTAMPS', () => { + const newTimeStamp = new Date().getTime(); + const action = new ResetResponseCacheTimestampsAction(newTimeStamp); + + it('should perform the action without affecting the previous state', () => { + // testState has already been frozen above + responseCacheReducer(testState, action); + }); + + it('should set the timestamp of all requests in the cache', () => { + const newState = responseCacheReducer(testState, action); + Object.keys(newState).forEach((key) => { + expect(newState[key].timeAdded).toEqual(newTimeStamp); + }); + }); + + }); +}); diff --git a/src/app/core/cache/response-cache.service.spec.ts b/src/app/core/cache/response-cache.service.spec.ts index 71b1da789c..1def7faa02 100644 --- a/src/app/core/cache/response-cache.service.spec.ts +++ b/src/app/core/cache/response-cache.service.spec.ts @@ -1,147 +1,83 @@ -import { OpaqueToken } from '@angular/core'; -import { Observable } from 'rxjs/Observable'; import { Store } from '@ngrx/store'; import { ResponseCacheService } from './response-cache.service'; -import { ResponseCacheState, ResponseCacheEntry } from './response-cache.reducer'; +import { Observable } from 'rxjs/Observable'; +import { CoreState } from '../core.reducers'; +import { RestResponse } from './response-cache.models'; +import { ResponseCacheEntry } from './response-cache.reducer'; -// describe('ResponseCacheService', () => { -// let service: ResponseCacheService; -// let store: Store; -// -// const keys = ['125c17f89046283c5f0640722aac9feb', 'a06c3006a41caec5d635af099b0c780c']; -// const serviceTokens = [new OpaqueToken('service1'), new OpaqueToken('service2')]; -// const resourceID = '9978'; -// const paginationOptions = { 'resultsPerPage': 10, 'currentPage': 1 }; -// const sortOptions = { 'field': 'id', 'direction': 0 }; -// const timestamp = new Date().getTime(); -// const validCacheEntry = (key) => { -// return { -// key: key, -// timeAdded: timestamp, -// msToLive: 24 * 60 * 60 * 1000 // a day -// } -// }; -// const invalidCacheEntry = (key) => { -// return { -// key: key, -// timeAdded: 0, -// msToLive: 0 -// } -// }; -// -// beforeEach(() => { -// store = new Store(undefined, undefined, undefined); -// spyOn(store, 'dispatch'); -// service = new ResponseCacheService(store); -// spyOn(window, 'Date').and.returnValue({ getTime: () => timestamp }); -// }); -// -// describe('findAll', () => { -// beforeEach(() => { -// spyOn(service, 'get').and.callFake((key) => Observable.of({key: key})); -// }); -// describe('if the key isn't cached', () => { -// beforeEach(() => { -// spyOn(service, 'has').and.returnValue(false); -// }); -// it('should dispatch a FIND_ALL action with the key, service, scopeID, paginationOptions and sortOptions', () => { -// service.findAll(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions); -// expect(store.dispatch).toHaveBeenCalledWith(new ResponseCacheFindAllAction(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions)) -// }); -// it('should return an observable of the newly cached request with the specified key', () => { -// let result: ResponseCacheEntry; -// service.findAll(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions).take(1).subscribe(entry => result = entry); -// expect(result.key).toEqual(keys[0]); -// }); -// }); -// describe('if the key is already cached', () => { -// beforeEach(() => { -// spyOn(service, 'has').and.returnValue(true); -// }); -// it('shouldn't dispatch anything', () => { -// service.findAll(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions); -// expect(store.dispatch).not.toHaveBeenCalled(); -// }); -// it('should return an observable of the existing cached request with the specified key', () => { -// let result: ResponseCacheEntry; -// service.findAll(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions).take(1).subscribe(entry => result = entry); -// expect(result.key).toEqual(keys[0]); -// }); -// }); -// }); -// -// describe('findById', () => { -// beforeEach(() => { -// spyOn(service, 'get').and.callFake((key) => Observable.of({key: key})); -// }); -// describe('if the key isn't cached', () => { -// beforeEach(() => { -// spyOn(service, 'has').and.returnValue(false); -// }); -// it('should dispatch a FIND_BY_ID action with the key, service, and resourceID', () => { -// service.findById(keys[0], serviceTokens[0], resourceID); -// expect(store.dispatch).toHaveBeenCalledWith(new ResponseCacheFindByIDAction(keys[0], serviceTokens[0], resourceID)) -// }); -// it('should return an observable of the newly cached request with the specified key', () => { -// let result: ResponseCacheEntry; -// service.findById(keys[0], serviceTokens[0], resourceID).take(1).subscribe(entry => result = entry); -// expect(result.key).toEqual(keys[0]); -// }); -// }); -// describe('if the key is already cached', () => { -// beforeEach(() => { -// spyOn(service, 'has').and.returnValue(true); -// }); -// it('shouldn't dispatch anything', () => { -// service.findById(keys[0], serviceTokens[0], resourceID); -// expect(store.dispatch).not.toHaveBeenCalled(); -// }); -// it('should return an observable of the existing cached request with the specified key', () => { -// let result: ResponseCacheEntry; -// service.findById(keys[0], serviceTokens[0], resourceID).take(1).subscribe(entry => result = entry); -// expect(result.key).toEqual(keys[0]); -// }); -// }); -// }); -// -// describe('get', () => { -// it('should return an observable of the cached request with the specified key', () => { -// spyOn(store, 'select').and.callFake((...args:Array) => { -// return Observable.of(validCacheEntry(args[args.length - 1])); -// }); -// -// let testObj: ResponseCacheEntry; -// service.get(keys[1]).take(1).subscribe(entry => testObj = entry); -// expect(testObj.key).toEqual(keys[1]); -// }); -// -// it('should not return a cached request that has exceeded its time to live', () => { -// spyOn(store, 'select').and.callFake((...args:Array) => { -// return Observable.of(invalidCacheEntry(args[args.length - 1])); -// }); -// -// let getObsHasFired = false; -// const subscription = service.get(keys[1]).subscribe(entry => getObsHasFired = true); -// expect(getObsHasFired).toBe(false); -// subscription.unsubscribe(); -// }); -// }); -// -// describe('has', () => { -// it('should return true if the request with the supplied key is cached and still valid', () => { -// spyOn(store, 'select').and.returnValue(Observable.of(validCacheEntry(keys[1]))); -// expect(service.has(keys[1])).toBe(true); -// }); -// -// it('should return false if the request with the supplied key isn't cached', () => { -// spyOn(store, 'select').and.returnValue(Observable.of(undefined)); -// expect(service.has(keys[1])).toBe(false); -// }); -// -// it('should return false if the request with the supplied key is cached but has exceeded its time to live', () => { -// spyOn(store, 'select').and.returnValue(Observable.of(invalidCacheEntry(keys[1]))); -// expect(service.has(keys[1])).toBe(false); -// }); -// }); -// }); +describe('ResponseCacheService', () => { + let service: ResponseCacheService; + let store: Store; + + const keys = ['125c17f89046283c5f0640722aac9feb', 'a06c3006a41caec5d635af099b0c780c']; + const timestamp = new Date().getTime(); + const validCacheEntry = (key) => { + return { + key: key, + response: new RestResponse(true, '200'), + timeAdded: timestamp, + msToLive: 24 * 60 * 60 * 1000 // a day + } + }; + const invalidCacheEntry = (key) => { + return { + key: key, + response: new RestResponse(true, '200'), + timeAdded: 0, + msToLive: 0 + } + }; + + beforeEach(() => { + store = new Store(undefined, undefined, undefined); + spyOn(store, 'dispatch'); + service = new ResponseCacheService(store); + spyOn(Date.prototype, 'getTime').and.callFake(() => { + return timestamp; + }); + }); + + describe('get', () => { + it('should return an observable of the cached request with the specified key', () => { + spyOn(store, 'select').and.callFake((...args: any[]) => { + return Observable.of(validCacheEntry(keys[1])); + }); + + let testObj: ResponseCacheEntry; + service.get(keys[1]).first().subscribe((entry) => { + console.log(entry); + testObj = entry; + }); + expect(testObj.key).toEqual(keys[1]); + }); + + it('should not return a cached request that has exceeded its time to live', () => { + spyOn(store, 'select').and.callFake((...args: any[]) => { + return Observable.of(invalidCacheEntry(keys[1])); + }); + + let getObsHasFired = false; + const subscription = service.get(keys[1]).subscribe((entry) => getObsHasFired = true); + expect(getObsHasFired).toBe(false); + subscription.unsubscribe(); + }); + }); + + describe('has', () => { + it('should return true if the request with the supplied key is cached and still valid', () => { + spyOn(store, 'select').and.returnValue(Observable.of(validCacheEntry(keys[1]))); + expect(service.has(keys[1])).toBe(true); + }); + + it('should return false if the request with the supplied key isn\'t cached', () => { + spyOn(store, 'select').and.returnValue(Observable.of(undefined)); + expect(service.has(keys[1])).toBe(false); + }); + + it('should return false if the request with the supplied key is cached but has exceeded its time to live', () => { + spyOn(store, 'select').and.returnValue(Observable.of(invalidCacheEntry(keys[1]))); + expect(service.has(keys[1])).toBe(false); + }); + }); +}); diff --git a/src/app/core/cache/response-cache.service.ts b/src/app/core/cache/response-cache.service.ts index d734940496..65ce8b2bac 100644 --- a/src/app/core/cache/response-cache.service.ts +++ b/src/app/core/cache/response-cache.service.ts @@ -4,7 +4,7 @@ import { MemoizedSelector, Store } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; import { ResponseCacheEntry } from './response-cache.reducer'; -import { hasNoValue, hasValue } from '../../shared/empty.util'; +import { hasNoValue } from '../../shared/empty.util'; import { ResponseCacheRemoveAction, ResponseCacheAddAction } from './response-cache.actions'; import { RestResponse } from './response-cache.models'; import { CoreState } from '../core.reducers'; @@ -25,7 +25,6 @@ export class ResponseCacheService { add(key: string, response: RestResponse, msToLive: number): Observable { if (!this.has(key)) { - // this.store.dispatch(new ResponseCacheFindAllAction(key, service, scopeID, paginationOptions, sortOptions)); this.store.dispatch(new ResponseCacheAddAction(key, response, new Date().getTime(), msToLive)); } return this.get(key); diff --git a/src/app/core/core.effects.ts b/src/app/core/core.effects.ts index 593b17e0f5..f144f773a1 100644 --- a/src/app/core/core.effects.ts +++ b/src/app/core/core.effects.ts @@ -1,11 +1,11 @@ -import { ObjectCacheEffects } from './data/object-cache.effects'; -import { RequestCacheEffects } from './data/request-cache.effects'; +import { ObjectCacheEffects } from './cache/object-cache.effects'; +import { ResponseCacheEffects } from './cache/response-cache.effects'; import { UUIDIndexEffects } from './index/uuid-index.effects'; import { RequestEffects } from './data/request.effects'; export const coreEffects = [ - RequestCacheEffects, + ResponseCacheEffects, RequestEffects, ObjectCacheEffects, UUIDIndexEffects, From 7083503ccd482c7c2ee7befe1245f683be542f20 Mon Sep 17 00:00:00 2001 From: courtneypattison Date: Wed, 29 Nov 2017 14:08:11 -0800 Subject: [PATCH 15/77] Let linting exit with a nonzero status --- package.json | 2 +- .../search-facet-filter.component.spec.ts | 8 ++++---- .../search-filter/search-filter.component.spec.ts | 2 -- src/app/+search-page/search-page.component.spec.ts | 8 ++++---- .../search-sidebar/search-sidebar.component.ts | 2 -- src/app/header/header.component.spec.ts | 1 - src/app/shared/route.service.ts | 2 +- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index e32a9af765..f2bb074ff4 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "test:watch": "karma start --no-single-run --auto-watch", "webdriver:start": "node node_modules/protractor/bin/webdriver-manager start --seleniumPort 4444", "webdriver:update": "node node_modules/protractor/bin/webdriver-manager update --standalone", - "lint": "tslint \"src/**/*.ts\" || true && tslint \"e2e/**/*.ts\" || true", + "lint": "tslint \"src/**/*.ts\" && tslint \"e2e/**/*.ts\"", "docs": "typedoc --options typedoc.json ./src/", "coverage": "http-server -c-1 -o -p 9875 ./coverage" }, diff --git a/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts b/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts index 08ee0fd840..bf069eee60 100644 --- a/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts +++ b/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts @@ -41,7 +41,7 @@ describe('SearchFacetFilterComponent', () => { } ]; let filterService; - let page = Observable.of(0) + const page = Observable.of(0) beforeEach(async(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, FormsModule], @@ -147,8 +147,8 @@ describe('SearchFacetFilterComponent', () => { it('should return the correct number of items shown (this equals the page count x page size)', () => { const sub = count.subscribe((c) => { - const subsub = comp.currentPage.subscribe((page) => { - expect(c).toBe(page * mockFilterConfig.pageSize); + const subsub = comp.currentPage.subscribe((currentPage) => { + expect(c).toBe(currentPage * mockFilterConfig.pageSize); }); subsub.unsubscribe() }); @@ -188,4 +188,4 @@ describe('SearchFacetFilterComponent', () => { expect(filterService.getPage).toHaveBeenCalledWith(mockFilterConfig.name) }); }); -}); \ No newline at end of file +}); diff --git a/src/app/+search-page/search-filters/search-filter/search-filter.component.spec.ts b/src/app/+search-page/search-filters/search-filter/search-filter.component.spec.ts index 62cfb23970..78d40b1cf6 100644 --- a/src/app/+search-page/search-filters/search-filter/search-filter.component.spec.ts +++ b/src/app/+search-page/search-filters/search-filter/search-filter.component.spec.ts @@ -166,6 +166,4 @@ describe('SearchFilterComponent', () => { sub.unsubscribe(); }); }); - - }); diff --git a/src/app/+search-page/search-page.component.spec.ts b/src/app/+search-page/search-page.component.spec.ts index 31878ceb21..d72610695d 100644 --- a/src/app/+search-page/search-page.component.spec.ts +++ b/src/app/+search-page/search-page.component.spec.ts @@ -109,10 +109,10 @@ describe('SearchPageComponent', () => { }); describe('when update search results is called', () => { - let pagination; - let sort; + let paginationUpdate; + let sortUpdate; beforeEach(() => { - pagination = Object.assign( + paginationUpdate = Object.assign( {}, new PaginationComponentOptions(), { @@ -120,7 +120,7 @@ describe('SearchPageComponent', () => { pageSize: 15 } ); - sort = Object.assign({}, + sortUpdate = Object.assign({}, new SortOptions(), { direction: SortDirection.Ascending, diff --git a/src/app/+search-page/search-sidebar/search-sidebar.component.ts b/src/app/+search-page/search-sidebar/search-sidebar.component.ts index beec358a6c..946048462a 100644 --- a/src/app/+search-page/search-sidebar/search-sidebar.component.ts +++ b/src/app/+search-page/search-sidebar/search-sidebar.component.ts @@ -15,6 +15,4 @@ import { Component, EventEmitter, Input, Output } from '@angular/core'; export class SearchSidebarComponent { @Input() resultCount; @Output() toggleSidebar = new EventEmitter(); - constructor() { - } } diff --git a/src/app/header/header.component.spec.ts b/src/app/header/header.component.spec.ts index 61ec8e2a0d..7c1a9601ac 100644 --- a/src/app/header/header.component.spec.ts +++ b/src/app/header/header.component.spec.ts @@ -10,7 +10,6 @@ import { HeaderComponent } from './header.component'; import { HeaderState } from './header.reducer'; import { HeaderToggleAction } from './header.actions'; - let comp: HeaderComponent; let fixture: ComponentFixture; let store: Store; diff --git a/src/app/shared/route.service.ts b/src/app/shared/route.service.ts index b11da41211..f24fa0d00d 100644 --- a/src/app/shared/route.service.ts +++ b/src/app/shared/route.service.ts @@ -18,7 +18,7 @@ export class RouteService { } hasQueryParam(paramName: string): Observable { - return this.route.queryParamMap.map((map) => {return map.has(paramName);}); + return this.route.queryParamMap.map((map) => map.has(paramName)); } hasQueryParamWithValue(paramName: string, paramValue: string): Observable { From d2135ab019458dfe906f80515c51b5d3d2f80043 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 26 Oct 2017 09:38:27 +0200 Subject: [PATCH 16/77] #150 Initial grid/list view implementation --- package.json | 1 + .../collection-page.component.html | 4 +- ...ty-page-sub-collection-list.component.html | 8 +- .../top-level-community-list.component.html | 26 ++-- src/app/+search-page/search-page.component.ts | 15 +++ src/app/+search-page/search-page.module.ts | 15 ++- src/app/+search-page/search-result.model.ts | 2 +- .../search-results.component.html | 4 +- .../search-service/search.service.ts | 2 +- src/app/core/shared/dspace-object.model.ts | 2 +- .../object-collection.component.html | 13 ++ .../object-collection.component.scss | 1 + .../object-collection.component.ts | 113 ++++++++++++++++++ .../shared/item-search-result.model.ts | 5 + .../shared}/listable-object.model.ts | 0 .../collection-grid-element.component.html | 12 ++ .../collection-grid-element.component.scss | 2 + .../collection-grid-element.component.ts | 14 +++ .../community-grid-element.component.html | 12 ++ .../community-grid-element.component.scss | 2 + .../community-grid-element.component.ts | 14 +++ src/app/object-grid/grid-card-styling.scss | 36 ++++++ src/app/object-grid/grid-element-decorator.ts | 16 +++ .../item-grid-element.component.html | 20 ++++ .../item-grid-element.component.scss | 2 + .../item-grid-element.component.ts | 14 +++ .../object-grid-element.component.html | 0 .../object-grid-element.component.scss | 6 + .../object-grid-element.component.ts | 14 +++ .../object-grid/object-grid.component.html | 23 ++++ .../object-grid/object-grid.component.scss | 1 + src/app/object-grid/object-grid.component.ts | 86 +++++++++++++ ...-search-result-grid-element.component.html | 2 + ...-search-result-grid-element.component.scss | 2 + ...on-search-result-grid-element.component.ts | 15 +++ .../collection-search-result.model.ts | 5 + ...-search-result-grid-element.component.html | 2 + ...-search-result-grid-element.component.scss | 2 + ...ty-search-result-grid-element.component.ts | 17 +++ .../community-search-result.model.ts | 5 + ...-search-result-grid-element.component.html | 27 +++++ ...-search-result-grid-element.component.scss | 2 + ...em-search-result-grid-element.component.ts | 15 +++ .../search-result-grid-element.component.scss | 8 ++ .../search-result-grid-element.component.ts | 57 +++++++++ .../wrapper-grid-element.component.html | 1 + .../wrapper-grid-element.component.scss | 2 + .../wrapper-grid-element.component.ts | 27 +++++ src/app/object-list/list-element-decorator.ts | 2 +- .../object-list-element.component.ts | 2 +- src/app/object-list/object-list.component.ts | 4 +- ...em-search-result-list-element.component.ts | 2 +- .../item-search-result.model.ts | 5 - .../search-result-list-element.component.ts | 2 +- .../wrapper-list-element.component.ts | 2 +- src/app/shared/shared.module.ts | 35 ++++-- src/styles/_mixins.scss | 1 + yarn.lock | 4 + 58 files changed, 684 insertions(+), 49 deletions(-) create mode 100644 src/app/object-collection/object-collection.component.html create mode 100644 src/app/object-collection/object-collection.component.scss create mode 100644 src/app/object-collection/object-collection.component.ts create mode 100644 src/app/object-collection/shared/item-search-result.model.ts rename src/app/{object-list/listable-object => object-collection/shared}/listable-object.model.ts (100%) create mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.html create mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.scss create mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.ts create mode 100644 src/app/object-grid/community-grid-element/community-grid-element.component.html create mode 100644 src/app/object-grid/community-grid-element/community-grid-element.component.scss create mode 100644 src/app/object-grid/community-grid-element/community-grid-element.component.ts create mode 100644 src/app/object-grid/grid-card-styling.scss create mode 100644 src/app/object-grid/grid-element-decorator.ts create mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.html create mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.scss create mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.ts create mode 100644 src/app/object-grid/object-grid-element/object-grid-element.component.html create mode 100644 src/app/object-grid/object-grid-element/object-grid-element.component.scss create mode 100644 src/app/object-grid/object-grid-element/object-grid-element.component.ts create mode 100644 src/app/object-grid/object-grid.component.html create mode 100644 src/app/object-grid/object-grid.component.scss create mode 100644 src/app/object-grid/object-grid.component.ts create mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html create mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss create mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts create mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts create mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html create mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss create mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts create mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts create mode 100644 src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html create mode 100644 src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss create mode 100644 src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts create mode 100644 src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss create mode 100644 src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts create mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html create mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss create mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts delete mode 100644 src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts diff --git a/package.json b/package.json index e32a9af765..1d6a6ef36e 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,7 @@ "methods": "1.1.2", "morgan": "1.9.0", "ngx-pagination": "3.0.1", + "object-fit-images": "^3.2.3", "pem": "1.12.3", "reflect-metadata": "0.1.10", "rxjs": "5.4.3", diff --git a/src/app/+collection-page/collection-page.component.html b/src/app/+collection-page/collection-page.component.html index fe5b2a1f16..05b4d6f11e 100644 --- a/src/app/+collection-page/collection-page.component.html +++ b/src/app/+collection-page/collection-page.component.html @@ -41,13 +41,13 @@

    {{'collection.page.browse.recent.head' | translate}}

    - - +
    diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html index b04e93ff71..f78b212bee 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html @@ -2,12 +2,8 @@

    {{'community.sub-collection-list.head' | translate}}

    diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html index a34951afe0..4eebb53e1e 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html @@ -1,15 +1,13 @@ -
    -

    {{'home.top-level-communities.head' | translate}}

    -

    {{'home.top-level-communities.help' | translate}}

    - - -
    - - -
    +
    +

    {{'home.top-level-communities.head' | translate}}

    +

    {{'home.top-level-communities.help' | translate}}

    + + +
    + +
    diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 153402d11f..d50f5e9442 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -51,7 +51,22 @@ export class SearchPageComponent implements OnInit, OnDestroy { ); this.scopeListRDObs = communityService.findAll(); // Initial pagination config + const pagination: PaginationComponentOptions = new PaginationComponentOptions(); + pagination.id = 'search-results-pagination'; + pagination.currentPage = 1; + pagination.pageSize = 10; + + // TODO Update to accommodate view switcher + this.route.queryParams.map((params) => { + if (isNotEmpty(params.view) && params.view == 'grid') { + pagination.pageSize = 12; + } + }); + + + const sort: SortOptions = new SortOptions(); this.searchOptions = this.service.searchOptions; + } ngOnInit(): void { diff --git a/src/app/+search-page/search-page.module.ts b/src/app/+search-page/search-page.module.ts index 6519d1e92a..be99a0eae4 100644 --- a/src/app/+search-page/search-page.module.ts +++ b/src/app/+search-page/search-page.module.ts @@ -7,6 +7,9 @@ import { SearchResultsComponent } from './search-results/search-results.componen import { ItemSearchResultListElementComponent } from '../object-list/search-result-list-element/item-search-result/item-search-result-list-element.component'; import { CollectionSearchResultListElementComponent } from '../object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component'; import { CommunitySearchResultListElementComponent } from '../object-list/search-result-list-element/community-search-result/community-search-result-list-element.component'; +import { ItemSearchResultGridElementComponent } from '../object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component'; +import { CommunitySearchResultGridElementComponent } from '../object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component' +import { CollectionSearchResultGridElementComponent } from '../object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component'; import { SearchService } from './search-service/search.service'; import { SearchSidebarComponent } from './search-sidebar/search-sidebar.component'; import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; @@ -37,6 +40,10 @@ const effects = [ ItemSearchResultListElementComponent, CollectionSearchResultListElementComponent, CommunitySearchResultListElementComponent, + ItemSearchResultGridElementComponent, + CollectionSearchResultGridElementComponent, + CommunitySearchResultGridElementComponent, + CommunitySearchResultListElementComponent, SearchFiltersComponent, SearchFilterComponent, SearchFacetFilterComponent @@ -49,7 +56,11 @@ const effects = [ entryComponents: [ ItemSearchResultListElementComponent, CollectionSearchResultListElementComponent, - CommunitySearchResultListElementComponent + CommunitySearchResultListElementComponent, + ItemSearchResultGridElementComponent, + CollectionSearchResultGridElementComponent, + CommunitySearchResultGridElementComponent, ] }) -export class SearchPageModule { } +export class SearchPageModule { +} diff --git a/src/app/+search-page/search-result.model.ts b/src/app/+search-page/search-result.model.ts index 2dd9130ee8..602d8ac9c2 100644 --- a/src/app/+search-page/search-result.model.ts +++ b/src/app/+search-page/search-result.model.ts @@ -1,6 +1,6 @@ import { DSpaceObject } from '../core/shared/dspace-object.model'; import { Metadatum } from '../core/shared/metadatum.model'; -import { ListableObject } from '../object-list/listable-object/listable-object.model'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; export class SearchResult implements ListableObject { diff --git a/src/app/+search-page/search-results/search-results.component.html b/src/app/+search-page/search-results/search-results.component.html index 70e315671b..1b9bd7d52a 100644 --- a/src/app/+search-page/search-results/search-results.component.html +++ b/src/app/+search-page/search-results/search-results.component.html @@ -1,10 +1,10 @@

    {{ 'search.results.head' | translate }}

    - -
    + diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 4b5ba7b702..5258756bfb 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -9,10 +9,10 @@ import { SearchOptions } from '../search-options.model'; import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { Metadatum } from '../../core/shared/metadatum.model'; import { Item } from '../../core/shared/item.model'; -import { ItemSearchResult } from '../../object-list/search-result-list-element/item-search-result/item-search-result.model'; import { SearchFilterConfig } from './search-filter-config.model'; import { FilterType } from './filter-type.model'; import { FacetValue } from './facet-value.model'; +import { ItemSearchResult } from '../../object-collection/shared/item-search-result.model'; import { ViewMode } from '../../+search-page/search-options.model'; import { Router, NavigationExtras, ActivatedRoute } from '@angular/router'; import { RouteService } from '../../shared/route.service'; diff --git a/src/app/core/shared/dspace-object.model.ts b/src/app/core/shared/dspace-object.model.ts index 572efecada..a17a6b31ce 100644 --- a/src/app/core/shared/dspace-object.model.ts +++ b/src/app/core/shared/dspace-object.model.ts @@ -3,7 +3,7 @@ import { isEmpty, isNotEmpty } from '../../shared/empty.util'; import { CacheableObject } from '../cache/object-cache.reducer'; import { RemoteData } from '../data/remote-data'; import { ResourceType } from './resource-type'; -import { ListableObject } from '../../object-list/listable-object/listable-object.model'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; import { Observable } from 'rxjs/Observable'; /** diff --git a/src/app/object-collection/object-collection.component.html b/src/app/object-collection/object-collection.component.html new file mode 100644 index 0000000000..e651c18290 --- /dev/null +++ b/src/app/object-collection/object-collection.component.html @@ -0,0 +1,13 @@ + + + + + + + diff --git a/src/app/object-collection/object-collection.component.scss b/src/app/object-collection/object-collection.component.scss new file mode 100644 index 0000000000..da97dd7a62 --- /dev/null +++ b/src/app/object-collection/object-collection.component.scss @@ -0,0 +1 @@ +@import '../../styles/variables.scss'; diff --git a/src/app/object-collection/object-collection.component.ts b/src/app/object-collection/object-collection.component.ts new file mode 100644 index 0000000000..25761073e4 --- /dev/null +++ b/src/app/object-collection/object-collection.component.ts @@ -0,0 +1,113 @@ +import { Component, EventEmitter, + Input, + OnInit, + Output, SimpleChanges, OnChanges, ChangeDetectorRef } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; + +import { Observable } from 'rxjs/Observable'; + +import { RemoteData } from '../core/data/remote-data'; +import { PageInfo } from '../core/shared/page-info.model'; + +import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; + +import { SortDirection } from '../core/cache/models/sort-options.model'; + +import { ListableObject } from './shared/listable-object.model'; +import { hasValue, isNotEmpty } from '../shared/empty.util'; +@Component({ + selector: 'ds-viewable-collection', + styleUrls: ['./object-collection.component.scss'], + templateUrl: './object-collection.component.html', +}) +export class ObjectCollectionComponent implements OnChanges, OnInit { + + @Input() objects: RemoteData; + @Input() config?: PaginationComponentOptions; + pageInfo: Observable; + + /** + * An event fired when the page is changed. + * Event's payload equals to the newly selected page. + */ + @Output() pageChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the page wsize is changed. + * Event's payload equals to the newly selected page size. + */ + @Output() pageSizeChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort direction is changed. + * Event's payload equals to the newly selected sort direction. + */ + @Output() sortDirectionChange: EventEmitter = new EventEmitter(); + + @Output() paginationChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort field is changed. + * Event's payload equals to the newly selected sort field. + */ + @Output() sortFieldChange: EventEmitter = new EventEmitter(); + data: any = {}; + defaultViewMode: string ='list'; + + ngOnChanges(changes: SimpleChanges) { + if (changes.objects && !changes.objects.isFirstChange()) { + this.pageInfo = this.objects.pageInfo; + } + } + + ngOnInit(): void { + this.pageInfo = this.objects.pageInfo; + } + + /** + * @param route + * Route is a singleton service provided by Angular. + * @param router + * Router is a singleton service provided by Angular. + */ + constructor(private cdRef: ChangeDetectorRef, private route: ActivatedRoute, + private router: Router) { + } + + getViewMode(): string { + // TODO Update to accommodate view switcher + + this.route.queryParams.map((params) => { + if (isNotEmpty(params.view) && hasValue(params.view)) { + return params.view; + } else { + return this.defaultViewMode; + } + }); + return this.defaultViewMode; + } + + setViewMode(viewMode: string) { + this.defaultViewMode = viewMode; + } + onPageChange(event) { + this.pageChange.emit(event); + } + + onPageSizeChange(event) { + this.pageSizeChange.emit(event); + } + + onSortDirectionChange(event) { + this.sortDirectionChange.emit(event); + } + + onSortFieldChange(event) { + this.sortFieldChange.emit(event); + } + + onPaginationChange(event) { + this.paginationChange.emit(event); + } + +} diff --git a/src/app/object-collection/shared/item-search-result.model.ts b/src/app/object-collection/shared/item-search-result.model.ts new file mode 100644 index 0000000000..75d56a2488 --- /dev/null +++ b/src/app/object-collection/shared/item-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../+search-page/search-result.model'; +import { Item } from '../../core/shared/item.model'; + +export class ItemSearchResult extends SearchResult { +} diff --git a/src/app/object-list/listable-object/listable-object.model.ts b/src/app/object-collection/shared/listable-object.model.ts similarity index 100% rename from src/app/object-list/listable-object/listable-object.model.ts rename to src/app/object-collection/shared/listable-object.model.ts diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.html b/src/app/object-grid/collection-grid-element/collection-grid-element.component.html new file mode 100644 index 0000000000..5dc717cf54 --- /dev/null +++ b/src/app/object-grid/collection-grid-element/collection-grid-element.component.html @@ -0,0 +1,12 @@ +
    + + + + +
    +

    {{object.name}}

    +

    {{object.shortDescription}}

    + View + +
    +
    diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss b/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss new file mode 100644 index 0000000000..48e2b121d4 --- /dev/null +++ b/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts new file mode 100644 index 0000000000..80be3d75b3 --- /dev/null +++ b/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -0,0 +1,14 @@ +import { Component, Inject } from '@angular/core'; + +import { Collection } from '../../core/shared/collection.model'; +import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { gridElementFor } from '../grid-element-decorator'; + +@Component({ + selector: 'ds-collection-grid-element', + styleUrls: ['./collection-grid-element.component.scss'], + templateUrl: './collection-grid-element.component.html' +}) + +@gridElementFor(Collection) +export class CollectionGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.html b/src/app/object-grid/community-grid-element/community-grid-element.component.html new file mode 100644 index 0000000000..e4ea3dcb13 --- /dev/null +++ b/src/app/object-grid/community-grid-element/community-grid-element.component.html @@ -0,0 +1,12 @@ +
    + + + + + +
    +

    {{object.name}}

    +

    {{object.shortDescription}}

    + View +
    +
    diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.scss b/src/app/object-grid/community-grid-element/community-grid-element.component.scss new file mode 100644 index 0000000000..48e2b121d4 --- /dev/null +++ b/src/app/object-grid/community-grid-element/community-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.ts b/src/app/object-grid/community-grid-element/community-grid-element.component.ts new file mode 100644 index 0000000000..e29e037c5d --- /dev/null +++ b/src/app/object-grid/community-grid-element/community-grid-element.component.ts @@ -0,0 +1,14 @@ +import { Component, Input, Inject } from '@angular/core'; + +import { Community } from '../../core/shared/community.model'; +import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { gridElementFor} from '../grid-element-decorator'; + +@Component({ + selector: 'ds-community-grid-element', + styleUrls: ['./community-grid-element.component.scss'], + templateUrl: './community-grid-element.component.html' +}) + +@gridElementFor(Community) +export class CommunityGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/grid-card-styling.scss b/src/app/object-grid/grid-card-styling.scss new file mode 100644 index 0000000000..52b78524b0 --- /dev/null +++ b/src/app/object-grid/grid-card-styling.scss @@ -0,0 +1,36 @@ +.card-title{ + line-height: 1em; + height:3em; + overflow: hidden; + text-overflow: ellipsis; +} + +.card-text { + overflow: hidden; + text-overflow: ellipsis; + line-height: 1em; + margin-bottom:10px; +} +.card-text.item-authors { + height: 1em; +} +.card-text.item-abstract { + height: 5em; + +} +.viewButton{ + display:block; +} + +.card{ + padding:10px; + margin-bottom: 15px; +} + +.card-img-top ::ng-deep img +{ + height: 120px; + width: 100%; + object-fit: cover; + margin-bottom: 10px; +} diff --git a/src/app/object-grid/grid-element-decorator.ts b/src/app/object-grid/grid-element-decorator.ts new file mode 100644 index 0000000000..cd5ebbcaeb --- /dev/null +++ b/src/app/object-grid/grid-element-decorator.ts @@ -0,0 +1,16 @@ +import { GenericConstructor } from '../core/shared/generic-constructor'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; + +const gridElementMap = new Map(); +export function gridElementFor(gridable: GenericConstructor) { + return function decorator(objectElement: any) { + if (!objectElement) { + return; + } + gridElementMap.set(gridable, objectElement); + }; +} + +export function getGridElementFor(gridable: GenericConstructor) { + return gridElementMap.get(gridable); +} diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.html b/src/app/object-grid/item-grid-element/item-grid-element.component.html new file mode 100644 index 0000000000..ea7b894896 --- /dev/null +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.html @@ -0,0 +1,20 @@ +
    + + + + + +
    +

    {{object.findMetadata('dc.title')}}

    +

    + {{authorMd.value}} + ; + +

    + ({{object.findMetadata("dc.publisher")}}, {{object.findMetadata("dc.date.issued")}}) + +

    {{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

    + + View +
    +
    diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.scss b/src/app/object-grid/item-grid-element/item-grid-element.component.scss new file mode 100644 index 0000000000..48e2b121d4 --- /dev/null +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.ts b/src/app/object-grid/item-grid-element/item-grid-element.component.ts new file mode 100644 index 0000000000..c651ccfc9c --- /dev/null +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.ts @@ -0,0 +1,14 @@ +import { Component, Input, Inject } from '@angular/core'; + +import { Item } from '../../core/shared/item.model'; +import { gridElementFor } from '../grid-element-decorator'; +import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; + +@Component({ + selector: 'ds-item-grid-element', + styleUrls: ['./item-grid-element.component.scss'], + templateUrl: './item-grid-element.component.html' +}) + +@gridElementFor(Item) +export class ItemGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.html b/src/app/object-grid/object-grid-element/object-grid-element.component.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/object-grid/object-grid-element/object-grid-element.component.scss new file mode 100644 index 0000000000..0351acf15f --- /dev/null +++ b/src/app/object-grid/object-grid-element/object-grid-element.component.scss @@ -0,0 +1,6 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; +:host { + display: block; + margin-bottom: $spacer; +} diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.ts b/src/app/object-grid/object-grid-element/object-grid-element.component.ts new file mode 100644 index 0000000000..c3ab5e39e3 --- /dev/null +++ b/src/app/object-grid/object-grid-element/object-grid-element.component.ts @@ -0,0 +1,14 @@ +import { Component, Inject } from '@angular/core'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; + +@Component({ + selector: 'ds-object-grid-element', + styleUrls: ['./object-grid-element.component.scss'], + templateUrl: './object-grid-element.component.html' +}) +export class ObjectGridElementComponent { + object: T; + public constructor(@Inject('objectElementProvider') public gridable: ListableObject) { + this.object = gridable as T; + } +} diff --git a/src/app/object-grid/object-grid.component.html b/src/app/object-grid/object-grid.component.html new file mode 100644 index 0000000000..2ad9c11a8f --- /dev/null +++ b/src/app/object-grid/object-grid.component.html @@ -0,0 +1,23 @@ + +
      +
      +
      + +
      +
      +
    + + +
    diff --git a/src/app/object-grid/object-grid.component.scss b/src/app/object-grid/object-grid.component.scss new file mode 100644 index 0000000000..da97dd7a62 --- /dev/null +++ b/src/app/object-grid/object-grid.component.scss @@ -0,0 +1 @@ +@import '../../styles/variables.scss'; diff --git a/src/app/object-grid/object-grid.component.ts b/src/app/object-grid/object-grid.component.ts new file mode 100644 index 0000000000..b316fe37c2 --- /dev/null +++ b/src/app/object-grid/object-grid.component.ts @@ -0,0 +1,86 @@ +import { + Component, EventEmitter, + Input, + ViewEncapsulation, + ChangeDetectionStrategy, + OnInit, + Output, SimpleChanges, OnChanges, ChangeDetectorRef, DoCheck +} from '@angular/core'; +import { Observable } from 'rxjs/Observable'; + +import { RemoteData } from '../core/data/remote-data'; +import { PageInfo } from '../core/shared/page-info.model'; + +import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; + +import { SortOptions, SortDirection } from '../core/cache/models/sort-options.model'; +import { fadeIn } from '../shared/animations/fade'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; + +@Component({ + changeDetection: ChangeDetectionStrategy.Default, + encapsulation: ViewEncapsulation.Emulated, + selector: 'ds-object-grid', + styleUrls: [ './object-grid.component.scss' ], + templateUrl: './object-grid.component.html', + animations: [fadeIn] +}) + +export class ObjectGridComponent implements OnChanges, OnInit { + + @Input() objects: RemoteData; + @Input() config: PaginationComponentOptions; + @Input() sortConfig: SortOptions; + @Input() hideGear = false; + @Input() hidePagerWhenSinglePage = true; + pageInfo: Observable; + + /** + * An event fired when the page is changed. + * Event's payload equals to the newly selected page. + */ + @Output() pageChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the page wsize is changed. + * Event's payload equals to the newly selected page size. + */ + @Output() pageSizeChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort direction is changed. + * Event's payload equals to the newly selected sort direction. + */ + @Output() sortDirectionChange: EventEmitter = new EventEmitter(); + + @Output() paginationChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort field is changed. + * Event's payload equals to the newly selected sort field. + */ + @Output() sortFieldChange: EventEmitter = new EventEmitter(); + data: any = {}; + + ngOnChanges(changes: SimpleChanges) { + if (changes.objects && !changes.objects.isFirstChange()) { + this.pageInfo = this.objects.pageInfo; + } + } + + ngOnInit(): void { + this.pageInfo = this.objects.pageInfo; + this.config.pageSize = 4; + } + + /** + * @param route + * Route is a singleton service provided by Angular. + * @param router + * Router is a singleton service provided by Angular. + */ + constructor(private cdRef: ChangeDetectorRef) { + } + + +} diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html new file mode 100644 index 0000000000..914fb49487 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html @@ -0,0 +1,2 @@ + +
    diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss new file mode 100644 index 0000000000..790f794381 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables.scss'; +@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts new file mode 100644 index 0000000000..aa1d495dba --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts @@ -0,0 +1,15 @@ +import { Component } from '@angular/core'; + +import { gridElementFor } from '../../grid-element-decorator'; +import { CollectionSearchResult } from './collection-search-result.model'; +import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; +import { Collection } from '../../../core/shared/collection.model'; + +@Component({ + selector: 'ds-collection-search-result-grid-element', + styleUrls: ['../search-result-grid-element.component.scss', 'collection-search-result-grid-element.component.scss'], + templateUrl: 'collection-search-result-grid-element.component.html' +}) + +@gridElementFor(CollectionSearchResult) +export class CollectionSearchResultGridElementComponent extends SearchResultGridElementComponent {} diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts new file mode 100644 index 0000000000..fa7945dedd --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../+search-page/search-result.model'; +import { Collection } from '../../../core/shared/collection.model'; + +export class CollectionSearchResult extends SearchResult { +} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html new file mode 100644 index 0000000000..d09ef7d668 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html @@ -0,0 +1,2 @@ + +
    diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss new file mode 100644 index 0000000000..790f794381 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables.scss'; +@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts new file mode 100644 index 0000000000..1ce9e1d09a --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts @@ -0,0 +1,17 @@ +import { Component } from '@angular/core'; + +import { CommunitySearchResult } from './community-search-result.model'; +import { Community } from '../../../core/shared/community.model'; +import { gridElementFor } from '../../grid-element-decorator'; +import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; + +@Component({ + selector: 'ds-community-search-result-grid-element', + styleUrls: ['../search-result-grid-element.component.scss', 'community-search-result-grid-element.component.scss'], + templateUrl: 'community-search-result-grid-element.component.html' +}) + +@gridElementFor(CommunitySearchResult) +export class CommunitySearchResultGridElementComponent extends SearchResultGridElementComponent { + +} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts new file mode 100644 index 0000000000..79ea34b6cd --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../+search-page/search-result.model'; +import { Community } from '../../../core/shared/community.model'; + +export class CommunitySearchResult extends SearchResult { +} diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html new file mode 100644 index 0000000000..c6e1bc6b14 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html @@ -0,0 +1,27 @@ +
    + + + + +
    +

    {{dso.findMetadata('dc.title')}}

    + +

    + {{authorMd.value}} + ; + +

    + ({{dso.findMetadata("dc.publisher")}}, {{dso.findMetadata("dc.date.issued")}}) + +

    + {{dso.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

    + +
    + View + +
    + diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss new file mode 100644 index 0000000000..790f794381 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables.scss'; +@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts new file mode 100644 index 0000000000..7a82803c9b --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts @@ -0,0 +1,15 @@ +import { Component } from '@angular/core'; + +import { gridElementFor } from '../../grid-element-decorator'; +import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; +import { Item } from '../../../core/shared/item.model'; +import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; + +@Component({ + selector: 'ds-item-search-result-grid-element', + styleUrls: ['../search-result-grid-element.component.scss', 'item-search-result-grid-element.component.scss'], + templateUrl: 'item-search-result-grid-element.component.html' +}) + +@gridElementFor(ItemSearchResult) +export class ItemSearchResultGridElementComponent extends SearchResultGridElementComponent {} diff --git a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss new file mode 100644 index 0000000000..0f2684f1f1 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss @@ -0,0 +1,8 @@ + @import '../../../styles/variables.scss'; + @import '../grid-card-styling.scss'; +:host { + /deep/ em { + font-weight: bold; + font-style: normal; + } +} diff --git a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts new file mode 100644 index 0000000000..ba98a58d4b --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts @@ -0,0 +1,57 @@ +import { Component, Inject } from '@angular/core'; + +import { SearchResult } from '../../+search-page/search-result.model'; +import { DSpaceObject } from '../../core/shared/dspace-object.model'; +import { Metadatum } from '../../core/shared/metadatum.model'; +import { isEmpty, hasNoValue } from '../../shared/empty.util'; +import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; + +@Component({ + selector: 'ds-search-result-grid-element', + template: `` +}) + +export class SearchResultGridElementComponent, K extends DSpaceObject> extends ObjectGridElementComponent { + dso: K; + + public constructor(@Inject('objectElementProvider') public gridable: ListableObject) { + super(gridable); + this.dso = this.object.dspaceObject; + } + + getValues(keys: string[]): string[] { + const results: string[] = new Array(); + this.object.hitHighlights.forEach( + (md: Metadatum) => { + if (keys.indexOf(md.key) > -1) { + results.push(md.value); + } + } + ); + if (isEmpty(results)) { + this.dso.filterMetadata(keys).forEach( + (md: Metadatum) => { + results.push(md.value); + } + ); + } + return results; + } + + getFirstValue(key: string): string { + let result: string; + this.object.hitHighlights.some( + (md: Metadatum) => { + if (key === md.key) { + result = md.value; + return true; + } + } + ); + if (hasNoValue(result)) { + result = this.dso.findMetadata(key); + } + return result; + } +} diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html new file mode 100644 index 0000000000..b613b16055 --- /dev/null +++ b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html @@ -0,0 +1 @@ + diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss new file mode 100644 index 0000000000..48e2b121d4 --- /dev/null +++ b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts new file mode 100644 index 0000000000..bd15a0d443 --- /dev/null +++ b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts @@ -0,0 +1,27 @@ +import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; +import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { getGridElementFor } from '../grid-element-decorator'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; + +@Component({ + selector: 'ds-wrapper-grid-element', + styleUrls: ['./wrapper-grid-element.component.scss'], + templateUrl: './wrapper-grid-element.component.html' +}) +export class WrapperGridElementComponent implements OnInit { + @Input() object: ListableObject; + objectInjector: Injector; + + constructor(private injector: Injector) {} + + ngOnInit(): void { + this.objectInjector = ReflectiveInjector.resolveAndCreate( + [{provide: 'objectElementProvider', useFactory: () => (this.object) }], this.injector); + + } + + getGridElement(): string { + const f: GenericConstructor = this.object.constructor as GenericConstructor; + return getGridElementFor(f); + } +} diff --git a/src/app/object-list/list-element-decorator.ts b/src/app/object-list/list-element-decorator.ts index 64a747d4a5..aa044755ea 100644 --- a/src/app/object-list/list-element-decorator.ts +++ b/src/app/object-list/list-element-decorator.ts @@ -1,5 +1,5 @@ -import { ListableObject } from './listable-object/listable-object.model'; import { GenericConstructor } from '../core/shared/generic-constructor'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; const listElementMap = new Map(); export function listElementFor(listable: GenericConstructor) { diff --git a/src/app/object-list/object-list-element/object-list-element.component.ts b/src/app/object-list/object-list-element/object-list-element.component.ts index df39a7d18d..24f0ec1d93 100644 --- a/src/app/object-list/object-list-element/object-list-element.component.ts +++ b/src/app/object-list/object-list-element/object-list-element.component.ts @@ -1,5 +1,5 @@ import { Component, Inject } from '@angular/core'; -import { ListableObject } from '../listable-object/listable-object.model'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ selector: 'ds-object-list-element', diff --git a/src/app/object-list/object-list.component.ts b/src/app/object-list/object-list.component.ts index 0f7decadd7..352d7bc393 100644 --- a/src/app/object-list/object-list.component.ts +++ b/src/app/object-list/object-list.component.ts @@ -11,9 +11,8 @@ import { SortDirection, SortOptions } from '../core/cache/models/sort-options.mo import { RemoteData } from '../core/data/remote-data'; import { PageInfo } from '../core/shared/page-info.model'; -import { ListableObject } from '../object-list/listable-object/listable-object.model'; - import { fadeIn } from '../shared/animations/fade'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; import { hasValue } from '../shared/empty.util'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; @@ -83,6 +82,7 @@ export class ObjectListComponent { @Output() sortFieldChange: EventEmitter = new EventEmitter(); data: any = {}; + onPageChange(event) { this.pageChange.emit(event); } diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts index ef968db0b8..2974a87883 100644 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts @@ -1,9 +1,9 @@ import { Component } from '@angular/core'; import { listElementFor } from '../../list-element-decorator'; -import { ItemSearchResult } from './item-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; import { Item } from '../../../core/shared/item.model'; +import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; @Component({ selector: 'ds-item-search-result-list-element', diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts b/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts deleted file mode 100644 index d9af3539a0..0000000000 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Item } from '../../../core/shared/item.model'; - -export class ItemSearchResult extends SearchResult { -} diff --git a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/search-result-list-element.component.ts index 4119bc3c2e..ec0afde65d 100644 --- a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/search-result-list-element.component.ts @@ -1,11 +1,11 @@ import { Component, Inject } from '@angular/core'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { ListableObject } from '../listable-object/listable-object.model'; import { SearchResult } from '../../+search-page/search-result.model'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { Metadatum } from '../../core/shared/metadatum.model'; import { isEmpty, hasNoValue } from '../../shared/empty.util'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ selector: 'ds-search-result-list-element', diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts index 443b9681d1..2e1184b023 100644 --- a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts +++ b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts @@ -1,7 +1,7 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; -import { ListableObject } from '../listable-object/listable-object.model'; import { getListElementFor } from '../list-element-decorator' import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ selector: 'ds-wrapper-list-element', diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 245d45ea4e..1ebf251e2c 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -15,20 +15,30 @@ import { SafeUrlPipe } from './utils/safe-url-pipe'; import { TruncatePipe } from './utils/truncate.pipe'; import { CollectionListElementComponent } from '../object-list/collection-list-element/collection-list-element.component'; +import { CommunityListElementComponent } from '../object-list/community-list-element/community-list-element.component'; +import { ItemListElementComponent } from '../object-list/item-list-element/item-list-element.component'; +import { ObjectListElementComponent } from '../object-list/object-list-element/object-list-element.component'; +import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component'; +import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; +import { ObjectListComponent } from '../object-list/object-list.component'; + +import { CollectionGridElementComponent} from '../object-grid/collection-grid-element/collection-grid-element.component' +import { CommunityGridElementComponent} from '../object-grid/community-grid-element/community-grid-element.component' +import { ItemGridElementComponent} from '../object-grid/item-grid-element/item-grid-element.component' +import { ObjectGridElementComponent} from '../object-grid/object-grid-element/object-grid-element.component' +import { WrapperGridElementComponent} from '../object-grid/wrapper-grid-element/wrapper-grid-element.component' +import { ObjectGridComponent } from '../object-grid/object-grid.component'; +import { ObjectCollectionComponent } from '../object-collection/object-collection.component'; import { ComcolPageContentComponent } from './comcol-page-content/comcol-page-content.component'; import { ComcolPageHeaderComponent } from './comcol-page-header/comcol-page-header.component'; import { ComcolPageLogoComponent } from './comcol-page-logo/comcol-page-logo.component'; -import { CommunityListElementComponent } from '../object-list/community-list-element/community-list-element.component'; import { ErrorComponent } from './error/error.component'; import { LoadingComponent } from './loading/loading.component'; -import { ItemListElementComponent } from '../object-list/item-list-element/item-list-element.component'; -import { ObjectListComponent } from '../object-list/object-list.component'; -import { ObjectListElementComponent } from '../object-list/object-list-element/object-list-element.component'; + import { PaginationComponent } from './pagination/pagination.component'; import { ThumbnailComponent } from '../thumbnail/thumbnail.component'; -import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component'; import { SearchFormComponent } from './search-form/search-form.component'; -import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; +import { SearchResultGridElementComponent } from '../object-grid/search-result-grid-element/search-result-grid-element.component'; import { ViewModeSwitchComponent } from './view-mode-switch/view-mode-switch.component'; import { VarDirective } from './utils/var.directive'; @@ -60,6 +70,11 @@ const COMPONENTS = [ LoadingComponent, ObjectListComponent, ObjectListElementComponent, + WrapperListElementComponent, + ObjectGridComponent, + ObjectGridElementComponent, + WrapperGridElementComponent, + ObjectCollectionComponent, PaginationComponent, SearchFormComponent, ThumbnailComponent, @@ -69,10 +84,14 @@ const COMPONENTS = [ const ENTRY_COMPONENTS = [ // put shared entry components (components that are created dynamically) here + ItemListElementComponent, CollectionListElementComponent, CommunityListElementComponent, - ItemListElementComponent, - SearchResultListElementComponent + SearchResultListElementComponent, + ItemGridElementComponent, + CollectionGridElementComponent, + CommunityGridElementComponent, + SearchResultGridElementComponent ]; const DIRECTIVES = [ diff --git a/src/styles/_mixins.scss b/src/styles/_mixins.scss index 73aa27eccc..7d05343152 100644 --- a/src/styles/_mixins.scss +++ b/src/styles/_mixins.scss @@ -2,3 +2,4 @@ @import '../../node_modules/bootstrap/scss/mixins.scss'; /* Custom mixins go here */ + diff --git a/yarn.lock b/yarn.lock index 91b2a787e2..4211b7228a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4804,6 +4804,10 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" +object-fit-images@^3.2.3: + version "3.2.3" + resolved "https://registry.yarnpkg.com/object-fit-images/-/object-fit-images-3.2.3.tgz#4089f6d0070a3b5563d3c1ab6f1b28d61331f0ac" + object-keys@^1.0.8: version "1.0.11" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d" From a65dd805511596aaa71b59a8533170784e37118a Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 31 Oct 2017 13:28:48 +0100 Subject: [PATCH 17/77] #150 SortOptions config fixing --- ...ty-page-sub-collection-list.component.html | 15 ++++++------- .../top-level-community-list.component.html | 2 +- .../+search-page/search-page.component.html | 2 +- src/app/+search-page/search-page.component.ts | 7 +++--- .../search-results.component.ts | 2 ++ .../object-collection.component.html | 4 ++-- .../object-collection.component.ts | 22 +++++++++---------- src/app/object-grid/object-grid.component.ts | 19 ++++++++++++++++ ...-search-result-grid-element.component.html | 2 +- src/app/object-list/object-list.component.ts | 19 ++++++++++++++++ 10 files changed, 66 insertions(+), 28 deletions(-) diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html index f78b212bee..9494cdb755 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html @@ -1,11 +1,10 @@ -
    -

    {{'community.sub-collection-list.head' | translate}}

    -
      - - -
    -
    - +
    +

    {{'community.sub-collection-list.head' | translate}}

    +
      + +
    +
    diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html index 4eebb53e1e..934bb3933c 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html @@ -4,8 +4,8 @@

    {{'home.top-level-communities.help' | translate}}

    diff --git a/src/app/+search-page/search-page.component.html b/src/app/+search-page/search-page.component.html index c4d679f72b..68a7bf6a9e 100644 --- a/src/app/+search-page/search-page.component.html +++ b/src/app/+search-page/search-page.component.html @@ -30,7 +30,7 @@ + [searchConfig]="searchOptions" [sortConfig]="sortConfig"> diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index d50f5e9442..d5f220d2b1 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -6,7 +6,7 @@ import { RemoteData } from '../core/data/remote-data'; import { Community } from '../core/shared/community.model'; import { DSpaceObject } from '../core/shared/dspace-object.model'; import { isNotEmpty } from '../shared/empty.util'; -import { SearchOptions } from './search-options.model'; +import { SearchOptions,ViewMode } from './search-options.model'; import { SearchResult } from './search-result.model'; import { SearchService } from './search-service/search.service'; import { pushInOut } from '../shared/animations/push'; @@ -36,6 +36,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { resultsRDObs: Observable>>>; currentParams = {}; searchOptions: SearchOptions; + sortConfig: SortOptions; scopeListRDObs: Observable>; isMobileView: Observable; @@ -58,15 +59,15 @@ export class SearchPageComponent implements OnInit, OnDestroy { // TODO Update to accommodate view switcher this.route.queryParams.map((params) => { - if (isNotEmpty(params.view) && params.view == 'grid') { + if (isNotEmpty(params.view) && params.view == ViewMode.Grid) { pagination.pageSize = 12; } }); const sort: SortOptions = new SortOptions(); + this.sortConfig=sort; this.searchOptions = this.service.searchOptions; - } ngOnInit(): void { diff --git a/src/app/+search-page/search-results/search-results.component.ts b/src/app/+search-page/search-results/search-results.component.ts index 4733699f95..f8b3721630 100644 --- a/src/app/+search-page/search-results/search-results.component.ts +++ b/src/app/+search-page/search-results/search-results.component.ts @@ -3,6 +3,7 @@ import { RemoteData } from '../../core/data/remote-data'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { fadeIn, fadeInOut } from '../../shared/animations/fade'; import { SearchOptions } from '../search-options.model'; +import { SortOptions } from '../../core/cache/models/sort-options.model'; import { SearchResult } from '../search-result.model'; /** @@ -21,4 +22,5 @@ import { SearchResult } from '../search-result.model'; export class SearchResultsComponent { @Input() searchResults: RemoteData>>; @Input() searchConfig: SearchOptions; + @Input() sortConfig: SortOptions; } diff --git a/src/app/object-collection/object-collection.component.html b/src/app/object-collection/object-collection.component.html index e651c18290..6c2a2fb1de 100644 --- a/src/app/object-collection/object-collection.component.html +++ b/src/app/object-collection/object-collection.component.html @@ -1,13 +1,13 @@ + *ngIf="getViewMode()===viewModeEnum.List"> + *ngIf="getViewMode()===viewModeEnum.Grid"> diff --git a/src/app/object-collection/object-collection.component.ts b/src/app/object-collection/object-collection.component.ts index 25761073e4..5a6d06509b 100644 --- a/src/app/object-collection/object-collection.component.ts +++ b/src/app/object-collection/object-collection.component.ts @@ -11,10 +11,12 @@ import { PageInfo } from '../core/shared/page-info.model'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; -import { SortDirection } from '../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; import { ListableObject } from './shared/listable-object.model'; +import { ViewMode } from '../+search-page/search-options.model'; import { hasValue, isNotEmpty } from '../shared/empty.util'; + @Component({ selector: 'ds-viewable-collection', styleUrls: ['./object-collection.component.scss'], @@ -24,6 +26,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { @Input() objects: RemoteData; @Input() config?: PaginationComponentOptions; + @Input() sortConfig: SortOptions; pageInfo: Observable; /** @@ -52,7 +55,8 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { */ @Output() sortFieldChange: EventEmitter = new EventEmitter(); data: any = {}; - defaultViewMode: string ='list'; + currentMode: ViewMode = ViewMode.List; + viewModeEnum = ViewMode; ngOnChanges(changes: SimpleChanges) { if (changes.objects && !changes.objects.isFirstChange()) { @@ -60,6 +64,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { } } + ngOnInit(): void { this.pageInfo = this.objects.pageInfo; } @@ -74,22 +79,15 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { private router: Router) { } - getViewMode(): string { - // TODO Update to accommodate view switcher - + getViewMode(): ViewMode { this.route.queryParams.map((params) => { if (isNotEmpty(params.view) && hasValue(params.view)) { - return params.view; - } else { - return this.defaultViewMode; + this.currentMode= params.view; } }); - return this.defaultViewMode; + return this.currentMode; } - setViewMode(viewMode: string) { - this.defaultViewMode = viewMode; - } onPageChange(event) { this.pageChange.emit(event); } diff --git a/src/app/object-grid/object-grid.component.ts b/src/app/object-grid/object-grid.component.ts index b316fe37c2..02931165c8 100644 --- a/src/app/object-grid/object-grid.component.ts +++ b/src/app/object-grid/object-grid.component.ts @@ -82,5 +82,24 @@ export class ObjectGridComponent implements OnChanges, OnInit { constructor(private cdRef: ChangeDetectorRef) { } + onPageChange(event) { + this.pageChange.emit(event); + } + + onPageSizeChange(event) { + this.pageSizeChange.emit(event); + } + + onSortDirectionChange(event) { + this.sortDirectionChange.emit(event); + } + + onSortFieldChange(event) { + this.sortFieldChange.emit(event); + } + + onPaginationChange(event) { + this.paginationChange.emit(event); + } } diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html index c6e1bc6b14..895e8b59c3 100644 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html @@ -20,8 +20,8 @@

    {{dso.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

    + View - View diff --git a/src/app/object-list/object-list.component.ts b/src/app/object-list/object-list.component.ts index 352d7bc393..9422d1d843 100644 --- a/src/app/object-list/object-list.component.ts +++ b/src/app/object-list/object-list.component.ts @@ -103,4 +103,23 @@ export class ObjectListComponent { this.paginationChange.emit(event); } + onPageChange(event) { + this.pageChange.emit(event); + } + + onPageSizeChange(event) { + this.pageSizeChange.emit(event); + } + + onSortDirectionChange(event) { + this.sortDirectionChange.emit(event); + } + + onSortFieldChange(event) { + this.sortFieldChange.emit(event); + } + + onPaginationChange(event) { + this.paginationChange.emit(event); + } } From 1acd8a952b2f87669c7eb0b7b7067ac7fc1f485d Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 31 Oct 2017 13:51:08 +0100 Subject: [PATCH 18/77] #150 Pre grid/list decorator generalisation commit --- src/app/object-grid/object-grid.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/object-grid/object-grid.component.html b/src/app/object-grid/object-grid.component.html index 2ad9c11a8f..7abfaf28d3 100644 --- a/src/app/object-grid/object-grid.component.html +++ b/src/app/object-grid/object-grid.component.html @@ -12,7 +12,7 @@ (paginationChange)="onPaginationChange($event)">
      -
      From 6a4500b8e7f9bc3e75880fbb97c2735153de5809 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 31 Oct 2017 14:47:52 +0100 Subject: [PATCH 19/77] #150 Intermediate commit --- src/app/+search-page/search-page.component.ts | 10 ++-------- .../object-collection/object-collection.component.ts | 10 +++++++++- src/app/object-grid/object-grid.component.ts | 1 - 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index d5f220d2b1..0d9064dc87 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -57,14 +57,6 @@ export class SearchPageComponent implements OnInit, OnDestroy { pagination.currentPage = 1; pagination.pageSize = 10; - // TODO Update to accommodate view switcher - this.route.queryParams.map((params) => { - if (isNotEmpty(params.view) && params.view == ViewMode.Grid) { - pagination.pageSize = 12; - } - }); - - const sort: SortOptions = new SortOptions(); this.sortConfig=sort; this.searchOptions = this.service.searchOptions; @@ -80,6 +72,8 @@ export class SearchPageComponent implements OnInit, OnDestroy { this.scope = params.scope; const page = +params.page || this.searchOptions.pagination.currentPage; const pageSize = +params.pageSize || this.searchOptions.pagination.pageSize; + + const sortDirection = +params.sortDirection || this.searchOptions.sort.direction; const pagination = Object.assign({}, this.searchOptions.pagination, diff --git a/src/app/object-collection/object-collection.component.ts b/src/app/object-collection/object-collection.component.ts index 5a6d06509b..a79653d970 100644 --- a/src/app/object-collection/object-collection.component.ts +++ b/src/app/object-collection/object-collection.component.ts @@ -28,7 +28,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { @Input() config?: PaginationComponentOptions; @Input() sortConfig: SortOptions; pageInfo: Observable; - + private sub; /** * An event fired when the page is changed. * Event's payload equals to the newly selected page. @@ -67,6 +67,14 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { ngOnInit(): void { this.pageInfo = this.objects.pageInfo; + + this.sub = this.route + .queryParams + .subscribe((params) => { + if(isNotEmpty(params.view)){ + this.currentMode = params.view; + } + }); } /** diff --git a/src/app/object-grid/object-grid.component.ts b/src/app/object-grid/object-grid.component.ts index 02931165c8..a6b62d735f 100644 --- a/src/app/object-grid/object-grid.component.ts +++ b/src/app/object-grid/object-grid.component.ts @@ -70,7 +70,6 @@ export class ObjectGridComponent implements OnChanges, OnInit { ngOnInit(): void { this.pageInfo = this.objects.pageInfo; - this.config.pageSize = 4; } /** From 0032a73ec29d720a93080680e648f0bca1bf2b9a Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 2 Nov 2017 10:53:18 +0100 Subject: [PATCH 20/77] #150 Intermediate commit --- src/app/+search-page/search-page.component.ts | 14 ++++++- src/app/object-grid/grid-card-styling.scss | 33 +++++++++------ .../grid-thumbnail.component.html | 4 ++ .../grid-thumbnail.component.scss | 1 + .../grid-thumbnail.component.spec.ts | 42 +++++++++++++++++++ .../grid-thumbnail.component.ts | 30 +++++++++++++ .../item-grid-element.component.html | 9 ++-- .../object-grid/object-grid.component.html | 4 +- ...-search-result-grid-element.component.html | 31 ++++++++------ src/app/shared/shared.module.ts | 2 + src/styles/_custom_variables.scss | 2 +- 11 files changed, 137 insertions(+), 35 deletions(-) create mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html create mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss create mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts create mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 0d9064dc87..697e379f3d 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -71,18 +71,27 @@ export class SearchPageComponent implements OnInit, OnDestroy { this.query = params.query || ''; this.scope = params.scope; const page = +params.page || this.searchOptions.pagination.currentPage; - const pageSize = +params.pageSize || this.searchOptions.pagination.pageSize; + let pageSize = +params.pageSize || this.searchOptions.pagination.pageSize; + let pageSizeOptions: number[] = [5, 10, 20, 40, 60, 80, 100]; + + if (isNotEmpty(params.view) && params.view === ViewMode.Grid) { + pageSize = 12; + pageSizeOptions = [12, 24, 36, 48 , 50, 62, 74, 84]; + // pageSize = 9; + // pageSizeOptions = [9, 18, 27, 36 , 45, 54, 63, 72]; + } const sortDirection = +params.sortDirection || this.searchOptions.sort.direction; const pagination = Object.assign({}, this.searchOptions.pagination, - { currentPage: page, pageSize: pageSize } + { currentPage: page, pageSize: pageSize, pageSizeOptions: pageSizeOptions} ); const sort = Object.assign({}, this.searchOptions.sort, { direction: sortDirection, field: params.sortField } ); + this.updateSearchResults({ pagination: pagination, sort: sort @@ -98,6 +107,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { private updateSearchResults(searchOptions) { this.resultsRDObs = this.service.search(this.query, this.scope, searchOptions); + this.searchOptions = searchOptions; } ngOnDestroy() { diff --git a/src/app/object-grid/grid-card-styling.scss b/src/app/object-grid/grid-card-styling.scss index 52b78524b0..44f4183bfd 100644 --- a/src/app/object-grid/grid-card-styling.scss +++ b/src/app/object-grid/grid-card-styling.scss @@ -1,6 +1,9 @@ +@import '../../styles/custom_variables'; + .card-title{ - line-height: 1em; - height:3em; + line-height: $line-height-base; + height:$headings-line-height; + font-size:$headings-font-size; overflow: hidden; text-overflow: ellipsis; } @@ -8,29 +11,35 @@ .card-text { overflow: hidden; text-overflow: ellipsis; - line-height: 1em; - margin-bottom:10px; + line-height: $line-height-base; + margin-bottom:$card-block-margin-base*2; } .card-text.item-authors { - height: 1em; + height: $line-height-base; } .card-text.item-abstract { - height: 5em; - + height: $content-line-height; } + .viewButton{ - display:block; + display:table; + margin:auto; + width: $card-button-width; } .card{ - padding:10px; - margin-bottom: 15px; + margin-bottom: $card-block-margin-base *3; + height: 98%; } .card-img-top ::ng-deep img { - height: 120px; + height: $card-thumbnail-height; width: 100%; object-fit: cover; - margin-bottom: 10px; } + +.card-block{ + margin: $card-block-margin-base; +} + diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html new file mode 100644 index 0000000000..6221cbaba1 --- /dev/null +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html @@ -0,0 +1,4 @@ +
      + + +
      diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss new file mode 100644 index 0000000000..50be6f5ad0 --- /dev/null +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss @@ -0,0 +1 @@ +@import '../../../styles/variables.scss'; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts new file mode 100644 index 0000000000..f4ca434221 --- /dev/null +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts @@ -0,0 +1,42 @@ +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +import { ThumbnailComponent } from './thumbnail.component'; +import { Bitstream } from '../../core/shared/bitstream.model'; +import { SafeUrlPipe } from '../../shared/utils/safe-url-pipe'; + +describe('ThumbnailComponent', () => { + let comp: ThumbnailComponent; + let fixture: ComponentFixture; + let de: DebugElement; + let el: HTMLElement; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ThumbnailComponent, SafeUrlPipe] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ThumbnailComponent); + comp = fixture.componentInstance; // BannerComponent test instance + de = fixture.debugElement.query(By.css('div.thumbnail')); + el = de.nativeElement; + }); + + it('should display image', () => { + comp.thumbnail = new Bitstream(); + comp.thumbnail.content = 'test.url'; + fixture.detectChanges(); + const image: HTMLElement = de.query(By.css('img')).nativeElement; + expect(image.getAttribute('src')).toBe(comp.thumbnail.content); + }); + + it('should display placeholder', () => { + fixture.detectChanges(); + const image: HTMLElement = de.query(By.css('img')).nativeElement; + expect(image.getAttribute('src')).toBe(comp.holderSource); + }); + +}); diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts new file mode 100644 index 0000000000..7baa47b39e --- /dev/null +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts @@ -0,0 +1,30 @@ +import { Component, Input } from '@angular/core'; +import { Bitstream } from '../../core/shared/bitstream.model'; + +/** + * This component renders a given Bitstream as a thumbnail. + * One input parameter of type Bitstream is expected. + * If no Bitstream is provided, a holderjs image will be rendered instead. + */ + +@Component({ + selector: 'ds-grid-thumbnail', + styleUrls: ['./grid-thumbnail.component.scss'], + templateUrl: './grid-thumbnail.component.html' +}) +export class GridThumbnailComponent { + + @Input() thumbnail: Bitstream; + + data: any = {}; + + /** + * The default 'holder.js' image + */ + holderSource = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMjYwIiBoZWlnaHQ9IjE4MCIgdmlld0JveD0iMCAwIDI2MCAxODAiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjwhLS0KU291cmNlIFVSTDogaG9sZGVyLmpzLzEwMCV4MTgwL3RleHQ6Tm8gVGh1bWJuYWlsCkNyZWF0ZWQgd2l0aCBIb2xkZXIuanMgMi42LjAuCkxlYXJuIG1vcmUgYXQgaHR0cDovL2hvbGRlcmpzLmNvbQooYykgMjAxMi0yMDE1IEl2YW4gTWFsb3BpbnNreSAtIGh0dHA6Ly9pbXNreS5jbwotLT48ZGVmcz48c3R5bGUgdHlwZT0idGV4dC9jc3MiPjwhW0NEQVRBWyNob2xkZXJfMTVmNzJmMmFlMGIgdGV4dCB7IGZpbGw6I0FBQUFBQTtmb250LXdlaWdodDpib2xkO2ZvbnQtZmFtaWx5OkFyaWFsLCBIZWx2ZXRpY2EsIE9wZW4gU2Fucywgc2Fucy1zZXJpZiwgbW9ub3NwYWNlO2ZvbnQtc2l6ZToxM3B0IH0gXV0+PC9zdHlsZT48L2RlZnM+PGcgaWQ9ImhvbGRlcl8xNWY3MmYyYWUwYiI+PHJlY3Qgd2lkdGg9IjI2MCIgaGVpZ2h0PSIxODAiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSI3Mi4yNDIxODc1IiB5PSI5NiI+Tm8gVGh1bWJuYWlsPC90ZXh0PjwvZz48L2c+PC9zdmc+'; + + errorHandler(event) { + event.currentTarget.src = this.holderSource; + } + +} diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.html b/src/app/object-grid/item-grid-element/item-grid-element.component.html index ea7b894896..3fae55088e 100644 --- a/src/app/object-grid/item-grid-element/item-grid-element.component.html +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.html @@ -1,17 +1,18 @@
      - - + +

      {{object.findMetadata('dc.title')}}

      -

      + +

      {{authorMd.value}} ; + {{object.findMetadata("dc.date.issued")}}

      - ({{object.findMetadata("dc.publisher")}}, {{object.findMetadata("dc.date.issued")}})

      {{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

      diff --git a/src/app/object-grid/object-grid.component.html b/src/app/object-grid/object-grid.component.html index 7abfaf28d3..ebcf240d28 100644 --- a/src/app/object-grid/object-grid.component.html +++ b/src/app/object-grid/object-grid.component.html @@ -10,14 +10,12 @@ (sortDirectionChange)="onSortDirectionChange($event)" (sortFieldChange)="onSortDirectionChange($event)" (paginationChange)="onPaginationChange($event)"> -
        -
        +
        -
      diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html index 895e8b59c3..be84039416 100644 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html @@ -1,24 +1,29 @@
      - - + +
      -

      {{dso.findMetadata('dc.title')}}

      +

      -

      +

      {{authorMd.value}} - ; + *ngFor="let authorMd of dso.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']); let first=first;"> + + , ... + -

      - ({{dso.findMetadata("dc.publisher")}}, {{dso.findMetadata("dc.date.issued")}}) + + , + {{dso.findMetadata("dc.date.issued")}} -

      - {{dso.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

      + +

      +

      +

      View
      diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 1ebf251e2c..8ef05b2f89 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -40,6 +40,7 @@ import { ThumbnailComponent } from '../thumbnail/thumbnail.component'; import { SearchFormComponent } from './search-form/search-form.component'; import { SearchResultGridElementComponent } from '../object-grid/search-result-grid-element/search-result-grid-element.component'; import { ViewModeSwitchComponent } from './view-mode-switch/view-mode-switch.component'; +import { GridThumbnailComponent } from '../object-grid/grid-thumbnail/grid-thumbnail.component'; import { VarDirective } from './utils/var.directive'; const MODULES = [ @@ -78,6 +79,7 @@ const COMPONENTS = [ PaginationComponent, SearchFormComponent, ThumbnailComponent, + GridThumbnailComponent, WrapperListElementComponent, ViewModeSwitchComponent ]; diff --git a/src/styles/_custom_variables.scss b/src/styles/_custom_variables.scss index 12ebfd6618..f52a99f014 100644 --- a/src/styles/_custom_variables.scss +++ b/src/styles/_custom_variables.scss @@ -1,3 +1,3 @@ $content-spacing: $spacer * 1.5; -$button-height: $input-btn-padding-y * 2 + $input-btn-line-height + calculateRem($input-btn-border-width*2); \ No newline at end of file +$button-height: $input-btn-padding-y * 2 + $input-btn-line-height + calculateRem($input-btn-border-width*2); From 7d982ad954f780dcc69a4fb41407bf315e85bd8b Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 2 Nov 2017 13:43:02 +0100 Subject: [PATCH 21/77] #150 Intermediate commit --- .../search-results/search-results.component.ts | 3 ++- .../shared/dso-element-decorator.ts | 17 +++++++++++++++++ .../collection-grid-element.component.ts | 6 ++++-- .../community-grid-element.component.ts | 5 +++-- src/app/object-grid/grid-card-styling.scss | 2 +- src/app/object-grid/grid-element-decorator.ts | 16 ---------------- .../item-grid-element.component.ts | 5 +++-- ...tion-search-result-grid-element.component.ts | 6 ++++-- ...nity-search-result-grid-element.component.ts | 5 +++-- ...item-search-result-grid-element.component.ts | 5 +++-- .../wrapper-grid-element.component.ts | 5 +++-- .../collection-list-element.component.ts | 5 +++-- .../community-list-element.component.ts | 5 +++-- .../item-list-element.component.ts | 5 +++-- src/app/object-list/list-element-decorator.ts | 16 ---------------- src/app/object-list/object-list.component.html | 2 +- ...tion-search-result-list-element.component.ts | 5 +++-- ...nity-search-result-list-element.component.ts | 5 +++-- ...item-search-result-list-element.component.ts | 5 +++-- .../wrapper-list-element.component.ts | 6 +++--- src/styles/_custom_variables.scss | 1 + 21 files changed, 66 insertions(+), 64 deletions(-) create mode 100644 src/app/object-collection/shared/dso-element-decorator.ts delete mode 100644 src/app/object-grid/grid-element-decorator.ts diff --git a/src/app/+search-page/search-results/search-results.component.ts b/src/app/+search-page/search-results/search-results.component.ts index f8b3721630..4b3fec4565 100644 --- a/src/app/+search-page/search-results/search-results.component.ts +++ b/src/app/+search-page/search-results/search-results.component.ts @@ -2,7 +2,7 @@ import { Component, Input } from '@angular/core'; import { RemoteData } from '../../core/data/remote-data'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { fadeIn, fadeInOut } from '../../shared/animations/fade'; -import { SearchOptions } from '../search-options.model'; +import { SearchOptions, ViewMode } from '../search-options.model'; import { SortOptions } from '../../core/cache/models/sort-options.model'; import { SearchResult } from '../search-result.model'; @@ -23,4 +23,5 @@ export class SearchResultsComponent { @Input() searchResults: RemoteData>>; @Input() searchConfig: SearchOptions; @Input() sortConfig: SortOptions; + @Input() viewMode: ViewMode; } diff --git a/src/app/object-collection/shared/dso-element-decorator.ts b/src/app/object-collection/shared/dso-element-decorator.ts new file mode 100644 index 0000000000..310a65f056 --- /dev/null +++ b/src/app/object-collection/shared/dso-element-decorator.ts @@ -0,0 +1,17 @@ +import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { ListableObject } from './listable-object.model'; +import { ViewMode } from '../../+search-page/search-options.model'; + +const dsoElementMap = new Map(); +export function renderElementsFor(listable: GenericConstructor, viewMode : ViewMode) { + return function decorator(objectElement: any) { + if (!objectElement) { + return; + } + dsoElementMap.set(listable+viewMode, objectElement); + }; +} + +export function rendersDSOType(listable: GenericConstructor, viewMode : ViewMode) { + return dsoElementMap.get(listable+viewMode); +} diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts index 80be3d75b3..7e2ae5f468 100644 --- a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts +++ b/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -2,7 +2,9 @@ import { Component, Inject } from '@angular/core'; import { Collection } from '../../core/shared/collection.model'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; -import { gridElementFor } from '../grid-element-decorator'; +import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; + @Component({ selector: 'ds-collection-grid-element', @@ -10,5 +12,5 @@ import { gridElementFor } from '../grid-element-decorator'; templateUrl: './collection-grid-element.component.html' }) -@gridElementFor(Collection) +@renderElementsFor(Collection, ViewMode.Grid) export class CollectionGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.ts b/src/app/object-grid/community-grid-element/community-grid-element.component.ts index e29e037c5d..76ee6736be 100644 --- a/src/app/object-grid/community-grid-element/community-grid-element.component.ts +++ b/src/app/object-grid/community-grid-element/community-grid-element.component.ts @@ -2,7 +2,8 @@ import { Component, Input, Inject } from '@angular/core'; import { Community } from '../../core/shared/community.model'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; -import { gridElementFor} from '../grid-element-decorator'; +import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-community-grid-element', @@ -10,5 +11,5 @@ import { gridElementFor} from '../grid-element-decorator'; templateUrl: './community-grid-element.component.html' }) -@gridElementFor(Community) +@renderElementsFor(Community, ViewMode.Grid) export class CommunityGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/grid-card-styling.scss b/src/app/object-grid/grid-card-styling.scss index 44f4183bfd..b25c603b55 100644 --- a/src/app/object-grid/grid-card-styling.scss +++ b/src/app/object-grid/grid-card-styling.scss @@ -29,7 +29,7 @@ .card{ margin-bottom: $card-block-margin-base *3; - height: 98%; + height: $card-height-percentage; } .card-img-top ::ng-deep img diff --git a/src/app/object-grid/grid-element-decorator.ts b/src/app/object-grid/grid-element-decorator.ts deleted file mode 100644 index cd5ebbcaeb..0000000000 --- a/src/app/object-grid/grid-element-decorator.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { GenericConstructor } from '../core/shared/generic-constructor'; -import { ListableObject } from '../object-collection/shared/listable-object.model'; - -const gridElementMap = new Map(); -export function gridElementFor(gridable: GenericConstructor) { - return function decorator(objectElement: any) { - if (!objectElement) { - return; - } - gridElementMap.set(gridable, objectElement); - }; -} - -export function getGridElementFor(gridable: GenericConstructor) { - return gridElementMap.get(gridable); -} diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.ts b/src/app/object-grid/item-grid-element/item-grid-element.component.ts index c651ccfc9c..e11c51312a 100644 --- a/src/app/object-grid/item-grid-element/item-grid-element.component.ts +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.ts @@ -1,8 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; import { Item } from '../../core/shared/item.model'; -import { gridElementFor } from '../grid-element-decorator'; +import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-item-grid-element', @@ -10,5 +11,5 @@ import { ObjectGridElementComponent } from '../object-grid-element/object-grid-e templateUrl: './item-grid-element.component.html' }) -@gridElementFor(Item) +@renderElementsFor(Item, ViewMode.Grid) export class ItemGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts index aa1d495dba..6c5e526d15 100644 --- a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts @@ -1,9 +1,11 @@ import { Component } from '@angular/core'; -import { gridElementFor } from '../../grid-element-decorator'; +import { renderElementsFor} from '../../../object-collection/shared/dso-element-decorator'; + import { CollectionSearchResult } from './collection-search-result.model'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; import { Collection } from '../../../core/shared/collection.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-search-result-grid-element', @@ -11,5 +13,5 @@ import { Collection } from '../../../core/shared/collection.model'; templateUrl: 'collection-search-result-grid-element.component.html' }) -@gridElementFor(CollectionSearchResult) +@renderElementsFor(CollectionSearchResult, ViewMode.Grid) export class CollectionSearchResultGridElementComponent extends SearchResultGridElementComponent {} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts index 1ce9e1d09a..b6aa4bdb6d 100644 --- a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts @@ -2,8 +2,9 @@ import { Component } from '@angular/core'; import { CommunitySearchResult } from './community-search-result.model'; import { Community } from '../../../core/shared/community.model'; -import { gridElementFor } from '../../grid-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-search-result-grid-element', @@ -11,7 +12,7 @@ import { SearchResultGridElementComponent } from '../search-result-grid-element. templateUrl: 'community-search-result-grid-element.component.html' }) -@gridElementFor(CommunitySearchResult) +@renderElementsFor(CommunitySearchResult, ViewMode.Grid) export class CommunitySearchResultGridElementComponent extends SearchResultGridElementComponent { } diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts index 7a82803c9b..d4989d2efd 100644 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; -import { gridElementFor } from '../../grid-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; import { Item } from '../../../core/shared/item.model'; import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-search-result-grid-element', @@ -11,5 +12,5 @@ import { ItemSearchResult } from '../../../object-collection/shared/item-search- templateUrl: 'item-search-result-grid-element.component.html' }) -@gridElementFor(ItemSearchResult) +@renderElementsFor(ItemSearchResult, ViewMode.Grid) export class ItemSearchResultGridElementComponent extends SearchResultGridElementComponent {} diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts index bd15a0d443..000c826188 100644 --- a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts +++ b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts @@ -1,7 +1,8 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; import { GenericConstructor } from '../../core/shared/generic-constructor'; -import { getGridElementFor } from '../grid-element-decorator'; +import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-wrapper-grid-element', @@ -22,6 +23,6 @@ export class WrapperGridElementComponent implements OnInit { getGridElement(): string { const f: GenericConstructor = this.object.constructor as GenericConstructor; - return getGridElementFor(f); + return rendersDSOType(f, ViewMode.Grid); } } diff --git a/src/app/object-list/collection-list-element/collection-list-element.component.ts b/src/app/object-list/collection-list-element/collection-list-element.component.ts index a99e64a27f..c065a64b72 100644 --- a/src/app/object-list/collection-list-element/collection-list-element.component.ts +++ b/src/app/object-list/collection-list-element/collection-list-element.component.ts @@ -2,7 +2,8 @@ import { Component, Inject } from '@angular/core'; import { Collection } from '../../core/shared/collection.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { listElementFor } from '../list-element-decorator'; +import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-list-element', @@ -10,5 +11,5 @@ import { listElementFor } from '../list-element-decorator'; templateUrl: './collection-list-element.component.html' }) -@listElementFor(Collection) +@renderElementsFor(Collection, ViewMode.List) export class CollectionListElementComponent extends ObjectListElementComponent {} diff --git a/src/app/object-list/community-list-element/community-list-element.component.ts b/src/app/object-list/community-list-element/community-list-element.component.ts index c05915e8d7..11ff392942 100644 --- a/src/app/object-list/community-list-element/community-list-element.component.ts +++ b/src/app/object-list/community-list-element/community-list-element.component.ts @@ -2,7 +2,8 @@ import { Component, Input, Inject } from '@angular/core'; import { Community } from '../../core/shared/community.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { listElementFor } from '../list-element-decorator'; +import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-community-list-element', @@ -10,5 +11,5 @@ import { listElementFor } from '../list-element-decorator'; templateUrl: './community-list-element.component.html' }) -@listElementFor(Community) +@renderElementsFor(Community, ViewMode.List) export class CommunityListElementComponent extends ObjectListElementComponent {} diff --git a/src/app/object-list/item-list-element/item-list-element.component.ts b/src/app/object-list/item-list-element/item-list-element.component.ts index cc6c837bb7..bdc5733dcd 100644 --- a/src/app/object-list/item-list-element/item-list-element.component.ts +++ b/src/app/object-list/item-list-element/item-list-element.component.ts @@ -2,7 +2,8 @@ import { Component, Input, Inject } from '@angular/core'; import { Item } from '../../core/shared/item.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { listElementFor } from '../list-element-decorator'; +import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-item-list-element', @@ -10,5 +11,5 @@ import { listElementFor } from '../list-element-decorator'; templateUrl: './item-list-element.component.html' }) -@listElementFor(Item) +@renderElementsFor(Item, ViewMode.List) export class ItemListElementComponent extends ObjectListElementComponent {} diff --git a/src/app/object-list/list-element-decorator.ts b/src/app/object-list/list-element-decorator.ts index aa044755ea..e69de29bb2 100644 --- a/src/app/object-list/list-element-decorator.ts +++ b/src/app/object-list/list-element-decorator.ts @@ -1,16 +0,0 @@ -import { GenericConstructor } from '../core/shared/generic-constructor'; -import { ListableObject } from '../object-collection/shared/listable-object.model'; - -const listElementMap = new Map(); -export function listElementFor(listable: GenericConstructor) { - return function decorator(objectElement: any) { - if (!objectElement) { - return; - } - listElementMap.set(listable, objectElement); - }; -} - -export function getListElementFor(listable: GenericConstructor) { - return listElementMap.get(listable); -} diff --git a/src/app/object-list/object-list.component.html b/src/app/object-list/object-list.component.html index b97524d58c..0178533bda 100644 --- a/src/app/object-list/object-list.component.html +++ b/src/app/object-list/object-list.component.html @@ -12,7 +12,7 @@ (paginationChange)="onPaginationChange($event)">
      • - +
      diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts index 9bea14e9a1..1b5d7ef0ba 100644 --- a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; -import { listElementFor } from '../../list-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { CollectionSearchResult } from './collection-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; import { Collection } from '../../../core/shared/collection.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-search-result-list-element', @@ -11,5 +12,5 @@ import { Collection } from '../../../core/shared/collection.model'; templateUrl: 'collection-search-result-list-element.component.html' }) -@listElementFor(CollectionSearchResult) +@renderElementsFor(CollectionSearchResult, ViewMode.List) export class CollectionSearchResultListElementComponent extends SearchResultListElementComponent {} diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts index 741b4b4f65..d9ab001f58 100644 --- a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; -import { listElementFor } from '../../list-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { CommunitySearchResult } from './community-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; import { Community } from '../../../core/shared/community.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-search-result-list-element', @@ -11,7 +12,7 @@ import { Community } from '../../../core/shared/community.model'; templateUrl: 'community-search-result-list-element.component.html' }) -@listElementFor(CommunitySearchResult) +@renderElementsFor(CommunitySearchResult, ViewMode.List) export class CommunitySearchResultListElementComponent extends SearchResultListElementComponent { } diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts index 2974a87883..929233f1a3 100644 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; -import { listElementFor } from '../../list-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; import { Item } from '../../../core/shared/item.model'; import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-search-result-list-element', @@ -11,5 +12,5 @@ import { ItemSearchResult } from '../../../object-collection/shared/item-search- templateUrl: 'item-search-result-list-element.component.html' }) -@listElementFor(ItemSearchResult) +@renderElementsFor(ItemSearchResult, ViewMode.List) export class ItemSearchResultListElementComponent extends SearchResultListElementComponent {} diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts index 2e1184b023..ff5591442d 100644 --- a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts +++ b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts @@ -1,7 +1,8 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; -import { getListElementFor } from '../list-element-decorator' +import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator' import { GenericConstructor } from '../../core/shared/generic-constructor'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-wrapper-list-element', @@ -17,11 +18,10 @@ export class WrapperListElementComponent implements OnInit { ngOnInit(): void { this.objectInjector = ReflectiveInjector.resolveAndCreate( [{provide: 'objectElementProvider', useFactory: () => (this.object) }], this.injector); - } getListElement(): string { const f: GenericConstructor = this.object.constructor as GenericConstructor; - return getListElementFor(f); + return rendersDSOType(f, ViewMode.List); } } diff --git a/src/styles/_custom_variables.scss b/src/styles/_custom_variables.scss index f52a99f014..8c0dcae928 100644 --- a/src/styles/_custom_variables.scss +++ b/src/styles/_custom_variables.scss @@ -1,3 +1,4 @@ $content-spacing: $spacer * 1.5; $button-height: $input-btn-padding-y * 2 + $input-btn-line-height + calculateRem($input-btn-border-width*2); +$card-height-percentage:98%; From 727353988fd0870f269509e1908437c9d8ad54fa Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 3 Nov 2017 14:46:33 +0100 Subject: [PATCH 22/77] #150 Safety-commit before moving to "shared" package --- dspace-angular.iml | 8 +++ .../object-collection.component.spec.ts | 52 +++++++++++++++++++ .../shared/dso-element-decorator.spec.ts | 16 ++++++ .../collection-grid-element.component.spec.ts | 0 .../grid-thumbnail.component.spec.ts | 10 ++-- .../item-grid-element.component.spec.ts | 6 +++ .../object-grid/object-grid.component.spec.ts | 0 .../wrapper-grid-element.component.spec.ts | 0 8 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 dspace-angular.iml create mode 100644 src/app/object-collection/object-collection.component.spec.ts create mode 100644 src/app/object-collection/shared/dso-element-decorator.spec.ts create mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts create mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts create mode 100644 src/app/object-grid/object-grid.component.spec.ts create mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts diff --git a/dspace-angular.iml b/dspace-angular.iml new file mode 100644 index 0000000000..5806390693 --- /dev/null +++ b/dspace-angular.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/app/object-collection/object-collection.component.spec.ts b/src/app/object-collection/object-collection.component.spec.ts new file mode 100644 index 0000000000..abbf66e4f1 --- /dev/null +++ b/src/app/object-collection/object-collection.component.spec.ts @@ -0,0 +1,52 @@ +import { ObjectCollectionComponent } from './object-collection.component'; +import { ViewMode } from '../+search-page/search-options.model'; +import { element } from 'protractor'; +import { By } from '@angular/platform-browser'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Config } from '../../config/config.interface'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; +import { RouterStub } from '../shared/testing/router-stub'; + +describe('ObjectCollectionComponent', () => { + let fixture: ComponentFixture; + let objectCollectionComponent: ObjectCollectionComponent; + const queryParam = 'test query'; + const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; + const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) + }; + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ObjectCollectionComponent ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub } + ], + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(ObjectCollectionComponent); + objectCollectionComponent = fixture.componentInstance; + })); + it('should only show the grid component when the viewmode is set to grid', () => { + objectCollectionComponent.currentMode = ViewMode.Grid; + + // expect(By.css('ds-object-grid')).toEqual(1); + // expect(By.css('ds-object-list')).toEqual(0); + }); + + it('should only show the list component when the viewmode is set to list', () => { + objectCollectionComponent.currentMode = ViewMode.List; + + // expect(By.css('ds-object-list').length).toEqual(1); + // expect(By.css('ds-object-grid').length).toEqual(0); + }) + +}); diff --git a/src/app/object-collection/shared/dso-element-decorator.spec.ts b/src/app/object-collection/shared/dso-element-decorator.spec.ts new file mode 100644 index 0000000000..952afb9ac3 --- /dev/null +++ b/src/app/object-collection/shared/dso-element-decorator.spec.ts @@ -0,0 +1,16 @@ +import { ViewMode } from '../../+search-page/search-options.model'; +import { renderElementsFor } from './dso-element-decorator'; +import { Item } from '../../core/shared/item.model'; + +describe('ElementDecorator', () => { + let gridDecorator = renderElementsFor(Item, ViewMode.Grid); + let listDecorator = renderElementsFor(Item, ViewMode.List); + it('should have a decorator for both list and grid', () => { + expect(listDecorator.length).not.toBeNull(); + expect(gridDecorator.length).not.toBeNull(); + }); + it('should have 2 separate decorators for grid and list', () => { + expect(listDecorator).not.toEqual(gridDecorator); + }); + +}); diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts index f4ca434221..209ac52997 100644 --- a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts @@ -2,24 +2,24 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; -import { ThumbnailComponent } from './thumbnail.component'; +import { GridThumbnailComponent } from './grid-thumbnail.component'; import { Bitstream } from '../../core/shared/bitstream.model'; import { SafeUrlPipe } from '../../shared/utils/safe-url-pipe'; describe('ThumbnailComponent', () => { - let comp: ThumbnailComponent; - let fixture: ComponentFixture; + let comp: GridThumbnailComponent; + let fixture: ComponentFixture; let de: DebugElement; let el: HTMLElement; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ThumbnailComponent, SafeUrlPipe] + declarations: [GridThumbnailComponent, SafeUrlPipe] }).compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(ThumbnailComponent); + fixture = TestBed.createComponent(GridThumbnailComponent); comp = fixture.componentInstance; // BannerComponent test instance de = fixture.debugElement.query(By.css('div.thumbnail')); el = de.nativeElement; diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts new file mode 100644 index 0000000000..0da99aa697 --- /dev/null +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts @@ -0,0 +1,6 @@ +import { ItemGridElementComponent } from './item-grid-element.component'; + +describe('ItemGridElementComponent',()=>{ + let itemGridElementComponent: ItemGridElementComponent; + +}) diff --git a/src/app/object-grid/object-grid.component.spec.ts b/src/app/object-grid/object-grid.component.spec.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts new file mode 100644 index 0000000000..e69de29bb2 From 7adfa5b5fb6d0ba4f7c83016b718cc8cf1d7cbf7 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 3 Nov 2017 15:02:01 +0100 Subject: [PATCH 23/77] #150 Moved list,grid and object-collection to shared package --- src/app/+search-page/search-page.module.ts | 12 +++---- src/app/+search-page/search-result.model.ts | 2 +- .../search-service/search.service.ts | 1 + src/app/core/shared/dspace-object.model.ts | 2 +- .../object-collection.component.scss | 1 - .../shared/item-search-result.model.ts | 5 --- .../collection-grid-element.component.scss | 2 -- .../community-grid-element.component.scss | 2 -- .../grid-thumbnail.component.scss | 1 - .../item-grid-element.component.scss | 2 -- .../object-grid-element.component.scss | 6 ---- .../object-grid/object-grid.component.scss | 1 - ...-search-result-grid-element.component.scss | 2 -- .../collection-search-result.model.ts | 5 --- ...-search-result-grid-element.component.scss | 2 -- .../community-search-result.model.ts | 5 --- ...-search-result-grid-element.component.scss | 2 -- .../wrapper-grid-element.component.scss | 2 -- .../collection-list-element.component.scss | 1 - .../community-list-element.component.scss | 1 - .../item-list-element.component.scss | 1 - .../object-list/object-list.component.scss | 1 - ...-search-result-list-element.component.scss | 1 - .../collection-search-result.model.ts | 5 --- ...-search-result-list-element.component.scss | 1 - .../community-search-result.model.ts | 5 --- ...-search-result-list-element.component.scss | 1 - .../wrapper-list-element.component.scss | 2 -- .../object-collection.component.html | 0 .../object-collection.component.scss | 1 + .../object-collection.component.spec.ts | 6 ++-- .../object-collection.component.ts | 12 +++---- .../shared/dso-element-decorator.spec.ts | 4 +-- .../shared/dso-element-decorator.ts | 4 +-- .../shared/item-search-result.model.ts | 5 +++ .../shared/listable-object.model.ts | 0 .../collection-grid-element.component.html | 0 .../collection-grid-element.component.scss | 2 ++ .../collection-grid-element.component.spec.ts | 0 .../collection-grid-element.component.ts | 4 +-- .../community-grid-element.component.html | 0 .../community-grid-element.component.scss | 2 ++ .../community-grid-element.component.ts | 4 +-- .../object-grid/grid-card-styling.scss | 2 +- .../grid-thumbnail.component.html | 0 .../grid-thumbnail.component.scss | 1 + .../grid-thumbnail.component.spec.ts | 4 +-- .../grid-thumbnail.component.ts | 2 +- .../item-grid-element.component.html | 0 .../item-grid-element.component.scss | 2 ++ .../item-grid-element.component.spec.ts | 0 .../item-grid-element.component.ts | 4 +-- .../object-grid-element.component.html | 0 .../object-grid-element.component.scss | 6 ++++ .../object-grid-element.component.ts | 0 .../object-grid/object-grid.component.html | 0 .../object-grid/object-grid.component.scss | 1 + .../object-grid/object-grid.component.spec.ts | 0 .../object-grid/object-grid.component.ts | 10 +++--- ...-search-result-grid-element.component.html | 0 ...-search-result-grid-element.component.scss | 2 ++ ...on-search-result-grid-element.component.ts | 4 +-- .../collection-search-result.model.ts | 5 +++ ...-search-result-grid-element.component.html | 0 ...-search-result-grid-element.component.scss | 2 ++ ...ty-search-result-grid-element.component.ts | 4 +-- .../community-search-result.model.ts | 5 +++ ...-search-result-grid-element.component.html | 0 ...-search-result-grid-element.component.scss | 2 ++ ...em-search-result-grid-element.component.ts | 4 +-- .../search-result-grid-element.component.scss | 4 +-- .../search-result-grid-element.component.ts | 8 ++--- .../wrapper-grid-element.component.html | 0 .../wrapper-grid-element.component.scss | 2 ++ .../wrapper-grid-element.component.spec.ts | 0 .../wrapper-grid-element.component.ts | 4 +-- .../collection-list-element.component.html | 0 .../collection-list-element.component.scss | 1 + .../collection-list-element.component.ts | 4 +-- .../community-list-element.component.html | 0 .../community-list-element.component.scss | 1 + .../community-list-element.component.ts | 4 +-- .../item-list-element.component.html | 0 .../item-list-element.component.scss | 1 + .../item-list-element.component.ts | 4 +-- .../object-list-element.component.html | 0 .../object-list-element.component.scss | 2 +- .../object-list-element.component.ts | 0 .../object-list/object-list.component.html | 0 .../object-list/object-list.component.scss | 1 + .../object-list/object-list.component.ts | 11 +++++-- ...-search-result-list-element.component.html | 0 ...-search-result-list-element.component.scss | 1 + ...on-search-result-list-element.component.ts | 4 +-- .../collection-search-result.model.ts | 5 +++ ...-search-result-list-element.component.html | 0 ...-search-result-list-element.component.scss | 1 + ...ty-search-result-list-element.component.ts | 4 +-- .../community-search-result.model.ts | 5 +++ ...-search-result-list-element.component.html | 0 ...-search-result-list-element.component.scss | 1 + ...em-search-result-list-element.component.ts | 4 +-- .../search-result-list-element.component.scss | 4 +-- .../search-result-list-element.component.ts | 8 ++--- .../wrapper-list-element.component.html | 0 .../wrapper-list-element.component.scss | 2 ++ .../wrapper-list-element.component.ts | 4 +-- src/app/shared/shared.module.ts | 32 +++++++++---------- 108 files changed, 153 insertions(+), 147 deletions(-) delete mode 100644 src/app/object-collection/object-collection.component.scss delete mode 100644 src/app/object-collection/shared/item-search-result.model.ts delete mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.scss delete mode 100644 src/app/object-grid/community-grid-element/community-grid-element.component.scss delete mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss delete mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.scss delete mode 100644 src/app/object-grid/object-grid-element/object-grid-element.component.scss delete mode 100644 src/app/object-grid/object-grid.component.scss delete mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss delete mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts delete mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss delete mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts delete mode 100644 src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss delete mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss delete mode 100644 src/app/object-list/collection-list-element/collection-list-element.component.scss delete mode 100644 src/app/object-list/community-list-element/community-list-element.component.scss delete mode 100644 src/app/object-list/item-list-element/item-list-element.component.scss delete mode 100644 src/app/object-list/object-list.component.scss delete mode 100644 src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss delete mode 100644 src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts delete mode 100644 src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss delete mode 100644 src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts delete mode 100644 src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss delete mode 100644 src/app/object-list/wrapper-list-element/wrapper-list-element.component.scss rename src/app/{ => shared}/object-collection/object-collection.component.html (100%) create mode 100644 src/app/shared/object-collection/object-collection.component.scss rename src/app/{ => shared}/object-collection/object-collection.component.spec.ts (90%) rename src/app/{ => shared}/object-collection/object-collection.component.ts (87%) rename src/app/{ => shared}/object-collection/shared/dso-element-decorator.spec.ts (80%) rename src/app/{ => shared}/object-collection/shared/dso-element-decorator.ts (77%) create mode 100644 src/app/shared/object-collection/shared/item-search-result.model.ts rename src/app/{ => shared}/object-collection/shared/listable-object.model.ts (100%) rename src/app/{ => shared}/object-grid/collection-grid-element/collection-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss rename src/app/{ => shared}/object-grid/collection-grid-element/collection-grid-element.component.spec.ts (100%) rename src/app/{ => shared}/object-grid/collection-grid-element/collection-grid-element.component.ts (80%) rename src/app/{ => shared}/object-grid/community-grid-element/community-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss rename src/app/{ => shared}/object-grid/community-grid-element/community-grid-element.component.ts (80%) rename src/app/{ => shared}/object-grid/grid-card-styling.scss (94%) rename src/app/{ => shared}/object-grid/grid-thumbnail/grid-thumbnail.component.html (100%) create mode 100644 src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.scss rename src/app/{ => shared}/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts (91%) rename src/app/{ => shared}/object-grid/grid-thumbnail/grid-thumbnail.component.ts (95%) rename src/app/{ => shared}/object-grid/item-grid-element/item-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss rename src/app/{ => shared}/object-grid/item-grid-element/item-grid-element.component.spec.ts (100%) rename src/app/{ => shared}/object-grid/item-grid-element/item-grid-element.component.ts (80%) rename src/app/{ => shared}/object-grid/object-grid-element/object-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss rename src/app/{ => shared}/object-grid/object-grid-element/object-grid-element.component.ts (100%) rename src/app/{ => shared}/object-grid/object-grid.component.html (100%) create mode 100644 src/app/shared/object-grid/object-grid.component.scss rename src/app/{ => shared}/object-grid/object-grid.component.spec.ts (100%) rename src/app/{ => shared}/object-grid/object-grid.component.ts (88%) rename src/app/{ => shared}/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss rename src/app/{ => shared}/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts (84%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts rename src/app/{ => shared}/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss rename src/app/{ => shared}/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts (84%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts rename src/app/{ => shared}/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss rename src/app/{ => shared}/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts (84%) rename src/app/{ => shared}/object-grid/search-result-grid-element/search-result-grid-element.component.scss (51%) rename src/app/{ => shared}/object-grid/search-result-grid-element/search-result-grid-element.component.ts (83%) rename src/app/{ => shared}/object-grid/wrapper-grid-element/wrapper-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss rename src/app/{ => shared}/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts (100%) rename src/app/{ => shared}/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts (86%) rename src/app/{ => shared}/object-list/collection-list-element/collection-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/collection-list-element/collection-list-element.component.scss rename src/app/{ => shared}/object-list/collection-list-element/collection-list-element.component.ts (80%) rename src/app/{ => shared}/object-list/community-list-element/community-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/community-list-element/community-list-element.component.scss rename src/app/{ => shared}/object-list/community-list-element/community-list-element.component.ts (80%) rename src/app/{ => shared}/object-list/item-list-element/item-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/item-list-element/item-list-element.component.scss rename src/app/{ => shared}/object-list/item-list-element/item-list-element.component.ts (80%) rename src/app/{ => shared}/object-list/object-list-element/object-list-element.component.html (100%) rename src/app/{ => shared}/object-list/object-list-element/object-list-element.component.scss (56%) rename src/app/{ => shared}/object-list/object-list-element/object-list-element.component.ts (100%) rename src/app/{ => shared}/object-list/object-list.component.html (100%) create mode 100644 src/app/shared/object-list/object-list.component.scss rename src/app/{ => shared}/object-list/object-list.component.ts (90%) rename src/app/{ => shared}/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss rename src/app/{ => shared}/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts (84%) create mode 100644 src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts rename src/app/{ => shared}/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss rename src/app/{ => shared}/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts (84%) create mode 100644 src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result.model.ts rename src/app/{ => shared}/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss rename src/app/{ => shared}/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts (84%) rename src/app/{ => shared}/object-list/search-result-list-element/search-result-list-element.component.scss (67%) rename src/app/{ => shared}/object-list/search-result-list-element/search-result-list-element.component.ts (83%) rename src/app/{ => shared}/object-list/wrapper-list-element/wrapper-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.scss rename src/app/{ => shared}/object-list/wrapper-list-element/wrapper-list-element.component.ts (86%) diff --git a/src/app/+search-page/search-page.module.ts b/src/app/+search-page/search-page.module.ts index be99a0eae4..7c2001c909 100644 --- a/src/app/+search-page/search-page.module.ts +++ b/src/app/+search-page/search-page.module.ts @@ -4,12 +4,12 @@ import { SharedModule } from '../shared/shared.module'; import { SearchPageRoutingModule } from './search-page-routing.module'; import { SearchPageComponent } from './search-page.component'; import { SearchResultsComponent } from './search-results/search-results.component'; -import { ItemSearchResultListElementComponent } from '../object-list/search-result-list-element/item-search-result/item-search-result-list-element.component'; -import { CollectionSearchResultListElementComponent } from '../object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component'; -import { CommunitySearchResultListElementComponent } from '../object-list/search-result-list-element/community-search-result/community-search-result-list-element.component'; -import { ItemSearchResultGridElementComponent } from '../object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component'; -import { CommunitySearchResultGridElementComponent } from '../object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component' -import { CollectionSearchResultGridElementComponent } from '../object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component'; +import { ItemSearchResultListElementComponent } from '../shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component'; +import { CollectionSearchResultListElementComponent } from '../shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component'; +import { CommunitySearchResultListElementComponent } from '../shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component'; +import { ItemSearchResultGridElementComponent } from '../shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component'; +import { CommunitySearchResultGridElementComponent } from '../shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component' +import { CollectionSearchResultGridElementComponent } from '../shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component'; import { SearchService } from './search-service/search.service'; import { SearchSidebarComponent } from './search-sidebar/search-sidebar.component'; import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; diff --git a/src/app/+search-page/search-result.model.ts b/src/app/+search-page/search-result.model.ts index 602d8ac9c2..cc2bd8cd58 100644 --- a/src/app/+search-page/search-result.model.ts +++ b/src/app/+search-page/search-result.model.ts @@ -1,6 +1,6 @@ import { DSpaceObject } from '../core/shared/dspace-object.model'; import { Metadatum } from '../core/shared/metadatum.model'; -import { ListableObject } from '../object-collection/shared/listable-object.model'; +import { ListableObject } from '../shared/object-collection/shared/listable-object.model'; export class SearchResult implements ListableObject { diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 5258756bfb..63b1b04dce 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -15,6 +15,7 @@ import { FacetValue } from './facet-value.model'; import { ItemSearchResult } from '../../object-collection/shared/item-search-result.model'; import { ViewMode } from '../../+search-page/search-options.model'; import { Router, NavigationExtras, ActivatedRoute } from '@angular/router'; +import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; import { RouteService } from '../../shared/route.service'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; import { SortOptions } from '../../core/cache/models/sort-options.model'; diff --git a/src/app/core/shared/dspace-object.model.ts b/src/app/core/shared/dspace-object.model.ts index a17a6b31ce..8f96f2485a 100644 --- a/src/app/core/shared/dspace-object.model.ts +++ b/src/app/core/shared/dspace-object.model.ts @@ -3,7 +3,7 @@ import { isEmpty, isNotEmpty } from '../../shared/empty.util'; import { CacheableObject } from '../cache/object-cache.reducer'; import { RemoteData } from '../data/remote-data'; import { ResourceType } from './resource-type'; -import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { ListableObject } from '../../shared/object-collection/shared/listable-object.model'; import { Observable } from 'rxjs/Observable'; /** diff --git a/src/app/object-collection/object-collection.component.scss b/src/app/object-collection/object-collection.component.scss deleted file mode 100644 index da97dd7a62..0000000000 --- a/src/app/object-collection/object-collection.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../styles/variables.scss'; diff --git a/src/app/object-collection/shared/item-search-result.model.ts b/src/app/object-collection/shared/item-search-result.model.ts deleted file mode 100644 index 75d56a2488..0000000000 --- a/src/app/object-collection/shared/item-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../+search-page/search-result.model'; -import { Item } from '../../core/shared/item.model'; - -export class ItemSearchResult extends SearchResult { -} diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss b/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss deleted file mode 100644 index 48e2b121d4..0000000000 --- a/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.scss b/src/app/object-grid/community-grid-element/community-grid-element.component.scss deleted file mode 100644 index 48e2b121d4..0000000000 --- a/src/app/object-grid/community-grid-element/community-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss deleted file mode 100644 index 50be6f5ad0..0000000000 --- a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../styles/variables.scss'; diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.scss b/src/app/object-grid/item-grid-element/item-grid-element.component.scss deleted file mode 100644 index 48e2b121d4..0000000000 --- a/src/app/object-grid/item-grid-element/item-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/object-grid/object-grid-element/object-grid-element.component.scss deleted file mode 100644 index 0351acf15f..0000000000 --- a/src/app/object-grid/object-grid-element/object-grid-element.component.scss +++ /dev/null @@ -1,6 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; -:host { - display: block; - margin-bottom: $spacer; -} diff --git a/src/app/object-grid/object-grid.component.scss b/src/app/object-grid/object-grid.component.scss deleted file mode 100644 index da97dd7a62..0000000000 --- a/src/app/object-grid/object-grid.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../styles/variables.scss'; diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss deleted file mode 100644 index 790f794381..0000000000 --- a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../../styles/variables.scss'; -@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts deleted file mode 100644 index fa7945dedd..0000000000 --- a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Collection } from '../../../core/shared/collection.model'; - -export class CollectionSearchResult extends SearchResult { -} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss deleted file mode 100644 index 790f794381..0000000000 --- a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../../styles/variables.scss'; -@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts deleted file mode 100644 index 79ea34b6cd..0000000000 --- a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Community } from '../../../core/shared/community.model'; - -export class CommunitySearchResult extends SearchResult { -} diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss deleted file mode 100644 index 790f794381..0000000000 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../../styles/variables.scss'; -@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss deleted file mode 100644 index 48e2b121d4..0000000000 --- a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; diff --git a/src/app/object-list/collection-list-element/collection-list-element.component.scss b/src/app/object-list/collection-list-element/collection-list-element.component.scss deleted file mode 100644 index ad84b72f8c..0000000000 --- a/src/app/object-list/collection-list-element/collection-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/community-list-element/community-list-element.component.scss b/src/app/object-list/community-list-element/community-list-element.component.scss deleted file mode 100644 index ad84b72f8c..0000000000 --- a/src/app/object-list/community-list-element/community-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/item-list-element/item-list-element.component.scss b/src/app/object-list/item-list-element/item-list-element.component.scss deleted file mode 100644 index ad84b72f8c..0000000000 --- a/src/app/object-list/item-list-element/item-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/object-list.component.scss b/src/app/object-list/object-list.component.scss deleted file mode 100644 index b14c7376e3..0000000000 --- a/src/app/object-list/object-list.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss deleted file mode 100644 index 88eb98509a..0000000000 --- a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts deleted file mode 100644 index fa7945dedd..0000000000 --- a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Collection } from '../../../core/shared/collection.model'; - -export class CollectionSearchResult extends SearchResult { -} diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss deleted file mode 100644 index 88eb98509a..0000000000 --- a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts b/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts deleted file mode 100644 index 79ea34b6cd..0000000000 --- a/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Community } from '../../../core/shared/community.model'; - -export class CommunitySearchResult extends SearchResult { -} diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss deleted file mode 100644 index 88eb98509a..0000000000 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.scss b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.scss deleted file mode 100644 index 6f997644cc..0000000000 --- a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; - diff --git a/src/app/object-collection/object-collection.component.html b/src/app/shared/object-collection/object-collection.component.html similarity index 100% rename from src/app/object-collection/object-collection.component.html rename to src/app/shared/object-collection/object-collection.component.html diff --git a/src/app/shared/object-collection/object-collection.component.scss b/src/app/shared/object-collection/object-collection.component.scss new file mode 100644 index 0000000000..48e6526dff --- /dev/null +++ b/src/app/shared/object-collection/object-collection.component.scss @@ -0,0 +1 @@ +@import '../../../styles/variables'; diff --git a/src/app/object-collection/object-collection.component.spec.ts b/src/app/shared/object-collection/object-collection.component.spec.ts similarity index 90% rename from src/app/object-collection/object-collection.component.spec.ts rename to src/app/shared/object-collection/object-collection.component.spec.ts index abbf66e4f1..a56a3e56dc 100644 --- a/src/app/object-collection/object-collection.component.spec.ts +++ b/src/app/shared/object-collection/object-collection.component.spec.ts @@ -1,13 +1,13 @@ import { ObjectCollectionComponent } from './object-collection.component'; -import { ViewMode } from '../+search-page/search-options.model'; +import { ViewMode } from '../../+search-page/search-options.model'; import { element } from 'protractor'; import { By } from '@angular/platform-browser'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { Config } from '../../config/config.interface'; +import { Config } from '../../../config/config.interface'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; -import { RouterStub } from '../shared/testing/router-stub'; +import { RouterStub } from '../testing/router-stub'; describe('ObjectCollectionComponent', () => { let fixture: ComponentFixture; diff --git a/src/app/object-collection/object-collection.component.ts b/src/app/shared/object-collection/object-collection.component.ts similarity index 87% rename from src/app/object-collection/object-collection.component.ts rename to src/app/shared/object-collection/object-collection.component.ts index a79653d970..8d5a9ce3c7 100644 --- a/src/app/object-collection/object-collection.component.ts +++ b/src/app/shared/object-collection/object-collection.component.ts @@ -6,16 +6,16 @@ import { ActivatedRoute, Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; -import { RemoteData } from '../core/data/remote-data'; -import { PageInfo } from '../core/shared/page-info.model'; +import { RemoteData } from '../../core/data/remote-data'; +import { PageInfo } from '../../core/shared/page-info.model'; -import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; +import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; -import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { ListableObject } from './shared/listable-object.model'; -import { ViewMode } from '../+search-page/search-options.model'; -import { hasValue, isNotEmpty } from '../shared/empty.util'; +import { ViewMode } from '../../+search-page/search-options.model'; +import { hasValue, isNotEmpty } from '../empty.util'; @Component({ selector: 'ds-viewable-collection', diff --git a/src/app/object-collection/shared/dso-element-decorator.spec.ts b/src/app/shared/object-collection/shared/dso-element-decorator.spec.ts similarity index 80% rename from src/app/object-collection/shared/dso-element-decorator.spec.ts rename to src/app/shared/object-collection/shared/dso-element-decorator.spec.ts index 952afb9ac3..b4b27bb52a 100644 --- a/src/app/object-collection/shared/dso-element-decorator.spec.ts +++ b/src/app/shared/object-collection/shared/dso-element-decorator.spec.ts @@ -1,6 +1,6 @@ -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; import { renderElementsFor } from './dso-element-decorator'; -import { Item } from '../../core/shared/item.model'; +import { Item } from '../../../core/shared/item.model'; describe('ElementDecorator', () => { let gridDecorator = renderElementsFor(Item, ViewMode.Grid); diff --git a/src/app/object-collection/shared/dso-element-decorator.ts b/src/app/shared/object-collection/shared/dso-element-decorator.ts similarity index 77% rename from src/app/object-collection/shared/dso-element-decorator.ts rename to src/app/shared/object-collection/shared/dso-element-decorator.ts index 310a65f056..5dc085d3a7 100644 --- a/src/app/object-collection/shared/dso-element-decorator.ts +++ b/src/app/shared/object-collection/shared/dso-element-decorator.ts @@ -1,6 +1,6 @@ -import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { ListableObject } from './listable-object.model'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; const dsoElementMap = new Map(); export function renderElementsFor(listable: GenericConstructor, viewMode : ViewMode) { diff --git a/src/app/shared/object-collection/shared/item-search-result.model.ts b/src/app/shared/object-collection/shared/item-search-result.model.ts new file mode 100644 index 0000000000..d9af3539a0 --- /dev/null +++ b/src/app/shared/object-collection/shared/item-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../+search-page/search-result.model'; +import { Item } from '../../../core/shared/item.model'; + +export class ItemSearchResult extends SearchResult { +} diff --git a/src/app/object-collection/shared/listable-object.model.ts b/src/app/shared/object-collection/shared/listable-object.model.ts similarity index 100% rename from src/app/object-collection/shared/listable-object.model.ts rename to src/app/shared/object-collection/shared/listable-object.model.ts diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.html b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html similarity index 100% rename from src/app/object-grid/collection-grid-element/collection-grid-element.component.html rename to src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss new file mode 100644 index 0000000000..946c8a6a31 --- /dev/null +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts similarity index 100% rename from src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts rename to src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts similarity index 80% rename from src/app/object-grid/collection-grid-element/collection-grid-element.component.ts rename to src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts index 7e2ae5f468..09aadab15e 100644 --- a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; -import { Collection } from '../../core/shared/collection.model'; +import { Collection } from '../../../core/shared/collection.model'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.html b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html similarity index 100% rename from src/app/object-grid/community-grid-element/community-grid-element.component.html rename to src/app/shared/object-grid/community-grid-element/community-grid-element.component.html diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss new file mode 100644 index 0000000000..946c8a6a31 --- /dev/null +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts similarity index 80% rename from src/app/object-grid/community-grid-element/community-grid-element.component.ts rename to src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts index 76ee6736be..d40bd717a4 100644 --- a/src/app/object-grid/community-grid-element/community-grid-element.component.ts +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; -import { Community } from '../../core/shared/community.model'; +import { Community } from '../../../core/shared/community.model'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-grid-element', diff --git a/src/app/object-grid/grid-card-styling.scss b/src/app/shared/object-grid/grid-card-styling.scss similarity index 94% rename from src/app/object-grid/grid-card-styling.scss rename to src/app/shared/object-grid/grid-card-styling.scss index b25c603b55..2fe199d1ce 100644 --- a/src/app/object-grid/grid-card-styling.scss +++ b/src/app/shared/object-grid/grid-card-styling.scss @@ -1,4 +1,4 @@ -@import '../../styles/custom_variables'; +@import '../../../styles/custom_variables'; .card-title{ line-height: $line-height-base; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html similarity index 100% rename from src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html rename to src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html diff --git a/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.scss b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.scss new file mode 100644 index 0000000000..45a533cd01 --- /dev/null +++ b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.scss @@ -0,0 +1 @@ +@import '../../../../styles/variables'; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts similarity index 91% rename from src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts rename to src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts index 209ac52997..2d2bd6305a 100644 --- a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts +++ b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts @@ -3,8 +3,8 @@ import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; import { GridThumbnailComponent } from './grid-thumbnail.component'; -import { Bitstream } from '../../core/shared/bitstream.model'; -import { SafeUrlPipe } from '../../shared/utils/safe-url-pipe'; +import { Bitstream } from '../../../core/shared/bitstream.model'; +import { SafeUrlPipe } from '../../utils/safe-url-pipe'; describe('ThumbnailComponent', () => { let comp: GridThumbnailComponent; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts similarity index 95% rename from src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts rename to src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts index 7baa47b39e..8ca93470da 100644 --- a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts +++ b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts @@ -1,5 +1,5 @@ import { Component, Input } from '@angular/core'; -import { Bitstream } from '../../core/shared/bitstream.model'; +import { Bitstream } from '../../../core/shared/bitstream.model'; /** * This component renders a given Bitstream as a thumbnail. diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.html b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html similarity index 100% rename from src/app/object-grid/item-grid-element/item-grid-element.component.html rename to src/app/shared/object-grid/item-grid-element/item-grid-element.component.html diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss new file mode 100644 index 0000000000..946c8a6a31 --- /dev/null +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts similarity index 100% rename from src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts rename to src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts similarity index 80% rename from src/app/object-grid/item-grid-element/item-grid-element.component.ts rename to src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts index e11c51312a..c41a6c9352 100644 --- a/src/app/object-grid/item-grid-element/item-grid-element.component.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; -import { Item } from '../../core/shared/item.model'; +import { Item } from '../../../core/shared/item.model'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-grid-element', diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.html b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.html similarity index 100% rename from src/app/object-grid/object-grid-element/object-grid-element.component.html rename to src/app/shared/object-grid/object-grid-element/object-grid-element.component.html diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss new file mode 100644 index 0000000000..d299edd0ab --- /dev/null +++ b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss @@ -0,0 +1,6 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; +:host { + display: block; + margin-bottom: $spacer; +} diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.ts b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts similarity index 100% rename from src/app/object-grid/object-grid-element/object-grid-element.component.ts rename to src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts diff --git a/src/app/object-grid/object-grid.component.html b/src/app/shared/object-grid/object-grid.component.html similarity index 100% rename from src/app/object-grid/object-grid.component.html rename to src/app/shared/object-grid/object-grid.component.html diff --git a/src/app/shared/object-grid/object-grid.component.scss b/src/app/shared/object-grid/object-grid.component.scss new file mode 100644 index 0000000000..48e6526dff --- /dev/null +++ b/src/app/shared/object-grid/object-grid.component.scss @@ -0,0 +1 @@ +@import '../../../styles/variables'; diff --git a/src/app/object-grid/object-grid.component.spec.ts b/src/app/shared/object-grid/object-grid.component.spec.ts similarity index 100% rename from src/app/object-grid/object-grid.component.spec.ts rename to src/app/shared/object-grid/object-grid.component.spec.ts diff --git a/src/app/object-grid/object-grid.component.ts b/src/app/shared/object-grid/object-grid.component.ts similarity index 88% rename from src/app/object-grid/object-grid.component.ts rename to src/app/shared/object-grid/object-grid.component.ts index a6b62d735f..c811d90d62 100644 --- a/src/app/object-grid/object-grid.component.ts +++ b/src/app/shared/object-grid/object-grid.component.ts @@ -8,13 +8,13 @@ import { } from '@angular/core'; import { Observable } from 'rxjs/Observable'; -import { RemoteData } from '../core/data/remote-data'; -import { PageInfo } from '../core/shared/page-info.model'; +import { RemoteData } from '../../core/data/remote-data'; +import { PageInfo } from '../../core/shared/page-info.model'; -import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; +import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; -import { SortOptions, SortDirection } from '../core/cache/models/sort-options.model'; -import { fadeIn } from '../shared/animations/fade'; +import { SortOptions, SortDirection } from '../../core/cache/models/sort-options.model'; +import { fadeIn } from '../animations/fade'; import { ListableObject } from '../object-collection/shared/listable-object.model'; @Component({ diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html similarity index 100% rename from src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html rename to src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss new file mode 100644 index 0000000000..2867dd78ac --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../../styles/variables'; +@import '../../grid-card-styling'; diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts similarity index 84% rename from src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts rename to src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts index 6c5e526d15..0228107a57 100644 --- a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts @@ -4,8 +4,8 @@ import { renderElementsFor} from '../../../object-collection/shared/dso-element- import { CollectionSearchResult } from './collection-search-result.model'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; -import { Collection } from '../../../core/shared/collection.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { Collection } from '../../../../core/shared/collection.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-search-result-grid-element', diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts new file mode 100644 index 0000000000..ad48247e70 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../../+search-page/search-result.model'; +import { Collection } from '../../../../core/shared/collection.model'; + +export class CollectionSearchResult extends SearchResult { +} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html similarity index 100% rename from src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html rename to src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss new file mode 100644 index 0000000000..2867dd78ac --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../../styles/variables'; +@import '../../grid-card-styling'; diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts similarity index 84% rename from src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts rename to src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts index b6aa4bdb6d..4876a784fc 100644 --- a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts @@ -1,10 +1,10 @@ import { Component } from '@angular/core'; import { CommunitySearchResult } from './community-search-result.model'; -import { Community } from '../../../core/shared/community.model'; +import { Community } from '../../../../core/shared/community.model'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-search-result-grid-element', diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts new file mode 100644 index 0000000000..efeb328e11 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../../+search-page/search-result.model'; +import { Community } from '../../../../core/shared/community.model'; + +export class CommunitySearchResult extends SearchResult { +} diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html similarity index 100% rename from src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html rename to src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss new file mode 100644 index 0000000000..2867dd78ac --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../../styles/variables'; +@import '../../grid-card-styling'; diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts similarity index 84% rename from src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts rename to src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts index d4989d2efd..f9fe13cb88 100644 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts @@ -2,9 +2,9 @@ import { Component } from '@angular/core'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; -import { Item } from '../../../core/shared/item.model'; +import { Item } from '../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-search-result-grid-element', diff --git a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss similarity index 51% rename from src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss rename to src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss index 0f2684f1f1..ebec5817e6 100644 --- a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss @@ -1,5 +1,5 @@ - @import '../../../styles/variables.scss'; - @import '../grid-card-styling.scss'; + @import '../../../../styles/variables'; + @import '../grid-card-styling'; :host { /deep/ em { font-weight: bold; diff --git a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts similarity index 83% rename from src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts rename to src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts index ba98a58d4b..052a9377b5 100644 --- a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; -import { SearchResult } from '../../+search-page/search-result.model'; -import { DSpaceObject } from '../../core/shared/dspace-object.model'; -import { Metadatum } from '../../core/shared/metadatum.model'; -import { isEmpty, hasNoValue } from '../../shared/empty.util'; +import { SearchResult } from '../../../+search-page/search-result.model'; +import { DSpaceObject } from '../../../core/shared/dspace-object.model'; +import { Metadatum } from '../../../core/shared/metadatum.model'; +import { isEmpty, hasNoValue } from '../../empty.util'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.html similarity index 100% rename from src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html rename to src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.html diff --git a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss new file mode 100644 index 0000000000..946c8a6a31 --- /dev/null +++ b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts similarity index 100% rename from src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts rename to src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts similarity index 86% rename from src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts rename to src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts index 000c826188..912df16786 100644 --- a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts +++ b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts @@ -1,8 +1,8 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; -import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-wrapper-grid-element', diff --git a/src/app/object-list/collection-list-element/collection-list-element.component.html b/src/app/shared/object-list/collection-list-element/collection-list-element.component.html similarity index 100% rename from src/app/object-list/collection-list-element/collection-list-element.component.html rename to src/app/shared/object-list/collection-list-element/collection-list-element.component.html diff --git a/src/app/shared/object-list/collection-list-element/collection-list-element.component.scss b/src/app/shared/object-list/collection-list-element/collection-list-element.component.scss new file mode 100644 index 0000000000..45a533cd01 --- /dev/null +++ b/src/app/shared/object-list/collection-list-element/collection-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../styles/variables'; diff --git a/src/app/object-list/collection-list-element/collection-list-element.component.ts b/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts similarity index 80% rename from src/app/object-list/collection-list-element/collection-list-element.component.ts rename to src/app/shared/object-list/collection-list-element/collection-list-element.component.ts index c065a64b72..5e08e8ef3a 100644 --- a/src/app/object-list/collection-list-element/collection-list-element.component.ts +++ b/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; -import { Collection } from '../../core/shared/collection.model'; +import { Collection } from '../../../core/shared/collection.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-list-element', diff --git a/src/app/object-list/community-list-element/community-list-element.component.html b/src/app/shared/object-list/community-list-element/community-list-element.component.html similarity index 100% rename from src/app/object-list/community-list-element/community-list-element.component.html rename to src/app/shared/object-list/community-list-element/community-list-element.component.html diff --git a/src/app/shared/object-list/community-list-element/community-list-element.component.scss b/src/app/shared/object-list/community-list-element/community-list-element.component.scss new file mode 100644 index 0000000000..45a533cd01 --- /dev/null +++ b/src/app/shared/object-list/community-list-element/community-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../styles/variables'; diff --git a/src/app/object-list/community-list-element/community-list-element.component.ts b/src/app/shared/object-list/community-list-element/community-list-element.component.ts similarity index 80% rename from src/app/object-list/community-list-element/community-list-element.component.ts rename to src/app/shared/object-list/community-list-element/community-list-element.component.ts index 11ff392942..cd6e6f7574 100644 --- a/src/app/object-list/community-list-element/community-list-element.component.ts +++ b/src/app/shared/object-list/community-list-element/community-list-element.component.ts @@ -1,9 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; -import { Community } from '../../core/shared/community.model'; +import { Community } from '../../../core/shared/community.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-list-element', diff --git a/src/app/object-list/item-list-element/item-list-element.component.html b/src/app/shared/object-list/item-list-element/item-list-element.component.html similarity index 100% rename from src/app/object-list/item-list-element/item-list-element.component.html rename to src/app/shared/object-list/item-list-element/item-list-element.component.html diff --git a/src/app/shared/object-list/item-list-element/item-list-element.component.scss b/src/app/shared/object-list/item-list-element/item-list-element.component.scss new file mode 100644 index 0000000000..45a533cd01 --- /dev/null +++ b/src/app/shared/object-list/item-list-element/item-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../styles/variables'; diff --git a/src/app/object-list/item-list-element/item-list-element.component.ts b/src/app/shared/object-list/item-list-element/item-list-element.component.ts similarity index 80% rename from src/app/object-list/item-list-element/item-list-element.component.ts rename to src/app/shared/object-list/item-list-element/item-list-element.component.ts index bdc5733dcd..43c59f0980 100644 --- a/src/app/object-list/item-list-element/item-list-element.component.ts +++ b/src/app/shared/object-list/item-list-element/item-list-element.component.ts @@ -1,9 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; -import { Item } from '../../core/shared/item.model'; +import { Item } from '../../../core/shared/item.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-list-element', diff --git a/src/app/object-list/object-list-element/object-list-element.component.html b/src/app/shared/object-list/object-list-element/object-list-element.component.html similarity index 100% rename from src/app/object-list/object-list-element/object-list-element.component.html rename to src/app/shared/object-list/object-list-element/object-list-element.component.html diff --git a/src/app/object-list/object-list-element/object-list-element.component.scss b/src/app/shared/object-list/object-list-element/object-list-element.component.scss similarity index 56% rename from src/app/object-list/object-list-element/object-list-element.component.scss rename to src/app/shared/object-list/object-list-element/object-list-element.component.scss index 1a22768fe8..f96f4ae744 100644 --- a/src/app/object-list/object-list-element/object-list-element.component.scss +++ b/src/app/shared/object-list/object-list-element/object-list-element.component.scss @@ -1,4 +1,4 @@ -@import '../../../styles/variables.scss'; +@import '../../../../styles/variables'; :host { display: block; diff --git a/src/app/object-list/object-list-element/object-list-element.component.ts b/src/app/shared/object-list/object-list-element/object-list-element.component.ts similarity index 100% rename from src/app/object-list/object-list-element/object-list-element.component.ts rename to src/app/shared/object-list/object-list-element/object-list-element.component.ts diff --git a/src/app/object-list/object-list.component.html b/src/app/shared/object-list/object-list.component.html similarity index 100% rename from src/app/object-list/object-list.component.html rename to src/app/shared/object-list/object-list.component.html diff --git a/src/app/shared/object-list/object-list.component.scss b/src/app/shared/object-list/object-list.component.scss new file mode 100644 index 0000000000..48e6526dff --- /dev/null +++ b/src/app/shared/object-list/object-list.component.scss @@ -0,0 +1 @@ +@import '../../../styles/variables'; diff --git a/src/app/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts similarity index 90% rename from src/app/object-list/object-list.component.ts rename to src/app/shared/object-list/object-list.component.ts index 9422d1d843..c1e3d21760 100644 --- a/src/app/object-list/object-list.component.ts +++ b/src/app/shared/object-list/object-list.component.ts @@ -9,9 +9,14 @@ import { import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; -import { RemoteData } from '../core/data/remote-data'; -import { PageInfo } from '../core/shared/page-info.model'; -import { fadeIn } from '../shared/animations/fade'; +import { RemoteData } from '../../core/data/remote-data'; +import { PageInfo } from '../../core/shared/page-info.model'; + +import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; + +import { SortOptions, SortDirection } from '../../core/cache/models/sort-options.model'; + +import { fadeIn } from '../animations/fade'; import { ListableObject } from '../object-collection/shared/listable-object.model'; import { hasValue } from '../shared/empty.util'; diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html similarity index 100% rename from src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html rename to src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html diff --git a/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss new file mode 100644 index 0000000000..1d0786105c --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../../styles/variables'; diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts similarity index 84% rename from src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts rename to src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts index 1b5d7ef0ba..5545ea17ec 100644 --- a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts @@ -3,8 +3,8 @@ import { Component } from '@angular/core'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { CollectionSearchResult } from './collection-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; -import { Collection } from '../../../core/shared/collection.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { Collection } from '../../../../core/shared/collection.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-search-result-list-element', diff --git a/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts new file mode 100644 index 0000000000..ad48247e70 --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../../+search-page/search-result.model'; +import { Collection } from '../../../../core/shared/collection.model'; + +export class CollectionSearchResult extends SearchResult { +} diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html similarity index 100% rename from src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html rename to src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html diff --git a/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss new file mode 100644 index 0000000000..1d0786105c --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../../styles/variables'; diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts similarity index 84% rename from src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts rename to src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts index d9ab001f58..2d96f61833 100644 --- a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts @@ -3,8 +3,8 @@ import { Component } from '@angular/core'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { CommunitySearchResult } from './community-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; -import { Community } from '../../../core/shared/community.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { Community } from '../../../../core/shared/community.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-search-result-list-element', diff --git a/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result.model.ts b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result.model.ts new file mode 100644 index 0000000000..efeb328e11 --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../../+search-page/search-result.model'; +import { Community } from '../../../../core/shared/community.model'; + +export class CommunitySearchResult extends SearchResult { +} diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html similarity index 100% rename from src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html rename to src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html diff --git a/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss new file mode 100644 index 0000000000..1d0786105c --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../../styles/variables'; diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts similarity index 84% rename from src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts rename to src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts index 929233f1a3..d1011c8c45 100644 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts @@ -2,9 +2,9 @@ import { Component } from '@angular/core'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; -import { Item } from '../../../core/shared/item.model'; +import { Item } from '../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-search-result-list-element', diff --git a/src/app/object-list/search-result-list-element/search-result-list-element.component.scss b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.scss similarity index 67% rename from src/app/object-list/search-result-list-element/search-result-list-element.component.scss rename to src/app/shared/object-list/search-result-list-element/search-result-list-element.component.scss index 5ec8b5d81b..7134c43dad 100644 --- a/src/app/object-list/search-result-list-element/search-result-list-element.component.scss +++ b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.scss @@ -1,7 +1,7 @@ -@import '../../../styles/variables.scss'; +@import '../../../../styles/variables'; :host { ::ng-deep em { font-weight: bold; font-style: normal; } -} \ No newline at end of file +} diff --git a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts similarity index 83% rename from src/app/object-list/search-result-list-element/search-result-list-element.component.ts rename to src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts index ec0afde65d..b89bb56da6 100644 --- a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts @@ -1,10 +1,10 @@ import { Component, Inject } from '@angular/core'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { SearchResult } from '../../+search-page/search-result.model'; -import { DSpaceObject } from '../../core/shared/dspace-object.model'; -import { Metadatum } from '../../core/shared/metadatum.model'; -import { isEmpty, hasNoValue } from '../../shared/empty.util'; +import { SearchResult } from '../../../+search-page/search-result.model'; +import { DSpaceObject } from '../../../core/shared/dspace-object.model'; +import { Metadatum } from '../../../core/shared/metadatum.model'; +import { isEmpty, hasNoValue } from '../../empty.util'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.html b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.html similarity index 100% rename from src/app/object-list/wrapper-list-element/wrapper-list-element.component.html rename to src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.html diff --git a/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.scss b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.scss new file mode 100644 index 0000000000..51a7fc6a55 --- /dev/null +++ b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; + diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.ts similarity index 86% rename from src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts rename to src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.ts index ff5591442d..6450babae8 100644 --- a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts +++ b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.ts @@ -1,8 +1,8 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator' -import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-wrapper-list-element', diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 8ef05b2f89..7ee5ba56df 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -14,21 +14,21 @@ import { FileSizePipe } from './utils/file-size-pipe'; import { SafeUrlPipe } from './utils/safe-url-pipe'; import { TruncatePipe } from './utils/truncate.pipe'; -import { CollectionListElementComponent } from '../object-list/collection-list-element/collection-list-element.component'; -import { CommunityListElementComponent } from '../object-list/community-list-element/community-list-element.component'; -import { ItemListElementComponent } from '../object-list/item-list-element/item-list-element.component'; -import { ObjectListElementComponent } from '../object-list/object-list-element/object-list-element.component'; -import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component'; -import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; -import { ObjectListComponent } from '../object-list/object-list.component'; +import { CollectionListElementComponent } from './object-list/collection-list-element/collection-list-element.component'; +import { CommunityListElementComponent } from './object-list/community-list-element/community-list-element.component'; +import { ItemListElementComponent } from './object-list/item-list-element/item-list-element.component'; +import { ObjectListElementComponent } from './object-list/object-list-element/object-list-element.component'; +import { SearchResultListElementComponent } from './object-list/search-result-list-element/search-result-list-element.component'; +import { WrapperListElementComponent } from './object-list/wrapper-list-element/wrapper-list-element.component'; +import { ObjectListComponent } from './object-list/object-list.component'; -import { CollectionGridElementComponent} from '../object-grid/collection-grid-element/collection-grid-element.component' -import { CommunityGridElementComponent} from '../object-grid/community-grid-element/community-grid-element.component' -import { ItemGridElementComponent} from '../object-grid/item-grid-element/item-grid-element.component' -import { ObjectGridElementComponent} from '../object-grid/object-grid-element/object-grid-element.component' -import { WrapperGridElementComponent} from '../object-grid/wrapper-grid-element/wrapper-grid-element.component' -import { ObjectGridComponent } from '../object-grid/object-grid.component'; -import { ObjectCollectionComponent } from '../object-collection/object-collection.component'; +import { CollectionGridElementComponent} from './object-grid/collection-grid-element/collection-grid-element.component' +import { CommunityGridElementComponent} from './object-grid/community-grid-element/community-grid-element.component' +import { ItemGridElementComponent} from './object-grid/item-grid-element/item-grid-element.component' +import { ObjectGridElementComponent} from './object-grid/object-grid-element/object-grid-element.component' +import { WrapperGridElementComponent} from './object-grid/wrapper-grid-element/wrapper-grid-element.component' +import { ObjectGridComponent } from './object-grid/object-grid.component'; +import { ObjectCollectionComponent } from './object-collection/object-collection.component'; import { ComcolPageContentComponent } from './comcol-page-content/comcol-page-content.component'; import { ComcolPageHeaderComponent } from './comcol-page-header/comcol-page-header.component'; import { ComcolPageLogoComponent } from './comcol-page-logo/comcol-page-logo.component'; @@ -38,9 +38,9 @@ import { LoadingComponent } from './loading/loading.component'; import { PaginationComponent } from './pagination/pagination.component'; import { ThumbnailComponent } from '../thumbnail/thumbnail.component'; import { SearchFormComponent } from './search-form/search-form.component'; -import { SearchResultGridElementComponent } from '../object-grid/search-result-grid-element/search-result-grid-element.component'; +import { SearchResultGridElementComponent } from './object-grid/search-result-grid-element/search-result-grid-element.component'; import { ViewModeSwitchComponent } from './view-mode-switch/view-mode-switch.component'; -import { GridThumbnailComponent } from '../object-grid/grid-thumbnail/grid-thumbnail.component'; +import { GridThumbnailComponent } from './object-grid/grid-thumbnail/grid-thumbnail.component'; import { VarDirective } from './utils/var.directive'; const MODULES = [ From 2aa8bdf3c16630cd364c58fd9503b97878445aca Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 6 Nov 2017 10:08:28 +0100 Subject: [PATCH 24/77] 150 Backup commit --- .../object-collection.component.spec.ts | 13 +++--- .../collection-grid-element.component.spec.ts | 43 ++++++++++++++++++ .../community-grid-element.component.spec.ts | 44 +++++++++++++++++++ .../item-grid-element.component.spec.ts | 42 +++++++++++++++++- ...-search-result-grid-element.component.html | 14 +++++- ...-search-result-grid-element.component.html | 14 +++++- .../wrapper-grid-element.component.spec.ts | 43 ++++++++++++++++++ 7 files changed, 202 insertions(+), 11 deletions(-) create mode 100644 src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts diff --git a/src/app/shared/object-collection/object-collection.component.spec.ts b/src/app/shared/object-collection/object-collection.component.spec.ts index a56a3e56dc..6793042f35 100644 --- a/src/app/shared/object-collection/object-collection.component.spec.ts +++ b/src/app/shared/object-collection/object-collection.component.spec.ts @@ -4,7 +4,7 @@ import { element } from 'protractor'; import { By } from '@angular/platform-browser'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { Config } from '../../../config/config.interface'; -import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { RouterStub } from '../testing/router-stub'; @@ -12,6 +12,7 @@ import { RouterStub } from '../testing/router-stub'; describe('ObjectCollectionComponent', () => { let fixture: ComponentFixture; let objectCollectionComponent: ObjectCollectionComponent; + const queryParam = 'test query'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const activatedRouteStub = { @@ -34,19 +35,21 @@ describe('ObjectCollectionComponent', () => { beforeEach(async(() => { fixture = TestBed.createComponent(ObjectCollectionComponent); objectCollectionComponent = fixture.componentInstance; + })); it('should only show the grid component when the viewmode is set to grid', () => { objectCollectionComponent.currentMode = ViewMode.Grid; - // expect(By.css('ds-object-grid')).toEqual(1); - // expect(By.css('ds-object-list')).toEqual(0); + + expect(fixture.debugElement.query(By.css('ds-object-grid'))).toBeDefined(); + expect(fixture.debugElement.query(By.css('ds-object-list'))).toBeNull(); }); it('should only show the list component when the viewmode is set to list', () => { objectCollectionComponent.currentMode = ViewMode.List; - // expect(By.css('ds-object-list').length).toEqual(1); - // expect(By.css('ds-object-grid').length).toEqual(0); + expect(fixture.debugElement.query(By.css('ds-object-list'))).toBeDefined(); + expect(fixture.debugElement.query(By.css('ds-object-grid'))).toBeNull(); }) }); diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts index e69de29bb2..a1af8b5a3c 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts @@ -0,0 +1,43 @@ +import { CollectionGridElementComponent } from './collection-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; + +let collectionGridElementComponent: CollectionGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; + +describe('CollectionGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CollectionGridElementComponent ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useFactory: (collectionGridElementComponent)} + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(CollectionGridElementComponent); + collectionGridElementComponent = fixture.componentInstance; + + })); + + it('should show the collection cards in the grid element',()=>{ + expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); + }) +}) diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts new file mode 100644 index 0000000000..f6ab7bc6cd --- /dev/null +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts @@ -0,0 +1,44 @@ +import { CommunityGridElementComponent } from './community-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../testing/router-stub'; +import { Observable } from 'rxjs/Observable'; +import { By } from '@angular/platform-browser'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { Community } from '../../../core/shared/community.model'; + +let communityGridElementComponent: CommunityGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +describe('CommunityGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CommunityGridElementComponent ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useFactory: (communityGridElementComponent)} + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(CommunityGridElementComponent); + communityGridElementComponent = fixture.componentInstance; + + })); + + it('should show the community cards in the grid element',()=>{ + expect(fixture.debugElement.query(By.css('ds-community-grid-element'))).toBeDefined(); + }) +}); diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts index 0da99aa697..b4fb9c8029 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts @@ -1,6 +1,44 @@ import { ItemGridElementComponent } from './item-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { TruncatePipe } from '../../utils/truncate.pipe'; -describe('ItemGridElementComponent',()=>{ - let itemGridElementComponent: ItemGridElementComponent; +let itemGridElementComponent: ItemGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +describe('ItemGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ItemGridElementComponent , TruncatePipe], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useFactory: (itemGridElementComponent)} + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(ItemGridElementComponent); + itemGridElementComponent = fixture.componentInstance; + + })); + + it('should show the item cards in the grid element',()=>{ + expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined(); + }) }) diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html index 914fb49487..ae63924374 100644 --- a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html @@ -1,2 +1,12 @@ - -
      +
      + + + + +
      +

      {{dso.name}}

      +

      {{dso.shortDescription}}

      + View + +
      +
      diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html index d09ef7d668..2707934c56 100644 --- a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html @@ -1,2 +1,12 @@ - -
      +
      + + + + + +
      +

      {{dso.name}}

      +

      {{dso.shortDescription}}

      + View +
      +
      diff --git a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts index e69de29bb2..5b02fbe95a 100644 --- a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts @@ -0,0 +1,43 @@ +import { WrapperGridElementComponent } from './wrapper-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; + +let wrapperGridElementComponent: WrapperGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; + +describe('WrapperGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ WrapperGridElementComponent ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useFactory: (wrapperGridElementComponent)} + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(WrapperGridElementComponent); + wrapperGridElementComponent = fixture.componentInstance; + + })); + + it('should show the wrapper element containing the cards',()=>{ + expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); + }) +}) From 1a2c74d6f197e4df87a4f873c22c0577284340d1 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 6 Nov 2017 13:40:00 +0100 Subject: [PATCH 25/77] #150 Grid element testing --- .../collection-grid-element.component.spec.ts | 26 +++++- .../community-grid-element.component.spec.ts | 24 +++++- .../item-grid-element.component.spec.ts | 30 ++++++- ...arch-result-grid-element.component.spec.ts | 67 +++++++++++++++ ...arch-result-grid-element.component.spec.ts | 67 +++++++++++++++ ...arch-result-grid-element.component.spec.ts | 84 +++++++++++++++++++ 6 files changed, 290 insertions(+), 8 deletions(-) create mode 100644 src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts create mode 100644 src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts create mode 100644 src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts index a1af8b5a3c..fd935af992 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts @@ -5,6 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { RouterStub } from '../../testing/router-stub'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; +import { Collection } from '../../../core/shared/collection.model'; let collectionGridElementComponent: CollectionGridElementComponent; let fixture: ComponentFixture; @@ -16,6 +17,15 @@ const activatedRouteStub = { scope: scopeParam }) }; +let mockCollection: Collection = Object.assign(new Collection(), { + metadata: [ + { + key: 'dc.description.abstract', + language: 'en_US', + value: 'Short description' + }] +}); +let createdGridElementComponent:CollectionGridElementComponent= new CollectionGridElementComponent(mockCollection); describe('CollectionGridElementComponent', () => { beforeEach(async(() => { @@ -24,7 +34,7 @@ describe('CollectionGridElementComponent', () => { providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useFactory: (collectionGridElementComponent)} + { provide: 'objectElementProvider', useValue: (createdGridElementComponent)} ], schemas: [ NO_ERRORS_SCHEMA ] @@ -33,11 +43,19 @@ describe('CollectionGridElementComponent', () => { beforeEach(async(() => { fixture = TestBed.createComponent(CollectionGridElementComponent); - collectionGridElementComponent = fixture.componentInstance; - })); it('should show the collection cards in the grid element',()=>{ expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); - }) + }); + + it('should only show the description if "short description" metadata is present',()=>{ + let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + + if(mockCollection.shortDescription.length>0){ + expect(descriptionText).toBeDefined(); + }else{ + expect(descriptionText).not.toBeDefined(); + } + }); }) diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts index f6ab7bc6cd..dc837e3c0c 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts @@ -18,6 +18,18 @@ const activatedRouteStub = { scope: scopeParam }) }; + +let mockCommunity: Community = Object.assign(new Community(), { + metadata: [ + { + key: 'dc.description.abstract', + language: 'en_US', + value: 'Short description' + }] +}); + +let createdGridElementComponent:CommunityGridElementComponent= new CommunityGridElementComponent(mockCommunity); + describe('CommunityGridElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ @@ -25,7 +37,7 @@ describe('CommunityGridElementComponent', () => { providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useFactory: (communityGridElementComponent)} + { provide: 'objectElementProvider', useValue: (createdGridElementComponent)} ], schemas: [ NO_ERRORS_SCHEMA ] @@ -41,4 +53,14 @@ describe('CommunityGridElementComponent', () => { it('should show the community cards in the grid element',()=>{ expect(fixture.debugElement.query(By.css('ds-community-grid-element'))).toBeDefined(); }) + + it('should only show the description if "short description" metadata is present',()=>{ + let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + + if(mockCommunity.shortDescription.length>0){ + expect(descriptionText).toBeDefined(); + }else{ + expect(descriptionText).not.toBeDefined(); + } + }); }); diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts index b4fb9c8029..8913dca3ee 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts @@ -6,6 +6,7 @@ import { RouterStub } from '../../testing/router-stub'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; import { TruncatePipe } from '../../utils/truncate.pipe'; +import { Item } from '../../../core/shared/item.model'; let itemGridElementComponent: ItemGridElementComponent; let fixture: ComponentFixture; @@ -17,6 +18,17 @@ const activatedRouteStub = { scope: scopeParam }) }; +/* tslint:disable:no-shadowed-variable */ +let mockItem: Item = Object.assign(new Item(), { + metadata: [ + { + key: 'dc.contributor.author', + language: 'en_US', + value: 'Smith, Donald' + }] +}); + +let createdGridElementComponent:ItemGridElementComponent= new ItemGridElementComponent(mockItem); describe('ItemGridElementComponent', () => { beforeEach(async(() => { @@ -25,7 +37,7 @@ describe('ItemGridElementComponent', () => { providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useFactory: (itemGridElementComponent)} + { provide: 'objectElementProvider', useValue: {createdGridElementComponent}} ], schemas: [ NO_ERRORS_SCHEMA ] @@ -39,6 +51,18 @@ describe('ItemGridElementComponent', () => { })); it('should show the item cards in the grid element',()=>{ - expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined(); - }) + expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined() + }); + + it('should only show the author span if the author metadata is present',()=>{ + let itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); + + if(mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length>0){ + expect(itemAuthorField).toBeDefined(); + }else{ + expect(itemAuthorField).toBeDefined(); + } + }); + + }) diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts new file mode 100644 index 0000000000..8d6fe6fb38 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts @@ -0,0 +1,67 @@ +import {CollectionSearchResultGridElementComponent } from './collection-search-result-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { TruncatePipe } from '../../../utils/truncate.pipe'; +import { Community } from '../../../../core/shared/community.model'; +import { Collection } from '../../../../core/shared/collection.model'; + + +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +let mockCollection: Collection = Object.assign(new Collection(), { + metadata: [ + { + key: 'dc.description.abstract', + language: 'en_US', + value: 'Short description' + } ] + +}); + +let createdGridElementComponent: CollectionSearchResultGridElementComponent = new CollectionSearchResultGridElementComponent(mockCollection); + + +describe('CollectionSearchResultGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CollectionSearchResultGridElementComponent, TruncatePipe ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useValue: (createdGridElementComponent) } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(CollectionSearchResultGridElementComponent); + })); + + it('should show the item result cards in the grid element', () => { + expect(fixture.debugElement.query(By.css('ds-collection-search-result-grid-element'))).toBeDefined(); + }); + + + it('should only show the description if "short description" metadata is present',()=>{ + let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + + if(mockCollection.shortDescription.length>0){ + expect(descriptionText).toBeDefined(); + }else{ + expect(descriptionText).not.toBeDefined(); + } + }); +}); diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts new file mode 100644 index 0000000000..0924700da7 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts @@ -0,0 +1,67 @@ +import { CommunitySearchResultGridElementComponent } from './community-search-result-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { TruncatePipe } from '../../../utils/truncate.pipe'; +import { Community } from '../../../../core/shared/community.model'; + + +let communitySearchResultGridElementComponent: CommunitySearchResultGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +let mockCommunity: Community = Object.assign(new Community(), { + metadata: [ + { + key: 'dc.description.abstract', + language: 'en_US', + value: 'Short description' + } ] + +}); + +let createdGridElementComponent: CommunitySearchResultGridElementComponent = new CommunitySearchResultGridElementComponent(mockCommunity); + + +describe('CommunitySearchResultGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CommunitySearchResultGridElementComponent, TruncatePipe ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useValue: (createdGridElementComponent) } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(CommunitySearchResultGridElementComponent); + })); + + it('should show the item result cards in the grid element', () => { + expect(fixture.debugElement.query(By.css('ds-community-search-result-grid-element'))).toBeDefined(); + }); + + + it('should only show the description if "short description" metadata is present',()=>{ + let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + + if(mockCommunity.shortDescription.length>0){ + expect(descriptionText).toBeDefined(); + }else{ + expect(descriptionText).not.toBeDefined(); + } + }); +}); diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts new file mode 100644 index 0000000000..318910304f --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts @@ -0,0 +1,84 @@ +import { ItemSearchResultGridElementComponent } from './item-search-result-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { TruncatePipe } from '../../../utils/truncate.pipe'; +import { Item } from '../../../../core/shared/item.model'; + + +let itemSearchResultGridElementComponent: ItemSearchResultGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +let mockItem: Item = Object.assign(new Item(), { + metadata: [ + { + key: 'dc.contributor.author', + language: 'en_US', + value: 'Smith, Donald' + }, + { + key: 'dc.date.issued', + language: null, + value: '1650-06-26' + }] +}); +let createdGridElementComponent:ItemSearchResultGridElementComponent= new ItemSearchResultGridElementComponent(mockItem); + +describe('ItemSearchResultGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ItemSearchResultGridElementComponent, TruncatePipe ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useValue: (createdGridElementComponent) } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(ItemSearchResultGridElementComponent); + itemSearchResultGridElementComponent = fixture.componentInstance; + + })); + + it('should show the item result cards in the grid element',()=>{ + expect(fixture.debugElement.query(By.css('ds-item-search-result-grid-element'))).toBeDefined(); + }); + + it('should only show the author span if the author metadata is present',()=>{ + let itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); + + if(mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length>0){ + expect(itemAuthorField).toBeDefined(); + }else{ + expect(itemAuthorField).not.toBeDefined(); + } + }); + + it('should only show the date span if the issuedate is present',()=>{ + let dateField = expect(fixture.debugElement.query(By.css('span.item-list-date'))); + + if(mockItem.findMetadata('dc.date.issued').length>0){ + expect(dateField).toBeDefined(); + }else{ + expect(dateField).not.toBeDefined(); + } + }); + + + + +}); From 78cbc48376de3489f7fe9b3c1f9459a3012171b1 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 13 Nov 2017 13:37:02 +0100 Subject: [PATCH 26/77] #150 Removal of inherited css + restyling using bootstrap classes --- package.json | 1 - .../collection-grid-element.component.html | 6 ++- .../collection-grid-element.component.scss | 2 +- .../community-grid-element.component.html | 6 ++- .../community-grid-element.component.scss | 2 +- .../shared/object-grid/grid-card-styling.scss | 45 ------------------- .../item-grid-element.component.html | 6 ++- .../item-grid-element.component.scss | 2 +- .../object-grid-element.component.scss | 1 - .../object-grid/object-grid.component.html | 4 +- .../object-grid/object-grid.component.scss | 22 +++++++++ ...-search-result-grid-element.component.html | 7 +-- ...-search-result-grid-element.component.scss | 1 - ...-search-result-grid-element.component.html | 6 ++- ...-search-result-grid-element.component.scss | 2 +- ...-search-result-grid-element.component.html | 10 +++-- ...-search-result-grid-element.component.scss | 2 +- .../search-result-grid-element.component.scss | 1 - .../wrapper-grid-element.component.scss | 2 +- src/styles/_custom_variables.scss | 2 + yarn.lock | 4 -- 21 files changed, 58 insertions(+), 76 deletions(-) delete mode 100644 src/app/shared/object-grid/grid-card-styling.scss diff --git a/package.json b/package.json index 1d6a6ef36e..e32a9af765 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,6 @@ "methods": "1.1.2", "morgan": "1.9.0", "ngx-pagination": "3.0.1", - "object-fit-images": "^3.2.3", "pem": "1.12.3", "reflect-metadata": "0.1.10", "rxjs": "5.4.3", diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html index 5dc717cf54..b1287212a3 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html @@ -3,10 +3,12 @@ -
      +

      {{object.name}}

      {{object.shortDescription}}

      - View +
      + View +
      diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss index 946c8a6a31..51a7fc6a55 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; + diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html index e4ea3dcb13..b6f4c5c5d9 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html @@ -4,9 +4,11 @@ -
      +

      {{object.name}}

      {{object.shortDescription}}

      - View +
      + View +
      diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss index 946c8a6a31..51a7fc6a55 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; + diff --git a/src/app/shared/object-grid/grid-card-styling.scss b/src/app/shared/object-grid/grid-card-styling.scss deleted file mode 100644 index 2fe199d1ce..0000000000 --- a/src/app/shared/object-grid/grid-card-styling.scss +++ /dev/null @@ -1,45 +0,0 @@ -@import '../../../styles/custom_variables'; - -.card-title{ - line-height: $line-height-base; - height:$headings-line-height; - font-size:$headings-font-size; - overflow: hidden; - text-overflow: ellipsis; -} - -.card-text { - overflow: hidden; - text-overflow: ellipsis; - line-height: $line-height-base; - margin-bottom:$card-block-margin-base*2; -} -.card-text.item-authors { - height: $line-height-base; -} -.card-text.item-abstract { - height: $content-line-height; -} - -.viewButton{ - display:table; - margin:auto; - width: $card-button-width; -} - -.card{ - margin-bottom: $card-block-margin-base *3; - height: $card-height-percentage; -} - -.card-img-top ::ng-deep img -{ - height: $card-thumbnail-height; - width: 100%; - object-fit: cover; -} - -.card-block{ - margin: $card-block-margin-base; -} - diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html index 3fae55088e..b8bacfaf2e 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html @@ -4,7 +4,7 @@ -
      +

      {{object.findMetadata('dc.title')}}

      @@ -16,6 +16,8 @@

      {{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

      - View +
      + View +
      diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss index 946c8a6a31..51a7fc6a55 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; + diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss index d299edd0ab..d4720c4a64 100644 --- a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss +++ b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss @@ -1,5 +1,4 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; :host { display: block; margin-bottom: $spacer; diff --git a/src/app/shared/object-grid/object-grid.component.html b/src/app/shared/object-grid/object-grid.component.html index ebcf240d28..32c3e9ec4f 100644 --- a/src/app/shared/object-grid/object-grid.component.html +++ b/src/app/shared/object-grid/object-grid.component.html @@ -10,8 +10,8 @@ (sortDirectionChange)="onSortDirectionChange($event)" (sortFieldChange)="onSortDirectionChange($event)" (paginationChange)="onPaginationChange($event)"> -
      -
      +
      diff --git a/src/app/shared/object-grid/object-grid.component.scss b/src/app/shared/object-grid/object-grid.component.scss index 48e6526dff..c01dfbdc85 100644 --- a/src/app/shared/object-grid/object-grid.component.scss +++ b/src/app/shared/object-grid/object-grid.component.scss @@ -1 +1,23 @@ @import '../../../styles/variables'; + +ds-wrapper-grid-element ::ng-deep { + div.thumbnail > img { + height: $card-thumbnail-height; + width: 100%; + } + .card-title { + line-height: $headings-line-height; + height: ($headings-line-height*3) +em; + overflow: hidden; + text-overflow: ellipsis; + } + .item-abstract { + line-height: $line-height-base; + height: ($line-height-base*5)+em; + overflow: hidden; + text-overflow: ellipsis; + } + div.card { + margin-bottom: 20px; + } +} diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html index ae63924374..d6b1bfb5f4 100644 --- a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html @@ -3,10 +3,11 @@ -
      +

      {{dso.name}}

      {{dso.shortDescription}}

      - View - +
      + View +
      diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss index 2867dd78ac..1d0786105c 100644 --- a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss @@ -1,2 +1 @@ @import '../../../../../styles/variables'; -@import '../../grid-card-styling'; diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html index 2707934c56..8ff6874bff 100644 --- a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html @@ -4,9 +4,11 @@ -
      +

      {{dso.name}}

      {{dso.shortDescription}}

      - View +
      + View +
      diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss index 2867dd78ac..bd63aa6a3a 100644 --- a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../../styles/variables'; -@import '../../grid-card-styling'; + diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html index be84039416..ce9324477f 100644 --- a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html @@ -1,10 +1,10 @@
      - + -
      -

      +
      +

      @@ -25,7 +25,9 @@

      - View +
      + View +
      diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss index 2867dd78ac..bd63aa6a3a 100644 --- a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../../styles/variables'; -@import '../../grid-card-styling'; + diff --git a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss index ebec5817e6..e8d681fb32 100644 --- a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss @@ -1,5 +1,4 @@ @import '../../../../styles/variables'; - @import '../grid-card-styling'; :host { /deep/ em { font-weight: bold; diff --git a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss index 946c8a6a31..51a7fc6a55 100644 --- a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss +++ b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; + diff --git a/src/styles/_custom_variables.scss b/src/styles/_custom_variables.scss index 8c0dcae928..4dcc161cc4 100644 --- a/src/styles/_custom_variables.scss +++ b/src/styles/_custom_variables.scss @@ -2,3 +2,5 @@ $content-spacing: $spacer * 1.5; $button-height: $input-btn-padding-y * 2 + $input-btn-line-height + calculateRem($input-btn-border-width*2); $card-height-percentage:98%; +$card-thumbnail-height:240px; + diff --git a/yarn.lock b/yarn.lock index 4211b7228a..91b2a787e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4804,10 +4804,6 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" -object-fit-images@^3.2.3: - version "3.2.3" - resolved "https://registry.yarnpkg.com/object-fit-images/-/object-fit-images-3.2.3.tgz#4089f6d0070a3b5563d3c1ab6f1b28d61331f0ac" - object-keys@^1.0.8: version "1.0.11" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d" From aabc6836e37917477380aaba2d2e9f9cf8b0becc Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 14 Nov 2017 14:51:49 +0100 Subject: [PATCH 27/77] Additional IDE generated files ignored --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f8395956f5..dd5f5fa391 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ npm-debug.log /coverage/ .idea +*.iml *.ngfactory.ts *.css.shim.ts *.scss.shim.ts From 995771192e7360265d8fc4fe984422052b6f511e Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Wed, 15 Nov 2017 09:15:34 +0100 Subject: [PATCH 28/77] #150 Removal of iml file + small margin between pagination and grid --- dspace-angular.iml | 8 -------- src/app/shared/object-grid/object-grid.component.html | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 dspace-angular.iml diff --git a/dspace-angular.iml b/dspace-angular.iml deleted file mode 100644 index 5806390693..0000000000 --- a/dspace-angular.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/app/shared/object-grid/object-grid.component.html b/src/app/shared/object-grid/object-grid.component.html index 32c3e9ec4f..445d681268 100644 --- a/src/app/shared/object-grid/object-grid.component.html +++ b/src/app/shared/object-grid/object-grid.component.html @@ -10,7 +10,7 @@ (sortDirectionChange)="onSortDirectionChange($event)" (sortFieldChange)="onSortDirectionChange($event)" (paginationChange)="onPaginationChange($event)"> -
      +
      From cb15939a5372b5c468fb6ab7dd9eb1d172d4d9f9 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Wed, 15 Nov 2017 10:28:11 +0100 Subject: [PATCH 29/77] #150 Merge fixes --- .../search-service/search.service.ts | 2 +- .../object-collection.component.html | 2 ++ .../object-collection.component.ts | 5 ++-- .../object-grid/object-grid.component.html | 4 +-- .../object-grid/object-grid.component.scss | 4 +++ .../object-grid/object-grid.component.ts | 4 +-- .../object-list/object-list.component.ts | 27 +------------------ 7 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 63b1b04dce..8ca84f4a32 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -12,7 +12,7 @@ import { Item } from '../../core/shared/item.model'; import { SearchFilterConfig } from './search-filter-config.model'; import { FilterType } from './filter-type.model'; import { FacetValue } from './facet-value.model'; -import { ItemSearchResult } from '../../object-collection/shared/item-search-result.model'; +import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; import { ViewMode } from '../../+search-page/search-options.model'; import { Router, NavigationExtras, ActivatedRoute } from '@angular/router'; import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; diff --git a/src/app/shared/object-collection/object-collection.component.html b/src/app/shared/object-collection/object-collection.component.html index 6c2a2fb1de..c9b1cb92f5 100644 --- a/src/app/shared/object-collection/object-collection.component.html +++ b/src/app/shared/object-collection/object-collection.component.html @@ -1,12 +1,14 @@ diff --git a/src/app/shared/object-collection/object-collection.component.ts b/src/app/shared/object-collection/object-collection.component.ts index 8d5a9ce3c7..5a356dcbdc 100644 --- a/src/app/shared/object-collection/object-collection.component.ts +++ b/src/app/shared/object-collection/object-collection.component.ts @@ -27,6 +27,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { @Input() objects: RemoteData; @Input() config?: PaginationComponentOptions; @Input() sortConfig: SortOptions; + @Input() hideGear = false; pageInfo: Observable; private sub; /** @@ -60,13 +61,13 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { ngOnChanges(changes: SimpleChanges) { if (changes.objects && !changes.objects.isFirstChange()) { - this.pageInfo = this.objects.pageInfo; + // this.pageInfo = this.objects.pageInfo; } } ngOnInit(): void { - this.pageInfo = this.objects.pageInfo; + // this.pageInfo = this.objects.pageInfo; this.sub = this.route .queryParams diff --git a/src/app/shared/object-grid/object-grid.component.html b/src/app/shared/object-grid/object-grid.component.html index 445d681268..ad9bf20a32 100644 --- a/src/app/shared/object-grid/object-grid.component.html +++ b/src/app/shared/object-grid/object-grid.component.html @@ -10,9 +10,9 @@ (sortDirectionChange)="onSortDirectionChange($event)" (sortFieldChange)="onSortDirectionChange($event)" (paginationChange)="onPaginationChange($event)"> -
      +
      + *ngFor="let object of objects?.payload">
      diff --git a/src/app/shared/object-grid/object-grid.component.scss b/src/app/shared/object-grid/object-grid.component.scss index c01dfbdc85..a85e38d26f 100644 --- a/src/app/shared/object-grid/object-grid.component.scss +++ b/src/app/shared/object-grid/object-grid.component.scss @@ -17,6 +17,10 @@ ds-wrapper-grid-element ::ng-deep { overflow: hidden; text-overflow: ellipsis; } + .item-authors{ + line-height: $line-height-base; + height: ($line-height-base*1.5)+em; + } div.card { margin-bottom: 20px; } diff --git a/src/app/shared/object-grid/object-grid.component.ts b/src/app/shared/object-grid/object-grid.component.ts index c811d90d62..1c890c8959 100644 --- a/src/app/shared/object-grid/object-grid.component.ts +++ b/src/app/shared/object-grid/object-grid.component.ts @@ -64,12 +64,12 @@ export class ObjectGridComponent implements OnChanges, OnInit { ngOnChanges(changes: SimpleChanges) { if (changes.objects && !changes.objects.isFirstChange()) { - this.pageInfo = this.objects.pageInfo; + // this.pageInfo = this.objects.pageInfo; } } ngOnInit(): void { - this.pageInfo = this.objects.pageInfo; + // this.pageInfo = this.objects.pageInfo; } /** diff --git a/src/app/shared/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts index c1e3d21760..a300e06f59 100644 --- a/src/app/shared/object-list/object-list.component.ts +++ b/src/app/shared/object-list/object-list.component.ts @@ -7,8 +7,6 @@ import { ViewEncapsulation } from '@angular/core'; -import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; - import { RemoteData } from '../../core/data/remote-data'; import { PageInfo } from '../../core/shared/page-info.model'; @@ -18,9 +16,8 @@ import { SortOptions, SortDirection } from '../../core/cache/models/sort-options import { fadeIn } from '../animations/fade'; import { ListableObject } from '../object-collection/shared/listable-object.model'; -import { hasValue } from '../shared/empty.util'; +import { hasValue } from '../empty.util'; -import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; @Component({ changeDetection: ChangeDetectionStrategy.Default, @@ -86,28 +83,6 @@ export class ObjectListComponent { */ @Output() sortFieldChange: EventEmitter = new EventEmitter(); data: any = {}; - - - onPageChange(event) { - this.pageChange.emit(event); - } - - onPageSizeChange(event) { - this.pageSizeChange.emit(event); - } - - onSortDirectionChange(event) { - this.sortDirectionChange.emit(event); - } - - onSortFieldChange(event) { - this.sortFieldChange.emit(event); - } - - onPaginationChange(event) { - this.paginationChange.emit(event); - } - onPageChange(event) { this.pageChange.emit(event); } From 9a16812c2b5394f21c4e224ca25702c2a842fdc2 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 17 Nov 2017 16:26:33 +0100 Subject: [PATCH 30/77] #150 Generalised AbstractListableElementComponent instead of grid/list specific implementations --- .../abstract-listable-element.component.ts | 13 +++++++++++++ .../collection-grid-element.component.ts | 4 ++-- .../community-grid-element.component.ts | 4 ++-- .../item-grid-element.component.ts | 4 ++-- .../object-grid-element.component.html | 0 .../object-grid-element.component.scss | 5 ----- .../object-grid-element.component.ts | 14 -------------- .../search-result-grid-element.component.ts | 4 ++-- .../collection-list-element.component.ts | 4 ++-- .../community-list-element.component.ts | 4 ++-- .../item-list-element.component.ts | 4 ++-- .../object-list-element.component.html | 0 .../object-list-element.component.scss | 6 ------ .../object-list-element.component.ts | 14 -------------- .../search-result-list-element.component.ts | 4 ++-- src/app/shared/shared.module.ts | 6 ++---- 16 files changed, 31 insertions(+), 59 deletions(-) create mode 100644 src/app/shared/object-collection/shared/object-collection-element/abstract-listable-element.component.ts delete mode 100644 src/app/shared/object-grid/object-grid-element/object-grid-element.component.html delete mode 100644 src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss delete mode 100644 src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts delete mode 100644 src/app/shared/object-list/object-list-element/object-list-element.component.html delete mode 100644 src/app/shared/object-list/object-list-element/object-list-element.component.scss delete mode 100644 src/app/shared/object-list/object-list-element/object-list-element.component.ts diff --git a/src/app/shared/object-collection/shared/object-collection-element/abstract-listable-element.component.ts b/src/app/shared/object-collection/shared/object-collection-element/abstract-listable-element.component.ts new file mode 100644 index 0000000000..d52036b5dc --- /dev/null +++ b/src/app/shared/object-collection/shared/object-collection-element/abstract-listable-element.component.ts @@ -0,0 +1,13 @@ +import { Component, Inject } from '@angular/core'; +import { ListableObject } from '../listable-object.model'; + +@Component({ + selector: 'ds-abstract-object-element', + template: ``, +}) +export class AbstractListableElementComponent { + object: T; + public constructor(@Inject('objectElementProvider') public listableObject: ListableObject) { + this.object = listableObject as T; + } +} diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts index 09aadab15e..a7f5ef3e49 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; import { Collection } from '../../../core/shared/collection.model'; -import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; @Component({ @@ -13,4 +13,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Collection, ViewMode.Grid) -export class CollectionGridElementComponent extends ObjectGridElementComponent {} +export class CollectionGridElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts index d40bd717a4..21d73ff0fa 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts @@ -1,7 +1,7 @@ import { Component, Input, Inject } from '@angular/core'; import { Community } from '../../../core/shared/community.model'; -import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Community, ViewMode.Grid) -export class CommunityGridElementComponent extends ObjectGridElementComponent {} +export class CommunityGridElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts index c41a6c9352..5a8d46f1f2 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts @@ -2,7 +2,7 @@ import { Component, Input, Inject } from '@angular/core'; import { Item } from '../../../core/shared/item.model'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; -import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Item, ViewMode.Grid) -export class ItemGridElementComponent extends ObjectGridElementComponent {} +export class ItemGridElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.html b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.html deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss deleted file mode 100644 index d4720c4a64..0000000000 --- a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss +++ /dev/null @@ -1,5 +0,0 @@ -@import '../../../../styles/variables'; -:host { - display: block; - margin-bottom: $spacer; -} diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts deleted file mode 100644 index c3ab5e39e3..0000000000 --- a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Component, Inject } from '@angular/core'; -import { ListableObject } from '../../object-collection/shared/listable-object.model'; - -@Component({ - selector: 'ds-object-grid-element', - styleUrls: ['./object-grid-element.component.scss'], - templateUrl: './object-grid-element.component.html' -}) -export class ObjectGridElementComponent { - object: T; - public constructor(@Inject('objectElementProvider') public gridable: ListableObject) { - this.object = gridable as T; - } -} diff --git a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts index 052a9377b5..8e1d7e0647 100644 --- a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts @@ -4,7 +4,7 @@ import { SearchResult } from '../../../+search-page/search-result.model'; import { DSpaceObject } from '../../../core/shared/dspace-object.model'; import { Metadatum } from '../../../core/shared/metadatum.model'; import { isEmpty, hasNoValue } from '../../empty.util'; -import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ @@ -12,7 +12,7 @@ import { ListableObject } from '../../object-collection/shared/listable-object.m template: `` }) -export class SearchResultGridElementComponent, K extends DSpaceObject> extends ObjectGridElementComponent { +export class SearchResultGridElementComponent, K extends DSpaceObject> extends AbstractListableElementComponent { dso: K; public constructor(@Inject('objectElementProvider') public gridable: ListableObject) { diff --git a/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts b/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts index 5e08e8ef3a..f95c087d5c 100644 --- a/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts +++ b/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; import { Collection } from '../../../core/shared/collection.model'; -import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; @Component({ selector: 'ds-collection-list-element', @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Collection, ViewMode.List) -export class CollectionListElementComponent extends ObjectListElementComponent {} +export class CollectionListElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-list/community-list-element/community-list-element.component.ts b/src/app/shared/object-list/community-list-element/community-list-element.component.ts index cd6e6f7574..e92c080a31 100644 --- a/src/app/shared/object-list/community-list-element/community-list-element.component.ts +++ b/src/app/shared/object-list/community-list-element/community-list-element.component.ts @@ -1,7 +1,7 @@ import { Component, Input, Inject } from '@angular/core'; import { Community } from '../../../core/shared/community.model'; -import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Community, ViewMode.List) -export class CommunityListElementComponent extends ObjectListElementComponent {} +export class CommunityListElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-list/item-list-element/item-list-element.component.ts b/src/app/shared/object-list/item-list-element/item-list-element.component.ts index 43c59f0980..e4efbd6b08 100644 --- a/src/app/shared/object-list/item-list-element/item-list-element.component.ts +++ b/src/app/shared/object-list/item-list-element/item-list-element.component.ts @@ -1,7 +1,7 @@ import { Component, Input, Inject } from '@angular/core'; import { Item } from '../../../core/shared/item.model'; -import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Item, ViewMode.List) -export class ItemListElementComponent extends ObjectListElementComponent {} +export class ItemListElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-list/object-list-element/object-list-element.component.html b/src/app/shared/object-list/object-list-element/object-list-element.component.html deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/app/shared/object-list/object-list-element/object-list-element.component.scss b/src/app/shared/object-list/object-list-element/object-list-element.component.scss deleted file mode 100644 index f96f4ae744..0000000000 --- a/src/app/shared/object-list/object-list-element/object-list-element.component.scss +++ /dev/null @@ -1,6 +0,0 @@ -@import '../../../../styles/variables'; - -:host { - display: block; - margin-bottom: $spacer; -} diff --git a/src/app/shared/object-list/object-list-element/object-list-element.component.ts b/src/app/shared/object-list/object-list-element/object-list-element.component.ts deleted file mode 100644 index 24f0ec1d93..0000000000 --- a/src/app/shared/object-list/object-list-element/object-list-element.component.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Component, Inject } from '@angular/core'; -import { ListableObject } from '../../object-collection/shared/listable-object.model'; - -@Component({ - selector: 'ds-object-list-element', - styleUrls: ['./object-list-element.component.scss'], - templateUrl: './object-list-element.component.html' -}) -export class ObjectListElementComponent { - object: T; - public constructor(@Inject('objectElementProvider') public listable: ListableObject) { - this.object = listable as T; - } -} diff --git a/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts index b89bb56da6..6c79eaad53 100644 --- a/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts @@ -1,18 +1,18 @@ import { Component, Inject } from '@angular/core'; -import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { SearchResult } from '../../../+search-page/search-result.model'; import { DSpaceObject } from '../../../core/shared/dspace-object.model'; import { Metadatum } from '../../../core/shared/metadatum.model'; import { isEmpty, hasNoValue } from '../../empty.util'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; @Component({ selector: 'ds-search-result-list-element', template: `` }) -export class SearchResultListElementComponent, K extends DSpaceObject> extends ObjectListElementComponent { +export class SearchResultListElementComponent, K extends DSpaceObject> extends AbstractListableElementComponent { dso: K; public constructor(@Inject('objectElementProvider') public listable: ListableObject) { diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 7ee5ba56df..ca13067851 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -17,7 +17,6 @@ import { TruncatePipe } from './utils/truncate.pipe'; import { CollectionListElementComponent } from './object-list/collection-list-element/collection-list-element.component'; import { CommunityListElementComponent } from './object-list/community-list-element/community-list-element.component'; import { ItemListElementComponent } from './object-list/item-list-element/item-list-element.component'; -import { ObjectListElementComponent } from './object-list/object-list-element/object-list-element.component'; import { SearchResultListElementComponent } from './object-list/search-result-list-element/search-result-list-element.component'; import { WrapperListElementComponent } from './object-list/wrapper-list-element/wrapper-list-element.component'; import { ObjectListComponent } from './object-list/object-list.component'; @@ -25,7 +24,7 @@ import { ObjectListComponent } from './object-list/object-list.component'; import { CollectionGridElementComponent} from './object-grid/collection-grid-element/collection-grid-element.component' import { CommunityGridElementComponent} from './object-grid/community-grid-element/community-grid-element.component' import { ItemGridElementComponent} from './object-grid/item-grid-element/item-grid-element.component' -import { ObjectGridElementComponent} from './object-grid/object-grid-element/object-grid-element.component' +import { AbstractListableElementComponent} from './object-collection/shared/object-collection-element/abstract-listable-element.component' import { WrapperGridElementComponent} from './object-grid/wrapper-grid-element/wrapper-grid-element.component' import { ObjectGridComponent } from './object-grid/object-grid.component'; import { ObjectCollectionComponent } from './object-collection/object-collection.component'; @@ -70,10 +69,9 @@ const COMPONENTS = [ ErrorComponent, LoadingComponent, ObjectListComponent, - ObjectListElementComponent, + AbstractListableElementComponent, WrapperListElementComponent, ObjectGridComponent, - ObjectGridElementComponent, WrapperGridElementComponent, ObjectCollectionComponent, PaginationComponent, From 806b7bc5fc0cf82320049b970c08fb30f78ba305 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 21 Nov 2017 13:57:49 +0100 Subject: [PATCH 31/77] 150 Separate maps per viewMode --- .../object-collection/shared/dso-element-decorator.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/shared/object-collection/shared/dso-element-decorator.ts b/src/app/shared/object-collection/shared/dso-element-decorator.ts index 5dc085d3a7..51aa57bc50 100644 --- a/src/app/shared/object-collection/shared/dso-element-decorator.ts +++ b/src/app/shared/object-collection/shared/dso-element-decorator.ts @@ -3,15 +3,18 @@ import { ListableObject } from './listable-object.model'; import { ViewMode } from '../../../+search-page/search-options.model'; const dsoElementMap = new Map(); -export function renderElementsFor(listable: GenericConstructor, viewMode : ViewMode) { +export function renderElementsFor(listable: GenericConstructor, viewMode: ViewMode) { return function decorator(objectElement: any) { if (!objectElement) { return; } - dsoElementMap.set(listable+viewMode, objectElement); + if (!dsoElementMap.get(viewMode)) { + dsoElementMap.set(viewMode, new Map()); + } + dsoElementMap.get(viewMode).set(listable, objectElement); }; } -export function rendersDSOType(listable: GenericConstructor, viewMode : ViewMode) { - return dsoElementMap.get(listable+viewMode); +export function rendersDSOType(listable: GenericConstructor, viewMode: ViewMode) { + return dsoElementMap.get(viewMode).get(listable); } From 1ac9bc0292181b772f846b439f3d59a449e9a181 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 21 Nov 2017 16:16:37 +0100 Subject: [PATCH 32/77] #150 Rollback to previous state (not part of this issue) --- ...ty-page-sub-collection-list.component.html | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html index 9494cdb755..b04e93ff71 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html @@ -1,10 +1,15 @@ -
      -

      {{'community.sub-collection-list.head' | translate}}

      -
        - -
      -
      +
      +

      {{'community.sub-collection-list.head' | translate}}

      + +
      +
      From 17dec3d032aeea586630ce5e99755941e20098ba Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Wed, 22 Nov 2017 08:13:24 +0100 Subject: [PATCH 33/77] #150 Avoid first "null" download for initial content --- .../object-grid/grid-thumbnail/grid-thumbnail.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html index 6221cbaba1..c0c3c1f65f 100644 --- a/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html +++ b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html @@ -1,4 +1,4 @@
      - - + +
      From 02e6c8928f78068b62d505362dbbcf9535726097 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 30 Nov 2017 15:06:52 +0100 Subject: [PATCH 34/77] #150 Fixing rebase errors --- src/app/+search-page/search-page.component.ts | 5 +++-- src/app/+search-page/search-service/search.service.ts | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 697e379f3d..6952a2da96 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -12,6 +12,8 @@ import { SearchService } from './search-service/search.service'; import { pushInOut } from '../shared/animations/push'; import { HostWindowService } from '../shared/host-window.service'; import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; +import { PaginationComponentOptions } from 'src/app/shared/pagination/pagination-component-options.model'; +import { SortOptions } from '../core/cache/models/sort-options.model'; /** * This component renders a simple item page. @@ -58,7 +60,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { pagination.pageSize = 10; const sort: SortOptions = new SortOptions(); - this.sortConfig=sort; + this.sortConfig = sort; this.searchOptions = this.service.searchOptions; } @@ -81,7 +83,6 @@ export class SearchPageComponent implements OnInit, OnDestroy { // pageSizeOptions = [9, 18, 27, 36 , 45, 54, 63, 72]; } - const sortDirection = +params.sortDirection || this.searchOptions.sort.direction; const pagination = Object.assign({}, this.searchOptions.pagination, diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 8ca84f4a32..52d86927d6 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -15,7 +15,6 @@ import { FacetValue } from './facet-value.model'; import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; import { ViewMode } from '../../+search-page/search-options.model'; import { Router, NavigationExtras, ActivatedRoute } from '@angular/router'; -import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; import { RouteService } from '../../shared/route.service'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; import { SortOptions } from '../../core/cache/models/sort-options.model'; From a704157c1fea16977e7d17a83998878992459cf9 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 26 Oct 2017 09:38:27 +0200 Subject: [PATCH 35/77] #150 Initial grid/list view implementation --- package.json | 1 + .../collection-page.component.html | 4 +- ...ty-page-sub-collection-list.component.html | 8 +- .../top-level-community-list.component.html | 26 ++-- src/app/+search-page/search-page.component.ts | 15 +++ src/app/+search-page/search-page.module.ts | 15 ++- src/app/+search-page/search-result.model.ts | 2 +- .../search-results.component.html | 4 +- .../search-service/search.service.ts | 2 +- src/app/core/shared/dspace-object.model.ts | 2 +- .../object-collection.component.html | 13 ++ .../object-collection.component.scss | 1 + .../object-collection.component.ts | 113 ++++++++++++++++++ .../shared/item-search-result.model.ts | 5 + .../shared}/listable-object.model.ts | 0 .../collection-grid-element.component.html | 12 ++ .../collection-grid-element.component.scss | 2 + .../collection-grid-element.component.ts | 14 +++ .../community-grid-element.component.html | 12 ++ .../community-grid-element.component.scss | 2 + .../community-grid-element.component.ts | 14 +++ src/app/object-grid/grid-card-styling.scss | 36 ++++++ src/app/object-grid/grid-element-decorator.ts | 16 +++ .../item-grid-element.component.html | 20 ++++ .../item-grid-element.component.scss | 2 + .../item-grid-element.component.ts | 14 +++ .../object-grid-element.component.html | 0 .../object-grid-element.component.scss | 6 + .../object-grid-element.component.ts | 14 +++ .../object-grid/object-grid.component.html | 23 ++++ .../object-grid/object-grid.component.scss | 1 + src/app/object-grid/object-grid.component.ts | 86 +++++++++++++ ...-search-result-grid-element.component.html | 2 + ...-search-result-grid-element.component.scss | 2 + ...on-search-result-grid-element.component.ts | 15 +++ .../collection-search-result.model.ts | 5 + ...-search-result-grid-element.component.html | 2 + ...-search-result-grid-element.component.scss | 2 + ...ty-search-result-grid-element.component.ts | 17 +++ .../community-search-result.model.ts | 5 + ...-search-result-grid-element.component.html | 27 +++++ ...-search-result-grid-element.component.scss | 2 + ...em-search-result-grid-element.component.ts | 15 +++ .../search-result-grid-element.component.scss | 8 ++ .../search-result-grid-element.component.ts | 57 +++++++++ .../wrapper-grid-element.component.html | 1 + .../wrapper-grid-element.component.scss | 2 + .../wrapper-grid-element.component.ts | 27 +++++ src/app/object-list/list-element-decorator.ts | 2 +- .../object-list-element.component.ts | 2 +- src/app/object-list/object-list.component.ts | 4 +- ...em-search-result-list-element.component.ts | 2 +- .../item-search-result.model.ts | 5 - .../search-result-list-element.component.ts | 2 +- .../wrapper-list-element.component.ts | 2 +- src/app/shared/shared.module.ts | 35 ++++-- src/styles/_mixins.scss | 1 + yarn.lock | 4 + 58 files changed, 684 insertions(+), 49 deletions(-) create mode 100644 src/app/object-collection/object-collection.component.html create mode 100644 src/app/object-collection/object-collection.component.scss create mode 100644 src/app/object-collection/object-collection.component.ts create mode 100644 src/app/object-collection/shared/item-search-result.model.ts rename src/app/{object-list/listable-object => object-collection/shared}/listable-object.model.ts (100%) create mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.html create mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.scss create mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.ts create mode 100644 src/app/object-grid/community-grid-element/community-grid-element.component.html create mode 100644 src/app/object-grid/community-grid-element/community-grid-element.component.scss create mode 100644 src/app/object-grid/community-grid-element/community-grid-element.component.ts create mode 100644 src/app/object-grid/grid-card-styling.scss create mode 100644 src/app/object-grid/grid-element-decorator.ts create mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.html create mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.scss create mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.ts create mode 100644 src/app/object-grid/object-grid-element/object-grid-element.component.html create mode 100644 src/app/object-grid/object-grid-element/object-grid-element.component.scss create mode 100644 src/app/object-grid/object-grid-element/object-grid-element.component.ts create mode 100644 src/app/object-grid/object-grid.component.html create mode 100644 src/app/object-grid/object-grid.component.scss create mode 100644 src/app/object-grid/object-grid.component.ts create mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html create mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss create mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts create mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts create mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html create mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss create mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts create mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts create mode 100644 src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html create mode 100644 src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss create mode 100644 src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts create mode 100644 src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss create mode 100644 src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts create mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html create mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss create mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts delete mode 100644 src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts diff --git a/package.json b/package.json index f2bb074ff4..662b4b627f 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,7 @@ "methods": "1.1.2", "morgan": "1.9.0", "ngx-pagination": "3.0.1", + "object-fit-images": "^3.2.3", "pem": "1.12.3", "reflect-metadata": "0.1.10", "rxjs": "5.4.3", diff --git a/src/app/+collection-page/collection-page.component.html b/src/app/+collection-page/collection-page.component.html index fe5b2a1f16..05b4d6f11e 100644 --- a/src/app/+collection-page/collection-page.component.html +++ b/src/app/+collection-page/collection-page.component.html @@ -41,13 +41,13 @@

      {{'collection.page.browse.recent.head' | translate}}

      - - +
      diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html index b04e93ff71..f78b212bee 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html @@ -2,12 +2,8 @@

      {{'community.sub-collection-list.head' | translate}}

      diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html index a34951afe0..4eebb53e1e 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html @@ -1,15 +1,13 @@ -
      -

      {{'home.top-level-communities.head' | translate}}

      -

      {{'home.top-level-communities.help' | translate}}

      - - -
      - - -
      +
      +

      {{'home.top-level-communities.head' | translate}}

      +

      {{'home.top-level-communities.help' | translate}}

      + + +
      + +
      diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 153402d11f..d50f5e9442 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -51,7 +51,22 @@ export class SearchPageComponent implements OnInit, OnDestroy { ); this.scopeListRDObs = communityService.findAll(); // Initial pagination config + const pagination: PaginationComponentOptions = new PaginationComponentOptions(); + pagination.id = 'search-results-pagination'; + pagination.currentPage = 1; + pagination.pageSize = 10; + + // TODO Update to accommodate view switcher + this.route.queryParams.map((params) => { + if (isNotEmpty(params.view) && params.view == 'grid') { + pagination.pageSize = 12; + } + }); + + + const sort: SortOptions = new SortOptions(); this.searchOptions = this.service.searchOptions; + } ngOnInit(): void { diff --git a/src/app/+search-page/search-page.module.ts b/src/app/+search-page/search-page.module.ts index 6519d1e92a..be99a0eae4 100644 --- a/src/app/+search-page/search-page.module.ts +++ b/src/app/+search-page/search-page.module.ts @@ -7,6 +7,9 @@ import { SearchResultsComponent } from './search-results/search-results.componen import { ItemSearchResultListElementComponent } from '../object-list/search-result-list-element/item-search-result/item-search-result-list-element.component'; import { CollectionSearchResultListElementComponent } from '../object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component'; import { CommunitySearchResultListElementComponent } from '../object-list/search-result-list-element/community-search-result/community-search-result-list-element.component'; +import { ItemSearchResultGridElementComponent } from '../object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component'; +import { CommunitySearchResultGridElementComponent } from '../object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component' +import { CollectionSearchResultGridElementComponent } from '../object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component'; import { SearchService } from './search-service/search.service'; import { SearchSidebarComponent } from './search-sidebar/search-sidebar.component'; import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; @@ -37,6 +40,10 @@ const effects = [ ItemSearchResultListElementComponent, CollectionSearchResultListElementComponent, CommunitySearchResultListElementComponent, + ItemSearchResultGridElementComponent, + CollectionSearchResultGridElementComponent, + CommunitySearchResultGridElementComponent, + CommunitySearchResultListElementComponent, SearchFiltersComponent, SearchFilterComponent, SearchFacetFilterComponent @@ -49,7 +56,11 @@ const effects = [ entryComponents: [ ItemSearchResultListElementComponent, CollectionSearchResultListElementComponent, - CommunitySearchResultListElementComponent + CommunitySearchResultListElementComponent, + ItemSearchResultGridElementComponent, + CollectionSearchResultGridElementComponent, + CommunitySearchResultGridElementComponent, ] }) -export class SearchPageModule { } +export class SearchPageModule { +} diff --git a/src/app/+search-page/search-result.model.ts b/src/app/+search-page/search-result.model.ts index 2dd9130ee8..602d8ac9c2 100644 --- a/src/app/+search-page/search-result.model.ts +++ b/src/app/+search-page/search-result.model.ts @@ -1,6 +1,6 @@ import { DSpaceObject } from '../core/shared/dspace-object.model'; import { Metadatum } from '../core/shared/metadatum.model'; -import { ListableObject } from '../object-list/listable-object/listable-object.model'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; export class SearchResult implements ListableObject { diff --git a/src/app/+search-page/search-results/search-results.component.html b/src/app/+search-page/search-results/search-results.component.html index 70e315671b..1b9bd7d52a 100644 --- a/src/app/+search-page/search-results/search-results.component.html +++ b/src/app/+search-page/search-results/search-results.component.html @@ -1,10 +1,10 @@

      {{ 'search.results.head' | translate }}

      - -
      +
      diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 4b5ba7b702..5258756bfb 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -9,10 +9,10 @@ import { SearchOptions } from '../search-options.model'; import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { Metadatum } from '../../core/shared/metadatum.model'; import { Item } from '../../core/shared/item.model'; -import { ItemSearchResult } from '../../object-list/search-result-list-element/item-search-result/item-search-result.model'; import { SearchFilterConfig } from './search-filter-config.model'; import { FilterType } from './filter-type.model'; import { FacetValue } from './facet-value.model'; +import { ItemSearchResult } from '../../object-collection/shared/item-search-result.model'; import { ViewMode } from '../../+search-page/search-options.model'; import { Router, NavigationExtras, ActivatedRoute } from '@angular/router'; import { RouteService } from '../../shared/route.service'; diff --git a/src/app/core/shared/dspace-object.model.ts b/src/app/core/shared/dspace-object.model.ts index 572efecada..a17a6b31ce 100644 --- a/src/app/core/shared/dspace-object.model.ts +++ b/src/app/core/shared/dspace-object.model.ts @@ -3,7 +3,7 @@ import { isEmpty, isNotEmpty } from '../../shared/empty.util'; import { CacheableObject } from '../cache/object-cache.reducer'; import { RemoteData } from '../data/remote-data'; import { ResourceType } from './resource-type'; -import { ListableObject } from '../../object-list/listable-object/listable-object.model'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; import { Observable } from 'rxjs/Observable'; /** diff --git a/src/app/object-collection/object-collection.component.html b/src/app/object-collection/object-collection.component.html new file mode 100644 index 0000000000..e651c18290 --- /dev/null +++ b/src/app/object-collection/object-collection.component.html @@ -0,0 +1,13 @@ + + + + + + + diff --git a/src/app/object-collection/object-collection.component.scss b/src/app/object-collection/object-collection.component.scss new file mode 100644 index 0000000000..da97dd7a62 --- /dev/null +++ b/src/app/object-collection/object-collection.component.scss @@ -0,0 +1 @@ +@import '../../styles/variables.scss'; diff --git a/src/app/object-collection/object-collection.component.ts b/src/app/object-collection/object-collection.component.ts new file mode 100644 index 0000000000..25761073e4 --- /dev/null +++ b/src/app/object-collection/object-collection.component.ts @@ -0,0 +1,113 @@ +import { Component, EventEmitter, + Input, + OnInit, + Output, SimpleChanges, OnChanges, ChangeDetectorRef } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; + +import { Observable } from 'rxjs/Observable'; + +import { RemoteData } from '../core/data/remote-data'; +import { PageInfo } from '../core/shared/page-info.model'; + +import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; + +import { SortDirection } from '../core/cache/models/sort-options.model'; + +import { ListableObject } from './shared/listable-object.model'; +import { hasValue, isNotEmpty } from '../shared/empty.util'; +@Component({ + selector: 'ds-viewable-collection', + styleUrls: ['./object-collection.component.scss'], + templateUrl: './object-collection.component.html', +}) +export class ObjectCollectionComponent implements OnChanges, OnInit { + + @Input() objects: RemoteData; + @Input() config?: PaginationComponentOptions; + pageInfo: Observable; + + /** + * An event fired when the page is changed. + * Event's payload equals to the newly selected page. + */ + @Output() pageChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the page wsize is changed. + * Event's payload equals to the newly selected page size. + */ + @Output() pageSizeChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort direction is changed. + * Event's payload equals to the newly selected sort direction. + */ + @Output() sortDirectionChange: EventEmitter = new EventEmitter(); + + @Output() paginationChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort field is changed. + * Event's payload equals to the newly selected sort field. + */ + @Output() sortFieldChange: EventEmitter = new EventEmitter(); + data: any = {}; + defaultViewMode: string ='list'; + + ngOnChanges(changes: SimpleChanges) { + if (changes.objects && !changes.objects.isFirstChange()) { + this.pageInfo = this.objects.pageInfo; + } + } + + ngOnInit(): void { + this.pageInfo = this.objects.pageInfo; + } + + /** + * @param route + * Route is a singleton service provided by Angular. + * @param router + * Router is a singleton service provided by Angular. + */ + constructor(private cdRef: ChangeDetectorRef, private route: ActivatedRoute, + private router: Router) { + } + + getViewMode(): string { + // TODO Update to accommodate view switcher + + this.route.queryParams.map((params) => { + if (isNotEmpty(params.view) && hasValue(params.view)) { + return params.view; + } else { + return this.defaultViewMode; + } + }); + return this.defaultViewMode; + } + + setViewMode(viewMode: string) { + this.defaultViewMode = viewMode; + } + onPageChange(event) { + this.pageChange.emit(event); + } + + onPageSizeChange(event) { + this.pageSizeChange.emit(event); + } + + onSortDirectionChange(event) { + this.sortDirectionChange.emit(event); + } + + onSortFieldChange(event) { + this.sortFieldChange.emit(event); + } + + onPaginationChange(event) { + this.paginationChange.emit(event); + } + +} diff --git a/src/app/object-collection/shared/item-search-result.model.ts b/src/app/object-collection/shared/item-search-result.model.ts new file mode 100644 index 0000000000..75d56a2488 --- /dev/null +++ b/src/app/object-collection/shared/item-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../+search-page/search-result.model'; +import { Item } from '../../core/shared/item.model'; + +export class ItemSearchResult extends SearchResult { +} diff --git a/src/app/object-list/listable-object/listable-object.model.ts b/src/app/object-collection/shared/listable-object.model.ts similarity index 100% rename from src/app/object-list/listable-object/listable-object.model.ts rename to src/app/object-collection/shared/listable-object.model.ts diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.html b/src/app/object-grid/collection-grid-element/collection-grid-element.component.html new file mode 100644 index 0000000000..5dc717cf54 --- /dev/null +++ b/src/app/object-grid/collection-grid-element/collection-grid-element.component.html @@ -0,0 +1,12 @@ +
      + + + + +
      +

      {{object.name}}

      +

      {{object.shortDescription}}

      + View + +
      +
      diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss b/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss new file mode 100644 index 0000000000..48e2b121d4 --- /dev/null +++ b/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts new file mode 100644 index 0000000000..80be3d75b3 --- /dev/null +++ b/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -0,0 +1,14 @@ +import { Component, Inject } from '@angular/core'; + +import { Collection } from '../../core/shared/collection.model'; +import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { gridElementFor } from '../grid-element-decorator'; + +@Component({ + selector: 'ds-collection-grid-element', + styleUrls: ['./collection-grid-element.component.scss'], + templateUrl: './collection-grid-element.component.html' +}) + +@gridElementFor(Collection) +export class CollectionGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.html b/src/app/object-grid/community-grid-element/community-grid-element.component.html new file mode 100644 index 0000000000..e4ea3dcb13 --- /dev/null +++ b/src/app/object-grid/community-grid-element/community-grid-element.component.html @@ -0,0 +1,12 @@ +
      + + + + + +
      +

      {{object.name}}

      +

      {{object.shortDescription}}

      + View +
      +
      diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.scss b/src/app/object-grid/community-grid-element/community-grid-element.component.scss new file mode 100644 index 0000000000..48e2b121d4 --- /dev/null +++ b/src/app/object-grid/community-grid-element/community-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.ts b/src/app/object-grid/community-grid-element/community-grid-element.component.ts new file mode 100644 index 0000000000..e29e037c5d --- /dev/null +++ b/src/app/object-grid/community-grid-element/community-grid-element.component.ts @@ -0,0 +1,14 @@ +import { Component, Input, Inject } from '@angular/core'; + +import { Community } from '../../core/shared/community.model'; +import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { gridElementFor} from '../grid-element-decorator'; + +@Component({ + selector: 'ds-community-grid-element', + styleUrls: ['./community-grid-element.component.scss'], + templateUrl: './community-grid-element.component.html' +}) + +@gridElementFor(Community) +export class CommunityGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/grid-card-styling.scss b/src/app/object-grid/grid-card-styling.scss new file mode 100644 index 0000000000..52b78524b0 --- /dev/null +++ b/src/app/object-grid/grid-card-styling.scss @@ -0,0 +1,36 @@ +.card-title{ + line-height: 1em; + height:3em; + overflow: hidden; + text-overflow: ellipsis; +} + +.card-text { + overflow: hidden; + text-overflow: ellipsis; + line-height: 1em; + margin-bottom:10px; +} +.card-text.item-authors { + height: 1em; +} +.card-text.item-abstract { + height: 5em; + +} +.viewButton{ + display:block; +} + +.card{ + padding:10px; + margin-bottom: 15px; +} + +.card-img-top ::ng-deep img +{ + height: 120px; + width: 100%; + object-fit: cover; + margin-bottom: 10px; +} diff --git a/src/app/object-grid/grid-element-decorator.ts b/src/app/object-grid/grid-element-decorator.ts new file mode 100644 index 0000000000..cd5ebbcaeb --- /dev/null +++ b/src/app/object-grid/grid-element-decorator.ts @@ -0,0 +1,16 @@ +import { GenericConstructor } from '../core/shared/generic-constructor'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; + +const gridElementMap = new Map(); +export function gridElementFor(gridable: GenericConstructor) { + return function decorator(objectElement: any) { + if (!objectElement) { + return; + } + gridElementMap.set(gridable, objectElement); + }; +} + +export function getGridElementFor(gridable: GenericConstructor) { + return gridElementMap.get(gridable); +} diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.html b/src/app/object-grid/item-grid-element/item-grid-element.component.html new file mode 100644 index 0000000000..ea7b894896 --- /dev/null +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.html @@ -0,0 +1,20 @@ +
      + + + + + +
      +

      {{object.findMetadata('dc.title')}}

      +

      + {{authorMd.value}} + ; + +

      + ({{object.findMetadata("dc.publisher")}}, {{object.findMetadata("dc.date.issued")}}) + +

      {{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

      + + View +
      +
      diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.scss b/src/app/object-grid/item-grid-element/item-grid-element.component.scss new file mode 100644 index 0000000000..48e2b121d4 --- /dev/null +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.ts b/src/app/object-grid/item-grid-element/item-grid-element.component.ts new file mode 100644 index 0000000000..c651ccfc9c --- /dev/null +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.ts @@ -0,0 +1,14 @@ +import { Component, Input, Inject } from '@angular/core'; + +import { Item } from '../../core/shared/item.model'; +import { gridElementFor } from '../grid-element-decorator'; +import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; + +@Component({ + selector: 'ds-item-grid-element', + styleUrls: ['./item-grid-element.component.scss'], + templateUrl: './item-grid-element.component.html' +}) + +@gridElementFor(Item) +export class ItemGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.html b/src/app/object-grid/object-grid-element/object-grid-element.component.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/object-grid/object-grid-element/object-grid-element.component.scss new file mode 100644 index 0000000000..0351acf15f --- /dev/null +++ b/src/app/object-grid/object-grid-element/object-grid-element.component.scss @@ -0,0 +1,6 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; +:host { + display: block; + margin-bottom: $spacer; +} diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.ts b/src/app/object-grid/object-grid-element/object-grid-element.component.ts new file mode 100644 index 0000000000..c3ab5e39e3 --- /dev/null +++ b/src/app/object-grid/object-grid-element/object-grid-element.component.ts @@ -0,0 +1,14 @@ +import { Component, Inject } from '@angular/core'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; + +@Component({ + selector: 'ds-object-grid-element', + styleUrls: ['./object-grid-element.component.scss'], + templateUrl: './object-grid-element.component.html' +}) +export class ObjectGridElementComponent { + object: T; + public constructor(@Inject('objectElementProvider') public gridable: ListableObject) { + this.object = gridable as T; + } +} diff --git a/src/app/object-grid/object-grid.component.html b/src/app/object-grid/object-grid.component.html new file mode 100644 index 0000000000..2ad9c11a8f --- /dev/null +++ b/src/app/object-grid/object-grid.component.html @@ -0,0 +1,23 @@ + +
        +
        +
        + +
        +
        +
      + + +
      diff --git a/src/app/object-grid/object-grid.component.scss b/src/app/object-grid/object-grid.component.scss new file mode 100644 index 0000000000..da97dd7a62 --- /dev/null +++ b/src/app/object-grid/object-grid.component.scss @@ -0,0 +1 @@ +@import '../../styles/variables.scss'; diff --git a/src/app/object-grid/object-grid.component.ts b/src/app/object-grid/object-grid.component.ts new file mode 100644 index 0000000000..b316fe37c2 --- /dev/null +++ b/src/app/object-grid/object-grid.component.ts @@ -0,0 +1,86 @@ +import { + Component, EventEmitter, + Input, + ViewEncapsulation, + ChangeDetectionStrategy, + OnInit, + Output, SimpleChanges, OnChanges, ChangeDetectorRef, DoCheck +} from '@angular/core'; +import { Observable } from 'rxjs/Observable'; + +import { RemoteData } from '../core/data/remote-data'; +import { PageInfo } from '../core/shared/page-info.model'; + +import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; + +import { SortOptions, SortDirection } from '../core/cache/models/sort-options.model'; +import { fadeIn } from '../shared/animations/fade'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; + +@Component({ + changeDetection: ChangeDetectionStrategy.Default, + encapsulation: ViewEncapsulation.Emulated, + selector: 'ds-object-grid', + styleUrls: [ './object-grid.component.scss' ], + templateUrl: './object-grid.component.html', + animations: [fadeIn] +}) + +export class ObjectGridComponent implements OnChanges, OnInit { + + @Input() objects: RemoteData; + @Input() config: PaginationComponentOptions; + @Input() sortConfig: SortOptions; + @Input() hideGear = false; + @Input() hidePagerWhenSinglePage = true; + pageInfo: Observable; + + /** + * An event fired when the page is changed. + * Event's payload equals to the newly selected page. + */ + @Output() pageChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the page wsize is changed. + * Event's payload equals to the newly selected page size. + */ + @Output() pageSizeChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort direction is changed. + * Event's payload equals to the newly selected sort direction. + */ + @Output() sortDirectionChange: EventEmitter = new EventEmitter(); + + @Output() paginationChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort field is changed. + * Event's payload equals to the newly selected sort field. + */ + @Output() sortFieldChange: EventEmitter = new EventEmitter(); + data: any = {}; + + ngOnChanges(changes: SimpleChanges) { + if (changes.objects && !changes.objects.isFirstChange()) { + this.pageInfo = this.objects.pageInfo; + } + } + + ngOnInit(): void { + this.pageInfo = this.objects.pageInfo; + this.config.pageSize = 4; + } + + /** + * @param route + * Route is a singleton service provided by Angular. + * @param router + * Router is a singleton service provided by Angular. + */ + constructor(private cdRef: ChangeDetectorRef) { + } + + +} diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html new file mode 100644 index 0000000000..914fb49487 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html @@ -0,0 +1,2 @@ + +
      diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss new file mode 100644 index 0000000000..790f794381 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables.scss'; +@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts new file mode 100644 index 0000000000..aa1d495dba --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts @@ -0,0 +1,15 @@ +import { Component } from '@angular/core'; + +import { gridElementFor } from '../../grid-element-decorator'; +import { CollectionSearchResult } from './collection-search-result.model'; +import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; +import { Collection } from '../../../core/shared/collection.model'; + +@Component({ + selector: 'ds-collection-search-result-grid-element', + styleUrls: ['../search-result-grid-element.component.scss', 'collection-search-result-grid-element.component.scss'], + templateUrl: 'collection-search-result-grid-element.component.html' +}) + +@gridElementFor(CollectionSearchResult) +export class CollectionSearchResultGridElementComponent extends SearchResultGridElementComponent {} diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts new file mode 100644 index 0000000000..fa7945dedd --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../+search-page/search-result.model'; +import { Collection } from '../../../core/shared/collection.model'; + +export class CollectionSearchResult extends SearchResult { +} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html new file mode 100644 index 0000000000..d09ef7d668 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html @@ -0,0 +1,2 @@ + +
      diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss new file mode 100644 index 0000000000..790f794381 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables.scss'; +@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts new file mode 100644 index 0000000000..1ce9e1d09a --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts @@ -0,0 +1,17 @@ +import { Component } from '@angular/core'; + +import { CommunitySearchResult } from './community-search-result.model'; +import { Community } from '../../../core/shared/community.model'; +import { gridElementFor } from '../../grid-element-decorator'; +import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; + +@Component({ + selector: 'ds-community-search-result-grid-element', + styleUrls: ['../search-result-grid-element.component.scss', 'community-search-result-grid-element.component.scss'], + templateUrl: 'community-search-result-grid-element.component.html' +}) + +@gridElementFor(CommunitySearchResult) +export class CommunitySearchResultGridElementComponent extends SearchResultGridElementComponent { + +} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts new file mode 100644 index 0000000000..79ea34b6cd --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../+search-page/search-result.model'; +import { Community } from '../../../core/shared/community.model'; + +export class CommunitySearchResult extends SearchResult { +} diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html new file mode 100644 index 0000000000..c6e1bc6b14 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html @@ -0,0 +1,27 @@ +
      + + + + +
      +

      {{dso.findMetadata('dc.title')}}

      + +

      + {{authorMd.value}} + ; + +

      + ({{dso.findMetadata("dc.publisher")}}, {{dso.findMetadata("dc.date.issued")}}) + +

      + {{dso.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

      + +
      + View + +
      + diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss new file mode 100644 index 0000000000..790f794381 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables.scss'; +@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts new file mode 100644 index 0000000000..7a82803c9b --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts @@ -0,0 +1,15 @@ +import { Component } from '@angular/core'; + +import { gridElementFor } from '../../grid-element-decorator'; +import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; +import { Item } from '../../../core/shared/item.model'; +import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; + +@Component({ + selector: 'ds-item-search-result-grid-element', + styleUrls: ['../search-result-grid-element.component.scss', 'item-search-result-grid-element.component.scss'], + templateUrl: 'item-search-result-grid-element.component.html' +}) + +@gridElementFor(ItemSearchResult) +export class ItemSearchResultGridElementComponent extends SearchResultGridElementComponent {} diff --git a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss new file mode 100644 index 0000000000..0f2684f1f1 --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss @@ -0,0 +1,8 @@ + @import '../../../styles/variables.scss'; + @import '../grid-card-styling.scss'; +:host { + /deep/ em { + font-weight: bold; + font-style: normal; + } +} diff --git a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts new file mode 100644 index 0000000000..ba98a58d4b --- /dev/null +++ b/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts @@ -0,0 +1,57 @@ +import { Component, Inject } from '@angular/core'; + +import { SearchResult } from '../../+search-page/search-result.model'; +import { DSpaceObject } from '../../core/shared/dspace-object.model'; +import { Metadatum } from '../../core/shared/metadatum.model'; +import { isEmpty, hasNoValue } from '../../shared/empty.util'; +import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; + +@Component({ + selector: 'ds-search-result-grid-element', + template: `` +}) + +export class SearchResultGridElementComponent, K extends DSpaceObject> extends ObjectGridElementComponent { + dso: K; + + public constructor(@Inject('objectElementProvider') public gridable: ListableObject) { + super(gridable); + this.dso = this.object.dspaceObject; + } + + getValues(keys: string[]): string[] { + const results: string[] = new Array(); + this.object.hitHighlights.forEach( + (md: Metadatum) => { + if (keys.indexOf(md.key) > -1) { + results.push(md.value); + } + } + ); + if (isEmpty(results)) { + this.dso.filterMetadata(keys).forEach( + (md: Metadatum) => { + results.push(md.value); + } + ); + } + return results; + } + + getFirstValue(key: string): string { + let result: string; + this.object.hitHighlights.some( + (md: Metadatum) => { + if (key === md.key) { + result = md.value; + return true; + } + } + ); + if (hasNoValue(result)) { + result = this.dso.findMetadata(key); + } + return result; + } +} diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html new file mode 100644 index 0000000000..b613b16055 --- /dev/null +++ b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html @@ -0,0 +1 @@ + diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss new file mode 100644 index 0000000000..48e2b121d4 --- /dev/null +++ b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../styles/variables.scss'; +@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts new file mode 100644 index 0000000000..bd15a0d443 --- /dev/null +++ b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts @@ -0,0 +1,27 @@ +import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; +import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { getGridElementFor } from '../grid-element-decorator'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; + +@Component({ + selector: 'ds-wrapper-grid-element', + styleUrls: ['./wrapper-grid-element.component.scss'], + templateUrl: './wrapper-grid-element.component.html' +}) +export class WrapperGridElementComponent implements OnInit { + @Input() object: ListableObject; + objectInjector: Injector; + + constructor(private injector: Injector) {} + + ngOnInit(): void { + this.objectInjector = ReflectiveInjector.resolveAndCreate( + [{provide: 'objectElementProvider', useFactory: () => (this.object) }], this.injector); + + } + + getGridElement(): string { + const f: GenericConstructor = this.object.constructor as GenericConstructor; + return getGridElementFor(f); + } +} diff --git a/src/app/object-list/list-element-decorator.ts b/src/app/object-list/list-element-decorator.ts index 64a747d4a5..aa044755ea 100644 --- a/src/app/object-list/list-element-decorator.ts +++ b/src/app/object-list/list-element-decorator.ts @@ -1,5 +1,5 @@ -import { ListableObject } from './listable-object/listable-object.model'; import { GenericConstructor } from '../core/shared/generic-constructor'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; const listElementMap = new Map(); export function listElementFor(listable: GenericConstructor) { diff --git a/src/app/object-list/object-list-element/object-list-element.component.ts b/src/app/object-list/object-list-element/object-list-element.component.ts index df39a7d18d..24f0ec1d93 100644 --- a/src/app/object-list/object-list-element/object-list-element.component.ts +++ b/src/app/object-list/object-list-element/object-list-element.component.ts @@ -1,5 +1,5 @@ import { Component, Inject } from '@angular/core'; -import { ListableObject } from '../listable-object/listable-object.model'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ selector: 'ds-object-list-element', diff --git a/src/app/object-list/object-list.component.ts b/src/app/object-list/object-list.component.ts index 0f7decadd7..352d7bc393 100644 --- a/src/app/object-list/object-list.component.ts +++ b/src/app/object-list/object-list.component.ts @@ -11,9 +11,8 @@ import { SortDirection, SortOptions } from '../core/cache/models/sort-options.mo import { RemoteData } from '../core/data/remote-data'; import { PageInfo } from '../core/shared/page-info.model'; -import { ListableObject } from '../object-list/listable-object/listable-object.model'; - import { fadeIn } from '../shared/animations/fade'; +import { ListableObject } from '../object-collection/shared/listable-object.model'; import { hasValue } from '../shared/empty.util'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; @@ -83,6 +82,7 @@ export class ObjectListComponent { @Output() sortFieldChange: EventEmitter = new EventEmitter(); data: any = {}; + onPageChange(event) { this.pageChange.emit(event); } diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts index ef968db0b8..2974a87883 100644 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts @@ -1,9 +1,9 @@ import { Component } from '@angular/core'; import { listElementFor } from '../../list-element-decorator'; -import { ItemSearchResult } from './item-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; import { Item } from '../../../core/shared/item.model'; +import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; @Component({ selector: 'ds-item-search-result-list-element', diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts b/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts deleted file mode 100644 index d9af3539a0..0000000000 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Item } from '../../../core/shared/item.model'; - -export class ItemSearchResult extends SearchResult { -} diff --git a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/search-result-list-element.component.ts index 4119bc3c2e..ec0afde65d 100644 --- a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/search-result-list-element.component.ts @@ -1,11 +1,11 @@ import { Component, Inject } from '@angular/core'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { ListableObject } from '../listable-object/listable-object.model'; import { SearchResult } from '../../+search-page/search-result.model'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { Metadatum } from '../../core/shared/metadatum.model'; import { isEmpty, hasNoValue } from '../../shared/empty.util'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ selector: 'ds-search-result-list-element', diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts index 443b9681d1..2e1184b023 100644 --- a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts +++ b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts @@ -1,7 +1,7 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; -import { ListableObject } from '../listable-object/listable-object.model'; import { getListElementFor } from '../list-element-decorator' import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ selector: 'ds-wrapper-list-element', diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 245d45ea4e..1ebf251e2c 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -15,20 +15,30 @@ import { SafeUrlPipe } from './utils/safe-url-pipe'; import { TruncatePipe } from './utils/truncate.pipe'; import { CollectionListElementComponent } from '../object-list/collection-list-element/collection-list-element.component'; +import { CommunityListElementComponent } from '../object-list/community-list-element/community-list-element.component'; +import { ItemListElementComponent } from '../object-list/item-list-element/item-list-element.component'; +import { ObjectListElementComponent } from '../object-list/object-list-element/object-list-element.component'; +import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component'; +import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; +import { ObjectListComponent } from '../object-list/object-list.component'; + +import { CollectionGridElementComponent} from '../object-grid/collection-grid-element/collection-grid-element.component' +import { CommunityGridElementComponent} from '../object-grid/community-grid-element/community-grid-element.component' +import { ItemGridElementComponent} from '../object-grid/item-grid-element/item-grid-element.component' +import { ObjectGridElementComponent} from '../object-grid/object-grid-element/object-grid-element.component' +import { WrapperGridElementComponent} from '../object-grid/wrapper-grid-element/wrapper-grid-element.component' +import { ObjectGridComponent } from '../object-grid/object-grid.component'; +import { ObjectCollectionComponent } from '../object-collection/object-collection.component'; import { ComcolPageContentComponent } from './comcol-page-content/comcol-page-content.component'; import { ComcolPageHeaderComponent } from './comcol-page-header/comcol-page-header.component'; import { ComcolPageLogoComponent } from './comcol-page-logo/comcol-page-logo.component'; -import { CommunityListElementComponent } from '../object-list/community-list-element/community-list-element.component'; import { ErrorComponent } from './error/error.component'; import { LoadingComponent } from './loading/loading.component'; -import { ItemListElementComponent } from '../object-list/item-list-element/item-list-element.component'; -import { ObjectListComponent } from '../object-list/object-list.component'; -import { ObjectListElementComponent } from '../object-list/object-list-element/object-list-element.component'; + import { PaginationComponent } from './pagination/pagination.component'; import { ThumbnailComponent } from '../thumbnail/thumbnail.component'; -import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component'; import { SearchFormComponent } from './search-form/search-form.component'; -import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; +import { SearchResultGridElementComponent } from '../object-grid/search-result-grid-element/search-result-grid-element.component'; import { ViewModeSwitchComponent } from './view-mode-switch/view-mode-switch.component'; import { VarDirective } from './utils/var.directive'; @@ -60,6 +70,11 @@ const COMPONENTS = [ LoadingComponent, ObjectListComponent, ObjectListElementComponent, + WrapperListElementComponent, + ObjectGridComponent, + ObjectGridElementComponent, + WrapperGridElementComponent, + ObjectCollectionComponent, PaginationComponent, SearchFormComponent, ThumbnailComponent, @@ -69,10 +84,14 @@ const COMPONENTS = [ const ENTRY_COMPONENTS = [ // put shared entry components (components that are created dynamically) here + ItemListElementComponent, CollectionListElementComponent, CommunityListElementComponent, - ItemListElementComponent, - SearchResultListElementComponent + SearchResultListElementComponent, + ItemGridElementComponent, + CollectionGridElementComponent, + CommunityGridElementComponent, + SearchResultGridElementComponent ]; const DIRECTIVES = [ diff --git a/src/styles/_mixins.scss b/src/styles/_mixins.scss index 73aa27eccc..7d05343152 100644 --- a/src/styles/_mixins.scss +++ b/src/styles/_mixins.scss @@ -2,3 +2,4 @@ @import '../../node_modules/bootstrap/scss/mixins.scss'; /* Custom mixins go here */ + diff --git a/yarn.lock b/yarn.lock index 91b2a787e2..4211b7228a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4804,6 +4804,10 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" +object-fit-images@^3.2.3: + version "3.2.3" + resolved "https://registry.yarnpkg.com/object-fit-images/-/object-fit-images-3.2.3.tgz#4089f6d0070a3b5563d3c1ab6f1b28d61331f0ac" + object-keys@^1.0.8: version "1.0.11" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d" From 17f839f9e1eb33ebf82538b08bc9ca7d9f1c718f Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 31 Oct 2017 13:28:48 +0100 Subject: [PATCH 36/77] #150 SortOptions config fixing --- ...ty-page-sub-collection-list.component.html | 15 ++++++------- .../top-level-community-list.component.html | 2 +- .../+search-page/search-page.component.html | 2 +- src/app/+search-page/search-page.component.ts | 7 +++--- .../search-results.component.ts | 2 ++ .../object-collection.component.html | 4 ++-- .../object-collection.component.ts | 22 +++++++++---------- src/app/object-grid/object-grid.component.ts | 19 ++++++++++++++++ ...-search-result-grid-element.component.html | 2 +- src/app/object-list/object-list.component.ts | 19 ++++++++++++++++ 10 files changed, 66 insertions(+), 28 deletions(-) diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html index f78b212bee..9494cdb755 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html @@ -1,11 +1,10 @@ -
      -

      {{'community.sub-collection-list.head' | translate}}

      -
        - - -
      -
      - +
      +

      {{'community.sub-collection-list.head' | translate}}

      +
        + +
      +
      diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html index 4eebb53e1e..934bb3933c 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html @@ -4,8 +4,8 @@

      {{'home.top-level-communities.help' | translate}}

      diff --git a/src/app/+search-page/search-page.component.html b/src/app/+search-page/search-page.component.html index c4d679f72b..68a7bf6a9e 100644 --- a/src/app/+search-page/search-page.component.html +++ b/src/app/+search-page/search-page.component.html @@ -30,7 +30,7 @@
      + [searchConfig]="searchOptions" [sortConfig]="sortConfig">
      diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index d50f5e9442..d5f220d2b1 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -6,7 +6,7 @@ import { RemoteData } from '../core/data/remote-data'; import { Community } from '../core/shared/community.model'; import { DSpaceObject } from '../core/shared/dspace-object.model'; import { isNotEmpty } from '../shared/empty.util'; -import { SearchOptions } from './search-options.model'; +import { SearchOptions,ViewMode } from './search-options.model'; import { SearchResult } from './search-result.model'; import { SearchService } from './search-service/search.service'; import { pushInOut } from '../shared/animations/push'; @@ -36,6 +36,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { resultsRDObs: Observable>>>; currentParams = {}; searchOptions: SearchOptions; + sortConfig: SortOptions; scopeListRDObs: Observable>; isMobileView: Observable; @@ -58,15 +59,15 @@ export class SearchPageComponent implements OnInit, OnDestroy { // TODO Update to accommodate view switcher this.route.queryParams.map((params) => { - if (isNotEmpty(params.view) && params.view == 'grid') { + if (isNotEmpty(params.view) && params.view == ViewMode.Grid) { pagination.pageSize = 12; } }); const sort: SortOptions = new SortOptions(); + this.sortConfig=sort; this.searchOptions = this.service.searchOptions; - } ngOnInit(): void { diff --git a/src/app/+search-page/search-results/search-results.component.ts b/src/app/+search-page/search-results/search-results.component.ts index 4733699f95..f8b3721630 100644 --- a/src/app/+search-page/search-results/search-results.component.ts +++ b/src/app/+search-page/search-results/search-results.component.ts @@ -3,6 +3,7 @@ import { RemoteData } from '../../core/data/remote-data'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { fadeIn, fadeInOut } from '../../shared/animations/fade'; import { SearchOptions } from '../search-options.model'; +import { SortOptions } from '../../core/cache/models/sort-options.model'; import { SearchResult } from '../search-result.model'; /** @@ -21,4 +22,5 @@ import { SearchResult } from '../search-result.model'; export class SearchResultsComponent { @Input() searchResults: RemoteData>>; @Input() searchConfig: SearchOptions; + @Input() sortConfig: SortOptions; } diff --git a/src/app/object-collection/object-collection.component.html b/src/app/object-collection/object-collection.component.html index e651c18290..6c2a2fb1de 100644 --- a/src/app/object-collection/object-collection.component.html +++ b/src/app/object-collection/object-collection.component.html @@ -1,13 +1,13 @@ + *ngIf="getViewMode()===viewModeEnum.List"> + *ngIf="getViewMode()===viewModeEnum.Grid"> diff --git a/src/app/object-collection/object-collection.component.ts b/src/app/object-collection/object-collection.component.ts index 25761073e4..5a6d06509b 100644 --- a/src/app/object-collection/object-collection.component.ts +++ b/src/app/object-collection/object-collection.component.ts @@ -11,10 +11,12 @@ import { PageInfo } from '../core/shared/page-info.model'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; -import { SortDirection } from '../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; import { ListableObject } from './shared/listable-object.model'; +import { ViewMode } from '../+search-page/search-options.model'; import { hasValue, isNotEmpty } from '../shared/empty.util'; + @Component({ selector: 'ds-viewable-collection', styleUrls: ['./object-collection.component.scss'], @@ -24,6 +26,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { @Input() objects: RemoteData; @Input() config?: PaginationComponentOptions; + @Input() sortConfig: SortOptions; pageInfo: Observable; /** @@ -52,7 +55,8 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { */ @Output() sortFieldChange: EventEmitter = new EventEmitter(); data: any = {}; - defaultViewMode: string ='list'; + currentMode: ViewMode = ViewMode.List; + viewModeEnum = ViewMode; ngOnChanges(changes: SimpleChanges) { if (changes.objects && !changes.objects.isFirstChange()) { @@ -60,6 +64,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { } } + ngOnInit(): void { this.pageInfo = this.objects.pageInfo; } @@ -74,22 +79,15 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { private router: Router) { } - getViewMode(): string { - // TODO Update to accommodate view switcher - + getViewMode(): ViewMode { this.route.queryParams.map((params) => { if (isNotEmpty(params.view) && hasValue(params.view)) { - return params.view; - } else { - return this.defaultViewMode; + this.currentMode= params.view; } }); - return this.defaultViewMode; + return this.currentMode; } - setViewMode(viewMode: string) { - this.defaultViewMode = viewMode; - } onPageChange(event) { this.pageChange.emit(event); } diff --git a/src/app/object-grid/object-grid.component.ts b/src/app/object-grid/object-grid.component.ts index b316fe37c2..02931165c8 100644 --- a/src/app/object-grid/object-grid.component.ts +++ b/src/app/object-grid/object-grid.component.ts @@ -82,5 +82,24 @@ export class ObjectGridComponent implements OnChanges, OnInit { constructor(private cdRef: ChangeDetectorRef) { } + onPageChange(event) { + this.pageChange.emit(event); + } + + onPageSizeChange(event) { + this.pageSizeChange.emit(event); + } + + onSortDirectionChange(event) { + this.sortDirectionChange.emit(event); + } + + onSortFieldChange(event) { + this.sortFieldChange.emit(event); + } + + onPaginationChange(event) { + this.paginationChange.emit(event); + } } diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html index c6e1bc6b14..895e8b59c3 100644 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html @@ -20,8 +20,8 @@

      {{dso.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

      + View
      - View
      diff --git a/src/app/object-list/object-list.component.ts b/src/app/object-list/object-list.component.ts index 352d7bc393..9422d1d843 100644 --- a/src/app/object-list/object-list.component.ts +++ b/src/app/object-list/object-list.component.ts @@ -103,4 +103,23 @@ export class ObjectListComponent { this.paginationChange.emit(event); } + onPageChange(event) { + this.pageChange.emit(event); + } + + onPageSizeChange(event) { + this.pageSizeChange.emit(event); + } + + onSortDirectionChange(event) { + this.sortDirectionChange.emit(event); + } + + onSortFieldChange(event) { + this.sortFieldChange.emit(event); + } + + onPaginationChange(event) { + this.paginationChange.emit(event); + } } From c5bfbeaa00e8309a0a4766895943ae3be221485f Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 31 Oct 2017 13:51:08 +0100 Subject: [PATCH 37/77] #150 Pre grid/list decorator generalisation commit --- src/app/object-grid/object-grid.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/object-grid/object-grid.component.html b/src/app/object-grid/object-grid.component.html index 2ad9c11a8f..7abfaf28d3 100644 --- a/src/app/object-grid/object-grid.component.html +++ b/src/app/object-grid/object-grid.component.html @@ -12,7 +12,7 @@ (paginationChange)="onPaginationChange($event)">
        -
        From 491d40c026fbf712774ce7a40fdb4b4c3ce88800 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 31 Oct 2017 14:47:52 +0100 Subject: [PATCH 38/77] #150 Intermediate commit --- src/app/+search-page/search-page.component.ts | 10 ++-------- .../object-collection/object-collection.component.ts | 10 +++++++++- src/app/object-grid/object-grid.component.ts | 1 - 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index d5f220d2b1..0d9064dc87 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -57,14 +57,6 @@ export class SearchPageComponent implements OnInit, OnDestroy { pagination.currentPage = 1; pagination.pageSize = 10; - // TODO Update to accommodate view switcher - this.route.queryParams.map((params) => { - if (isNotEmpty(params.view) && params.view == ViewMode.Grid) { - pagination.pageSize = 12; - } - }); - - const sort: SortOptions = new SortOptions(); this.sortConfig=sort; this.searchOptions = this.service.searchOptions; @@ -80,6 +72,8 @@ export class SearchPageComponent implements OnInit, OnDestroy { this.scope = params.scope; const page = +params.page || this.searchOptions.pagination.currentPage; const pageSize = +params.pageSize || this.searchOptions.pagination.pageSize; + + const sortDirection = +params.sortDirection || this.searchOptions.sort.direction; const pagination = Object.assign({}, this.searchOptions.pagination, diff --git a/src/app/object-collection/object-collection.component.ts b/src/app/object-collection/object-collection.component.ts index 5a6d06509b..a79653d970 100644 --- a/src/app/object-collection/object-collection.component.ts +++ b/src/app/object-collection/object-collection.component.ts @@ -28,7 +28,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { @Input() config?: PaginationComponentOptions; @Input() sortConfig: SortOptions; pageInfo: Observable; - + private sub; /** * An event fired when the page is changed. * Event's payload equals to the newly selected page. @@ -67,6 +67,14 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { ngOnInit(): void { this.pageInfo = this.objects.pageInfo; + + this.sub = this.route + .queryParams + .subscribe((params) => { + if(isNotEmpty(params.view)){ + this.currentMode = params.view; + } + }); } /** diff --git a/src/app/object-grid/object-grid.component.ts b/src/app/object-grid/object-grid.component.ts index 02931165c8..a6b62d735f 100644 --- a/src/app/object-grid/object-grid.component.ts +++ b/src/app/object-grid/object-grid.component.ts @@ -70,7 +70,6 @@ export class ObjectGridComponent implements OnChanges, OnInit { ngOnInit(): void { this.pageInfo = this.objects.pageInfo; - this.config.pageSize = 4; } /** From e7e129f80f59269063180ec75392d431b781ec44 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 2 Nov 2017 10:53:18 +0100 Subject: [PATCH 39/77] #150 Intermediate commit --- src/app/+search-page/search-page.component.ts | 14 ++++++- src/app/object-grid/grid-card-styling.scss | 33 +++++++++------ .../grid-thumbnail.component.html | 4 ++ .../grid-thumbnail.component.scss | 1 + .../grid-thumbnail.component.spec.ts | 42 +++++++++++++++++++ .../grid-thumbnail.component.ts | 30 +++++++++++++ .../item-grid-element.component.html | 9 ++-- .../object-grid/object-grid.component.html | 4 +- ...-search-result-grid-element.component.html | 31 ++++++++------ src/app/shared/shared.module.ts | 2 + src/styles/_custom_variables.scss | 2 +- 11 files changed, 137 insertions(+), 35 deletions(-) create mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html create mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss create mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts create mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 0d9064dc87..697e379f3d 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -71,18 +71,27 @@ export class SearchPageComponent implements OnInit, OnDestroy { this.query = params.query || ''; this.scope = params.scope; const page = +params.page || this.searchOptions.pagination.currentPage; - const pageSize = +params.pageSize || this.searchOptions.pagination.pageSize; + let pageSize = +params.pageSize || this.searchOptions.pagination.pageSize; + let pageSizeOptions: number[] = [5, 10, 20, 40, 60, 80, 100]; + + if (isNotEmpty(params.view) && params.view === ViewMode.Grid) { + pageSize = 12; + pageSizeOptions = [12, 24, 36, 48 , 50, 62, 74, 84]; + // pageSize = 9; + // pageSizeOptions = [9, 18, 27, 36 , 45, 54, 63, 72]; + } const sortDirection = +params.sortDirection || this.searchOptions.sort.direction; const pagination = Object.assign({}, this.searchOptions.pagination, - { currentPage: page, pageSize: pageSize } + { currentPage: page, pageSize: pageSize, pageSizeOptions: pageSizeOptions} ); const sort = Object.assign({}, this.searchOptions.sort, { direction: sortDirection, field: params.sortField } ); + this.updateSearchResults({ pagination: pagination, sort: sort @@ -98,6 +107,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { private updateSearchResults(searchOptions) { this.resultsRDObs = this.service.search(this.query, this.scope, searchOptions); + this.searchOptions = searchOptions; } ngOnDestroy() { diff --git a/src/app/object-grid/grid-card-styling.scss b/src/app/object-grid/grid-card-styling.scss index 52b78524b0..44f4183bfd 100644 --- a/src/app/object-grid/grid-card-styling.scss +++ b/src/app/object-grid/grid-card-styling.scss @@ -1,6 +1,9 @@ +@import '../../styles/custom_variables'; + .card-title{ - line-height: 1em; - height:3em; + line-height: $line-height-base; + height:$headings-line-height; + font-size:$headings-font-size; overflow: hidden; text-overflow: ellipsis; } @@ -8,29 +11,35 @@ .card-text { overflow: hidden; text-overflow: ellipsis; - line-height: 1em; - margin-bottom:10px; + line-height: $line-height-base; + margin-bottom:$card-block-margin-base*2; } .card-text.item-authors { - height: 1em; + height: $line-height-base; } .card-text.item-abstract { - height: 5em; - + height: $content-line-height; } + .viewButton{ - display:block; + display:table; + margin:auto; + width: $card-button-width; } .card{ - padding:10px; - margin-bottom: 15px; + margin-bottom: $card-block-margin-base *3; + height: 98%; } .card-img-top ::ng-deep img { - height: 120px; + height: $card-thumbnail-height; width: 100%; object-fit: cover; - margin-bottom: 10px; } + +.card-block{ + margin: $card-block-margin-base; +} + diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html new file mode 100644 index 0000000000..6221cbaba1 --- /dev/null +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html @@ -0,0 +1,4 @@ +
        + + +
        diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss new file mode 100644 index 0000000000..50be6f5ad0 --- /dev/null +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss @@ -0,0 +1 @@ +@import '../../../styles/variables.scss'; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts new file mode 100644 index 0000000000..f4ca434221 --- /dev/null +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts @@ -0,0 +1,42 @@ +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +import { ThumbnailComponent } from './thumbnail.component'; +import { Bitstream } from '../../core/shared/bitstream.model'; +import { SafeUrlPipe } from '../../shared/utils/safe-url-pipe'; + +describe('ThumbnailComponent', () => { + let comp: ThumbnailComponent; + let fixture: ComponentFixture; + let de: DebugElement; + let el: HTMLElement; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ThumbnailComponent, SafeUrlPipe] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ThumbnailComponent); + comp = fixture.componentInstance; // BannerComponent test instance + de = fixture.debugElement.query(By.css('div.thumbnail')); + el = de.nativeElement; + }); + + it('should display image', () => { + comp.thumbnail = new Bitstream(); + comp.thumbnail.content = 'test.url'; + fixture.detectChanges(); + const image: HTMLElement = de.query(By.css('img')).nativeElement; + expect(image.getAttribute('src')).toBe(comp.thumbnail.content); + }); + + it('should display placeholder', () => { + fixture.detectChanges(); + const image: HTMLElement = de.query(By.css('img')).nativeElement; + expect(image.getAttribute('src')).toBe(comp.holderSource); + }); + +}); diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts new file mode 100644 index 0000000000..7baa47b39e --- /dev/null +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts @@ -0,0 +1,30 @@ +import { Component, Input } from '@angular/core'; +import { Bitstream } from '../../core/shared/bitstream.model'; + +/** + * This component renders a given Bitstream as a thumbnail. + * One input parameter of type Bitstream is expected. + * If no Bitstream is provided, a holderjs image will be rendered instead. + */ + +@Component({ + selector: 'ds-grid-thumbnail', + styleUrls: ['./grid-thumbnail.component.scss'], + templateUrl: './grid-thumbnail.component.html' +}) +export class GridThumbnailComponent { + + @Input() thumbnail: Bitstream; + + data: any = {}; + + /** + * The default 'holder.js' image + */ + holderSource = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMjYwIiBoZWlnaHQ9IjE4MCIgdmlld0JveD0iMCAwIDI2MCAxODAiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjwhLS0KU291cmNlIFVSTDogaG9sZGVyLmpzLzEwMCV4MTgwL3RleHQ6Tm8gVGh1bWJuYWlsCkNyZWF0ZWQgd2l0aCBIb2xkZXIuanMgMi42LjAuCkxlYXJuIG1vcmUgYXQgaHR0cDovL2hvbGRlcmpzLmNvbQooYykgMjAxMi0yMDE1IEl2YW4gTWFsb3BpbnNreSAtIGh0dHA6Ly9pbXNreS5jbwotLT48ZGVmcz48c3R5bGUgdHlwZT0idGV4dC9jc3MiPjwhW0NEQVRBWyNob2xkZXJfMTVmNzJmMmFlMGIgdGV4dCB7IGZpbGw6I0FBQUFBQTtmb250LXdlaWdodDpib2xkO2ZvbnQtZmFtaWx5OkFyaWFsLCBIZWx2ZXRpY2EsIE9wZW4gU2Fucywgc2Fucy1zZXJpZiwgbW9ub3NwYWNlO2ZvbnQtc2l6ZToxM3B0IH0gXV0+PC9zdHlsZT48L2RlZnM+PGcgaWQ9ImhvbGRlcl8xNWY3MmYyYWUwYiI+PHJlY3Qgd2lkdGg9IjI2MCIgaGVpZ2h0PSIxODAiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSI3Mi4yNDIxODc1IiB5PSI5NiI+Tm8gVGh1bWJuYWlsPC90ZXh0PjwvZz48L2c+PC9zdmc+'; + + errorHandler(event) { + event.currentTarget.src = this.holderSource; + } + +} diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.html b/src/app/object-grid/item-grid-element/item-grid-element.component.html index ea7b894896..3fae55088e 100644 --- a/src/app/object-grid/item-grid-element/item-grid-element.component.html +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.html @@ -1,17 +1,18 @@
        - - + +

        {{object.findMetadata('dc.title')}}

        -

        + +

        {{authorMd.value}} ; + {{object.findMetadata("dc.date.issued")}}

        - ({{object.findMetadata("dc.publisher")}}, {{object.findMetadata("dc.date.issued")}})

        {{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

        diff --git a/src/app/object-grid/object-grid.component.html b/src/app/object-grid/object-grid.component.html index 7abfaf28d3..ebcf240d28 100644 --- a/src/app/object-grid/object-grid.component.html +++ b/src/app/object-grid/object-grid.component.html @@ -10,14 +10,12 @@ (sortDirectionChange)="onSortDirectionChange($event)" (sortFieldChange)="onSortDirectionChange($event)" (paginationChange)="onPaginationChange($event)"> -
          -
          +
          -
        diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html index 895e8b59c3..be84039416 100644 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html @@ -1,24 +1,29 @@
        - - + +
        -

        {{dso.findMetadata('dc.title')}}

        +

        -

        +

        {{authorMd.value}} - ; + *ngFor="let authorMd of dso.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']); let first=first;"> + + , ... + -

        - ({{dso.findMetadata("dc.publisher")}}, {{dso.findMetadata("dc.date.issued")}}) + + , + {{dso.findMetadata("dc.date.issued")}} -

        - {{dso.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

        + +

        +

        +

        View
        diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 1ebf251e2c..8ef05b2f89 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -40,6 +40,7 @@ import { ThumbnailComponent } from '../thumbnail/thumbnail.component'; import { SearchFormComponent } from './search-form/search-form.component'; import { SearchResultGridElementComponent } from '../object-grid/search-result-grid-element/search-result-grid-element.component'; import { ViewModeSwitchComponent } from './view-mode-switch/view-mode-switch.component'; +import { GridThumbnailComponent } from '../object-grid/grid-thumbnail/grid-thumbnail.component'; import { VarDirective } from './utils/var.directive'; const MODULES = [ @@ -78,6 +79,7 @@ const COMPONENTS = [ PaginationComponent, SearchFormComponent, ThumbnailComponent, + GridThumbnailComponent, WrapperListElementComponent, ViewModeSwitchComponent ]; diff --git a/src/styles/_custom_variables.scss b/src/styles/_custom_variables.scss index 12ebfd6618..f52a99f014 100644 --- a/src/styles/_custom_variables.scss +++ b/src/styles/_custom_variables.scss @@ -1,3 +1,3 @@ $content-spacing: $spacer * 1.5; -$button-height: $input-btn-padding-y * 2 + $input-btn-line-height + calculateRem($input-btn-border-width*2); \ No newline at end of file +$button-height: $input-btn-padding-y * 2 + $input-btn-line-height + calculateRem($input-btn-border-width*2); From 67356efaab30c37e4329a7892a25a4477e93aba6 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 2 Nov 2017 13:43:02 +0100 Subject: [PATCH 40/77] #150 Intermediate commit --- .../search-results/search-results.component.ts | 3 ++- .../shared/dso-element-decorator.ts | 17 +++++++++++++++++ .../collection-grid-element.component.ts | 6 ++++-- .../community-grid-element.component.ts | 5 +++-- src/app/object-grid/grid-card-styling.scss | 2 +- src/app/object-grid/grid-element-decorator.ts | 16 ---------------- .../item-grid-element.component.ts | 5 +++-- ...tion-search-result-grid-element.component.ts | 6 ++++-- ...nity-search-result-grid-element.component.ts | 5 +++-- ...item-search-result-grid-element.component.ts | 5 +++-- .../wrapper-grid-element.component.ts | 5 +++-- .../collection-list-element.component.ts | 5 +++-- .../community-list-element.component.ts | 5 +++-- .../item-list-element.component.ts | 5 +++-- src/app/object-list/list-element-decorator.ts | 16 ---------------- src/app/object-list/object-list.component.html | 2 +- ...tion-search-result-list-element.component.ts | 5 +++-- ...nity-search-result-list-element.component.ts | 5 +++-- ...item-search-result-list-element.component.ts | 5 +++-- .../wrapper-list-element.component.ts | 6 +++--- src/styles/_custom_variables.scss | 1 + 21 files changed, 66 insertions(+), 64 deletions(-) create mode 100644 src/app/object-collection/shared/dso-element-decorator.ts delete mode 100644 src/app/object-grid/grid-element-decorator.ts diff --git a/src/app/+search-page/search-results/search-results.component.ts b/src/app/+search-page/search-results/search-results.component.ts index f8b3721630..4b3fec4565 100644 --- a/src/app/+search-page/search-results/search-results.component.ts +++ b/src/app/+search-page/search-results/search-results.component.ts @@ -2,7 +2,7 @@ import { Component, Input } from '@angular/core'; import { RemoteData } from '../../core/data/remote-data'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { fadeIn, fadeInOut } from '../../shared/animations/fade'; -import { SearchOptions } from '../search-options.model'; +import { SearchOptions, ViewMode } from '../search-options.model'; import { SortOptions } from '../../core/cache/models/sort-options.model'; import { SearchResult } from '../search-result.model'; @@ -23,4 +23,5 @@ export class SearchResultsComponent { @Input() searchResults: RemoteData>>; @Input() searchConfig: SearchOptions; @Input() sortConfig: SortOptions; + @Input() viewMode: ViewMode; } diff --git a/src/app/object-collection/shared/dso-element-decorator.ts b/src/app/object-collection/shared/dso-element-decorator.ts new file mode 100644 index 0000000000..310a65f056 --- /dev/null +++ b/src/app/object-collection/shared/dso-element-decorator.ts @@ -0,0 +1,17 @@ +import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { ListableObject } from './listable-object.model'; +import { ViewMode } from '../../+search-page/search-options.model'; + +const dsoElementMap = new Map(); +export function renderElementsFor(listable: GenericConstructor, viewMode : ViewMode) { + return function decorator(objectElement: any) { + if (!objectElement) { + return; + } + dsoElementMap.set(listable+viewMode, objectElement); + }; +} + +export function rendersDSOType(listable: GenericConstructor, viewMode : ViewMode) { + return dsoElementMap.get(listable+viewMode); +} diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts index 80be3d75b3..7e2ae5f468 100644 --- a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts +++ b/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -2,7 +2,9 @@ import { Component, Inject } from '@angular/core'; import { Collection } from '../../core/shared/collection.model'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; -import { gridElementFor } from '../grid-element-decorator'; +import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; + @Component({ selector: 'ds-collection-grid-element', @@ -10,5 +12,5 @@ import { gridElementFor } from '../grid-element-decorator'; templateUrl: './collection-grid-element.component.html' }) -@gridElementFor(Collection) +@renderElementsFor(Collection, ViewMode.Grid) export class CollectionGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.ts b/src/app/object-grid/community-grid-element/community-grid-element.component.ts index e29e037c5d..76ee6736be 100644 --- a/src/app/object-grid/community-grid-element/community-grid-element.component.ts +++ b/src/app/object-grid/community-grid-element/community-grid-element.component.ts @@ -2,7 +2,8 @@ import { Component, Input, Inject } from '@angular/core'; import { Community } from '../../core/shared/community.model'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; -import { gridElementFor} from '../grid-element-decorator'; +import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-community-grid-element', @@ -10,5 +11,5 @@ import { gridElementFor} from '../grid-element-decorator'; templateUrl: './community-grid-element.component.html' }) -@gridElementFor(Community) +@renderElementsFor(Community, ViewMode.Grid) export class CommunityGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/grid-card-styling.scss b/src/app/object-grid/grid-card-styling.scss index 44f4183bfd..b25c603b55 100644 --- a/src/app/object-grid/grid-card-styling.scss +++ b/src/app/object-grid/grid-card-styling.scss @@ -29,7 +29,7 @@ .card{ margin-bottom: $card-block-margin-base *3; - height: 98%; + height: $card-height-percentage; } .card-img-top ::ng-deep img diff --git a/src/app/object-grid/grid-element-decorator.ts b/src/app/object-grid/grid-element-decorator.ts deleted file mode 100644 index cd5ebbcaeb..0000000000 --- a/src/app/object-grid/grid-element-decorator.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { GenericConstructor } from '../core/shared/generic-constructor'; -import { ListableObject } from '../object-collection/shared/listable-object.model'; - -const gridElementMap = new Map(); -export function gridElementFor(gridable: GenericConstructor) { - return function decorator(objectElement: any) { - if (!objectElement) { - return; - } - gridElementMap.set(gridable, objectElement); - }; -} - -export function getGridElementFor(gridable: GenericConstructor) { - return gridElementMap.get(gridable); -} diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.ts b/src/app/object-grid/item-grid-element/item-grid-element.component.ts index c651ccfc9c..e11c51312a 100644 --- a/src/app/object-grid/item-grid-element/item-grid-element.component.ts +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.ts @@ -1,8 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; import { Item } from '../../core/shared/item.model'; -import { gridElementFor } from '../grid-element-decorator'; +import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-item-grid-element', @@ -10,5 +11,5 @@ import { ObjectGridElementComponent } from '../object-grid-element/object-grid-e templateUrl: './item-grid-element.component.html' }) -@gridElementFor(Item) +@renderElementsFor(Item, ViewMode.Grid) export class ItemGridElementComponent extends ObjectGridElementComponent {} diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts index aa1d495dba..6c5e526d15 100644 --- a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts +++ b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts @@ -1,9 +1,11 @@ import { Component } from '@angular/core'; -import { gridElementFor } from '../../grid-element-decorator'; +import { renderElementsFor} from '../../../object-collection/shared/dso-element-decorator'; + import { CollectionSearchResult } from './collection-search-result.model'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; import { Collection } from '../../../core/shared/collection.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-search-result-grid-element', @@ -11,5 +13,5 @@ import { Collection } from '../../../core/shared/collection.model'; templateUrl: 'collection-search-result-grid-element.component.html' }) -@gridElementFor(CollectionSearchResult) +@renderElementsFor(CollectionSearchResult, ViewMode.Grid) export class CollectionSearchResultGridElementComponent extends SearchResultGridElementComponent {} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts index 1ce9e1d09a..b6aa4bdb6d 100644 --- a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts +++ b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts @@ -2,8 +2,9 @@ import { Component } from '@angular/core'; import { CommunitySearchResult } from './community-search-result.model'; import { Community } from '../../../core/shared/community.model'; -import { gridElementFor } from '../../grid-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-search-result-grid-element', @@ -11,7 +12,7 @@ import { SearchResultGridElementComponent } from '../search-result-grid-element. templateUrl: 'community-search-result-grid-element.component.html' }) -@gridElementFor(CommunitySearchResult) +@renderElementsFor(CommunitySearchResult, ViewMode.Grid) export class CommunitySearchResultGridElementComponent extends SearchResultGridElementComponent { } diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts index 7a82803c9b..d4989d2efd 100644 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts +++ b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; -import { gridElementFor } from '../../grid-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; import { Item } from '../../../core/shared/item.model'; import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-search-result-grid-element', @@ -11,5 +12,5 @@ import { ItemSearchResult } from '../../../object-collection/shared/item-search- templateUrl: 'item-search-result-grid-element.component.html' }) -@gridElementFor(ItemSearchResult) +@renderElementsFor(ItemSearchResult, ViewMode.Grid) export class ItemSearchResultGridElementComponent extends SearchResultGridElementComponent {} diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts index bd15a0d443..000c826188 100644 --- a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts +++ b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts @@ -1,7 +1,8 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; import { GenericConstructor } from '../../core/shared/generic-constructor'; -import { getGridElementFor } from '../grid-element-decorator'; +import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-wrapper-grid-element', @@ -22,6 +23,6 @@ export class WrapperGridElementComponent implements OnInit { getGridElement(): string { const f: GenericConstructor = this.object.constructor as GenericConstructor; - return getGridElementFor(f); + return rendersDSOType(f, ViewMode.Grid); } } diff --git a/src/app/object-list/collection-list-element/collection-list-element.component.ts b/src/app/object-list/collection-list-element/collection-list-element.component.ts index a99e64a27f..c065a64b72 100644 --- a/src/app/object-list/collection-list-element/collection-list-element.component.ts +++ b/src/app/object-list/collection-list-element/collection-list-element.component.ts @@ -2,7 +2,8 @@ import { Component, Inject } from '@angular/core'; import { Collection } from '../../core/shared/collection.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { listElementFor } from '../list-element-decorator'; +import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-list-element', @@ -10,5 +11,5 @@ import { listElementFor } from '../list-element-decorator'; templateUrl: './collection-list-element.component.html' }) -@listElementFor(Collection) +@renderElementsFor(Collection, ViewMode.List) export class CollectionListElementComponent extends ObjectListElementComponent {} diff --git a/src/app/object-list/community-list-element/community-list-element.component.ts b/src/app/object-list/community-list-element/community-list-element.component.ts index c05915e8d7..11ff392942 100644 --- a/src/app/object-list/community-list-element/community-list-element.component.ts +++ b/src/app/object-list/community-list-element/community-list-element.component.ts @@ -2,7 +2,8 @@ import { Component, Input, Inject } from '@angular/core'; import { Community } from '../../core/shared/community.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { listElementFor } from '../list-element-decorator'; +import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-community-list-element', @@ -10,5 +11,5 @@ import { listElementFor } from '../list-element-decorator'; templateUrl: './community-list-element.component.html' }) -@listElementFor(Community) +@renderElementsFor(Community, ViewMode.List) export class CommunityListElementComponent extends ObjectListElementComponent {} diff --git a/src/app/object-list/item-list-element/item-list-element.component.ts b/src/app/object-list/item-list-element/item-list-element.component.ts index cc6c837bb7..bdc5733dcd 100644 --- a/src/app/object-list/item-list-element/item-list-element.component.ts +++ b/src/app/object-list/item-list-element/item-list-element.component.ts @@ -2,7 +2,8 @@ import { Component, Input, Inject } from '@angular/core'; import { Item } from '../../core/shared/item.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { listElementFor } from '../list-element-decorator'; +import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-item-list-element', @@ -10,5 +11,5 @@ import { listElementFor } from '../list-element-decorator'; templateUrl: './item-list-element.component.html' }) -@listElementFor(Item) +@renderElementsFor(Item, ViewMode.List) export class ItemListElementComponent extends ObjectListElementComponent {} diff --git a/src/app/object-list/list-element-decorator.ts b/src/app/object-list/list-element-decorator.ts index aa044755ea..e69de29bb2 100644 --- a/src/app/object-list/list-element-decorator.ts +++ b/src/app/object-list/list-element-decorator.ts @@ -1,16 +0,0 @@ -import { GenericConstructor } from '../core/shared/generic-constructor'; -import { ListableObject } from '../object-collection/shared/listable-object.model'; - -const listElementMap = new Map(); -export function listElementFor(listable: GenericConstructor) { - return function decorator(objectElement: any) { - if (!objectElement) { - return; - } - listElementMap.set(listable, objectElement); - }; -} - -export function getListElementFor(listable: GenericConstructor) { - return listElementMap.get(listable); -} diff --git a/src/app/object-list/object-list.component.html b/src/app/object-list/object-list.component.html index b97524d58c..0178533bda 100644 --- a/src/app/object-list/object-list.component.html +++ b/src/app/object-list/object-list.component.html @@ -12,7 +12,7 @@ (paginationChange)="onPaginationChange($event)">
        • - +
        diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts index 9bea14e9a1..1b5d7ef0ba 100644 --- a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; -import { listElementFor } from '../../list-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { CollectionSearchResult } from './collection-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; import { Collection } from '../../../core/shared/collection.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-search-result-list-element', @@ -11,5 +12,5 @@ import { Collection } from '../../../core/shared/collection.model'; templateUrl: 'collection-search-result-list-element.component.html' }) -@listElementFor(CollectionSearchResult) +@renderElementsFor(CollectionSearchResult, ViewMode.List) export class CollectionSearchResultListElementComponent extends SearchResultListElementComponent {} diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts index 741b4b4f65..d9ab001f58 100644 --- a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; -import { listElementFor } from '../../list-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { CommunitySearchResult } from './community-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; import { Community } from '../../../core/shared/community.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-search-result-list-element', @@ -11,7 +12,7 @@ import { Community } from '../../../core/shared/community.model'; templateUrl: 'community-search-result-list-element.component.html' }) -@listElementFor(CommunitySearchResult) +@renderElementsFor(CommunitySearchResult, ViewMode.List) export class CommunitySearchResultListElementComponent extends SearchResultListElementComponent { } diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts index 2974a87883..929233f1a3 100644 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; -import { listElementFor } from '../../list-element-decorator'; +import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; import { Item } from '../../../core/shared/item.model'; import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-search-result-list-element', @@ -11,5 +12,5 @@ import { ItemSearchResult } from '../../../object-collection/shared/item-search- templateUrl: 'item-search-result-list-element.component.html' }) -@listElementFor(ItemSearchResult) +@renderElementsFor(ItemSearchResult, ViewMode.List) export class ItemSearchResultListElementComponent extends SearchResultListElementComponent {} diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts index 2e1184b023..ff5591442d 100644 --- a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts +++ b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts @@ -1,7 +1,8 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; -import { getListElementFor } from '../list-element-decorator' +import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator' import { GenericConstructor } from '../../core/shared/generic-constructor'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { ViewMode } from '../../+search-page/search-options.model'; @Component({ selector: 'ds-wrapper-list-element', @@ -17,11 +18,10 @@ export class WrapperListElementComponent implements OnInit { ngOnInit(): void { this.objectInjector = ReflectiveInjector.resolveAndCreate( [{provide: 'objectElementProvider', useFactory: () => (this.object) }], this.injector); - } getListElement(): string { const f: GenericConstructor = this.object.constructor as GenericConstructor; - return getListElementFor(f); + return rendersDSOType(f, ViewMode.List); } } diff --git a/src/styles/_custom_variables.scss b/src/styles/_custom_variables.scss index f52a99f014..8c0dcae928 100644 --- a/src/styles/_custom_variables.scss +++ b/src/styles/_custom_variables.scss @@ -1,3 +1,4 @@ $content-spacing: $spacer * 1.5; $button-height: $input-btn-padding-y * 2 + $input-btn-line-height + calculateRem($input-btn-border-width*2); +$card-height-percentage:98%; From cc4aaa4c79d9a1551f639568c3852a5f4ad06a3a Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 3 Nov 2017 14:46:33 +0100 Subject: [PATCH 41/77] #150 Safety-commit before moving to "shared" package --- dspace-angular.iml | 8 +++ .../object-collection.component.spec.ts | 52 +++++++++++++++++++ .../shared/dso-element-decorator.spec.ts | 16 ++++++ .../collection-grid-element.component.spec.ts | 0 .../grid-thumbnail.component.spec.ts | 10 ++-- .../item-grid-element.component.spec.ts | 6 +++ .../object-grid/object-grid.component.spec.ts | 0 .../wrapper-grid-element.component.spec.ts | 0 8 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 dspace-angular.iml create mode 100644 src/app/object-collection/object-collection.component.spec.ts create mode 100644 src/app/object-collection/shared/dso-element-decorator.spec.ts create mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts create mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts create mode 100644 src/app/object-grid/object-grid.component.spec.ts create mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts diff --git a/dspace-angular.iml b/dspace-angular.iml new file mode 100644 index 0000000000..5806390693 --- /dev/null +++ b/dspace-angular.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/app/object-collection/object-collection.component.spec.ts b/src/app/object-collection/object-collection.component.spec.ts new file mode 100644 index 0000000000..abbf66e4f1 --- /dev/null +++ b/src/app/object-collection/object-collection.component.spec.ts @@ -0,0 +1,52 @@ +import { ObjectCollectionComponent } from './object-collection.component'; +import { ViewMode } from '../+search-page/search-options.model'; +import { element } from 'protractor'; +import { By } from '@angular/platform-browser'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Config } from '../../config/config.interface'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; +import { RouterStub } from '../shared/testing/router-stub'; + +describe('ObjectCollectionComponent', () => { + let fixture: ComponentFixture; + let objectCollectionComponent: ObjectCollectionComponent; + const queryParam = 'test query'; + const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; + const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) + }; + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ObjectCollectionComponent ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub } + ], + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(ObjectCollectionComponent); + objectCollectionComponent = fixture.componentInstance; + })); + it('should only show the grid component when the viewmode is set to grid', () => { + objectCollectionComponent.currentMode = ViewMode.Grid; + + // expect(By.css('ds-object-grid')).toEqual(1); + // expect(By.css('ds-object-list')).toEqual(0); + }); + + it('should only show the list component when the viewmode is set to list', () => { + objectCollectionComponent.currentMode = ViewMode.List; + + // expect(By.css('ds-object-list').length).toEqual(1); + // expect(By.css('ds-object-grid').length).toEqual(0); + }) + +}); diff --git a/src/app/object-collection/shared/dso-element-decorator.spec.ts b/src/app/object-collection/shared/dso-element-decorator.spec.ts new file mode 100644 index 0000000000..952afb9ac3 --- /dev/null +++ b/src/app/object-collection/shared/dso-element-decorator.spec.ts @@ -0,0 +1,16 @@ +import { ViewMode } from '../../+search-page/search-options.model'; +import { renderElementsFor } from './dso-element-decorator'; +import { Item } from '../../core/shared/item.model'; + +describe('ElementDecorator', () => { + let gridDecorator = renderElementsFor(Item, ViewMode.Grid); + let listDecorator = renderElementsFor(Item, ViewMode.List); + it('should have a decorator for both list and grid', () => { + expect(listDecorator.length).not.toBeNull(); + expect(gridDecorator.length).not.toBeNull(); + }); + it('should have 2 separate decorators for grid and list', () => { + expect(listDecorator).not.toEqual(gridDecorator); + }); + +}); diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts index f4ca434221..209ac52997 100644 --- a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts +++ b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts @@ -2,24 +2,24 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; -import { ThumbnailComponent } from './thumbnail.component'; +import { GridThumbnailComponent } from './grid-thumbnail.component'; import { Bitstream } from '../../core/shared/bitstream.model'; import { SafeUrlPipe } from '../../shared/utils/safe-url-pipe'; describe('ThumbnailComponent', () => { - let comp: ThumbnailComponent; - let fixture: ComponentFixture; + let comp: GridThumbnailComponent; + let fixture: ComponentFixture; let de: DebugElement; let el: HTMLElement; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ThumbnailComponent, SafeUrlPipe] + declarations: [GridThumbnailComponent, SafeUrlPipe] }).compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(ThumbnailComponent); + fixture = TestBed.createComponent(GridThumbnailComponent); comp = fixture.componentInstance; // BannerComponent test instance de = fixture.debugElement.query(By.css('div.thumbnail')); el = de.nativeElement; diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts new file mode 100644 index 0000000000..0da99aa697 --- /dev/null +++ b/src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts @@ -0,0 +1,6 @@ +import { ItemGridElementComponent } from './item-grid-element.component'; + +describe('ItemGridElementComponent',()=>{ + let itemGridElementComponent: ItemGridElementComponent; + +}) diff --git a/src/app/object-grid/object-grid.component.spec.ts b/src/app/object-grid/object-grid.component.spec.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts new file mode 100644 index 0000000000..e69de29bb2 From 520b7f3e1204780a47f955640f482cf553bd623e Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 3 Nov 2017 15:02:01 +0100 Subject: [PATCH 42/77] #150 Moved list,grid and object-collection to shared package --- src/app/+search-page/search-page.module.ts | 12 +++---- src/app/+search-page/search-result.model.ts | 2 +- .../search-service/search.service.ts | 1 + src/app/core/shared/dspace-object.model.ts | 2 +- .../object-collection.component.scss | 1 - .../shared/item-search-result.model.ts | 5 --- .../collection-grid-element.component.scss | 2 -- .../community-grid-element.component.scss | 2 -- .../grid-thumbnail.component.scss | 1 - .../item-grid-element.component.scss | 2 -- .../object-grid-element.component.scss | 6 ---- .../object-grid/object-grid.component.scss | 1 - ...-search-result-grid-element.component.scss | 2 -- .../collection-search-result.model.ts | 5 --- ...-search-result-grid-element.component.scss | 2 -- .../community-search-result.model.ts | 5 --- ...-search-result-grid-element.component.scss | 2 -- .../wrapper-grid-element.component.scss | 2 -- .../collection-list-element.component.scss | 1 - .../community-list-element.component.scss | 1 - .../item-list-element.component.scss | 1 - .../object-list/object-list.component.scss | 1 - ...-search-result-list-element.component.scss | 1 - .../collection-search-result.model.ts | 5 --- ...-search-result-list-element.component.scss | 1 - .../community-search-result.model.ts | 5 --- ...-search-result-list-element.component.scss | 1 - .../wrapper-list-element.component.scss | 2 -- .../object-collection.component.html | 0 .../object-collection.component.scss | 1 + .../object-collection.component.spec.ts | 6 ++-- .../object-collection.component.ts | 12 +++---- .../shared/dso-element-decorator.spec.ts | 4 +-- .../shared/dso-element-decorator.ts | 4 +-- .../shared/item-search-result.model.ts | 5 +++ .../shared/listable-object.model.ts | 0 .../collection-grid-element.component.html | 0 .../collection-grid-element.component.scss | 2 ++ .../collection-grid-element.component.spec.ts | 0 .../collection-grid-element.component.ts | 4 +-- .../community-grid-element.component.html | 0 .../community-grid-element.component.scss | 2 ++ .../community-grid-element.component.ts | 4 +-- .../object-grid/grid-card-styling.scss | 2 +- .../grid-thumbnail.component.html | 0 .../grid-thumbnail.component.scss | 1 + .../grid-thumbnail.component.spec.ts | 4 +-- .../grid-thumbnail.component.ts | 2 +- .../item-grid-element.component.html | 0 .../item-grid-element.component.scss | 2 ++ .../item-grid-element.component.spec.ts | 0 .../item-grid-element.component.ts | 4 +-- .../object-grid-element.component.html | 0 .../object-grid-element.component.scss | 6 ++++ .../object-grid-element.component.ts | 0 .../object-grid/object-grid.component.html | 0 .../object-grid/object-grid.component.scss | 1 + .../object-grid/object-grid.component.spec.ts | 0 .../object-grid/object-grid.component.ts | 10 +++--- ...-search-result-grid-element.component.html | 0 ...-search-result-grid-element.component.scss | 2 ++ ...on-search-result-grid-element.component.ts | 4 +-- .../collection-search-result.model.ts | 5 +++ ...-search-result-grid-element.component.html | 0 ...-search-result-grid-element.component.scss | 2 ++ ...ty-search-result-grid-element.component.ts | 4 +-- .../community-search-result.model.ts | 5 +++ ...-search-result-grid-element.component.html | 0 ...-search-result-grid-element.component.scss | 2 ++ ...em-search-result-grid-element.component.ts | 4 +-- .../search-result-grid-element.component.scss | 4 +-- .../search-result-grid-element.component.ts | 8 ++--- .../wrapper-grid-element.component.html | 0 .../wrapper-grid-element.component.scss | 2 ++ .../wrapper-grid-element.component.spec.ts | 0 .../wrapper-grid-element.component.ts | 4 +-- .../collection-list-element.component.html | 0 .../collection-list-element.component.scss | 1 + .../collection-list-element.component.ts | 4 +-- .../community-list-element.component.html | 0 .../community-list-element.component.scss | 1 + .../community-list-element.component.ts | 4 +-- .../item-list-element.component.html | 0 .../item-list-element.component.scss | 1 + .../item-list-element.component.ts | 4 +-- .../object-list-element.component.html | 0 .../object-list-element.component.scss | 2 +- .../object-list-element.component.ts | 0 .../object-list/object-list.component.html | 0 .../object-list/object-list.component.scss | 1 + .../object-list/object-list.component.ts | 11 +++++-- ...-search-result-list-element.component.html | 0 ...-search-result-list-element.component.scss | 1 + ...on-search-result-list-element.component.ts | 4 +-- .../collection-search-result.model.ts | 5 +++ ...-search-result-list-element.component.html | 0 ...-search-result-list-element.component.scss | 1 + ...ty-search-result-list-element.component.ts | 4 +-- .../community-search-result.model.ts | 5 +++ ...-search-result-list-element.component.html | 0 ...-search-result-list-element.component.scss | 1 + ...em-search-result-list-element.component.ts | 4 +-- .../search-result-list-element.component.scss | 4 +-- .../search-result-list-element.component.ts | 8 ++--- .../wrapper-list-element.component.html | 0 .../wrapper-list-element.component.scss | 2 ++ .../wrapper-list-element.component.ts | 4 +-- src/app/shared/shared.module.ts | 32 +++++++++---------- 108 files changed, 153 insertions(+), 147 deletions(-) delete mode 100644 src/app/object-collection/object-collection.component.scss delete mode 100644 src/app/object-collection/shared/item-search-result.model.ts delete mode 100644 src/app/object-grid/collection-grid-element/collection-grid-element.component.scss delete mode 100644 src/app/object-grid/community-grid-element/community-grid-element.component.scss delete mode 100644 src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss delete mode 100644 src/app/object-grid/item-grid-element/item-grid-element.component.scss delete mode 100644 src/app/object-grid/object-grid-element/object-grid-element.component.scss delete mode 100644 src/app/object-grid/object-grid.component.scss delete mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss delete mode 100644 src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts delete mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss delete mode 100644 src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts delete mode 100644 src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss delete mode 100644 src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss delete mode 100644 src/app/object-list/collection-list-element/collection-list-element.component.scss delete mode 100644 src/app/object-list/community-list-element/community-list-element.component.scss delete mode 100644 src/app/object-list/item-list-element/item-list-element.component.scss delete mode 100644 src/app/object-list/object-list.component.scss delete mode 100644 src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss delete mode 100644 src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts delete mode 100644 src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss delete mode 100644 src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts delete mode 100644 src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss delete mode 100644 src/app/object-list/wrapper-list-element/wrapper-list-element.component.scss rename src/app/{ => shared}/object-collection/object-collection.component.html (100%) create mode 100644 src/app/shared/object-collection/object-collection.component.scss rename src/app/{ => shared}/object-collection/object-collection.component.spec.ts (90%) rename src/app/{ => shared}/object-collection/object-collection.component.ts (87%) rename src/app/{ => shared}/object-collection/shared/dso-element-decorator.spec.ts (80%) rename src/app/{ => shared}/object-collection/shared/dso-element-decorator.ts (77%) create mode 100644 src/app/shared/object-collection/shared/item-search-result.model.ts rename src/app/{ => shared}/object-collection/shared/listable-object.model.ts (100%) rename src/app/{ => shared}/object-grid/collection-grid-element/collection-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss rename src/app/{ => shared}/object-grid/collection-grid-element/collection-grid-element.component.spec.ts (100%) rename src/app/{ => shared}/object-grid/collection-grid-element/collection-grid-element.component.ts (80%) rename src/app/{ => shared}/object-grid/community-grid-element/community-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss rename src/app/{ => shared}/object-grid/community-grid-element/community-grid-element.component.ts (80%) rename src/app/{ => shared}/object-grid/grid-card-styling.scss (94%) rename src/app/{ => shared}/object-grid/grid-thumbnail/grid-thumbnail.component.html (100%) create mode 100644 src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.scss rename src/app/{ => shared}/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts (91%) rename src/app/{ => shared}/object-grid/grid-thumbnail/grid-thumbnail.component.ts (95%) rename src/app/{ => shared}/object-grid/item-grid-element/item-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss rename src/app/{ => shared}/object-grid/item-grid-element/item-grid-element.component.spec.ts (100%) rename src/app/{ => shared}/object-grid/item-grid-element/item-grid-element.component.ts (80%) rename src/app/{ => shared}/object-grid/object-grid-element/object-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss rename src/app/{ => shared}/object-grid/object-grid-element/object-grid-element.component.ts (100%) rename src/app/{ => shared}/object-grid/object-grid.component.html (100%) create mode 100644 src/app/shared/object-grid/object-grid.component.scss rename src/app/{ => shared}/object-grid/object-grid.component.spec.ts (100%) rename src/app/{ => shared}/object-grid/object-grid.component.ts (88%) rename src/app/{ => shared}/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss rename src/app/{ => shared}/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts (84%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts rename src/app/{ => shared}/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss rename src/app/{ => shared}/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts (84%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts rename src/app/{ => shared}/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss rename src/app/{ => shared}/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts (84%) rename src/app/{ => shared}/object-grid/search-result-grid-element/search-result-grid-element.component.scss (51%) rename src/app/{ => shared}/object-grid/search-result-grid-element/search-result-grid-element.component.ts (83%) rename src/app/{ => shared}/object-grid/wrapper-grid-element/wrapper-grid-element.component.html (100%) create mode 100644 src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss rename src/app/{ => shared}/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts (100%) rename src/app/{ => shared}/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts (86%) rename src/app/{ => shared}/object-list/collection-list-element/collection-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/collection-list-element/collection-list-element.component.scss rename src/app/{ => shared}/object-list/collection-list-element/collection-list-element.component.ts (80%) rename src/app/{ => shared}/object-list/community-list-element/community-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/community-list-element/community-list-element.component.scss rename src/app/{ => shared}/object-list/community-list-element/community-list-element.component.ts (80%) rename src/app/{ => shared}/object-list/item-list-element/item-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/item-list-element/item-list-element.component.scss rename src/app/{ => shared}/object-list/item-list-element/item-list-element.component.ts (80%) rename src/app/{ => shared}/object-list/object-list-element/object-list-element.component.html (100%) rename src/app/{ => shared}/object-list/object-list-element/object-list-element.component.scss (56%) rename src/app/{ => shared}/object-list/object-list-element/object-list-element.component.ts (100%) rename src/app/{ => shared}/object-list/object-list.component.html (100%) create mode 100644 src/app/shared/object-list/object-list.component.scss rename src/app/{ => shared}/object-list/object-list.component.ts (90%) rename src/app/{ => shared}/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss rename src/app/{ => shared}/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts (84%) create mode 100644 src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts rename src/app/{ => shared}/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss rename src/app/{ => shared}/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts (84%) create mode 100644 src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result.model.ts rename src/app/{ => shared}/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss rename src/app/{ => shared}/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts (84%) rename src/app/{ => shared}/object-list/search-result-list-element/search-result-list-element.component.scss (67%) rename src/app/{ => shared}/object-list/search-result-list-element/search-result-list-element.component.ts (83%) rename src/app/{ => shared}/object-list/wrapper-list-element/wrapper-list-element.component.html (100%) create mode 100644 src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.scss rename src/app/{ => shared}/object-list/wrapper-list-element/wrapper-list-element.component.ts (86%) diff --git a/src/app/+search-page/search-page.module.ts b/src/app/+search-page/search-page.module.ts index be99a0eae4..7c2001c909 100644 --- a/src/app/+search-page/search-page.module.ts +++ b/src/app/+search-page/search-page.module.ts @@ -4,12 +4,12 @@ import { SharedModule } from '../shared/shared.module'; import { SearchPageRoutingModule } from './search-page-routing.module'; import { SearchPageComponent } from './search-page.component'; import { SearchResultsComponent } from './search-results/search-results.component'; -import { ItemSearchResultListElementComponent } from '../object-list/search-result-list-element/item-search-result/item-search-result-list-element.component'; -import { CollectionSearchResultListElementComponent } from '../object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component'; -import { CommunitySearchResultListElementComponent } from '../object-list/search-result-list-element/community-search-result/community-search-result-list-element.component'; -import { ItemSearchResultGridElementComponent } from '../object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component'; -import { CommunitySearchResultGridElementComponent } from '../object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component' -import { CollectionSearchResultGridElementComponent } from '../object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component'; +import { ItemSearchResultListElementComponent } from '../shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component'; +import { CollectionSearchResultListElementComponent } from '../shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component'; +import { CommunitySearchResultListElementComponent } from '../shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component'; +import { ItemSearchResultGridElementComponent } from '../shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component'; +import { CommunitySearchResultGridElementComponent } from '../shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component' +import { CollectionSearchResultGridElementComponent } from '../shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component'; import { SearchService } from './search-service/search.service'; import { SearchSidebarComponent } from './search-sidebar/search-sidebar.component'; import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; diff --git a/src/app/+search-page/search-result.model.ts b/src/app/+search-page/search-result.model.ts index 602d8ac9c2..cc2bd8cd58 100644 --- a/src/app/+search-page/search-result.model.ts +++ b/src/app/+search-page/search-result.model.ts @@ -1,6 +1,6 @@ import { DSpaceObject } from '../core/shared/dspace-object.model'; import { Metadatum } from '../core/shared/metadatum.model'; -import { ListableObject } from '../object-collection/shared/listable-object.model'; +import { ListableObject } from '../shared/object-collection/shared/listable-object.model'; export class SearchResult implements ListableObject { diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 5258756bfb..63b1b04dce 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -15,6 +15,7 @@ import { FacetValue } from './facet-value.model'; import { ItemSearchResult } from '../../object-collection/shared/item-search-result.model'; import { ViewMode } from '../../+search-page/search-options.model'; import { Router, NavigationExtras, ActivatedRoute } from '@angular/router'; +import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; import { RouteService } from '../../shared/route.service'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; import { SortOptions } from '../../core/cache/models/sort-options.model'; diff --git a/src/app/core/shared/dspace-object.model.ts b/src/app/core/shared/dspace-object.model.ts index a17a6b31ce..8f96f2485a 100644 --- a/src/app/core/shared/dspace-object.model.ts +++ b/src/app/core/shared/dspace-object.model.ts @@ -3,7 +3,7 @@ import { isEmpty, isNotEmpty } from '../../shared/empty.util'; import { CacheableObject } from '../cache/object-cache.reducer'; import { RemoteData } from '../data/remote-data'; import { ResourceType } from './resource-type'; -import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { ListableObject } from '../../shared/object-collection/shared/listable-object.model'; import { Observable } from 'rxjs/Observable'; /** diff --git a/src/app/object-collection/object-collection.component.scss b/src/app/object-collection/object-collection.component.scss deleted file mode 100644 index da97dd7a62..0000000000 --- a/src/app/object-collection/object-collection.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../styles/variables.scss'; diff --git a/src/app/object-collection/shared/item-search-result.model.ts b/src/app/object-collection/shared/item-search-result.model.ts deleted file mode 100644 index 75d56a2488..0000000000 --- a/src/app/object-collection/shared/item-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../+search-page/search-result.model'; -import { Item } from '../../core/shared/item.model'; - -export class ItemSearchResult extends SearchResult { -} diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss b/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss deleted file mode 100644 index 48e2b121d4..0000000000 --- a/src/app/object-grid/collection-grid-element/collection-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.scss b/src/app/object-grid/community-grid-element/community-grid-element.component.scss deleted file mode 100644 index 48e2b121d4..0000000000 --- a/src/app/object-grid/community-grid-element/community-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss b/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss deleted file mode 100644 index 50be6f5ad0..0000000000 --- a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../styles/variables.scss'; diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.scss b/src/app/object-grid/item-grid-element/item-grid-element.component.scss deleted file mode 100644 index 48e2b121d4..0000000000 --- a/src/app/object-grid/item-grid-element/item-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/object-grid/object-grid-element/object-grid-element.component.scss deleted file mode 100644 index 0351acf15f..0000000000 --- a/src/app/object-grid/object-grid-element/object-grid-element.component.scss +++ /dev/null @@ -1,6 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; -:host { - display: block; - margin-bottom: $spacer; -} diff --git a/src/app/object-grid/object-grid.component.scss b/src/app/object-grid/object-grid.component.scss deleted file mode 100644 index da97dd7a62..0000000000 --- a/src/app/object-grid/object-grid.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../styles/variables.scss'; diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss deleted file mode 100644 index 790f794381..0000000000 --- a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../../styles/variables.scss'; -@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts b/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts deleted file mode 100644 index fa7945dedd..0000000000 --- a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Collection } from '../../../core/shared/collection.model'; - -export class CollectionSearchResult extends SearchResult { -} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss deleted file mode 100644 index 790f794381..0000000000 --- a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../../styles/variables.scss'; -@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts b/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts deleted file mode 100644 index 79ea34b6cd..0000000000 --- a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Community } from '../../../core/shared/community.model'; - -export class CommunitySearchResult extends SearchResult { -} diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss b/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss deleted file mode 100644 index 790f794381..0000000000 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../../styles/variables.scss'; -@import '../../grid-card-styling.scss'; diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss b/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss deleted file mode 100644 index 48e2b121d4..0000000000 --- a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; -@import '../grid-card-styling.scss'; diff --git a/src/app/object-list/collection-list-element/collection-list-element.component.scss b/src/app/object-list/collection-list-element/collection-list-element.component.scss deleted file mode 100644 index ad84b72f8c..0000000000 --- a/src/app/object-list/collection-list-element/collection-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/community-list-element/community-list-element.component.scss b/src/app/object-list/community-list-element/community-list-element.component.scss deleted file mode 100644 index ad84b72f8c..0000000000 --- a/src/app/object-list/community-list-element/community-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/item-list-element/item-list-element.component.scss b/src/app/object-list/item-list-element/item-list-element.component.scss deleted file mode 100644 index ad84b72f8c..0000000000 --- a/src/app/object-list/item-list-element/item-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/object-list.component.scss b/src/app/object-list/object-list.component.scss deleted file mode 100644 index b14c7376e3..0000000000 --- a/src/app/object-list/object-list.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss deleted file mode 100644 index 88eb98509a..0000000000 --- a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts deleted file mode 100644 index fa7945dedd..0000000000 --- a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Collection } from '../../../core/shared/collection.model'; - -export class CollectionSearchResult extends SearchResult { -} diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss deleted file mode 100644 index 88eb98509a..0000000000 --- a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts b/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts deleted file mode 100644 index 79ea34b6cd..0000000000 --- a/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SearchResult } from '../../../+search-page/search-result.model'; -import { Community } from '../../../core/shared/community.model'; - -export class CommunitySearchResult extends SearchResult { -} diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss deleted file mode 100644 index 88eb98509a..0000000000 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss +++ /dev/null @@ -1 +0,0 @@ -@import '../../../../styles/variables.scss'; \ No newline at end of file diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.scss b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.scss deleted file mode 100644 index 6f997644cc..0000000000 --- a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.scss +++ /dev/null @@ -1,2 +0,0 @@ -@import '../../../styles/variables.scss'; - diff --git a/src/app/object-collection/object-collection.component.html b/src/app/shared/object-collection/object-collection.component.html similarity index 100% rename from src/app/object-collection/object-collection.component.html rename to src/app/shared/object-collection/object-collection.component.html diff --git a/src/app/shared/object-collection/object-collection.component.scss b/src/app/shared/object-collection/object-collection.component.scss new file mode 100644 index 0000000000..48e6526dff --- /dev/null +++ b/src/app/shared/object-collection/object-collection.component.scss @@ -0,0 +1 @@ +@import '../../../styles/variables'; diff --git a/src/app/object-collection/object-collection.component.spec.ts b/src/app/shared/object-collection/object-collection.component.spec.ts similarity index 90% rename from src/app/object-collection/object-collection.component.spec.ts rename to src/app/shared/object-collection/object-collection.component.spec.ts index abbf66e4f1..a56a3e56dc 100644 --- a/src/app/object-collection/object-collection.component.spec.ts +++ b/src/app/shared/object-collection/object-collection.component.spec.ts @@ -1,13 +1,13 @@ import { ObjectCollectionComponent } from './object-collection.component'; -import { ViewMode } from '../+search-page/search-options.model'; +import { ViewMode } from '../../+search-page/search-options.model'; import { element } from 'protractor'; import { By } from '@angular/platform-browser'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { Config } from '../../config/config.interface'; +import { Config } from '../../../config/config.interface'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; -import { RouterStub } from '../shared/testing/router-stub'; +import { RouterStub } from '../testing/router-stub'; describe('ObjectCollectionComponent', () => { let fixture: ComponentFixture; diff --git a/src/app/object-collection/object-collection.component.ts b/src/app/shared/object-collection/object-collection.component.ts similarity index 87% rename from src/app/object-collection/object-collection.component.ts rename to src/app/shared/object-collection/object-collection.component.ts index a79653d970..8d5a9ce3c7 100644 --- a/src/app/object-collection/object-collection.component.ts +++ b/src/app/shared/object-collection/object-collection.component.ts @@ -6,16 +6,16 @@ import { ActivatedRoute, Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; -import { RemoteData } from '../core/data/remote-data'; -import { PageInfo } from '../core/shared/page-info.model'; +import { RemoteData } from '../../core/data/remote-data'; +import { PageInfo } from '../../core/shared/page-info.model'; -import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; +import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; -import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { ListableObject } from './shared/listable-object.model'; -import { ViewMode } from '../+search-page/search-options.model'; -import { hasValue, isNotEmpty } from '../shared/empty.util'; +import { ViewMode } from '../../+search-page/search-options.model'; +import { hasValue, isNotEmpty } from '../empty.util'; @Component({ selector: 'ds-viewable-collection', diff --git a/src/app/object-collection/shared/dso-element-decorator.spec.ts b/src/app/shared/object-collection/shared/dso-element-decorator.spec.ts similarity index 80% rename from src/app/object-collection/shared/dso-element-decorator.spec.ts rename to src/app/shared/object-collection/shared/dso-element-decorator.spec.ts index 952afb9ac3..b4b27bb52a 100644 --- a/src/app/object-collection/shared/dso-element-decorator.spec.ts +++ b/src/app/shared/object-collection/shared/dso-element-decorator.spec.ts @@ -1,6 +1,6 @@ -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; import { renderElementsFor } from './dso-element-decorator'; -import { Item } from '../../core/shared/item.model'; +import { Item } from '../../../core/shared/item.model'; describe('ElementDecorator', () => { let gridDecorator = renderElementsFor(Item, ViewMode.Grid); diff --git a/src/app/object-collection/shared/dso-element-decorator.ts b/src/app/shared/object-collection/shared/dso-element-decorator.ts similarity index 77% rename from src/app/object-collection/shared/dso-element-decorator.ts rename to src/app/shared/object-collection/shared/dso-element-decorator.ts index 310a65f056..5dc085d3a7 100644 --- a/src/app/object-collection/shared/dso-element-decorator.ts +++ b/src/app/shared/object-collection/shared/dso-element-decorator.ts @@ -1,6 +1,6 @@ -import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { ListableObject } from './listable-object.model'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; const dsoElementMap = new Map(); export function renderElementsFor(listable: GenericConstructor, viewMode : ViewMode) { diff --git a/src/app/shared/object-collection/shared/item-search-result.model.ts b/src/app/shared/object-collection/shared/item-search-result.model.ts new file mode 100644 index 0000000000..d9af3539a0 --- /dev/null +++ b/src/app/shared/object-collection/shared/item-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../+search-page/search-result.model'; +import { Item } from '../../../core/shared/item.model'; + +export class ItemSearchResult extends SearchResult { +} diff --git a/src/app/object-collection/shared/listable-object.model.ts b/src/app/shared/object-collection/shared/listable-object.model.ts similarity index 100% rename from src/app/object-collection/shared/listable-object.model.ts rename to src/app/shared/object-collection/shared/listable-object.model.ts diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.html b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html similarity index 100% rename from src/app/object-grid/collection-grid-element/collection-grid-element.component.html rename to src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss new file mode 100644 index 0000000000..946c8a6a31 --- /dev/null +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts similarity index 100% rename from src/app/object-grid/collection-grid-element/collection-grid-element.component.spec.ts rename to src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts diff --git a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts similarity index 80% rename from src/app/object-grid/collection-grid-element/collection-grid-element.component.ts rename to src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts index 7e2ae5f468..09aadab15e 100644 --- a/src/app/object-grid/collection-grid-element/collection-grid-element.component.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; -import { Collection } from '../../core/shared/collection.model'; +import { Collection } from '../../../core/shared/collection.model'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.html b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html similarity index 100% rename from src/app/object-grid/community-grid-element/community-grid-element.component.html rename to src/app/shared/object-grid/community-grid-element/community-grid-element.component.html diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss new file mode 100644 index 0000000000..946c8a6a31 --- /dev/null +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; diff --git a/src/app/object-grid/community-grid-element/community-grid-element.component.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts similarity index 80% rename from src/app/object-grid/community-grid-element/community-grid-element.component.ts rename to src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts index 76ee6736be..d40bd717a4 100644 --- a/src/app/object-grid/community-grid-element/community-grid-element.component.ts +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; -import { Community } from '../../core/shared/community.model'; +import { Community } from '../../../core/shared/community.model'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-grid-element', diff --git a/src/app/object-grid/grid-card-styling.scss b/src/app/shared/object-grid/grid-card-styling.scss similarity index 94% rename from src/app/object-grid/grid-card-styling.scss rename to src/app/shared/object-grid/grid-card-styling.scss index b25c603b55..2fe199d1ce 100644 --- a/src/app/object-grid/grid-card-styling.scss +++ b/src/app/shared/object-grid/grid-card-styling.scss @@ -1,4 +1,4 @@ -@import '../../styles/custom_variables'; +@import '../../../styles/custom_variables'; .card-title{ line-height: $line-height-base; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html similarity index 100% rename from src/app/object-grid/grid-thumbnail/grid-thumbnail.component.html rename to src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html diff --git a/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.scss b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.scss new file mode 100644 index 0000000000..45a533cd01 --- /dev/null +++ b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.scss @@ -0,0 +1 @@ +@import '../../../../styles/variables'; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts similarity index 91% rename from src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts rename to src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts index 209ac52997..2d2bd6305a 100644 --- a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts +++ b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.spec.ts @@ -3,8 +3,8 @@ import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; import { GridThumbnailComponent } from './grid-thumbnail.component'; -import { Bitstream } from '../../core/shared/bitstream.model'; -import { SafeUrlPipe } from '../../shared/utils/safe-url-pipe'; +import { Bitstream } from '../../../core/shared/bitstream.model'; +import { SafeUrlPipe } from '../../utils/safe-url-pipe'; describe('ThumbnailComponent', () => { let comp: GridThumbnailComponent; diff --git a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts similarity index 95% rename from src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts rename to src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts index 7baa47b39e..8ca93470da 100644 --- a/src/app/object-grid/grid-thumbnail/grid-thumbnail.component.ts +++ b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts @@ -1,5 +1,5 @@ import { Component, Input } from '@angular/core'; -import { Bitstream } from '../../core/shared/bitstream.model'; +import { Bitstream } from '../../../core/shared/bitstream.model'; /** * This component renders a given Bitstream as a thumbnail. diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.html b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html similarity index 100% rename from src/app/object-grid/item-grid-element/item-grid-element.component.html rename to src/app/shared/object-grid/item-grid-element/item-grid-element.component.html diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss new file mode 100644 index 0000000000..946c8a6a31 --- /dev/null +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts similarity index 100% rename from src/app/object-grid/item-grid-element/item-grid-element.component.spec.ts rename to src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts diff --git a/src/app/object-grid/item-grid-element/item-grid-element.component.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts similarity index 80% rename from src/app/object-grid/item-grid-element/item-grid-element.component.ts rename to src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts index e11c51312a..c41a6c9352 100644 --- a/src/app/object-grid/item-grid-element/item-grid-element.component.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; -import { Item } from '../../core/shared/item.model'; +import { Item } from '../../../core/shared/item.model'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-grid-element', diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.html b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.html similarity index 100% rename from src/app/object-grid/object-grid-element/object-grid-element.component.html rename to src/app/shared/object-grid/object-grid-element/object-grid-element.component.html diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss new file mode 100644 index 0000000000..d299edd0ab --- /dev/null +++ b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss @@ -0,0 +1,6 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; +:host { + display: block; + margin-bottom: $spacer; +} diff --git a/src/app/object-grid/object-grid-element/object-grid-element.component.ts b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts similarity index 100% rename from src/app/object-grid/object-grid-element/object-grid-element.component.ts rename to src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts diff --git a/src/app/object-grid/object-grid.component.html b/src/app/shared/object-grid/object-grid.component.html similarity index 100% rename from src/app/object-grid/object-grid.component.html rename to src/app/shared/object-grid/object-grid.component.html diff --git a/src/app/shared/object-grid/object-grid.component.scss b/src/app/shared/object-grid/object-grid.component.scss new file mode 100644 index 0000000000..48e6526dff --- /dev/null +++ b/src/app/shared/object-grid/object-grid.component.scss @@ -0,0 +1 @@ +@import '../../../styles/variables'; diff --git a/src/app/object-grid/object-grid.component.spec.ts b/src/app/shared/object-grid/object-grid.component.spec.ts similarity index 100% rename from src/app/object-grid/object-grid.component.spec.ts rename to src/app/shared/object-grid/object-grid.component.spec.ts diff --git a/src/app/object-grid/object-grid.component.ts b/src/app/shared/object-grid/object-grid.component.ts similarity index 88% rename from src/app/object-grid/object-grid.component.ts rename to src/app/shared/object-grid/object-grid.component.ts index a6b62d735f..c811d90d62 100644 --- a/src/app/object-grid/object-grid.component.ts +++ b/src/app/shared/object-grid/object-grid.component.ts @@ -8,13 +8,13 @@ import { } from '@angular/core'; import { Observable } from 'rxjs/Observable'; -import { RemoteData } from '../core/data/remote-data'; -import { PageInfo } from '../core/shared/page-info.model'; +import { RemoteData } from '../../core/data/remote-data'; +import { PageInfo } from '../../core/shared/page-info.model'; -import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; +import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; -import { SortOptions, SortDirection } from '../core/cache/models/sort-options.model'; -import { fadeIn } from '../shared/animations/fade'; +import { SortOptions, SortDirection } from '../../core/cache/models/sort-options.model'; +import { fadeIn } from '../animations/fade'; import { ListableObject } from '../object-collection/shared/listable-object.model'; @Component({ diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html similarity index 100% rename from src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html rename to src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss new file mode 100644 index 0000000000..2867dd78ac --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../../styles/variables'; +@import '../../grid-card-styling'; diff --git a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts similarity index 84% rename from src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts rename to src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts index 6c5e526d15..0228107a57 100644 --- a/src/app/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.ts @@ -4,8 +4,8 @@ import { renderElementsFor} from '../../../object-collection/shared/dso-element- import { CollectionSearchResult } from './collection-search-result.model'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; -import { Collection } from '../../../core/shared/collection.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { Collection } from '../../../../core/shared/collection.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-search-result-grid-element', diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts new file mode 100644 index 0000000000..ad48247e70 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../../+search-page/search-result.model'; +import { Collection } from '../../../../core/shared/collection.model'; + +export class CollectionSearchResult extends SearchResult { +} diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html similarity index 100% rename from src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html rename to src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss new file mode 100644 index 0000000000..2867dd78ac --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../../styles/variables'; +@import '../../grid-card-styling'; diff --git a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts similarity index 84% rename from src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts rename to src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts index b6aa4bdb6d..4876a784fc 100644 --- a/src/app/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.ts @@ -1,10 +1,10 @@ import { Component } from '@angular/core'; import { CommunitySearchResult } from './community-search-result.model'; -import { Community } from '../../../core/shared/community.model'; +import { Community } from '../../../../core/shared/community.model'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-search-result-grid-element', diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts new file mode 100644 index 0000000000..efeb328e11 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../../+search-page/search-result.model'; +import { Community } from '../../../../core/shared/community.model'; + +export class CommunitySearchResult extends SearchResult { +} diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html similarity index 100% rename from src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html rename to src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss new file mode 100644 index 0000000000..2867dd78ac --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../../styles/variables'; +@import '../../grid-card-styling'; diff --git a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts similarity index 84% rename from src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts rename to src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts index d4989d2efd..f9fe13cb88 100644 --- a/src/app/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.ts @@ -2,9 +2,9 @@ import { Component } from '@angular/core'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultGridElementComponent } from '../search-result-grid-element.component'; -import { Item } from '../../../core/shared/item.model'; +import { Item } from '../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-search-result-grid-element', diff --git a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss similarity index 51% rename from src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss rename to src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss index 0f2684f1f1..ebec5817e6 100644 --- a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss @@ -1,5 +1,5 @@ - @import '../../../styles/variables.scss'; - @import '../grid-card-styling.scss'; + @import '../../../../styles/variables'; + @import '../grid-card-styling'; :host { /deep/ em { font-weight: bold; diff --git a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts similarity index 83% rename from src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts rename to src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts index ba98a58d4b..052a9377b5 100644 --- a/src/app/object-grid/search-result-grid-element/search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; -import { SearchResult } from '../../+search-page/search-result.model'; -import { DSpaceObject } from '../../core/shared/dspace-object.model'; -import { Metadatum } from '../../core/shared/metadatum.model'; -import { isEmpty, hasNoValue } from '../../shared/empty.util'; +import { SearchResult } from '../../../+search-page/search-result.model'; +import { DSpaceObject } from '../../../core/shared/dspace-object.model'; +import { Metadatum } from '../../../core/shared/metadatum.model'; +import { isEmpty, hasNoValue } from '../../empty.util'; import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.html similarity index 100% rename from src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.html rename to src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.html diff --git a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss new file mode 100644 index 0000000000..946c8a6a31 --- /dev/null +++ b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; +@import '../grid-card-styling'; diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts similarity index 100% rename from src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts rename to src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts diff --git a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts similarity index 86% rename from src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts rename to src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts index 000c826188..912df16786 100644 --- a/src/app/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts +++ b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.ts @@ -1,8 +1,8 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; -import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-wrapper-grid-element', diff --git a/src/app/object-list/collection-list-element/collection-list-element.component.html b/src/app/shared/object-list/collection-list-element/collection-list-element.component.html similarity index 100% rename from src/app/object-list/collection-list-element/collection-list-element.component.html rename to src/app/shared/object-list/collection-list-element/collection-list-element.component.html diff --git a/src/app/shared/object-list/collection-list-element/collection-list-element.component.scss b/src/app/shared/object-list/collection-list-element/collection-list-element.component.scss new file mode 100644 index 0000000000..45a533cd01 --- /dev/null +++ b/src/app/shared/object-list/collection-list-element/collection-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../styles/variables'; diff --git a/src/app/object-list/collection-list-element/collection-list-element.component.ts b/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts similarity index 80% rename from src/app/object-list/collection-list-element/collection-list-element.component.ts rename to src/app/shared/object-list/collection-list-element/collection-list-element.component.ts index c065a64b72..5e08e8ef3a 100644 --- a/src/app/object-list/collection-list-element/collection-list-element.component.ts +++ b/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; -import { Collection } from '../../core/shared/collection.model'; +import { Collection } from '../../../core/shared/collection.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-list-element', diff --git a/src/app/object-list/community-list-element/community-list-element.component.html b/src/app/shared/object-list/community-list-element/community-list-element.component.html similarity index 100% rename from src/app/object-list/community-list-element/community-list-element.component.html rename to src/app/shared/object-list/community-list-element/community-list-element.component.html diff --git a/src/app/shared/object-list/community-list-element/community-list-element.component.scss b/src/app/shared/object-list/community-list-element/community-list-element.component.scss new file mode 100644 index 0000000000..45a533cd01 --- /dev/null +++ b/src/app/shared/object-list/community-list-element/community-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../styles/variables'; diff --git a/src/app/object-list/community-list-element/community-list-element.component.ts b/src/app/shared/object-list/community-list-element/community-list-element.component.ts similarity index 80% rename from src/app/object-list/community-list-element/community-list-element.component.ts rename to src/app/shared/object-list/community-list-element/community-list-element.component.ts index 11ff392942..cd6e6f7574 100644 --- a/src/app/object-list/community-list-element/community-list-element.component.ts +++ b/src/app/shared/object-list/community-list-element/community-list-element.component.ts @@ -1,9 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; -import { Community } from '../../core/shared/community.model'; +import { Community } from '../../../core/shared/community.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-list-element', diff --git a/src/app/object-list/item-list-element/item-list-element.component.html b/src/app/shared/object-list/item-list-element/item-list-element.component.html similarity index 100% rename from src/app/object-list/item-list-element/item-list-element.component.html rename to src/app/shared/object-list/item-list-element/item-list-element.component.html diff --git a/src/app/shared/object-list/item-list-element/item-list-element.component.scss b/src/app/shared/object-list/item-list-element/item-list-element.component.scss new file mode 100644 index 0000000000..45a533cd01 --- /dev/null +++ b/src/app/shared/object-list/item-list-element/item-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../styles/variables'; diff --git a/src/app/object-list/item-list-element/item-list-element.component.ts b/src/app/shared/object-list/item-list-element/item-list-element.component.ts similarity index 80% rename from src/app/object-list/item-list-element/item-list-element.component.ts rename to src/app/shared/object-list/item-list-element/item-list-element.component.ts index bdc5733dcd..43c59f0980 100644 --- a/src/app/object-list/item-list-element/item-list-element.component.ts +++ b/src/app/shared/object-list/item-list-element/item-list-element.component.ts @@ -1,9 +1,9 @@ import { Component, Input, Inject } from '@angular/core'; -import { Item } from '../../core/shared/item.model'; +import { Item } from '../../../core/shared/item.model'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-list-element', diff --git a/src/app/object-list/object-list-element/object-list-element.component.html b/src/app/shared/object-list/object-list-element/object-list-element.component.html similarity index 100% rename from src/app/object-list/object-list-element/object-list-element.component.html rename to src/app/shared/object-list/object-list-element/object-list-element.component.html diff --git a/src/app/object-list/object-list-element/object-list-element.component.scss b/src/app/shared/object-list/object-list-element/object-list-element.component.scss similarity index 56% rename from src/app/object-list/object-list-element/object-list-element.component.scss rename to src/app/shared/object-list/object-list-element/object-list-element.component.scss index 1a22768fe8..f96f4ae744 100644 --- a/src/app/object-list/object-list-element/object-list-element.component.scss +++ b/src/app/shared/object-list/object-list-element/object-list-element.component.scss @@ -1,4 +1,4 @@ -@import '../../../styles/variables.scss'; +@import '../../../../styles/variables'; :host { display: block; diff --git a/src/app/object-list/object-list-element/object-list-element.component.ts b/src/app/shared/object-list/object-list-element/object-list-element.component.ts similarity index 100% rename from src/app/object-list/object-list-element/object-list-element.component.ts rename to src/app/shared/object-list/object-list-element/object-list-element.component.ts diff --git a/src/app/object-list/object-list.component.html b/src/app/shared/object-list/object-list.component.html similarity index 100% rename from src/app/object-list/object-list.component.html rename to src/app/shared/object-list/object-list.component.html diff --git a/src/app/shared/object-list/object-list.component.scss b/src/app/shared/object-list/object-list.component.scss new file mode 100644 index 0000000000..48e6526dff --- /dev/null +++ b/src/app/shared/object-list/object-list.component.scss @@ -0,0 +1 @@ +@import '../../../styles/variables'; diff --git a/src/app/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts similarity index 90% rename from src/app/object-list/object-list.component.ts rename to src/app/shared/object-list/object-list.component.ts index 9422d1d843..c1e3d21760 100644 --- a/src/app/object-list/object-list.component.ts +++ b/src/app/shared/object-list/object-list.component.ts @@ -9,9 +9,14 @@ import { import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; -import { RemoteData } from '../core/data/remote-data'; -import { PageInfo } from '../core/shared/page-info.model'; -import { fadeIn } from '../shared/animations/fade'; +import { RemoteData } from '../../core/data/remote-data'; +import { PageInfo } from '../../core/shared/page-info.model'; + +import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; + +import { SortOptions, SortDirection } from '../../core/cache/models/sort-options.model'; + +import { fadeIn } from '../animations/fade'; import { ListableObject } from '../object-collection/shared/listable-object.model'; import { hasValue } from '../shared/empty.util'; diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html similarity index 100% rename from src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html rename to src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html diff --git a/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss new file mode 100644 index 0000000000..1d0786105c --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../../styles/variables'; diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts similarity index 84% rename from src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts rename to src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts index 1b5d7ef0ba..5545ea17ec 100644 --- a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts @@ -3,8 +3,8 @@ import { Component } from '@angular/core'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { CollectionSearchResult } from './collection-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; -import { Collection } from '../../../core/shared/collection.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { Collection } from '../../../../core/shared/collection.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-collection-search-result-list-element', diff --git a/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts new file mode 100644 index 0000000000..ad48247e70 --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../../+search-page/search-result.model'; +import { Collection } from '../../../../core/shared/collection.model'; + +export class CollectionSearchResult extends SearchResult { +} diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html similarity index 100% rename from src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html rename to src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html diff --git a/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss new file mode 100644 index 0000000000..1d0786105c --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../../styles/variables'; diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts similarity index 84% rename from src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts rename to src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts index d9ab001f58..2d96f61833 100644 --- a/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts @@ -3,8 +3,8 @@ import { Component } from '@angular/core'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { CommunitySearchResult } from './community-search-result.model'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; -import { Community } from '../../../core/shared/community.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { Community } from '../../../../core/shared/community.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-community-search-result-list-element', diff --git a/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result.model.ts b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result.model.ts new file mode 100644 index 0000000000..efeb328e11 --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/community-search-result/community-search-result.model.ts @@ -0,0 +1,5 @@ +import { SearchResult } from '../../../../+search-page/search-result.model'; +import { Community } from '../../../../core/shared/community.model'; + +export class CommunitySearchResult extends SearchResult { +} diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html similarity index 100% rename from src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html rename to src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html diff --git a/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss new file mode 100644 index 0000000000..1d0786105c --- /dev/null +++ b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss @@ -0,0 +1 @@ +@import '../../../../../styles/variables'; diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts similarity index 84% rename from src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts rename to src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts index 929233f1a3..d1011c8c45 100644 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts @@ -2,9 +2,9 @@ import { Component } from '@angular/core'; import { renderElementsFor } from '../../../object-collection/shared/dso-element-decorator'; import { SearchResultListElementComponent } from '../search-result-list-element.component'; -import { Item } from '../../../core/shared/item.model'; +import { Item } from '../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; -import { ViewMode } from '../../../+search-page/search-options.model'; +import { ViewMode } from '../../../../+search-page/search-options.model'; @Component({ selector: 'ds-item-search-result-list-element', diff --git a/src/app/object-list/search-result-list-element/search-result-list-element.component.scss b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.scss similarity index 67% rename from src/app/object-list/search-result-list-element/search-result-list-element.component.scss rename to src/app/shared/object-list/search-result-list-element/search-result-list-element.component.scss index 5ec8b5d81b..7134c43dad 100644 --- a/src/app/object-list/search-result-list-element/search-result-list-element.component.scss +++ b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.scss @@ -1,7 +1,7 @@ -@import '../../../styles/variables.scss'; +@import '../../../../styles/variables'; :host { ::ng-deep em { font-weight: bold; font-style: normal; } -} \ No newline at end of file +} diff --git a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts similarity index 83% rename from src/app/object-list/search-result-list-element/search-result-list-element.component.ts rename to src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts index ec0afde65d..b89bb56da6 100644 --- a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts @@ -1,10 +1,10 @@ import { Component, Inject } from '@angular/core'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; -import { SearchResult } from '../../+search-page/search-result.model'; -import { DSpaceObject } from '../../core/shared/dspace-object.model'; -import { Metadatum } from '../../core/shared/metadatum.model'; -import { isEmpty, hasNoValue } from '../../shared/empty.util'; +import { SearchResult } from '../../../+search-page/search-result.model'; +import { DSpaceObject } from '../../../core/shared/dspace-object.model'; +import { Metadatum } from '../../../core/shared/metadatum.model'; +import { isEmpty, hasNoValue } from '../../empty.util'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.html b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.html similarity index 100% rename from src/app/object-list/wrapper-list-element/wrapper-list-element.component.html rename to src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.html diff --git a/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.scss b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.scss new file mode 100644 index 0000000000..51a7fc6a55 --- /dev/null +++ b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.scss @@ -0,0 +1,2 @@ +@import '../../../../styles/variables'; + diff --git a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.ts similarity index 86% rename from src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts rename to src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.ts index ff5591442d..6450babae8 100644 --- a/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts +++ b/src/app/shared/object-list/wrapper-list-element/wrapper-list-element.component.ts @@ -1,8 +1,8 @@ import { Component, Input, Injector, ReflectiveInjector, OnInit } from '@angular/core'; import { rendersDSOType } from '../../object-collection/shared/dso-element-decorator' -import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; -import { ViewMode } from '../../+search-page/search-options.model'; +import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ selector: 'ds-wrapper-list-element', diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 8ef05b2f89..7ee5ba56df 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -14,21 +14,21 @@ import { FileSizePipe } from './utils/file-size-pipe'; import { SafeUrlPipe } from './utils/safe-url-pipe'; import { TruncatePipe } from './utils/truncate.pipe'; -import { CollectionListElementComponent } from '../object-list/collection-list-element/collection-list-element.component'; -import { CommunityListElementComponent } from '../object-list/community-list-element/community-list-element.component'; -import { ItemListElementComponent } from '../object-list/item-list-element/item-list-element.component'; -import { ObjectListElementComponent } from '../object-list/object-list-element/object-list-element.component'; -import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component'; -import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; -import { ObjectListComponent } from '../object-list/object-list.component'; +import { CollectionListElementComponent } from './object-list/collection-list-element/collection-list-element.component'; +import { CommunityListElementComponent } from './object-list/community-list-element/community-list-element.component'; +import { ItemListElementComponent } from './object-list/item-list-element/item-list-element.component'; +import { ObjectListElementComponent } from './object-list/object-list-element/object-list-element.component'; +import { SearchResultListElementComponent } from './object-list/search-result-list-element/search-result-list-element.component'; +import { WrapperListElementComponent } from './object-list/wrapper-list-element/wrapper-list-element.component'; +import { ObjectListComponent } from './object-list/object-list.component'; -import { CollectionGridElementComponent} from '../object-grid/collection-grid-element/collection-grid-element.component' -import { CommunityGridElementComponent} from '../object-grid/community-grid-element/community-grid-element.component' -import { ItemGridElementComponent} from '../object-grid/item-grid-element/item-grid-element.component' -import { ObjectGridElementComponent} from '../object-grid/object-grid-element/object-grid-element.component' -import { WrapperGridElementComponent} from '../object-grid/wrapper-grid-element/wrapper-grid-element.component' -import { ObjectGridComponent } from '../object-grid/object-grid.component'; -import { ObjectCollectionComponent } from '../object-collection/object-collection.component'; +import { CollectionGridElementComponent} from './object-grid/collection-grid-element/collection-grid-element.component' +import { CommunityGridElementComponent} from './object-grid/community-grid-element/community-grid-element.component' +import { ItemGridElementComponent} from './object-grid/item-grid-element/item-grid-element.component' +import { ObjectGridElementComponent} from './object-grid/object-grid-element/object-grid-element.component' +import { WrapperGridElementComponent} from './object-grid/wrapper-grid-element/wrapper-grid-element.component' +import { ObjectGridComponent } from './object-grid/object-grid.component'; +import { ObjectCollectionComponent } from './object-collection/object-collection.component'; import { ComcolPageContentComponent } from './comcol-page-content/comcol-page-content.component'; import { ComcolPageHeaderComponent } from './comcol-page-header/comcol-page-header.component'; import { ComcolPageLogoComponent } from './comcol-page-logo/comcol-page-logo.component'; @@ -38,9 +38,9 @@ import { LoadingComponent } from './loading/loading.component'; import { PaginationComponent } from './pagination/pagination.component'; import { ThumbnailComponent } from '../thumbnail/thumbnail.component'; import { SearchFormComponent } from './search-form/search-form.component'; -import { SearchResultGridElementComponent } from '../object-grid/search-result-grid-element/search-result-grid-element.component'; +import { SearchResultGridElementComponent } from './object-grid/search-result-grid-element/search-result-grid-element.component'; import { ViewModeSwitchComponent } from './view-mode-switch/view-mode-switch.component'; -import { GridThumbnailComponent } from '../object-grid/grid-thumbnail/grid-thumbnail.component'; +import { GridThumbnailComponent } from './object-grid/grid-thumbnail/grid-thumbnail.component'; import { VarDirective } from './utils/var.directive'; const MODULES = [ From 04218060ddec55993f779ef7c0a3d4f63372a939 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 6 Nov 2017 10:08:28 +0100 Subject: [PATCH 43/77] 150 Backup commit --- .../object-collection.component.spec.ts | 13 +++--- .../collection-grid-element.component.spec.ts | 43 ++++++++++++++++++ .../community-grid-element.component.spec.ts | 44 +++++++++++++++++++ .../item-grid-element.component.spec.ts | 42 +++++++++++++++++- ...-search-result-grid-element.component.html | 14 +++++- ...-search-result-grid-element.component.html | 14 +++++- .../wrapper-grid-element.component.spec.ts | 43 ++++++++++++++++++ 7 files changed, 202 insertions(+), 11 deletions(-) create mode 100644 src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts diff --git a/src/app/shared/object-collection/object-collection.component.spec.ts b/src/app/shared/object-collection/object-collection.component.spec.ts index a56a3e56dc..6793042f35 100644 --- a/src/app/shared/object-collection/object-collection.component.spec.ts +++ b/src/app/shared/object-collection/object-collection.component.spec.ts @@ -4,7 +4,7 @@ import { element } from 'protractor'; import { By } from '@angular/platform-browser'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { Config } from '../../../config/config.interface'; -import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { RouterStub } from '../testing/router-stub'; @@ -12,6 +12,7 @@ import { RouterStub } from '../testing/router-stub'; describe('ObjectCollectionComponent', () => { let fixture: ComponentFixture; let objectCollectionComponent: ObjectCollectionComponent; + const queryParam = 'test query'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const activatedRouteStub = { @@ -34,19 +35,21 @@ describe('ObjectCollectionComponent', () => { beforeEach(async(() => { fixture = TestBed.createComponent(ObjectCollectionComponent); objectCollectionComponent = fixture.componentInstance; + })); it('should only show the grid component when the viewmode is set to grid', () => { objectCollectionComponent.currentMode = ViewMode.Grid; - // expect(By.css('ds-object-grid')).toEqual(1); - // expect(By.css('ds-object-list')).toEqual(0); + + expect(fixture.debugElement.query(By.css('ds-object-grid'))).toBeDefined(); + expect(fixture.debugElement.query(By.css('ds-object-list'))).toBeNull(); }); it('should only show the list component when the viewmode is set to list', () => { objectCollectionComponent.currentMode = ViewMode.List; - // expect(By.css('ds-object-list').length).toEqual(1); - // expect(By.css('ds-object-grid').length).toEqual(0); + expect(fixture.debugElement.query(By.css('ds-object-list'))).toBeDefined(); + expect(fixture.debugElement.query(By.css('ds-object-grid'))).toBeNull(); }) }); diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts index e69de29bb2..a1af8b5a3c 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts @@ -0,0 +1,43 @@ +import { CollectionGridElementComponent } from './collection-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; + +let collectionGridElementComponent: CollectionGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; + +describe('CollectionGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CollectionGridElementComponent ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useFactory: (collectionGridElementComponent)} + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(CollectionGridElementComponent); + collectionGridElementComponent = fixture.componentInstance; + + })); + + it('should show the collection cards in the grid element',()=>{ + expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); + }) +}) diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts new file mode 100644 index 0000000000..f6ab7bc6cd --- /dev/null +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts @@ -0,0 +1,44 @@ +import { CommunityGridElementComponent } from './community-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../testing/router-stub'; +import { Observable } from 'rxjs/Observable'; +import { By } from '@angular/platform-browser'; +import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { Community } from '../../../core/shared/community.model'; + +let communityGridElementComponent: CommunityGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +describe('CommunityGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CommunityGridElementComponent ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useFactory: (communityGridElementComponent)} + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(CommunityGridElementComponent); + communityGridElementComponent = fixture.componentInstance; + + })); + + it('should show the community cards in the grid element',()=>{ + expect(fixture.debugElement.query(By.css('ds-community-grid-element'))).toBeDefined(); + }) +}); diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts index 0da99aa697..b4fb9c8029 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts @@ -1,6 +1,44 @@ import { ItemGridElementComponent } from './item-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { TruncatePipe } from '../../utils/truncate.pipe'; -describe('ItemGridElementComponent',()=>{ - let itemGridElementComponent: ItemGridElementComponent; +let itemGridElementComponent: ItemGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +describe('ItemGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ItemGridElementComponent , TruncatePipe], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useFactory: (itemGridElementComponent)} + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(ItemGridElementComponent); + itemGridElementComponent = fixture.componentInstance; + + })); + + it('should show the item cards in the grid element',()=>{ + expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined(); + }) }) diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html index 914fb49487..ae63924374 100644 --- a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html @@ -1,2 +1,12 @@ - -
        +
        + + + + +
        +

        {{dso.name}}

        +

        {{dso.shortDescription}}

        + View + +
        +
        diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html index d09ef7d668..2707934c56 100644 --- a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html @@ -1,2 +1,12 @@ - -
        +
        + + + + + +
        +

        {{dso.name}}

        +

        {{dso.shortDescription}}

        + View +
        +
        diff --git a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts index e69de29bb2..5b02fbe95a 100644 --- a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts @@ -0,0 +1,43 @@ +import { WrapperGridElementComponent } from './wrapper-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; + +let wrapperGridElementComponent: WrapperGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; + +describe('WrapperGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ WrapperGridElementComponent ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useFactory: (wrapperGridElementComponent)} + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(WrapperGridElementComponent); + wrapperGridElementComponent = fixture.componentInstance; + + })); + + it('should show the wrapper element containing the cards',()=>{ + expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); + }) +}) From 68dd411ae782e2f78eeccbd0da3edcee61fb0dec Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 6 Nov 2017 13:40:00 +0100 Subject: [PATCH 44/77] #150 Grid element testing --- .../collection-grid-element.component.spec.ts | 26 +++++- .../community-grid-element.component.spec.ts | 24 +++++- .../item-grid-element.component.spec.ts | 30 ++++++- ...arch-result-grid-element.component.spec.ts | 67 +++++++++++++++ ...arch-result-grid-element.component.spec.ts | 67 +++++++++++++++ ...arch-result-grid-element.component.spec.ts | 84 +++++++++++++++++++ 6 files changed, 290 insertions(+), 8 deletions(-) create mode 100644 src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts create mode 100644 src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts create mode 100644 src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts index a1af8b5a3c..fd935af992 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts @@ -5,6 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { RouterStub } from '../../testing/router-stub'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; +import { Collection } from '../../../core/shared/collection.model'; let collectionGridElementComponent: CollectionGridElementComponent; let fixture: ComponentFixture; @@ -16,6 +17,15 @@ const activatedRouteStub = { scope: scopeParam }) }; +let mockCollection: Collection = Object.assign(new Collection(), { + metadata: [ + { + key: 'dc.description.abstract', + language: 'en_US', + value: 'Short description' + }] +}); +let createdGridElementComponent:CollectionGridElementComponent= new CollectionGridElementComponent(mockCollection); describe('CollectionGridElementComponent', () => { beforeEach(async(() => { @@ -24,7 +34,7 @@ describe('CollectionGridElementComponent', () => { providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useFactory: (collectionGridElementComponent)} + { provide: 'objectElementProvider', useValue: (createdGridElementComponent)} ], schemas: [ NO_ERRORS_SCHEMA ] @@ -33,11 +43,19 @@ describe('CollectionGridElementComponent', () => { beforeEach(async(() => { fixture = TestBed.createComponent(CollectionGridElementComponent); - collectionGridElementComponent = fixture.componentInstance; - })); it('should show the collection cards in the grid element',()=>{ expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); - }) + }); + + it('should only show the description if "short description" metadata is present',()=>{ + let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + + if(mockCollection.shortDescription.length>0){ + expect(descriptionText).toBeDefined(); + }else{ + expect(descriptionText).not.toBeDefined(); + } + }); }) diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts index f6ab7bc6cd..dc837e3c0c 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts @@ -18,6 +18,18 @@ const activatedRouteStub = { scope: scopeParam }) }; + +let mockCommunity: Community = Object.assign(new Community(), { + metadata: [ + { + key: 'dc.description.abstract', + language: 'en_US', + value: 'Short description' + }] +}); + +let createdGridElementComponent:CommunityGridElementComponent= new CommunityGridElementComponent(mockCommunity); + describe('CommunityGridElementComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ @@ -25,7 +37,7 @@ describe('CommunityGridElementComponent', () => { providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useFactory: (communityGridElementComponent)} + { provide: 'objectElementProvider', useValue: (createdGridElementComponent)} ], schemas: [ NO_ERRORS_SCHEMA ] @@ -41,4 +53,14 @@ describe('CommunityGridElementComponent', () => { it('should show the community cards in the grid element',()=>{ expect(fixture.debugElement.query(By.css('ds-community-grid-element'))).toBeDefined(); }) + + it('should only show the description if "short description" metadata is present',()=>{ + let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + + if(mockCommunity.shortDescription.length>0){ + expect(descriptionText).toBeDefined(); + }else{ + expect(descriptionText).not.toBeDefined(); + } + }); }); diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts index b4fb9c8029..8913dca3ee 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts @@ -6,6 +6,7 @@ import { RouterStub } from '../../testing/router-stub'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; import { TruncatePipe } from '../../utils/truncate.pipe'; +import { Item } from '../../../core/shared/item.model'; let itemGridElementComponent: ItemGridElementComponent; let fixture: ComponentFixture; @@ -17,6 +18,17 @@ const activatedRouteStub = { scope: scopeParam }) }; +/* tslint:disable:no-shadowed-variable */ +let mockItem: Item = Object.assign(new Item(), { + metadata: [ + { + key: 'dc.contributor.author', + language: 'en_US', + value: 'Smith, Donald' + }] +}); + +let createdGridElementComponent:ItemGridElementComponent= new ItemGridElementComponent(mockItem); describe('ItemGridElementComponent', () => { beforeEach(async(() => { @@ -25,7 +37,7 @@ describe('ItemGridElementComponent', () => { providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: Router, useClass: RouterStub }, - { provide: 'objectElementProvider', useFactory: (itemGridElementComponent)} + { provide: 'objectElementProvider', useValue: {createdGridElementComponent}} ], schemas: [ NO_ERRORS_SCHEMA ] @@ -39,6 +51,18 @@ describe('ItemGridElementComponent', () => { })); it('should show the item cards in the grid element',()=>{ - expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined(); - }) + expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined() + }); + + it('should only show the author span if the author metadata is present',()=>{ + let itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); + + if(mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length>0){ + expect(itemAuthorField).toBeDefined(); + }else{ + expect(itemAuthorField).toBeDefined(); + } + }); + + }) diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts new file mode 100644 index 0000000000..8d6fe6fb38 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts @@ -0,0 +1,67 @@ +import {CollectionSearchResultGridElementComponent } from './collection-search-result-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { TruncatePipe } from '../../../utils/truncate.pipe'; +import { Community } from '../../../../core/shared/community.model'; +import { Collection } from '../../../../core/shared/collection.model'; + + +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +let mockCollection: Collection = Object.assign(new Collection(), { + metadata: [ + { + key: 'dc.description.abstract', + language: 'en_US', + value: 'Short description' + } ] + +}); + +let createdGridElementComponent: CollectionSearchResultGridElementComponent = new CollectionSearchResultGridElementComponent(mockCollection); + + +describe('CollectionSearchResultGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CollectionSearchResultGridElementComponent, TruncatePipe ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useValue: (createdGridElementComponent) } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(CollectionSearchResultGridElementComponent); + })); + + it('should show the item result cards in the grid element', () => { + expect(fixture.debugElement.query(By.css('ds-collection-search-result-grid-element'))).toBeDefined(); + }); + + + it('should only show the description if "short description" metadata is present',()=>{ + let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + + if(mockCollection.shortDescription.length>0){ + expect(descriptionText).toBeDefined(); + }else{ + expect(descriptionText).not.toBeDefined(); + } + }); +}); diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts new file mode 100644 index 0000000000..0924700da7 --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts @@ -0,0 +1,67 @@ +import { CommunitySearchResultGridElementComponent } from './community-search-result-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { TruncatePipe } from '../../../utils/truncate.pipe'; +import { Community } from '../../../../core/shared/community.model'; + + +let communitySearchResultGridElementComponent: CommunitySearchResultGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +let mockCommunity: Community = Object.assign(new Community(), { + metadata: [ + { + key: 'dc.description.abstract', + language: 'en_US', + value: 'Short description' + } ] + +}); + +let createdGridElementComponent: CommunitySearchResultGridElementComponent = new CommunitySearchResultGridElementComponent(mockCommunity); + + +describe('CommunitySearchResultGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CommunitySearchResultGridElementComponent, TruncatePipe ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useValue: (createdGridElementComponent) } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(CommunitySearchResultGridElementComponent); + })); + + it('should show the item result cards in the grid element', () => { + expect(fixture.debugElement.query(By.css('ds-community-search-result-grid-element'))).toBeDefined(); + }); + + + it('should only show the description if "short description" metadata is present',()=>{ + let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + + if(mockCommunity.shortDescription.length>0){ + expect(descriptionText).toBeDefined(); + }else{ + expect(descriptionText).not.toBeDefined(); + } + }); +}); diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts new file mode 100644 index 0000000000..318910304f --- /dev/null +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts @@ -0,0 +1,84 @@ +import { ItemSearchResultGridElementComponent } from './item-search-result-grid-element.component'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Observable } from 'rxjs/Observable'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RouterStub } from '../../../testing/router-stub'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { TruncatePipe } from '../../../utils/truncate.pipe'; +import { Item } from '../../../../core/shared/item.model'; + + +let itemSearchResultGridElementComponent: ItemSearchResultGridElementComponent; +let fixture: ComponentFixture; +const queryParam = 'test query'; +const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; +const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) +}; +let mockItem: Item = Object.assign(new Item(), { + metadata: [ + { + key: 'dc.contributor.author', + language: 'en_US', + value: 'Smith, Donald' + }, + { + key: 'dc.date.issued', + language: null, + value: '1650-06-26' + }] +}); +let createdGridElementComponent:ItemSearchResultGridElementComponent= new ItemSearchResultGridElementComponent(mockItem); + +describe('ItemSearchResultGridElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ItemSearchResultGridElementComponent, TruncatePipe ], + providers: [ + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: Router, useClass: RouterStub }, + { provide: 'objectElementProvider', useValue: (createdGridElementComponent) } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).compileComponents(); // compile template and css + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(ItemSearchResultGridElementComponent); + itemSearchResultGridElementComponent = fixture.componentInstance; + + })); + + it('should show the item result cards in the grid element',()=>{ + expect(fixture.debugElement.query(By.css('ds-item-search-result-grid-element'))).toBeDefined(); + }); + + it('should only show the author span if the author metadata is present',()=>{ + let itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); + + if(mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length>0){ + expect(itemAuthorField).toBeDefined(); + }else{ + expect(itemAuthorField).not.toBeDefined(); + } + }); + + it('should only show the date span if the issuedate is present',()=>{ + let dateField = expect(fixture.debugElement.query(By.css('span.item-list-date'))); + + if(mockItem.findMetadata('dc.date.issued').length>0){ + expect(dateField).toBeDefined(); + }else{ + expect(dateField).not.toBeDefined(); + } + }); + + + + +}); From 7ae8950be5405c392d6399c024dc2178379ad520 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Mon, 13 Nov 2017 13:37:02 +0100 Subject: [PATCH 45/77] #150 Removal of inherited css + restyling using bootstrap classes --- package.json | 1 - .../collection-grid-element.component.html | 6 ++- .../collection-grid-element.component.scss | 2 +- .../community-grid-element.component.html | 6 ++- .../community-grid-element.component.scss | 2 +- .../shared/object-grid/grid-card-styling.scss | 45 ------------------- .../item-grid-element.component.html | 6 ++- .../item-grid-element.component.scss | 2 +- .../object-grid-element.component.scss | 1 - .../object-grid/object-grid.component.html | 4 +- .../object-grid/object-grid.component.scss | 22 +++++++++ ...-search-result-grid-element.component.html | 7 +-- ...-search-result-grid-element.component.scss | 1 - ...-search-result-grid-element.component.html | 6 ++- ...-search-result-grid-element.component.scss | 2 +- ...-search-result-grid-element.component.html | 10 +++-- ...-search-result-grid-element.component.scss | 2 +- .../search-result-grid-element.component.scss | 1 - .../wrapper-grid-element.component.scss | 2 +- src/styles/_custom_variables.scss | 2 + yarn.lock | 4 -- 21 files changed, 58 insertions(+), 76 deletions(-) delete mode 100644 src/app/shared/object-grid/grid-card-styling.scss diff --git a/package.json b/package.json index 662b4b627f..f2bb074ff4 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,6 @@ "methods": "1.1.2", "morgan": "1.9.0", "ngx-pagination": "3.0.1", - "object-fit-images": "^3.2.3", "pem": "1.12.3", "reflect-metadata": "0.1.10", "rxjs": "5.4.3", diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html index 5dc717cf54..b1287212a3 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.html @@ -3,10 +3,12 @@ -
        +

        {{object.name}}

        {{object.shortDescription}}

        - View +
        + View +
        diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss index 946c8a6a31..51a7fc6a55 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; + diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html index e4ea3dcb13..b6f4c5c5d9 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.html @@ -4,9 +4,11 @@ -
        +

        {{object.name}}

        {{object.shortDescription}}

        - View +
        + View +
        diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss index 946c8a6a31..51a7fc6a55 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; + diff --git a/src/app/shared/object-grid/grid-card-styling.scss b/src/app/shared/object-grid/grid-card-styling.scss deleted file mode 100644 index 2fe199d1ce..0000000000 --- a/src/app/shared/object-grid/grid-card-styling.scss +++ /dev/null @@ -1,45 +0,0 @@ -@import '../../../styles/custom_variables'; - -.card-title{ - line-height: $line-height-base; - height:$headings-line-height; - font-size:$headings-font-size; - overflow: hidden; - text-overflow: ellipsis; -} - -.card-text { - overflow: hidden; - text-overflow: ellipsis; - line-height: $line-height-base; - margin-bottom:$card-block-margin-base*2; -} -.card-text.item-authors { - height: $line-height-base; -} -.card-text.item-abstract { - height: $content-line-height; -} - -.viewButton{ - display:table; - margin:auto; - width: $card-button-width; -} - -.card{ - margin-bottom: $card-block-margin-base *3; - height: $card-height-percentage; -} - -.card-img-top ::ng-deep img -{ - height: $card-thumbnail-height; - width: 100%; - object-fit: cover; -} - -.card-block{ - margin: $card-block-margin-base; -} - diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html index 3fae55088e..b8bacfaf2e 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.html @@ -4,7 +4,7 @@ -
        +

        {{object.findMetadata('dc.title')}}

        @@ -16,6 +16,8 @@

        {{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}

        - View +
        + View +
        diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss index 946c8a6a31..51a7fc6a55 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; + diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss index d299edd0ab..d4720c4a64 100644 --- a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss +++ b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss @@ -1,5 +1,4 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; :host { display: block; margin-bottom: $spacer; diff --git a/src/app/shared/object-grid/object-grid.component.html b/src/app/shared/object-grid/object-grid.component.html index ebcf240d28..32c3e9ec4f 100644 --- a/src/app/shared/object-grid/object-grid.component.html +++ b/src/app/shared/object-grid/object-grid.component.html @@ -10,8 +10,8 @@ (sortDirectionChange)="onSortDirectionChange($event)" (sortFieldChange)="onSortDirectionChange($event)" (paginationChange)="onPaginationChange($event)"> -
        -
        +
        diff --git a/src/app/shared/object-grid/object-grid.component.scss b/src/app/shared/object-grid/object-grid.component.scss index 48e6526dff..c01dfbdc85 100644 --- a/src/app/shared/object-grid/object-grid.component.scss +++ b/src/app/shared/object-grid/object-grid.component.scss @@ -1 +1,23 @@ @import '../../../styles/variables'; + +ds-wrapper-grid-element ::ng-deep { + div.thumbnail > img { + height: $card-thumbnail-height; + width: 100%; + } + .card-title { + line-height: $headings-line-height; + height: ($headings-line-height*3) +em; + overflow: hidden; + text-overflow: ellipsis; + } + .item-abstract { + line-height: $line-height-base; + height: ($line-height-base*5)+em; + overflow: hidden; + text-overflow: ellipsis; + } + div.card { + margin-bottom: 20px; + } +} diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html index ae63924374..d6b1bfb5f4 100644 --- a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.html @@ -3,10 +3,11 @@ -
        +

        {{dso.name}}

        {{dso.shortDescription}}

        - View - +
        + View +
        diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss index 2867dd78ac..1d0786105c 100644 --- a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.scss @@ -1,2 +1 @@ @import '../../../../../styles/variables'; -@import '../../grid-card-styling'; diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html index 2707934c56..8ff6874bff 100644 --- a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.html @@ -4,9 +4,11 @@ -
        +

        {{dso.name}}

        {{dso.shortDescription}}

        - View +
        + View +
        diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss index 2867dd78ac..bd63aa6a3a 100644 --- a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../../styles/variables'; -@import '../../grid-card-styling'; + diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html index be84039416..ce9324477f 100644 --- a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.html @@ -1,10 +1,10 @@
        - + -
        -

        +
        +

        @@ -25,7 +25,9 @@

        - View +
        + View +
        diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss index 2867dd78ac..bd63aa6a3a 100644 --- a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../../styles/variables'; -@import '../../grid-card-styling'; + diff --git a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss index ebec5817e6..e8d681fb32 100644 --- a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss +++ b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.scss @@ -1,5 +1,4 @@ @import '../../../../styles/variables'; - @import '../grid-card-styling'; :host { /deep/ em { font-weight: bold; diff --git a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss index 946c8a6a31..51a7fc6a55 100644 --- a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss +++ b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.scss @@ -1,2 +1,2 @@ @import '../../../../styles/variables'; -@import '../grid-card-styling'; + diff --git a/src/styles/_custom_variables.scss b/src/styles/_custom_variables.scss index 8c0dcae928..4dcc161cc4 100644 --- a/src/styles/_custom_variables.scss +++ b/src/styles/_custom_variables.scss @@ -2,3 +2,5 @@ $content-spacing: $spacer * 1.5; $button-height: $input-btn-padding-y * 2 + $input-btn-line-height + calculateRem($input-btn-border-width*2); $card-height-percentage:98%; +$card-thumbnail-height:240px; + diff --git a/yarn.lock b/yarn.lock index 4211b7228a..91b2a787e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4804,10 +4804,6 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" -object-fit-images@^3.2.3: - version "3.2.3" - resolved "https://registry.yarnpkg.com/object-fit-images/-/object-fit-images-3.2.3.tgz#4089f6d0070a3b5563d3c1ab6f1b28d61331f0ac" - object-keys@^1.0.8: version "1.0.11" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d" From 9be1d5946474219cce9e5a768cdcc324477e4765 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 14 Nov 2017 14:51:49 +0100 Subject: [PATCH 46/77] Additional IDE generated files ignored --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f8395956f5..dd5f5fa391 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ npm-debug.log /coverage/ .idea +*.iml *.ngfactory.ts *.css.shim.ts *.scss.shim.ts From ee099e275c821f2afcedd64657737b570e6d19d8 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Wed, 15 Nov 2017 09:15:34 +0100 Subject: [PATCH 47/77] #150 Removal of iml file + small margin between pagination and grid --- dspace-angular.iml | 8 -------- src/app/shared/object-grid/object-grid.component.html | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 dspace-angular.iml diff --git a/dspace-angular.iml b/dspace-angular.iml deleted file mode 100644 index 5806390693..0000000000 --- a/dspace-angular.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/app/shared/object-grid/object-grid.component.html b/src/app/shared/object-grid/object-grid.component.html index 32c3e9ec4f..445d681268 100644 --- a/src/app/shared/object-grid/object-grid.component.html +++ b/src/app/shared/object-grid/object-grid.component.html @@ -10,7 +10,7 @@ (sortDirectionChange)="onSortDirectionChange($event)" (sortFieldChange)="onSortDirectionChange($event)" (paginationChange)="onPaginationChange($event)"> -
        +
        From d1b225bd954a5cfb6de493c6524eab5b9720bdd3 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Wed, 15 Nov 2017 10:28:11 +0100 Subject: [PATCH 48/77] #150 Merge fixes --- .../search-service/search.service.ts | 2 +- .../object-collection.component.html | 2 ++ .../object-collection.component.ts | 5 ++-- .../object-grid/object-grid.component.html | 4 +-- .../object-grid/object-grid.component.scss | 4 +++ .../object-grid/object-grid.component.ts | 4 +-- .../object-list/object-list.component.ts | 27 +------------------ 7 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 63b1b04dce..8ca84f4a32 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -12,7 +12,7 @@ import { Item } from '../../core/shared/item.model'; import { SearchFilterConfig } from './search-filter-config.model'; import { FilterType } from './filter-type.model'; import { FacetValue } from './facet-value.model'; -import { ItemSearchResult } from '../../object-collection/shared/item-search-result.model'; +import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; import { ViewMode } from '../../+search-page/search-options.model'; import { Router, NavigationExtras, ActivatedRoute } from '@angular/router'; import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; diff --git a/src/app/shared/object-collection/object-collection.component.html b/src/app/shared/object-collection/object-collection.component.html index 6c2a2fb1de..c9b1cb92f5 100644 --- a/src/app/shared/object-collection/object-collection.component.html +++ b/src/app/shared/object-collection/object-collection.component.html @@ -1,12 +1,14 @@ diff --git a/src/app/shared/object-collection/object-collection.component.ts b/src/app/shared/object-collection/object-collection.component.ts index 8d5a9ce3c7..5a356dcbdc 100644 --- a/src/app/shared/object-collection/object-collection.component.ts +++ b/src/app/shared/object-collection/object-collection.component.ts @@ -27,6 +27,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { @Input() objects: RemoteData; @Input() config?: PaginationComponentOptions; @Input() sortConfig: SortOptions; + @Input() hideGear = false; pageInfo: Observable; private sub; /** @@ -60,13 +61,13 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { ngOnChanges(changes: SimpleChanges) { if (changes.objects && !changes.objects.isFirstChange()) { - this.pageInfo = this.objects.pageInfo; + // this.pageInfo = this.objects.pageInfo; } } ngOnInit(): void { - this.pageInfo = this.objects.pageInfo; + // this.pageInfo = this.objects.pageInfo; this.sub = this.route .queryParams diff --git a/src/app/shared/object-grid/object-grid.component.html b/src/app/shared/object-grid/object-grid.component.html index 445d681268..ad9bf20a32 100644 --- a/src/app/shared/object-grid/object-grid.component.html +++ b/src/app/shared/object-grid/object-grid.component.html @@ -10,9 +10,9 @@ (sortDirectionChange)="onSortDirectionChange($event)" (sortFieldChange)="onSortDirectionChange($event)" (paginationChange)="onPaginationChange($event)"> -
        +
        + *ngFor="let object of objects?.payload">
        diff --git a/src/app/shared/object-grid/object-grid.component.scss b/src/app/shared/object-grid/object-grid.component.scss index c01dfbdc85..a85e38d26f 100644 --- a/src/app/shared/object-grid/object-grid.component.scss +++ b/src/app/shared/object-grid/object-grid.component.scss @@ -17,6 +17,10 @@ ds-wrapper-grid-element ::ng-deep { overflow: hidden; text-overflow: ellipsis; } + .item-authors{ + line-height: $line-height-base; + height: ($line-height-base*1.5)+em; + } div.card { margin-bottom: 20px; } diff --git a/src/app/shared/object-grid/object-grid.component.ts b/src/app/shared/object-grid/object-grid.component.ts index c811d90d62..1c890c8959 100644 --- a/src/app/shared/object-grid/object-grid.component.ts +++ b/src/app/shared/object-grid/object-grid.component.ts @@ -64,12 +64,12 @@ export class ObjectGridComponent implements OnChanges, OnInit { ngOnChanges(changes: SimpleChanges) { if (changes.objects && !changes.objects.isFirstChange()) { - this.pageInfo = this.objects.pageInfo; + // this.pageInfo = this.objects.pageInfo; } } ngOnInit(): void { - this.pageInfo = this.objects.pageInfo; + // this.pageInfo = this.objects.pageInfo; } /** diff --git a/src/app/shared/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts index c1e3d21760..a300e06f59 100644 --- a/src/app/shared/object-list/object-list.component.ts +++ b/src/app/shared/object-list/object-list.component.ts @@ -7,8 +7,6 @@ import { ViewEncapsulation } from '@angular/core'; -import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; - import { RemoteData } from '../../core/data/remote-data'; import { PageInfo } from '../../core/shared/page-info.model'; @@ -18,9 +16,8 @@ import { SortOptions, SortDirection } from '../../core/cache/models/sort-options import { fadeIn } from '../animations/fade'; import { ListableObject } from '../object-collection/shared/listable-object.model'; -import { hasValue } from '../shared/empty.util'; +import { hasValue } from '../empty.util'; -import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; @Component({ changeDetection: ChangeDetectionStrategy.Default, @@ -86,28 +83,6 @@ export class ObjectListComponent { */ @Output() sortFieldChange: EventEmitter = new EventEmitter(); data: any = {}; - - - onPageChange(event) { - this.pageChange.emit(event); - } - - onPageSizeChange(event) { - this.pageSizeChange.emit(event); - } - - onSortDirectionChange(event) { - this.sortDirectionChange.emit(event); - } - - onSortFieldChange(event) { - this.sortFieldChange.emit(event); - } - - onPaginationChange(event) { - this.paginationChange.emit(event); - } - onPageChange(event) { this.pageChange.emit(event); } From db0db81c63de93f5fc0124ff4ffbda4139300ba5 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 17 Nov 2017 16:26:33 +0100 Subject: [PATCH 49/77] #150 Generalised AbstractListableElementComponent instead of grid/list specific implementations --- .../abstract-listable-element.component.ts | 13 +++++++++++++ .../collection-grid-element.component.ts | 4 ++-- .../community-grid-element.component.ts | 4 ++-- .../item-grid-element.component.ts | 4 ++-- .../object-grid-element.component.html | 0 .../object-grid-element.component.scss | 5 ----- .../object-grid-element.component.ts | 14 -------------- .../search-result-grid-element.component.ts | 4 ++-- .../collection-list-element.component.ts | 4 ++-- .../community-list-element.component.ts | 4 ++-- .../item-list-element.component.ts | 4 ++-- .../object-list-element.component.html | 0 .../object-list-element.component.scss | 6 ------ .../object-list-element.component.ts | 14 -------------- .../search-result-list-element.component.ts | 4 ++-- src/app/shared/shared.module.ts | 6 ++---- 16 files changed, 31 insertions(+), 59 deletions(-) create mode 100644 src/app/shared/object-collection/shared/object-collection-element/abstract-listable-element.component.ts delete mode 100644 src/app/shared/object-grid/object-grid-element/object-grid-element.component.html delete mode 100644 src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss delete mode 100644 src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts delete mode 100644 src/app/shared/object-list/object-list-element/object-list-element.component.html delete mode 100644 src/app/shared/object-list/object-list-element/object-list-element.component.scss delete mode 100644 src/app/shared/object-list/object-list-element/object-list-element.component.ts diff --git a/src/app/shared/object-collection/shared/object-collection-element/abstract-listable-element.component.ts b/src/app/shared/object-collection/shared/object-collection-element/abstract-listable-element.component.ts new file mode 100644 index 0000000000..d52036b5dc --- /dev/null +++ b/src/app/shared/object-collection/shared/object-collection-element/abstract-listable-element.component.ts @@ -0,0 +1,13 @@ +import { Component, Inject } from '@angular/core'; +import { ListableObject } from '../listable-object.model'; + +@Component({ + selector: 'ds-abstract-object-element', + template: ``, +}) +export class AbstractListableElementComponent { + object: T; + public constructor(@Inject('objectElementProvider') public listableObject: ListableObject) { + this.object = listableObject as T; + } +} diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts index 09aadab15e..a7f5ef3e49 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; import { Collection } from '../../../core/shared/collection.model'; -import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; @Component({ @@ -13,4 +13,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Collection, ViewMode.Grid) -export class CollectionGridElementComponent extends ObjectGridElementComponent {} +export class CollectionGridElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts index d40bd717a4..21d73ff0fa 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.ts @@ -1,7 +1,7 @@ import { Component, Input, Inject } from '@angular/core'; import { Community } from '../../../core/shared/community.model'; -import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Community, ViewMode.Grid) -export class CommunityGridElementComponent extends ObjectGridElementComponent {} +export class CommunityGridElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts index c41a6c9352..5a8d46f1f2 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.ts @@ -2,7 +2,7 @@ import { Component, Input, Inject } from '@angular/core'; import { Item } from '../../../core/shared/item.model'; import { renderElementsFor} from '../../object-collection/shared/dso-element-decorator'; -import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { ViewMode } from '../../../+search-page/search-options.model'; @Component({ @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Item, ViewMode.Grid) -export class ItemGridElementComponent extends ObjectGridElementComponent {} +export class ItemGridElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.html b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.html deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss deleted file mode 100644 index d4720c4a64..0000000000 --- a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.scss +++ /dev/null @@ -1,5 +0,0 @@ -@import '../../../../styles/variables'; -:host { - display: block; - margin-bottom: $spacer; -} diff --git a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts b/src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts deleted file mode 100644 index c3ab5e39e3..0000000000 --- a/src/app/shared/object-grid/object-grid-element/object-grid-element.component.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Component, Inject } from '@angular/core'; -import { ListableObject } from '../../object-collection/shared/listable-object.model'; - -@Component({ - selector: 'ds-object-grid-element', - styleUrls: ['./object-grid-element.component.scss'], - templateUrl: './object-grid-element.component.html' -}) -export class ObjectGridElementComponent { - object: T; - public constructor(@Inject('objectElementProvider') public gridable: ListableObject) { - this.object = gridable as T; - } -} diff --git a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts index 052a9377b5..8e1d7e0647 100644 --- a/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts +++ b/src/app/shared/object-grid/search-result-grid-element/search-result-grid-element.component.ts @@ -4,7 +4,7 @@ import { SearchResult } from '../../../+search-page/search-result.model'; import { DSpaceObject } from '../../../core/shared/dspace-object.model'; import { Metadatum } from '../../../core/shared/metadatum.model'; import { isEmpty, hasNoValue } from '../../empty.util'; -import { ObjectGridElementComponent } from '../object-grid-element/object-grid-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; @Component({ @@ -12,7 +12,7 @@ import { ListableObject } from '../../object-collection/shared/listable-object.m template: `` }) -export class SearchResultGridElementComponent, K extends DSpaceObject> extends ObjectGridElementComponent { +export class SearchResultGridElementComponent, K extends DSpaceObject> extends AbstractListableElementComponent { dso: K; public constructor(@Inject('objectElementProvider') public gridable: ListableObject) { diff --git a/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts b/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts index 5e08e8ef3a..f95c087d5c 100644 --- a/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts +++ b/src/app/shared/object-list/collection-list-element/collection-list-element.component.ts @@ -1,9 +1,9 @@ import { Component, Inject } from '@angular/core'; import { Collection } from '../../../core/shared/collection.model'; -import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; @Component({ selector: 'ds-collection-list-element', @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Collection, ViewMode.List) -export class CollectionListElementComponent extends ObjectListElementComponent {} +export class CollectionListElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-list/community-list-element/community-list-element.component.ts b/src/app/shared/object-list/community-list-element/community-list-element.component.ts index cd6e6f7574..e92c080a31 100644 --- a/src/app/shared/object-list/community-list-element/community-list-element.component.ts +++ b/src/app/shared/object-list/community-list-element/community-list-element.component.ts @@ -1,7 +1,7 @@ import { Component, Input, Inject } from '@angular/core'; import { Community } from '../../../core/shared/community.model'; -import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Community, ViewMode.List) -export class CommunityListElementComponent extends ObjectListElementComponent {} +export class CommunityListElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-list/item-list-element/item-list-element.component.ts b/src/app/shared/object-list/item-list-element/item-list-element.component.ts index 43c59f0980..e4efbd6b08 100644 --- a/src/app/shared/object-list/item-list-element/item-list-element.component.ts +++ b/src/app/shared/object-list/item-list-element/item-list-element.component.ts @@ -1,7 +1,7 @@ import { Component, Input, Inject } from '@angular/core'; import { Item } from '../../../core/shared/item.model'; -import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; import { renderElementsFor } from '../../object-collection/shared/dso-element-decorator'; import { ViewMode } from '../../../+search-page/search-options.model'; @@ -12,4 +12,4 @@ import { ViewMode } from '../../../+search-page/search-options.model'; }) @renderElementsFor(Item, ViewMode.List) -export class ItemListElementComponent extends ObjectListElementComponent {} +export class ItemListElementComponent extends AbstractListableElementComponent {} diff --git a/src/app/shared/object-list/object-list-element/object-list-element.component.html b/src/app/shared/object-list/object-list-element/object-list-element.component.html deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/app/shared/object-list/object-list-element/object-list-element.component.scss b/src/app/shared/object-list/object-list-element/object-list-element.component.scss deleted file mode 100644 index f96f4ae744..0000000000 --- a/src/app/shared/object-list/object-list-element/object-list-element.component.scss +++ /dev/null @@ -1,6 +0,0 @@ -@import '../../../../styles/variables'; - -:host { - display: block; - margin-bottom: $spacer; -} diff --git a/src/app/shared/object-list/object-list-element/object-list-element.component.ts b/src/app/shared/object-list/object-list-element/object-list-element.component.ts deleted file mode 100644 index 24f0ec1d93..0000000000 --- a/src/app/shared/object-list/object-list-element/object-list-element.component.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Component, Inject } from '@angular/core'; -import { ListableObject } from '../../object-collection/shared/listable-object.model'; - -@Component({ - selector: 'ds-object-list-element', - styleUrls: ['./object-list-element.component.scss'], - templateUrl: './object-list-element.component.html' -}) -export class ObjectListElementComponent { - object: T; - public constructor(@Inject('objectElementProvider') public listable: ListableObject) { - this.object = listable as T; - } -} diff --git a/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts index b89bb56da6..6c79eaad53 100644 --- a/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts +++ b/src/app/shared/object-list/search-result-list-element/search-result-list-element.component.ts @@ -1,18 +1,18 @@ import { Component, Inject } from '@angular/core'; -import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { SearchResult } from '../../../+search-page/search-result.model'; import { DSpaceObject } from '../../../core/shared/dspace-object.model'; import { Metadatum } from '../../../core/shared/metadatum.model'; import { isEmpty, hasNoValue } from '../../empty.util'; import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; @Component({ selector: 'ds-search-result-list-element', template: `` }) -export class SearchResultListElementComponent, K extends DSpaceObject> extends ObjectListElementComponent { +export class SearchResultListElementComponent, K extends DSpaceObject> extends AbstractListableElementComponent { dso: K; public constructor(@Inject('objectElementProvider') public listable: ListableObject) { diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 7ee5ba56df..ca13067851 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -17,7 +17,6 @@ import { TruncatePipe } from './utils/truncate.pipe'; import { CollectionListElementComponent } from './object-list/collection-list-element/collection-list-element.component'; import { CommunityListElementComponent } from './object-list/community-list-element/community-list-element.component'; import { ItemListElementComponent } from './object-list/item-list-element/item-list-element.component'; -import { ObjectListElementComponent } from './object-list/object-list-element/object-list-element.component'; import { SearchResultListElementComponent } from './object-list/search-result-list-element/search-result-list-element.component'; import { WrapperListElementComponent } from './object-list/wrapper-list-element/wrapper-list-element.component'; import { ObjectListComponent } from './object-list/object-list.component'; @@ -25,7 +24,7 @@ import { ObjectListComponent } from './object-list/object-list.component'; import { CollectionGridElementComponent} from './object-grid/collection-grid-element/collection-grid-element.component' import { CommunityGridElementComponent} from './object-grid/community-grid-element/community-grid-element.component' import { ItemGridElementComponent} from './object-grid/item-grid-element/item-grid-element.component' -import { ObjectGridElementComponent} from './object-grid/object-grid-element/object-grid-element.component' +import { AbstractListableElementComponent} from './object-collection/shared/object-collection-element/abstract-listable-element.component' import { WrapperGridElementComponent} from './object-grid/wrapper-grid-element/wrapper-grid-element.component' import { ObjectGridComponent } from './object-grid/object-grid.component'; import { ObjectCollectionComponent } from './object-collection/object-collection.component'; @@ -70,10 +69,9 @@ const COMPONENTS = [ ErrorComponent, LoadingComponent, ObjectListComponent, - ObjectListElementComponent, + AbstractListableElementComponent, WrapperListElementComponent, ObjectGridComponent, - ObjectGridElementComponent, WrapperGridElementComponent, ObjectCollectionComponent, PaginationComponent, From d045b67b736ad16ea618b9401c3f00e0668f1f1c Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 21 Nov 2017 13:57:49 +0100 Subject: [PATCH 50/77] 150 Separate maps per viewMode --- .../object-collection/shared/dso-element-decorator.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/shared/object-collection/shared/dso-element-decorator.ts b/src/app/shared/object-collection/shared/dso-element-decorator.ts index 5dc085d3a7..51aa57bc50 100644 --- a/src/app/shared/object-collection/shared/dso-element-decorator.ts +++ b/src/app/shared/object-collection/shared/dso-element-decorator.ts @@ -3,15 +3,18 @@ import { ListableObject } from './listable-object.model'; import { ViewMode } from '../../../+search-page/search-options.model'; const dsoElementMap = new Map(); -export function renderElementsFor(listable: GenericConstructor, viewMode : ViewMode) { +export function renderElementsFor(listable: GenericConstructor, viewMode: ViewMode) { return function decorator(objectElement: any) { if (!objectElement) { return; } - dsoElementMap.set(listable+viewMode, objectElement); + if (!dsoElementMap.get(viewMode)) { + dsoElementMap.set(viewMode, new Map()); + } + dsoElementMap.get(viewMode).set(listable, objectElement); }; } -export function rendersDSOType(listable: GenericConstructor, viewMode : ViewMode) { - return dsoElementMap.get(listable+viewMode); +export function rendersDSOType(listable: GenericConstructor, viewMode: ViewMode) { + return dsoElementMap.get(viewMode).get(listable); } From e331f7e288d0a2b09cfd9c21a87527da9b1fbd42 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 21 Nov 2017 16:16:37 +0100 Subject: [PATCH 51/77] #150 Rollback to previous state (not part of this issue) --- ...ty-page-sub-collection-list.component.html | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html index 9494cdb755..b04e93ff71 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html @@ -1,10 +1,15 @@ -
        -

        {{'community.sub-collection-list.head' | translate}}

        -
          - -
        -
        +
        +

        {{'community.sub-collection-list.head' | translate}}

        + +
        +
        From 27ae938153b81d3f5373e852fd26ca4eef8df5be Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Wed, 22 Nov 2017 08:13:24 +0100 Subject: [PATCH 52/77] #150 Avoid first "null" download for initial content --- .../object-grid/grid-thumbnail/grid-thumbnail.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html index 6221cbaba1..c0c3c1f65f 100644 --- a/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html +++ b/src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.html @@ -1,4 +1,4 @@
        - - + +
        From b86905ab0522c8157e24db151a6a58af3d68fde7 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 30 Nov 2017 15:06:52 +0100 Subject: [PATCH 53/77] #150 Fixing rebase errors --- src/app/+search-page/search-page.component.ts | 5 +++-- src/app/+search-page/search-service/search.service.ts | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 697e379f3d..6952a2da96 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -12,6 +12,8 @@ import { SearchService } from './search-service/search.service'; import { pushInOut } from '../shared/animations/push'; import { HostWindowService } from '../shared/host-window.service'; import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; +import { PaginationComponentOptions } from 'src/app/shared/pagination/pagination-component-options.model'; +import { SortOptions } from '../core/cache/models/sort-options.model'; /** * This component renders a simple item page. @@ -58,7 +60,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { pagination.pageSize = 10; const sort: SortOptions = new SortOptions(); - this.sortConfig=sort; + this.sortConfig = sort; this.searchOptions = this.service.searchOptions; } @@ -81,7 +83,6 @@ export class SearchPageComponent implements OnInit, OnDestroy { // pageSizeOptions = [9, 18, 27, 36 , 45, 54, 63, 72]; } - const sortDirection = +params.sortDirection || this.searchOptions.sort.direction; const pagination = Object.assign({}, this.searchOptions.pagination, diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 8ca84f4a32..52d86927d6 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -15,7 +15,6 @@ import { FacetValue } from './facet-value.model'; import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; import { ViewMode } from '../../+search-page/search-options.model'; import { Router, NavigationExtras, ActivatedRoute } from '@angular/router'; -import { ItemSearchResult } from '../../shared/object-collection/shared/item-search-result.model'; import { RouteService } from '../../shared/route.service'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; import { SortOptions } from '../../core/cache/models/sort-options.model'; From aca0bca694c87fa873eba86ae8d0b2761d8bec82 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Fri, 1 Dec 2017 10:08:52 +0100 Subject: [PATCH 54/77] 130: fixed test description mistakes --- src/app/core/cache/object-cache.effects.spec.ts | 2 +- src/app/core/cache/response-cache.effects.spec.ts | 2 +- src/app/core/data/request.reducer.spec.ts | 4 ++-- src/app/core/index/uuid-index.reducer.spec.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/core/cache/object-cache.effects.spec.ts b/src/app/core/cache/object-cache.effects.spec.ts index 48241c2c4f..d0a97a18fd 100644 --- a/src/app/core/cache/object-cache.effects.spec.ts +++ b/src/app/core/cache/object-cache.effects.spec.ts @@ -24,7 +24,7 @@ describe('ObjectCacheEffects', () => { describe('fixTimestampsOnRehydrate$', () => { - it('should return a RESET_TIMESTAMPS action in response to an REHYDRATE action to a new route', () => { + it('should return a RESET_TIMESTAMPS action in response to a REHYDRATE action', () => { spyOn(Date.prototype, 'getTime').and.callFake(() => { return timestamp; }); diff --git a/src/app/core/cache/response-cache.effects.spec.ts b/src/app/core/cache/response-cache.effects.spec.ts index 422b8bf181..60f4162fc6 100644 --- a/src/app/core/cache/response-cache.effects.spec.ts +++ b/src/app/core/cache/response-cache.effects.spec.ts @@ -24,7 +24,7 @@ describe('ResponseCacheEffects', () => { describe('fixTimestampsOnRehydrate$', () => { - it('should return a RESET_TIMESTAMPS action in response to an REHYDRATE action to a new route', () => { + it('should return a RESET_TIMESTAMPS action in response to an REHYDRATE action', () => { spyOn(Date.prototype, 'getTime').and.callFake(() => { return timestamp; }); diff --git a/src/app/core/data/request.reducer.spec.ts b/src/app/core/data/request.reducer.spec.ts index d9a58b4107..a6d84ffe80 100644 --- a/src/app/core/data/request.reducer.spec.ts +++ b/src/app/core/data/request.reducer.spec.ts @@ -55,7 +55,7 @@ describe('requestReducer', () => { expect(newState[link2].completed).toEqual(false); }); - it('should set \'requestPending\' to false, \'responsePending\' to false and leave \'completed\' untouched for the given RestRequest in the state, in response to an EXECUTE action', () => { + it('should set \'requestPending\' to false, \'responsePending\' to true and leave \'completed\' untouched for the given RestRequest in the state, in response to an EXECUTE action', () => { const state = testState; const action = new RequestExecuteAction(link1); @@ -66,7 +66,7 @@ describe('requestReducer', () => { expect(newState[link1].responsePending).toEqual(true); expect(newState[link1].completed).toEqual(state[link1].completed); }); - it('should leave \'requestPending\' untouched, set \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to a COMPLETE action', () => { + it('should leave \'requestPending\' untouched, set \'responsePending\' to false and \'completed\' to true for the given RestRequest in the state, in response to a COMPLETE action', () => { const state = testState; const action = new RequestCompleteAction(link1); diff --git a/src/app/core/index/uuid-index.reducer.spec.ts b/src/app/core/index/uuid-index.reducer.spec.ts index 7b96096604..e477d8df2e 100644 --- a/src/app/core/index/uuid-index.reducer.spec.ts +++ b/src/app/core/index/uuid-index.reducer.spec.ts @@ -45,7 +45,7 @@ describe('requestReducer', () => { expect(newState[uuid2]).toEqual(link2); }); - it('should remove the given \'href\' from it\'s corresponding \'uuid\' in the state, in response to a REMOVE_HREF action', () => { + it('should remove the given \'href\' from its corresponding \'uuid\' in the state, in response to a REMOVE_HREF action', () => { const state = testState; const action = new RemoveHrefFromUUIDIndexAction(link1); From 1f873901c9c6f7b06cb3b3830cefa5f96158a92d Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Fri, 1 Dec 2017 10:09:39 +0100 Subject: [PATCH 55/77] 130: fixed test description mistakes --- src/app/core/cache/response-cache.effects.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/cache/response-cache.effects.spec.ts b/src/app/core/cache/response-cache.effects.spec.ts index 60f4162fc6..e58ec536e3 100644 --- a/src/app/core/cache/response-cache.effects.spec.ts +++ b/src/app/core/cache/response-cache.effects.spec.ts @@ -24,7 +24,7 @@ describe('ResponseCacheEffects', () => { describe('fixTimestampsOnRehydrate$', () => { - it('should return a RESET_TIMESTAMPS action in response to an REHYDRATE action', () => { + it('should return a RESET_TIMESTAMPS action in response to a REHYDRATE action', () => { spyOn(Date.prototype, 'getTime').and.callFake(() => { return timestamp; }); From 9b812100b12a558c1ea6d722309c18835b73e5e6 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 1 Dec 2017 11:50:34 +0100 Subject: [PATCH 56/77] #150 Fixing path to use relative import --- src/app/+search-page/search-page.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 6952a2da96..101eb68e8f 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -12,7 +12,7 @@ import { SearchService } from './search-service/search.service'; import { pushInOut } from '../shared/animations/push'; import { HostWindowService } from '../shared/host-window.service'; import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; -import { PaginationComponentOptions } from 'src/app/shared/pagination/pagination-component-options.model'; +import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; import { SortOptions } from '../core/cache/models/sort-options.model'; /** From 1f873acea4edff6826ffe28797171a94c2a62286 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 1 Dec 2017 13:09:48 +0100 Subject: [PATCH 57/77] #150 TSLint error fixing --- .../object-collection.component.spec.ts | 1 - .../object-collection.component.ts | 5 ++-- .../shared/dso-element-decorator.spec.ts | 4 +-- .../collection-grid-element.component.spec.ts | 16 +++++------- .../collection-grid-element.component.ts | 1 - .../community-grid-element.component.spec.ts | 14 +++++----- .../item-grid-element.component.spec.ts | 15 +++++------ ...arch-result-grid-element.component.spec.ts | 15 +++++------ ...arch-result-grid-element.component.spec.ts | 16 +++++------- ...arch-result-grid-element.component.spec.ts | 26 ++++++++----------- .../wrapper-grid-element.component.spec.ts | 2 +- .../object-list/object-list.component.ts | 1 - 12 files changed, 49 insertions(+), 67 deletions(-) diff --git a/src/app/shared/object-collection/object-collection.component.spec.ts b/src/app/shared/object-collection/object-collection.component.spec.ts index 6793042f35..b27a342eac 100644 --- a/src/app/shared/object-collection/object-collection.component.spec.ts +++ b/src/app/shared/object-collection/object-collection.component.spec.ts @@ -40,7 +40,6 @@ describe('ObjectCollectionComponent', () => { it('should only show the grid component when the viewmode is set to grid', () => { objectCollectionComponent.currentMode = ViewMode.Grid; - expect(fixture.debugElement.query(By.css('ds-object-grid'))).toBeDefined(); expect(fixture.debugElement.query(By.css('ds-object-list'))).toBeNull(); }); diff --git a/src/app/shared/object-collection/object-collection.component.ts b/src/app/shared/object-collection/object-collection.component.ts index 5a356dcbdc..3af92443c1 100644 --- a/src/app/shared/object-collection/object-collection.component.ts +++ b/src/app/shared/object-collection/object-collection.component.ts @@ -65,14 +65,13 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { } } - ngOnInit(): void { // this.pageInfo = this.objects.pageInfo; this.sub = this.route .queryParams .subscribe((params) => { - if(isNotEmpty(params.view)){ + if (isNotEmpty(params.view)) { this.currentMode = params.view; } }); @@ -91,7 +90,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit { getViewMode(): ViewMode { this.route.queryParams.map((params) => { if (isNotEmpty(params.view) && hasValue(params.view)) { - this.currentMode= params.view; + this.currentMode = params.view; } }); return this.currentMode; diff --git a/src/app/shared/object-collection/shared/dso-element-decorator.spec.ts b/src/app/shared/object-collection/shared/dso-element-decorator.spec.ts index b4b27bb52a..9f54bebed9 100644 --- a/src/app/shared/object-collection/shared/dso-element-decorator.spec.ts +++ b/src/app/shared/object-collection/shared/dso-element-decorator.spec.ts @@ -3,8 +3,8 @@ import { renderElementsFor } from './dso-element-decorator'; import { Item } from '../../../core/shared/item.model'; describe('ElementDecorator', () => { - let gridDecorator = renderElementsFor(Item, ViewMode.Grid); - let listDecorator = renderElementsFor(Item, ViewMode.List); + const gridDecorator = renderElementsFor(Item, ViewMode.Grid); + const listDecorator = renderElementsFor(Item, ViewMode.List); it('should have a decorator for both list and grid', () => { expect(listDecorator.length).not.toBeNull(); expect(gridDecorator.length).not.toBeNull(); diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts index fd935af992..eaa6edc4d0 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.spec.ts @@ -6,8 +6,6 @@ import { RouterStub } from '../../testing/router-stub'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; import { Collection } from '../../../core/shared/collection.model'; - -let collectionGridElementComponent: CollectionGridElementComponent; let fixture: ComponentFixture; const queryParam = 'test query'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; @@ -17,7 +15,7 @@ const activatedRouteStub = { scope: scopeParam }) }; -let mockCollection: Collection = Object.assign(new Collection(), { +const mockCollection: Collection = Object.assign(new Collection(), { metadata: [ { key: 'dc.description.abstract', @@ -25,7 +23,7 @@ let mockCollection: Collection = Object.assign(new Collection(), { value: 'Short description' }] }); -let createdGridElementComponent:CollectionGridElementComponent= new CollectionGridElementComponent(mockCollection); +const createdGridElementComponent:CollectionGridElementComponent= new CollectionGridElementComponent(mockCollection); describe('CollectionGridElementComponent', () => { beforeEach(async(() => { @@ -45,16 +43,16 @@ describe('CollectionGridElementComponent', () => { fixture = TestBed.createComponent(CollectionGridElementComponent); })); - it('should show the collection cards in the grid element',()=>{ + it('should show the collection cards in the grid element',() => { expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); }); - it('should only show the description if "short description" metadata is present',()=>{ - let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + it('should only show the description if "short description" metadata is present',() => { + const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); - if(mockCollection.shortDescription.length>0){ + if (mockCollection.shortDescription.length > 0) { expect(descriptionText).toBeDefined(); - }else{ + }else { expect(descriptionText).not.toBeDefined(); } }); diff --git a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts index a7f5ef3e49..f383367e3f 100644 --- a/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts +++ b/src/app/shared/object-grid/collection-grid-element/collection-grid-element.component.ts @@ -5,7 +5,6 @@ import { renderElementsFor} from '../../object-collection/shared/dso-element-dec import { ViewMode } from '../../../+search-page/search-options.model'; import { AbstractListableElementComponent } from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; - @Component({ selector: 'ds-collection-grid-element', styleUrls: ['./collection-grid-element.component.scss'], diff --git a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts index dc837e3c0c..cb9e20449e 100644 --- a/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/community-grid-element/community-grid-element.component.spec.ts @@ -19,7 +19,7 @@ const activatedRouteStub = { }) }; -let mockCommunity: Community = Object.assign(new Community(), { +const mockCommunity: Community = Object.assign(new Community(), { metadata: [ { key: 'dc.description.abstract', @@ -28,7 +28,7 @@ let mockCommunity: Community = Object.assign(new Community(), { }] }); -let createdGridElementComponent:CommunityGridElementComponent= new CommunityGridElementComponent(mockCommunity); +const createdGridElementComponent:CommunityGridElementComponent= new CommunityGridElementComponent(mockCommunity); describe('CommunityGridElementComponent', () => { beforeEach(async(() => { @@ -50,16 +50,16 @@ describe('CommunityGridElementComponent', () => { })); - it('should show the community cards in the grid element',()=>{ + it('should show the community cards in the grid element',() => { expect(fixture.debugElement.query(By.css('ds-community-grid-element'))).toBeDefined(); }) - it('should only show the description if "short description" metadata is present',()=>{ - let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); + it('should only show the description if "short description" metadata is present',() => { + const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); - if(mockCommunity.shortDescription.length>0){ + if (mockCommunity.shortDescription.length > 0) { expect(descriptionText).toBeDefined(); - }else{ + }else { expect(descriptionText).not.toBeDefined(); } }); diff --git a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts index 8913dca3ee..3be46965ee 100644 --- a/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/item-grid-element/item-grid-element.component.spec.ts @@ -19,7 +19,7 @@ const activatedRouteStub = { }) }; /* tslint:disable:no-shadowed-variable */ -let mockItem: Item = Object.assign(new Item(), { +const mockItem: Item = Object.assign(new Item(), { metadata: [ { key: 'dc.contributor.author', @@ -28,7 +28,7 @@ let mockItem: Item = Object.assign(new Item(), { }] }); -let createdGridElementComponent:ItemGridElementComponent= new ItemGridElementComponent(mockItem); +const createdGridElementComponent:ItemGridElementComponent= new ItemGridElementComponent(mockItem); describe('ItemGridElementComponent', () => { beforeEach(async(() => { @@ -50,19 +50,18 @@ describe('ItemGridElementComponent', () => { })); - it('should show the item cards in the grid element',()=>{ + it('should show the item cards in the grid element',() => { expect(fixture.debugElement.query(By.css('ds-item-grid-element'))).toBeDefined() }); - it('should only show the author span if the author metadata is present',()=>{ - let itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); + it('should only show the author span if the author metadata is present',() => { + const itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); - if(mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length>0){ + if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) { expect(itemAuthorField).toBeDefined(); - }else{ + }else { expect(itemAuthorField).toBeDefined(); } }); - }) diff --git a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts index 8d6fe6fb38..a3b3710080 100644 --- a/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/search-result-grid-element/collection-search-result/collection-search-result-grid-element.component.spec.ts @@ -9,7 +9,6 @@ import { TruncatePipe } from '../../../utils/truncate.pipe'; import { Community } from '../../../../core/shared/community.model'; import { Collection } from '../../../../core/shared/collection.model'; - let fixture: ComponentFixture; const queryParam = 'test query'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; @@ -19,7 +18,7 @@ const activatedRouteStub = { scope: scopeParam }) }; -let mockCollection: Collection = Object.assign(new Collection(), { +const mockCollection: Collection = Object.assign(new Collection(), { metadata: [ { key: 'dc.description.abstract', @@ -29,8 +28,7 @@ let mockCollection: Collection = Object.assign(new Collection(), { }); -let createdGridElementComponent: CollectionSearchResultGridElementComponent = new CollectionSearchResultGridElementComponent(mockCollection); - +const createdGridElementComponent: CollectionSearchResultGridElementComponent = new CollectionSearchResultGridElementComponent(mockCollection); describe('CollectionSearchResultGridElementComponent', () => { beforeEach(async(() => { @@ -54,13 +52,12 @@ describe('CollectionSearchResultGridElementComponent', () => { expect(fixture.debugElement.query(By.css('ds-collection-search-result-grid-element'))).toBeDefined(); }); + it('should only show the description if "short description" metadata is present',() => { + const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); - it('should only show the description if "short description" metadata is present',()=>{ - let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); - - if(mockCollection.shortDescription.length>0){ + if (mockCollection.shortDescription.length > 0) { expect(descriptionText).toBeDefined(); - }else{ + }else { expect(descriptionText).not.toBeDefined(); } }); diff --git a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts index 0924700da7..dd9e16a120 100644 --- a/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/search-result-grid-element/community-search-result/community-search-result-grid-element.component.spec.ts @@ -8,8 +8,6 @@ import { By } from '@angular/platform-browser'; import { TruncatePipe } from '../../../utils/truncate.pipe'; import { Community } from '../../../../core/shared/community.model'; - -let communitySearchResultGridElementComponent: CommunitySearchResultGridElementComponent; let fixture: ComponentFixture; const queryParam = 'test query'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; @@ -19,7 +17,7 @@ const activatedRouteStub = { scope: scopeParam }) }; -let mockCommunity: Community = Object.assign(new Community(), { +const mockCommunity: Community = Object.assign(new Community(), { metadata: [ { key: 'dc.description.abstract', @@ -29,8 +27,7 @@ let mockCommunity: Community = Object.assign(new Community(), { }); -let createdGridElementComponent: CommunitySearchResultGridElementComponent = new CommunitySearchResultGridElementComponent(mockCommunity); - +const createdGridElementComponent: CommunitySearchResultGridElementComponent = new CommunitySearchResultGridElementComponent(mockCommunity); describe('CommunitySearchResultGridElementComponent', () => { beforeEach(async(() => { @@ -54,13 +51,12 @@ describe('CommunitySearchResultGridElementComponent', () => { expect(fixture.debugElement.query(By.css('ds-community-search-result-grid-element'))).toBeDefined(); }); + it('should only show the description if "short description" metadata is present',() => { + const descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); - it('should only show the description if "short description" metadata is present',()=>{ - let descriptionText = expect(fixture.debugElement.query(By.css('p.card-text'))); - - if(mockCommunity.shortDescription.length>0){ + if (mockCommunity.shortDescription.length > 0) { expect(descriptionText).toBeDefined(); - }else{ + }else { expect(descriptionText).not.toBeDefined(); } }); diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts index 318910304f..1a2ca908e2 100644 --- a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item-search-result-grid-element.component.spec.ts @@ -8,7 +8,6 @@ import { By } from '@angular/platform-browser'; import { TruncatePipe } from '../../../utils/truncate.pipe'; import { Item } from '../../../../core/shared/item.model'; - let itemSearchResultGridElementComponent: ItemSearchResultGridElementComponent; let fixture: ComponentFixture; const queryParam = 'test query'; @@ -19,7 +18,7 @@ const activatedRouteStub = { scope: scopeParam }) }; -let mockItem: Item = Object.assign(new Item(), { +const mockItem: Item = Object.assign(new Item(), { metadata: [ { key: 'dc.contributor.author', @@ -32,7 +31,7 @@ let mockItem: Item = Object.assign(new Item(), { value: '1650-06-26' }] }); -let createdGridElementComponent:ItemSearchResultGridElementComponent= new ItemSearchResultGridElementComponent(mockItem); +const createdGridElementComponent:ItemSearchResultGridElementComponent= new ItemSearchResultGridElementComponent(mockItem); describe('ItemSearchResultGridElementComponent', () => { beforeEach(async(() => { @@ -54,31 +53,28 @@ describe('ItemSearchResultGridElementComponent', () => { })); - it('should show the item result cards in the grid element',()=>{ + it('should show the item result cards in the grid element',() => { expect(fixture.debugElement.query(By.css('ds-item-search-result-grid-element'))).toBeDefined(); }); - it('should only show the author span if the author metadata is present',()=>{ - let itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); + it('should only show the author span if the author metadata is present',() => { + const itemAuthorField = expect(fixture.debugElement.query(By.css('p.item-authors'))); - if(mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length>0){ + if (mockItem.filterMetadata(['dc.contributor.author', 'dc.creator', 'dc.contributor.*']).length > 0) { expect(itemAuthorField).toBeDefined(); - }else{ + }else { expect(itemAuthorField).not.toBeDefined(); } }); - it('should only show the date span if the issuedate is present',()=>{ - let dateField = expect(fixture.debugElement.query(By.css('span.item-list-date'))); + it('should only show the date span if the issuedate is present',() => { + const dateField = expect(fixture.debugElement.query(By.css('span.item-list-date'))); - if(mockItem.findMetadata('dc.date.issued').length>0){ + if (mockItem.findMetadata('dc.date.issued').length > 0) { expect(dateField).toBeDefined(); - }else{ + }else { expect(dateField).not.toBeDefined(); } }); - - - }); diff --git a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts index 5b02fbe95a..390b003e2e 100644 --- a/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/wrapper-grid-element/wrapper-grid-element.component.spec.ts @@ -37,7 +37,7 @@ describe('WrapperGridElementComponent', () => { })); - it('should show the wrapper element containing the cards',()=>{ + it('should show the wrapper element containing the cards',() => { expect(fixture.debugElement.query(By.css('ds-collection-grid-element'))).toBeDefined(); }) }) diff --git a/src/app/shared/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts index a300e06f59..b9abed37ac 100644 --- a/src/app/shared/object-list/object-list.component.ts +++ b/src/app/shared/object-list/object-list.component.ts @@ -18,7 +18,6 @@ import { fadeIn } from '../animations/fade'; import { ListableObject } from '../object-collection/shared/listable-object.model'; import { hasValue } from '../empty.util'; - @Component({ changeDetection: ChangeDetectionStrategy.Default, encapsulation: ViewEncapsulation.Emulated, From 5061ceef3c36ceced4355fcca8fcc380c0bbd6ee Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Fri, 1 Dec 2017 13:34:38 +0100 Subject: [PATCH 58/77] #150 Payload compatibility fix --- .../core/data/browse-response-parsing.service.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/core/data/browse-response-parsing.service.spec.ts b/src/app/core/data/browse-response-parsing.service.spec.ts index 5f27519a93..263c4a0532 100644 --- a/src/app/core/data/browse-response-parsing.service.spec.ts +++ b/src/app/core/data/browse-response-parsing.service.spec.ts @@ -2,6 +2,7 @@ import { BrowseResponseParsingService } from './browse-response-parsing.service' import { BrowseEndpointRequest } from './request.models'; import { BrowseSuccessResponse, ErrorResponse } from '../cache/response-cache.models'; import { BrowseDefinition } from '../shared/browse-definition.model'; +import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model'; describe('BrowseResponseParsingService', () => { let service: BrowseResponseParsingService; @@ -48,7 +49,7 @@ describe('BrowseResponseParsingService', () => { _links: { self: { href: 'https://rest.api/discover/browses' } }, page: { size: 20, totalElements: 2, totalPages: 1, number: 0 } }, statusCode: '200' - }; + } as DSpaceRESTV2Response; const invalidResponse1 = { payload: { @@ -71,22 +72,21 @@ describe('BrowseResponseParsingService', () => { _links: { self: { href: 'https://rest.api/discover/browses' } }, page: { size: 20, totalElements: 2, totalPages: 1, number: 0 } }, statusCode: '200' - }; + } as DSpaceRESTV2Response; const invalidResponse2 = { payload: { - browses: [{}, {}], _links: { self: { href: 'https://rest.api/discover/browses' } }, page: { size: 20, totalElements: 2, totalPages: 1, number: 0 } }, statusCode: '200' - }; + } as DSpaceRESTV2Response ; const invalidResponse3 = { payload: { _links: { self: { href: 'https://rest.api/discover/browses' } }, page: { size: 20, totalElements: 2, totalPages: 1, number: 0 } }, statusCode: '500' - }; + } as DSpaceRESTV2Response; const definitions = [ Object.assign(new BrowseDefinition(), { From 98a49b3191dbafad3ac4f429daf74112c09501a2 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Wed, 29 Nov 2017 16:47:40 +0100 Subject: [PATCH 59/77] add support for multiple request methods --- src/app/core/cache/object-cache.reducer.ts | 11 +++++++ src/app/core/data/data.service.ts | 29 ++++++++++++++++-- src/app/core/data/request.effects.ts | 30 ++++++++++++++----- src/app/core/data/request.models.ts | 12 ++++++++ .../dspace-rest-v2/dspace-rest-v2.service.ts | 25 +++++++++++++++- 5 files changed, 95 insertions(+), 12 deletions(-) diff --git a/src/app/core/cache/object-cache.reducer.ts b/src/app/core/cache/object-cache.reducer.ts index 3af7209b24..39c623deed 100644 --- a/src/app/core/cache/object-cache.reducer.ts +++ b/src/app/core/cache/object-cache.reducer.ts @@ -5,6 +5,12 @@ import { import { hasValue } from '../../shared/empty.util'; import { CacheEntry } from './cache-entry'; +export enum DirtyType { + Created = 'Created', + Updated = 'Updated', + Deleted = 'Deleted' +} + /** * An interface to represent objects that can be cached * @@ -13,6 +19,11 @@ import { CacheEntry } from './cache-entry'; export interface CacheableObject { uuid?: string; self: string; + // isNew: boolean; + // dirtyType: DirtyType; + // hasDirtyAttributes: boolean; + // changedAttributes: AttributeDiffh; + // save(): void; } /** diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index e2f41f5962..5751173054 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -6,12 +6,19 @@ import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv import { CacheableObject } from '../cache/object-cache.reducer'; import { ResponseCacheService } from '../cache/response-cache.service'; import { CoreState } from '../core.reducers'; +import { DSpaceObject } from '../shared/dspace-object.model'; import { GenericConstructor } from '../shared/generic-constructor'; import { HALEndpointService } from '../shared/hal-endpoint.service'; -import { RemoteData } from './remote-data'; -import { FindAllOptions, FindAllRequest, FindByIDRequest, RestRequest } from './request.models'; -import { RequestService } from './request.service'; import { URLCombiner } from '../url-combiner/url-combiner'; +import { RemoteData } from './remote-data'; +import { + FindAllOptions, + FindAllRequest, + FindByIDRequest, + RestRequest, + RestRequestMethod +} from './request.models'; +import { RequestService } from './request.service'; export abstract class DataService extends HALEndpointService { protected abstract responseCache: ResponseCacheService; @@ -102,4 +109,20 @@ export abstract class DataService return this.rdbService.buildSingle(href, this.normalizedResourceType); } + create(dso: DSpaceObject): Observable> { + const postHrefObs = this.getEndpoint(); + + // TODO ID is unknown at this point + const idHrefObs = postHrefObs.map((href: string) => this.getFindByIDHref(href, dso.id)); + + postHrefObs + .filter((href: string) => hasValue(href)) + .take(1) + .subscribe((href: string) => { + const request = new RestRequest(href, RestRequestMethod.Post, dso); + this.requestService.configure(request); + }); + + return this.rdbService.buildSingle(idHrefObs, this.normalizedResourceType); + } } diff --git a/src/app/core/data/request.effects.ts b/src/app/core/data/request.effects.ts index 84f19679b1..f848d7f0d7 100644 --- a/src/app/core/data/request.effects.ts +++ b/src/app/core/data/request.effects.ts @@ -1,18 +1,23 @@ import { Inject, Injectable, Injector } from '@angular/core'; +import { Request } from '@angular/http'; +import { RequestArgs } from '@angular/http/src/interfaces'; import { Actions, Effect } from '@ngrx/effects'; // tslint:disable-next-line:import-blacklist import { Observable } from 'rxjs'; import { GLOBAL_CONFIG, GlobalConfig } from '../../../config'; +import { isNotEmpty } from '../../shared/empty.util'; import { ErrorResponse, RestResponse } from '../cache/response-cache.models'; import { ResponseCacheService } from '../cache/response-cache.service'; import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model'; import { DSpaceRESTv2Service } from '../dspace-rest-v2/dspace-rest-v2.service'; import { RequestActionTypes, RequestCompleteAction, RequestExecuteAction } from './request.actions'; -import { RequestError } from './request.models'; +import { RequestError, RestRequest } from './request.models'; import { RequestEntry } from './request.reducer'; import { RequestService } from './request.service'; +import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer'; +import { NormalizedObjectFactory } from '../cache/models/normalized-object-factory'; @Injectable() export class RequestEffects { @@ -23,15 +28,24 @@ export class RequestEffects { return this.requestService.get(action.payload) .take(1); }) - .flatMap((entry: RequestEntry) => { - return this.restApi.get(entry.request.href) + .map((entry: RequestEntry) => entry.request) + .flatMap((request: RestRequest) => { + const httpRequestConfig: RequestArgs = { + method: request.method, + url: request.href + }; + if (isNotEmpty(request.body)) { + const serializer = new DSpaceRESTv2Serializer(NormalizedObjectFactory.getConstructor(request.body.type)); + httpRequestConfig.body = JSON.stringify(serializer.serialize(request.body)); + } + return this.restApi.request(new Request(httpRequestConfig)) .map((data: DSpaceRESTV2Response) => - this.injector.get(entry.request.getResponseParser()).parse(entry.request, data)) - .do((response: RestResponse) => this.responseCache.add(entry.request.href, response, this.EnvConfig.cache.msToLive)) - .map((response: RestResponse) => new RequestCompleteAction(entry.request.href)) + this.injector.get(request.getResponseParser()).parse(request, data)) + .do((response: RestResponse) => this.responseCache.add(request.href, response, this.EnvConfig.cache.msToLive)) + .map((response: RestResponse) => new RequestCompleteAction(request.href)) .catch((error: RequestError) => Observable.of(new ErrorResponse(error)) - .do((response: RestResponse) => this.responseCache.add(entry.request.href, response, this.EnvConfig.cache.msToLive)) - .map((response: RestResponse) => new RequestCompleteAction(entry.request.href))); + .do((response: RestResponse) => this.responseCache.add(request.href, response, this.EnvConfig.cache.msToLive)) + .map((response: RestResponse) => new RequestCompleteAction(request.href))); }); constructor( diff --git a/src/app/core/data/request.models.ts b/src/app/core/data/request.models.ts index a80eccfaa8..3ab7dc0b8c 100644 --- a/src/app/core/data/request.models.ts +++ b/src/app/core/data/request.models.ts @@ -9,9 +9,21 @@ import { BrowseResponseParsingService } from './browse-response-parsing.service' import { ConfigResponseParsingService } from './config-response-parsing.service'; /* tslint:disable:max-classes-per-file */ +export enum RestRequestMethod { + Get = 'GET', + Post = 'POST', + Put = 'PUT', + Delete = 'DELETE', + Options = 'OPTIONS', + Head = 'HEAD', + Patch = 'PATCH' +} + export class RestRequest { constructor( public href: string, + public method: RestRequestMethod = RestRequestMethod.Get, + public body?: any ) { } getResponseParser(): GenericConstructor { diff --git a/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts index 6464268201..bc9d5eddaf 100644 --- a/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts +++ b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts @@ -1,11 +1,12 @@ import { Inject, Injectable } from '@angular/core'; -import { Http, RequestOptionsArgs } from '@angular/http'; +import { Http, RequestOptionsArgs, Request } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import { RESTURLCombiner } from '../url-combiner/rest-url-combiner'; import { DSpaceRESTV2Response } from './dspace-rest-v2-response.model'; import { GLOBAL_CONFIG, GlobalConfig } from '../../../config'; +import { RestRequest } from '../data/request.models'; /** * Service to access DSpace's REST API @@ -36,4 +37,26 @@ export class DSpaceRESTv2Service { }); } + /** + * Performs a request to the REST API. + * + * @param httpRequest + * A Request object + * @return {Observable} + * An Observable containing the response from the server + */ + request(httpRequest: Request): Observable { + // const httpRequest = new Request({ + // method: request.method, + // url: request.href, + // body: request.body + // }); + return this.http.request(httpRequest) + .map((res) => ({ payload: res.json(), statusCode: res.statusText })) + .catch((err) => { + console.log('Error: ', err); + return Observable.throw(err); + }); + } + } From d775467fcb62c5216a99d894a25925a709fa8e3f Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Thu, 7 Dec 2017 11:28:44 +0100 Subject: [PATCH 60/77] cleaned up remotedata for a better separation of concerns, moved statuscode and errormsg in to RemoteDataError object, moved pageInfo to PaginatedList object in the payload --- .../collection-page.component.ts | 3 +- ...ty-page-sub-collection-list.component.html | 2 +- ...nity-page-sub-collection-list.component.ts | 5 +- .../top-level-community-list.component.ts | 3 +- .../+search-page/search-page.component.html | 4 +- src/app/+search-page/search-page.component.ts | 3 +- .../search-service/search.service.ts | 66 +++++------------ .../builders/remote-data-build.service.ts | 70 ++++++++++--------- src/app/core/data/data.service.ts | 5 +- src/app/core/data/paginated-list.ts | 42 +++++++++++ src/app/core/data/remote-data-error.ts | 7 ++ src/app/core/data/remote-data.ts | 7 +- src/app/core/data/request.models.ts | 20 ++++-- src/app/core/data/request.service.ts | 28 +++++--- .../core/metadata/metadata.service.spec.ts | 6 +- .../object-list/object-list.component.html | 6 +- src/app/object-list/object-list.component.ts | 13 ++-- 17 files changed, 162 insertions(+), 128 deletions(-) create mode 100644 src/app/core/data/paginated-list.ts create mode 100644 src/app/core/data/remote-data-error.ts diff --git a/src/app/+collection-page/collection-page.component.ts b/src/app/+collection-page/collection-page.component.ts index 853bd0d154..de7e9a72d4 100644 --- a/src/app/+collection-page/collection-page.component.ts +++ b/src/app/+collection-page/collection-page.component.ts @@ -6,6 +6,7 @@ import { Subscription } from 'rxjs/Subscription'; import { SortOptions } from '../core/cache/models/sort-options.model'; import { CollectionDataService } from '../core/data/collection-data.service'; import { ItemDataService } from '../core/data/item-data.service'; +import { PaginatedList } from '../core/data/paginated-list'; import { RemoteData } from '../core/data/remote-data'; import { MetadataService } from '../core/metadata/metadata.service'; @@ -30,7 +31,7 @@ import { PaginationComponentOptions } from '../shared/pagination/pagination-comp }) export class CollectionPageComponent implements OnInit, OnDestroy { collectionRDObs: Observable>; - itemRDObs: Observable>; + itemRDObs: Observable>>; logoRDObs: Observable>; paginationConfig: PaginationComponentOptions; sortConfig: SortOptions; diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html index b04e93ff71..8e2d04c5cd 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html @@ -2,7 +2,7 @@

        {{'community.sub-collection-list.head' | translate}}

          -
        • +
        • {{collection.name}}
          {{collection.shortDescription}} diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts index 8edc275437..cb371617c9 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts @@ -1,11 +1,12 @@ import { Component, OnInit } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; import { CollectionDataService } from '../../core/data/collection-data.service'; +import { PaginatedList } from '../../core/data/paginated-list'; import { RemoteData } from '../../core/data/remote-data'; import { Collection } from '../../core/shared/collection.model'; import { fadeIn } from '../../shared/animations/fade'; -import { Observable } from 'rxjs/Observable'; @Component({ selector: 'ds-community-page-sub-collection-list', @@ -14,7 +15,7 @@ import { Observable } from 'rxjs/Observable'; animations:[fadeIn] }) export class CommunityPageSubCollectionListComponent implements OnInit { - subCollectionsRDObs: Observable>; + subCollectionsRDObs: Observable>>; constructor(private cds: CollectionDataService) { diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts b/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts index b364985fc1..1b71220382 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts @@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { SortOptions } from '../../core/cache/models/sort-options.model'; import { CommunityDataService } from '../../core/data/community-data.service'; +import { PaginatedList } from '../../core/data/paginated-list'; import { RemoteData } from '../../core/data/remote-data'; import { Community } from '../../core/shared/community.model'; @@ -17,7 +18,7 @@ import { PaginationComponentOptions } from '../../shared/pagination/pagination-c animations: [fadeInOut] }) export class TopLevelCommunityListComponent { - communitiesRDObs: Observable>; + communitiesRDObs: Observable>>; config: PaginationComponentOptions; sortConfig: SortOptions; diff --git a/src/app/+search-page/search-page.component.html b/src/app/+search-page/search-page.component.html index c4d679f72b..953de02ab4 100644 --- a/src/app/+search-page/search-page.component.html +++ b/src/app/+search-page/search-page.component.html @@ -8,7 +8,7 @@ [query]="query" [scope]="(scopeObjectRDObs | async)?.payload" [currentParams]="currentParams" - [scopes]="(scopeListRDObs | async)?.payload"> + [scopes]="(scopeListRDObs | async)?.payload?.page">

          -
        diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 153402d11f..3dcd0ccccf 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/ import { ActivatedRoute } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { CommunityDataService } from '../core/data/community-data.service'; +import { PaginatedList } from '../core/data/paginated-list'; import { RemoteData } from '../core/data/remote-data'; import { Community } from '../core/shared/community.model'; import { DSpaceObject } from '../core/shared/dspace-object.model'; @@ -36,7 +37,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { resultsRDObs: Observable>>>; currentParams = {}; searchOptions: SearchOptions; - scopeListRDObs: Observable>; + scopeListRDObs: Observable>>; isMobileView: Observable; constructor(private service: SearchService, diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 4b5ba7b702..a6648fedd7 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -1,6 +1,8 @@ import { Injectable, OnDestroy } from '@angular/core'; +import { PaginatedList } from '../../core/data/paginated-list'; import { RemoteData } from '../../core/data/remote-data'; import { Observable } from 'rxjs/Observable'; +import { RemoteDataError } from '../../core/data/remote-data-error'; import { SearchResult } from '../search-result.model'; import { ItemDataService } from '../../core/data/item-data.service'; import { PageInfo } from '../../core/shared/page-info.model'; @@ -100,26 +102,7 @@ export class SearchService implements OnDestroy { } search(query: string, scopeId?: string, searchOptions?: SearchOptions): Observable>>> { - this.searchOptions = this.searchOptions; - let self = `https://dspace7.4science.it/dspace-spring-rest/api/search?query=${query}`; - if (hasValue(scopeId)) { - self += `&scope=${scopeId}`; - } - if (isNotEmpty(searchOptions) && hasValue(searchOptions.pagination.currentPage)) { - self += `&page=${searchOptions.pagination.currentPage}`; - } - if (isNotEmpty(searchOptions) && hasValue(searchOptions.pagination.pageSize)) { - self += `&pageSize=${searchOptions.pagination.pageSize}`; - } - if (isNotEmpty(searchOptions) && hasValue(searchOptions.sort.direction)) { - self += `&sortDirection=${searchOptions.sort.direction}`; - } - if (isNotEmpty(searchOptions) && hasValue(searchOptions.sort.field)) { - self += `&sortField=${searchOptions.sort.field}`; - } - - const errorMessage = undefined; - const statusCode = '200'; + const error = new RemoteDataError('200', undefined); const returningPageInfo = new PageInfo(); if (isNotEmpty(searchOptions)) { @@ -137,13 +120,12 @@ export class SearchService implements OnDestroy { }); return itemsObs - .filter((rd: RemoteData) => rd.hasSucceeded) - .map((rd: RemoteData) => { + .filter((rd: RemoteData>) => rd.hasSucceeded) + .map((rd: RemoteData>) => { - const totalElements = rd.pageInfo.totalElements > 20 ? 20 : rd.pageInfo.totalElements; - const pageInfo = Object.assign({}, rd.pageInfo, { totalElements: totalElements }); + const totalElements = rd.payload.totalElements > 20 ? 20 : rd.payload.totalElements; - const payload = shuffle(rd.payload) + const page = shuffle(rd.payload.page) .map((item: Item, index: number) => { const mockResult: SearchResult = new ItemSearchResult(); mockResult.dspaceObject = item; @@ -154,24 +136,20 @@ export class SearchService implements OnDestroy { return mockResult; }); + const payload = Object.assign({}, rd.payload, { totalElements: totalElements, page }); + return new RemoteData( - self, rd.isRequestPending, rd.isResponsePending, rd.hasSucceeded, - errorMessage, - statusCode, - pageInfo, + error, payload ) }).startWith(new RemoteData( - '', true, false, undefined, undefined, - undefined, - undefined, undefined )); } @@ -180,17 +158,12 @@ export class SearchService implements OnDestroy { const requestPending = false; const responsePending = false; const isSuccessful = true; - const errorMessage = undefined; - const statusCode = '200'; - const returningPageInfo = new PageInfo(); + const error = new RemoteDataError('200', undefined); return Observable.of(new RemoteData( - 'https://dspace7.4science.it/dspace-spring-rest/api/search', requestPending, responsePending, isSuccessful, - errorMessage, - statusCode, - returningPageInfo, + error, this.config )); } @@ -198,12 +171,12 @@ export class SearchService implements OnDestroy { getFacetValuesFor(searchFilterConfigName: string): Observable> { const filterConfig = this.config.find((config: SearchFilterConfig) => config.name === searchFilterConfigName); return this.routeService.getQueryParameterValues(filterConfig.paramName).map((selectedValues: string[]) => { - const values: FacetValue[] = []; + const payload: FacetValue[] = []; const totalFilters = 13; for (let i = 0; i < totalFilters; i++) { const value = searchFilterConfigName + ' ' + (i + 1); if (!selectedValues.includes(value)) { - values.push({ + payload.push({ value: value, count: Math.floor(Math.random() * 20) + 20 * (totalFilters - i), // make sure first results have the highest (random) count search: decodeURI(this.router.url) + (this.router.url.includes('?') ? '&' : '?') + filterConfig.paramName + '=' + value @@ -213,18 +186,13 @@ export class SearchService implements OnDestroy { const requestPending = false; const responsePending = false; const isSuccessful = true; - const errorMessage = undefined; - const statusCode = '200'; - const returningPageInfo = new PageInfo(); + const error = new RemoteDataError('200', undefined);; return new RemoteData( - 'https://dspace7.4science.it/dspace-spring-rest/api/search', requestPending, responsePending, isSuccessful, - errorMessage, - statusCode, - returningPageInfo, - values + error, + payload ) } ) 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 2e3fc01b52..eee6808d86 100644 --- a/src/app/core/cache/builders/remote-data-build.service.ts +++ b/src/app/core/cache/builders/remote-data-build.service.ts @@ -1,5 +1,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; +import { PaginatedList } from '../../data/paginated-list'; +import { RemoteDataError } from '../../data/remote-data-error'; import { CacheableObject } from '../object-cache.reducer'; import { ObjectCacheService } from '../object-cache.service'; @@ -88,32 +90,18 @@ export class RemoteDataBuildService { const requestPending = hasValue(reqEntry.requestPending) ? reqEntry.requestPending : true; const responsePending = hasValue(reqEntry.responsePending) ? reqEntry.responsePending : false; let isSuccessFul: boolean; - let errorMessage: string; - let statusCode: string; - let pageInfo: PageInfo; + let error: RemoteDataError; if (hasValue(resEntry) && hasValue(resEntry.response)) { isSuccessFul = resEntry.response.isSuccessful; - errorMessage = isSuccessFul === false ? (resEntry.response as ErrorResponse).errorMessage : undefined; - statusCode = resEntry.response.statusCode; - - if (hasValue((resEntry.response as DSOSuccessResponse).pageInfo)) { - const resPageInfo = (resEntry.response as DSOSuccessResponse).pageInfo; - if (isNotEmpty(resPageInfo) && resPageInfo.currentPage >= 0) { - pageInfo = Object.assign({}, resPageInfo, { currentPage: resPageInfo.currentPage + 1 }); - } else { - pageInfo = resPageInfo; - } - } + const errorMessage = isSuccessFul === false ? (resEntry.response as ErrorResponse).errorMessage : undefined; + error = new RemoteDataError(resEntry.response.statusCode, errorMessage); } return new RemoteData( - href, requestPending, responsePending, isSuccessFul, - errorMessage, - statusCode, - pageInfo, + error, payload ); }); @@ -122,7 +110,7 @@ export class RemoteDataBuildService { buildList( hrefObs: string | Observable, normalizedType: GenericConstructor - ): Observable> { + ): Observable>> { if (typeof hrefObs === 'string') { hrefObs = Observable.of(hrefObs); } @@ -132,7 +120,7 @@ export class RemoteDataBuildService { const responseCacheObs = hrefObs.flatMap((href: string) => this.responseCache.get(href)) .filter((entry) => hasValue(entry)); - const payloadObs = responseCacheObs + const tDomainListObs = responseCacheObs .filter((entry: ResponseCacheEntry) => entry.response.isSuccessful) .map((entry: ResponseCacheEntry) => (entry.response as DSOSuccessResponse).resourceSelfLinks) .flatMap((resourceUUIDs: string[]) => { @@ -146,6 +134,27 @@ export class RemoteDataBuildService { .startWith([]) .distinctUntilChanged(); + const pageInfoObs = responseCacheObs + .filter((entry: ResponseCacheEntry) => entry.response.isSuccessful) + .map((entry: ResponseCacheEntry) => { + if (hasValue((entry.response as DSOSuccessResponse).pageInfo)) { + const resPageInfo = (entry.response as DSOSuccessResponse).pageInfo; + if (isNotEmpty(resPageInfo) && resPageInfo.currentPage >= 0) { + return Object.assign({}, resPageInfo, { currentPage: resPageInfo.currentPage + 1 }); + } else { + return resPageInfo; + } + } + }); + + const payloadObs = Observable.combineLatest(tDomainListObs, pageInfoObs, (tDomainList, pageInfo) => { + if (hasValue(pageInfo)) { + return new PaginatedList(pageInfo, tDomainList); + } else { + return tDomainList; + } + }); + return this.toRemoteDataObservable(hrefObs, requestObs, responseCacheObs, payloadObs); } @@ -209,35 +218,32 @@ export class RemoteDataBuildService { .every((b: boolean) => b === true); const errorMessage: string = arr - .map((d: RemoteData) => d.errorMessage) - .map((e: string, idx: number) => { + .map((d: RemoteData) => d.error) + .map((e: RemoteDataError, idx: number) => { if (hasValue(e)) { - return `[${idx}]: ${e}`; + return `[${idx}]: ${e.message}`; } }).filter((e: string) => hasValue(e)) .join(', '); const statusCode: string = arr - .map((d: RemoteData) => d.statusCode) - .map((c: string, idx: number) => { - if (hasValue(c)) { - return `[${idx}]: ${c}`; + .map((d: RemoteData) => d.error) + .map((e: RemoteDataError, idx: number) => { + if (hasValue(e)) { + return `[${idx}]: ${e.statusCode}`; } }).filter((c: string) => hasValue(c)) .join(', '); - const pageInfo = undefined; + const error = new RemoteDataError(statusCode, errorMessage); const payload: T[] = arr.map((d: RemoteData) => d.payload); return new RemoteData( - `dspace-angular://aggregated/object/${new Date().getTime()}`, requestPending, responsePending, isSuccessFul, - errorMessage, - statusCode, - pageInfo, + error, payload ); }) diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 5751173054..68fa2657f5 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -10,6 +10,7 @@ import { DSpaceObject } from '../shared/dspace-object.model'; import { GenericConstructor } from '../shared/generic-constructor'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { URLCombiner } from '../url-combiner/url-combiner'; +import { PaginatedList } from './paginated-list'; import { RemoteData } from './remote-data'; import { FindAllOptions, @@ -70,7 +71,7 @@ export abstract class DataService } } - findAll(options: FindAllOptions = {}): Observable> { + findAll(options: FindAllOptions = {}): Observable>> { const hrefObs = this.getEndpoint().filter((href: string) => isNotEmpty(href)) .flatMap((endpoint: string) => this.getFindAllHref(endpoint, options)); @@ -82,7 +83,7 @@ export abstract class DataService this.requestService.configure(request); }); - return this.rdbService.buildList(hrefObs, this.normalizedResourceType); + return this.rdbService.buildList(hrefObs, this.normalizedResourceType) as Observable>>; } getFindByIDHref(endpoint, resourceID): string { diff --git a/src/app/core/data/paginated-list.ts b/src/app/core/data/paginated-list.ts new file mode 100644 index 0000000000..f1d076927d --- /dev/null +++ b/src/app/core/data/paginated-list.ts @@ -0,0 +1,42 @@ +import { PageInfo } from '../shared/page-info.model'; + +export class PaginatedList { + + constructor( + private pageInfo: PageInfo, + public page: T[] + ) { + } + + get elementsPerPage(): number { + return this.pageInfo.elementsPerPage; + } + + set elementsPerPage(value: number) { + this.pageInfo.elementsPerPage = value; + } + + get totalElements(): number { + return this.pageInfo.totalElements; + } + + set totalElements(value: number) { + this.pageInfo.totalElements = value; + } + + get totalPages(): number { + return this.pageInfo.totalPages; + } + + set totalPages(value: number) { + this.pageInfo.totalPages = value; + } + + get currentPage(): number { + return this.pageInfo.currentPage; + } + + set currentPage(value: number) { + this.pageInfo.currentPage = value; + } +} diff --git a/src/app/core/data/remote-data-error.ts b/src/app/core/data/remote-data-error.ts new file mode 100644 index 0000000000..a2ff27a073 --- /dev/null +++ b/src/app/core/data/remote-data-error.ts @@ -0,0 +1,7 @@ +export class RemoteDataError { + constructor( + public statusCode: string, + public message: string + ) { + } +} diff --git a/src/app/core/data/remote-data.ts b/src/app/core/data/remote-data.ts index d8a2f79e66..41953260ac 100644 --- a/src/app/core/data/remote-data.ts +++ b/src/app/core/data/remote-data.ts @@ -1,5 +1,5 @@ -import { PageInfo } from '../shared/page-info.model'; import { hasValue } from '../../shared/empty.util'; +import { RemoteDataError } from './remote-data-error'; export enum RemoteDataState { RequestPending = 'RequestPending', @@ -13,13 +13,10 @@ export enum RemoteDataState { */ export class RemoteData { constructor( - public self: string, private requestPending: boolean, private responsePending: boolean, private isSuccessFul: boolean, - public errorMessage: string, - public statusCode: string, - public pageInfo: PageInfo, + public error: RemoteDataError, public payload: T ) { } diff --git a/src/app/core/data/request.models.ts b/src/app/core/data/request.models.ts index 3ab7dc0b8c..3a7141d22d 100644 --- a/src/app/core/data/request.models.ts +++ b/src/app/core/data/request.models.ts @@ -9,14 +9,24 @@ import { BrowseResponseParsingService } from './browse-response-parsing.service' import { ConfigResponseParsingService } from './config-response-parsing.service'; /* tslint:disable:max-classes-per-file */ + +/** + * Represents a Request Method. + * + * I didn't reuse the RequestMethod enum in @angular/http because + * it uses numbers. The string values here are more clear when + * debugging. + * + * The ones commented out are still unsupported in the rest of the codebase + */ export enum RestRequestMethod { Get = 'GET', Post = 'POST', - Put = 'PUT', - Delete = 'DELETE', - Options = 'OPTIONS', - Head = 'HEAD', - Patch = 'PATCH' + // Put = 'PUT', + // Delete = 'DELETE', + // Options = 'OPTIONS', + // Head = 'HEAD', + // Patch = 'PATCH' } export class RestRequest { diff --git a/src/app/core/data/request.service.ts b/src/app/core/data/request.service.ts index 0eee771a52..a075244648 100644 --- a/src/app/core/data/request.service.ts +++ b/src/app/core/data/request.service.ts @@ -12,7 +12,7 @@ import { ResponseCacheService } from '../cache/response-cache.service'; import { coreSelector, CoreState } from '../core.reducers'; import { keySelector } from '../shared/selectors'; import { RequestConfigureAction, RequestExecuteAction } from './request.actions'; -import { RestRequest } from './request.models'; +import { RestRequest, RestRequestMethod } from './request.models'; import { RequestEntry, RequestState } from './request.reducer'; @@ -30,11 +30,9 @@ export function requestStateSelector(): MemoizedSelector - ) { + constructor(private objectCache: ObjectCacheService, + private responseCache: ResponseCacheService, + private store: Store) { } isPending(href: string): boolean { @@ -59,6 +57,12 @@ export class RequestService { } configure(request: RestRequest): void { + if (request.method !== RestRequestMethod.Get || !this.isCachedOrPending(request)) { + this.dispatchRequest(request); + } + } + + private isCachedOrPending(request: RestRequest) { let isCached = this.objectCache.hasBySelfLink(request.href); if (!isCached && this.responseCache.has(request.href)) { const [successResponse, errorResponse] = this.responseCache.get(request.href) @@ -84,11 +88,13 @@ export class RequestService { const isPending = this.isPending(request.href); - if (!(isCached || isPending)) { - this.store.dispatch(new RequestConfigureAction(request)); - this.store.dispatch(new RequestExecuteAction(request.href)); - this.trackRequestsOnTheirWayToTheStore(request.href); - } + return isCached || isPending; + } + + private dispatchRequest(request: RestRequest) { + this.store.dispatch(new RequestConfigureAction(request)); + this.store.dispatch(new RequestExecuteAction(request.href)); + this.trackRequestsOnTheirWayToTheStore(request.href); } /** diff --git a/src/app/core/metadata/metadata.service.spec.ts b/src/app/core/metadata/metadata.service.spec.ts index 4c8775fcfb..110a46c1b9 100644 --- a/src/app/core/metadata/metadata.service.spec.ts +++ b/src/app/core/metadata/metadata.service.spec.ts @@ -11,6 +11,7 @@ import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; import { Store, StoreModule } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; +import { RemoteDataError } from '../data/remote-data-error'; import { MetadataService } from './metadata.service'; @@ -178,13 +179,10 @@ describe('MetadataService', () => { const mockRemoteData = (mockItem: Item): Observable> => { return Observable.of(new RemoteData( - '', false, false, true, - '', - '200', - {} as PageInfo, + new RemoteDataError('200', ''), MockItem )); } diff --git a/src/app/object-list/object-list.component.html b/src/app/object-list/object-list.component.html index 0d488b5298..897342ae0d 100644 --- a/src/app/object-list/object-list.component.html +++ b/src/app/object-list/object-list.component.html @@ -1,7 +1,7 @@
          -
        • +
        diff --git a/src/app/object-list/object-list.component.ts b/src/app/object-list/object-list.component.ts index 0f7decadd7..b298522ebc 100644 --- a/src/app/object-list/object-list.component.ts +++ b/src/app/object-list/object-list.component.ts @@ -8,13 +8,12 @@ import { } from '@angular/core'; import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; +import { PaginatedList } from '../core/data/paginated-list'; import { RemoteData } from '../core/data/remote-data'; -import { PageInfo } from '../core/shared/page-info.model'; -import { ListableObject } from '../object-list/listable-object/listable-object.model'; +import { ListableObject } from './listable-object/listable-object.model'; import { fadeIn } from '../shared/animations/fade'; -import { hasValue } from '../shared/empty.util'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; @@ -32,13 +31,9 @@ export class ObjectListComponent { @Input() sortConfig: SortOptions; @Input() hideGear = false; @Input() hidePagerWhenSinglePage = true; - private _objects: RemoteData; - pageInfo: PageInfo; - @Input() set objects(objects: RemoteData) { + private _objects: RemoteData>; + @Input() set objects(objects: RemoteData>) { this._objects = objects; - if (hasValue(objects)) { - this.pageInfo = objects.pageInfo; - } } get objects() { return this._objects; From 827058762449b14ff3f36cd6eddfee3ab055b0b0 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 7 Dec 2017 13:12:41 +0100 Subject: [PATCH 61/77] #150 Mive object-list.component test to correct package + delete empty file --- src/app/object-list/list-element-decorator.ts | 0 src/app/{ => shared}/object-list/object-list.component.spec.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/app/object-list/list-element-decorator.ts rename src/app/{ => shared}/object-list/object-list.component.spec.ts (100%) diff --git a/src/app/object-list/list-element-decorator.ts b/src/app/object-list/list-element-decorator.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/app/object-list/object-list.component.spec.ts b/src/app/shared/object-list/object-list.component.spec.ts similarity index 100% rename from src/app/object-list/object-list.component.spec.ts rename to src/app/shared/object-list/object-list.component.spec.ts From 5f5d9eaeeedc03c3adcd8c88f0b0e067faa55b66 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Tue, 12 Dec 2017 17:45:32 +0100 Subject: [PATCH 62/77] Switched to storing requests based on UUID, generalized UUIDIndexReducer to work with any type of index --- package.json | 2 + .../+search-page/search-page.component.html | 2 +- src/app/core/browse/browse.service.spec.ts | 7 +- src/app/core/browse/browse.service.ts | 2 +- .../builders/remote-data-build.service.ts | 10 +-- src/app/core/cache/object-cache.service.ts | 11 +-- src/app/core/cache/response-cache.service.ts | 6 +- src/app/core/config/config.service.spec.ts | 11 ++- src/app/core/config/config.service.ts | 8 +-- src/app/core/core.effects.ts | 2 +- src/app/core/core.module.ts | 2 + src/app/core/core.reducers.ts | 6 +- .../browse-response-parsing.service.spec.ts | 2 +- src/app/core/data/comcol-data.service.spec.ts | 7 +- src/app/core/data/comcol-data.service.ts | 2 +- .../config-response-parsing.service.spec.ts | 2 +- src/app/core/data/data.service.ts | 8 +-- src/app/core/data/request.actions.ts | 18 +++-- src/app/core/data/request.effects.ts | 6 +- src/app/core/data/request.models.ts | 22 +++--- src/app/core/data/request.reducer.spec.ts | 39 ++++++----- src/app/core/data/request.reducer.ts | 4 +- src/app/core/data/request.service.ts | 46 ++++++++---- src/app/core/index/index.actions.ts | 69 ++++++++++++++++++ src/app/core/index/index.effects.ts | 61 ++++++++++++++++ src/app/core/index/index.reducer.spec.ts | 58 +++++++++++++++ src/app/core/index/index.reducer.ts | 62 ++++++++++++++++ src/app/core/index/uuid-index.actions.ts | 60 ---------------- src/app/core/index/uuid-index.effects.ts | 34 --------- src/app/core/index/uuid-index.reducer.spec.ts | 56 --------------- src/app/core/index/uuid-index.reducer.ts | 46 ------------ .../core/shared/hal-endpoint.service.spec.ts | 5 +- src/app/core/shared/hal-endpoint.service.ts | 2 +- src/app/core/shared/selectors.ts | 24 ++++--- src/app/core/shared/uuid.service.ts | 9 +++ src/app/shared/mocks/mock-request.service.ts | 8 +++ yarn.lock | 70 ++++++++++--------- 37 files changed, 449 insertions(+), 340 deletions(-) create mode 100644 src/app/core/index/index.actions.ts create mode 100644 src/app/core/index/index.effects.ts create mode 100644 src/app/core/index/index.reducer.spec.ts create mode 100644 src/app/core/index/index.reducer.ts delete mode 100644 src/app/core/index/uuid-index.actions.ts delete mode 100644 src/app/core/index/uuid-index.effects.ts delete mode 100644 src/app/core/index/uuid-index.reducer.spec.ts delete mode 100644 src/app/core/index/uuid-index.reducer.ts create mode 100644 src/app/core/shared/uuid.service.ts create mode 100644 src/app/shared/mocks/mock-request.service.ts diff --git a/package.json b/package.json index f2bb074ff4..60bb3c8d09 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "reflect-metadata": "0.1.10", "rxjs": "5.4.3", "ts-md5": "1.2.2", + "uuid": "^3.1.0", "webfontloader": "1.6.28", "zone.js": "0.8.18" }, @@ -126,6 +127,7 @@ "@types/node": "8.0.34", "@types/serve-static": "1.7.32", "@types/source-map": "0.5.1", + "@types/uuid": "^3.4.3", "@types/webfontloader": "1.6.29", "ajv": "5.2.3", "ajv-keywords": "2.1.0", diff --git a/src/app/+search-page/search-page.component.html b/src/app/+search-page/search-page.component.html index 953de02ab4..08fae7d19a 100644 --- a/src/app/+search-page/search-page.component.html +++ b/src/app/+search-page/search-page.component.html @@ -29,7 +29,7 @@ | translate}}
        -
        diff --git a/src/app/core/browse/browse.service.spec.ts b/src/app/core/browse/browse.service.spec.ts index 65b32b3c0b..30429c5a8c 100644 --- a/src/app/core/browse/browse.service.spec.ts +++ b/src/app/core/browse/browse.service.spec.ts @@ -1,3 +1,4 @@ +import { initMockRequestService } from '../../shared/mocks/mock-request.service'; import { BrowseService } from './browse.service'; import { ResponseCacheService } from '../cache/response-cache.service'; import { RequestService } from '../data/request.service'; @@ -85,10 +86,6 @@ describe('BrowseService', () => { }); } - function initMockRequestService() { - return jasmine.createSpyObj('requestService', ['configure']); - } - function initTestService() { return new BrowseService( responseCache, @@ -157,7 +154,7 @@ describe('BrowseService', () => { it('should configure a new BrowseEndpointRequest', () => { const metadatumKey = 'dc.date.issued'; const linkName = 'items'; - const expected = new BrowseEndpointRequest(browsesEndpointURL); + const expected = new BrowseEndpointRequest(requestService.generateRequestId(), browsesEndpointURL); scheduler.schedule(() => service.getBrowseURLFor(metadatumKey, linkName).subscribe()); scheduler.flush(); diff --git a/src/app/core/browse/browse.service.ts b/src/app/core/browse/browse.service.ts index 6d8d504b82..a321e14706 100644 --- a/src/app/core/browse/browse.service.ts +++ b/src/app/core/browse/browse.service.ts @@ -40,7 +40,7 @@ export class BrowseService extends HALEndpointService { return this.getEndpoint() .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() - .map((endpointURL: string) => new BrowseEndpointRequest(endpointURL)) + .map((endpointURL: string) => new BrowseEndpointRequest(this.requestService.generateRequestId(), endpointURL)) .do((request: RestRequest) => this.requestService.configure(request)) .flatMap((request: RestRequest) => { const [successResponse, errorResponse] = this.responseCache.get(request.href) 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 eee6808d86..6fb24328c2 100644 --- a/src/app/core/cache/builders/remote-data-build.service.ts +++ b/src/app/core/cache/builders/remote-data-build.service.ts @@ -39,10 +39,10 @@ export class RemoteDataBuildService { this.objectCache.getRequestHrefBySelfLink(href)); const requestObs = Observable.race( - hrefObs.flatMap((href: string) => this.requestService.get(href)) + hrefObs.flatMap((href: string) => this.requestService.getByHref(href)) .filter((entry) => hasValue(entry)), requestHrefObs.flatMap((requestHref) => - this.requestService.get(requestHref)).filter((entry) => hasValue(entry)) + this.requestService.getByHref(requestHref)).filter((entry) => hasValue(entry)) ); const responseCacheObs = Observable.race( @@ -115,7 +115,7 @@ export class RemoteDataBuildService { hrefObs = Observable.of(hrefObs); } - const requestObs = hrefObs.flatMap((href: string) => this.requestService.get(href)) + const requestObs = hrefObs.flatMap((href: string) => this.requestService.getByHref(href)) .filter((entry) => hasValue(entry)); const responseCacheObs = hrefObs.flatMap((href: string) => this.responseCache.get(href)) .filter((entry) => hasValue(entry)); @@ -169,7 +169,7 @@ export class RemoteDataBuildService { const resourceConstructor = NormalizedObjectFactory.getConstructor(resourceType); if (Array.isArray(normalized[relationship])) { normalized[relationship].forEach((href: string) => { - this.requestService.configure(new RestRequest(href)) + this.requestService.configure(new RestRequest(this.requestService.generateRequestId(), href)) }); const rdArr = []; @@ -183,7 +183,7 @@ export class RemoteDataBuildService { links[relationship] = rdArr[0]; } } else { - this.requestService.configure(new RestRequest(normalized[relationship])); + this.requestService.configure(new RestRequest(this.requestService.generateRequestId(), normalized[relationship])); // The rest API can return a single URL to represent a list of resources (e.g. /items/:id/bitstreams) // in that case only 1 href will be stored in the normalized obj (so the isArray above fails), diff --git a/src/app/core/cache/object-cache.service.ts b/src/app/core/cache/object-cache.service.ts index 31eb2d0b6a..ae41c38fbe 100644 --- a/src/app/core/cache/object-cache.service.ts +++ b/src/app/core/cache/object-cache.service.ts @@ -2,20 +2,21 @@ import { Injectable } from '@angular/core'; import { MemoizedSelector, Store } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; +import { IndexName } from '../index/index.reducer'; import { ObjectCacheEntry, CacheableObject } from './object-cache.reducer'; import { AddToObjectCacheAction, RemoveFromObjectCacheAction } from './object-cache.actions'; import { hasNoValue } from '../../shared/empty.util'; import { GenericConstructor } from '../shared/generic-constructor'; -import { CoreState } from '../core.reducers'; -import { keySelector } from '../shared/selectors'; +import { coreSelector, CoreState } from '../core.reducers'; +import { pathSelector } from '../shared/selectors'; function selfLinkFromUuidSelector(uuid: string): MemoizedSelector { - return keySelector('index/uuid', uuid); + return pathSelector(coreSelector, 'index', IndexName.OBJECT, uuid); } function entryFromSelfLinkSelector(selfLink: string): MemoizedSelector { - return keySelector('data/object', selfLink); + return pathSelector(coreSelector, 'data/object', selfLink); } /** @@ -60,7 +61,7 @@ export class ObjectCacheService { * the cached plain javascript object in to an instance of * a class. * - * e.g. get('c96588c6-72d3-425d-9d47-fa896255a695', Item) + * e.g. getByUUID('c96588c6-72d3-425d-9d47-fa896255a695', Item) * * @param uuid * The UUID of the object to get diff --git a/src/app/core/cache/response-cache.service.ts b/src/app/core/cache/response-cache.service.ts index 65ce8b2bac..77a2402043 100644 --- a/src/app/core/cache/response-cache.service.ts +++ b/src/app/core/cache/response-cache.service.ts @@ -7,11 +7,11 @@ import { ResponseCacheEntry } from './response-cache.reducer'; import { hasNoValue } from '../../shared/empty.util'; import { ResponseCacheRemoveAction, ResponseCacheAddAction } from './response-cache.actions'; import { RestResponse } from './response-cache.models'; -import { CoreState } from '../core.reducers'; -import { keySelector } from '../shared/selectors'; +import { coreSelector, CoreState } from '../core.reducers'; +import { pathSelector } from '../shared/selectors'; function entryFromKeySelector(key: string): MemoizedSelector { - return keySelector('data/response', key); + return pathSelector(coreSelector, 'data/response', key); } /** diff --git a/src/app/core/config/config.service.spec.ts b/src/app/core/config/config.service.spec.ts index c0d02be82a..111e1d3eaa 100644 --- a/src/app/core/config/config.service.spec.ts +++ b/src/app/core/config/config.service.spec.ts @@ -1,6 +1,7 @@ import { cold, getTestScheduler, hot } from 'jasmine-marbles'; import { TestScheduler } from 'rxjs/Rx'; import { GlobalConfig } from '../../../config'; +import { initMockRequestService } from '../../shared/mocks/mock-request.service'; import { ResponseCacheService } from '../cache/response-cache.service'; import { ConfigService } from './config.service'; import { RequestService } from '../data/request.service'; @@ -38,10 +39,6 @@ describe('ConfigService', () => { const scopedEndpoint = `${serviceEndpoint}/${scopeName}`; const searchEndpoint = `${serviceEndpoint}/${BROWSE}?uuid=${scopeID}`; - function initMockRequestService(): RequestService { - return jasmine.createSpyObj('requestService', ['configure']); - } - function initMockResponseCacheService(isSuccessful: boolean): ResponseCacheService { return jasmine.createSpyObj('responseCache', { get: cold('c-', { @@ -70,7 +67,7 @@ describe('ConfigService', () => { describe('getConfigByHref', () => { it('should configure a new ConfigRequest', () => { - const expected = new ConfigRequest(scopedEndpoint); + const expected = new ConfigRequest(requestService.generateRequestId(), scopedEndpoint); scheduler.schedule(() => service.getConfigByHref(scopedEndpoint).subscribe()); scheduler.flush(); @@ -81,7 +78,7 @@ describe('ConfigService', () => { describe('getConfigByName', () => { it('should configure a new ConfigRequest', () => { - const expected = new ConfigRequest(scopedEndpoint); + const expected = new ConfigRequest(requestService.generateRequestId(), scopedEndpoint); scheduler.schedule(() => service.getConfigByName(scopeName).subscribe()); scheduler.flush(); @@ -93,7 +90,7 @@ describe('ConfigService', () => { it('should configure a new ConfigRequest', () => { findOptions.scopeID = scopeID; - const expected = new ConfigRequest(searchEndpoint); + const expected = new ConfigRequest(requestService.generateRequestId(), searchEndpoint); scheduler.schedule(() => service.getConfigBySearch(findOptions).subscribe()); scheduler.flush(); diff --git a/src/app/core/config/config.service.ts b/src/app/core/config/config.service.ts index 55c4055ed7..9ad4684300 100644 --- a/src/app/core/config/config.service.ts +++ b/src/app/core/config/config.service.ts @@ -75,14 +75,14 @@ export abstract class ConfigService extends HALEndpointService { return this.getEndpoint() .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() - .map((endpointURL: string) => new ConfigRequest(endpointURL)) + .map((endpointURL: string) => new ConfigRequest(this.requestService.generateRequestId(), endpointURL)) .do((request: RestRequest) => this.requestService.configure(request)) .flatMap((request: RestRequest) => this.getConfig(request)) .distinctUntilChanged(); } public getConfigByHref(href: string): Observable { - const request = new ConfigRequest(href); + const request = new ConfigRequest(this.requestService.generateRequestId(), href); this.requestService.configure(request); return this.getConfig(request); @@ -93,7 +93,7 @@ export abstract class ConfigService extends HALEndpointService { .map((endpoint: string) => this.getConfigByNameHref(endpoint, name)) .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() - .map((endpointURL: string) => new ConfigRequest(endpointURL)) + .map((endpointURL: string) => new ConfigRequest(this.requestService.generateRequestId(), endpointURL)) .do((request: RestRequest) => this.requestService.configure(request)) .flatMap((request: RestRequest) => this.getConfig(request)) .distinctUntilChanged(); @@ -104,7 +104,7 @@ export abstract class ConfigService extends HALEndpointService { .map((endpoint: string) => this.getConfigSearchHref(endpoint, options)) .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() - .map((endpointURL: string) => new ConfigRequest(endpointURL)) + .map((endpointURL: string) => new ConfigRequest(this.requestService.generateRequestId(), endpointURL)) .do((request: RestRequest) => this.requestService.configure(request)) .flatMap((request: RestRequest) => this.getConfig(request)) .distinctUntilChanged(); diff --git a/src/app/core/core.effects.ts b/src/app/core/core.effects.ts index f144f773a1..7cda10b4ae 100644 --- a/src/app/core/core.effects.ts +++ b/src/app/core/core.effects.ts @@ -1,7 +1,7 @@ import { ObjectCacheEffects } from './cache/object-cache.effects'; import { ResponseCacheEffects } from './cache/response-cache.effects'; -import { UUIDIndexEffects } from './index/uuid-index.effects'; +import { UUIDIndexEffects } from './index/index.effects'; import { RequestEffects } from './data/request.effects'; export const coreEffects = [ diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index f4c7e2bbcc..768f05f24b 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -37,6 +37,7 @@ import { RouteService } from '../shared/route.service'; import { SubmissionDefinitionsConfigService } from './config/submission-definitions-config.service'; import { SubmissionFormsConfigService } from './config/submission-forms-config.service'; import { SubmissionSectionsConfigService } from './config/submission-sections-config.service'; +import { UUIDService } from './shared/uuid.service'; const IMPORTS = [ CommonModule, @@ -75,6 +76,7 @@ const PROVIDERS = [ SubmissionDefinitionsConfigService, SubmissionFormsConfigService, SubmissionSectionsConfigService, + UUIDService, { provide: NativeWindowService, useFactory: NativeWindowFactory } ]; diff --git a/src/app/core/core.reducers.ts b/src/app/core/core.reducers.ts index 493c9e96d9..d2898eb3c3 100644 --- a/src/app/core/core.reducers.ts +++ b/src/app/core/core.reducers.ts @@ -2,21 +2,21 @@ import { ActionReducerMap, createFeatureSelector } from '@ngrx/store'; import { responseCacheReducer, ResponseCacheState } from './cache/response-cache.reducer'; import { objectCacheReducer, ObjectCacheState } from './cache/object-cache.reducer'; -import { uuidIndexReducer, UUIDIndexState } from './index/uuid-index.reducer'; +import { indexReducer, IndexState } from './index/index.reducer'; import { requestReducer, RequestState } from './data/request.reducer'; export interface CoreState { 'data/object': ObjectCacheState, 'data/response': ResponseCacheState, 'data/request': RequestState, - 'index/uuid': UUIDIndexState + 'index': IndexState } export const coreReducers: ActionReducerMap = { 'data/object': objectCacheReducer, 'data/response': responseCacheReducer, 'data/request': requestReducer, - 'index/uuid': uuidIndexReducer + 'index': indexReducer }; export const coreSelector = createFeatureSelector('core'); diff --git a/src/app/core/data/browse-response-parsing.service.spec.ts b/src/app/core/data/browse-response-parsing.service.spec.ts index 5f27519a93..6579621610 100644 --- a/src/app/core/data/browse-response-parsing.service.spec.ts +++ b/src/app/core/data/browse-response-parsing.service.spec.ts @@ -11,7 +11,7 @@ describe('BrowseResponseParsingService', () => { }); describe('parse', () => { - const validRequest = new BrowseEndpointRequest('https://rest.api/discover/browses'); + const validRequest = new BrowseEndpointRequest('clients/b186e8ce-e99c-4183-bc9a-42b4821bdb78', 'https://rest.api/discover/browses'); const validResponse = { payload: { diff --git a/src/app/core/data/comcol-data.service.spec.ts b/src/app/core/data/comcol-data.service.spec.ts index 0d78a9fa8d..d34ffc2277 100644 --- a/src/app/core/data/comcol-data.service.spec.ts +++ b/src/app/core/data/comcol-data.service.spec.ts @@ -2,6 +2,7 @@ import { Store } from '@ngrx/store'; import { cold, getTestScheduler, hot } from 'jasmine-marbles'; import { TestScheduler } from 'rxjs/Rx'; import { GlobalConfig } from '../../../config'; +import { initMockRequestService } 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'; @@ -62,10 +63,6 @@ describe('ComColDataService', () => { }); } - function initMockRequestService(): RequestService { - return jasmine.createSpyObj('requestService', ['configure']); - } - function initMockResponseCacheService(isSuccessful: boolean): ResponseCacheService { return jasmine.createSpyObj('responseCache', { get: cold('c-', { @@ -110,7 +107,7 @@ describe('ComColDataService', () => { responseCache = initMockResponseCacheService(true); service = initTestService(); - const expected = new FindByIDRequest(communityEndpoint, scopeID); + const expected = new FindByIDRequest(requestService.generateRequestId(), communityEndpoint, scopeID); scheduler.schedule(() => service.getScopedEndpoint(scopeID).subscribe()); scheduler.flush(); diff --git a/src/app/core/data/comcol-data.service.ts b/src/app/core/data/comcol-data.service.ts index 17d2fb313c..68981121c1 100644 --- a/src/app/core/data/comcol-data.service.ts +++ b/src/app/core/data/comcol-data.service.ts @@ -33,7 +33,7 @@ export abstract class ComColDataService isNotEmpty(href)) .take(1) .do((href: string) => { - const request = new FindByIDRequest(href, scopeID); + const request = new FindByIDRequest(this.requestService.generateRequestId(), href, scopeID); this.requestService.configure(request); }); diff --git a/src/app/core/data/config-response-parsing.service.spec.ts b/src/app/core/data/config-response-parsing.service.spec.ts index 46e6d61f8f..dc5c42cbd5 100644 --- a/src/app/core/data/config-response-parsing.service.spec.ts +++ b/src/app/core/data/config-response-parsing.service.spec.ts @@ -21,7 +21,7 @@ describe('ConfigResponseParsingService', () => { }); describe('parse', () => { - const validRequest = new ConfigRequest('https://rest.api/config/submissiondefinitions/traditional'); + const validRequest = new ConfigRequest('69f375b5-19f4-4453-8c7a-7dc5c55aafbb', 'https://rest.api/config/submissiondefinitions/traditional'); const validResponse = { payload: { diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 68fa2657f5..3e86bb21b0 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -79,7 +79,7 @@ export abstract class DataService .filter((href: string) => hasValue(href)) .take(1) .subscribe((href: string) => { - const request = new FindAllRequest(href, options); + const request = new FindAllRequest(this.requestService.generateRequestId(), href, options); this.requestService.configure(request); }); @@ -98,7 +98,7 @@ export abstract class DataService .filter((href: string) => hasValue(href)) .take(1) .subscribe((href: string) => { - const request = new FindByIDRequest(href, id); + const request = new FindByIDRequest(this.requestService.generateRequestId(), href, id); this.requestService.configure(request); }); @@ -106,7 +106,7 @@ export abstract class DataService } findByHref(href: string): Observable> { - this.requestService.configure(new RestRequest(href)); + this.requestService.configure(new RestRequest(this.requestService.generateRequestId(), href)); return this.rdbService.buildSingle(href, this.normalizedResourceType); } @@ -120,7 +120,7 @@ export abstract class DataService .filter((href: string) => hasValue(href)) .take(1) .subscribe((href: string) => { - const request = new RestRequest(href, RestRequestMethod.Post, dso); + const request = new RestRequest(this.requestService.generateRequestId(), href, RestRequestMethod.Post, dso); this.requestService.configure(request); }); diff --git a/src/app/core/data/request.actions.ts b/src/app/core/data/request.actions.ts index 31f0dc5996..436c365caa 100644 --- a/src/app/core/data/request.actions.ts +++ b/src/app/core/data/request.actions.ts @@ -27,8 +27,14 @@ export class RequestExecuteAction implements Action { type = RequestActionTypes.EXECUTE; payload: string; - constructor(key: string) { - this.payload = key + /** + * Create a new RequestExecuteAction + * + * @param uuid + * the request's uuid + */ + constructor(uuid: string) { + this.payload = uuid } } @@ -42,11 +48,11 @@ export class RequestCompleteAction implements Action { /** * Create a new RequestCompleteAction * - * @param key - * the key under which this request is stored, + * @param uuid + * the request's uuid */ - constructor(key: string) { - this.payload = key; + constructor(uuid: string) { + this.payload = uuid; } } /* tslint:enable:max-classes-per-file */ diff --git a/src/app/core/data/request.effects.ts b/src/app/core/data/request.effects.ts index f848d7f0d7..815878b7bf 100644 --- a/src/app/core/data/request.effects.ts +++ b/src/app/core/data/request.effects.ts @@ -25,7 +25,7 @@ export class RequestEffects { @Effect() execute = this.actions$ .ofType(RequestActionTypes.EXECUTE) .flatMap((action: RequestExecuteAction) => { - return this.requestService.get(action.payload) + return this.requestService.getByUUID(action.payload) .take(1); }) .map((entry: RequestEntry) => entry.request) @@ -42,10 +42,10 @@ export class RequestEffects { .map((data: DSpaceRESTV2Response) => this.injector.get(request.getResponseParser()).parse(request, data)) .do((response: RestResponse) => this.responseCache.add(request.href, response, this.EnvConfig.cache.msToLive)) - .map((response: RestResponse) => new RequestCompleteAction(request.href)) + .map((response: RestResponse) => new RequestCompleteAction(request.uuid)) .catch((error: RequestError) => Observable.of(new ErrorResponse(error)) .do((response: RestResponse) => this.responseCache.add(request.href, response, this.EnvConfig.cache.msToLive)) - .map((response: RestResponse) => new RequestCompleteAction(request.href))); + .map((response: RestResponse) => new RequestCompleteAction(request.uuid))); }); constructor( diff --git a/src/app/core/data/request.models.ts b/src/app/core/data/request.models.ts index 3a7141d22d..46f40b0abf 100644 --- a/src/app/core/data/request.models.ts +++ b/src/app/core/data/request.models.ts @@ -31,10 +31,12 @@ export enum RestRequestMethod { export class RestRequest { constructor( + public uuid: string, public href: string, public method: RestRequestMethod = RestRequestMethod.Get, public body?: any - ) { } + ) { + } getResponseParser(): GenericConstructor { return DSOResponseParsingService; @@ -43,10 +45,11 @@ export class RestRequest { export class FindByIDRequest extends RestRequest { constructor( + uuid: string, href: string, public resourceID: string ) { - super(href); + super(uuid, href); } } @@ -59,17 +62,18 @@ export class FindAllOptions { export class FindAllRequest extends RestRequest { constructor( + uuid: string, href: string, public options?: FindAllOptions, ) { - super(href); + super(uuid, href); } } export class RootEndpointRequest extends RestRequest { - constructor(EnvConfig: GlobalConfig) { + constructor(uuid: string, EnvConfig: GlobalConfig) { const href = new RESTURLCombiner(EnvConfig, '/').toString(); - super(href); + super(uuid, href); } getResponseParser(): GenericConstructor { @@ -78,8 +82,8 @@ export class RootEndpointRequest extends RestRequest { } export class BrowseEndpointRequest extends RestRequest { - constructor(href: string) { - super(href); + constructor(uuid: string, href: string) { + super(uuid, href); } getResponseParser(): GenericConstructor { @@ -88,8 +92,8 @@ export class BrowseEndpointRequest extends RestRequest { } export class ConfigRequest extends RestRequest { - constructor(href: string) { - super(href); + constructor(uuid: string, href: string) { + super(uuid, href); } getResponseParser(): GenericConstructor { diff --git a/src/app/core/data/request.reducer.spec.ts b/src/app/core/data/request.reducer.spec.ts index a6d84ffe80..138d3ea5dd 100644 --- a/src/app/core/data/request.reducer.spec.ts +++ b/src/app/core/data/request.reducer.spec.ts @@ -16,11 +16,13 @@ class NullAction extends RequestCompleteAction { } describe('requestReducer', () => { + const id1 = 'clients/eca2ea1d-6a6a-4f62-8907-176d5fec5014'; + const id2 = 'clients/eb7cde2e-a03f-4f0b-ac5d-888a4ef2b4eb'; const link1 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/567a639f-f5ff-4126-807c-b7d0910808c8'; const link2 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/1911e8a4-6939-490c-b58b-a5d70f8d91fb'; const testState: RequestState = { - [link1]: { - request: new RestRequest(link1), + [id1]: { + request: new RestRequest(id1, link1), requestPending: false, responsePending: false, completed: false @@ -44,37 +46,40 @@ describe('requestReducer', () => { it('should add the new RestRequest and set \'requestPending\' to true, \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to a CONFIGURE action', () => { const state = testState; - const request = new RestRequest(link2); + const request = new RestRequest(id2, link2); const action = new RequestConfigureAction(request); const newState = requestReducer(state, action); - expect(newState[link2].request.href).toEqual(link2); - expect(newState[link2].requestPending).toEqual(true); - expect(newState[link2].responsePending).toEqual(false); - expect(newState[link2].completed).toEqual(false); + expect(newState[id2].request.uuid).toEqual(id2); + expect(newState[id2].request.href).toEqual(link2); + expect(newState[id2].requestPending).toEqual(true); + expect(newState[id2].responsePending).toEqual(false); + expect(newState[id2].completed).toEqual(false); }); it('should set \'requestPending\' to false, \'responsePending\' to true and leave \'completed\' untouched for the given RestRequest in the state, in response to an EXECUTE action', () => { const state = testState; - const action = new RequestExecuteAction(link1); + const action = new RequestExecuteAction(id1); const newState = requestReducer(state, action); - expect(newState[link1].request.href).toEqual(link1); - expect(newState[link1].requestPending).toEqual(false); - expect(newState[link1].responsePending).toEqual(true); - expect(newState[link1].completed).toEqual(state[link1].completed); + expect(newState[id1].request.uuid).toEqual(id1); + expect(newState[id1].request.href).toEqual(link1); + expect(newState[id1].requestPending).toEqual(false); + expect(newState[id1].responsePending).toEqual(true); + expect(newState[id1].completed).toEqual(state[id1].completed); }); it('should leave \'requestPending\' untouched, set \'responsePending\' to false and \'completed\' to true for the given RestRequest in the state, in response to a COMPLETE action', () => { const state = testState; - const action = new RequestCompleteAction(link1); + const action = new RequestCompleteAction(id1); const newState = requestReducer(state, action); - expect(newState[link1].request.href).toEqual(link1); - expect(newState[link1].requestPending).toEqual(state[link1].requestPending); - expect(newState[link1].responsePending).toEqual(false); - expect(newState[link1].completed).toEqual(true); + expect(newState[id1].request.uuid).toEqual(id1); + expect(newState[id1].request.href).toEqual(link1); + expect(newState[id1].requestPending).toEqual(state[id1].requestPending); + expect(newState[id1].responsePending).toEqual(false); + expect(newState[id1].completed).toEqual(true); }); }); diff --git a/src/app/core/data/request.reducer.ts b/src/app/core/data/request.reducer.ts index 628725f745..3ac35d2741 100644 --- a/src/app/core/data/request.reducer.ts +++ b/src/app/core/data/request.reducer.ts @@ -12,7 +12,7 @@ export class RequestEntry { } export interface RequestState { - [key: string]: RequestEntry + [uuid: string]: RequestEntry } // Object.create(null) ensures the object has no default js properties (e.g. `__proto__`) @@ -41,7 +41,7 @@ export function requestReducer(state = initialState, action: RequestAction): Req function configureRequest(state: RequestState, action: RequestConfigureAction): RequestState { return Object.assign({}, state, { - [action.payload.href]: { + [action.payload.uuid]: { request: action.payload, requestPending: true, responsePending: false, diff --git a/src/app/core/data/request.service.ts b/src/app/core/data/request.service.ts index a075244648..6cfbedb5cb 100644 --- a/src/app/core/data/request.service.ts +++ b/src/app/core/data/request.service.ts @@ -10,14 +10,20 @@ import { DSOSuccessResponse, RestResponse } from '../cache/response-cache.models import { ResponseCacheEntry } from '../cache/response-cache.reducer'; import { ResponseCacheService } from '../cache/response-cache.service'; import { coreSelector, CoreState } from '../core.reducers'; -import { keySelector } from '../shared/selectors'; +import { IndexName } from '../index/index.reducer'; +import { pathSelector } from '../shared/selectors'; +import { UUIDService } from '../shared/uuid.service'; import { RequestConfigureAction, RequestExecuteAction } from './request.actions'; import { RestRequest, RestRequestMethod } from './request.models'; import { RequestEntry, RequestState } from './request.reducer'; -function entryFromHrefSelector(href: string): MemoizedSelector { - return keySelector('data/request', href); +function entryFromUUIDSelector(uuid: string): MemoizedSelector { + return pathSelector(coreSelector, 'data/request', uuid); +} + +function uuidFromHrefSelector(href: string): MemoizedSelector { + return pathSelector(coreSelector, 'index', IndexName.REQUEST, href); } export function requestStateSelector(): MemoizedSelector { @@ -32,18 +38,23 @@ export class RequestService { constructor(private objectCache: ObjectCacheService, private responseCache: ResponseCacheService, + private uuidService: UUIDService, private store: Store) { } - isPending(href: string): boolean { + generateRequestId(): string { + return `client/${this.uuidService.generate()}`; + } + + isPending(uuid: string): boolean { // first check requests that haven't made it to the store yet - if (this.requestsOnTheirWayToTheStore.includes(href)) { + if (this.requestsOnTheirWayToTheStore.includes(uuid)) { return true; } // then check the store let isPending = false; - this.store.select(entryFromHrefSelector(href)) + this.store.select(entryFromUUIDSelector(uuid)) .take(1) .subscribe((re: RequestEntry) => { isPending = (hasValue(re) && !re.completed) @@ -52,8 +63,13 @@ export class RequestService { return isPending; } - get(href: string): Observable { - return this.store.select(entryFromHrefSelector(href)); + getByUUID(uuid: string): Observable { + return this.store.select(entryFromUUIDSelector(uuid)); + } + + getByHref(href: string): Observable { + return this.store.select(uuidFromHrefSelector(href)) + .flatMap((uuid: string) => this.getByUUID(uuid)); } configure(request: RestRequest): void { @@ -86,15 +102,15 @@ export class RequestService { ).subscribe((c) => isCached = c); } - const isPending = this.isPending(request.href); + const isPending = this.isPending(request.uuid); return isCached || isPending; } private dispatchRequest(request: RestRequest) { this.store.dispatch(new RequestConfigureAction(request)); - this.store.dispatch(new RequestExecuteAction(request.href)); - this.trackRequestsOnTheirWayToTheStore(request.href); + this.store.dispatch(new RequestExecuteAction(request.uuid)); + this.trackRequestsOnTheirWayToTheStore(request.uuid); } /** @@ -104,13 +120,13 @@ export class RequestService { * This method will store the href of every request that gets configured in a local variable, and * remove it as soon as it can be found in the store. */ - private trackRequestsOnTheirWayToTheStore(href: string) { - this.requestsOnTheirWayToTheStore = [...this.requestsOnTheirWayToTheStore, href]; - this.store.select(entryFromHrefSelector(href)) + private trackRequestsOnTheirWayToTheStore(uuid: string) { + this.requestsOnTheirWayToTheStore = [...this.requestsOnTheirWayToTheStore, uuid]; + this.store.select(entryFromUUIDSelector(uuid)) .filter((re: RequestEntry) => hasValue(re)) .take(1) .subscribe((re: RequestEntry) => { - this.requestsOnTheirWayToTheStore = this.requestsOnTheirWayToTheStore.filter((pendingHref: string) => pendingHref !== href) + this.requestsOnTheirWayToTheStore = this.requestsOnTheirWayToTheStore.filter((pendingUUID: string) => pendingUUID !== uuid) }); } } diff --git a/src/app/core/index/index.actions.ts b/src/app/core/index/index.actions.ts new file mode 100644 index 0000000000..014b6561a3 --- /dev/null +++ b/src/app/core/index/index.actions.ts @@ -0,0 +1,69 @@ +import { Action } from '@ngrx/store'; + +import { type } from '../../shared/ngrx/type'; +import { IndexName } from './index.reducer'; + +/** + * The list of HrefIndexAction type definitions + */ +export const IndexActionTypes = { + ADD: type('dspace/core/index/ADD'), + REMOVE_BY_VALUE: type('dspace/core/index/REMOVE_BY_VALUE') +}; + +/* tslint:disable:max-classes-per-file */ +/** + * An ngrx action to add an value to the index + */ +export class AddToIndexAction implements Action { + type = IndexActionTypes.ADD; + payload: { + name: IndexName; + value: string; + key: string; + }; + + /** + * Create a new AddToIndexAction + * + * @param name + * the name of the index to add to + * @param key + * the key to add + * @param value + * the self link of the resource the key belongs to + */ + constructor(name: IndexName, key: string, value: string) { + this.payload = { name, key, value }; + } +} + +/** + * An ngrx action to remove an value from the index + */ +export class RemoveFromIndexByValueAction implements Action { + type = IndexActionTypes.REMOVE_BY_VALUE; + payload: { + name: IndexName, + value: string + }; + + /** + * Create a new RemoveFromIndexByValueAction + * + * @param name + * the name of the index to remove from + * @param value + * the value to remove the UUID for + */ + constructor(name: IndexName, value: string) { + this.payload = { name, value }; + } + +} +/* tslint:enable:max-classes-per-file */ + +/** + * A type to encompass all HrefIndexActions + */ +export type IndexAction = AddToIndexAction | RemoveFromIndexByValueAction; diff --git a/src/app/core/index/index.effects.ts b/src/app/core/index/index.effects.ts new file mode 100644 index 0000000000..05ae529c8e --- /dev/null +++ b/src/app/core/index/index.effects.ts @@ -0,0 +1,61 @@ +import { Injectable } from '@angular/core'; +import { Effect, Actions } from '@ngrx/effects'; + +import { + ObjectCacheActionTypes, AddToObjectCacheAction, + RemoveFromObjectCacheAction +} from '../cache/object-cache.actions'; +import { RequestActionTypes, RequestConfigureAction } from '../data/request.actions'; +import { RestRequestMethod } from '../data/request.models'; +import { AddToIndexAction, RemoveFromIndexByValueAction } from './index.actions'; +import { hasValue } from '../../shared/empty.util'; +import { IndexName } from './index.reducer'; + +@Injectable() +export class UUIDIndexEffects { + + @Effect() addObject$ = this.actions$ + .ofType(ObjectCacheActionTypes.ADD) + .filter((action: AddToObjectCacheAction) => hasValue(action.payload.objectToCache.uuid)) + .map((action: AddToObjectCacheAction) => { + return new AddToIndexAction( + IndexName.OBJECT, + action.payload.objectToCache.uuid, + action.payload.objectToCache.self + ); + }); + + @Effect() removeObject$ = this.actions$ + .ofType(ObjectCacheActionTypes.REMOVE) + .map((action: RemoveFromObjectCacheAction) => { + return new RemoveFromIndexByValueAction( + IndexName.OBJECT, + action.payload + ); + }); + + @Effect() addRequest$ = this.actions$ + .ofType(RequestActionTypes.CONFIGURE) + .filter((action: RequestConfigureAction) => action.payload.method === RestRequestMethod.Get) + .map((action: RequestConfigureAction) => { + return new AddToIndexAction( + IndexName.REQUEST, + action.payload.href, + action.payload.uuid + ); + }); + + // @Effect() removeRequest$ = this.actions$ + // .ofType(ObjectCacheActionTypes.REMOVE) + // .map((action: RemoveFromObjectCacheAction) => { + // return new RemoveFromIndexByValueAction( + // IndexName.OBJECT, + // action.payload + // ); + // }); + + constructor(private actions$: Actions) { + + } + +} diff --git a/src/app/core/index/index.reducer.spec.ts b/src/app/core/index/index.reducer.spec.ts new file mode 100644 index 0000000000..a1cf92aeb3 --- /dev/null +++ b/src/app/core/index/index.reducer.spec.ts @@ -0,0 +1,58 @@ +import * as deepFreeze from 'deep-freeze'; + +import { IndexName, indexReducer, IndexState } from './index.reducer'; +import { AddToIndexAction, RemoveFromIndexByValueAction } from './index.actions'; + +class NullAction extends AddToIndexAction { + type = null; + payload = null; + + constructor() { + super(null, null, null); + } +} + +describe('requestReducer', () => { + const key1 = '567a639f-f5ff-4126-807c-b7d0910808c8'; + const key2 = '1911e8a4-6939-490c-b58b-a5d70f8d91fb'; + const val1 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/567a639f-f5ff-4126-807c-b7d0910808c8'; + const val2 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/1911e8a4-6939-490c-b58b-a5d70f8d91fb'; + const testState: IndexState = { + [IndexName.OBJECT]: { + [key1]: val1 + } + }; + deepFreeze(testState); + + it('should return the current state when no valid actions have been made', () => { + const action = new NullAction(); + const newState = indexReducer(testState, action); + + expect(newState).toEqual(testState); + }); + + it('should start with an empty state', () => { + const action = new NullAction(); + const initialState = indexReducer(undefined, action); + + expect(initialState).toEqual(Object.create(null)); + }); + + it('should add the \'key\' with the corresponding \'value\' to the correct substate, in response to an ADD action', () => { + const state = testState; + + const action = new AddToIndexAction(IndexName.REQUEST, key2, val2); + const newState = indexReducer(state, action); + + expect(newState[IndexName.REQUEST][key2]).toEqual(val2); + }); + + it('should remove the given \'value\' from its corresponding \'key\' in the correct substate, in response to a REMOVE_BY_VALUE action', () => { + const state = testState; + + const action = new RemoveFromIndexByValueAction(IndexName.OBJECT, val1); + const newState = indexReducer(state, action); + + expect(newState[IndexName.OBJECT][key1]).toBeUndefined(); + }); +}); diff --git a/src/app/core/index/index.reducer.ts b/src/app/core/index/index.reducer.ts new file mode 100644 index 0000000000..869dee9e51 --- /dev/null +++ b/src/app/core/index/index.reducer.ts @@ -0,0 +1,62 @@ +import { + IndexAction, + IndexActionTypes, + AddToIndexAction, + RemoveFromIndexByValueAction +} from './index.actions'; + +export enum IndexName { + OBJECT = 'object/uuid-to-self-link', + REQUEST = 'get-request/href-to-uuid' +} + +export interface IndexState { + // TODO this should be `[name in IndexName]: {` but that's currently broken, + // see https://github.com/Microsoft/TypeScript/issues/13042 + [name: string]: { + [key: string]: string + } +} + +// Object.create(null) ensures the object has no default js properties (e.g. `__proto__`) +const initialState: IndexState = Object.create(null); + +export function indexReducer(state = initialState, action: IndexAction): IndexState { + switch (action.type) { + + case IndexActionTypes.ADD: { + return addToIndex(state, action as AddToIndexAction); + } + + case IndexActionTypes.REMOVE_BY_VALUE: { + return removeFromIndexByValue(state, action as RemoveFromIndexByValueAction) + } + + default: { + return state; + } + } +} + +function addToIndex(state: IndexState, action: AddToIndexAction): IndexState { + const subState = state[action.payload.name]; + const newSubState = Object.assign({}, subState, { + [action.payload.key]: action.payload.value + }); + return Object.assign({}, state, { + [action.payload.name]: newSubState + }) +} + +function removeFromIndexByValue(state: IndexState, action: RemoveFromIndexByValueAction): IndexState { + const subState = state[action.payload.name]; + const newSubState = Object.create(null); + for (const value in subState) { + if (subState[value] !== action.payload.value) { + newSubState[value] = subState[value]; + } + } + return Object.assign({}, state, { + [action.payload.name]: newSubState + }); +} diff --git a/src/app/core/index/uuid-index.actions.ts b/src/app/core/index/uuid-index.actions.ts deleted file mode 100644 index 0bea11204c..0000000000 --- a/src/app/core/index/uuid-index.actions.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { Action } from '@ngrx/store'; - -import { type } from '../../shared/ngrx/type'; - -/** - * The list of HrefIndexAction type definitions - */ -export const UUIDIndexActionTypes = { - ADD: type('dspace/core/index/uuid/ADD'), - REMOVE_HREF: type('dspace/core/index/uuid/REMOVE_HREF') -}; - -/* tslint:disable:max-classes-per-file */ -/** - * An ngrx action to add an href to the index - */ -export class AddToUUIDIndexAction implements Action { - type = UUIDIndexActionTypes.ADD; - payload: { - href: string; - uuid: string; - }; - - /** - * Create a new AddToUUIDIndexAction - * - * @param uuid - * the uuid to add - * @param href - * the self link of the resource the uuid belongs to - */ - constructor(uuid: string, href: string) { - this.payload = { href, uuid }; - } -} - -/** - * An ngrx action to remove an href from the index - */ -export class RemoveHrefFromUUIDIndexAction implements Action { - type = UUIDIndexActionTypes.REMOVE_HREF; - payload: string; - - /** - * Create a new RemoveHrefFromUUIDIndexAction - * - * @param href - * the href to remove the UUID for - */ - constructor(href: string) { - this.payload = href; - } - -} -/* tslint:enable:max-classes-per-file */ - -/** - * A type to encompass all HrefIndexActions - */ -export type UUIDIndexAction = AddToUUIDIndexAction | RemoveHrefFromUUIDIndexAction; diff --git a/src/app/core/index/uuid-index.effects.ts b/src/app/core/index/uuid-index.effects.ts deleted file mode 100644 index 2f5900ed04..0000000000 --- a/src/app/core/index/uuid-index.effects.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Effect, Actions } from '@ngrx/effects'; - -import { - ObjectCacheActionTypes, AddToObjectCacheAction, - RemoveFromObjectCacheAction -} from '../cache/object-cache.actions'; -import { AddToUUIDIndexAction, RemoveHrefFromUUIDIndexAction } from './uuid-index.actions'; -import { hasValue } from '../../shared/empty.util'; - -@Injectable() -export class UUIDIndexEffects { - - @Effect() add$ = this.actions$ - .ofType(ObjectCacheActionTypes.ADD) - .filter((action: AddToObjectCacheAction) => hasValue(action.payload.objectToCache.uuid)) - .map((action: AddToObjectCacheAction) => { - return new AddToUUIDIndexAction( - action.payload.objectToCache.uuid, - action.payload.objectToCache.self - ); - }); - - @Effect() remove$ = this.actions$ - .ofType(ObjectCacheActionTypes.REMOVE) - .map((action: RemoveFromObjectCacheAction) => { - return new RemoveHrefFromUUIDIndexAction(action.payload); - }); - - constructor(private actions$: Actions) { - - } - -} diff --git a/src/app/core/index/uuid-index.reducer.spec.ts b/src/app/core/index/uuid-index.reducer.spec.ts deleted file mode 100644 index e477d8df2e..0000000000 --- a/src/app/core/index/uuid-index.reducer.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import * as deepFreeze from 'deep-freeze'; - -import { uuidIndexReducer, UUIDIndexState } from './uuid-index.reducer'; -import { AddToUUIDIndexAction, RemoveHrefFromUUIDIndexAction } from './uuid-index.actions'; - -class NullAction extends AddToUUIDIndexAction { - type = null; - payload = null; - - constructor() { - super(null, null); - } -} - -describe('requestReducer', () => { - const link1 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/567a639f-f5ff-4126-807c-b7d0910808c8'; - const link2 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/1911e8a4-6939-490c-b58b-a5d70f8d91fb'; - const uuid1 = '567a639f-f5ff-4126-807c-b7d0910808c8'; - const uuid2 = '1911e8a4-6939-490c-b58b-a5d70f8d91fb'; - const testState: UUIDIndexState = { - [uuid1]: link1 - }; - deepFreeze(testState); - - it('should return the current state when no valid actions have been made', () => { - const action = new NullAction(); - const newState = uuidIndexReducer(testState, action); - - expect(newState).toEqual(testState); - }); - - it('should start with an empty state', () => { - const action = new NullAction(); - const initialState = uuidIndexReducer(undefined, action); - - expect(initialState).toEqual(Object.create(null)); - }); - - it('should add the \'uuid\' with the corresponding \'href\' to the state, in response to an ADD action', () => { - const state = testState; - - const action = new AddToUUIDIndexAction(uuid2, link2); - const newState = uuidIndexReducer(state, action); - - expect(newState[uuid2]).toEqual(link2); - }); - - it('should remove the given \'href\' from its corresponding \'uuid\' in the state, in response to a REMOVE_HREF action', () => { - const state = testState; - - const action = new RemoveHrefFromUUIDIndexAction(link1); - const newState = uuidIndexReducer(state, action); - - expect(newState[uuid1]).toBeUndefined(); - }); -}); diff --git a/src/app/core/index/uuid-index.reducer.ts b/src/app/core/index/uuid-index.reducer.ts deleted file mode 100644 index 191dd8f463..0000000000 --- a/src/app/core/index/uuid-index.reducer.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { - UUIDIndexAction, - UUIDIndexActionTypes, - AddToUUIDIndexAction, - RemoveHrefFromUUIDIndexAction -} from './uuid-index.actions'; - -export interface UUIDIndexState { - [uuid: string]: string -} - -// Object.create(null) ensures the object has no default js properties (e.g. `__proto__`) -const initialState: UUIDIndexState = Object.create(null); - -export function uuidIndexReducer(state = initialState, action: UUIDIndexAction): UUIDIndexState { - switch (action.type) { - - case UUIDIndexActionTypes.ADD: { - return addToUUIDIndex(state, action as AddToUUIDIndexAction); - } - - case UUIDIndexActionTypes.REMOVE_HREF: { - return removeHrefFromUUIDIndex(state, action as RemoveHrefFromUUIDIndexAction) - } - - default: { - return state; - } - } -} - -function addToUUIDIndex(state: UUIDIndexState, action: AddToUUIDIndexAction): UUIDIndexState { - return Object.assign({}, state, { - [action.payload.uuid]: action.payload.href - }); -} - -function removeHrefFromUUIDIndex(state: UUIDIndexState, action: RemoveHrefFromUUIDIndexAction): UUIDIndexState { - const newState = Object.create(null); - for (const uuid in state) { - if (state[uuid] !== action.payload) { - newState[uuid] = state[uuid]; - } - } - return newState; -} diff --git a/src/app/core/shared/hal-endpoint.service.spec.ts b/src/app/core/shared/hal-endpoint.service.spec.ts index f7adc1eccf..22d9a15fd7 100644 --- a/src/app/core/shared/hal-endpoint.service.spec.ts +++ b/src/app/core/shared/hal-endpoint.service.spec.ts @@ -1,5 +1,6 @@ import { cold, hot } from 'jasmine-marbles'; import { GlobalConfig } from '../../../config/global-config.interface'; +import { initMockRequestService } from '../../shared/mocks/mock-request.service'; import { ResponseCacheService } from '../cache/response-cache.service'; import { RootEndpointRequest } from '../data/request.models'; import { RequestService } from '../data/request.service'; @@ -38,7 +39,7 @@ describe('HALEndpointService', () => { }) }); - requestService = jasmine.createSpyObj('requestService', ['configure']); + requestService = initMockRequestService(); envConfig = { rest: { baseUrl: 'https://rest.api/' } @@ -53,7 +54,7 @@ describe('HALEndpointService', () => { it('should configure a new RootEndpointRequest', () => { (service as any).getEndpointMap(); - const expected = new RootEndpointRequest(envConfig); + const expected = new RootEndpointRequest(requestService.generateRequestId(), envConfig); expect(requestService.configure).toHaveBeenCalledWith(expected); }); diff --git a/src/app/core/shared/hal-endpoint.service.ts b/src/app/core/shared/hal-endpoint.service.ts index fa11fed308..84587f1eea 100644 --- a/src/app/core/shared/hal-endpoint.service.ts +++ b/src/app/core/shared/hal-endpoint.service.ts @@ -14,7 +14,7 @@ export abstract class HALEndpointService { protected abstract EnvConfig: GlobalConfig; protected getEndpointMap(): Observable { - const request = new RootEndpointRequest(this.EnvConfig); + const request = new RootEndpointRequest(this.requestService.generateRequestId(), this.EnvConfig); this.requestService.configure(request); return this.responseCache.get(request.href) .map((entry: ResponseCacheEntry) => entry.response) diff --git a/src/app/core/shared/selectors.ts b/src/app/core/shared/selectors.ts index 06f444b2e6..7bd35d39c1 100644 --- a/src/app/core/shared/selectors.ts +++ b/src/app/core/shared/selectors.ts @@ -1,13 +1,17 @@ import { createSelector, MemoizedSelector } from '@ngrx/store'; -import { coreSelector, CoreState } from '../core.reducers'; -import { hasValue } from '../../shared/empty.util'; +import { hasNoValue, isEmpty } from '../../shared/empty.util'; -export function keySelector(subState: string, key: string): MemoizedSelector { - return createSelector(coreSelector, (state: CoreState) => { - if (hasValue(state[subState])) { - return state[subState][key]; - } else { - return undefined; - } - }); +export function pathSelector(selector: MemoizedSelector, ...path: string[]): MemoizedSelector { + return createSelector(selector, (state: any) => getSubState(state, path)); +} + +function getSubState(state: any, path: string[]) { + const current = path[0]; + const remainingPath = path.slice(1); + const subState = state[current]; + if (hasNoValue(subState) || isEmpty(remainingPath)) { + return subState; + } else { + return getSubState(subState, remainingPath); + } } diff --git a/src/app/core/shared/uuid.service.ts b/src/app/core/shared/uuid.service.ts new file mode 100644 index 0000000000..6c02facbac --- /dev/null +++ b/src/app/core/shared/uuid.service.ts @@ -0,0 +1,9 @@ +import { Injectable } from '@angular/core'; +import * as uuidv4 from 'uuid/v4'; + +@Injectable() +export class UUIDService { + generate(): string { + return uuidv4(); + } +} diff --git a/src/app/shared/mocks/mock-request.service.ts b/src/app/shared/mocks/mock-request.service.ts new file mode 100644 index 0000000000..9ece96da3e --- /dev/null +++ b/src/app/shared/mocks/mock-request.service.ts @@ -0,0 +1,8 @@ +import { RequestService } from '../../core/data/request.service'; + +export function initMockRequestService(): RequestService { + return jasmine.createSpyObj('requestService', { + configure: () => false, + generateRequestId: () => 'clients/b186e8ce-e99c-4183-bc9a-42b4821bdb78' + }); +} diff --git a/yarn.lock b/yarn.lock index 91b2a787e2..6fc8d3ab0f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -225,6 +225,12 @@ version "0.5.1" resolved "https://registry.yarnpkg.com/@types/source-map/-/source-map-0.5.1.tgz#7e74db5d06ab373a712356eebfaea2fad0ea2367" +"@types/key@^3.4.3": + version "3.4.3" + resolved "https://registry.yarnpkg.com/@types/key/-/key-3.4.3.tgz#121ace265f5569ce40f4f6d0ff78a338c732a754" + dependencies: + "@types/node" "*" + "@types/webfontloader@1.6.29": version "1.6.29" resolved "https://registry.yarnpkg.com/@types/webfontloader/-/webfontloader-1.6.29.tgz#c6b5f6eb8ca31d0aae6b02b6c1300349dd93ea8e" @@ -1009,7 +1015,7 @@ cache-base@^1.0.1: dependencies: collection-visit "^1.0.0" component-emitter "^1.2.1" - get-value "^2.0.6" + getByUUID-value "^2.0.6" has-value "^1.0.0" isobject "^3.0.1" set-value "^2.0.0" @@ -1751,7 +1757,7 @@ dateformat@^1.0.11, dateformat@^1.0.6: version "1.0.12" resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-1.0.12.tgz#9f124b67594c937ff706932e4a642cca8dbbfee9" dependencies: - get-stdin "^4.0.1" + getByUUID-stdin "^4.0.1" meow "^3.3.0" debug@2, debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.6, debug@^2.6.8: @@ -2317,7 +2323,7 @@ execa@^0.7.0: resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777" dependencies: cross-spawn "^5.0.1" - get-stream "^3.0.0" + getByUUID-stream "^3.0.0" is-stream "^1.1.0" npm-run-path "^2.0.0" p-finally "^1.0.0" @@ -2731,25 +2737,25 @@ generate-object-property@^1.1.0: dependencies: is-property "^1.0.0" -get-caller-file@^1.0.1: +getByUUID-caller-file@^1.0.1: version "1.0.2" - resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5" + resolved "https://registry.yarnpkg.com/getByUUID-caller-file/-/getByUUID-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5" -get-stdin@^4.0.1: +getByUUID-stdin@^4.0.1: version "4.0.1" - resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" + resolved "https://registry.yarnpkg.com/getByUUID-stdin/-/getByUUID-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" -get-stdin@^5.0.1: +getByUUID-stdin@^5.0.1: version "5.0.1" - resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398" + resolved "https://registry.yarnpkg.com/getByUUID-stdin/-/getByUUID-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398" -get-stream@^3.0.0: +getByUUID-stream@^3.0.0: version "3.0.0" - resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" + resolved "https://registry.yarnpkg.com/getByUUID-stream/-/getByUUID-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" -get-value@^2.0.3, get-value@^2.0.6: +getByUUID-value@^2.0.3, getByUUID-value@^2.0.6: version "2.0.6" - resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" + resolved "https://registry.yarnpkg.com/getByUUID-value/-/getByUUID-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" getpass@^0.1.1: version "0.1.7" @@ -2842,7 +2848,7 @@ got@^6.7.1: dependencies: create-error-class "^3.0.0" duplexer3 "^0.1.4" - get-stream "^3.0.0" + getByUUID-stream "^3.0.0" is-redirect "^1.0.0" is-retry-allowed "^1.0.0" is-stream "^1.0.0" @@ -2974,7 +2980,7 @@ has-value@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/has-value/-/has-value-0.3.1.tgz#7b1f58bada62ca827ec0a2078025654845995e1f" dependencies: - get-value "^2.0.3" + getByUUID-value "^2.0.3" has-values "^0.1.4" isobject "^2.0.0" @@ -2982,7 +2988,7 @@ has-value@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/has-value/-/has-value-1.0.0.tgz#18b281da585b1c5c51def24c930ed29a0be6b177" dependencies: - get-value "^2.0.6" + getByUUID-value "^2.0.6" has-values "^1.0.0" isobject "^3.0.0" @@ -4652,7 +4658,7 @@ node-sass@4.5.3: chalk "^1.1.1" cross-spawn "^3.0.0" gaze "^1.0.0" - get-stdin "^4.0.1" + getByUUID-stdin "^4.0.1" glob "^7.0.3" in-publish "^2.0.0" lodash.assign "^4.2.0" @@ -5223,7 +5229,7 @@ postcss-cli@4.1.1: chokidar "^1.6.1" dependency-graph "^0.5.0" fs-extra "^4.0.1" - get-stdin "^5.0.1" + getByUUID-stdin "^5.0.1" globby "^6.1.0" ora "^1.1.0" postcss "^6.0.1" @@ -5802,7 +5808,7 @@ protractor-istanbul-plugin@2.0.0: fs-extra "^0.22.1" merge "^1.2.0" q "^1.4.1" - uuid "^2.0.1" + key "^2.0.1" protractor@5.1.2: version "5.1.2" @@ -6224,7 +6230,7 @@ request@2, request@^2.78.0, request@^2.79.0: stringstream "~0.0.5" tough-cookie "~2.3.3" tunnel-agent "^0.6.0" - uuid "^3.1.0" + key "^3.1.0" request@2.79.0: version "2.79.0" @@ -6249,7 +6255,7 @@ request@2.79.0: stringstream "~0.0.4" tough-cookie "~2.3.0" tunnel-agent "~0.4.1" - uuid "^3.0.0" + key "^3.0.0" request@2.81.0, request@~2.81.0: version "2.81.0" @@ -6276,7 +6282,7 @@ request@2.81.0, request@~2.81.0: stringstream "~0.0.4" tough-cookie "~2.3.0" tunnel-agent "^0.6.0" - uuid "^3.0.0" + key "^3.0.0" require-directory@^2.1.1: version "2.1.1" @@ -6783,7 +6789,7 @@ sockjs@0.3.18: resolved "https://registry.yarnpkg.com/sockjs/-/sockjs-0.3.18.tgz#d9b289316ca7df77595ef299e075f0f937eb4207" dependencies: faye-websocket "^0.10.0" - uuid "^2.0.2" + key "^2.0.2" sort-keys@^1.0.0: version "1.1.2" @@ -7056,7 +7062,7 @@ strip-indent@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2" dependencies: - get-stdin "^4.0.1" + getByUUID-stdin "^4.0.1" strip-json-comments@^2.0.0, strip-json-comments@~2.0.1: version "2.0.1" @@ -7459,7 +7465,7 @@ union-value@^1.0.0: resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4" dependencies: arr-union "^3.1.0" - get-value "^2.0.6" + getByUUID-value "^2.0.6" is-extendable "^0.1.1" set-value "^0.4.3" @@ -7604,13 +7610,13 @@ utils-merge@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" -uuid@^2.0.1, uuid@^2.0.2: +key@^2.0.1, key@^2.0.2: version "2.0.3" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" + resolved "https://registry.yarnpkg.com/key/-/key-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" -uuid@^3.0.0, uuid@^3.1.0: +key@^3.0.0, key@^3.1.0: version "3.1.0" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04" + resolved "https://registry.yarnpkg.com/key/-/key-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04" v8flags@^3.0.0: version "3.0.1" @@ -7999,7 +8005,7 @@ yargs@^6.6.0: camelcase "^3.0.0" cliui "^3.2.0" decamelize "^1.1.1" - get-caller-file "^1.0.1" + getByUUID-caller-file "^1.0.1" os-locale "^1.4.0" read-pkg-up "^1.0.1" require-directory "^2.1.1" @@ -8017,7 +8023,7 @@ yargs@^7.0.0: camelcase "^3.0.0" cliui "^3.2.0" decamelize "^1.1.1" - get-caller-file "^1.0.1" + getByUUID-caller-file "^1.0.1" os-locale "^1.4.0" read-pkg-up "^1.0.1" require-directory "^2.1.1" @@ -8035,7 +8041,7 @@ yargs@^8.0.1, yargs@^8.0.2: camelcase "^4.1.0" cliui "^3.2.0" decamelize "^1.1.1" - get-caller-file "^1.0.1" + getByUUID-caller-file "^1.0.1" os-locale "^2.0.0" read-pkg-up "^2.0.0" require-directory "^2.1.1" From 4a56bd0f1483a002c6b0c48dedca8b6f4b0efa11 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Tue, 19 Dec 2017 10:41:35 +0100 Subject: [PATCH 63/77] #150 Feedback fixes --- src/app/+search-page/search-page.component.ts | 11 +++- .../object-grid/object-grid.component.html | 4 +- .../object-grid/object-grid.component.ts | 56 +++++++++---------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/app/+search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts index 101eb68e8f..5ed649e4cc 100644 --- a/src/app/+search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -77,10 +77,15 @@ export class SearchPageComponent implements OnInit, OnDestroy { let pageSizeOptions: number[] = [5, 10, 20, 40, 60, 80, 100]; if (isNotEmpty(params.view) && params.view === ViewMode.Grid) { - pageSize = 12; pageSizeOptions = [12, 24, 36, 48 , 50, 62, 74, 84]; - // pageSize = 9; - // pageSizeOptions = [9, 18, 27, 36 , 45, 54, 63, 72]; + if (pageSizeOptions.indexOf(pageSize) === -1) { + pageSize = 12; + } + } + if (isNotEmpty(params.view) && params.view === ViewMode.List) { + if (pageSizeOptions.indexOf(pageSize) === -1) { + pageSize = 10; + } } const sortDirection = +params.sortDirection || this.searchOptions.sort.direction; diff --git a/src/app/shared/object-grid/object-grid.component.html b/src/app/shared/object-grid/object-grid.component.html index ad9bf20a32..64231bc931 100644 --- a/src/app/shared/object-grid/object-grid.component.html +++ b/src/app/shared/object-grid/object-grid.component.html @@ -1,14 +1,14 @@
        ; @Input() config: PaginationComponentOptions; @Input() sortConfig: SortOptions; @Input() hideGear = false; @Input() hidePagerWhenSinglePage = true; - pageInfo: Observable; + private _objects: RemoteData; + pageInfo: PageInfo; + @Input() set objects(objects: RemoteData) { + this._objects = objects; + if (hasValue(objects)) { + this.pageInfo = objects.pageInfo; + } + } + get objects() { + return this._objects; + } + + /** + * An event fired when the page is changed. + * Event's payload equals to the newly selected page. + */ + @Output() change: EventEmitter<{ + pagination: PaginationComponentOptions, + sort: SortOptions + }> = new EventEmitter<{ + pagination: PaginationComponentOptions, + sort: SortOptions + }>(); /** * An event fired when the page is changed. @@ -61,26 +81,6 @@ export class ObjectGridComponent implements OnChanges, OnInit { */ @Output() sortFieldChange: EventEmitter = new EventEmitter(); data: any = {}; - - ngOnChanges(changes: SimpleChanges) { - if (changes.objects && !changes.objects.isFirstChange()) { - // this.pageInfo = this.objects.pageInfo; - } - } - - ngOnInit(): void { - // this.pageInfo = this.objects.pageInfo; - } - - /** - * @param route - * Route is a singleton service provided by Angular. - * @param router - * Router is a singleton service provided by Angular. - */ - constructor(private cdRef: ChangeDetectorRef) { - } - onPageChange(event) { this.pageChange.emit(event); } From 7a7d27c6809275942e7fca2a17f3b05117178402 Mon Sep 17 00:00:00 2001 From: courtneypattison Date: Tue, 19 Dec 2017 13:50:12 -0800 Subject: [PATCH 64/77] Replaced Http with HttpClient --- src/app/app.module.ts | 4 +- .../dspace-rest-v2.service.spec.ts | 37 +++++++++++++++++++ .../dspace-rest-v2/dspace-rest-v2.service.ts | 16 ++++---- src/app/shared/api.service.ts | 6 +-- 4 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 src/app/core/dspace-rest-v2/dspace-rest-v2.service.spec.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ef1e098f02..c2728941d0 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core'; import { CommonModule, APP_BASE_HREF } from '@angular/common'; -import { HttpModule } from '@angular/http'; +import { HttpClientModule } from '@angular/common/http'; import { EffectsModule } from '@ngrx/effects'; import { StoreModule, MetaReducer, META_REDUCERS } from '@ngrx/store'; @@ -51,7 +51,7 @@ if (!ENV_CONFIG.production) { @NgModule({ imports: [ CommonModule, - HttpModule, + HttpClientModule, AppRoutingModule, CoreModule.forRoot(), NgbModule.forRoot(), diff --git a/src/app/core/dspace-rest-v2/dspace-rest-v2.service.spec.ts b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.spec.ts new file mode 100644 index 0000000000..b45b7ae526 --- /dev/null +++ b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.spec.ts @@ -0,0 +1,37 @@ +import { TestBed, inject } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { DSpaceRESTv2Service } from './dspace-rest-v2.service'; + +describe('DSpaceRESTv2Service', () => { + let dSpaceRESTv2Service: DSpaceRESTv2Service; + let httpMock: HttpTestingController; + const mockDSpaceRESTV2Response = {}; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [DSpaceRESTv2Service] + }); + + dSpaceRESTv2Service = TestBed.get(DSpaceRESTv2Service); + httpMock = TestBed.get(HttpTestingController); + }); + + it('should be created', inject([DSpaceRESTv2Service], (service: DSpaceRESTv2Service) => { + expect(service).toBeTruthy(); + })); + + describe('#get', () => { + it('should return an Observable', () => { + const url = 'http://www.dspace.org/'; + dSpaceRESTv2Service.get(url).subscribe((response) => { + expect(response).toBeTruthy(); + }); + + const req = httpMock.expectOne(url); + expect(req.request.method).toBe('GET'); + req.flush(mockDSpaceRESTV2Response); + }); + }); +}); diff --git a/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts index 6464268201..1c719a6831 100644 --- a/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts +++ b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts @@ -1,8 +1,7 @@ -import { Inject, Injectable } from '@angular/core'; -import { Http, RequestOptionsArgs } from '@angular/http'; +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; -import { RESTURLCombiner } from '../url-combiner/rest-url-combiner'; import { DSpaceRESTV2Response } from './dspace-rest-v2-response.model'; import { GLOBAL_CONFIG, GlobalConfig } from '../../../config'; @@ -13,7 +12,7 @@ import { GLOBAL_CONFIG, GlobalConfig } from '../../../config'; @Injectable() export class DSpaceRESTv2Service { - constructor(private http: Http, @Inject(GLOBAL_CONFIG) private EnvConfig: GlobalConfig) { + constructor(private http: HttpClient) { } @@ -23,13 +22,12 @@ export class DSpaceRESTv2Service { * @param absoluteURL * A URL * @param options - * A RequestOptionsArgs object, with options for the http call. - * @return {Observable} - * An Observable containing the response from the server + * An object, with options for the http call. + * @return {Observable} + * An Observable containing the response from the server */ - get(absoluteURL: string, options?: RequestOptionsArgs): Observable { + get(absoluteURL: string, options?: {}): Observable { return this.http.get(absoluteURL, options) - .map((res) => ({ payload: res.json(), statusCode: res.statusText })) .catch((err) => { console.log('Error: ', err); return Observable.throw(err); diff --git a/src/app/shared/api.service.ts b/src/app/shared/api.service.ts index 64a1b538c8..90c79d132e 100644 --- a/src/app/shared/api.service.ts +++ b/src/app/shared/api.service.ts @@ -1,14 +1,13 @@ import 'rxjs/add/observable/throw'; -import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import { Injectable } from '@angular/core'; -import { Http } from '@angular/http'; +import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; @Injectable() export class ApiService { - constructor(public _http: Http) { + constructor(public _http: HttpClient) { } @@ -17,7 +16,6 @@ export class ApiService { */ get(url: string, options?: any) { return this._http.get(url, options) - .map((res) => res.json()) .catch((err) => { console.log('Error: ', err); return Observable.throw(err); From df3179018321d6d79c120ad57b3e7fbb1d45dfcb Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Wed, 20 Dec 2017 16:10:39 +0100 Subject: [PATCH 65/77] #150 Remove incorrectly referencing searchOptions --- src/app/+search-page/search-service/search.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 52d86927d6..8c903f261d 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -100,7 +100,7 @@ export class SearchService implements OnDestroy { } search(query: string, scopeId?: string, searchOptions?: SearchOptions): Observable>>> { - this.searchOptions = this.searchOptions; + this.searchOptions = searchOptions; let self = `https://dspace7.4science.it/dspace-spring-rest/api/search?query=${query}`; if (hasValue(scopeId)) { self += `&scope=${scopeId}`; @@ -124,7 +124,7 @@ export class SearchService implements OnDestroy { if (isNotEmpty(searchOptions)) { returningPageInfo.elementsPerPage = searchOptions.pagination.pageSize; - returningPageInfo.currentPage = searchOptions.pagination.currentPage; + returningPageInfo.currentPage = searchOptions.pagination.currentPage; } else { returningPageInfo.elementsPerPage = 10; returningPageInfo.currentPage = 1; From 0e4c93bd491d727e6dd6b1203c2ec8d69445156c Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Wed, 20 Dec 2017 16:19:22 +0100 Subject: [PATCH 66/77] #150 Separate pageSizeOptions for list and grid --- .../search-settings/search-settings.component.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 7b8bb8eb6e..ad6aeb21dd 100644 --- a/src/app/+search-page/search-settings/search-settings.component.ts +++ b/src/app/+search-page/search-settings/search-settings.component.ts @@ -1,6 +1,6 @@ import { Component, Input, OnInit } from '@angular/core'; import { SearchService } from '../search-service/search.service'; -import { SearchOptions } from '../search-options.model'; +import { SearchOptions, ViewMode } from '../search-options.model'; import { SortDirection } from '../../core/cache/models/sort-options.model'; import { ActivatedRoute, NavigationExtras, Router } from '@angular/router'; @@ -20,6 +20,9 @@ export class SearchSettingsComponent implements OnInit { * Number of items per page. */ public pageSize; + @Input() public pageSizeOptions; + public listPageSizeOptions: number[] = [5, 10, 20, 40, 60, 80, 100]; + public gridPageSizeOptions: number[] = [12, 24, 36, 48 , 50, 62, 74, 84]; private sub; private scope: string; @@ -36,6 +39,7 @@ export class SearchSettingsComponent implements OnInit { ngOnInit(): void { this.searchOptions = this.service.searchOptions; this.pageSize = this.searchOptions.pagination.pageSize; + this.pageSizeOptions = this.searchOptions.pagination.pageSizeOptions; this.sub = this.route .queryParams .subscribe((params) => { @@ -45,6 +49,11 @@ export class SearchSettingsComponent implements OnInit { this.page = +params.page || this.searchOptions.pagination.currentPage; this.pageSize = +params.pageSize || this.searchOptions.pagination.pageSize; this.direction = +params.sortDirection || this.searchOptions.sort.direction; + if (params.view === ViewMode.Grid) { + this.pageSizeOptions = this.gridPageSizeOptions; + } else { + this.pageSizeOptions = this.listPageSizeOptions; + } }); } From c89e34386b80c440f08e67d932b1dae0e7582492 Mon Sep 17 00:00:00 2001 From: Jonas Van Goolen Date: Thu, 21 Dec 2017 08:53:49 +0100 Subject: [PATCH 67/77] #150 Get component's pageSizeOptions --- .../+search-page/search-settings/search-settings.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d5a4d412ff..4ee0812602 100644 --- a/src/app/+search-page/search-settings/search-settings.component.html +++ b/src/app/+search-page/search-settings/search-settings.component.html @@ -14,7 +14,7 @@
        {{ 'search.sidebar.settings.rpp' | translate}}