diff --git a/resources/i18n/en.json b/resources/i18n/en.json index df1ee73260..85738b2c24 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -16,7 +16,8 @@ "author": "Author", "abstract": "Abstract", "date": "Date", - "uri": "URI" + "uri": "URI", + "files": "Files" } }, diff --git a/src/app/core/cache/models/normalized-bitstream.model.ts b/src/app/core/cache/models/normalized-bitstream.model.ts index 69f02ebb7c..57b4f63346 100644 --- a/src/app/core/cache/models/normalized-bitstream.model.ts +++ b/src/app/core/cache/models/normalized-bitstream.model.ts @@ -10,6 +10,7 @@ export class NormalizedBitstream extends NormalizedDSpaceObject { /** * The size of this bitstream in bytes(?) */ + @autoserialize size: number; /** diff --git a/src/app/core/cache/models/normalized-dspace-object.model.ts b/src/app/core/cache/models/normalized-dspace-object.model.ts index c3b782e6df..29688d5f9d 100644 --- a/src/app/core/cache/models/normalized-dspace-object.model.ts +++ b/src/app/core/cache/models/normalized-dspace-object.model.ts @@ -42,6 +42,7 @@ export abstract class NormalizedDSpaceObject implements CacheableObject { /** * An array of DSpaceObjects that are direct parents of this DSpaceObject */ + @autoserialize parents: Array; /** diff --git a/src/app/core/cache/models/normalized-item.model.ts b/src/app/core/cache/models/normalized-item.model.ts index 9e1dca1a12..74a3063a20 100644 --- a/src/app/core/cache/models/normalized-item.model.ts +++ b/src/app/core/cache/models/normalized-item.model.ts @@ -3,6 +3,7 @@ import { NormalizedDSpaceObject } from "./normalized-dspace-object.model"; import { Item } from "../../shared/item.model"; import { mapsTo, relationship } from "../builders/build-decorators"; import { NormalizedBundle } from "./normalized-bundle.model"; +import { NormalizedCollection } from "./normalized-collection.model"; @mapsTo(Item) @inheritSerialization(NormalizedDSpaceObject) @@ -32,6 +33,8 @@ export class NormalizedItem extends NormalizedDSpaceObject { /** * An array of Collections that are direct parents of this Item */ + @autoserialize + @relationship(NormalizedCollection) parents: Array; /** diff --git a/src/app/core/shared/bitstream.model.ts b/src/app/core/shared/bitstream.model.ts index acceaa38f0..1b35e8197d 100644 --- a/src/app/core/shared/bitstream.model.ts +++ b/src/app/core/shared/bitstream.model.ts @@ -1,5 +1,6 @@ import { DSpaceObject } from "./dspace-object.model"; import { Bundle } from "./bundle.model"; +import { RemoteData } from "../data/remote-data"; export class Bitstream extends DSpaceObject { @@ -26,7 +27,7 @@ export class Bitstream extends DSpaceObject { /** * An array of Bundles that are direct parents of this Bitstream */ - parents: Array; + parents: Array>; /** * The Bundle that owns this Bitstream diff --git a/src/app/core/shared/bundle.model.ts b/src/app/core/shared/bundle.model.ts index f6fd8f3820..ec13a78711 100644 --- a/src/app/core/shared/bundle.model.ts +++ b/src/app/core/shared/bundle.model.ts @@ -14,7 +14,7 @@ export class Bundle extends DSpaceObject { /** * An array of Items that are direct parents of this Bundle */ - parents: Array; + parents: Array>; /** * The Item that owns this Bundle diff --git a/src/app/core/shared/collection.model.ts b/src/app/core/shared/collection.model.ts index 2e4056fb3e..4287eff63c 100644 --- a/src/app/core/shared/collection.model.ts +++ b/src/app/core/shared/collection.model.ts @@ -58,7 +58,7 @@ export class Collection extends DSpaceObject { /** * An array of Collections that are direct parents of this Collection */ - parents: Array; + parents: Array>; /** * The Collection that owns this Collection diff --git a/src/app/core/shared/dspace-object.model.ts b/src/app/core/shared/dspace-object.model.ts index 7b4fbaea5c..22769763bf 100644 --- a/src/app/core/shared/dspace-object.model.ts +++ b/src/app/core/shared/dspace-object.model.ts @@ -2,6 +2,7 @@ import { autoserialize, autoserializeAs } from "cerialize"; import { Metadatum } from "./metadatum.model" import { isEmpty, isNotEmpty } from "../../shared/empty.util"; import { CacheableObject } from "../cache/object-cache.reducer"; +import { RemoteData } from "../data/remote-data"; /** * An abstract model class for a DSpaceObject. @@ -43,7 +44,7 @@ export abstract class DSpaceObject implements CacheableObject { /** * An array of DSpaceObjects that are direct parents of this DSpaceObject */ - parents: Array; + parents: Array>; /** * The DSpaceObject that owns this DSpaceObject diff --git a/src/app/core/shared/item.model.ts b/src/app/core/shared/item.model.ts index 4974abe1f2..5d43c1afab 100644 --- a/src/app/core/shared/item.model.ts +++ b/src/app/core/shared/item.model.ts @@ -33,8 +33,7 @@ export class Item extends DSpaceObject { /** * An array of Collections that are direct parents of this Item */ - @autoserializeAs(Collection) - parents: Array; + parents: Array>; /** * The Collection that owns this Item @@ -50,14 +49,8 @@ export class Item extends DSpaceObject { ); } - getFiles(): Array> { - return this.getBundle("ORIGINAL").map(bundle => bundle.bitstreams.map(bitstream => bitstream.payload.flatMap(b => b))).; - // const bundle: Observable = this.getBundle("ORIGINAL"); - // return bundle.map( - // bundle => bundle.bitstreams.flatMap( - // bitstream => bitstream.payload - // ) - // ); + getFiles(): Observable>> { + return this.getBundle("ORIGINAL").map(bundle => bundle.bitstreams.map(bitstream => bitstream.payload)); } getBundle(name: String): Observable { @@ -71,4 +64,8 @@ export class Item extends DSpaceObject { }); } + getCollections(): Array> { + return this.parents.map(c => c.payload.map(p => p)); + } + } diff --git a/src/app/item-page/collections/collections.component.html b/src/app/item-page/collections/collections.component.html new file mode 100644 index 0000000000..6c4346464c --- /dev/null +++ b/src/app/item-page/collections/collections.component.html @@ -0,0 +1,7 @@ + + + diff --git a/src/app/item-page/collections/collections.component.ts b/src/app/item-page/collections/collections.component.ts new file mode 100644 index 0000000000..9845fc13d1 --- /dev/null +++ b/src/app/item-page/collections/collections.component.ts @@ -0,0 +1,31 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { Collection } from "../../core/shared/collection.model"; +import { Observable } from "rxjs"; +import { Item } from "../../core/shared/item.model"; + +@Component({ + selector: 'ds-item-page-collections', + templateUrl: './collections.component.html' +}) +export class CollectionsComponent implements OnInit { + + @Input() item: Item; + label : string = "item.page.collections"; + collections: Array>; + + constructor() { + this.universalInit(); + + } + + universalInit() { + } + + ngOnInit(): void { + this.collections = this.item.getCollections(); + this.collections[0].subscribe(d => console.log("TEST TEST LOREM IPSUM LALALALAL")); + } + + + +} diff --git a/src/app/item-page/file-section/file-section.component.html b/src/app/item-page/file-section/file-section.component.html index 68c1bb36a5..94eab7ec1b 100644 --- a/src/app/item-page/file-section/file-section.component.html +++ b/src/app/item-page/file-section/file-section.component.html @@ -1,4 +1,8 @@ -
- -
- + + + diff --git a/src/app/item-page/file-section/file-section.component.ts b/src/app/item-page/file-section/file-section.component.ts index 4d0a1b5f02..b7c7fbb733 100644 --- a/src/app/item-page/file-section/file-section.component.ts +++ b/src/app/item-page/file-section/file-section.component.ts @@ -1,16 +1,17 @@ -import { Component, Input } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { Bitstream } from "../../core/shared/bitstream.model"; import { Item } from "../../core/shared/item.model"; +import { Observable } from "rxjs"; @Component({ - selector: 'ds-metadata-field-wrapper', - styleUrls: ['./metadata-field-wrapper.component.css'], - templateUrl: './metadata-field-wrapper.component.html' + selector: 'ds-item-page-file-section', + templateUrl: './file-section.component.html' }) -export class MetadataFieldWrapperComponent { +export class FileSectionComponent implements OnInit { @Input() item: Item; - files: Array; + label : string = "item.page.files"; + files: Observable>>; constructor() { this.universalInit(); @@ -18,7 +19,11 @@ export class MetadataFieldWrapperComponent { } universalInit() { - this.files = this.item.getBundle("ORIGINAL").map(bundle => bundle.bitstreams.map(bitstream => bitstream.payload)); } + ngOnInit(): void { + this.files = this.item.getFiles(); + } + + } diff --git a/src/app/item-page/item-page.component.html b/src/app/item-page/item-page.component.html index 59c963dd81..1c63038bf2 100644 --- a/src/app/item-page/item-page.component.html +++ b/src/app/item-page/item-page.component.html @@ -1,10 +1,17 @@
- Item page component - - - - - - - + +
+
+ + + + +
+
+ + + +
+
diff --git a/src/app/item-page/item-page.component.ts b/src/app/item-page/item-page.component.ts index d18963f3de..22b1df997d 100644 --- a/src/app/item-page/item-page.component.ts +++ b/src/app/item-page/item-page.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { Item } from "../core/shared/item.model"; import { ItemDataService } from "../core/data/item-data.service"; @@ -10,7 +10,6 @@ import { Bitstream } from "../core/shared/bitstream.model"; selector: 'ds-item-page', styleUrls: ['./item-page.component.css'], templateUrl: './item-page.component.html', - // changeDetection: ChangeDetectionStrategy.OnPush }) export class ItemPageComponent implements OnInit { diff --git a/src/app/item-page/item-page.module.ts b/src/app/item-page/item-page.module.ts index dcdd7b7130..a081b45339 100644 --- a/src/app/item-page/item-page.module.ts +++ b/src/app/item-page/item-page.module.ts @@ -13,6 +13,8 @@ import { ItemPageTitleFieldComponent } from './specific-field/title/item-page-ti import { ItemPageSpecificFieldComponent } from './specific-field/item-page-specific-field.component'; import { SharedModule } from './../shared/shared.module'; import { ThumbnailComponent } from "../thumbnail/thumbnail.component"; +import { FileSectionComponent } from "./file-section/file-section.component"; +import { CollectionsComponent } from "./collections/collections.component"; @NgModule({ declarations: [ @@ -27,6 +29,8 @@ import { ThumbnailComponent } from "../thumbnail/thumbnail.component"; ItemPageTitleFieldComponent, ItemPageSpecificFieldComponent, ThumbnailComponent, + FileSectionComponent, + CollectionsComponent ], imports: [ ItemPageRoutingModule, diff --git a/src/app/item-page/metadata-field-wrapper/metadata-field-wrapper.component.scss b/src/app/item-page/metadata-field-wrapper/metadata-field-wrapper.component.scss index 50be6f5ad0..749382bc9a 100644 --- a/src/app/item-page/metadata-field-wrapper/metadata-field-wrapper.component.scss +++ b/src/app/item-page/metadata-field-wrapper/metadata-field-wrapper.component.scss @@ -1 +1,6 @@ @import '../../../styles/variables.scss'; +:host { + .simple-view-element { + margin-bottom: 15px; + } +} \ No newline at end of file diff --git a/src/app/item-page/specific-field/abstract/item-page-abstract-field.component.ts b/src/app/item-page/specific-field/abstract/item-page-abstract-field.component.ts index d10fb84feb..2199616905 100644 --- a/src/app/item-page/specific-field/abstract/item-page-abstract-field.component.ts +++ b/src/app/item-page/specific-field/abstract/item-page-abstract-field.component.ts @@ -9,6 +9,7 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp export class ItemPageAbstractFieldComponent extends ItemPageSpecificFieldComponent implements OnInit { @Input() item: Item; + separator : string; fields : string[] = [ "dc.description.abstract" diff --git a/src/app/item-page/specific-field/date/item-page-date-field.component.ts b/src/app/item-page/specific-field/date/item-page-date-field.component.ts index 19d931c467..eca64c82e9 100644 --- a/src/app/item-page/specific-field/date/item-page-date-field.component.ts +++ b/src/app/item-page/specific-field/date/item-page-date-field.component.ts @@ -9,6 +9,7 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp export class ItemPageDateFieldComponent extends ItemPageSpecificFieldComponent implements OnInit { @Input() item: Item; + separator : string; fields : string[] = [ "dc.date.issued" diff --git a/src/app/item-page/specific-field/title/item-page-title-field.component.ts b/src/app/item-page/specific-field/title/item-page-title-field.component.ts index e9fea3fdee..d6c2301b27 100644 --- a/src/app/item-page/specific-field/title/item-page-title-field.component.ts +++ b/src/app/item-page/specific-field/title/item-page-title-field.component.ts @@ -9,6 +9,7 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp export class ItemPageTitleFieldComponent extends ItemPageSpecificFieldComponent implements OnInit { @Input() item: Item; + separator : string; fields : string[] = [ "dc.title" diff --git a/src/app/item-page/specific-field/uri/item-page-uri-field.component.ts b/src/app/item-page/specific-field/uri/item-page-uri-field.component.ts index 4ca523849d..16120af863 100644 --- a/src/app/item-page/specific-field/uri/item-page-uri-field.component.ts +++ b/src/app/item-page/specific-field/uri/item-page-uri-field.component.ts @@ -9,6 +9,8 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp export class ItemPageUriFieldComponent extends ItemPageSpecificFieldComponent implements OnInit { @Input() item: Item; + separator : string; + fields : string[] = [ "dc.identifier.uri" diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 1b7b0ad20e..daaad71cf0 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -7,6 +7,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { TranslateModule } from 'ng2-translate/ng2-translate'; import { ApiService } from './api.service'; +import { FileSizePipe } from "./utils/file-size-pipe"; const MODULES = [ // Do NOT include UniversalModule, HttpModule, or JsonpModule here @@ -19,6 +20,7 @@ const MODULES = [ ]; const PIPES = [ + FileSizePipe // put pipes here ]; diff --git a/src/app/shared/utils/file-size-pipe.ts b/src/app/shared/utils/file-size-pipe.ts new file mode 100644 index 0000000000..fbd3ae081c --- /dev/null +++ b/src/app/shared/utils/file-size-pipe.ts @@ -0,0 +1,36 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +/* + * Convert bytes into largest possible unit. + * Takes an precision argument that defaults to 2. + * Usage: + * bytes | fileSize:precision + * Example: + * {{ 1024 | fileSize}} + * formats to: 1 KB + */ +@Pipe({name: 'dsFileSize'}) +export class FileSizePipe implements PipeTransform { + + private units = [ + 'bytes', + 'KiB', + 'MiB', + 'GiB', + 'TiB', + 'PiB' + ]; + + transform(bytes: number = 0, precision: number = 2 ) : string { + if ( isNaN( parseFloat( String(bytes) )) || ! isFinite( bytes ) ) return '?'; + + let unit = 0; + + while ( bytes >= 1024 ) { + bytes /= 1024; + unit ++; + } + + return bytes.toFixed( + precision ) + ' ' + this.units[ unit ]; + } +} \ No newline at end of file diff --git a/src/backend/items.ts b/src/backend/items.ts index 5578691215..91b070113d 100644 --- a/src/backend/items.ts +++ b/src/backend/items.ts @@ -4,7 +4,7 @@ export const ITEMS = [ "self": { "href": "/items/8871" }, - "collections": [ + "parents": [ { "href": "/collections/5179" }, @@ -96,7 +96,7 @@ export const ITEMS = [ "self": { "href": "/items/9978" }, - "collections": [ + "parents": [ { "href": "/collections/5179" },