Skip to content

Commit

Permalink
More sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianPienaar committed Sep 21, 2023
1 parent c299e5d commit 46f6b00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 146 deletions.
19 changes: 8 additions & 11 deletions frontend/src/app/edit/edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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)
);
Expand All @@ -388,7 +385,7 @@ export class EditComponent implements AfterViewInit, OnInit {
);

if (readablePatch !== '')
this.versionControlService.saveDiff(
this.versioningApiService.saveDiff(
markdownID ? (markdownID as string) : '',
readablePatch
);
Expand Down Expand Up @@ -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(
Expand Down
135 changes: 0 additions & 135 deletions frontend/src/app/services/version.control.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,139 +245,4 @@ export class VersionControlService {
this.sortSnapshotArr(this.snapshotArr);
this.sortDiffArr(this.diffArr);
}

saveDiff(
fileID: string,
content: string
): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
this.sendSaveDiff(fileID, content).subscribe({
next: (response: HttpResponse<any>) => {
if (response.status === 200) {
resolve(true);
} else {
resolve(false);
}
},
});
});
}

sendSaveDiff(
markdownID: string,
content: string
): Observable<HttpResponse<any>> {
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<any> {
return new Promise<any>((resolve, reject) => {
this.sendRetrieveAllSnapshots(markdownID).subscribe({
next: (response: HttpResponse<any>) => {
console.log(response);
if (response.status === 200) {
resolve(response.body);
} else {
resolve(null);
}
},
});
});
}

sendRetrieveAllSnapshots(markdownID: string): Observable<HttpResponse<any>> {
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<any> {
return new Promise<any>((resolve, reject) => {
this.sendRetrieveAllHistory(markdownID).subscribe({
next: (response: HttpResponse<any>) => {
console.log('Backend data response: ', response);
if (response.status === 200) {
resolve(response.body);
} else {
resolve(null);
}
},
});
});
}

sendRetrieveAllHistory(markdownID: string): Observable<HttpResponse<any>> {
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<any>((resolve, reject) => {
this.sendLoadHistorySet(markdownID, diffHistory, snapshotID).subscribe({
next: (response: HttpResponse<any>) => {
console.log(response);
if (response.status === 200) {
resolve(response.body);
} else {
resolve(null);
}
},
});
});
}

sendLoadHistorySet(
markdownID: string,
diffHistory: string[],
snapshotID: string
): Observable<HttpResponse<any>> {
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' });
}
}

0 comments on commit 46f6b00

Please sign in to comment.