From 404848c804fbf14d7eb9a4db84d5fcc3240c75d5 Mon Sep 17 00:00:00 2001 From: Rahul K R Date: Thu, 16 May 2024 17:53:08 +0530 Subject: [PATCH 1/2] bulk upload story 1173 --- src/app/core/constants/urlConstants.ts | 2 + .../organisation/organisation.service.ts | 18 +++- .../manage-list/manage-list.component.html | 14 +--- .../manage-list/manage-list.component.ts | 33 ++------ .../manage-session.component.html | 82 +++++++++++++------ .../manage-session.component.scss | 3 + .../manage-session.component.ts | 18 ++-- .../bulk-upload/bulk-upload.component.html | 13 +++ .../bulk-upload/bulk-upload.component.scss | 0 .../bulk-upload/bulk-upload.component.spec.ts | 24 ++++++ .../bulk-upload/bulk-upload.component.ts | 49 +++++++++++ src/app/shared/shared.module.ts | 3 + 12 files changed, 184 insertions(+), 75 deletions(-) create mode 100644 src/app/shared/components/bulk-upload/bulk-upload.component.html create mode 100644 src/app/shared/components/bulk-upload/bulk-upload.component.scss create mode 100644 src/app/shared/components/bulk-upload/bulk-upload.component.spec.ts create mode 100644 src/app/shared/components/bulk-upload/bulk-upload.component.ts diff --git a/src/app/core/constants/urlConstants.ts b/src/app/core/constants/urlConstants.ts index 8d60ef69..16ed3a72 100644 --- a/src/app/core/constants/urlConstants.ts +++ b/src/app/core/constants/urlConstants.ts @@ -23,6 +23,8 @@ export const urlConstants = { CREATED_SESSIONS: "/mentoring/v1/mentors/createdSessions?page=", MENTORS_DIRECTORY_LIST: "/mentoring/v1/mentors/list?page=", MENTORS_PROFILE_DETAILS: "/mentoring/v1/mentors/details/", + SESSION_DOWNLOAD_CSV: "/mentoring/v1/sessions/getSampleCSV", + SESSION_BULK_UPLOAD: "/mentoring/v1/sessions/bulkSessionCreate", // FORMS FORM_READ:'/mentoring/v1/form/read', diff --git a/src/app/core/services/organisation/organisation.service.ts b/src/app/core/services/organisation/organisation.service.ts index 2346841f..e1e976ab 100644 --- a/src/app/core/services/organisation/organisation.service.ts +++ b/src/app/core/services/organisation/organisation.service.ts @@ -79,9 +79,9 @@ export class OrganisationService { } } - async bulkUpload(path){ + async bulkUpload(path, uploadCsvUrl){ const config = { - url: urlConstants.API_URLS.ADMIN_BULK_UPLOAD, + url: uploadCsvUrl, payload: { "file_path": path, }, @@ -115,4 +115,18 @@ export class OrganisationService { }; return this.http.put(path.signedUrl, file, options); } + + async downloadManageUserCsv(downloadCsvUrl){ + let config = { + url: downloadCsvUrl, + payload: {} + } + try { + let data: any = await this.httpService.get(config); + return data.result + } + catch (error) { + } + + } } diff --git a/src/app/modules/admin/components/manage-list/manage-list.component.html b/src/app/modules/admin/components/manage-list/manage-list.component.html index a697c2bf..b8d10c95 100644 --- a/src/app/modules/admin/components/manage-list/manage-list.component.html +++ b/src/app/modules/admin/components/manage-list/manage-list.component.html @@ -52,19 +52,7 @@
- - -
- {{"DOWNLOAD_SAMPLE_CSV"|translate}} -
-
- {{"UPLOAD_CSV"|translate}} - -
-
-
+
diff --git a/src/app/modules/admin/components/manage-list/manage-list.component.ts b/src/app/modules/admin/components/manage-list/manage-list.component.ts index 4836f6fd..6c955663 100644 --- a/src/app/modules/admin/components/manage-list/manage-list.component.ts +++ b/src/app/modules/admin/components/manage-list/manage-list.component.ts @@ -28,6 +28,12 @@ export class ManageListComponent implements OnInit { }; requestList: any; formData: any; + + public manageUserUrls: any = { + downloadCsvApiUrl: urlConstants.API_URLS.ADMIN_DOWNLOAD_SAMPLE_CSV, + uploadCsvApiUrl: urlConstants.API_URLS.ADMIN_BULK_UPLOAD + } + constructor(private organisation: OrganisationService, private util: UtilService, private toast: ToastService, private form: FormService, private sessionService: SessionService, private profileService:ProfileService, private http: HttpService) { } async ngOnInit() { @@ -83,31 +89,4 @@ export class ManageListComponent implements OnInit { this.util.openModal(componenProps).then((data)=>{ }) } - async downloadCSV(){ - let config = { - url: urlConstants.API_URLS.ADMIN_DOWNLOAD_SAMPLE_CSV, - payload: {} - } - this.http.get(config).then(async (response)=>{ - await this.sessionService.openBrowser(response.result,"_blank") - }) - } - - async uploadCSV(event){ - let file= event.target.files[0]; - if(file.type != 'text/csv'){ - this.toast.showToast('PLEASE_UPLOAD_CSV_FILE', 'danger') - event.target.value=''; - }else{ - let signedUrl = await this.organisation.getSignedUrl(event.target.files[0].name) - this.organisation.upload(event.target.files[0], signedUrl).subscribe(async () => { - let data = await this.organisation.bulkUpload(signedUrl.filePath); - if(data){ - this.toast.showToast(data.message, 'success'); - event.target.value=''; - } - (error) => event.target.value=''; - }) - } - } } diff --git a/src/app/modules/admin/components/manage-session/manage-session.component.html b/src/app/modules/admin/components/manage-session/manage-session.component.html index ac2d87c6..f253784a 100644 --- a/src/app/modules/admin/components/manage-session/manage-session.component.html +++ b/src/app/modules/admin/components/manage-session/manage-session.component.html @@ -5,33 +5,61 @@ -
- - -
- {{"START_CREATE_SESSION"|translate}} +
+ + + + {{ "CREATE_SESSIONS" | translate }} + + + {{ "MANAGE_SESSION" | translate }} + + + +
+
+
+
+ + +
+ {{"START_CREATE_SESSION"|translate}} +
+ + + + + {{"CREATE_SESSION" | translate }} + + + + +
+
+
+

{{"FILTER"|translate}}

+
+
- - - - - {{'CREATE_SESSION' | translate}} - - - - - - -
-
-

{{"FILTER"|translate}}

-
- +
+
+ +
{{ download | translate}}
+
+
+
+
+ +
+
-
-
- -
{{ download | translate}}
-
-
\ No newline at end of file diff --git a/src/app/modules/admin/components/manage-session/manage-session.component.scss b/src/app/modules/admin/components/manage-session/manage-session.component.scss index 1f0d037c..0832a2d0 100644 --- a/src/app/modules/admin/components/manage-session/manage-session.component.scss +++ b/src/app/modules/admin/components/manage-session/manage-session.component.scss @@ -61,4 +61,7 @@ color: #6da6f2; text-decoration: underline; cursor: pointer; +} +.normal-case { + text-transform: none; } \ No newline at end of file diff --git a/src/app/modules/admin/components/manage-session/manage-session.component.ts b/src/app/modules/admin/components/manage-session/manage-session.component.ts index f572a5d3..59f7531c 100644 --- a/src/app/modules/admin/components/manage-session/manage-session.component.ts +++ b/src/app/modules/admin/components/manage-session/manage-session.component.ts @@ -1,15 +1,12 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; -import { LineElement } from 'chart.js/dist'; -import { urlConstants } from 'src/app/core/constants/urlConstants'; import { AdminWorkapceService } from 'src/app/core/services/admin-workspace/admin-workapce.service'; import { CommonRoutes } from 'src/global.routes'; import { ModalController } from '@ionic/angular'; import { FilterPopupComponent } from 'src/app/shared/components/filter-popup/filter-popup.component'; -import { UtilService } from 'src/app/core/services'; -import { SessionService } from 'src/app/core/services/session/session.service'; import { MenteeListPopupComponent } from 'src/app/shared/components/mentee-list-popup/mentee-list-popup.component'; import * as moment from 'moment'; +import { urlConstants } from 'src/app/core/constants/urlConstants'; @Component({ selector: 'app-manage-session', @@ -24,7 +21,13 @@ export class ManageSessionComponent implements OnInit { // label: 'MANAGE_SESSION' }; receivedEventData: any; - constructor(private adminWorkapceService: AdminWorkapceService, private router: Router, private modalCtrl: ModalController,private utilService:UtilService, private sessionService:SessionService) { } + + public manageSessionUrls: any = { + downloadCsvApiUrl: urlConstants.API_URLS.SESSION_DOWNLOAD_CSV, + uploadCsvApiUrl: urlConstants.API_URLS.SESSION_BULK_UPLOAD + } + + constructor(private adminWorkapceService: AdminWorkapceService, private router: Router, private modalCtrl: ModalController) { } headingText = "SESSION_LIST" download = "DOWNLOAD"; page = 1; @@ -85,6 +88,7 @@ export class ManageSessionComponent implements OnInit { tableData: any; dummyTableData: any = false; noDataMessage: any; + segmentType = 'manage-session'; filteredDatas = [] actionButtons = { 'UPCOMING': [{ icon: 'eye', cssColor: 'white-color' , action:'VIEW'}, { icon: 'create', cssColor: 'white-color' ,action:'EDIT'}, { icon: 'trash', cssColor: 'white-color',action:'DELETE' }], @@ -208,5 +212,7 @@ export class ManageSessionComponent implements OnInit { createSession(){ this.router.navigate([`${CommonRoutes.CREATE_SESSION}`]); } - + segmentChanged(event){ + this.segmentType = event.target.value; + } } diff --git a/src/app/shared/components/bulk-upload/bulk-upload.component.html b/src/app/shared/components/bulk-upload/bulk-upload.component.html new file mode 100644 index 00000000..3e597e3b --- /dev/null +++ b/src/app/shared/components/bulk-upload/bulk-upload.component.html @@ -0,0 +1,13 @@ + + +
+ {{"DOWNLOAD_SAMPLE_CSV"|translate}} +
+
+ {{"UPLOAD_CSV"|translate}} + +
+
+
\ No newline at end of file diff --git a/src/app/shared/components/bulk-upload/bulk-upload.component.scss b/src/app/shared/components/bulk-upload/bulk-upload.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/shared/components/bulk-upload/bulk-upload.component.spec.ts b/src/app/shared/components/bulk-upload/bulk-upload.component.spec.ts new file mode 100644 index 00000000..68915e66 --- /dev/null +++ b/src/app/shared/components/bulk-upload/bulk-upload.component.spec.ts @@ -0,0 +1,24 @@ +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { IonicModule } from '@ionic/angular'; + +import { BulkUploadComponent } from './bulk-upload.component'; + +describe('BulkUploadComponent', () => { + let component: BulkUploadComponent; + let fixture: ComponentFixture; + + beforeEach(waitForAsync(() => { + TestBed.configureTestingModule({ + declarations: [ BulkUploadComponent ], + imports: [IonicModule.forRoot()] + }).compileComponents(); + + fixture = TestBed.createComponent(BulkUploadComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/components/bulk-upload/bulk-upload.component.ts b/src/app/shared/components/bulk-upload/bulk-upload.component.ts new file mode 100644 index 00000000..adb31f0c --- /dev/null +++ b/src/app/shared/components/bulk-upload/bulk-upload.component.ts @@ -0,0 +1,49 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { ToastService } from 'src/app/core/services'; +import { OrganisationService } from 'src/app/core/services/organisation/organisation.service'; +import { SessionService } from 'src/app/core/services/session/session.service'; + +@Component({ + selector: 'app-bulk-upload', + templateUrl: './bulk-upload.component.html', + styleUrls: ['./bulk-upload.component.scss'], +}) +export class BulkUploadComponent implements OnInit { + + @Input() data: any; + uploadData: any; + + constructor( + private toast: ToastService, + private organisation: OrganisationService, + private sessionService:SessionService + ) { } + + ngOnInit() {} + +async downloadCSV(){ + if(this.data){ + let response = await this.organisation.downloadManageUserCsv(this.data?.downloadCsvApiUrl); + if(response){this.sessionService.openBrowser(response,"_blank")} + } + } + +async uploadCSV(event){ + let file= event.target.files[0]; + if(file.type != 'text/csv'){ + this.toast.showToast('PLEASE_UPLOAD_CSV_FILE', 'danger') + event.target.value=''; + }else{ + let signedUrl = await this.organisation.getSignedUrl(event.target.files[0].name); + this.organisation.upload(event.target.files[0], signedUrl).subscribe(async () => { + let data = await this.organisation.bulkUpload(signedUrl.filePath,this.data?.uploadCsvApiUrl); + if(data){ + this.toast.showToast(data.message, 'success'); + event.target.value=''; + } + (error) => event.target.value=''; + }) + } + } + +} diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index fdcc3c36..0bf8668c 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -40,6 +40,7 @@ import { HasPermissionDirective } from './directive/permission.directive'; import { FilterTreeComponent } from './components/filter-tree/filter-tree.component'; import { FilterPopupComponent } from './components/filter-popup/filter-popup.component'; import { MenteeListPopupComponent } from './components/mentee-list-popup/mentee-list-popup.component'; +import { BulkUploadComponent } from './components/bulk-upload/bulk-upload.component'; import { UserListModalComponent } from './components/user-list-modal/user-list-modal.component'; import { snakeCaseToUpperCasePipe } from '../core/pipes/snake-case-to-normal-case.pipe'; @@ -73,6 +74,7 @@ import { snakeCaseToUpperCasePipe } from '../core/pipes/snake-case-to-normal-cas FilterTreeComponent, FilterPopupComponent, MenteeListPopupComponent, + BulkUploadComponent, UserListModalComponent, snakeCaseToUpperCasePipe ], @@ -120,6 +122,7 @@ import { snakeCaseToUpperCasePipe } from '../core/pipes/snake-case-to-normal-cas FilterTreeComponent, FilterPopupComponent, MenteeListPopupComponent, + BulkUploadComponent, UserListModalComponent, snakeCaseToUpperCasePipe ], From 38571a4381040457bce2c8ff0db1ac708f00b423 Mon Sep 17 00:00:00 2001 From: Rahul K R Date: Thu, 16 May 2024 18:25:43 +0530 Subject: [PATCH 2/2] comment resolved --- src/app/core/services/organisation/organisation.service.ts | 2 +- src/app/shared/components/bulk-upload/bulk-upload.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/core/services/organisation/organisation.service.ts b/src/app/core/services/organisation/organisation.service.ts index e1e976ab..0badd3d1 100644 --- a/src/app/core/services/organisation/organisation.service.ts +++ b/src/app/core/services/organisation/organisation.service.ts @@ -116,7 +116,7 @@ export class OrganisationService { return this.http.put(path.signedUrl, file, options); } - async downloadManageUserCsv(downloadCsvUrl){ + async downloadCsv(downloadCsvUrl){ let config = { url: downloadCsvUrl, payload: {} diff --git a/src/app/shared/components/bulk-upload/bulk-upload.component.ts b/src/app/shared/components/bulk-upload/bulk-upload.component.ts index adb31f0c..42eb062f 100644 --- a/src/app/shared/components/bulk-upload/bulk-upload.component.ts +++ b/src/app/shared/components/bulk-upload/bulk-upload.component.ts @@ -23,7 +23,7 @@ export class BulkUploadComponent implements OnInit { async downloadCSV(){ if(this.data){ - let response = await this.organisation.downloadManageUserCsv(this.data?.downloadCsvApiUrl); + let response = await this.organisation.downloadCsv(this.data?.downloadCsvApiUrl); if(response){this.sessionService.openBrowser(response,"_blank")} } }