Skip to content

Commit

Permalink
Versions temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmajchrak committed Oct 25, 2023
1 parent e273423 commit c0841e5
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 18 deletions.
40 changes: 27 additions & 13 deletions src/app/item-page/versions/item-versions.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@ <h2 *ngIf="displayTitle">{{"item.version.history.head" | translate}}</h2>
<th scope="col">{{'item.version.history.table.handle' | translate}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let version of versions?.page" [id]="'version-row-' + version.id">
<tbody *ngFor="let versionWithRelations of (gelAllVersions(versions?.page) | async)" [id]="'version-row-' + versionWithRelations?.version.id">
<tr *ngFor="let relationNameHandle of versionWithRelations?.isreplacedby">
<ng-container *ngIf="versionWithRelations?.isreplacedby?.length != 0">
<td></td>
<td>{{relationNameHandle.name}}</td>
<td><a [href]="relationNameHandle.handle">{{relationNameHandle.handle}}</a></td>
</ng-container>
</tr>
<tr>
<td class="version-row-element-version">
<!-- Get the ID of the workspace/workflow item (`undefined` if they don't exist).
Conditionals inside *ngVar are needed in order to avoid useless calls. -->
<ng-container *ngVar="((hasDraftVersion$ | async) ? getWorkspaceId(version?.item) : undefined) as workspaceId$">
<ng-container *ngVar=" ((workspaceId$ | async) ? undefined : getWorkflowId(version?.item)) as workflowId$">
<ng-container *ngVar="((hasDraftVersion$ | async) ? getWorkspaceId(versionWithRelations?.version?.item) : undefined) as workspaceId$">
<ng-container *ngVar=" ((workspaceId$ | async) ? undefined : getWorkflowId(versionWithRelations?.version?.item)) as workflowId$">

<div class="left-column">

<span *ngIf="(workspaceId$ | async) || (workflowId$ | async); then versionNumberWithoutLink else versionNumberWithLink"></span>
<ng-template #versionNumberWithLink>
<a [routerLink]="getVersionRoute(version.id)">{{version.version}}</a>
<a [routerLink]="getVersionRoute(versionWithRelations?.version.id)">{{versionWithRelations?.version.version}}</a>
</ng-template>
<ng-template #versionNumberWithoutLink>
{{version.version}}
{{versionWithRelations?.version.version}}
</ng-template>
<span *ngIf="version?.id === itemVersion?.id">*</span>
<span *ngIf="versionWithRelations?.version?.id === itemVersion?.id">*</span>

<span *ngIf="workspaceId$ | async" class="text-light badge badge-primary ml-3">
{{ "item.version.history.table.workspaceItem" | translate }}
Expand All @@ -64,17 +71,17 @@ <h2 *ngIf="displayTitle">{{"item.version.history.head" | translate}}</h2>
<ng-container *ngIf="canCreateVersion$ | async">
<button class="btn btn-outline-primary btn-sm version-row-element-create"
[disabled]="isAnyBeingEdited() || (hasDraftVersion$ | async)"
(click)="createNewVersion(version)"
(click)="createNewVersion(versionWithRelations?.version)"
title="{{createVersionTitle$ | async | translate }}">
<i class="fas fa-code-branch fa-fw"></i>
</button>
</ng-container>
<!--DELETE-->
<ng-container *ngIf="canDeleteVersion$(version) | async">
<ng-container *ngIf="canDeleteVersion$(versionWithRelations?.version) | async">
<button class="btn btn-sm version-row-element-delete"
[ngClass]="isAnyBeingEdited() ? 'btn-outline-primary' : 'btn-outline-danger'"
[disabled]="isAnyBeingEdited()"
(click)="deleteVersion(version, version.id==itemVersion.id)"
(click)="deleteVersion(versionWithRelations?.version, versionWithRelations?.version.id==itemVersion.id)"
title="{{'item.version.history.table.action.deleteVersion' | translate}}">
<i class="fas fa-trash fa-fw"></i>
</button>
Expand All @@ -88,15 +95,22 @@ <h2 *ngIf="displayTitle">{{"item.version.history.head" | translate}}</h2>
</td>
<td class="version-row-element-name">
<span>
<a [href]="(getItemHandleFromVersion(version) | async)">
{{getItemNameFromVersion(version) | async }}
<a [href]="(getItemHandleFromVersion(versionWithRelations?.version) | async)">
{{getItemNameFromVersion(versionWithRelations?.version) | async }}
</a>
</span>
</td>
<td class="version-row-element-handle" *ngVar="(getItemHandleFromVersion(version) | async) as itemHandle">
<td class="version-row-element-handle" *ngVar="(getItemHandleFromVersion(versionWithRelations?.version) | async) as itemHandle">
<span><a [href]="itemHandle">{{itemHandle}}</a></span>
</td>
</tr>
<tr *ngFor="let relationNameHandle of versionWithRelations?.replaces" >
<ng-container *ngIf="versionWithRelations?.replaces?.length != 0 " >
<td></td>
<td>{{relationNameHandle.name}}</td>
<td><a [href]="relationNameHandle.handle">{{relationNameHandle.handle}}</a></td>
</ng-container>
</tr>
</tbody>
</table>
<div>*&nbsp;{{"item.version.history.selected" | translate}}</div>
Expand Down
157 changes: 152 additions & 5 deletions src/app/item-page/versions/item-versions.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, OnInit } from '@angular/core';
import { BehaviorSubject, combineLatest, Observable, of, Subscription } from 'rxjs';
import {BehaviorSubject, combineLatest, Observable, of, Subscription} from 'rxjs';
import {
getAllSucceededRemoteData,
getAllSucceededRemoteDataPayload,
Expand Down Expand Up @@ -41,8 +41,11 @@ import { PaginationService } from 'src/app/core/pagination/pagination.service';
import { Version } from '../../core/shared/version.model';
import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model';
import { followLink } from '../../shared/utils/follow-link-config.model';
import { hasValue, hasValueOperator, isNotNull } from '../../shared/empty.util';
import {hasValue, hasValueOperator, isEmpty, isNotEmpty, isNotNull} from '../../shared/empty.util';

Check failure on line 44 in src/app/item-page/versions/item-versions.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

'isEmpty' is defined but never used

Check failure on line 44 in src/app/item-page/versions/item-versions.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

'isEmpty' is defined but never used
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import isEqual from 'lodash/isEqual';
// eslint-disable-next-line lodash/import-scope
import _ from 'lodash';

Check failure on line 48 in src/app/item-page/versions/item-versions.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

'_' is defined but never used

Check failure on line 48 in src/app/item-page/versions/item-versions.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

'_' is defined but never used

@Component({
selector: 'ds-item-versions',
Expand Down Expand Up @@ -162,11 +165,15 @@ export class ItemVersionsComponent implements OnInit {
canCreateVersion$: Observable<boolean>;
createVersionTitle$: Observable<string>;

relations: BehaviorSubject<string[]> = new BehaviorSubject<string[]>([]);

/**
* Show `Editor` column in the table.
*/
showSubmitter$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);

allVersions: BehaviorSubject<VersionWithRelations[]> = new BehaviorSubject<VersionWithRelations[]>([]);

constructor(private versionHistoryService: VersionHistoryDataService,
private versionService: VersionDataService,
private itemService: ItemDataService,
Expand Down Expand Up @@ -551,16 +558,156 @@ export class ItemVersionsComponent implements OnInit {
map((item: Item) => item.firstMetadataValue('dc.identifier.uri')));
}

ngOnDestroy(): void {
this.cleanupSubscribes();
this.paginationService.clearPagination(this.options.id);
getVersionsFromMetadata(version: Version) {
return '';
}


/**
* Unsub all subscriptions
*/
cleanupSubscribes() {
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
}

getItemFromVersion(version: Version) {
return version.item
.pipe(
getFirstSucceededRemoteDataPayload(),
map((item: Item) => item)
);
}

gelAllVersions(versions: Version[]) {
this.allVersions.next([]);
// Get item from current version and check `dc.relation.replaces` and `dc.relation.isreplacedby`
console.log('len', versions.length);
// let newVersionItem: Item;

versions.forEach((version: Version) => {
version.item
.pipe(getFirstSucceededRemoteDataPayload())
.subscribe((item: Item) => {
let allReplaces = [];
console.log('item', item);

// Store version
// Store replaces
let relationReplaces: RelationNameHandle[] = [];
item.allMetadataValues('dc.relation.replaces').forEach((metadataValue: string) => {
// if (isEqual(metadataValue, item.firstMetadataValue('dc.relation.replaces'))) {
// return;
// }
const newRelationReplaces: RelationNameHandle = {
name: '',
handle: metadataValue
};
// newRelationReplaces.handle = metadataValue;
// Get name of the item with handle TODO
relationReplaces.push(newRelationReplaces);
});
// Store isreplacedby
let relationIsReplacedBy: RelationNameHandle[] = [];
const allReplacedBy = [];
// const isReplacedByMetadataValues
item.allMetadataValues('dc.relation.isreplacedby').forEach((metadataValue: string) => {
allReplacedBy.push(metadataValue);
// if (isEqual(metadataValue, item.firstMetadataValue('dc.relation.isreplacedby'))) {
// return;
// }
const newRelationIsReplacedBy: RelationNameHandle = {
name: '',
handle: metadataValue
};
// Get name of the item with handle TODO
relationIsReplacedBy.push(newRelationIsReplacedBy);
});
const newVersionWithRelations: VersionWithRelations = {
version: version,
replaces: relationReplaces,
isreplacedby: relationIsReplacedBy,
handle: item.firstMetadataValue('dc.identifier.uri')
};
if (allReplacedBy.includes(this.item.firstMetadataValue('dc.identifier.uri'))) {
newVersionWithRelations.isreplacedby = [];
}
const updatedArray = this.allVersions.value;
updatedArray.push(newVersionWithRelations);
this.allVersions.next(updatedArray);
console.log('this.allVersions', this.allVersions.value);
// newVersionItem = item;
});
});

const filteredVersions: VersionWithRelations[] = [];
// Filter all versions table: Remove record from the table where the item:
// 1. has previous version handle the same as in the `dc.relation.replaces`
// 2. has new version handle the same the as in the `dc.relation.isreplacedby`
const allReplaces = [];
const allIsReplacedBy = [];
this.allVersions.value.forEach((currentVersion: VersionWithRelations, index) => {
let previousVersion: VersionWithRelations;
let newestVersion: VersionWithRelations;

if (isNotNull(this.allVersions.value?.[index - 1])) {
newestVersion = this.allVersions.value?.[index - 1];
}
if (isNotNull(this.allVersions.value?.[index + 1])) {
previousVersion = this.allVersions.value?.[index + 1];
}

// Process previous versions
if (isNotEmpty(previousVersion)) {
const newReplaces = [];
currentVersion.replaces.forEach((relationNameHandle: RelationNameHandle) => {
if (isEqual(previousVersion.handle, relationNameHandle.handle)) {
return;
}
newReplaces.push(relationNameHandle);
});
currentVersion.replaces = newReplaces;
}

// Process newest versions
if (isNotEmpty(newestVersion)) {
const newIsReplacedBy = [];
currentVersion.isreplacedby.forEach((relationNameHandle: RelationNameHandle) => {
if (isEqual(newestVersion.handle, relationNameHandle.handle)) {
return;
}
newIsReplacedBy.push(relationNameHandle);
});
currentVersion.isreplacedby = newIsReplacedBy;
}
filteredVersions.push(currentVersion);



console.log('current', currentVersion);
console.log('newestVersion', newestVersion);
console.log('previousVersion', previousVersion);
// if (isEqual(metadataValue, item.firstMetadataValue('dc.relation.replaces'))) {}
});
this.allVersions.next(filteredVersions);

return this.allVersions;
}

ngOnDestroy(): void {
this.cleanupSubscribes();
this.paginationService.clearPagination(this.options.id);
}

}

export interface VersionWithRelations {
version: Version;
handle: string,
replaces: RelationNameHandle[];
isreplacedby: RelationNameHandle[];
}

export interface RelationNameHandle {
name: string,
handle: string
}

0 comments on commit c0841e5

Please sign in to comment.