forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in DSC-544 (pull request DSpace#162)
[DSC-544] Workflow item task not showing correction change request Approved-by: Giuseppe Digilio
- Loading branch information
Showing
15 changed files
with
664 additions
and
4 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/app/core/submission/models/workspaceitem-section-correction.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* An interface to represent submission's correction section data. | ||
*/ | ||
export interface WorkspaceitemSectionCorrectionObject { | ||
metadata: WorkspaceitemSectionCorrectionMetadataObject[]; | ||
bitstream: WorkspaceitemSectionCorrectionBitstreamObject[]; | ||
} | ||
|
||
export interface WorkspaceitemSectionCorrectionMetadataObject { | ||
metadata: string; | ||
oldValues: string[]; | ||
newValues: string[]; | ||
label: string; | ||
} | ||
|
||
export enum OperationType { | ||
ADD = 'ADD', | ||
REMOVE = 'REMOVE', | ||
MODIFY = 'MODIFY' | ||
} | ||
|
||
export interface WorkspaceitemSectionCorrectionBitstreamObject { | ||
filename: string; | ||
operationType: OperationType; | ||
metadata: WorkspaceitemSectionCorrectionMetadataObject[]; | ||
policies: WorkspaceitemSectionCorrectionBitstreamPolicyObject[]; | ||
} | ||
|
||
export interface WorkspaceitemSectionCorrectionBitstreamPolicyObject { | ||
oldValue: string; | ||
newValue: string; | ||
label: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...p/shared/object-collection/shared/mydspace-item-correction/item-correction.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div *ngIf="isCorrectionOfItem$ | async"> | ||
<span class="badge badge-light">{{'mydspace.results.is-correction' | translate}}</span> | ||
</div> |
Empty file.
92 changes: 92 additions & 0 deletions
92
...hared/object-collection/shared/mydspace-item-correction/item-correction.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; | ||
|
||
import { ItemCorrectionComponent } from './item-correction.component'; | ||
import { TranslateLoaderMock } from '../../../testing/translate-loader.mock'; | ||
import { RelationshipService } from '../../../../core/data/relationship.service'; | ||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model'; | ||
import { buildPaginatedList } from '../../../../core/data/paginated-list.model'; | ||
import { PageInfo } from '../../../../core/shared/page-info.model'; | ||
import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils'; | ||
import { cold } from 'jasmine-marbles'; | ||
|
||
let component: ItemCorrectionComponent; | ||
let fixture: ComponentFixture<ItemCorrectionComponent>; | ||
let relationshipService: any; | ||
const mockRelationshipService = jasmine.createSpyObj('relationshipService', | ||
{ | ||
getItemRelationshipsByLabel: jasmine.createSpy('getItemRelationshipsByLabel') | ||
} | ||
); | ||
|
||
const relationship = Object.assign(new Relationship(), { | ||
_links: { | ||
self: { | ||
href: 'dspacerest/2' | ||
} | ||
}, | ||
id: '1', | ||
uuid: '1', | ||
leftId: 'author1', | ||
rightId: 'publication', | ||
}); | ||
|
||
const relationshipPaginatedList = buildPaginatedList(new PageInfo(), [relationship]); | ||
const relationshipPaginatedListEmpty = buildPaginatedList(new PageInfo(), [relationship]); | ||
const relationshipPaginatedListRD = createSuccessfulRemoteDataObject(relationshipPaginatedList); | ||
const relationshipPaginatedListEmptyRD = createSuccessfulRemoteDataObject(relationshipPaginatedListEmpty); | ||
|
||
describe('ItemCorrectionComponent', () => { | ||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useClass: TranslateLoaderMock | ||
} | ||
}) | ||
], | ||
declarations: [ItemCorrectionComponent], | ||
providers: [ | ||
{ provide: RelationshipService, useValue: mockRelationshipService }, | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).overrideComponent(ItemCorrectionComponent, { | ||
set: { changeDetection: ChangeDetectionStrategy.Default } | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(async(() => { | ||
fixture = TestBed.createComponent(ItemCorrectionComponent); | ||
component = fixture.componentInstance; | ||
})); | ||
|
||
beforeEach(() => { | ||
relationshipService = TestBed.get(RelationshipService); | ||
|
||
}); | ||
|
||
it('should show a badge when item is a correction', () => { | ||
relationshipService.getItemRelationshipsByLabel.and.returnValue(cold('a', { | ||
a: relationshipPaginatedListRD | ||
})); | ||
fixture.detectChanges(); | ||
const badge = fixture.debugElement.query(By.css('.text-muted')); | ||
|
||
expect(badge).toBeDefined(); | ||
}); | ||
|
||
it('should not show a badge when item is not a correction', () => { | ||
relationshipService.getItemRelationshipsByLabel.and.returnValue(cold('a', { | ||
a: relationshipPaginatedListEmptyRD | ||
})); | ||
fixture.detectChanges(); | ||
const badge = fixture.debugElement.query(By.css('.text-muted')); | ||
|
||
expect(badge).toBeNull(); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
...app/shared/object-collection/shared/mydspace-item-correction/item-correction.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
|
||
import { Observable, of as observableOf } from 'rxjs'; | ||
import { catchError, map, startWith } from 'rxjs/operators'; | ||
|
||
import { Item } from '../../../../core/shared/item.model'; | ||
import { getFirstSucceededRemoteListPayload } from '../../../../core/shared/operators'; | ||
import { Relationship } from '../../../../core/shared/item-relationships/relationship.model'; | ||
import { RelationshipService } from '../../../../core/data/relationship.service'; | ||
|
||
/** | ||
* This component represents a badge with correction item information. | ||
*/ | ||
@Component({ | ||
selector: 'ds-item-correction', | ||
styleUrls: ['./item-correction.component.scss'], | ||
templateUrl: './item-correction.component.html' | ||
}) | ||
export class ItemCorrectionComponent implements OnInit { | ||
|
||
/** | ||
* The target object | ||
*/ | ||
@Input() item: Item; | ||
|
||
/** | ||
* A boolean representing if item is a correction of an existing one | ||
*/ | ||
isCorrectionOfItem$: Observable<boolean>; | ||
|
||
constructor(private relationshipService: RelationshipService) { | ||
} | ||
/** | ||
* Check if item is a correction of an existing one | ||
*/ | ||
ngOnInit(): void { | ||
this.isCorrectionOfItem$ = this.relationshipService.getItemRelationshipsByLabel( | ||
this.item, | ||
'isCorrectionOfItem' | ||
).pipe( | ||
getFirstSucceededRemoteListPayload(), | ||
map((list: Relationship[]) => list.length > 0), | ||
startWith(false), | ||
catchError(() => observableOf(false)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/app/submission/sections/correction/ section-correction.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { Component, Inject } from '@angular/core'; | ||
|
||
import { Observable, of as observableOf } from 'rxjs'; | ||
|
||
import { renderSectionFor } from '../sections-decorator'; | ||
import { SectionsType } from '../sections-type'; | ||
import { SectionModelComponent } from '../models/section.model'; | ||
import { SectionDataObject } from '../models/section-data.model'; | ||
import { SectionsService } from '../sections.service'; | ||
import { RoleType } from '../../../core/roles/role-types'; | ||
import { | ||
OperationType, | ||
WorkspaceitemSectionCorrectionBitstreamObject, | ||
WorkspaceitemSectionCorrectionMetadataObject, | ||
WorkspaceitemSectionCorrectionObject | ||
} from '../../../core/submission/models/workspaceitem-section-correction.model'; | ||
|
||
@Component({ | ||
selector: 'ds-submission-correction', | ||
templateUrl: './section-correction.component.html' | ||
}) | ||
@renderSectionFor(SectionsType.Correction) | ||
export class SubmissionSectionCorrectionComponent extends SectionModelComponent { | ||
|
||
/** | ||
* Contain the correction information regarding item's bitstream | ||
*/ | ||
public correctionBitstreamData: WorkspaceitemSectionCorrectionBitstreamObject[]; | ||
|
||
/** | ||
* Contain the correction information regarding item's metadata | ||
*/ | ||
public correctionMetadataData: WorkspaceitemSectionCorrectionMetadataObject[]; | ||
|
||
public roleTypeEnum = RoleType; | ||
public operationType = OperationType; | ||
|
||
constructor(protected sectionService: SectionsService, | ||
@Inject('collectionIdProvider') public injectedCollectionId: string, | ||
@Inject('sectionDataProvider') public injectedSectionData: SectionDataObject, | ||
@Inject('submissionIdProvider') public injectedSubmissionId: string) { | ||
super(injectedCollectionId, injectedSectionData, injectedSubmissionId); | ||
} | ||
|
||
protected getSectionStatus(): Observable<boolean> { | ||
return observableOf(true); | ||
} | ||
|
||
/** | ||
* Retrieve correction metadata list | ||
*/ | ||
getItemData(): WorkspaceitemSectionCorrectionMetadataObject[] { | ||
const correctionObject: WorkspaceitemSectionCorrectionObject = this.sectionData.data as WorkspaceitemSectionCorrectionObject; | ||
return correctionObject.metadata; | ||
} | ||
|
||
/** | ||
* Retrieve correction bitstream list | ||
*/ | ||
getFileData(): WorkspaceitemSectionCorrectionBitstreamObject[] { | ||
const correctionObject: WorkspaceitemSectionCorrectionObject = this.sectionData.data as WorkspaceitemSectionCorrectionObject; | ||
return [...correctionObject?.bitstream].sort((obj1: WorkspaceitemSectionCorrectionBitstreamObject, obj2: WorkspaceitemSectionCorrectionBitstreamObject) => { | ||
return obj1.filename > obj2.filename ? 1 : -1; | ||
} | ||
); | ||
} | ||
|
||
getFileOperationLabel(operation: OperationType): string { | ||
let label = ''; | ||
switch (operation) { | ||
case OperationType.ADD: | ||
label = 'submission.sections.correction.bitstream.operation.add'; | ||
break; | ||
case OperationType.REMOVE: | ||
label = 'submission.sections.correction.bitstream.operation.remove'; | ||
break; | ||
case OperationType.MODIFY: | ||
label = 'submission.sections.correction.bitstream.operation.modify'; | ||
break; | ||
} | ||
|
||
return label; | ||
} | ||
|
||
sortMetadataByLabel(metadata: WorkspaceitemSectionCorrectionMetadataObject[]): WorkspaceitemSectionCorrectionMetadataObject[] { | ||
return metadata.sort((obj1: WorkspaceitemSectionCorrectionMetadataObject, obj2: WorkspaceitemSectionCorrectionMetadataObject) => { | ||
return obj1.label > obj2.label ? 1 : -1; | ||
}); | ||
} | ||
|
||
showTable(): boolean { | ||
return Object.values(this.sectionData.data).length > 0; | ||
} | ||
|
||
/* tslint:disable:no-empty */ | ||
protected onSectionDestroy() { | ||
} | ||
|
||
protected onSectionInit(): void { | ||
this.correctionMetadataData = this.getItemData(); | ||
this.correctionBitstreamData = this.getFileData(); | ||
} | ||
|
||
} |
Oops, something went wrong.