Skip to content

Commit

Permalink
Merge 53ec7d6 into c911ec9
Browse files Browse the repository at this point in the history
  • Loading branch information
Atmire-Kristof committed Mar 19, 2020
2 parents c911ec9 + 53ec7d6 commit fb69b1f
Show file tree
Hide file tree
Showing 27 changed files with 1,024 additions and 18 deletions.
29 changes: 29 additions & 0 deletions resources/i18n/en.json5
Expand Up @@ -1005,6 +1005,12 @@

"item.edit.tabs.status.title": "Item Edit - Status",

"item.edit.tabs.versionhistory.head": "Version History",

"item.edit.tabs.versionhistory.title": "Item Edit - Version History",

"item.edit.tabs.versionhistory.under-construction": "Editing or adding new versions is not yet possible in this user interface.",

"item.edit.tabs.view.head": "View Item",

"item.edit.tabs.view.title": "Item Edit - View",
Expand Down Expand Up @@ -1084,6 +1090,29 @@
"item.select.table.title": "Title",


"item.version.history.empty": "There are no other versions for this item yet.",

"item.version.history.head": "Version History",

"item.version.history.return": "Return",

"item.version.history.selected": "Selected version",

"item.version.history.table.version": "Version",

"item.version.history.table.item": "Item",

"item.version.history.table.editor": "Editor",

"item.version.history.table.date": "Date",

"item.version.history.table.summary": "Summary",



"item.version.notice": "This is not the latest version of this item. The latest version can be found <a href='{{destination}}'>here</a>.",



"journal.listelement.badge": "Journal",

Expand Down
2 changes: 2 additions & 0 deletions src/app/+item-page/edit-item-page/edit-item-page.module.ts
Expand Up @@ -22,6 +22,7 @@ import { EditRelationshipComponent } from './item-relationships/edit-relationshi
import { EditRelationshipListComponent } from './item-relationships/edit-relationship-list/edit-relationship-list.component';
import { ItemMoveComponent } from './item-move/item-move.component';
import { VirtualMetadataComponent } from './virtual-metadata/virtual-metadata.component';
import { ItemVersionHistoryComponent } from './item-version-history/item-version-history.component';

/**
* Module that contains all components related to the Edit Item page administrator functionality
Expand All @@ -47,6 +48,7 @@ import { VirtualMetadataComponent } from './virtual-metadata/virtual-metadata.co
ItemMetadataComponent,
ItemRelationshipsComponent,
ItemBitstreamsComponent,
ItemVersionHistoryComponent,
EditInPlaceFieldComponent,
EditRelationshipComponent,
EditRelationshipListComponent,
Expand Down
@@ -1,4 +1,3 @@
import { ItemPageResolver } from '../item-page.resolver';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { EditItemPageComponent } from './edit-item-page.component';
Expand All @@ -14,6 +13,7 @@ import { ItemCollectionMapperComponent } from './item-collection-mapper/item-col
import { ItemMoveComponent } from './item-move/item-move.component';
import { ItemRelationshipsComponent } from './item-relationships/item-relationships.component';
import { I18nBreadcrumbResolver } from '../../core/breadcrumbs/i18n-breadcrumb.resolver';
import { ItemVersionHistoryComponent } from './item-version-history/item-version-history.component';

export const ITEM_EDIT_WITHDRAW_PATH = 'withdraw';
export const ITEM_EDIT_REINSTATE_PATH = 'reinstate';
Expand Down Expand Up @@ -75,6 +75,11 @@ export const ITEM_EDIT_MOVE_PATH = 'move';
/* TODO - change when curate page exists */
component: ItemBitstreamsComponent,
data: { title: 'item.edit.tabs.curate.title', showBreadcrumbs: true }
},
{
path: 'versionhistory',
component: ItemVersionHistoryComponent,
data: { title: 'item.edit.tabs.versionhistory.title', showBreadcrumbs: true }
}
]
},
Expand Down
@@ -0,0 +1,6 @@
<div class="mt-4">
<ds-alert [content]="'item.edit.tabs.versionhistory.under-construction'" [type]="AlertTypeEnum.Warning"></ds-alert>
</div>
<div class="mt-2" *ngVar="(itemRD$ | async)?.payload as item">
<ds-item-versions *ngIf="item" [item]="item" [displayWhenEmpty]="true" [displayTitle]="false"></ds-item-versions>
</div>
@@ -0,0 +1,44 @@
import { ItemVersionHistoryComponent } from './item-version-history.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { VarDirective } from '../../../shared/utils/var.directive';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Item } from '../../../core/shared/item.model';
import { ActivatedRoute } from '@angular/router';
import { of as observableOf } from 'rxjs';
import { createSuccessfulRemoteDataObject } from '../../../shared/testing/utils';

