From d95995fb67cdefe487875bc8213ad6a070cadfed Mon Sep 17 00:00:00 2001 From: Dylan Kapnias Date: Sun, 22 Oct 2023 21:05:47 +0200 Subject: [PATCH 1/2] Add lines to improve prettier output --- frontend/src/app/services/version.control.service.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/services/version.control.service.ts b/frontend/src/app/services/version.control.service.ts index 6b024f73..27b1f4ec 100644 --- a/frontend/src/app/services/version.control.service.ts +++ b/frontend/src/app/services/version.control.service.ts @@ -235,6 +235,7 @@ export class VersionControlService { const close_del = /<\/del/g; const del_color = /#ffe6e6/g; const ins_color = /#e6ffe6/g; + const close_para = /<\/p>/g; const repl_text1 = text1 .replace(pattern_amp, '&') @@ -251,7 +252,10 @@ export class VersionControlService { .replace(pattern_nbsp, ''); // const dpsDiff = this.DiffPatchService.diff_main(repl_text1, repl_text2); - const dpsDiff = this.LineDiff(repl_text1, repl_text2); + const dpsDiff = this.LineDiff( + repl_text1.replace(close_para, '

\n'), + repl_text2.replace(close_para, '

\n') + ); this.DiffPatchService.diff_cleanupSemantic(dpsDiff); const prettyHtml = this.DiffPatchService.diff_prettyHtml(dpsDiff); @@ -267,11 +271,6 @@ export class VersionControlService { .replace(del_color, '#f995ab') .replace(ins_color, '#96ff9f'); - console.log('version.control.getPrettyHtml.repl_text1:', repl_text1); - console.log('version.control.getPrettyHtml.repl_text2:', repl_text2); - console.log('version.control.getPrettyHtml.dpsDiff:', dpsDiff); - console.log('version.control.getPrettyHtml.prettyHtml:', replPretty); - return prettyHtml .replace(pattern_amp, '&') .replace(pattern_lt, '<') From 323fefed06c0d2026e6c51cdf69cae8dae1e7945 Mon Sep 17 00:00:00 2001 From: Dylan Kapnias Date: Mon, 23 Oct 2023 12:20:20 +0200 Subject: [PATCH 2/2] Code smell removals --- .../app/services/version.control.service.ts | 81 +++---------------- 1 file changed, 9 insertions(+), 72 deletions(-) diff --git a/frontend/src/app/services/version.control.service.ts b/frontend/src/app/services/version.control.service.ts index 27b1f4ec..332898fe 100644 --- a/frontend/src/app/services/version.control.service.ts +++ b/frontend/src/app/services/version.control.service.ts @@ -2,19 +2,14 @@ import { Injectable } from '@angular/core'; import { UserService } from './user.service'; import { diff_match_patch as DiffMatchPatch } from 'diff-match-patch'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { Observable } from 'rxjs'; -import { HttpResponse } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { MessageService } from 'primeng/api'; -import { environment } from '../../environments/environment'; import { DiffDTO } from './dto/diff.dto'; import { SnapshotDTO } from './dto/snapshot.dto'; -import { MarkdownFileDTO } from './dto/markdown_file.dto'; import { FileService } from './file.service'; import { VersionDTO } from './dto/version.dto'; -import { VersionSetDTO } from './dto/version_set.dto'; @Injectable({ providedIn: 'root', @@ -34,22 +29,6 @@ export class VersionControlService { private latestVersion: VersionDTO = new VersionDTO(); private DiffPatchService = new DiffMatchPatch(); - // async test(): Promise { - // let text1: string = ''; - // let text2: string = ''; - // const filePath1 = '../assets/VersionControl/test1.txt'; - // const filePath2 = '../assets/VersionControl/test2.txt'; - // this.http.get(filePath1, { responseType: 'text' }).subscribe((data) => { - // text1 = data; - // this.http.get(filePath2, { responseType: 'text' }).subscribe((data) => { - // text2 = data; - - // const diff = this.DiffPatchService.diff_main(text1, text2); - // const patches = this.DiffPatchService.patch_make(diff); - // }); - // }); - // } - async init(): Promise { this.snapshotArr = []; this.diffArr = []; @@ -68,7 +47,7 @@ export class VersionControlService { for (let element of snapshotPathArr) { this.http.get(element, { responseType: 'text' }).subscribe((data) => { - var tempDTO = new SnapshotDTO(); + let tempDTO = new SnapshotDTO(); tempDTO.MarkdownID = 'abc123'; tempDTO.SnapshotNumber = +element.charAt(element.length - 1); tempDTO.Content = data; @@ -78,9 +57,8 @@ export class VersionControlService { for (let element of diffPathArr) { this.http.get(element, { responseType: 'text' }).subscribe((data) => { - var tempDTO = new DiffDTO(); + let tempDTO = new DiffDTO(); tempDTO.MarkdownID = 'abc123'; - // tempDTO.snapshotNumber = this.snapshotArr[0].snapshotNumber; tempDTO.Content = data; this.pushToDiffArr(tempDTO); }); @@ -117,25 +95,6 @@ export class VersionControlService { return this.snapshotArr; } - sortSnapshotArr(inArr: SnapshotDTO[]): void { - // Ascending sort on snapshotNumber - inArr.sort((a, b) => - a.SnapshotNumber > b.SnapshotNumber - ? 1 - : a.SnapshotNumber < b.SnapshotNumber - ? -1 - : 0 - ); - } - - sortDiffArr(inArr: DiffDTO[]): void { - // Ascending sort on diffNumber - inArr.sort( - (a, b) => - a.DiffNumber > b.DiffNumber ? 1 : a.DiffNumber < b.DiffNumber ? -1 : 0 // TODO: Rework - ); - } - visualise(): void { // Build snapshot version for (let element of this.snapshotArr) { @@ -199,11 +158,9 @@ export class VersionControlService { let retString = snapshot.Content; const tempArr = this.diffArr.filter((ele) => { - return ele.DiffNumber < diff.DiffNumber; // TODO: Rework + return ele.DiffNumber < diff.DiffNumber; }); - this.sortDiffArr(tempArr); - for (let element of tempArr) { let patches = this.DiffPatchService.patch_fromText(element.Content); retString = this.DiffPatchService.patch_apply(patches, retString)[0]; @@ -251,7 +208,6 @@ export class VersionControlService { .replace(pattern_para, '\n') .replace(pattern_nbsp, ''); - // const dpsDiff = this.DiffPatchService.diff_main(repl_text1, repl_text2); const dpsDiff = this.LineDiff( repl_text1.replace(close_para, '

\n'), repl_text2.replace(close_para, '

\n') @@ -259,17 +215,6 @@ export class VersionControlService { this.DiffPatchService.diff_cleanupSemantic(dpsDiff); const prettyHtml = this.DiffPatchService.diff_prettyHtml(dpsDiff); - const replPretty = prettyHtml - .replace(pattern_amp, '&') - .replace(pattern_lt, '<') - .replace(pattern_gt, '>') - .replace(pattern_para, '\n') - .replace(open_ins, ' { return ele.SnapshotNumber <= snapshot.SnapshotNumber; }); @@ -303,13 +247,9 @@ export class VersionControlService { this.diffArr = this.diffArr.filter((ele) => { return ele.SnapshotNumber <= snapshot.SnapshotNumber; }); - - this.sortSnapshotArr(this.snapshotArr); - this.sortDiffArr(this.diffArr); } diffRestore(diff: DiffDTO): void { - //TODO: Rework this.snapshotArr = this.snapshotArr.filter((ele) => { return ele.SnapshotNumber <= diff.SnapshotNumber; }); @@ -317,8 +257,5 @@ export class VersionControlService { this.diffArr = this.diffArr.filter((ele) => { return ele.SnapshotNumber <= diff.SnapshotNumber; }); - - this.sortSnapshotArr(this.snapshotArr); - this.sortDiffArr(this.diffArr); } }