diff --git a/angular.json b/angular.json index 31f04944fd9bafa1df96f4a112516d30fd47097e..a01348f9a136f5de4bc054c13803727cee986091 100644 --- a/angular.json +++ b/angular.json @@ -76,7 +76,7 @@ "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "arsnova-angular-frontend:build", - "proxyConfig": "proxy.conf.json" + "proxyConfig": "proxy.conf.js" }, "configurations": { "production": { diff --git a/proxy.conf.json b/proxy.conf.js similarity index 67% rename from proxy.conf.json rename to proxy.conf.js index 6aa7e2adcba2940d5444320a585b4fbedcb387ba..94414ef324d14a7934ae79c17326c9e896f7baff 100644 --- a/proxy.conf.json +++ b/proxy.conf.js @@ -1,45 +1,58 @@ -{ - "/languagetool": { - "target": "https://lt.frag.jetzt/v2/check", - "secure": true, - "changeOrigin": true, - "pathRewrite": { - "^/languagetool": "" - }, - "logLevel": "debug" - }, - "/spacy": { - "target": "https://spacy.frag.jetzt/spacy", - "secure": true, - "changeOrigin": true, - "pathRewrite": { - "^/spacy": "" - }, - "logLevel": "debug" - }, - "/api/ws/websocket": { - "target": "ws://localhost:8080", - "secure": false, - "pathRewrite": { - "^/api": "" - }, - "ws": true, - "logLevel": "debug" - }, - "/api/roomsubscription": { - "target": "http://localhost:8080", - "secure": false, - "pathRewrite": { - "^/api": "" - }, - "logLevel": "debug" - }, - "/api": { - "target": "http://localhost:8888", - "secure": false, - "pathRewrite": { - "^/api": "" - }, - "logLevel": "debug" - } -} +const PROXY_CONFIG = { + "/deepl": { + "target": "https://api-free.deepl.com/v2", + "secure": true, + "changeOrigin": true, + "logLevel": "debug", + "router": function (req) { + const DEEPL_API_KEY = 'DEEPL_API_KEY'; + req.url = req.url.substr(6) + '&auth_key=' + DEEPL_API_KEY; + return 'https://api-free.deepl.com/v2'; + } + }, + "/languagetool": { + "target": "https://lt.frag.jetzt/v2/check", + "secure": true, + "changeOrigin": true, + "pathRewrite": { + "^/languagetool": "" + }, + "logLevel": "debug" + }, + "/spacy": { + "target": "https://spacy.frag.jetzt/spacy", + "secure": true, + "changeOrigin": true, + "pathRewrite": { + "^/spacy": "" + }, + "logLevel": "debug" + }, + "/api/ws/websocket": { + "target": "ws://localhost:8080", + "secure": false, + "pathRewrite": { + "^/api": "" + }, + "ws": true, + "logLevel": "debug" + }, + "/api/roomsubscription": { + "target": "http://localhost:8080", + "secure": false, + "pathRewrite": { + "^/api": "" + }, + "logLevel": "debug" + }, + "/api": { + "target": "http://localhost:8888", + "secure": false, + "pathRewrite": { + "^/api": "" + }, + "logLevel": "debug" + } +}; + +module.exports = PROXY_CONFIG; diff --git a/src/app/components/creator/_dialogs/room-description-settings/room-description-settings.component.html b/src/app/components/creator/_dialogs/room-description-settings/room-description-settings.component.html index 14641669e982af754bd533ac273d5506f11cdabc..978a830181d30b3304dbf923111f9253c1f4cd42 100644 --- a/src/app/components/creator/_dialogs/room-description-settings/room-description-settings.component.html +++ b/src/app/components/creator/_dialogs/room-description-settings/room-description-settings.component.html @@ -1,38 +1,11 @@ <div mat-dialog-content *ngIf="editRoom"> <h2 class="oldtypo-h2">{{ 'room-page.description' | translate }}</h2> - <mat-tab-group> - <mat-tab label="{{'room-page.tab1' | translate}}"> - <mat-form-field class="input-block" style="width:100%;min-width:100%;"> - <textarea - (focus)="eventService.makeFocusOnInputTrue()" - (blur)="eventService.makeFocusOnInputFalse()" - [(ngModel)]="editRoom.description" - 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> + <app-write-comment [isModerator]="true" + [placeholder]="''" + [onClose]="buildCloseDialogActionCallback()" + [onSubmit]="buildSaveActionCallback()" + [i18nSection]="'room-page'" + [confirmLabel]="'update'"> + </app-write-comment> </div> -<app-dialog-action-buttons - buttonsLabelSection="room-page" - confirmButtonLabel="update" - - [cancelButtonClickAction]="buildCloseDialogActionCallback()" - [confirmButtonClickAction]="buildSaveActionCallback()" -></app-dialog-action-buttons> diff --git a/src/app/components/creator/_dialogs/room-description-settings/room-description-settings.component.ts b/src/app/components/creator/_dialogs/room-description-settings/room-description-settings.component.ts index cd5f3ac74bf44d7f926629a15046dadc5bebdfc1..1006684aa26ca7e6f900d42ad02ed35504193fda 100644 --- a/src/app/components/creator/_dialogs/room-description-settings/room-description-settings.component.ts +++ b/src/app/components/creator/_dialogs/room-description-settings/room-description-settings.component.ts @@ -1,22 +1,25 @@ -import {Component,Inject,OnInit} from '@angular/core'; -import {MAT_DIALOG_DATA,MatDialog,MatDialogRef} from '@angular/material/dialog'; -import {RoomCreatorPageComponent} from '../../room-creator-page/room-creator-page.component'; -import {NotificationService} from '../../../../services/util/notification.service'; -import {TranslateService} from '@ngx-translate/core'; -import {RoomService} from '../../../../services/http/room.service'; -import {Router} from '@angular/router'; -import {EventService} from '../../../../services/util/event.service'; -import {ProfanityFilter,Room} from '../../../../models/room'; -import {FormControl,Validators} from '@angular/forms'; +import { AfterViewInit, Component, Inject, ViewChild } from '@angular/core'; +import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; +import { RoomCreatorPageComponent } from '../../room-creator-page/room-creator-page.component'; +import { NotificationService } from '../../../../services/util/notification.service'; +import { TranslateService } from '@ngx-translate/core'; +import { RoomService } from '../../../../services/http/room.service'; +import { Router } from '@angular/router'; +import { EventService } from '../../../../services/util/event.service'; +import { Room } from '../../../../models/room'; +import { FormControl, Validators } from '@angular/forms'; +import { WriteCommentComponent } from '../../../shared/write-comment/write-comment.component'; @Component({ - selector:'app-room-description-settings', - templateUrl:'./room-description-settings.component.html', - styleUrls:['./room-description-settings.component.scss'] + selector: 'app-room-description-settings', + templateUrl: './room-description-settings.component.html', + styleUrls: ['./room-description-settings.component.scss'] }) -export class RoomDescriptionSettingsComponent implements OnInit{ +export class RoomDescriptionSettingsComponent implements AfterViewInit { + + @ViewChild(WriteCommentComponent) writeComment: WriteCommentComponent; 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>, public dialog: MatDialog, @@ -25,30 +28,34 @@ export class RoomDescriptionSettingsComponent implements OnInit{ protected roomService: RoomService, public router: Router, 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{ - return ()=>this.closeDialog('abort'); + buildCloseDialogActionCallback(): () => void { + return () => this.closeDialog('abort'); } - buildSaveActionCallback(): () => void{ - return ()=>this.save(); + buildSaveActionCallback(): () => void { + return () => this.save(); } - closeDialog(type: string): void{ + closeDialog(type: string): void { this.dialogRef.close(type); } - save(): void{ - this.roomService.updateRoom(this.editRoom).subscribe(r=>this.editRoom=r); - if(!this.roomNameFormControl.hasError('required') + save(): void { + this.editRoom.description = this.writeComment.commentData.currentData; + this.roomService.updateRoom(this.editRoom).subscribe(r => this.editRoom = r); + if (!this.roomNameFormControl.hasError('required') && !this.roomNameFormControl.hasError('minlength') - && !this.roomNameFormControl.hasError('maxlength')){ + && !this.roomNameFormControl.hasError('maxlength')) { this.closeDialog('update'); } this.closeDialog('update'); diff --git a/src/app/components/creator/_dialogs/room-edit/room-edit.component.html b/src/app/components/creator/_dialogs/room-edit/room-edit.component.html index cd4de45f001a5760ce489a3f58dc13be51464565..13cc82a372f6d9187fbcf9e88c383060051e2075 100644 --- a/src/app/components/creator/_dialogs/room-edit/room-edit.component.html +++ b/src/app/components/creator/_dialogs/room-edit/room-edit.component.html @@ -46,7 +46,7 @@ </mat-tab> <mat-tab label="{{'session.preview' | translate}}" [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-group> <div fxLayout="column"> diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.html b/src/app/components/creator/room-creator-page/room-creator-page.component.html index b4d745512dc7295038fc4f211966c104a1fe46da..3fdd9b3c900921f0004752f7bbbbe02a727ff03c 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.html +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.html @@ -65,7 +65,7 @@ </div> <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> <div fxLayout="column" fxLayoutAlign="center" diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.ts b/src/app/components/creator/room-creator-page/room-creator-page.component.ts index 6f4b6d344027f77a976eb6fec79a2dc081090a5c..a783278555b4dc61ce7ac3558d8d9a7f530f32e3 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.ts +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.ts @@ -1,8 +1,8 @@ import { Component, OnInit, Renderer2, OnDestroy, AfterContentInit } from '@angular/core'; 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 {ProfanityFilter,Room} from '../../../models/room'; +import { Room } from '../../../models/room'; import { CommentSettingsDialog } from '../../../models/comment-settings-dialog'; import { Location } from '@angular/common'; import { NotificationService } from '../../../services/util/notification.service'; @@ -10,7 +10,6 @@ import { MatDialog } from '@angular/material/dialog'; import { RoomEditComponent } from '../_dialogs/room-edit/room-edit.component'; import { TranslateService } from '@ngx-translate/core'; import { LanguageService } from '../../../services/util/language.service'; -import { TSMap } from 'typescript-map'; import { WsCommentService } from '../../../services/websockets/ws-comment.service'; import { CommentService } from '../../../services/http/comment.service'; import { ModeratorsComponent } from '../_dialogs/moderators/moderators.component'; @@ -26,14 +25,10 @@ import { DeleteCommentsComponent } from '../_dialogs/delete-comments/delete-comm import { Export } from '../../../models/export'; import { BonusTokenService } from '../../../services/http/bonus-token.service'; 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 {RoomDeleted} from '../../../models/events/room-deleted'; -import {ProfanitySettingsComponent} from '../_dialogs/profanity-settings/profanity-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'; +import { RoomDeleteComponent } from '../_dialogs/room-delete/room-delete.component'; +import { RoomDeleted } from '../../../models/events/room-deleted'; +import { ProfanitySettingsComponent } from '../_dialogs/profanity-settings/profanity-settings.component'; +import { RoomDescriptionSettingsComponent } from '../_dialogs/room-description-settings/room-description-settings.component'; @Component({ selector: 'app-room-creator-page', @@ -110,9 +105,12 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni editSessionDescription(){ 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(){ diff --git a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.html b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.html index 61a847b46dc6ed9dac012768edb59457c3e5256f..e41c74dc5c36e13c62bf52337bd2a8706f481a53 100644 --- a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.html +++ b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.html @@ -34,7 +34,7 @@ <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> <div fxLayout="column" fxLayoutAlign="center" diff --git a/src/app/components/participant/room-participant-page/room-participant-page.component.html b/src/app/components/participant/room-participant-page/room-participant-page.component.html index 5da0230922f98d2fa9238d034ffd97aea4cbaa39..86b613e8beb52e5278a21d6cd99b937b911abc6a 100644 --- a/src/app/components/participant/room-participant-page/room-participant-page.component.html +++ b/src/app/components/participant/room-participant-page/room-participant-page.component.html @@ -21,7 +21,7 @@ </div> <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-grid-list cols="1" rowHeight="2:1"> <mat-grid-tile> diff --git a/src/app/components/shared/_dialogs/create-comment/create-comment.component.html b/src/app/components/shared/_dialogs/create-comment/create-comment.component.html index 3dc3a4528245855d1a48f62e446ef04c7755b6b0..25933dfdbd6d57e587884afc93afaeef630e203d 100644 --- a/src/app/components/shared/_dialogs/create-comment/create-comment.component.html +++ b/src/app/components/shared/_dialogs/create-comment/create-comment.component.html @@ -4,6 +4,6 @@ [onClose]="this.onNoClick.bind(this)" [isSpinning]="isSendingToSpacy" [tags]="tags" - [user]="user"> + [isModerator]="user && user.role > 0"> </app-write-comment> </ars-row> diff --git a/src/app/components/shared/_dialogs/present-comment/present-comment.component.html b/src/app/components/shared/_dialogs/present-comment/present-comment.component.html index cf4217111f40b7f7b6b7345310dccb992d4be044..c9fcc94778685b6540fc53efa58300adf728869d 100644 --- a/src/app/components/shared/_dialogs/present-comment/present-comment.component.html +++ b/src/app/components/shared/_dialogs/present-comment/present-comment.component.html @@ -12,7 +12,7 @@ <mat-icon >close</mat-icon> </button> <div id="comment"> - <app-custom-markdown [data]="body"></app-custom-markdown> + <app-view-comment-data [currentData]="body"></app-view-comment-data> </div> <div class="visually-hidden"> diff --git a/src/app/components/shared/comment-answer/comment-answer.component.html b/src/app/components/shared/comment-answer/comment-answer.component.html index 5015e4a847f0e22e8b7b865f841afc17271b8578..14edcc800a77c439679c936abe00a9dfb4e54856 100644 --- a/src/app/components/shared/comment-answer/comment-answer.component.html +++ b/src/app/components/shared/comment-answer/comment-answer.component.html @@ -10,8 +10,9 @@ fxLayoutAlign="center"> <mat-card class="answer border-answer" *ngIf="!isStudent || answer"> - <app-write-comment [user]="user" + <app-write-comment [isModerator]="user && user.role > 0" [isCommentAnswer]="true" + [placeholder]="'comment-page.your-answer'" [onClose]="openDeleteAnswerDialog()" [onSubmit]="saveAnswer()" [disableCancelButton]="!answer && commentComponent && commentComponent.commentData.currentText.length > 0" diff --git a/src/app/components/shared/questionwall/question-wall/question-wall.component.html b/src/app/components/shared/questionwall/question-wall/question-wall.component.html index b5c65f32b432ea53cd8a028ddbf6eef46a96fe10..04c121e001fd590014996b56101ea0f6a9463d4f 100644 --- a/src/app/components/shared/questionwall/question-wall/question-wall.component.html +++ b/src/app/components/shared/questionwall/question-wall/question-wall.component.html @@ -123,9 +123,9 @@ </ars-row> <ars-row> <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" - [data]="commentFocus.comment.body"></app-custom-markdown> + [currentData]="commentFocus.comment.body"></app-view-comment-data> </ars-row> </ars-row> <ars-row [height]="50"> @@ -231,7 +231,7 @@ (click)="focusComment(comment)" style="box-sizing:border-box;padding:0 16px;cursor:pointer"> <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> </ars-row> <ars-row [height]="50"> diff --git a/src/app/components/shared/questionwall/question-wall/question-wall.component.scss b/src/app/components/shared/questionwall/question-wall/question-wall.component.scss index 58dac5ddeb9628f3b4711f21fac53c92e5686cc1..3d8392f58f2c0c0ba5424a3f811e36cd7c37508a 100644 --- a/src/app/components/shared/questionwall/question-wall/question-wall.component.scss +++ b/src/app/components/shared/questionwall/question-wall/question-wall.component.scss @@ -275,10 +275,6 @@ hr { border: 1px solid yellow; } - - img { - width: 100% !important; - } } .questionwall-present-options-slider { diff --git a/src/app/components/shared/shared.module.ts b/src/app/components/shared/shared.module.ts index 52a78cd959336e7bc6839c700a1bf873a3ec0c75..87b4f5a8e5f54b40e16237949a6fd9be7586b9d8 100644 --- a/src/app/components/shared/shared.module.ts +++ b/src/app/components/shared/shared.module.ts @@ -130,7 +130,9 @@ import { ViewCommentDataComponent } from './view-comment-data/view-comment-data. JoyrideTemplateDirective, AutofocusDirective, CustomMarkdownComponent, - ScrollIntoViewDirective + ScrollIntoViewDirective, + ViewCommentDataComponent, + WriteCommentComponent ] }) export class SharedModule { diff --git a/src/app/components/shared/view-comment-data/view-comment-data.component.html b/src/app/components/shared/view-comment-data/view-comment-data.component.html index dd342f9014526b27a04ce4fbe480aa09e51af1c0..df7e8b0c54aca137defbe59559438a755877a67f 100644 --- a/src/app/components/shared/view-comment-data/view-comment-data.component.html +++ b/src/app/components/shared/view-comment-data/view-comment-data.component.html @@ -1,19 +1,15 @@ <ars-row *ngIf="isEditor"> <div #editorErrorLayer id="editorErrorLayer"></div> <quill-editor #editor - [maxLength]="user.role === 3 ? 1000 : 500" - placeholder="{{ 'comment-page.enter-comment' | translate }}" + placeholder="{{ placeHolderText | translate }}" [modules]="quillModules" (document:click)="onDocumentClick($event)"> </quill-editor> <div #tooltipContainer></div> - <div fxLayout="row" style="justify-content: space-between; padding: 0 5px"> + <div fxLayout="row" style="justify-content: flex-end; padding: 0 5px"> <span aria-hidden="true" style="font-size: 75%"> {{currentText.length}} / {{maxTextCharacters}} </span> - <span aria-hidden="true" style="font-size: 75%"> - {{'comment-page.format-count' | translate: {count: currentData.length, length: maxDataCharacters} }} - </span> </div> </ars-row> <div *ngIf="!isEditor"> diff --git a/src/app/components/shared/view-comment-data/view-comment-data.component.scss b/src/app/components/shared/view-comment-data/view-comment-data.component.scss index a9de9fcdc4172ecad0277c0a759b4606b27dde80..db69027a8a8b2b20c0967a8033ce5cfba1432074 100644 --- a/src/app/components/shared/view-comment-data/view-comment-data.component.scss +++ b/src/app/components/shared/view-comment-data/view-comment-data.component.scss @@ -3,6 +3,13 @@ filter: opacity(0.6); } +::ng-deep { + .images .ql-video { + width: 100%; + aspect-ratio: 16 / 9; + } +} + ::ng-deep .ql-snow { :focus { outline-offset: 0; @@ -12,12 +19,22 @@ min-height: 8.8em; } + &.ql-disabled { + .ql-editor { + min-height: unset; + padding: unset; + } + } + .ql-stroke { stroke: var(--on-surface); } .ql-picker { color: var(--on-surface); + font-size: inherit !important; + height: 1.5em !important; + width: 1.75em !important; } .ql-tooltip { @@ -86,10 +103,14 @@ &.ql-container { border-color: var(--on-surface); height: 80%; + font-size: inherit !important; } &.ql-toolbar, .ql-toolbar { border-color: var(--on-surface); + border-top: unset; + border-right: unset; + border-left: unset; .ql-formats { margin-right: 0; @@ -112,6 +133,12 @@ } } + button { + font-size: inherit !important; + height: 1.5em !important; + width: 1.75em !important; + } + button:hover, button:focus, button.ql-active, .ql-picker-label:hover, .ql-picker-label.ql-active, .ql-picker-item:hover, .ql-picker-item.ql-selected { diff --git a/src/app/components/shared/view-comment-data/view-comment-data.component.ts b/src/app/components/shared/view-comment-data/view-comment-data.component.ts index 805ed043b777fdceca76afab3d778f034db29bde..6f28e5e7b7e9b0462a5cde1b23d6f642e3cef68e 100644 --- a/src/app/components/shared/view-comment-data/view-comment-data.component.ts +++ b/src/app/components/shared/view-comment-data/view-comment-data.component.ts @@ -1,5 +1,4 @@ import { AfterViewInit, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'; -import { User } from '../../../models/user'; import { QuillEditorComponent, QuillModules, QuillViewComponent } from 'ngx-quill'; import Delta from 'quill-delta'; import Quill from 'quill'; @@ -7,6 +6,7 @@ import ImageResize from 'quill-image-resize-module'; import 'quill-emoji/dist/quill-emoji.js'; import { LanguageService } from '../../../services/util/language.service'; import { TranslateService } from '@ngx-translate/core'; +import { DeviceInfoService } from '../../../services/util/device-info.service'; Quill.register('modules/imageResize', ImageResize); @@ -31,10 +31,23 @@ export class ViewCommentDataComponent implements OnInit, AfterViewInit { @ViewChild('editorErrorLayer') editorErrorLayer: ElementRef<HTMLDivElement>; @ViewChild('tooltipContainer') tooltipContainer: ElementRef<HTMLDivElement>; @Input() isEditor = false; - @Input() user: User; - @Input() currentData = ''; + @Input() isModerator = false; + + @Input() + set currentData(data: string) { + this._currentData = data; + if ((this.editor && this.editor.quillEditor) || (this.quillView && this.quillView.quillEditor)) { + this.set(this._currentData); + } + } + + get currentData(): string { + return this._currentData; + } + @Input() maxTextCharacters = 500; @Input() maxDataCharacters = 1500; + @Input() placeHolderText = ''; @Input() markEvents?: { onCreate: (markContainer: HTMLDivElement, tooltipContainer: HTMLDivElement, editor: QuillEditorComponent) => void; onChange: (delta: any) => void; @@ -53,9 +66,11 @@ export class ViewCommentDataComponent implements OnInit, AfterViewInit { } } }; + private _currentData = ''; constructor(private languageService: LanguageService, - private translateService: TranslateService) { + private translateService: TranslateService, + private deviceInfo: DeviceInfoService) { this.languageService.langEmitter.subscribe(lang => { this.translateService.use(lang); if (this.isEditor) { @@ -90,12 +105,13 @@ export class ViewCommentDataComponent implements OnInit, AfterViewInit { } ngOnInit(): void { - if (this.user && this.user.role > 0) { + if (this.isModerator) { this.quillModules.toolbar['container'] = moderatorToolbar; } + const isMobile = this.deviceInfo.isUserAgentMobile; if (this.isEditor) { - this.quillModules['emoji-toolbar'] = true; - this.quillModules['emoji-shortname'] = true; + this.quillModules['emoji-toolbar'] = !isMobile; + this.quillModules['emoji-shortname'] = !isMobile; this.quillModules.imageResize = { modules: ['Resize', 'DisplaySize'] }; @@ -112,13 +128,15 @@ export class ViewCommentDataComponent implements OnInit, AfterViewInit { if (this.markEvents && this.markEvents.onChange) { this.markEvents.onChange(e.delta); } - this.currentData = ViewCommentDataComponent.getDataFromDelta(e.content); + this._currentData = ViewCommentDataComponent.getDataFromDelta(e.content); this.currentText = e.text; }); this.editor.onEditorCreated.subscribe(_ => { if (this.markEvents && this.markEvents.onCreate) { this.markEvents.onCreate(this.editorErrorLayer.nativeElement, this.tooltipContainer.nativeElement, this.editor); } + this.set(this._currentData); + (this.editor.editorElem.firstElementChild as HTMLElement).focus(); this.syncErrorLayer(); setTimeout(() => this.syncErrorLayer(), 200); // animations? }); @@ -145,7 +163,7 @@ export class ViewCommentDataComponent implements OnInit, AfterViewInit { }); } else { this.quillView.onEditorCreated.subscribe(_ => { - this.set(this.currentData); + this.set(this._currentData); }); } } diff --git a/src/app/components/shared/write-comment/write-comment.component.html b/src/app/components/shared/write-comment/write-comment.component.html index 0c6189d9d5e91268a3833612aa8c34a0fb996879..32a9d67ce13b57558f363173015f13b35dd7050e 100644 --- a/src/app/components/shared/write-comment/write-comment.component.html +++ b/src/app/components/shared/write-comment/write-comment.component.html @@ -46,10 +46,11 @@ </ars-row> <ars-row [height]="12"></ars-row> <app-view-comment-data *ngIf="enabled" - [user]="user" + [isModerator]="isModerator" [isEditor]="true" [maxTextCharacters]="maxTextCharacters" [maxDataCharacters]="maxDataCharacters" + [placeHolderText]="placeholder" [markEvents]="getMarkEvents()"></app-view-comment-data> <ars-row ars-flex-box *ngIf="enabled" class="spellcheck"> <ars-col> @@ -66,7 +67,7 @@ </ars-col> <ars-col> <app-dialog-action-buttons - buttonsLabelSection="comment-page" + [buttonsLabelSection]="i18nSection" [confirmButtonLabel]="confirmLabel" [cancelButtonLabel]="cancelLabel" [showLoadingCycle]="isSpinning" diff --git a/src/app/components/shared/write-comment/write-comment.component.scss b/src/app/components/shared/write-comment/write-comment.component.scss index 0f303ef0146cb8af2965e175a00a2eadd31dd795..a54b280fe5f29f6cad4c4d64bf7a340970c1e1fb 100644 --- a/src/app/components/shared/write-comment/write-comment.component.scss +++ b/src/app/components/shared/write-comment/write-comment.component.scss @@ -234,122 +234,3 @@ $borderOffset: 2px; text-align: center; } } - -/* - For quill - */ - -::ng-deep .ql-editor.ql-blank::before { - color: var(--on-surface); - filter: opacity(0.6); -} - -::ng-deep .ql-snow { - :focus { - outline-offset: 0; - } - - .ql-editor { - min-height: 8.8em; - } - - .ql-stroke { - stroke: var(--on-surface); - } - - .ql-picker { - color: var(--on-surface); - } - - .ql-tooltip { - &[data-mode=formula]::before { - --quill-tooltip-label: var(--quill-tooltip-label-formula); - } - &[data-mode=video]::before { - --quill-tooltip-label: var(--quill-tooltip-label-video); - } - &[data-mode=image]::before { - --quill-tooltip-label: var(--quill-tooltip-label-image); - } - &[data-mode=link]::before { - --quill-tooltip-label: var(--quill-tooltip-label-link); - } - &::before { - content: var(--quill-tooltip-label) !important; - } - - color: var(--on-surface); - background-color: var(--surface); - - .ql-action::after { - padding: 7px !important; - background: var(--primary); - border-radius: 4px; - color: var(--on-primary); - content: var(--quill-tooltip-action) !important; - } - - &.ql-editing .ql-action::after { - --quill-tooltip-action: var(--quill-tooltip-action-save); - } - - .ql-remove::before { - content: var(--quill-tooltip-remove) !important; - padding: 7px !important; - background: var(--cancel); - border-radius: 4px; - color: var(--on-cancel); - } - - &.ql-editing input[type=text] { - border-color: var(--on-surface); - color: var(--on-surface); - background-color: var(--dialog); - } - } - - .ql-fill, .ql-stroke.ql-fill { - fill: var(--on-surface); - } - - .ql-picker.ql-expanded .ql-picker-label { - color: var(--primary); - - .ql-stroke { - stroke: var(--primary); - } - } - - &.ql-container { - border-color: var(--on-surface); - height: 80%; - } - - &.ql-toolbar, .ql-toolbar { - border-color: var(--on-surface); - - .ql-picker.ql-expanded { - .ql-picker-label { - border-color: var(--on-surface); - } - - .ql-picker-options { - background-color: var(--surface); - } - } - - button:hover, button:focus, button.ql-active, - .ql-picker-label:hover, .ql-picker-label.ql-active, - .ql-picker-item:hover, .ql-picker-item.ql-selected { - color: var(--primary); - - .ql-stroke { - stroke: var(--primary); - } - - .ql-fill, .ql-stroke.ql-fill { - fill: var(--primary); - } - } - } -} diff --git a/src/app/components/shared/write-comment/write-comment.component.ts b/src/app/components/shared/write-comment/write-comment.component.ts index 6a00264bae2ad3575bea300121dd32844fa1d221..a39b0b731799c7911c32002b2cb0e4f8b517de04 100644 --- a/src/app/components/shared/write-comment/write-comment.component.ts +++ b/src/app/components/shared/write-comment/write-comment.component.ts @@ -2,14 +2,13 @@ import { Component, ElementRef, Input, OnInit, TemplateRef, ViewChild } from '@a import { TranslateService } from '@ngx-translate/core'; import { Language, LanguagetoolService } from '../../../services/http/languagetool.service'; import { Comment } from '../../../models/comment'; -import { User } from '../../../models/user'; import { NotificationService } from '../../../services/util/notification.service'; import { EventService } from '../../../services/util/event.service'; import { Marks } from './write-comment.marks'; import { LanguageService } from '../../../services/util/language.service'; import { QuillEditorComponent } from 'ngx-quill'; import { ViewCommentDataComponent } from '../view-comment-data/view-comment-data.component'; - +import { DeepLService } from '../../../services/http/deep-l.service'; @Component({ selector: 'app-write-comment', @@ -20,7 +19,7 @@ export class WriteCommentComponent implements OnInit { @ViewChild(ViewCommentDataComponent) commentData: ViewCommentDataComponent; @ViewChild('langSelect') langSelect: ElementRef<HTMLDivElement>; - @Input() user: User; + @Input() isModerator = false; @Input() tags: string[]; @Input() onClose: () => any; @Input() onSubmit: (commentData: string, commentText: string, selectedTag: string) => any; @@ -31,6 +30,8 @@ export class WriteCommentComponent implements OnInit { @Input() additionalTemplate: TemplateRef<any>; @Input() enabled = true; @Input() isCommentAnswer = false; + @Input() placeholder = 'comment-page.enter-comment'; + @Input() i18nSection = 'comment-page'; comment: Comment; selectedTag: string; maxTextCharacters = 500; @@ -48,7 +49,8 @@ export class WriteCommentComponent implements OnInit { private languageService: LanguageService, private translateService: TranslateService, public eventService: EventService, - public languagetoolService: LanguagetoolService) { + public languagetoolService: LanguagetoolService, + public deepl: DeepLService) { this.languageService.langEmitter.subscribe(lang => { this.translateService.use(lang); }); @@ -57,11 +59,11 @@ export class WriteCommentComponent implements OnInit { ngOnInit(): void { this.translateService.use(localStorage.getItem('currentLang')); if (this.isCommentAnswer) { - this.maxTextCharacters = this.user.role > 0 ? 2000 : 0; + this.maxTextCharacters = this.isModerator ? 2000 : 0; } else { - this.maxTextCharacters = this.user.role > 0 ? 1000 : 500; + this.maxTextCharacters = this.isModerator ? 1000 : 500; } - this.maxDataCharacters = this.user.role > 0 ? this.maxTextCharacters * 5 : this.maxTextCharacters * 3; + this.maxDataCharacters = this.isModerator ? this.maxTextCharacters * 5 : this.maxTextCharacters * 3; } buildCloseDialogActionCallback(): () => void { @@ -91,6 +93,9 @@ export class WriteCommentComponent implements OnInit { } checkGrammar() { + this.deepl.improveTextStyle(this.commentData.currentText).subscribe(str => { + console.log(str); + }); this.grammarCheck(this.commentData.currentText, this.langSelect && this.langSelect.nativeElement); } diff --git a/src/app/services/http/base-http.service.ts b/src/app/services/http/base-http.service.ts index 6da60736a0b3cadf74868321c75e9afc58a24647..ed667e0795cff96cf0445d56a9b986ba45089ec3 100644 --- a/src/app/services/http/base-http.service.ts +++ b/src/app/services/http/base-http.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; import { Observable, throwError, TimeoutError } from 'rxjs'; +import { HttpErrorResponse } from '@angular/common/http'; @Injectable() export class BaseHttpService { @@ -13,6 +14,10 @@ export class BaseHttpService { return (error: any): Observable<T> => { if (error instanceof TimeoutError) { this.nextRequest = new Date().getTime() + 1_000; + } else if (error instanceof HttpErrorResponse) { + if (error.status === 429 || error.status === 456) { + this.nextRequest = new Date().getTime() + 30_000; + } } console.error(error); return throwError(error); diff --git a/src/app/services/http/deep-l.service.spec.ts b/src/app/services/http/deep-l.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..f402fba5ea9c57acd24e3d8b5298b3d95b38068a --- /dev/null +++ b/src/app/services/http/deep-l.service.spec.ts @@ -0,0 +1,17 @@ +/*import { TestBed } from '@angular/core/testing'; + +import { DeepLService } from './deep-l.service'; + +describe('DeepLService', () => { + let service: DeepLService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(DeepLService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); + */ diff --git a/src/app/services/http/deep-l.service.ts b/src/app/services/http/deep-l.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..7125235d5dee9ab6e2435d9993df5de8e8f00ee5 --- /dev/null +++ b/src/app/services/http/deep-l.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@angular/core'; +import { BaseHttpService } from './base-http.service'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { catchError, map, tap } from 'rxjs/operators'; +import { flatMap } from 'rxjs/internal/operators'; + +const httpOptions = { + // eslint-disable-next-line @typescript-eslint/naming-convention + headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }) +}; + +interface DeepLResult { + translations: { + detected_source_language: string; + text: string; + }[]; +} + +@Injectable({ + providedIn: 'root' +}) +export class DeepLService extends BaseHttpService { + + constructor(private http: HttpClient) { + super(); + } + + improveTextStyle(text: string): Observable<string> { + return this.makeTranslateRequest([text], 'EN-US').pipe( + flatMap(result => + this.makeTranslateRequest([result.translations[0].text], result.translations[0].detected_source_language)), + map(result => result.translations[0].text) + ); + } + + private makeTranslateRequest(text: string[], targetLang: string): Observable<DeepLResult> { + const url = '/deepl/translate'; + console.assert(text.length > 0, 'You need at least one text entry.'); + console.assert(text.length <= 50, 'Maximum 50 text entries are allowed'); + const additional = '?target_lang=' + encodeURIComponent(targetLang) + + '&text=' + text.map(e => encodeURIComponent(e)).join('&text='); + return this.http.get<string>(url + additional, httpOptions) + .pipe( + tap(_ => ''), + catchError(this.handleError<any>('makeTranslateRequest')), + ); + } +} diff --git a/src/app/services/util/device-info.service.spec.ts b/src/app/services/util/device-info.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..22755a345d35b4c26838db25ee2a994ce3294f6f --- /dev/null +++ b/src/app/services/util/device-info.service.spec.ts @@ -0,0 +1,17 @@ +/*import { TestBed } from '@angular/core/testing'; + +import { DeviceInfoService } from './device-info.service'; + +describe('DeviceInfoService', () => { + let service: DeviceInfoService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(DeviceInfoService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); + */ diff --git a/src/app/services/util/device-info.service.ts b/src/app/services/util/device-info.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..9bc0fd5685370e04b18b6cd8e18e70fa6f77ff8c --- /dev/null +++ b/src/app/services/util/device-info.service.ts @@ -0,0 +1,67 @@ +import { Injectable } from '@angular/core'; +import { BehaviorSubject, Observable } from 'rxjs'; + +@Injectable({ + providedIn: 'root' +}) +export class DeviceInfoService { + + private readonly _isSafari; + private readonly _userAgentDeviceType; + private readonly _isMobile = new BehaviorSubject(false); + + constructor() { + const userAgent = navigator.userAgent; + if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent)) { + // Check if IOS device + if (/iPhone|iPad|iPod/.test(userAgent)) { + this._isSafari = true; + } + this._userAgentDeviceType = 'mobile'; + } else { + // Check if Mac + if (/Macintosh|MacIntel|MacPPC|Mac68k/.test(userAgent)) { + // Check if Safari browser + if (userAgent.indexOf('Safari') !== -1 && userAgent.indexOf('Chrome') === -1) { + this._isSafari = true; + } + } + this._userAgentDeviceType = 'desktop'; + } + this._isSafari = this._isSafari || false; + if (window.matchMedia) { + const match = window.matchMedia('only screen and (max-device-width: 480px) and (orientation: portrait), ' + + 'only screen and (max-device-height: 480px) and (orientation: landscape)'); + this._isMobile.next(match.matches); + match.addEventListener('change', (e) => { + this._isMobile.next(e.matches); + }); + } else { + this._isMobile.next(this.isUserAgentMobile); + } + } + + get isSafari(): boolean { + return this._isSafari; + } + + get isUserAgentMobile(): boolean { + return this._userAgentDeviceType === 'mobile'; + } + + get isUserAgentDesktop(): boolean { + return this._userAgentDeviceType === 'desktop'; + } + + get userAgentDeviceType(): string { + return this._userAgentDeviceType; + } + + get isCurrentlyMobile(): boolean { + return this._isMobile.value; + } + + public isMobile(): Observable<boolean> { + return this._isMobile.asObservable(); + } +} diff --git a/src/app/services/util/onboarding.service.ts b/src/app/services/util/onboarding.service.ts index d884ebffe67445438de131a3d7ead6e85c7e03e5..f9b8c464e421ab0cb3ef0bad66a7aa983eb100d6 100644 --- a/src/app/services/util/onboarding.service.ts +++ b/src/app/services/util/onboarding.service.ts @@ -12,6 +12,7 @@ import { NotificationService } from './notification.service'; import { RoomService } from '../http/room.service'; import { TranslateService } from '@ngx-translate/core'; import { LanguageService } from './language.service'; +import { DeviceInfoService } from './device-info.service'; @Injectable({ providedIn: 'root' @@ -31,7 +32,8 @@ export class OnboardingService { private notificationService: NotificationService, private roomService: RoomService, private translateService: TranslateService, - private langService: LanguageService) { + private langService: LanguageService, + private deviceInfo: DeviceInfoService) { this.langService.langEmitter.subscribe(lang => { this.translateService.use(lang); }); @@ -79,6 +81,8 @@ export class OnboardingService { if (this._activeTour) { this.cleanup(); return false; + } else if (this.deviceInfo.isSafari) { + return false; } if (ignoreDone) { this.dataStoreService.remove('onboarding_' + tour.name); diff --git a/src/assets/i18n/creator/de.json b/src/assets/i18n/creator/de.json index f4003ad8add87d554a7c1e02e526e9cd07c0ebcd..161e2d1849f2bb4d184b15a90744ee784a0a29a0 100644 --- a/src/assets/i18n/creator/de.json +++ b/src/assets/i18n/creator/de.json @@ -147,7 +147,6 @@ "exit-description": "Präsentation verlassen", "export": "Exportieren", "export-description": "Exportieren", - "format-count": "Formatierungszeichen {{count}}/{{length}}", "live-announcer": "Du befindest dich jetzt auf der Fragen-Seite. Um Informationen zu Tastenkombinationen zu erhalten drücke jetzt die Enter-Taste oder rufe die Ansage zu einem späteren Zeitpunkt mit der Escape-Taste auf.", "live-announcer-moderation": "Du befindest dich jetzt auf der Moderations-Seite. Um Informationen zu Tastenkombinationen zu erhalten drücke jetzt die Enter-Taste oder rufe die Ansage zu einem späteren Zeitpunkt mit der Escape-Taste auf.", "mark-correct": "Frage bejahen", diff --git a/src/assets/i18n/creator/en.json b/src/assets/i18n/creator/en.json index 3a595fb79ed49117c879af4a3d9bd1c52a4f778a..751372cd27931d658ee5e4906d880bd6bca93de3 100644 --- a/src/assets/i18n/creator/en.json +++ b/src/assets/i18n/creator/en.json @@ -148,7 +148,6 @@ "exit-description": "Exit Presentation Mode", "export": "Export", "export-description": "Export", - "format-count": "Formatting characters {{count}}/{{length}}", "live-announcer": "You are now on the questions page. To get information about key combinations press the Enter key or call the announcement later with the Escape key.", "live-announcer-moderation": "You are now on the moderation page. To get information about key combinations press the Enter key or call the announcement later with the Escape key.", "mark-correct": "Mark as correct", diff --git a/src/assets/i18n/participant/de.json b/src/assets/i18n/participant/de.json index a243678dd5533a05edc88a673ffe59736e479652..e6ba2fec8b2ae87ad0154803aa7713360b0b204c 100644 --- a/src/assets/i18n/participant/de.json +++ b/src/assets/i18n/participant/de.json @@ -131,7 +131,6 @@ "error-comment-text": "Dein Text ist zu lang. Bitte kürze ihn.", "error-comment-data": "Zu viele Formatierungen oder verknüpfte Elemente. Bitte entferne einige.", "error-title": "Bitte gib einen Titel ein.", - "format-count": "Formatierungszeichen {{count}}/{{length}}", "has-answer": "Die Frage wurde kommentiert. Klick hier, um den Kommentar zu lesen.", "exit-description": "Präsentationsmodus verlassen", "live-announcer": "Du befindest dich jetzt auf der Fragen-Seite. Um Informationen zu Tastenkombinationen zu erhalten drücke jetzt die Enter-Taste oder rufe die Ansage zu einem späteren Zeitpunkt mit der Escape-Taste auf.", diff --git a/src/assets/i18n/participant/en.json b/src/assets/i18n/participant/en.json index 040cd7cc8209a717a2a034f420e6e07f86e62253..2a1328180bd0d83f98ed87c99422ca0d05b39501 100644 --- a/src/assets/i18n/participant/en.json +++ b/src/assets/i18n/participant/en.json @@ -141,7 +141,6 @@ "error-comment-data": "Too much formatting or linked elements. Please remove some.", "error-title": "Please enter a title.", "exit-description": "Exit Presentation Mode", - "format-count": "Formatting characters {{count}}/{{length}}", "has-answer": "The question was answered. Click for full view.", "live-announcer": "You are now on the questions page. To get information about key combinations press the Enter key or call the announcement later with the Escape key.", "mark-not-correct": "Marked as correct",