Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Commit

Permalink
Repeatable item metadata input. Update item counts on create new item.
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed May 3, 2016
1 parent 6db18d1 commit b23a5f1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
45 changes: 38 additions & 7 deletions src/app/dspace/components/item-create.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ import {Metadatum} from '../models/metadatum.model';
<tr *ngFor="#input of metadatumInputs">
<td>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-11">
<label>{{input.gloss}}</label>
<span class="text-danger" *ngIf="input.validation.required">*required</span>
<label class="pull-right">{{input.key}}</label>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-11">
<input *ngIf="input.type == 'TEXT'" class="form-control" type="text" id="{{input.key}}" [(ngModel)]="input.value" ngControl="{{input.key}}">
Expand All @@ -85,6 +85,12 @@ import {Metadatum} from '../models/metadatum.model';
</span>
</div>
<div class="col-xs-1" *ngIf="input.repeatable">
<span *ngIf="!input.repeat" class="glyphicon glyphicon-plus clickable" aria-hidden="true" (click)="addMetadatumInput(input)"></span>
<span *ngIf="input.repeat" class="glyphicon glyphicon-minus clickable" aria-hidden="true" (click)="removeMetadatumInput(input)"></span>
</div>
</div>
</td>
</tr>
Expand All @@ -106,7 +112,7 @@ export class ItemCreateComponent {

private active: boolean = false;

private item: Item = new Item();
private item: Item;

private metadatumInputs: Array<MetadatumInput>;

Expand All @@ -121,8 +127,14 @@ export class ItemCreateComponent {
private builder: FormBuilder) {
translate.setDefaultLang('en');
translate.use('en');
this.init();
}

init(): void {
this.item = new Item();

this.dspaceService.getItemMetadataForm().subscribe((metadatumInputs:Array<MetadatumInput>) => {

dspaceService.getItemMetadataForm().subscribe((metadatumInputs:Array<MetadatumInput>) => {
this.metadatumInputs = metadatumInputs;

let formControls = {};
Expand Down Expand Up @@ -152,12 +164,32 @@ export class ItemCreateComponent {

}

this.form = builder.group(formControls);
this.form = this.builder.group(formControls);

this.active = true;

});
}

addMetadatumInput(input: MetadatumInput): void {
let newInput = JSON.parse(JSON.stringify(input));
newInput.repeat = newInput.repeat ? newInput.repeat++ : 1;
newInput.value = '';
for(let i = this.metadatumInputs.length - 1; i > 0; i--) {
if(this.metadatumInputs[i].key == newInput.key) {
this.metadatumInputs.splice(i+1, 0, newInput);
break;
}
}
}

removeMetadatumInput(input: MetadatumInput): void {
for(let i = this.metadatumInputs.length - 1; i > 0; i--) {
if(this.metadatumInputs[i].key == input.key) {
this.metadatumInputs.splice(i, 1);
break;
}
}
}

createItem(): void {
Expand Down Expand Up @@ -189,9 +221,8 @@ export class ItemCreateComponent {
}

reset(): void {
this.item = new Item();
this.active = false;
setTimeout(() => this.active = true, 0);
this.init();
}

}
Expand Down
16 changes: 16 additions & 0 deletions src/app/dspace/dspace.directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class DSpaceDirectory {
else if(context.type == 'collection') {
context.items.splice(0, context.items.length);
this.loadNav('item', context);
this.incrementItemCount(context);
}
}
else {
Expand All @@ -60,6 +61,21 @@ export class DSpaceDirectory {
}
}

incrementItemCount(context: any): void {
if(context.type == 'community') {
context.countItems++;
}
else if(context.type == 'collection') {
context.numberItems++;
}
else {
console.log(context.type + " does not contain count of items");
}
if(context.parentCommunity) {
this.incrementItemCount(context.parentCommunity);
}
}

/**
* Method to perform initial loading of the directory.
* Calls prepare with the top community results.
Expand Down

0 comments on commit b23a5f1

Please sign in to comment.