Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resource): update resource's label (DSP-1801) #492

Merged
merged 2 commits into from Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 38 additions & 14 deletions src/app/main/dialog/dialog.component.html
Expand Up @@ -281,21 +281,24 @@
<div *ngSwitchCase="'updateCardinality'">
<app-dialog-header [title]="data.title" [subtitle]="data.subtitle">
</app-dialog-header>
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position" [canSetFullCardinality]="data.canBeUpdated" (closeDialog)="dialogRef.close()">
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position"
[canSetFullCardinality]="data.canBeUpdated" (closeDialog)="dialogRef.close()">
</app-property-form>
</div>

<div *ngSwitchCase="'createProperty'">
<app-dialog-header [title]="data.title" [subtitle]="data.subtitle">
</app-dialog-header>
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position" [canSetFullCardinality]="data.canBeUpdated" (closeDialog)="dialogRef.close()">
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position"
[canSetFullCardinality]="data.canBeUpdated" (closeDialog)="dialogRef.close()">
</app-property-form>
</div>

<div *ngSwitchCase="'editProperty'">
<app-dialog-header [title]="data.title" [subtitle]="data.subtitle">
</app-dialog-header>
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position" [canSetFullCardinality]="data.canBeUpdated" (closeDialog)="dialogRef.close()">
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position"
[canSetFullCardinality]="data.canBeUpdated" (closeDialog)="dialogRef.close()">
</app-property-form>
</div>

Expand Down Expand Up @@ -324,20 +327,40 @@
</app-resource-instance-form>
</div>

<div *ngSwitchCase="'editResource'">
<app-dialog-header [title]="data.title" [subtitle]="'Edit resource\'s label'">
</app-dialog-header>
<mat-dialog-content class="form-content">
<mat-form-field class="large-field">
<input matInput placeholder="Label" [value]="data.title" (keyup)="onKey($event)">
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button mat-dialog-close class="cancel-button center"
[mat-dialog-close]="{confirmed: false, comment: comment}">
Cancel
</button>
<span class="fill-remaining-space"></span>
<button mat-button mat-raised-button [color]="'primary'" class="confirm-button center"
[mat-dialog-close]="{confirmed: true, comment: comment}" [disabled]="!comment">
Save
</button>
</mat-dialog-actions>
</div>

<div *ngSwitchCase="'deleteResource'">
<app-dialog-header [title]="data.title" [subtitle]="'Delete resource instance'"></app-dialog-header>
<mat-dialog-content>
<mat-dialog-content class="form-content">
<mat-form-field class="large-field">
<mat-label>Comment why resource is being deleted</mat-label>
<textarea matInput class="deletion-comment" type="text" (keyup)="onKey($event)"
[placeholder]="'Ex. Resource was created by mistake...'"></textarea>
</mat-form-field>
Do you want to delete this resource?
<textarea
matinput
class="deletion-comment"
type="text"
(keyup)="onKey($event)"
[placeholder]="'Comment why resource is being deleted'"
></textarea>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button mat-dialog-close class="cancel-button center" [mat-dialog-close]="{confirmed: false, comment: comment}">
<button mat-button mat-dialog-close class="cancel-button center"
[mat-dialog-close]="{confirmed: false, comment: comment}">
No, keep it
</button>
<span class="fill-remaining-space"></span>
Expand All @@ -350,9 +373,10 @@

<div *ngSwitchCase="'eraseResource'">
<app-dialog-header [title]="data.title" [subtitle]="'Delete resource'"></app-dialog-header>
Do you want to erase this resource forever?<br>WARNING: This action cannot be undone, so use it with care.
Do you want to erase this resource forever?<br><br>WARNING: This action cannot be undone, so use it with care.
<mat-dialog-actions>
<button mat-button mat-dialog-close class="cancel-button center" [mat-dialog-close]="{confirmed: false, comment: comment}">
<button mat-button mat-dialog-close class="cancel-button center"
[mat-dialog-close]="{confirmed: false, comment: comment}">
No, keep it
</button>
<span class="fill-remaining-space"></span>
Expand Down
4 changes: 4 additions & 0 deletions src/app/main/dialog/dialog.component.scss
Expand Up @@ -11,3 +11,7 @@
padding: 8px;
height: 64px;
}