describe('ItemVersionHistoryComponent', () => {
let component: ItemVersionHistoryComponent;
let fixture: ComponentFixture<ItemVersionHistoryComponent>;

const item = Object.assign(new Item(), {
uuid: 'item-identifier-1',
handle: '123456789/1',
});

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ItemVersionHistoryComponent, VarDirective],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
providers: [
{ provide: ActivatedRoute, useValue: { parent: { data: observableOf({ item: createSuccessfulRemoteDataObject(item) }) } } }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ItemVersionHistoryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should initialize the itemRD$ from the route\'s data', (done) => {
component.itemRD$.subscribe((itemRD) => {
expect(itemRD.payload).toBe(item);
done();
});
});
});
@@ -0,0 +1,35 @@
import { Component } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { RemoteData } from '../../../core/data/remote-data';
import { Item } from '../../../core/shared/item.model';
import { map } from 'rxjs/operators';
import { getSucceededRemoteData } from '../../../core/shared/operators';
import { ActivatedRoute } from '@angular/router';
import { AlertType } from '../../../shared/alert/aletr-type';

@Component({
selector: 'ds-item-version-history',
templateUrl: './item-version-history.component.html'
})
/**
* Component for listing and managing an item's version history
*/
export class ItemVersionHistoryComponent {
/**
* The item to display the version history for
*/
itemRD$: Observable<RemoteData<Item>>;

/**
* The AlertType enumeration
* @type {AlertType}
*/
AlertTypeEnum = AlertType;

constructor(private route: ActivatedRoute) {
}

ngOnInit(): void {
this.itemRD$ = this.route.parent.data.pipe(map((data) => data.item)).pipe(getSucceededRemoteData()) as Observable<RemoteData<Item>>;
}
}
2 changes: 2 additions & 0 deletions src/app/+item-page/full/full-item-page.component.html
@@ -1,6 +1,7 @@
<div class="container" *ngVar="(itemRD$ | async) as itemRD">
<div class="item-page" *ngIf="itemRD?.hasSucceeded" @fadeInOut>
<div *ngIf="itemRD?.payload as item">
<ds-item-versions-notice [item]="item"></ds-item-versions-notice>
<ds-view-tracker [object]="item"></ds-view-tracker>
<ds-item-page-title-field [item]="item"></ds-item-page-title-field>
<div class="simple-view-link my-3">
Expand All @@ -21,6 +22,7 @@
</table>
<ds-item-page-full-file-section [item]="item"></ds-item-page-full-file-section>
<ds-item-page-collections [item]="item"></ds-item-page-collections>
<ds-item-versions class="mt-2" [item]="item"></ds-item-versions>
</div>
</div>
<ds-error *ngIf="itemRD?.hasFailed" message="{{'error.item' | translate}}"></ds-error>
Expand Down
2 changes: 1 addition & 1 deletion src/app/+item-page/item-page.module.ts
Expand Up @@ -59,7 +59,7 @@ import { AbstractIncrementalListComponent } from './simple/abstract-incremental-
MetadataRepresentationListComponent,
RelatedEntitiesSearchComponent,
TabbedRelatedEntitiesSearchComponent,
AbstractIncrementalListComponent
AbstractIncrementalListComponent,
],
exports: [
ItemComponent,
Expand Down
1 change: 1 addition & 0 deletions src/app/+item-page/item-page.resolver.ts
Expand Up @@ -28,6 +28,7 @@ export class ItemPageResolver implements Resolve<RemoteData<Item>> {
followLink('owningCollection'),
followLink('bundles'),
followLink('relationships'),
followLink('version', undefined, true, followLink('versionhistory')),
).pipe(
find((RD) => hasValue(RD.error) || RD.hasSucceeded),
);
Expand Down
2 changes: 2 additions & 0 deletions src/app/+item-page/simple/item-page.component.html
@@ -1,8 +1,10 @@
<div class="container" *ngVar="(itemRD$ | async) as itemRD">
<div class="item-page" *ngIf="itemRD?.hasSucceeded" @fadeInOut>
<div *ngIf="itemRD?.payload as item">
<ds-item-versions-notice [item]="item"></ds-item-versions-notice>
<ds-view-tracker [object]="item"></ds-view-tracker>
<ds-listable-object-component-loader [object]="item" [viewMode]="viewMode"></ds-listable-object-component-loader>
<ds-item-versions class="mt-2" [item]="item"></ds-item-versions>
</div>
</div>
<ds-error *ngIf="itemRD?.hasFailed" message="{{'error.item' | translate}}"></ds-error>
Expand Down
8 changes: 8 additions & 0 deletions src/app/core/core.module.ts
Expand Up @@ -142,6 +142,10 @@ import { PoolTask } from './tasks/models/pool-task-object.model';
import { TaskObject } from './tasks/models/task-object.model';
import { PoolTaskDataService } from './tasks/pool-task-data.service';
import { TaskResponseParsingService } from './tasks/task-response-parsing.service';
import { VersionDataService } from './data/version-data.service';
import { VersionHistoryDataService } from './data/version-history-data.service';
import { Version } from './shared/version.model';
import { VersionHistory } from './shared/version-history.model';

/**
* When not in production, endpoint responses can be mocked for testing purposes
Expand Down Expand Up @@ -255,6 +259,8 @@ const PROVIDERS = [
RelationshipTypeService,
ExternalSourceService,
LookupRelationService,
VersionDataService,
VersionHistoryDataService,
LicenseDataService,
ItemTypeDataService,
// register AuthInterceptor as HttpInterceptor
Expand Down Expand Up @@ -305,6 +311,8 @@ export const models =
ItemType,
ExternalSource,
ExternalSourceEntry,
Version,
VersionHistory
];

@NgModule({
Expand Down
44 changes: 44 additions & 0 deletions src/app/core/data/version-data.service.ts
@@ -0,0 +1,44 @@
import { Injectable } from '@angular/core';
import { DataService } from './data.service';
import { Version } from '../shared/version.model';
import { RequestService } from './request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { Store } from '@ngrx/store';
import { CoreState } from '../core.reducers';
import { ObjectCacheService } from '../cache/object-cache.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { HttpClient } from '@angular/common/http';
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
import { FindListOptions } from './request.models';
import { Observable } from 'rxjs/internal/Observable';
import { dataService } from '../cache/builders/build-decorators';
import { VERSION } from '../shared/version.resource-type';

/**
* Service responsible for handling requests related to the Version object
*/
@Injectable()
@dataService(VERSION)
export class VersionDataService extends DataService<Version> {
protected linkPath = 'versions';

constructor(
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected store: Store<CoreState>,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected notificationsService: NotificationsService,
protected http: HttpClient,
protected comparator: DefaultChangeAnalyzer<Version>) {
super();
}

/**
* Get the endpoint for browsing versions
*/
getBrowseEndpoint(options: FindListOptions = {}, linkPath?: string): Observable<string> {
return this.halService.getEndpoint(this.linkPath);
}
}
54 changes: 54 additions & 0 deletions src/app/core/data/version-history-data.service.spec.ts
@@ -0,0 +1,54 @@
import { RequestService } from './request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../cache/object-cache.service';
import { VersionHistoryDataService } from './version-history-data.service';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service-stub';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub';
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
import { GetRequest } from './request.models';

const url = 'fake-url';

describe('VersionHistoryDataService', () => {
let service: VersionHistoryDataService;

let requestService: RequestService;
let notificationsService: any;
let rdbService: RemoteDataBuildService;
let objectCache: ObjectCacheService;
let halService: any;

beforeEach(() => {
createService();
});

describe('getVersions', () => {
let result;

beforeEach(() => {
result = service.getVersions('1');
});

it('should configure a GET request', () => {
expect(requestService.configure).toHaveBeenCalledWith(jasmine.any(GetRequest));
});
});

/**
* Create a VersionHistoryDataService used for testing
* @param requestEntry$ Supply a requestEntry to be returned by the REST API (optional)
*/
function createService(requestEntry$?) {
requestService = getMockRequestService(requestEntry$);
rdbService = jasmine.createSpyObj('rdbService', {
buildList: jasmine.createSpy('buildList')
});
objectCache = jasmine.createSpyObj('objectCache', {
remove: jasmine.createSpy('remove')
});
halService = new HALEndpointServiceStub(url);
notificationsService = new NotificationsServiceStub();

service = new VersionHistoryDataService(requestService, rdbService, null, objectCache, halService, notificationsService, null, null);
}
});

0 comments on commit fb69b1f

Please sign in to comment.