From 357abffa0084af2df52f0d047d3db2b95056f695 Mon Sep 17 00:00:00 2001 From: GAURAV SETTY Date: Wed, 19 Apr 2023 13:39:14 -0400 Subject: [PATCH 1/3] rectified errors --- package-lock.json | 40 ++++----- package.json | 4 +- src/app/app.component.ts | 2 + src/app/components/item/item.component.ts | 101 +++++++++------------- src/app/services/admins.service.ts | 2 +- src/app/services/comments.service.ts | 2 +- src/app/services/email.service.ts | 2 +- src/app/services/encyclopedia.service.ts | 15 ++-- src/app/services/file-upload.service.ts | 3 +- src/app/services/statistics.service.ts | 2 +- src/environments/environment.ts | 2 +- 11 files changed, 74 insertions(+), 101 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1255f31..55da834 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@angular/material": "^13.1.3", "@angular/platform-browser": "^14.2.8", "@angular/platform-browser-dynamic": "^14.2.8", - "@angular/router": "^14.2.8", + "@angular/router": "^14.2.12", "@ckeditor/ckeditor5-angular": "^3.0.0", "@ckeditor/ckeditor5-build-classic": "^33.0.0", "@ckeditor/ckeditor5-upload": "^33.0.0", @@ -672,9 +672,9 @@ } }, "node_modules/@angular/router": { - "version": "14.2.8", - "resolved": "https://registry.npmjs.org/@angular/router/-/router-14.2.8.tgz", - "integrity": "sha512-rbKLsa4/scPP8AxaDRQfkLqfg8CbZ163dPqHMixou90uK/dx00LjCyUeS38/otdAYNZhrD0i5nu+k65qwhLX8w==", + "version": "14.2.12", + "resolved": "https://registry.npmjs.org/@angular/router/-/router-14.2.12.tgz", + "integrity": "sha512-r5tVus5RJDNc4U2v0jMtjPiAS1xDsVsJ70lS313DgZmBDHIVZP1cWIehdxwgNlGwQQtAA36eG7toBwqUU3gb/A==", "dependencies": { "tslib": "^2.3.0" }, @@ -682,9 +682,9 @@ "node": "^14.15.0 || >=16.10.0" }, "peerDependencies": { - "@angular/common": "14.2.8", - "@angular/core": "14.2.8", - "@angular/platform-browser": "14.2.8", + "@angular/common": "14.2.12", + "@angular/core": "14.2.12", + "@angular/platform-browser": "14.2.12", "rxjs": "^6.5.3 || ^7.4.0" } }, @@ -3428,9 +3428,9 @@ } }, "node_modules/@popperjs/core": { - "version": "2.11.2", - "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.2.tgz", - "integrity": "sha512-92FRmppjjqz29VMJ2dn+xdyXZBrMlE42AV6Kq6BwjWV7CNUW1hs2FtxSNLQE+gJhaZ6AAmYuO9y8dshhcBl7vA==", + "version": "2.11.6", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", + "integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==", "peer": true, "funding": { "type": "opencollective", @@ -6121,7 +6121,7 @@ "node_modules/desandro-matches-selector": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/desandro-matches-selector/-/desandro-matches-selector-2.0.2.tgz", - "integrity": "sha1-cXvu1NwT59jzdi9wem1YpndCGOE=", + "integrity": "sha512-+1q0nXhdzg1IpIJdMKalUwvvskeKnYyEe3shPRwedNcWtnhEKT3ZxvFjzywHDeGcKViIxTCAoOYQWP1qD7VNyg==", "peer": true }, "node_modules/destroy": { @@ -10049,7 +10049,7 @@ "node_modules/outlayer": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/outlayer/-/outlayer-2.1.1.tgz", - "integrity": "sha1-KYY7beEOpdrf/8rfoNcokHOH6aI=", + "integrity": "sha512-+GplXsCQ3VrbGujAeHEzP9SXsBmJxzn/YdDSQZL0xqBmAWBmortu2Y9Gwdp9J0bgDQ8/YNIPMoBM13nTwZfAhw==", "peer": true, "dependencies": { "ev-emitter": "^1.0.0", @@ -13863,9 +13863,9 @@ } }, "@angular/router": { - "version": "14.2.8", - "resolved": "https://registry.npmjs.org/@angular/router/-/router-14.2.8.tgz", - "integrity": "sha512-rbKLsa4/scPP8AxaDRQfkLqfg8CbZ163dPqHMixou90uK/dx00LjCyUeS38/otdAYNZhrD0i5nu+k65qwhLX8w==", + "version": "14.2.12", + "resolved": "https://registry.npmjs.org/@angular/router/-/router-14.2.12.tgz", + "integrity": "sha512-r5tVus5RJDNc4U2v0jMtjPiAS1xDsVsJ70lS313DgZmBDHIVZP1cWIehdxwgNlGwQQtAA36eG7toBwqUU3gb/A==", "requires": { "tslib": "^2.3.0" } @@ -15750,9 +15750,9 @@ } }, "@popperjs/core": { - "version": "2.11.2", - "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.2.tgz", - "integrity": "sha512-92FRmppjjqz29VMJ2dn+xdyXZBrMlE42AV6Kq6BwjWV7CNUW1hs2FtxSNLQE+gJhaZ6AAmYuO9y8dshhcBl7vA==", + "version": "2.11.6", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", + "integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==", "peer": true }, "@schematics/angular": { @@ -17995,7 +17995,7 @@ "desandro-matches-selector": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/desandro-matches-selector/-/desandro-matches-selector-2.0.2.tgz", - "integrity": "sha1-cXvu1NwT59jzdi9wem1YpndCGOE=", + "integrity": "sha512-+1q0nXhdzg1IpIJdMKalUwvvskeKnYyEe3shPRwedNcWtnhEKT3ZxvFjzywHDeGcKViIxTCAoOYQWP1qD7VNyg==", "peer": true }, "destroy": { @@ -20873,7 +20873,7 @@ "outlayer": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/outlayer/-/outlayer-2.1.1.tgz", - "integrity": "sha1-KYY7beEOpdrf/8rfoNcokHOH6aI=", + "integrity": "sha512-+GplXsCQ3VrbGujAeHEzP9SXsBmJxzn/YdDSQZL0xqBmAWBmortu2Y9Gwdp9J0bgDQ8/YNIPMoBM13nTwZfAhw==", "peer": true, "requires": { "ev-emitter": "^1.0.0", diff --git a/package.json b/package.json index fb231c7..90b3d74 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@angular/material": "^13.1.3", "@angular/platform-browser": "^14.2.8", "@angular/platform-browser-dynamic": "^14.2.8", - "@angular/router": "^14.2.8", + "@angular/router": "^14.2.12", "@ckeditor/ckeditor5-angular": "^3.0.0", "@ckeditor/ckeditor5-build-classic": "^33.0.0", "@ckeditor/ckeditor5-upload": "^33.0.0", @@ -57,4 +57,4 @@ "karma-jasmine-html-reporter": "~1.7.0", "typescript": "~4.8.4" } -} \ No newline at end of file +} diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 6a3c2db..5f0c942 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -62,6 +62,7 @@ export class AppComponent { this._snackBar.open('Welcome ' + user.firstName + ' ' + user.lastName + '!', 'Dismiss', { duration: 3000, }); + localStorage.setItem('user',user.name); } else { this.isLoggedInUserAdmin = false; @@ -85,5 +86,6 @@ export class AppComponent { signOut(): void { this.authService.signOut(true); + localStorage.removeItem('user') } } diff --git a/src/app/components/item/item.component.ts b/src/app/components/item/item.component.ts index ee86968..9b2eda2 100644 --- a/src/app/components/item/item.component.ts +++ b/src/app/components/item/item.component.ts @@ -200,18 +200,18 @@ export class ItemComponent implements OnInit { if (result !== null && result !== undefined) { this.encyclopediaService .updateEntry(this.encyclopediaItem.id, { title: result } as any) - .subscribe( - (data) => { + .subscribe({ + next: (data) => { this.encyclopediaItem.title = data.title; this._snackBar.open('Updated title!', 'Dismiss', { duration: 3000, }); }, - (error: any) => + error: (error: any) => this._snackBar.open('Error updating title!', 'Dismiss', { duration: 3000, }) - ); + }); } }); } @@ -299,49 +299,33 @@ export class ItemComponent implements OnInit { } openDeletePromptDialog() { - this.encyclopediaService.login().subscribe( - (name) => { - if (!this.dataService.getFlag()) { - this._snackBar.open('Welcome ' + name + '!', 'Dismiss', { - duration: 3000, - }); - this.dataService.setFlag(true); - } - const dialogRef = this.dialog.open(DeletePromptDialogComponent, {}); - - dialogRef.afterClosed().subscribe((result: boolean) => { - if (result) { - this.encyclopediaService - .deleteEntry(this.encyclopediaItem.id) - .subscribe( - () => { - this.location.back(); - this._snackBar.open( - 'Deleted page from encyclopedia!', - 'Dismiss', - { - duration: 3000, - } - ); - }, - (error: any) => - this._snackBar.open( - 'Error deleting page from encyclopedia!', - 'Dismiss', - { - duration: 3000, - } - ) + if (!this.dataService.getFlag()) { + let name = localStorage.getItem('user'); + this._snackBar.open('Welcome ' + name + '!', 'Dismiss', { + duration: 3000, + }); + this.dataService.setFlag(true); + } + const dialogRef = this.dialog.open(DeletePromptDialogComponent, {}); + + dialogRef.afterClosed().subscribe((result: boolean) => { + if (result) { + this.encyclopediaService + .deleteEntry(this.encyclopediaItem.id) + .subscribe( + () => { + this.location.back(); + this._snackBar.open( + 'Deleted page from encyclopedia!', + 'Dismiss', + { + duration: 3000, + } ); - } - }); - }, - (_error) => { - this._snackBar.open('Unable to login!', 'Dismiss', { - duration: 3000, - }); + } + ); } - ); + }); } onDownloadClick(file: Files) { @@ -391,23 +375,16 @@ export class ItemComponent implements OnInit { } toggleEditMode() { - if (this.showEditButtons == false) - this.encyclopediaService.login().subscribe( - (name) => { - if (!this.dataService.getFlag()) { - this._snackBar.open('Welcome ' + name + '!', 'Dismiss', { - duration: 3000, - }); - this.dataService.setFlag(true); - } - this.showEditButtons = true; - }, - (_error) => { - this._snackBar.open('Unable to login!', 'Dismiss', { - duration: 3000, - }); - } - ); + if (this.showEditButtons == false) { + let name = localStorage.getItem('user'); + if (!this.dataService.getFlag()) { + this._snackBar.open('Welcome ' + name + '!', 'Dismiss', { + duration: 3000, + }); + this.dataService.setFlag(true); + } + this.showEditButtons = true; + } else this.showEditButtons = false; } diff --git a/src/app/services/admins.service.ts b/src/app/services/admins.service.ts index 50ff954..397573d 100644 --- a/src/app/services/admins.service.ts +++ b/src/app/services/admins.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, } from '@angular/common/http'; -import { environment } from 'src/environments/environment'; +import { environment } from 'src/environments/environment.prod'; import { Admins } from '../models/admins.model'; @Injectable() diff --git a/src/app/services/comments.service.ts b/src/app/services/comments.service.ts index 2548a53..e899dcb 100644 --- a/src/app/services/comments.service.ts +++ b/src/app/services/comments.service.ts @@ -6,7 +6,7 @@ import { HttpErrorResponse, HttpResponse, } from '@angular/common/http'; -import { environment } from 'src/environments/environment'; +import { environment } from 'src/environments/environment.prod'; import { Comments } from '../models/comments.model'; import { CommentsExternalCollection } from '../models/comments-external-collection.model'; diff --git a/src/app/services/email.service.ts b/src/app/services/email.service.ts index c0b410f..969fde7 100644 --- a/src/app/services/email.service.ts +++ b/src/app/services/email.service.ts @@ -6,7 +6,7 @@ import { HttpErrorResponse, HttpResponse, } from '@angular/common/http'; -import { environment } from 'src/environments/environment'; +import { environment } from 'src/environments/environment.prod'; @Injectable() export class EmailService { diff --git a/src/app/services/encyclopedia.service.ts b/src/app/services/encyclopedia.service.ts index a071671..8c87f00 100644 --- a/src/app/services/encyclopedia.service.ts +++ b/src/app/services/encyclopedia.service.ts @@ -6,7 +6,7 @@ import { HttpErrorResponse, HttpResponse, } from '@angular/common/http'; -import { environment } from 'src/environments/environment'; +import { environment } from 'src/environments/environment.prod'; import { MainMinimizedExternalCollection } from '../models/main-minimized-collections.model'; import { Main } from '../models/main.model'; import { MainUpdateModel } from '../models/main-update.model'; @@ -112,10 +112,10 @@ export class EncyclopediaService { const headerOptions = new HttpHeaders({ 'Content-Type': 'application/json', }); - return this.http.put
(this.rootURL + '/' + id, body, { - headers: headerOptions, - // withCredentials: true, + let abc = this.http.put
(this.rootURL + '/' + id, body,{ + headers: headerOptions }); + return abc } deleteEntry(id: string) { @@ -124,10 +124,5 @@ export class EncyclopediaService { }); } - login() { - return this.http.get(this.rootURL + '/login', { - // withCredentials: true, - responseType: 'text', - }); - } + } diff --git a/src/app/services/file-upload.service.ts b/src/app/services/file-upload.service.ts index bea8c72..ee10a94 100644 --- a/src/app/services/file-upload.service.ts +++ b/src/app/services/file-upload.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpRequest, HttpEvent } from '@angular/common/http'; import { Observable } from 'rxjs'; -import { environment } from 'src/environments/environment'; +import { environment } from 'src/environments/environment.prod'; @Injectable({ providedIn: 'root', @@ -19,7 +19,6 @@ export class FileUploadService { const formData: FormData = new FormData(); formData.append('file', file); - const req = new HttpRequest( 'POST', `${this.baseUrl}/` + id + '?description=' + description, diff --git a/src/app/services/statistics.service.ts b/src/app/services/statistics.service.ts index 8de6b8a..e6b892f 100644 --- a/src/app/services/statistics.service.ts +++ b/src/app/services/statistics.service.ts @@ -6,7 +6,7 @@ import { HttpErrorResponse, HttpResponse, } from '@angular/common/http'; -import { environment } from 'src/environments/environment'; +import { environment } from 'src/environments/environment.prod'; @Injectable() export class StatisticsService { diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 4d137de..d4b26e6 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,7 +4,7 @@ export const environment = { production: false, - serverUrl: 'https://localhost:44309' + serverUrl: 'https://localhost:5001' }; /* From 888677086c316d810b4f9ab5d07c9c49857af199 Mon Sep 17 00:00:00 2001 From: GAURAV SETTY Date: Mon, 1 May 2023 09:41:02 -0400 Subject: [PATCH 2/3] changes made in HTTP requests --- src/app/services/admins.service.ts | 2 +- src/app/services/comments.service.ts | 4 ++-- src/app/services/encyclopedia.service.ts | 4 ++-- src/app/services/file-upload.service.ts | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/services/admins.service.ts b/src/app/services/admins.service.ts index 397573d..67ebf80 100644 --- a/src/app/services/admins.service.ts +++ b/src/app/services/admins.service.ts @@ -24,7 +24,7 @@ export class AdminsService { } removeAdmin(userSid: string) { - return this.http.delete( + return this.http.get( this.rootURL + '/RemoveAdmin?userSid=' + userSid ); } diff --git a/src/app/services/comments.service.ts b/src/app/services/comments.service.ts index e899dcb..abc0667 100644 --- a/src/app/services/comments.service.ts +++ b/src/app/services/comments.service.ts @@ -43,11 +43,11 @@ export class CommentsService { } delete(id: string, userSid: string) { - return this.http.delete(this.rootURL + '/' + id + '?userSid=' + userSid); + return this.http.get(this.rootURL + '/delete/' + id + '?userSid=' + userSid); } update(id: string, comment: string, userSid: string) { - return this.http.put(this.rootURL + '/' + id + '?comment=' + comment + '&userSid=' + userSid, { + return this.http.post(this.rootURL + '/' + id + '?comment=' + comment + '&userSid=' + userSid, { }); } diff --git a/src/app/services/encyclopedia.service.ts b/src/app/services/encyclopedia.service.ts index 8c87f00..eb2725d 100644 --- a/src/app/services/encyclopedia.service.ts +++ b/src/app/services/encyclopedia.service.ts @@ -112,14 +112,14 @@ export class EncyclopediaService { const headerOptions = new HttpHeaders({ 'Content-Type': 'application/json', }); - let abc = this.http.put
(this.rootURL + '/' + id, body,{ + let abc = this.http.post
(this.rootURL + '/' + id, body,{ headers: headerOptions }); return abc } deleteEntry(id: string) { - return this.http.delete(this.rootURL + '/' + id, { + return this.http.get(this.rootURL + '/delete/' + id, { // withCredentials: true, }); } diff --git a/src/app/services/file-upload.service.ts b/src/app/services/file-upload.service.ts index ee10a94..e2f2c09 100644 --- a/src/app/services/file-upload.service.ts +++ b/src/app/services/file-upload.service.ts @@ -50,8 +50,8 @@ export class FileUploadService { } deleteFile(id: string, filename: string, fileId: string): any { - return this.http.delete( - this.baseUrl + '/' + id + '?fileName=' + filename + '&fileId=' + fileId, + return this.http.get( + this.baseUrl + '/delete/' + id + '?fileName=' + filename + '&fileId=' + fileId, { // withCredentials: true, } @@ -69,7 +69,7 @@ export class FileUploadService { } destroyViewableLink(id: string, name: string) { - return this.http.delete(this.baseUrl + '/DestroyViewableLink/' + id + '?name=' + name, + return this.http.get(this.baseUrl + '/DestroyViewableLink/' + id + '?name=' + name, { // withCredentials: true, }); From 294c5c43f8904d739e30d4f18dc27f198cedd8bc Mon Sep 17 00:00:00 2001 From: GAURAV SETTY Date: Tue, 26 Sep 2023 12:49:48 -0400 Subject: [PATCH 3/3] adjusted code to solve loading external pages and categories --- src/app/app.component.ts | 8 +++----- src/app/components/item/item.component.ts | 11 +++++++---- src/app/services/encyclopedia.service.ts | 4 +++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5f0c942..c792c04 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -53,7 +53,7 @@ export class AppComponent { this.dataService.setCurrentUser(user); this.user = user; this.loggedIn = (user != null); - + if (this.loggedIn) { this.adminsService.isAdmin(user.email).subscribe((result) => { this.isLoggedInUserAdmin = result; @@ -64,11 +64,9 @@ export class AppComponent { }); localStorage.setItem('user',user.name); } - else { - this.isLoggedInUserAdmin = false; - this._router.navigate(['']); - } }); + + } goToUrl() { diff --git a/src/app/components/item/item.component.ts b/src/app/components/item/item.component.ts index 9b2eda2..94883cd 100644 --- a/src/app/components/item/item.component.ts +++ b/src/app/components/item/item.component.ts @@ -143,6 +143,7 @@ export class ItemComponent implements OnInit { this.encyclopediaService .getRelatedPages(params.get('id')) .subscribe((result) => { + console.log(result); this.relatedPages = result; this.recommendedSectionIsLoaded = true; this.relatedPages.forEach((value) => { @@ -167,19 +168,21 @@ export class ItemComponent implements OnInit { // load external pages this.encyclopediaService .getExternalPages(item.title, this.externalPageCardIndex + 1) - .subscribe( - (result) => { + .subscribe({ + next: (result) => { + console.log(result) if (result == null || result.length == 0) this.externalSectionLoadError = true; else this.externalPages[this.externalPageCardIndex] = result[0]; this.externalSectionIsLoaded = true; }, - () => { + error: () => { + console.log('error') this.externalSectionLoadError = true; this.externalSectionIsLoaded = true; } - ); + }); this.isPageLoading = false; }, diff --git a/src/app/services/encyclopedia.service.ts b/src/app/services/encyclopedia.service.ts index eb2725d..e833785 100644 --- a/src/app/services/encyclopedia.service.ts +++ b/src/app/services/encyclopedia.service.ts @@ -92,7 +92,9 @@ export class EncyclopediaService { } getExternalPages(pageTitle: string | null, startIndex: number) { - return this.http.get(this.rootURL + '/external-page/' + pageTitle + '?startIndex=' + startIndex); + let abc = this.http.get(this.rootURL + '/external-page/' + pageTitle + '?startIndex=' + startIndex); + console.log(abc) + return abc } createEntry(main: Main) {