.mat-dialog-content {
margin: 0 auto;
}
Expand Up @@ -5,6 +5,7 @@
<h3 class="label mat-title">
{{resource.res.label}} <span *ngIf="deletedResource">(deleted)</span>
</h3>

<span class="fill-remaining-space"></span>

<!-- tools: share, add to favorites, edit, delete etc. -->
Expand Down Expand Up @@ -55,6 +56,10 @@ <h3 class="label mat-title">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #more="matMenu" class="res-more-menu">
<button mat-menu-item matTooltip="Edit the label of this resource" matTooltipPosition="above" (click)="openDialog('edit')">
<mat-icon>edit</mat-icon>
Edit label
</button>
<button mat-menu-item matTooltip="Move resource to trash bin." matTooltipPosition="above" (click)="openDialog('delete')">
<mat-icon>delete</mat-icon>
Delete resource
Expand Down
81 changes: 52 additions & 29 deletions src/app/workspace/resource/properties/properties.component.ts
Expand Up @@ -20,6 +20,8 @@ import {
ReadUser,
ReadValue,
ResourcePropertyDefinition,
UpdateResourceMetadata,
UpdateResourceMetadataResponse,
UserResponse
} from '@dasch-swiss/dsp-js';
import {
Expand Down Expand Up @@ -226,7 +228,7 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
// --> TODO: pop up resource preview on hover
}

openDialog(type: 'delete' | 'erase') {
openDialog(type: 'delete' | 'erase' | 'edit') {
const dialogConfig: MatDialogConfig = {
width: '560px',
maxHeight: '80vh',
Expand All @@ -245,39 +247,60 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {

if (answer.confirmed === true) {

const payload = new DeleteResource();
payload.id = this.resource.res.id;
payload.type = this.resource.res.type;
payload.deleteComment = answer.comment ? answer.comment : undefined;
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'
this._notification.openSnackBar(`${response.result}: ${this.resource.res.label}`);
this.deletedResource = true;
if (type !== 'edit') {

const payload = new DeleteResource();
payload.id = this.resource.res.id;
payload.type = this.resource.res.type;
payload.deleteComment = answer.comment ? answer.comment : undefined;
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'
this._notification.openSnackBar(`${response.result}: ${this.resource.res.label}`);
this.deletedResource = true;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
);
break;

case 'erase':
// erase the resource and refresh the view
this._dspApiConnection.v2.res.eraseResource(payload).subscribe(
(response: DeleteResourceResponse) => {
// display notification and mark resource as 'erased'
this._notification.openSnackBar(`${response.result}: ${this.resource.res.label}`);
this.deletedResource = true;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
);
break;
}
} else {

// update resource's label if it has changed
if (this.resource.res.label !== answer.comment) {
const payload = new UpdateResourceMetadata();
payload.id = this.resource.res.id;
payload.type = this.resource.res.type;
payload.lastModificationDate = this.lastModificationDate;
payload.label = answer.comment;
this._dspApiConnection.v2.res.updateResourceMetadata(payload).subscribe(
(response: UpdateResourceMetadataResponse) => {
this.resource.res.label = payload.label;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
);
break;

case 'erase':
// erase the resource and refresh the view
this._dspApiConnection.v2.res.eraseResource(payload).subscribe(
(response: DeleteResourceResponse) => {
// display notification and mark resource as 'erased'
this._notification.openSnackBar(`${response.result}: ${this.resource.res.label}`);
this.deletedResource = true;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
);
break;
}
}

}
Expand Down