diff --git a/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.html b/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.html index 38bcd3e85..ae04b93c5 100644 --- a/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.html +++ b/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.html @@ -30,7 +30,7 @@ -
{{'ANNOTATION-DIALOG.TITLE' | translate}}
+
{{'ANNOTATION-DIALOG.TITLE' | translate}}
@@ -43,12 +43,12 @@
-
{{thread.timeStamp | date:'EEEE, MMMM d, y, h:mm a'}}
-
{{getAnnotationProtectionType(thread)}}
-
{{getAnnotationProtectionType(thread)}}
-
{{thread.payload}}
+
{{getParentAnnotation(thread).timeStamp | date:'EEEE, MMMM d, y, h:mm a'}}
+
{{getAnnotationProtectionType(thread)}}
+
{{getAnnotationProtectionType(thread)}}
+
{{getParentAnnotation(thread).payload}}
- {{'ANNOTATION-DIALOG.THREADS.FROM-USER' | translate}} {{thread.author.name}} + {{'ANNOTATION-DIALOG.THREADS.FROM-USER' | translate}} {{getParentAnnotation(thread).author.name}}
@@ -59,10 +59,10 @@
-
+
-
+
@@ -72,7 +72,7 @@
{{annotation.timeStamp | date:'EEEE, MMMM d, y, h:mm a'}}
-
{{annotation.text}}
+
{{annotation.payload}}
{{'ANNOTATION-DIALOG.THREADS.FROM-USER' | translate}} {{annotation.author.name}} @@ -89,11 +89,11 @@
- - {{'COMMONS.VALIDATION.REQUIRED' | translate}} + + {{'COMMONS.VALIDATION.REQUIRED' | translate}}
-
diff --git a/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.ts b/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.ts index 0ab4da412..fbaa3dc16 100644 --- a/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.ts +++ b/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.ts @@ -30,10 +30,11 @@ export class AnnotationDialogComponent extends BaseComponent { private entityId: Guid; private anchor: string; private entityType: string; - // public annotations: Array = []; - public threads = new Array(); + public comments = new Array(); + public threads = new Set(); public annotationsPerThread = {}; + public parentAnnotationsPerThread = {}; threadReplyTextsFG: Array; threadFormGroup: UntypedFormGroup; private formBuilder: FormBuilder = new FormBuilder(); @@ -73,6 +74,7 @@ export class AnnotationDialogComponent extends BaseComponent { return; } const threadToCreate: AnnotationPersist = { + threadId: Guid.create(), payload: this.threadFormGroup.get('text').value, protectionType: this.threadFormGroup.get('protectionType').value, entityId: this.entityId, @@ -86,7 +88,7 @@ export class AnnotationDialogComponent extends BaseComponent { ); } - replyThread(threadId: Guid, threadProtection: AnnotationProtectionType) { + replyThread(threadId: Guid) { // if (!this.threadReplyTexts[threadId.toString()] || this.threadReplyTexts[threadId.toString()].length === 0) { return; } this.formService.removeAllBackEndErrors(this.threadReplyTextsFG[threadId.toString()]); this.formService.touchAllFormFields(this.threadReplyTextsFG[threadId.toString()]); @@ -96,10 +98,11 @@ export class AnnotationDialogComponent extends BaseComponent { const replyToCreate: AnnotationPersist = { threadId: threadId, payload: this.threadReplyTextsFG[threadId.toString()].get('replyText').value, - protectionType: threadProtection, + protectionType: this.parentAnnotationsPerThread[threadId.toString()].protectionType, entityId: this.entityId, entityType: this.entityType, - anchor: this.anchor + anchor: this.anchor, + parentId: this.parentAnnotationsPerThread[threadId.toString()].id }; this.annotationService.persist(replyToCreate).pipe(takeUntil(this._destroyed)) .subscribe( @@ -118,12 +121,13 @@ export class AnnotationDialogComponent extends BaseComponent { private loadThreads() { const lookup: AnnotationLookup = new AnnotationLookup(); lookup.entityIds = [this.entityId]; - // lookup.anchors = [this.anchor]; + lookup.anchors = [this.anchor]; lookup.entityTypes = [this.entityType]; lookup.project = { fields: [ nameof(x => x.id), nameof(x => x.threadId), + nameof(x => x.parent.id), nameof(x => x.timeStamp), nameof(x => x.author.name), nameof(x => x.payload), @@ -135,23 +139,33 @@ export class AnnotationDialogComponent extends BaseComponent { .pipe(takeUntil(this._destroyed)) .subscribe( data => { - // this.annotationsPerThread = {}; - // this.threadReplyTextsFG = new Array(); - // this.resetFormGroup(); - // this.threads = data.items.filter(item => item.id === item.threadId).sort((a1, a2) => new Date(a2.timeStamp).getTime() - new Date(a1.timeStamp).getTime()); - // this.threads.forEach(element => { - // // this.threadReplyTextsFG.addControl(element.id.toString(), new FormControl(null)); - // this.threadReplyTextsFG[element.id.toString()] = this.fb.group({ replyText: new FormControl(null, [Validators.required]) }); - // this.annotationsPerThread[element.id.toString()] = data.items.filter(x => x.threadId === element.id && x.id !== element.id).sort((a1, a2) => new Date(a1.timeStamp).getTime() - new Date(a2.timeStamp).getTime()); - // }); - // // this.annotationsChanged.emit(this.threads); - - this.threads = data.items; + this.annotationsPerThread = {}; + this.parentAnnotationsPerThread = {}; + this.threads = new Set(); + this.threadReplyTextsFG = new Array(); + this.resetFormGroup(); + this.comments = data.items.sort((a1, a2) => new Date(a2.timeStamp).getTime() - new Date(a1.timeStamp).getTime()); + this.comments.forEach(element => { + // this.threadReplyTextsFG.addControl(element.id.toString(), new FormControl(null)); + this.threadReplyTextsFG[element.threadId.toString()] = this.formBuilder.group({ replyText: new FormControl(null, [Validators.required]) }); + this.annotationsPerThread[element.threadId.toString()] = data.items.filter(x => x.threadId === element.threadId && x.id !== element.id).sort((a1, a2) => new Date(a1.timeStamp).getTime() - new Date(a2.timeStamp).getTime()); + this.parentAnnotationsPerThread[element.threadId.toString()] = data.items.filter(x => x.threadId === element.threadId && x.id === element.id)[0]; + this.threads.add(element.threadId); + }); + // console.log(this.comments); + // console.log(this.threads); + // console.log(this.parentAnnotationsPerThread); + // console.log(this.annotationsPerThread); + // this.annotationsChanged.emit(this.threads); }, error => this.onCallbackError(error), ); } + getParentAnnotation(thread: Guid): Annotation { + return this.parentAnnotationsPerThread[thread.toString()]; + } + resetFormGroup() { this.threadFormGroup.reset(); this.threadFormGroup.get('protectionType').setValue(AnnotationProtectionType.EntityAccessors); @@ -181,8 +195,9 @@ export class AnnotationDialogComponent extends BaseComponent { } private onCallbackSuccess() { - this.uiNotificationService.snackBarNotification(this.language.instant('DMP-UPLOAD.UPLOAD-SUCCESS'), SnackBarNotificationLevel.Success); - this.router.navigate(['/reload']).then(() => this.router.navigate(['/plans'])); + this.uiNotificationService.snackBarNotification(this.language.instant('ANNOTATION-DIALOG.SUCCESS'), SnackBarNotificationLevel.Success); + this.refreshAnnotations(); + // this.router.navigate(['/reload']).then(() => this.router.navigate(['/plans'])); // this.router.navigate(['/reload']).then(() => this.isPublic ? this.router.navigate(['/explore-plans']) : this.router.navigate(['/plans'])); } @@ -191,8 +206,8 @@ export class AnnotationDialogComponent extends BaseComponent { } - getAnnotationProtectionType(thread: Annotation): string { - return this.enumUtils.toAnnotationProtectionTypeString(thread.protectionType); + getAnnotationProtectionType(thread: Guid): string { + return this.enumUtils.toAnnotationProtectionTypeString(this.parentAnnotationsPerThread[thread.toString()].protectionType); } diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts index fff43d34b..e16683ec9 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts @@ -127,6 +127,7 @@ export class DescriptionFormFieldSetComponent extends BaseComponent { const dialogRef = this.dialog.open(AnnotationDialogComponent, { width: '40rem', maxWidth: '90vw', + maxHeight: '90vh', data: { entityId: this.descriptionId, anchor: fieldSetId,