diff --git a/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts b/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts index 2834c7441bf9cc6300ba5edf46a8e4916a18a238..501cb1d2b8eac23a3bcd1b29512c611c33fdea14 100644 --- a/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts +++ b/src/app/components/creator/_dialogs/comment-settings/comment-settings.component.ts @@ -9,10 +9,8 @@ import { CommentService } from '../../../../services/http/comment.service'; import { BonusTokenService } from '../../../../services/http/bonus-token.service'; import { DeleteCommentsComponent } from '../delete-comments/delete-comments.component'; import { Room } from '../../../../models/room'; -import { CommentBonusTokenMixin } from '../../../../models/comment-bonus-token-mixin'; import { CommentSettings } from '../../../../models/comment-settings'; import { CommentSettingsDialog } from '../../../../models/comment-settings-dialog'; -import { ExportCsv } from '../../../../models/export-csv'; import { Export } from '../../../../models/export'; @Component({ @@ -47,7 +45,7 @@ export class CommentSettingsComponent implements OnInit { ngOnInit() { if (this.editRoom.threshold !== null) { this.commentThreshold = this.editRoom.threshold; - this.settingThreshold = true; + this.settingThreshold = !!this.editRoom.threshold; } this.tags = []; this.enableCommentModeration = this.editRoom.moderated; @@ -101,13 +99,12 @@ export class CommentSettingsComponent implements OnInit { const settingsReturn = new CommentSettingsDialog(); this.editRoom.directSend = this.directSend; - this.editRoom.threshold = this.commentThreshold; + this.editRoom.threshold = this.settingThreshold ? this.commentThreshold : 0; this.editRoom.moderated = this.enableCommentModeration; // If moderation isn't enabled, the direct send is of no interest and shouldn't be updated to avoid confusion about missing comments if ((this.enableCommentModeration && !this.directSend) || this.directSend) { - this.roomService.updateRoom(this.editRoom).subscribe(x => { - }); + this.roomService.updateRoom(this.editRoom).subscribe(); settingsReturn.directSend = this.directSend; } settingsReturn.enableModeration = this.enableCommentModeration; 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 1c18a3975852a912ab416a1d8154b56b0d16cd4e..5425e1e0a7e0f4393e4a23dd94ec117426ced4ab 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 @@ -1,7 +1,8 @@ <ars-row ars-flex-box> <app-write-comment [confirmLabel]="'send'" [isQuestionerNameEnabled]="true" - [onSubmit]="this.closeDialog.bind(this)" + [onSubmit]="this.forwardComment.bind(this)" + [onDeeplSubmit]="this.closeDialog.bind(this)" [onClose]="this.onNoClick.bind(this)" [isSpinning]="isSendingToSpacy" [tags]="tags" diff --git a/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts b/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts index 20b6adde434892a865b4408c9e40b63dccb44c52..12ddadb5c28685d76562b98182867fcaed028841 100644 --- a/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts +++ b/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts @@ -6,9 +6,11 @@ import { TranslateService } from '@ngx-translate/core'; import { User } from '../../../../models/user'; import { EventService } from '../../../../services/util/event.service'; import { SpacyDialogComponent } from '../spacy-dialog/spacy-dialog.component'; -import { LanguagetoolService, Language } from '../../../../services/http/languagetool.service'; +import { LanguagetoolService, Language, LanguagetoolResult } from '../../../../services/http/languagetool.service'; import { CreateCommentKeywords } from '../../../../utils/create-comment-keywords'; import { WriteCommentComponent } from '../../write-comment/write-comment.component'; +import { DeepLDialogComponent } from '../deep-ldialog/deep-ldialog.component'; +import { DeepLService, SourceLang, TargetLang } from '../../../../services/http/deep-l.service'; @Component({ selector: 'app-submit-comment', @@ -30,6 +32,7 @@ export class CreateCommentComponent implements OnInit { private translateService: TranslateService, public dialog: MatDialog, public languagetoolService: LanguagetoolService, + private deeplService: DeepLService, public eventService: EventService, @Inject(MAT_DIALOG_DATA) public data: any) { } @@ -43,7 +46,15 @@ export class CreateCommentComponent implements OnInit { this.dialogRef.close(); } + forwardComment(body: string, text: string, tag: string, name: string, verifiedWithoutDeepl: boolean) { + this.createComment(body, text, tag, name, !verifiedWithoutDeepl); + } + closeDialog(body: string, text: string, tag: string, name: string) { + this.createComment(body, text, tag, name); + } + + createComment(body: string, text: string, tag: string, name: string, forward = false) { const comment = new Comment(); comment.roomId = localStorage.getItem(`roomId`); comment.body = body; @@ -52,43 +63,67 @@ export class CreateCommentComponent implements OnInit { comment.tag = tag; comment.questionerName = name; this.isSendingToSpacy = true; - this.openSpacyDialog(comment, text); + this.openSpacyDialog(comment, text, forward); } - openSpacyDialog(comment: Comment, rawText: string): void { + openSpacyDialog(comment: Comment, rawText: string, forward: boolean): void { CreateCommentKeywords.isSpellingAcceptable(this.languagetoolService, rawText, this.commentComponent.selectedLang) .subscribe((result) => { if (result.isAcceptable) { - const commentLang = this.languagetoolService.mapLanguageToSpacyModel(result.result.language.code as Language); - const selectedLangExtend = this.commentComponent.selectedLang[2] === '-' ? - this.commentComponent.selectedLang.substr(0, 2) : this.commentComponent.selectedLang; - // Store language if it was auto-detected - if (this.commentComponent.selectedLang === 'auto') { - comment.language = Comment.mapModelToLanguage(commentLang); - } else if (CommentLanguage[selectedLangExtend]) { - comment.language = CommentLanguage[selectedLangExtend]; + if (forward) { + this.callDeepL(comment, result.text, result.result); + } else { + this.callSpacy(comment, result.text, result.result); } - const dialogRef = this.dialog.open(SpacyDialogComponent, { - data: { - comment, - commentLang, - commentBodyChecked: result.text - } - }); - dialogRef.afterClosed().subscribe(dialogResult => { - if (dialogResult) { - this.dialogRef.close(dialogResult); - } - }); } else { comment.language = CommentLanguage.auto; this.dialogRef.close(comment); + this.isSendingToSpacy = false; } - this.isSendingToSpacy = false; }, () => { comment.language = CommentLanguage.auto; this.dialogRef.close(comment); this.isSendingToSpacy = false; }); } + + private callDeepL(comment: Comment, text: string, result: LanguagetoolResult) { + let target = TargetLang.EN_US; + const code = result.language.detectedLanguage.code.toUpperCase().split('-')[0]; + if (code.startsWith(SourceLang.EN)) { + target = TargetLang.DE; + } + DeepLDialogComponent.generateDeeplDelta(this.deeplService, comment.body, target) + .subscribe(([_, improvedText]) => { + this.callSpacy(comment, CreateCommentKeywords.escapeForSpacy(improvedText), result, true); + }, () => { + this.callSpacy(comment, text, result, true); + }); + } + + private callSpacy(comment: Comment, text: string, result: LanguagetoolResult, forward = false) { + const commentLang = this.languagetoolService.mapLanguageToSpacyModel(result.language.code as Language); + const selectedLangExtend = this.commentComponent.selectedLang[2] === '-' ? + this.commentComponent.selectedLang.substr(0, 2) : this.commentComponent.selectedLang; + // Store language if it was auto-detected + if (this.commentComponent.selectedLang === 'auto') { + comment.language = Comment.mapModelToLanguage(commentLang); + } else if (CommentLanguage[selectedLangExtend]) { + comment.language = CommentLanguage[selectedLangExtend]; + } + this.isSendingToSpacy = false; + const dialogRef = this.dialog.open(SpacyDialogComponent, { + data: { + comment, + commentLang, + commentBodyChecked: text, + forward + } + }); + dialogRef.afterClosed().subscribe(dialogResult => { + if (dialogResult) { + this.dialogRef.close(dialogResult); + } + }); + } } diff --git a/src/app/components/shared/_dialogs/deep-ldialog/deep-ldialog.component.ts b/src/app/components/shared/_dialogs/deep-ldialog/deep-ldialog.component.ts index ac5e45af659453e526a4b06f53e2b64d0eb34c14..5844ca5d937fb344a7157ba2bbcd9112332d5b4c 100644 --- a/src/app/components/shared/_dialogs/deep-ldialog/deep-ldialog.component.ts +++ b/src/app/components/shared/_dialogs/deep-ldialog/deep-ldialog.component.ts @@ -10,7 +10,7 @@ import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { CreateCommentKeywords } from '../../../../utils/create-comment-keywords'; -interface ResultValue { +export interface ResultValue { body: string; text: string; view: ViewCommentDataComponent; @@ -95,7 +95,7 @@ export class DeepLDialogComponent implements OnInit, AfterViewInit { text: this.data.improvedText, view: this.improved }; - this.radioButtonValue = this.improvedValue; + this.radioButtonValue = this.normalValue; } ngAfterViewInit() { @@ -124,7 +124,7 @@ export class DeepLDialogComponent implements OnInit, AfterViewInit { } if (ViewCommentDataComponent.checkInputData(current.body, current.text, this.translateService, this.notificationService, this.data.maxTextCharacters, this.data.maxDataCharacters)) { - this.data.onClose(current.body, current.text, current.view); + this.data.onClose(current); this.dialogRef.close(true); } }; diff --git a/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts b/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts index b59c7c531251796aad8524a6f0bb4f5869e0d53c..d31762cc223b63b29718e60b93256b1615de0635 100644 --- a/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts +++ b/src/app/components/shared/_dialogs/spacy-dialog/spacy-dialog.component.ts @@ -53,6 +53,10 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit { ngAfterContentInit(): void { if (this.langSupported) { this.evalInput(this.commentLang); + } else if (this.data.forward) { + this.keywords = []; + this.keywordsOriginal = []; + setTimeout(() => this.buildCreateCommentActionCallback()()); } } @@ -76,6 +80,11 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit { evalInput(model: Model) { this.isLoading = true; + const afterFinish = () => { + if (this.data.forward) { + this.buildCreateCommentActionCallback()(); + } + }; // N at first pos = all Nouns(NN de/en) including singular(NN, NNP en), plural (NNPS, NNS en), proper Noun(NNE, NE de) this.spacyService.getKeywords(this.commentBodyChecked, model) @@ -95,8 +104,10 @@ export class SpacyDialogComponent implements OnInit, AfterContentInit { this.keywordsOriginal = []; this.hasKeywordsFromSpacy = false; this.isLoading = false; + afterFinish(); }, () => { this.isLoading = false; + afterFinish(); }); } diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index 2a746b20e4d83cb1c91b94e8c88af70ff0650e8b..94e0bebd71b7be2c35bbb73938a2c8daeeff8fcc 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -348,21 +348,8 @@ export class CommentListComponent implements OnInit, OnDestroy { } getComments(): void { - if (this.room.threshold) { - this.thresholdEnabled = true; - } else { - this.thresholdEnabled = false; - } + this.thresholdEnabled = !!this.room.threshold; this.isLoading = false; - let commentThreshold; - if (this.thresholdEnabled) { - commentThreshold = this.room.threshold; - if (this.hideCommentsList) { - this.filteredComments = this.filteredComments.filter(x => x.score >= commentThreshold); - } else { - this.setComments(this.comments.filter(x => x.score >= commentThreshold)); - } - } this.setTimePeriod(); } @@ -601,6 +588,7 @@ export class CommentListComponent implements OnInit, OnDestroy { this.period = period; this.fromNow = null; } + const comments = this.thresholdEnabled ? this.comments.filter(x => x.score >= this.room.threshold) : this.comments; const currentTime = new Date(); const hourInSeconds = 3600000; let periodInSeconds; @@ -627,11 +615,11 @@ export class CommentListComponent implements OnInit, OnDestroy { periodInSeconds = hourInSeconds * 336; break; } - this.commentsFilteredByTime = this.comments + this.commentsFilteredByTime = comments .filter(c => new Date(c.timestamp).getTime() >= (this.period === Period.fromNow ? this.fromNow : (currentTime.getTime() - periodInSeconds))); } else { - this.commentsFilteredByTime = this.comments; + this.commentsFilteredByTime = comments; } this.filterComments(this.currentFilter, this.currentFilterCompare); diff --git a/src/app/components/shared/comment/comment.component.html b/src/app/components/shared/comment/comment.component.html index 7ded0d2e6a8564510143addf2ee31727c7b16f27..ea2e4385d534c5abe56637dcb572f65ae5b1867a 100644 --- a/src/app/components/shared/comment/comment.component.html +++ b/src/app/components/shared/comment/comment.component.html @@ -262,7 +262,7 @@ role="button" style="width:100%;" tabindex="0"> - <ars-row #commentBody> + <ars-row #commentBody class="commentBody"> <ars-row #commentBodyInner> <app-view-comment-data class="images" [currentData]="comment.body"></app-view-comment-data> </ars-row> @@ -306,17 +306,15 @@ }}">{{comment.score}}</span> </div> </div> - <ars-row #commentExpander - ars-flex-box - [height]="37"> - <ars-fill></ars-fill> - <ars-col> - <button mat-button + <ars-row ars-flex-box #commentExpander> + <ars-fill> + <button mat-button style="width:100%;" (click)="toggleExpand($event)"><span class="commentExpanderButton"> - {{ isExpanded ? ('comment-page.show-less' | translate) : ('comment-page.show-more' | translate) }} - </span></button> + {{ isExpanded ? ('comment-page.show-less' | translate) : ('comment-page.show-more' | translate) }} + </span></button> + </ars-fill> + <ars-col [width]="16"> </ars-col> - <ars-fill></ars-fill> </ars-row> <div fxLayout="row" fxLayoutAlign="start center"> diff --git a/src/app/components/shared/comment/comment.component.scss b/src/app/components/shared/comment/comment.component.scss index f885388491b9da9b53216c6d5b96c4340e74eafd..54210399d84560176417cd8e0bc512a02727d888 100644 --- a/src/app/components/shared/comment/comment.component.scss +++ b/src/app/components/shared/comment/comment.component.scss @@ -285,6 +285,10 @@ mat-card-content > :first-child { color: var(--on-surface); } +.commentBody{ + transition:height ease-in-out 0.2s; +} + @keyframes upVote { 0% { transform: scale3d(1, 1, 1); diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts index 563184abe51f96c93b7da93dba4a4d06805cb18e..d5a2f2b06ad4e075277d8ca2c7c4ca648ce5c2ac 100644 --- a/src/app/components/shared/comment/comment.component.ts +++ b/src/app/components/shared/comment/comment.component.ts @@ -36,7 +36,7 @@ import { UserBonusTokenComponent } from '../../participant/_dialogs/user-bonus-t export class CommentComponent implements OnInit, AfterViewInit { - static COMMENT_MAX_HEIGHT = 200; + static COMMENT_MAX_HEIGHT = 150; @Input() comment: Comment; @Input() moderator: boolean; @@ -109,7 +109,7 @@ export class CommentComponent implements OnInit, AfterViewInit { const subscription = this.roomDataService.checkProfanity(this.comment).subscribe(e => { if (e !== null) { this.isProfanity = e; - subscription.unsubscribe(); + setTimeout(() => subscription.unsubscribe()); } }); } @@ -121,13 +121,15 @@ export class CommentComponent implements OnInit, AfterViewInit { } ngAfterViewInit(): void { - this.isExpandable = this.commentBody.getRenderedHeight() > CommentComponent.COMMENT_MAX_HEIGHT; - if (!this.isExpandable) { - this.commentExpander.ref.nativeElement.style.display = 'none'; - } else { - this.commentBody.setPx(CommentComponent.COMMENT_MAX_HEIGHT); - this.commentBody.setOverflow('hidden'); - } + setTimeout(()=>{ + this.isExpandable = this.commentBody.getRenderedHeight() > CommentComponent.COMMENT_MAX_HEIGHT; + if (!this.isExpandable) { + this.commentExpander.ref.nativeElement.style.display = 'none'; + } else { + this.commentBody.setPx(CommentComponent.COMMENT_MAX_HEIGHT); + this.commentBody.setOverflow('hidden'); + } + }); } sortKeywords(keywords: SpacyKeyword[]) { diff --git a/src/app/components/shared/tag-cloud/tag-cloud.component.ts b/src/app/components/shared/tag-cloud/tag-cloud.component.ts index e71cdbbe34fd31b5d71ce8305622c93fe7292618..7f8955384f86be47ec8db65168e78532b49e2c44 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.component.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud.component.ts @@ -357,7 +357,7 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit { return; } this._subscriptionCommentlist = this.eventService.on('commentListCreated').subscribe(() => { - this.eventService.broadcast('setTagConfig', tag.text); + this.eventService.broadcast('setTagConfig', (tag as TagComment).realText); this._subscriptionCommentlist.unsubscribe(); }); this.router.navigate(['../'], { relativeTo: this.route }); 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 9989ec458ca660906022aac0723601fd44268190..af8aca65b9f03ddf0f180a8b870eb5572beee464 100644 --- a/src/app/components/shared/write-comment/write-comment.component.html +++ b/src/app/components/shared/write-comment/write-comment.component.html @@ -88,7 +88,7 @@ [showDivider]="false" [spacing]="false" [cancelButtonClickAction]="buildCloseDialogActionCallback()" - [confirmButtonClickAction]="buildCreateCommentActionCallback()" + [confirmButtonClickAction]="buildCreateCommentActionCallback(this.onSubmit)" ></app-dialog-action-buttons> </ars-col> </ars-row> 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 994fbffc08e147ebd09287fe2c6424940e3014c6..5e0e5152cfa92f6caefa8d8513734ee26bee29a8 100644 --- a/src/app/components/shared/write-comment/write-comment.component.ts +++ b/src/app/components/shared/write-comment/write-comment.component.ts @@ -6,10 +6,13 @@ import { NotificationService } from '../../../services/util/notification.service import { LanguageService } from '../../../services/util/language.service'; import { ViewCommentDataComponent } from '../view-comment-data/view-comment-data.component'; import { DeepLService, SourceLang, TargetLang } from '../../../services/http/deep-l.service'; -import { DeepLDialogComponent } from '../_dialogs/deep-ldialog/deep-ldialog.component'; +import { DeepLDialogComponent, ResultValue } from '../_dialogs/deep-ldialog/deep-ldialog.component'; import { MatDialog } from '@angular/material/dialog'; import { FormControl, Validators } from '@angular/forms'; +type SubmitFunction = (commentData: string, commentText: string, selectedTag: string, name?: string, + verifiedWithoutDeepl?: boolean) => any; + @Component({ selector: 'app-write-comment', templateUrl: './write-comment.component.html', @@ -22,7 +25,8 @@ export class WriteCommentComponent implements OnInit { @Input() isModerator = false; @Input() tags: string[]; @Input() onClose: () => any; - @Input() onSubmit: (commentData: string, commentText: string, selectedTag: string, name?: string) => any; + @Input() onSubmit: SubmitFunction; + @Input() onDeeplSubmit: SubmitFunction; @Input() isSpinning = false; @Input() disableCancelButton = false; @Input() confirmLabel = 'save'; @@ -46,6 +50,7 @@ export class WriteCommentComponent implements OnInit { questionerNameFormControl = new FormControl('', [ Validators.minLength(2), Validators.maxLength(20) ]); + private _wasVerifiedWithoutDeepl = false; constructor(private notification: NotificationService, private languageService: LanguageService, @@ -75,8 +80,8 @@ export class WriteCommentComponent implements OnInit { return () => this.onClose(); } - buildCreateCommentActionCallback(): () => void { - if (!this.onSubmit) { + buildCreateCommentActionCallback(func: SubmitFunction): () => void { + if (!func) { return undefined; } return () => { @@ -88,7 +93,8 @@ export class WriteCommentComponent implements OnInit { } if (ViewCommentDataComponent.checkInputData(this.commentData.currentData, this.commentData.currentText, this.translateService, this.notification, this.maxTextCharacters, this.maxDataCharacters) && allowed) { - this.onSubmit(this.commentData.currentData, this.commentData.currentText, this.selectedTag, this.questionerNameFormControl.value); + func(this.commentData.currentData, this.commentData.currentText, this.selectedTag, + this.questionerNameFormControl.value, this._wasVerifiedWithoutDeepl); } }; } @@ -121,12 +127,13 @@ export class WriteCommentComponent implements OnInit { } const previous = this.commentData.currentData; this.openDeeplDialog(previous, rawText, wordsCheck, - (data: string, text: string, view: ViewCommentDataComponent) => { - if (view === this.commentData) { + (selected) => { + if (selected.view === this.commentData) { + this._wasVerifiedWithoutDeepl = true; this.commentData.buildMarks(rawText, wordsCheck); } else { - this.commentData.currentData = data; - this.commentData.copyMarks(view); + this.commentData.currentData = selected.body; + this.commentData.copyMarks(selected.view); } }); }, () => { @@ -145,7 +152,7 @@ export class WriteCommentComponent implements OnInit { private openDeeplDialog(body: string, text: string, result: LanguagetoolResult, - onClose: (data: string, text: string, view: ViewCommentDataComponent) => void) { + onClose: (selected: ResultValue) => void) { let target = TargetLang.EN_US; const code = result.language.detectedLanguage.code.toUpperCase().split('-')[0]; const source = code in SourceLang ? SourceLang[code] : null; @@ -156,10 +163,10 @@ export class WriteCommentComponent implements OnInit { .subscribe(([improvedBody, improvedText]) => { this.isSpellchecking = false; if (improvedText.replace(/\s+/g, '') === text.replace(/\s+/g, '')) { - onClose(body, text, this.commentData); + onClose({ body, text, view: this.commentData }); return; } - this.dialog.open(DeepLDialogComponent, { + const instance = this.dialog.open(DeepLDialogComponent, { width: '900px', maxWidth: '100%', data: { @@ -175,14 +182,17 @@ export class WriteCommentComponent implements OnInit { target: DeepLService.transformSourceToTarget(source), usedTarget: target } - }).afterClosed().subscribe((val) => { + }); + instance.afterClosed().subscribe((val) => { if (val) { - this.buildCreateCommentActionCallback()(); + this.buildCreateCommentActionCallback(this.onDeeplSubmit)(); + } else { + onClose({ body, text, view: this.commentData }); } }); }, (_) => { this.isSpellchecking = false; - onClose(body, text, this.commentData); + onClose({ body, text, view: this.commentData }); }); } diff --git a/src/app/directives/accessibility-escaped-input.directive.ts b/src/app/directives/accessibility-escaped-input.directive.ts index bc2f956795ccb9c84a248fb6eae047f8ef1b98f0..1e518050e8fd1887351b708feac458b61c0d9007 100644 --- a/src/app/directives/accessibility-escaped-input.directive.ts +++ b/src/app/directives/accessibility-escaped-input.directive.ts @@ -14,7 +14,7 @@ export class AccessibilityEscapedInputDirective implements AfterViewInit { const elem = this.reference.nativeElement; elem.addEventListener('focus', this.focus.bind(this)); elem.addEventListener('blur', this.blur.bind(this)); - if (document.activeElement && document.activeElement.contains(elem)) { + if (elem && document.activeElement && elem.contains(document.activeElement)) { this.focus(); } } diff --git a/src/app/utils/create-comment-keywords.ts b/src/app/utils/create-comment-keywords.ts index fb6e073b3a2fe856d6ab70a6f0c244995a7bd82f..e827d8c1c5b330c1b8495f0b9cc78a572cbe6378 100644 --- a/src/app/utils/create-comment-keywords.ts +++ b/src/app/utils/create-comment-keywords.ts @@ -19,7 +19,7 @@ export class CreateCommentKeywords { map(result => { const wordCount = text.trim().split(' ').length; const hasConfidence = language === 'auto' ? result.language.detectedLanguage.confidence >= 0.5 : true; - const hasLessMistakes = (result.matches.length * 100) / wordCount <= 20; + const hasLessMistakes = (result.matches.length * 100) / wordCount <= 50; return { isAcceptable: hasConfidence && hasLessMistakes, text: this.escapeForSpacy(text), @@ -29,7 +29,7 @@ export class CreateCommentKeywords { ); } - private static escapeForSpacy(text: string): string { + static escapeForSpacy(text: string): string { text = this.makeCapslockLowercase(text); return text.replace(/\(([^-\s)]+-)\)([^\s]+)/gmi, '$1$2'); }