Skip to content
Snippets Groups Projects
Commit a7475ff9 authored by Klaus-Dieter Quibeldey-Cirkel's avatar Klaus-Dieter Quibeldey-Cirkel
Browse files

Merge branch '612-implement-deepl-api' into 'staging'

Resolve "Implement DeepL API"

Closes #612

See merge request arsnova/frag.jetzt!567
parents 18156e58 7e149cb4
Branches
Tags
No related merge requests found
Showing
with 313 additions and 137 deletions
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
"builder": "@angular-devkit/build-angular:dev-server", "builder": "@angular-devkit/build-angular:dev-server",
"options": { "options": {
"browserTarget": "arsnova-angular-frontend:build", "browserTarget": "arsnova-angular-frontend:build",
"proxyConfig": "proxy.conf.json" "proxyConfig": "proxy.conf.js"
}, },
"configurations": { "configurations": {
"production": { "production": {
......
{ const PROXY_CONFIG = {
"/languagetool": { "/deepl": {
"target": "https://lt.frag.jetzt/v2/check", "target": "https://api-free.deepl.com/v2",
"secure": true, "secure": true,
"changeOrigin": true, "changeOrigin": true,
"pathRewrite": { "logLevel": "debug",
"^/languagetool": "" "router": function (req) {
}, const DEEPL_API_KEY = 'DEEPL_API_KEY';
"logLevel": "debug" req.url = req.url.substr(6) + '&auth_key=' + DEEPL_API_KEY;
}, return 'https://api-free.deepl.com/v2';
"/spacy": { }
"target": "https://spacy.frag.jetzt/spacy", },
"secure": true, "/languagetool": {
"changeOrigin": true, "target": "https://lt.frag.jetzt/v2/check",
"pathRewrite": { "secure": true,
"^/spacy": "" "changeOrigin": true,
}, "pathRewrite": {
"logLevel": "debug" "^/languagetool": ""
}, },
"/api/ws/websocket": { "logLevel": "debug"
"target": "ws://localhost:8080", },
"secure": false, "/spacy": {
"pathRewrite": { "target": "https://spacy.frag.jetzt/spacy",
"^/api": "" "secure": true,
}, "changeOrigin": true,
"ws": true, "pathRewrite": {
"logLevel": "debug" "^/spacy": ""
}, },
"/api/roomsubscription": { "logLevel": "debug"
"target": "http://localhost:8080", },
"secure": false, "/api/ws/websocket": {
"pathRewrite": { "target": "ws://localhost:8080",
"^/api": "" "secure": false,
}, "pathRewrite": {
"logLevel": "debug" "^/api": ""
}, },
"/api": { "ws": true,
"target": "http://localhost:8888", "logLevel": "debug"
"secure": false, },
"pathRewrite": { "/api/roomsubscription": {
"^/api": "" "target": "http://localhost:8080",
}, "secure": false,
"logLevel": "debug" "pathRewrite": {
} "^/api": ""
} },
"logLevel": "debug"
},
"/api": {
"target": "http://localhost:8888",
"secure": false,
"pathRewrite": {
"^/api": ""
},
"logLevel": "debug"
}
};
module.exports = PROXY_CONFIG;
<div mat-dialog-content <div mat-dialog-content
*ngIf="editRoom"> *ngIf="editRoom">
<h2 class="oldtypo-h2">{{ 'room-page.description' | translate }}</h2> <h2 class="oldtypo-h2">{{ 'room-page.description' | translate }}</h2>
<mat-tab-group> <app-write-comment [isModerator]="true"
<mat-tab label="{{'room-page.tab1' | translate}}"> [placeholder]="''"
<mat-form-field class="input-block" style="width:100%;min-width:100%;"> [onClose]="buildCloseDialogActionCallback()"
<textarea [onSubmit]="buildSaveActionCallback()"
(focus)="eventService.makeFocusOnInputTrue()" [i18nSection]="'room-page'"
(blur)="eventService.makeFocusOnInputFalse()" [confirmLabel]="'update'">
[(ngModel)]="editRoom.description" </app-write-comment>
matInput
matTextareaAutosize
matAutosizeMinRows="2"
matAutosizeMaxRows="5"
maxlength="500"
name="description"
aria-labelledby="description"
></textarea>
<mat-hint align="end">
<span aria-hidden="true">
{{ editRoom.description?editRoom.description.length:0 }} / 500
</span>
</mat-hint>
</mat-form-field>
</mat-tab>
<mat-tab label="{{'session.preview' | translate}}"
[disabled]="!editRoom.description">
<app-custom-markdown class="images" [data]="editRoom.description"></app-custom-markdown>
</mat-tab>
</mat-tab-group>
</div> </div>
<app-dialog-action-buttons
buttonsLabelSection="room-page"
confirmButtonLabel="update"
[cancelButtonClickAction]="buildCloseDialogActionCallback()"
[confirmButtonClickAction]="buildSaveActionCallback()"
></app-dialog-action-buttons>
import {Component,Inject,OnInit} from '@angular/core'; import { AfterViewInit, Component, Inject, ViewChild } from '@angular/core';
import {MAT_DIALOG_DATA,MatDialog,MatDialogRef} from '@angular/material/dialog'; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
import {RoomCreatorPageComponent} from '../../room-creator-page/room-creator-page.component'; import { RoomCreatorPageComponent } from '../../room-creator-page/room-creator-page.component';
import {NotificationService} from '../../../../services/util/notification.service'; import { NotificationService } from '../../../../services/util/notification.service';
import {TranslateService} from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import {RoomService} from '../../../../services/http/room.service'; import { RoomService } from '../../../../services/http/room.service';
import {Router} from '@angular/router'; import { Router } from '@angular/router';
import {EventService} from '../../../../services/util/event.service'; import { EventService } from '../../../../services/util/event.service';
import {ProfanityFilter,Room} from '../../../../models/room'; import { Room } from '../../../../models/room';
import {FormControl,Validators} from '@angular/forms'; import { FormControl, Validators } from '@angular/forms';
import { WriteCommentComponent } from '../../../shared/write-comment/write-comment.component';
@Component({ @Component({
selector:'app-room-description-settings', selector: 'app-room-description-settings',
templateUrl:'./room-description-settings.component.html', templateUrl: './room-description-settings.component.html',
styleUrls:['./room-description-settings.component.scss'] styleUrls: ['./room-description-settings.component.scss']
}) })
export class RoomDescriptionSettingsComponent implements OnInit{ export class RoomDescriptionSettingsComponent implements AfterViewInit {
@ViewChild(WriteCommentComponent) writeComment: WriteCommentComponent;
editRoom: Room; editRoom: Room;
roomNameFormControl=new FormControl('',[Validators.required,Validators.minLength(3),Validators.maxLength(30)]); roomNameFormControl = new FormControl('', [Validators.required, Validators.minLength(3), Validators.maxLength(30)]);
constructor(public dialogRef: MatDialogRef<RoomCreatorPageComponent>, constructor(public dialogRef: MatDialogRef<RoomCreatorPageComponent>,
public dialog: MatDialog, public dialog: MatDialog,
...@@ -25,30 +28,34 @@ export class RoomDescriptionSettingsComponent implements OnInit{ ...@@ -25,30 +28,34 @@ export class RoomDescriptionSettingsComponent implements OnInit{
protected roomService: RoomService, protected roomService: RoomService,
public router: Router, public router: Router,
public eventService: EventService, public eventService: EventService,
@Inject(MAT_DIALOG_DATA) public data: any){ @Inject(MAT_DIALOG_DATA) public data: any) {
} }
ngOnInit(){ ngAfterViewInit() {
if (this.editRoom) {
this.writeComment.commentData.currentData = this.editRoom.description;
}
} }
buildCloseDialogActionCallback(): () => void{ buildCloseDialogActionCallback(): () => void {
return ()=>this.closeDialog('abort'); return () => this.closeDialog('abort');
} }
buildSaveActionCallback(): () => void{ buildSaveActionCallback(): () => void {
return ()=>this.save(); return () => this.save();
} }
closeDialog(type: string): void{ closeDialog(type: string): void {
this.dialogRef.close(type); this.dialogRef.close(type);
} }
save(): void{ save(): void {
this.roomService.updateRoom(this.editRoom).subscribe(r=>this.editRoom=r); this.editRoom.description = this.writeComment.commentData.currentData;
if(!this.roomNameFormControl.hasError('required') this.roomService.updateRoom(this.editRoom).subscribe(r => this.editRoom = r);
if (!this.roomNameFormControl.hasError('required')
&& !this.roomNameFormControl.hasError('minlength') && !this.roomNameFormControl.hasError('minlength')
&& !this.roomNameFormControl.hasError('maxlength')){ && !this.roomNameFormControl.hasError('maxlength')) {
this.closeDialog('update'); this.closeDialog('update');
} }
this.closeDialog('update'); this.closeDialog('update');
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</mat-tab> </mat-tab>
<mat-tab label="{{'session.preview' | translate}}" <mat-tab label="{{'session.preview' | translate}}"
[disabled]="!editRoom.description"> [disabled]="!editRoom.description">
<app-custom-markdown class="images" [data]="editRoom.description"></app-custom-markdown> <app-view-comment-data class="images" [currentData]="editRoom.description"></app-view-comment-data>
</mat-tab> </mat-tab>
</mat-tab-group> </mat-tab-group>
<div fxLayout="column"> <div fxLayout="column">
......
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
</div> </div>
<mat-card-content *ngIf="room.description" <mat-card-content *ngIf="room.description"
fxLayoutAlign="center"> fxLayoutAlign="center">
<app-custom-markdown class="images" [data]="room.description.trim()"></app-custom-markdown> <app-view-comment-data class="images" [currentData]="room.description"></app-view-comment-data>
</mat-card-content> </mat-card-content>
<div fxLayout="column" <div fxLayout="column"
fxLayoutAlign="center" fxLayoutAlign="center"
......
import { Component, OnInit, Renderer2, OnDestroy, AfterContentInit } from '@angular/core'; import { Component, OnInit, Renderer2, OnDestroy, AfterContentInit } from '@angular/core';
import { RoomService } from '../../../services/http/room.service'; import { RoomService } from '../../../services/http/room.service';
import {ActivatedRoute,Router} from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { RoomPageComponent } from '../../shared/room-page/room-page.component'; import { RoomPageComponent } from '../../shared/room-page/room-page.component';
import {ProfanityFilter,Room} from '../../../models/room'; import { Room } from '../../../models/room';
import { CommentSettingsDialog } from '../../../models/comment-settings-dialog'; import { CommentSettingsDialog } from '../../../models/comment-settings-dialog';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { NotificationService } from '../../../services/util/notification.service'; import { NotificationService } from '../../../services/util/notification.service';
...@@ -10,7 +10,6 @@ import { MatDialog } from '@angular/material/dialog'; ...@@ -10,7 +10,6 @@ import { MatDialog } from '@angular/material/dialog';
import { RoomEditComponent } from '../_dialogs/room-edit/room-edit.component'; import { RoomEditComponent } from '../_dialogs/room-edit/room-edit.component';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { LanguageService } from '../../../services/util/language.service'; import { LanguageService } from '../../../services/util/language.service';
import { TSMap } from 'typescript-map';
import { WsCommentService } from '../../../services/websockets/ws-comment.service'; import { WsCommentService } from '../../../services/websockets/ws-comment.service';
import { CommentService } from '../../../services/http/comment.service'; import { CommentService } from '../../../services/http/comment.service';
import { ModeratorsComponent } from '../_dialogs/moderators/moderators.component'; import { ModeratorsComponent } from '../_dialogs/moderators/moderators.component';
...@@ -26,14 +25,10 @@ import { DeleteCommentsComponent } from '../_dialogs/delete-comments/delete-comm ...@@ -26,14 +25,10 @@ import { DeleteCommentsComponent } from '../_dialogs/delete-comments/delete-comm
import { Export } from '../../../models/export'; import { Export } from '../../../models/export';
import { BonusTokenService } from '../../../services/http/bonus-token.service'; import { BonusTokenService } from '../../../services/http/bonus-token.service';
import { TopicCloudFilterComponent } from '../../shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component'; import { TopicCloudFilterComponent } from '../../shared/_dialogs/topic-cloud-filter/topic-cloud-filter.component';
import {HeaderService} from '../../../services/util/header.service'; import { RoomDeleteComponent } from '../_dialogs/room-delete/room-delete.component';
import {RoomDeleteComponent} from '../_dialogs/room-delete/room-delete.component'; import { RoomDeleted } from '../../../models/events/room-deleted';
import {RoomDeleted} from '../../../models/events/room-deleted'; import { ProfanitySettingsComponent } from '../_dialogs/profanity-settings/profanity-settings.component';
import {ProfanitySettingsComponent} from '../_dialogs/profanity-settings/profanity-settings.component'; import { RoomDescriptionSettingsComponent } from '../_dialogs/room-description-settings/room-description-settings.component';
import {RoomDescriptionSettingsComponent} from '../_dialogs/room-description-settings/room-description-settings.component';
import {ModeratorDeleteComponent} from '../_dialogs/moderator-delete/moderator-delete.component';
import {ModeratorCommentPageComponent} from '../../moderator/moderator-comment-page/moderator-comment-page.component';
import {ModeratorCommentListComponent} from '../../moderator/moderator-comment-list/moderator-comment-list.component';
@Component({ @Component({
selector: 'app-room-creator-page', selector: 'app-room-creator-page',
...@@ -110,9 +105,12 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni ...@@ -110,9 +105,12 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni
editSessionDescription(){ editSessionDescription(){
const dialogRef = this.dialog.open(RoomDescriptionSettingsComponent, { const dialogRef = this.dialog.open(RoomDescriptionSettingsComponent, {
width: '400px' width: '900px',
maxWidth: 'calc( 100% - 50px )',
maxHeight: 'calc( 100vh - 50px )',
autoFocus: false
}); });
dialogRef.componentInstance.editRoom=this.room; dialogRef.componentInstance.editRoom = this.room;
} }
exportQuestions(){ exportQuestions(){
......
...@@ -19,7 +19,6 @@ import { ModeratorsComponent } from '../../creator/_dialogs/moderators/moderator ...@@ -19,7 +19,6 @@ import { ModeratorsComponent } from '../../creator/_dialogs/moderators/moderator
import { TagsComponent } from '../../creator/_dialogs/tags/tags.component'; import { TagsComponent } from '../../creator/_dialogs/tags/tags.component';
import { DeleteCommentsComponent } from '../../creator/_dialogs/delete-comments/delete-comments.component'; import { DeleteCommentsComponent } from '../../creator/_dialogs/delete-comments/delete-comments.component';
import { Export } from '../../../models/export'; import { Export } from '../../../models/export';
import { CreateCommentComponent } from '../../shared/_dialogs/create-comment/create-comment.component';
import { NotificationService } from '../../../services/util/notification.service'; import { NotificationService } from '../../../services/util/notification.service';
import { BonusTokenService } from '../../../services/http/bonus-token.service'; import { BonusTokenService } from '../../../services/http/bonus-token.service';
import { CommentFilter, Period } from '../../../utils/filter-options'; import { CommentFilter, Period } from '../../../utils/filter-options';
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<mat-card-content *ngIf="room.description" <mat-card-content *ngIf="room.description"
fxLayoutAlign="center"> fxLayoutAlign="center">
<app-custom-markdown class="images" [data]="room.description.trim()"></app-custom-markdown> <app-view-comment-data class="images" [currentData]="room.description"></app-view-comment-data>
</mat-card-content> </mat-card-content>
<div fxLayout="column" <div fxLayout="column"
fxLayoutAlign="center" fxLayoutAlign="center"
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
</div> </div>
<mat-card-content *ngIf="room.description" fxLayoutAlign="center"> <mat-card-content *ngIf="room.description" fxLayoutAlign="center">
<app-custom-markdown class="images" [data]="room.description.trim()"></app-custom-markdown> <app-view-comment-data class="images" [currentData]="room.description"></app-view-comment-data>
</mat-card-content> </mat-card-content>
<mat-grid-list cols="1" rowHeight="2:1"> <mat-grid-list cols="1" rowHeight="2:1">
<mat-grid-tile> <mat-grid-tile>
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
[onClose]="this.onNoClick.bind(this)" [onClose]="this.onNoClick.bind(this)"
[isSpinning]="isSendingToSpacy" [isSpinning]="isSendingToSpacy"
[tags]="tags" [tags]="tags"
[user]="user"> [isModerator]="user && user.role > 0">
</app-write-comment> </app-write-comment>
</ars-row> </ars-row>
...@@ -4,12 +4,13 @@ import { NotificationService } from '../../../../services/util/notification.serv ...@@ -4,12 +4,13 @@ import { NotificationService } from '../../../../services/util/notification.serv
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { User } from '../../../../models/user'; import { User } from '../../../../models/user';
import { CommentListComponent } from '../../comment-list/comment-list.component';
import { EventService } from '../../../../services/util/event.service'; import { EventService } from '../../../../services/util/event.service';
import { SpacyDialogComponent } from '../spacy-dialog/spacy-dialog.component'; import { SpacyDialogComponent } from '../spacy-dialog/spacy-dialog.component';
import { LanguagetoolService, Language } from '../../../../services/http/languagetool.service'; import { LanguagetoolService, Language } from '../../../../services/http/languagetool.service';
import { CreateCommentKeywords } from '../../../../utils/create-comment-keywords'; import { CreateCommentKeywords } from '../../../../utils/create-comment-keywords';
import { WriteCommentComponent } from '../../write-comment/write-comment.component'; import { WriteCommentComponent } from '../../write-comment/write-comment.component';
import { DeepLDialogComponent } from '../deep-ldialog/deep-ldialog.component';
import { DeepLService } from '../../../../services/http/deep-l.service';
@Component({ @Component({
selector: 'app-submit-comment', selector: 'app-submit-comment',
...@@ -19,7 +20,6 @@ import { WriteCommentComponent } from '../../write-comment/write-comment.compone ...@@ -19,7 +20,6 @@ import { WriteCommentComponent } from '../../write-comment/write-comment.compone
export class CreateCommentComponent implements OnInit { export class CreateCommentComponent implements OnInit {
@ViewChild(WriteCommentComponent) commentComponent: WriteCommentComponent; @ViewChild(WriteCommentComponent) commentComponent: WriteCommentComponent;
comment: Comment;
user: User; user: User;
roomId: string; roomId: string;
tags: string[]; tags: string[];
...@@ -27,11 +27,12 @@ export class CreateCommentComponent implements OnInit { ...@@ -27,11 +27,12 @@ export class CreateCommentComponent implements OnInit {
constructor( constructor(
private notification: NotificationService, private notification: NotificationService,
public dialogRef: MatDialogRef<CommentListComponent>, public dialogRef: MatDialogRef<CreateCommentComponent>,
private translateService: TranslateService, private translateService: TranslateService,
public dialog: MatDialog, public dialog: MatDialog,
public languagetoolService: LanguagetoolService, public languagetoolService: LanguagetoolService,
public eventService: EventService, public eventService: EventService,
private deeplService: DeepLService,
@Inject(MAT_DIALOG_DATA) public data: any) { @Inject(MAT_DIALOG_DATA) public data: any) {
} }
...@@ -51,7 +52,32 @@ export class CreateCommentComponent implements OnInit { ...@@ -51,7 +52,32 @@ export class CreateCommentComponent implements OnInit {
comment.createdFromLecturer = this.user.role > 0; comment.createdFromLecturer = this.user.role > 0;
comment.tag = tag; comment.tag = tag;
this.isSendingToSpacy = true; this.isSendingToSpacy = true;
this.openSpacyDialog(comment, text); this.openDeeplDialog(body, text, (newBody: string, newText: string) => {
comment.body = newBody;
this.openSpacyDialog(comment, newText);
});
}
openDeeplDialog(body: string, text: string, onClose: (data: string, text: string) => void) {
this.deeplService.improveTextStyle(text).subscribe(improvedText => {
this.isSendingToSpacy = false;
this.dialog.open(DeepLDialogComponent, {
width: '900px',
maxWidth: '100%',
data: {
body,
text,
improvedText
}
}).afterClosed().subscribe((res) => {
if (res) {
onClose(res.body, res.text);
}
});
}, (_) => {
this.isSendingToSpacy = false;
onClose(body, text);
});
} }
openSpacyDialog(comment: Comment, rawText: string): void { openSpacyDialog(comment: Comment, rawText: string): void {
......
<h2>{{'deepl.header' | translate}}</h2>
<div mat-dialog-content>
<label id="deepl-radio-group-label">{{'deepl.label' | translate}}</label>
<br>
<mat-radio-group
aria-labelledby="deepl-radio-group-label"
[(ngModel)]="radioButtonValue">
<mat-radio-button [value]="normalValue">
<strong>{{'deepl.option-normal' | translate}}</strong>
<app-view-comment-data [currentData]="normalValue.body"></app-view-comment-data>
</mat-radio-button>
<br>
<mat-radio-button [value]="improvedValue">
<strong>{{'deepl.option-improved' | translate}}</strong>
<app-view-comment-data [currentData]="improvedValue.body"></app-view-comment-data>
</mat-radio-button>
</mat-radio-group>
</div>
<app-dialog-action-buttons
[buttonsLabelSection]="'comment-page'"
[confirmButtonLabel]="'continue'"
[cancelButtonClickAction]="buildCloseDialogActionCallback()"
[confirmButtonClickAction]="buildSubmitBodyActionCallback()">
</app-dialog-action-buttons>
::ng-deep {
mat-radio-button {
width: 100%;
}
.mat-radio-label {
width: calc(100% - 16px) !important;
}
.mat-radio-label-content {
width: 100%;
}
app-view-comment-data > div {
background: var(--surface);
border-radius: 10px;
padding: 7px;
}
}
/*import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DeepLDialogComponent } from './deep-ldialog.component';
describe('DeepLDialogComponent', () => {
let component: DeepLDialogComponent;
let fixture: ComponentFixture<DeepLDialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DeepLDialogComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(DeepLDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
*/
import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ViewCommentDataComponent } from '../../view-comment-data/view-comment-data.component';
interface ResultValue {
body: string;
text: string;
}
@Component({
selector: 'app-deep-ldialog',
templateUrl: './deep-ldialog.component.html',
styleUrls: ['./deep-ldialog.component.scss']
})
export class DeepLDialogComponent implements OnInit {
radioButtonValue: ResultValue;
normalValue: ResultValue;
improvedValue: ResultValue;
constructor(
private dialogRef: MatDialogRef<DeepLDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) {
}
ngOnInit(): void {
this.normalValue = {
body: this.data.body,
text: this.data.text
};
const sentences = this.data.improvedText.split('\n').filter(sent => sent.length > 0);
const delta = ViewCommentDataComponent.getDeltaFromData(this.data.body);
if (delta === null) {
setTimeout(() => this.dialogRef.close(this.normalValue));
return;
}
const ops = delta.ops;
let i = 0;
let sentenceIndex = 0;
let lastFoundIndex = -1;
for (; i < ops.length && sentenceIndex < sentences.length; i++) {
const data = ops[i]['insert'];
if (typeof data !== 'string') {
continue;
}
if (data === '\n') {
continue;
}
const endsNewline = data.endsWith('\n');
const mod = (endsNewline ? -1 : 0) + (data.startsWith('\n') ? -1 : 0);
const occurrence = data.split('\n').length + mod;
ops[i]['insert'] = sentences.slice(sentenceIndex, sentenceIndex + occurrence).join('\n') +
(endsNewline ? '\n' : '');
sentenceIndex += occurrence;
lastFoundIndex = i;
}
for (let j = ops.length - 1; j >= i; j--) {
const data = ops[i]['insert'];
if (data === 'string' && data.trim().length) {
ops.splice(j, 1);
}
}
if (sentenceIndex < sentences.length) {
if (lastFoundIndex < 0) {
setTimeout(() => this.dialogRef.close(this.normalValue));
return;
}
let data = ops[i]['insert'];
const endsNewline = data.endsWith('\n');
if (endsNewline) {
data = data.substring(0, data.length - 1);
}
ops[i]['insert'] = data + sentences.slice(sentenceIndex).join('\n') + (endsNewline ? '\n' : '');
}
this.improvedValue = {
body: ViewCommentDataComponent.getDataFromDelta(delta),
text: this.data.improvedText
};
this.radioButtonValue = this.normalValue;
}
buildCloseDialogActionCallback(): () => void {
return () => this.dialogRef.close();
}
buildSubmitBodyActionCallback(): () => void {
return () => this.dialogRef.close(this.radioButtonValue);
}
}
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<mat-icon >close</mat-icon> <mat-icon >close</mat-icon>
</button> </button>
<div id="comment"> <div id="comment">
<app-custom-markdown [data]="body"></app-custom-markdown> <app-view-comment-data [currentData]="body"></app-view-comment-data>
</div> </div>
<div class="visually-hidden"> <div class="visually-hidden">
......
import { AfterContentInit, Component, Inject, OnInit, ViewChild } from '@angular/core'; import { AfterContentInit, Component, Inject, OnInit, ViewChild } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { CreateCommentComponent } from '../create-comment/create-comment.component';
import { SpacyService, SpacyKeyword } from '../../../../services/http/spacy.service'; import { SpacyService, SpacyKeyword } from '../../../../services/http/spacy.service';
import { LanguagetoolService } from '../../../../services/http/languagetool.service'; import { LanguagetoolService } from '../../../../services/http/languagetool.service';
import { Comment } from '../../../../models/comment'; import { Comment } from '../../../../models/comment';
...@@ -39,7 +37,7 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit { ...@@ -39,7 +37,7 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit {
constructor( constructor(
protected langService: LanguagetoolService, protected langService: LanguagetoolService,
private spacyService: SpacyService, private spacyService: SpacyService,
public dialogRef: MatDialogRef<CreateCommentComponent>, public dialogRef: MatDialogRef<SpacyDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data) { @Inject(MAT_DIALOG_DATA) public data) {
} }
......
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
fxLayoutAlign="center"> fxLayoutAlign="center">
<mat-card class="answer border-answer" <mat-card class="answer border-answer"
*ngIf="!isStudent || answer"> *ngIf="!isStudent || answer">
<app-write-comment [user]="user" <app-write-comment [isModerator]="user && user.role > 0"
[isCommentAnswer]="true" [isCommentAnswer]="true"
[placeholder]="'comment-page.your-answer'"
[onClose]="openDeleteAnswerDialog()" [onClose]="openDeleteAnswerDialog()"
[onSubmit]="saveAnswer()" [onSubmit]="saveAnswer()"
[disableCancelButton]="!answer && commentComponent && commentComponent.commentData.currentText.length > 0" [disableCancelButton]="!answer && commentComponent && commentComponent.commentData.currentText.length > 0"
......
...@@ -132,9 +132,9 @@ ...@@ -132,9 +132,9 @@
</ars-row> </ars-row>
<ars-row> <ars-row>
<ars-row class="bound" style="padding:16px 32px 16px 32px;box-sizing:border-box;max-width:100%;"> <ars-row class="bound" style="padding:16px 32px 16px 32px;box-sizing:border-box;max-width:100%;">
<app-custom-markdown [ngStyle]="{'font-size':fontSize+'%'}" <app-view-comment-data [ngStyle]="{'font-size':fontSize+'%'}"
class="questionwall-present-markdown images" class="questionwall-present-markdown images"
[data]="commentFocus.comment.body"></app-custom-markdown> [currentData]="commentFocus.comment.body"></app-view-comment-data>
</ars-row> </ars-row>
</ars-row> </ars-row>
<ars-row [height]="50"> <ars-row [height]="50">
...@@ -251,7 +251,7 @@ ...@@ -251,7 +251,7 @@
(click)="focusComment(comment)" (click)="focusComment(comment)"
style="box-sizing:border-box;padding:0 16px;cursor:pointer"> style="box-sizing:border-box;padding:0 16px;cursor:pointer">
<p class="questionwall-comment-body"> <p class="questionwall-comment-body">
<app-custom-markdown class="images" [data]="comment.comment.body"></app-custom-markdown> <app-view-comment-data class="images" [currentData]="comment.comment.body"></app-view-comment-data>
</p> </p>
</ars-row> </ars-row>
<ars-row [height]="50"> <ars-row [height]="50">
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment