diff --git a/resources/i18n/en.json b/resources/i18n/en.json index 777a6f8490..9714640287 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -7,7 +7,12 @@ "collection": { "page": { "news": "News", - "license": "License" + "license": "License", + "browse": { + "recent": { + "head": "Recent Submissions" + } + } } }, "community": { diff --git a/src/app/collection-page/collection-page.component.html b/src/app/collection-page/collection-page.component.html index 64520d3e84..a8345ef23d 100644 --- a/src/app/collection-page/collection-page.component.html +++ b/src/app/collection-page/collection-page.component.html @@ -1,32 +1,44 @@ -
- - - - - - - - +
+ + + + + + + + - - - + + - - - + + - - - + + - + +
+
+
+

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

+ +
diff --git a/src/app/collection-page/collection-page.component.ts b/src/app/collection-page/collection-page.component.ts index a7148cbc74..4d56dc30ea 100644 --- a/src/app/collection-page/collection-page.component.ts +++ b/src/app/collection-page/collection-page.component.ts @@ -1,4 +1,4 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; import { ActivatedRoute, Params } from '@angular/router'; import { Collection } from "../core/shared/collection.model"; @@ -6,6 +6,11 @@ import { Bitstream } from "../core/shared/bitstream.model"; import { RemoteData } from "../core/data/remote-data"; import { CollectionDataService } from "../core/data/collection-data.service"; import { Subscription } from "rxjs/Subscription"; +import { ItemDataService } from "../core/data/item-data.service"; +import { Item } from "../core/shared/item.model"; +import { SortOptions, SortDirection } from "../core/cache/models/sort-options.model"; +import { PaginationComponentOptions } from "../shared/pagination/pagination-component-options.model"; +import { Observable } from "rxjs/Observable"; @Component({ selector: 'ds-collection-page', @@ -14,22 +19,39 @@ import { Subscription } from "rxjs/Subscription"; }) export class CollectionPageComponent implements OnInit, OnDestroy { collectionData: RemoteData; + itemData: RemoteData; logoData: RemoteData; + config : PaginationComponentOptions; + sortConfig : SortOptions; private subs: Subscription[] = []; + private collectionId: string; constructor( private collectionDataService: CollectionDataService, + private itemDataService: ItemDataService, + private ref: ChangeDetectorRef, private route: ActivatedRoute ) { this.universalInit(); } ngOnInit(): void { - this.route.params.subscribe((params: Params) => { - this.collectionData = this.collectionDataService.findById(params['id']); - this.subs.push(this.collectionData.payload - .subscribe(collection => this.logoData = collection.logo)); - }); + this.subs.push(this.route.params.map((params: Params) => params['id'] ) + .subscribe((id: string) => { + this.collectionId = id; + this.collectionData = this.collectionDataService.findById(this.collectionId); + this.subs.push(this.collectionData.payload + .subscribe(collection => this.logoData = collection.logo)); + + this.config = new PaginationComponentOptions(); + this.config.id = "collection-browse"; + this.config.pageSizeOptions = [ 5, 10, 20, 40, 60, 80, 100 ]; + this.config.pageSize = 4; + this.sortConfig = new SortOptions(); + + this.updateResults(); + })); + } ngOnDestroy(): void { @@ -38,4 +60,35 @@ export class CollectionPageComponent implements OnInit, OnDestroy { universalInit() { } + + onPageChange(currentPage: number): void { + this.config.currentPage = currentPage; + this.updateResults(); + } + + onPageSizeChange(elementsPerPage: number): void { + this.config.pageSize = elementsPerPage; + this.updateResults(); + } + + onSortDirectionChange(sortDirection: SortDirection): void { + this.sortConfig = new SortOptions(this.sortConfig.field, sortDirection); + this.updateResults(); + } + + onSortFieldChange(field: string): void { + this.sortConfig = new SortOptions(field, this.sortConfig.direction); + this.updateResults(); + } + + updateResults() { + this.itemData = undefined; + this.itemData = this.itemDataService.findAll({ + scopeID: this.collectionId, + currentPage: this.config.currentPage, + elementsPerPage: this.config.pageSize, + sort: this.sortConfig + }); + this.ref.detectChanges(); + } } diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts index 8756d02837..53530cbcb3 100644 --- a/src/app/core/data/collection-data.service.ts +++ b/src/app/core/data/collection-data.service.ts @@ -12,7 +12,8 @@ import { GLOBAL_CONFIG, GlobalConfig } from "../../../config"; @Injectable() export class CollectionDataService extends DataService { - protected endpoint = '/core/collections'; + protected resourceEndpoint = '/core/collections'; + protected browseEndpoint = '/discover/browses/dateissued/collections'; constructor( protected objectCache: ObjectCacheService, diff --git a/src/app/core/data/community-data.service.ts b/src/app/core/data/community-data.service.ts index 07420ba58f..996b17eab5 100644 --- a/src/app/core/data/community-data.service.ts +++ b/src/app/core/data/community-data.service.ts @@ -12,7 +12,8 @@ import { GLOBAL_CONFIG, GlobalConfig } from "../../../config"; @Injectable() export class CommunityDataService extends DataService { - protected endpoint = '/core/communities'; + protected resourceEndpoint = '/core/communities'; + protected browseEndpoint = '/discover/browses/dateissued/communities'; constructor( protected objectCache: ObjectCacheService, diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 36dd88ca44..05e7066290 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -20,7 +20,8 @@ export abstract class DataService protected abstract requestService: RequestService; protected abstract rdbService: RemoteDataBuildService; protected abstract store: Store; - protected abstract endpoint: string; + protected abstract resourceEndpoint: string; + protected abstract browseEndpoint: string; constructor( private normalizedResourceType: GenericConstructor, @@ -30,12 +31,16 @@ export abstract class DataService } protected getFindAllHref(options: FindAllOptions = {}): string { - let result = this.endpoint; + let result; let args = []; if (hasValue(options.scopeID)) { + result = this.browseEndpoint; args.push(`scope=${options.scopeID}`); } + else { + result = this.resourceEndpoint; + } 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 */ @@ -69,7 +74,7 @@ export abstract class DataService } protected getFindByIDHref(resourceID): string { - return new RESTURLCombiner(this.EnvConfig, `${this.endpoint}/${resourceID}`).toString(); + return new RESTURLCombiner(this.EnvConfig, `${this.resourceEndpoint}/${resourceID}`).toString(); } findById(id: string): RemoteData { diff --git a/src/app/core/data/item-data.service.ts b/src/app/core/data/item-data.service.ts index e7df1aea07..88bb1506c8 100644 --- a/src/app/core/data/item-data.service.ts +++ b/src/app/core/data/item-data.service.ts @@ -12,7 +12,8 @@ import { GLOBAL_CONFIG, GlobalConfig } from "../../../config"; @Injectable() export class ItemDataService extends DataService { - protected endpoint = '/core/items'; + protected resourceEndpoint = '/core/items'; + protected browseEndpoint = '/discover/browses/dateissued/items'; constructor( protected objectCache: ObjectCacheService, diff --git a/src/app/home/home.module.ts b/src/app/home/home.module.ts index 1ec82e4748..4128c91097 100644 --- a/src/app/home/home.module.ts +++ b/src/app/home/home.module.ts @@ -7,11 +7,6 @@ import { TopLevelCommunityListComponent } from "./top-level-community-list/top-l import { HomeNewsComponent } from "./home-news/home-news.component"; import { RouterModule } from "@angular/router"; import { TranslateModule } from "@ngx-translate/core"; -import { ObjectListComponent } from "../object-list/object-list.component"; -import { ObjectListElementComponent } from "../object-list/object-list-element/object-list-element.component"; -import { ItemListElementComponent } from "../object-list/item-list-element/item-list-element.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 { SharedModule } from "../shared/shared.module"; @NgModule({ @@ -25,12 +20,7 @@ import { SharedModule } from "../shared/shared.module"; declarations: [ HomeComponent, TopLevelCommunityListComponent, - HomeNewsComponent, - ObjectListComponent, - ObjectListElementComponent, - ItemListElementComponent, - CollectionListElementComponent, - CommunityListElementComponent + HomeNewsComponent ] }) export class HomeModule { } 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 1463e2aef5..9e682a2bfd 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,12 +1,14 @@ {{item.findMetadata("dc.title")}} -
+
+ {{authorMd.value}} ; ({{item.findMetadata("dc.publisher")}}, {{item.findMetadata("dc.date.issued")}}) -
{{item.findMetadata("dc.description.abstract") | words : 35 : "..."}}
+
+
{{item.findMetadata("dc.description.abstract") | words : 35 : "..."}}
diff --git a/src/app/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts similarity index 80% rename from src/app/object-list/object-list.component.ts rename to src/app/shared/object-list/object-list.component.ts index df570bda46..7e404d0f51 100644 --- a/src/app/object-list/object-list.component.ts +++ b/src/app/shared/object-list/object-list.component.ts @@ -2,21 +2,21 @@ import { Component, Input, ViewEncapsulation, ChangeDetectionStrategy, OnInit, Output } from '@angular/core'; -import { RemoteData } from "../core/data/remote-data"; -import { DSpaceObject } from "../core/shared/dspace-object.model"; -import { PageInfo } from "../core/shared/page-info.model"; +import { RemoteData } from "../../core/data/remote-data"; +import { DSpaceObject } from "../../core/shared/dspace-object.model"; +import { PageInfo } from "../../core/shared/page-info.model"; import { Observable } from "rxjs"; -import { PaginationComponentOptions } from "../shared/pagination/pagination-component-options.model"; +import { PaginationComponentOptions } from "../pagination/pagination-component-options.model"; import { EventEmitter } from "@angular/common/src/facade/async"; -import { SortOptions, SortDirection } from "../core/cache/models/sort-options.model"; +import { SortOptions, SortDirection } from "../../core/cache/models/sort-options.model"; @Component({ changeDetection: ChangeDetectionStrategy.Default, encapsulation: ViewEncapsulation.Emulated, selector: 'ds-object-list', - styleUrls: ['./object-list.component.css'], - templateUrl: './object-list.component.html' + styleUrls: ['../../object-list/object-list.component.css'], + templateUrl: '../../object-list/object-list.component.html' }) export class ObjectListComponent implements OnInit { diff --git a/src/app/shared/pagination/pagination.component.spec.ts b/src/app/shared/pagination/pagination.component.spec.ts index dbe63132a1..8a8b5139b9 100644 --- a/src/app/shared/pagination/pagination.component.spec.ts +++ b/src/app/shared/pagination/pagination.component.spec.ts @@ -31,6 +31,8 @@ import { MockTranslateLoader } from "../testing/mock-translate-loader"; import { GLOBAL_CONFIG, EnvConfig } from '../../../config'; import { ActivatedRouteStub, RouterStub } from "../testing/router-stubs"; import { HostWindowService } from "../host-window.service"; +import { EnumKeysPipe } from "../utils/enum-keys-pipe"; +import { SortOptions } from "../../core/cache/models/sort-options.model"; function createTestComponent(html: string, type: {new (...args: any[]): T}): ComponentFixture { @@ -138,7 +140,7 @@ describe('Pagination component', () => { RouterTestingModule.withRoutes([ {path: 'home', component: TestComponent} ])], - declarations: [PaginationComponent, TestComponent], // declare the test component + declarations: [PaginationComponent, TestComponent, EnumKeysPipe], // declare the test component providers: [ { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: GLOBAL_CONFIG, useValue: EnvConfig }, @@ -156,6 +158,7 @@ describe('Pagination component', () => { html = ` @@ -247,12 +250,12 @@ describe('Pagination component', () => { changePage(testFixture, 3); tick(); - expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 10 } }); + expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 10, sortDirection: 0, sortField: 'name' } }); expect(paginationComponent.currentPage).toEqual(3); changePageSize(testFixture, '20'); tick(); - expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 20 } }); + expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 20, sortDirection: 0, sortField: 'name' } }); expect(paginationComponent.pageSize).toEqual(20); })); @@ -308,6 +311,7 @@ class TestComponent { collection: string[] = []; collectionSize: number; paginationOptions = new PaginationComponentOptions(); + sortOptions = new SortOptions(); constructor() { this.collection = Array.from(new Array(100), (x, i) => `item ${i + 1}`); diff --git a/src/app/shared/pagination/pagination.component.ts b/src/app/shared/pagination/pagination.component.ts index 6fc3994a37..62c518faa1 100644 --- a/src/app/shared/pagination/pagination.component.ts +++ b/src/app/shared/pagination/pagination.component.ts @@ -19,6 +19,7 @@ import { HostWindowService } from "../host-window.service"; import { HostWindowState } from "../host-window.reducer"; import { PaginationComponentOptions } from './pagination-component-options.model'; import { SortDirection, SortOptions } from "../../core/cache/models/sort-options.model"; +import { hasValue } from "../empty.util"; /** * The default pagination controls component. @@ -173,7 +174,7 @@ export class PaginationComponent implements OnDestroy, OnInit { this.sortDirection = this.sortOptions.direction; this.sortField = this.sortOptions.field; this.routeSubscription = this.route.queryParams - .map(queryParams => queryParams) + .filter(queryParams => hasValue(queryParams)) .subscribe(queryParams => { this.currentQueryParams = queryParams; if (this.id == queryParams['pageId'] diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 5ccfc92ab3..8c998b5b8e 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -19,6 +19,11 @@ import { ComcolPageHeaderComponent } from "./comcol-page-header/comcol-page-head import { ComcolPageLogoComponent } from "./comcol-page-logo/comcol-page-logo.component"; import { TRUNCATE_PIPES } from "ng2-truncate"; import { EnumKeysPipe } from "./utils/enum-keys-pipe"; +import { ObjectListComponent } from "./object-list/object-list.component"; +import { ObjectListElementComponent } from "../object-list/object-list-element/object-list-element.component"; +import { ItemListElementComponent } from "../object-list/item-list-element/item-list-element.component"; +import { CommunityListElementComponent } from "../object-list/community-list-element/community-list-element.component"; +import { CollectionListElementComponent } from "../object-list/collection-list-element/collection-list-element.component"; const MODULES = [ // Do NOT include UniversalModule, HttpModule, or JsonpModule here @@ -45,7 +50,12 @@ const COMPONENTS = [ ThumbnailComponent, ComcolPageContentComponent, ComcolPageHeaderComponent, - ComcolPageLogoComponent + ComcolPageLogoComponent, + ObjectListComponent, + ObjectListElementComponent, + ItemListElementComponent, + CollectionListElementComponent, + CommunityListElementComponent ]; const PROVIDERS = [