From 46f6b008b4bb9041ca2560816cc50379ac961efb Mon Sep 17 00:00:00 2001 From: JulianPienaar <104741835+JulianPienaar@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:19:27 +0200 Subject: [PATCH] More sonar fixes --- frontend/src/app/edit/edit.component.ts | 19 ++- .../app/services/version.control.service.ts | 135 ------------------ 2 files changed, 8 insertions(+), 146 deletions(-) diff --git a/frontend/src/app/edit/edit.component.ts b/frontend/src/app/edit/edit.component.ts index fc7fa759..241dca60 100644 --- a/frontend/src/app/edit/edit.component.ts +++ b/frontend/src/app/edit/edit.component.ts @@ -4,10 +4,10 @@ import { ElementRef, HostListener, OnInit, - ViewChild, + Inject, } from '@angular/core'; import { Router } from '@angular/router'; -import { MenuItem } from 'primeng/api'; +import { MenuItem, MessageService, ConfirmationService } from 'primeng/api'; import { FileUploadPopupComponent } from '../file-upload-popup/file-upload-popup.component'; import { ImageUploadPopupComponent } from '../image-upload-popup/image-upload-popup.component'; import { Clipboard } from '@angular/cdk/clipboard'; @@ -16,15 +16,11 @@ import { FileService } from '../services/file.service'; import { EditService } from '../services/edit.service'; import { AssetService } from '../services/asset.service'; import { VersionControlService } from '../services/version.control.service'; -import { Inject } from '@angular/core'; -import { MessageService, ConfirmationService } from 'primeng/api'; -import { set } from 'cypress/types/lodash'; -import { PageBreak } from '@ckeditor/ckeditor5-page-break'; +import { VersioningApiService } from '../services/versioning-api.service'; import html2pdf from 'html2pdf.js/dist/html2pdf'; import DecoupledEditor from '@ckeditor/ckeditor5-build-decoupled-document'; -import { parse } from 'path'; import { SnapshotDTO } from '../services/dto/snapshot.dto'; import { DiffDTO } from '../services/dto/diff.dto'; @@ -60,7 +56,8 @@ export class EditComponent implements AfterViewInit, OnInit { private clipboard: Clipboard, private messageService: MessageService, private versionControlService: VersionControlService, - private confirmationService: ConfirmationService + private confirmationService: ConfirmationService, + private versioningApiService: VersioningApiService ) {} @HostListener('window:beforeunload', ['$event']) @@ -375,7 +372,7 @@ export class EditComponent implements AfterViewInit, OnInit { ); if (readablePatch !== '') - this.versionControlService.saveDiff( + this.versioningApiService.saveDiff( markdownID ? (markdownID as string) : '', this.fileService.encryptSafeLockDocument(readablePatch, pass) ); @@ -388,7 +385,7 @@ export class EditComponent implements AfterViewInit, OnInit { ); if (readablePatch !== '') - this.versionControlService.saveDiff( + this.versioningApiService.saveDiff( markdownID ? (markdownID as string) : '', readablePatch ); @@ -616,7 +613,7 @@ export class EditComponent implements AfterViewInit, OnInit { async refreshSidebarHistory() { this.history = []; - this.versionControlService + this.versioningApiService .retrieveAllHistory(this.editService.getMarkdownID() as string) .then((data) => { const snapshot = JSON.parse( diff --git a/frontend/src/app/services/version.control.service.ts b/frontend/src/app/services/version.control.service.ts index a88c5102..ce56e2d4 100644 --- a/frontend/src/app/services/version.control.service.ts +++ b/frontend/src/app/services/version.control.service.ts @@ -245,139 +245,4 @@ export class VersionControlService { this.sortSnapshotArr(this.snapshotArr); this.sortDiffArr(this.diffArr); } - - saveDiff( - fileID: string, - content: string - ): Promise { - return new Promise((resolve, reject) => { - this.sendSaveDiff(fileID, content).subscribe({ - next: (response: HttpResponse) => { - if (response.status === 200) { - resolve(true); - } else { - resolve(false); - } - }, - }); - }); - } - - sendSaveDiff( - markdownID: string, - content: string - ): Observable> { - const environmentURL = environment.apiURL; - const url = `${environmentURL}version_control/save_diff`; - console.log(url); - const body = new DiffDTO(); - - body.UserID = this.userService.getUserID() as number; - body.Content = content; - body.MarkdownID = markdownID; - const headers = new HttpHeaders().set( - 'Authorization', - 'Bearer ' + this.userService.getAuthToken() - ); - console.log(body); - return this.http.post(url, body, { headers, observe: 'response' }); - } - - retrieveAllSnapshots(markdownID: string): Promise { - return new Promise((resolve, reject) => { - this.sendRetrieveAllSnapshots(markdownID).subscribe({ - next: (response: HttpResponse) => { - console.log(response); - if (response.status === 200) { - resolve(response.body); - } else { - resolve(null); - } - }, - }); - }); - } - - sendRetrieveAllSnapshots(markdownID: string): Observable> { - const environmentURL = environment.apiURL; - const url = `${environmentURL}version_control/get_all_snapshots`; - console.log(url); - const body = new SnapshotDTO(); - - body.UserID = this.userService.getUserID() as number; - body.MarkdownID = markdownID; - const headers = new HttpHeaders().set( - 'Authorization', - 'Bearer ' + this.userService.getAuthToken() - ); - return this.http.post(url, body, { headers, observe: 'response' }); - } - - retrieveAllHistory(markdownID: string): Promise { - return new Promise((resolve, reject) => { - this.sendRetrieveAllHistory(markdownID).subscribe({ - next: (response: HttpResponse) => { - console.log('Backend data response: ', response); - if (response.status === 200) { - resolve(response.body); - } else { - resolve(null); - } - }, - }); - }); - } - - sendRetrieveAllHistory(markdownID: string): Observable> { - const environmentURL = environment.apiURL; - const url = `${environmentURL}version_control/load_history`; - console.log(url); - const body = new MarkdownFileDTO(); - - body.UserID = this.userService.getUserID() as number; - body.MarkdownID = markdownID; - const headers = new HttpHeaders().set( - 'Authorization', - 'Bearer ' + this.userService.getAuthToken() - ); - return this.http.post(url, body, { headers, observe: 'response' }); - } - loadHistorySet( - markdownID: string, - diffHistory: string[], - snapshotID: string - ) { - return new Promise((resolve, reject) => { - this.sendLoadHistorySet(markdownID, diffHistory, snapshotID).subscribe({ - next: (response: HttpResponse) => { - console.log(response); - if (response.status === 200) { - resolve(response.body); - } else { - resolve(null); - } - }, - }); - }); - } - - sendLoadHistorySet( - markdownID: string, - diffHistory: string[], - snapshotID: string - ): Observable> { - const environmentURL = environment.apiURL; - const url = `${environmentURL}version_control/get_history_set`; - const body = new VersionSetDTO(); - - body.UserID = this.userService.getUserID() as number; - body.MarkdownID = markdownID; - body.DiffHistory = diffHistory; - body.SnapshotID = snapshotID; - const headers = new HttpHeaders().set( - 'Authorization', - 'Bearer ' + this.userService.getAuthToken() - ); - return this.http.post(url, body, { headers, observe: 'response' }); - } }