Skip to content

Commit

Permalink
fix(resource): get last modification date after editing a prop value
Browse files Browse the repository at this point in the history
  • Loading branch information
kilchenmann committed Jul 23, 2021
1 parent 941e95d commit ad54fa8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<!-- toolbar -->
<div class="toolbar" *ngIf="project">
<div class="toolbar" *ngIf="project" [class.deleted]="deletedResource">
<!-- resource info -->
<h3 class="label mat-title">
{{resource.res.label}} <span *ngIf="deletedResource">(deleted)</span>
Expand All @@ -12,7 +12,7 @@ <h3 class="label mat-title">

<!-- Toggle list of properties: all or only the ones with value -->
<button mat-icon-button class="toggle-props" [matTooltip]="(showAllProps ? 'Hide empty' : 'Show all')+' properties'" matTooltipPosition="above"
(click)="showAllProps = !showAllProps">
(click)="toggleAllProps(showAllProps)">
<mat-icon>{{showAllProps ? 'unfold_less' : 'unfold_more'}}</mat-icon>
<!-- <span class="desktop-only">{{showAllProps ? 'Hide empty' : 'Show all'}} properties</span> -->
</button>
Expand All @@ -26,6 +26,7 @@ <h3 class="label mat-title">

<!-- Share resource: copy ark url, add to favorites or open in new tab -->
<button mat-icon-button class="share-res" matTooltip="Share resource: {{resource.res.versionArkUrl}}" matTooltipPosition="above"
[disabled]="deletedResource"
[matMenuTriggerFor]="share">
<mat-icon>share</mat-icon>
<!-- <span class="desktop-only">Citation Link</span> -->
Expand All @@ -50,7 +51,7 @@ <h3 class="label mat-title">
</mat-menu>

<!-- more menu with: delete, erase resource -->
<button *ngIf="editPermissions" mat-icon-button class="more-menu" matTooltip="More" matTooltipPosition="above" [matMenuTriggerFor]="more">
<button *ngIf="editPermissions" mat-icon-button class="more-menu" matTooltip="More" matTooltipPosition="above" [matMenuTriggerFor]="more" [disabled]="deletedResource">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #more="matMenu" class="res-more-menu">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
color: rgba(0, 0, 0, 0.87);
}
.toolbar {
background: whitesmoke;
background: $primary_200;

&.deleted {
background: $warn;
}

.label {
margin: 0 !important;
Expand Down
44 changes: 39 additions & 5 deletions src/app/workspace/resource/properties/properties.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ProjectResponse,
ReadLinkValue,
ReadProject,
ReadResource,
ReadResourceSequence,
ReadTextValueAsXml,
ReadUser,
Expand Down Expand Up @@ -92,6 +93,8 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
*/
@Output() referredResourceHovered: EventEmitter<ReadLinkValue> = new EventEmitter<ReadLinkValue>();

lastModificationDate: string;

deletedResource = false;

addButtonIsVisible: boolean; // used to toggle add value button
Expand Down Expand Up @@ -124,6 +127,9 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
this.resource.res.userHasPermission as 'RV' | 'V' | 'M' | 'D' | 'CR'
);

// get last modification date
this.lastModificationDate = this.resource.res.lastModificationDate;

// if user has modify permissions, set addButtonIsVisible to true so the user see's the add button
this.addButtonIsVisible = allPermissions.indexOf(PermissionUtil.Permissions.M) !== -1;
}
Expand All @@ -150,6 +156,13 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
this.valueOperationEventSubscriptions.push(this._valueOperationEventService.on(
Events.ValueDeleted, (deletedValue: DeletedEventValue) => this.deleteValueFromResource(deletedValue.deletedValue)
));

// keep the information if the user wants to display all properties or not
if (localStorage.getItem('showAllProps')) {
this.showAllProps = JSON.parse(localStorage.getItem('showAllProps'));
} else {
localStorage.setItem('showAllProps', JSON.stringify(this.showAllProps));
}
}

ngOnChanges(): void {
Expand Down Expand Up @@ -214,7 +227,7 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
position: {
top: '112px'
},
data: { mode: type+'Resource', title: this.resource.res.label }
data: { mode: type + 'Resource', title: this.resource.res.label }
};

const dialogRef = this._dialog.open(
Expand All @@ -230,9 +243,10 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
payload.id = this.resource.res.id;
payload.type = this.resource.res.type;
payload.deleteComment = answer.comment ? answer.comment : undefined;
// delete and refresh the view
payload.lastModificationDate = this.lastModificationDate;
switch (type) {
case 'delete':
// delete the resource and refresh the view
this._dspApiConnection.v2.res.deleteResource(payload).subscribe(
(response: DeleteResourceResponse) => {
// display notification and mark resource as 'deleted'
Expand All @@ -246,7 +260,7 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
break;

case 'erase':
// delete resource class and refresh the view
// erase the resource and refresh the view
this._dspApiConnection.v2.res.eraseResource(payload).subscribe(
(response: DeleteResourceResponse) => {
// display notification and mark resource as 'erased'
Expand Down Expand Up @@ -322,8 +336,12 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
this.resource.resProps
.filter(propInfoValueArray =>
propInfoValueArray.propDef.id === valueToAdd.property) // filter to the correct property
.forEach(propInfoValue =>
propInfoValue.values.push(valueToAdd)); // push new value to array
.forEach(propInfoValue => {
propInfoValue.values.push(valueToAdd); // push new value to array
// update last modification date
this._getLastModificationDate(this.resource.res.id);
});

if (valueToAdd instanceof ReadTextValueAsXml) {
this._updateStandoffLinkValue();
}
Expand All @@ -348,6 +366,8 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
filteredpropInfoValueArray.values.forEach((val, index) => { // loop through each value of the current property
if (val.id === valueToReplace.id) { // find the value that should be updated using the id of valueToReplace
filteredpropInfoValueArray.values[index] = updatedValue; // replace value with the updated value
// update last modification date
this._getLastModificationDate(this.resource.res.id);
}
});
});
Expand All @@ -373,6 +393,9 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
filteredpropInfoValueArray.values.forEach((val, index) => { // loop through each value of the current property
if (val.id === valueToDelete.id) { // find the value that was deleted using the id
filteredpropInfoValueArray.values.splice(index, 1); // remove the value from the values array
// update last modification date
this._getLastModificationDate(this.resource.res.id);

if (val instanceof ReadTextValueAsXml) {
this._updateStandoffLinkValue();
}
Expand All @@ -385,6 +408,11 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
}
}

toggleAllProps(status: boolean) {
this.showAllProps = !status;
localStorage.setItem('showAllProps', JSON.stringify(this.showAllProps));
}

/**
* updates the standoff link value for the resource being displayed.
*
Expand Down Expand Up @@ -443,4 +471,10 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
);

}

private _getLastModificationDate(resId: string) {
this._dspApiConnection.v2.res.getResource(resId).subscribe(
(res: ReadResource) => this.lastModificationDate = res.lastModificationDate
);
}
}

0 comments on commit ad54fa8

Please sign in to comment.