- {{community.shortDescription}}
+
+ {{object.shortDescription}}
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 634e573e92..c05915e8d7 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
@@ -1,16 +1,14 @@
-import { Component, Input } from '@angular/core';
+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';
@Component({
selector: 'ds-community-list-element',
styleUrls: ['./community-list-element.component.scss'],
templateUrl: './community-list-element.component.html'
})
-export class CommunityListElementComponent {
- @Input() community: Community;
-
- data: any = {};
-
-}
+@listElementFor(Community)
+export class CommunityListElementComponent extends ObjectListElementComponent
{}
diff --git a/src/app/object-list/item-list-element/item-list-element.component.html b/src/app/object-list/item-list-element/item-list-element.component.html
index 517cae480f..cc24ba76b8 100644
--- a/src/app/object-list/item-list-element/item-list-element.component.html
+++ b/src/app/object-list/item-list-element/item-list-element.component.html
@@ -1,14 +1,14 @@
-
- {{item.findMetadata("dc.title")}}
+
+ {{object.findMetadata("dc.title")}}
-
- {{authorMd.value}}
+
+ {{authorMd.value}}
;
- ({{item.findMetadata("dc.publisher")}}, {{item.findMetadata("dc.date.issued")}})
+ ({{object.findMetadata("dc.publisher")}}, {{object.findMetadata("dc.date.issued")}})
- {{item.findMetadata("dc.description.abstract") | dsTruncate:[200] }}
+ {{object.findMetadata("dc.description.abstract") | dsTruncate:[200] }}
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 880f3d9fdc..cc6c837bb7 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
@@ -1,15 +1,14 @@
-import { Component, Input } from '@angular/core';
+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';
@Component({
selector: 'ds-item-list-element',
styleUrls: ['./item-list-element.component.scss'],
templateUrl: './item-list-element.component.html'
})
-export class ItemListElementComponent {
- @Input() item: Item;
- data: any = {};
-
-}
+@listElementFor(Item)
+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
new file mode 100644
index 0000000000..64a747d4a5
--- /dev/null
+++ b/src/app/object-list/list-element-decorator.ts
@@ -0,0 +1,16 @@
+import { ListableObject } from './listable-object/listable-object.model';
+import { GenericConstructor } from '../core/shared/generic-constructor';
+
+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/listable-object/listable-object.model.ts b/src/app/object-list/listable-object/listable-object.model.ts
new file mode 100644
index 0000000000..07c626cda2
--- /dev/null
+++ b/src/app/object-list/listable-object/listable-object.model.ts
@@ -0,0 +1 @@
+export interface ListableObject {}
diff --git a/src/app/object-list/object-list-element/object-list-element.component.html b/src/app/object-list/object-list-element/object-list-element.component.html
index 5feb69b3a6..e69de29bb2 100644
--- a/src/app/object-list/object-list-element/object-list-element.component.html
+++ b/src/app/object-list/object-list-element/object-list-element.component.html
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/app/object-list/object-list-element/object-list-element.component.scss b/src/app/object-list/object-list-element/object-list-element.component.scss
index 6bdc45f30f..1a22768fe8 100644
--- a/src/app/object-list/object-list-element/object-list-element.component.scss
+++ b/src/app/object-list/object-list-element/object-list-element.component.scss
@@ -1,7 +1,6 @@
@import '../../../styles/variables.scss';
-@import '../../../../node_modules/bootstrap/scss/variables';
:host {
display: block;
- margin-bottom: $spacer-y;
+ margin-bottom: $spacer;
}
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 4b5f56e1e1..df39a7d18d 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,18 +1,14 @@
-import { Component, Input, OnInit } from '@angular/core';
-import { DSpaceObject } from '../../core/shared/dspace-object.model';
-import { ResourceType } from '../../core/shared/resource-type';
+import { Component, Inject } from '@angular/core';
+import { ListableObject } from '../listable-object/listable-object.model';
@Component({
selector: 'ds-object-list-element',
styleUrls: ['./object-list-element.component.scss'],
templateUrl: './object-list-element.component.html'
})
-export class ObjectListElementComponent {
-
- public type = ResourceType;
-
- @Input() object: DSpaceObject;
-
- data: any = {};
-
+export class ObjectListElementComponent {
+ object: T;
+ public constructor(@Inject('objectElementProvider') public listable: ListableObject) {
+ this.object = listable as T;
+ }
}
diff --git a/src/app/object-list/object-list.component.html b/src/app/object-list/object-list.component.html
index da25195e27..0765e00476 100644
--- a/src/app/object-list/object-list.component.html
+++ b/src/app/object-list/object-list.component.html
@@ -7,10 +7,11 @@
(pageChange)="onPageChange($event)"
(pageSizeChange)="onPageSizeChange($event)"
(sortDirectionChange)="onSortDirectionChange($event)"
- (sortFieldChange)="onSortDirectionChange($event)">
+ (sortFieldChange)="onSortDirectionChange($event)"
+ (paginationChange)="onPaginationChange($event)">
diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html
new file mode 100644
index 0000000000..914fb49487
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html
@@ -0,0 +1,2 @@
+
+
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
new file mode 100644
index 0000000000..88eb98509a
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.scss
@@ -0,0 +1 @@
+@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.ts b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts
new file mode 100644
index 0000000000..9bea14e9a1
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts
@@ -0,0 +1,15 @@
+import { Component } from '@angular/core';
+
+import { listElementFor } from '../../list-element-decorator';
+import { CollectionSearchResult } from './collection-search-result.model';
+import { SearchResultListElementComponent } from '../search-result-list-element.component';
+import { Collection } from '../../../core/shared/collection.model';
+
+@Component({
+ selector: 'ds-collection-search-result-list-element',
+ styleUrls: ['../search-result-list-element.component.scss', 'collection-search-result-list-element.component.scss'],
+ templateUrl: 'collection-search-result-list-element.component.html'
+})
+
+@listElementFor(CollectionSearchResult)
+export class CollectionSearchResultListElementComponent extends SearchResultListElementComponent {}
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
new file mode 100644
index 0000000000..081111e96c
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts
@@ -0,0 +1,5 @@
+import { SearchResult } from '../../../search/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/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html
new file mode 100644
index 0000000000..d09ef7d668
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.html
@@ -0,0 +1,2 @@
+
+
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
new file mode 100644
index 0000000000..88eb98509a
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.scss
@@ -0,0 +1 @@
+@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-list-element.component.ts b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts
new file mode 100644
index 0000000000..741b4b4f65
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/community-search-result/community-search-result-list-element.component.ts
@@ -0,0 +1,17 @@
+import { Component } from '@angular/core';
+
+import { listElementFor } from '../../list-element-decorator';
+import { CommunitySearchResult } from './community-search-result.model';
+import { SearchResultListElementComponent } from '../search-result-list-element.component';
+import { Community } from '../../../core/shared/community.model';
+
+@Component({
+ selector: 'ds-community-search-result-list-element',
+ styleUrls: ['../search-result-list-element.component.scss', 'community-search-result-list-element.component.scss'],
+ templateUrl: 'community-search-result-list-element.component.html'
+})
+
+@listElementFor(CommunitySearchResult)
+export class CommunitySearchResultListElementComponent extends SearchResultListElementComponent {
+
+}
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
new file mode 100644
index 0000000000..522b41700e
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts
@@ -0,0 +1,5 @@
+import { SearchResult } from '../../../search/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/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html
new file mode 100644
index 0000000000..27b40eeeeb
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.html
@@ -0,0 +1,12 @@
+
+
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
new file mode 100644
index 0000000000..88eb98509a
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.scss
@@ -0,0 +1 @@
+@import '../../../../styles/variables.scss';
\ No newline at end of file
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
new file mode 100644
index 0000000000..ef968db0b8
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.ts
@@ -0,0 +1,15 @@
+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';
+
+@Component({
+ selector: 'ds-item-search-result-list-element',
+ styleUrls: ['../search-result-list-element.component.scss', 'item-search-result-list-element.component.scss'],
+ templateUrl: 'item-search-result-list-element.component.html'
+})
+
+@listElementFor(ItemSearchResult)
+export class ItemSearchResultListElementComponent extends SearchResultListElementComponent {}
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
new file mode 100644
index 0000000000..dc5d282c25
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts
@@ -0,0 +1,5 @@
+import { SearchResult } from '../../../search/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.scss b/src/app/object-list/search-result-list-element/search-result-list-element.component.scss
new file mode 100644
index 0000000000..d688753eb3
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/search-result-list-element.component.scss
@@ -0,0 +1,7 @@
+@import '../../../styles/variables.scss';
+:host {
+ /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/object-list/search-result-list-element/search-result-list-element.component.ts
new file mode 100644
index 0000000000..3a2bf51c97
--- /dev/null
+++ b/src/app/object-list/search-result-list-element/search-result-list-element.component.ts
@@ -0,0 +1,57 @@
+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/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';
+
+@Component({
+ selector: 'ds-search-result-list-element',
+ template: ``
+})
+
+export class SearchResultListElementComponent, K extends DSpaceObject> extends ObjectListElementComponent {
+ dso: K;
+
+ public constructor(@Inject('objectElementProvider') public listable: ListableObject) {
+ super(listable);
+ 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-list/wrapper-list-element/wrapper-list-element.component.html b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.html
new file mode 100644
index 0000000000..d5cfebdfa5
--- /dev/null
+++ b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.html
@@ -0,0 +1 @@
+
\ 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
new file mode 100644
index 0000000000..6f997644cc
--- /dev/null
+++ b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.scss
@@ -0,0 +1,2 @@
+@import '../../../styles/variables.scss';
+
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
new file mode 100644
index 0000000000..443b9681d1
--- /dev/null
+++ b/src/app/object-list/wrapper-list-element/wrapper-list-element.component.ts
@@ -0,0 +1,27 @@
+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';
+
+@Component({
+ selector: 'ds-wrapper-list-element',
+ styleUrls: ['./wrapper-list-element.component.scss'],
+ templateUrl: './wrapper-list-element.component.html'
+})
+export class WrapperListElementComponent implements OnInit {
+ @Input() object: ListableObject;
+ objectInjector: Injector;
+
+ constructor(private injector: Injector) {}
+
+ 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);
+ }
+}
diff --git a/src/app/search-page/search-page-routing.module.ts b/src/app/search-page/search-page-routing.module.ts
new file mode 100644
index 0000000000..76b7d9ad0c
--- /dev/null
+++ b/src/app/search-page/search-page-routing.module.ts
@@ -0,0 +1,13 @@
+import { NgModule } from '@angular/core';
+import { RouterModule } from '@angular/router';
+
+import { SearchPageComponent } from './search-page.component';
+
+@NgModule({
+ imports: [
+ RouterModule.forChild([
+ { path: 'search', component: SearchPageComponent }
+ ])
+ ]
+})
+export class SearchPageRoutingModule { }
diff --git a/src/app/search-page/search-page.component.html b/src/app/search-page/search-page.component.html
new file mode 100644
index 0000000000..a8747a6cf9
--- /dev/null
+++ b/src/app/search-page/search-page.component.html
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/src/app/search-page/search-page.component.scss b/src/app/search-page/search-page.component.scss
new file mode 100644
index 0000000000..da97dd7a62
--- /dev/null
+++ b/src/app/search-page/search-page.component.scss
@@ -0,0 +1 @@
+@import '../../styles/variables.scss';
diff --git a/src/app/search-page/search-page.component.ts b/src/app/search-page/search-page.component.ts
new file mode 100644
index 0000000000..a35f6f01a3
--- /dev/null
+++ b/src/app/search-page/search-page.component.ts
@@ -0,0 +1,89 @@
+import { Component, OnInit, OnDestroy } from '@angular/core';
+import { SearchService } from '../search/search.service';
+import { ActivatedRoute, Router } from '@angular/router';
+import { RemoteData } from '../core/data/remote-data';
+import { SearchResult } from '../search/search-result.model';
+import { DSpaceObject } from '../core/shared/dspace-object.model';
+import { SortOptions } from '../core/cache/models/sort-options.model';
+import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
+import { SearchOptions } from '../search/search-options.model';
+import { CommunityDataService } from '../core/data/community-data.service';
+import { isNotEmpty } from '../shared/empty.util';
+import { Community } from '../core/shared/community.model';
+
+/**
+ * This component renders a simple item page.
+ * The route parameter 'id' is used to request the item it represents.
+ * All fields of the item that should be displayed, are defined in its template.
+ */
+
+@Component({
+ selector: 'ds-search-page',
+ styleUrls: ['./search-page.component.scss'],
+ templateUrl: './search-page.component.html',
+})
+export class SearchPageComponent implements OnInit, OnDestroy {
+ private sub;
+ query: string;
+ private scope: string;
+ scopeObject: RemoteData;
+ results: RemoteData>>;
+ currentParams = {};
+ searchOptions: SearchOptions;
+ scopeList: RemoteData;
+
+ constructor(private service: SearchService,
+ private route: ActivatedRoute,
+ private communityService: CommunityDataService,) {
+ this.scopeList = communityService.findAll();
+ // Initial pagination config
+ const pagination: PaginationComponentOptions = new PaginationComponentOptions();
+ pagination.id = 'search-results-pagination';
+ pagination.currentPage = 1;
+ pagination.pageSize = 10;
+ const sort: SortOptions = new SortOptions();
+ this.searchOptions = { pagination: pagination, sort: sort };
+ }
+
+ ngOnInit(): void {
+ this.sub = this.route
+ .queryParams
+ .subscribe((params) => {
+ // Save current parameters
+ this.currentParams = params;
+ this.query = params.query || '';
+ 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,
+ { currentPage: page, pageSize: pageSize }
+ );
+ const sort = Object.assign({},
+ this.searchOptions.sort,
+ { direction: sortDirection, field: params.sortField }
+ );
+ this.updateSearchResults({
+ pagination: pagination,
+ sort: sort
+ });
+ if (isNotEmpty(this.scope)) {
+ this.scopeObject = this.communityService.findById(this.scope);
+ } else {
+ this.scopeObject = undefined;
+ }
+ }
+ );
+ }
+
+ private updateSearchResults(searchOptions) {
+ // Resolve search results
+ this.results = this.service.search(this.query, this.scope, searchOptions);
+
+ }
+
+ ngOnDestroy() {
+ this.sub.unsubscribe();
+ }
+}
diff --git a/src/app/search-page/search-page.module.ts b/src/app/search-page/search-page.module.ts
new file mode 100644
index 0000000000..67a88f579c
--- /dev/null
+++ b/src/app/search-page/search-page.module.ts
@@ -0,0 +1,38 @@
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { RouterModule } from '@angular/router';
+
+import { TranslateModule } from '@ngx-translate/core';
+
+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.compontent';
+import { SearchModule } from '../search/search.module';
+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';
+
+@NgModule({
+ imports: [
+ SearchPageRoutingModule,
+ CommonModule,
+ TranslateModule,
+ RouterModule,
+ SharedModule,
+ SearchModule
+ ],
+ declarations: [
+ SearchPageComponent,
+ SearchResultsComponent,
+ ItemSearchResultListElementComponent,
+ CollectionSearchResultListElementComponent,
+ CommunitySearchResultListElementComponent
+ ],
+ entryComponents: [
+ ItemSearchResultListElementComponent,
+ CollectionSearchResultListElementComponent,
+ CommunitySearchResultListElementComponent
+ ]
+})
+export class SearchPageModule { }
diff --git a/src/app/search-page/search-results/search-results.component.html b/src/app/search-page/search-results/search-results.component.html
new file mode 100644
index 0000000000..7d769dbeb0
--- /dev/null
+++ b/src/app/search-page/search-results/search-results.component.html
@@ -0,0 +1,3 @@
+ 0">{{ 'search.results.title' | translate }}
+
\ No newline at end of file
diff --git a/src/app/search-page/search-results/search-results.compontent.ts b/src/app/search-page/search-results/search-results.compontent.ts
new file mode 100644
index 0000000000..505a3eeae4
--- /dev/null
+++ b/src/app/search-page/search-results/search-results.compontent.ts
@@ -0,0 +1,21 @@
+import { Component, Input } from '@angular/core';
+import { RemoteData } from '../../core/data/remote-data';
+import { SearchResult } from '../../search/search-result.model';
+import { DSpaceObject } from '../../core/shared/dspace-object.model';
+import { SearchOptions } from '../../search/search-options.model';
+
+/**
+ * This component renders a simple item page.
+ * The route parameter 'id' is used to request the item it represents.
+ * All fields of the item that should be displayed, are defined in its template.
+ */
+
+@Component({
+ selector: 'ds-search-results',
+ templateUrl: './search-results.component.html',
+})
+
+export class SearchResultsComponent {
+ @Input() searchResults: RemoteData>>;
+ @Input() searchConfig: SearchOptions;
+}
diff --git a/src/app/search/search-options.model.ts b/src/app/search/search-options.model.ts
new file mode 100644
index 0000000000..fd4a5accf6
--- /dev/null
+++ b/src/app/search/search-options.model.ts
@@ -0,0 +1,7 @@
+import { SortOptions } from '../core/cache/models/sort-options.model';
+import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
+
+export class SearchOptions {
+ pagination?: PaginationComponentOptions;
+ sort?: SortOptions;
+}
diff --git a/src/app/search/search-result.model.ts b/src/app/search/search-result.model.ts
index a6022c1661..2dd9130ee8 100644
--- a/src/app/search/search-result.model.ts
+++ b/src/app/search/search-result.model.ts
@@ -1,7 +1,8 @@
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';
-export class SearchResult {
+export class SearchResult implements ListableObject {
dspaceObject: T;
hitHighlights: Metadatum[];
diff --git a/src/app/search/search.models.ts b/src/app/search/search.models.ts
deleted file mode 100644
index 4ce3b2e39d..0000000000
--- a/src/app/search/search.models.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { SortOptions } from '../core/cache/models/sort-options.model';
-
-export class SearchOptions {
- elementsPerPage?: number;
- currentPage?: number;
- sort?: SortOptions;
-}
diff --git a/src/app/search/search.service.ts b/src/app/search/search.service.ts
index 3c127946cb..87cfdafd4b 100644
--- a/src/app/search/search.service.ts
+++ b/src/app/search/search.service.ts
@@ -5,10 +5,25 @@ import { SearchResult } from './search-result.model';
import { ItemDataService } from '../core/data/item-data.service';
import { PageInfo } from '../core/shared/page-info.model';
import { DSpaceObject } from '../core/shared/dspace-object.model';
-import { SearchOptions } from './search.models';
+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';
+
+function shuffle(array: any[]) {
+ let i = 0;
+ let j = 0;
+ let temp = null;
+
+ for (i = array.length - 1; i > 0; i -= 1) {
+ j = Math.floor(Math.random() * (i + 1));
+ temp = array[i];
+ array[i] = array[j];
+ array[j] = temp;
+ }
+ return array;
+}
@Injectable()
export class SearchService {
@@ -36,39 +51,47 @@ export class SearchService {
if (hasValue(scopeId)) {
self += `&scope=${scopeId}`;
}
- if (isNotEmpty(searchOptions) && hasValue(searchOptions.currentPage)) {
- self += `&page=${searchOptions.currentPage}`;
+ 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 requestPending = Observable.of(false);
const responsePending = Observable.of(false);
- const isSuccessFul = Observable.of(true);
const errorMessage = Observable.of(undefined);
const statusCode = Observable.of('200');
const returningPageInfo = new PageInfo();
if (isNotEmpty(searchOptions)) {
- returningPageInfo.elementsPerPage = searchOptions.elementsPerPage;
- returningPageInfo.currentPage = searchOptions.currentPage;
+ returningPageInfo.elementsPerPage = searchOptions.pagination.pageSize;
+ returningPageInfo.currentPage = searchOptions.pagination.currentPage;
} else {
returningPageInfo.elementsPerPage = 10;
returningPageInfo.currentPage = 1;
}
- returningPageInfo.totalPages = this.totalPages;
- returningPageInfo.totalElements = 10 * this.totalPages;
- const pageInfo = Observable.of(returningPageInfo);
const itemsRD = this.itemDataService.findAll({
- scopeID: '8e0928a0-047a-4369-8883-12669f32dd64',
+ scopeID: scopeId,
currentPage: returningPageInfo.currentPage,
elementsPerPage: returningPageInfo.elementsPerPage
});
+
+ const pageInfo = itemsRD.pageInfo.map((info: PageInfo) => {
+ info.totalElements = info.totalElements > 20 ? 20 : info.totalElements;
+ return info;
+ });
+
const payload = itemsRD.payload.map((items: Item[]) => {
- return items.sort(() => {
- const values = [-1, 0, 1];
- return values[Math.floor(Math.random() * values.length)];
- })
+ return shuffle(items)
.map((item: Item, index: number) => {
- const mockResult: SearchResult = new SearchResult();
+ const mockResult: SearchResult = new ItemSearchResult();
mockResult.dspaceObject = item;
const highlight = new Metadatum();
highlight.key = 'dc.description.abstract';
@@ -82,7 +105,7 @@ export class SearchService {
self,
requestPending,
responsePending,
- isSuccessFul,
+ itemsRD.hasSucceeded,
errorMessage,
statusCode,
pageInfo,
diff --git a/src/app/shared/empty.util.spec.ts b/src/app/shared/empty.util.spec.ts
index 7761bccf8c..509f55f7f8 100644
--- a/src/app/shared/empty.util.spec.ts
+++ b/src/app/shared/empty.util.spec.ts
@@ -317,7 +317,7 @@ describe('Empty Utils', () => {
});
it('should return false for an empty Object', () => {
- expect(isEmpty({})).toBe(false);
+ expect(isEmpty({})).toBe(true);
});
it('should return true for an Object that has zero \'length\'', () => {
@@ -377,7 +377,7 @@ describe('Empty Utils', () => {
});
it('should return true for an empty Object', () => {
- expect(isNotEmpty({})).toBe(true);
+ expect(isNotEmpty({})).toBe(false);
});
it('should return false for an Object that has zero length', () => {
diff --git a/src/app/shared/empty.util.ts b/src/app/shared/empty.util.ts
index 6346e7d042..1dc3f71871 100644
--- a/src/app/shared/empty.util.ts
+++ b/src/app/shared/empty.util.ts
@@ -90,7 +90,7 @@ export function hasValue(obj?: any): boolean {
* isEmpty(undefined); // true
* isEmpty(''); // true
* isEmpty([]); // true
- * isEmpty({}); // false
+ * isEmpty({}); // true
* isEmpty('Adam Hawkins'); // false
* isEmpty([0,1,2]); // false
* isEmpty('\n\t'); // false
@@ -119,6 +119,9 @@ export function isEmpty(obj?: any): boolean {
}
if (objectType === 'object') {
+ if (Object.keys(obj).length === 0) {
+ return true;
+ }
const length = obj.length;
if (typeof length === 'number') {
return !length;
@@ -136,7 +139,7 @@ export function isEmpty(obj?: any): boolean {
* isNotEmpty(undefined); // false
* isNotEmpty(''); // false
* isNotEmpty([]); // false
- * isNotEmpty({}); // true
+ * isNotEmpty({}); // false
* isNotEmpty('Adam Hawkins'); // true
* isNotEmpty([0,1,2]); // true
* isNotEmpty('\n\t'); // true
diff --git a/src/app/shared/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts
index fd42e640fa..c3018b957c 100644
--- a/src/app/shared/object-list/object-list.component.ts
+++ b/src/app/shared/object-list/object-list.component.ts
@@ -11,12 +11,12 @@ import {
import { Observable } from 'rxjs/Observable';
import { RemoteData } from '../../core/data/remote-data';
-import { DSpaceObject } from '../../core/shared/dspace-object.model';
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 { ListableObject } from '../../object-list/listable-object/listable-object.model';
@Component({
changeDetection: ChangeDetectionStrategy.Default,
@@ -27,7 +27,7 @@ import { SortOptions, SortDirection } from '../../core/cache/models/sort-options
})
export class ObjectListComponent implements OnChanges, OnInit {
- @Input() objects: RemoteData;
+ @Input() objects: RemoteData;
@Input() config: PaginationComponentOptions;
@Input() sortConfig: SortOptions;
@Input() hideGear = false;
@@ -52,6 +52,8 @@ export class ObjectListComponent implements OnChanges, OnInit {
*/
@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.
@@ -95,4 +97,8 @@ export class ObjectListComponent implements OnChanges, OnInit {
this.sortFieldChange.emit(event);
}
+ onPaginationChange(event) {
+ this.paginationChange.emit(event);
+ }
+
}
diff --git a/src/app/shared/pagination/pagination.component.html b/src/app/shared/pagination/pagination.component.html
index b61920567d..b280f481ed 100644
--- a/src/app/shared/pagination/pagination.component.html
+++ b/src/app/shared/pagination/pagination.component.html
@@ -3,22 +3,21 @@
-
+