Skip to content

Commit

Permalink
Merge pull request #495 from rahulramakrishnan3/release-3.0.0
Browse files Browse the repository at this point in the history
bulk upload story 1173
  • Loading branch information
Cafnanc authored May 16, 2024
2 parents ab7593d + 38571a4 commit c4fbc4f
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 75 deletions.
2 changes: 2 additions & 0 deletions src/app/core/constants/urlConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 16 additions & 2 deletions src/app/core/services/organisation/organisation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -115,4 +115,18 @@ export class OrganisationService {
};
return this.http.put(path.signedUrl, file, options);
}

async downloadCsv(downloadCsvUrl){
let config = {
url: downloadCsvUrl,
payload: {}
}
try {
let data: any = await this.httpService.get(config);
return data.result
}
catch (error) {
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,7 @@
</ion-card>

<div *ngSwitchCase="'bulk-upload'" class="d-flex flex-justify-center flex-align-items-center">
<ion-grid>
<ion-row class="d-flex flex-justify-center">
<div class="ion-margin ion-padding">
<ion-button class="btn-width-200"
(click)="downloadCSV()">{{"DOWNLOAD_SAMPLE_CSV"|translate}}</ion-button>
</div>
<div class="ion-margin ion-padding">
<ion-button class="btn-width-200"
(click)="upload.click()">{{"UPLOAD_CSV"|translate}}</ion-button>
<input type="file" accept=".csv" (change)="uploadCSV($event)" hidden #upload />
</div>
</ion-row>
</ion-grid>
<app-bulk-upload [data]="manageUserUrls"></app-bulk-upload>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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='';
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,61 @@
</div>
</app-page-header>
<ion-content>
<div>
<ion-card class="session-sqr-card">
<ion-card-content class="card-content">
<div class="segment-button d-flex flex-justify-center flex-align-items-flex-end">
{{"START_CREATE_SESSION"|translate}}
<div class="d-flex flex-justify-center">
<ion-header>
<ion-segment (ionChange)="segmentChanged($event)" [value]="segmentType">
<ion-segment-button value="manage-session" class="normal-case">
<ion-label>{{ "CREATE_SESSIONS" | translate }}</ion-label>
</ion-segment-button>
<ion-segment-button value="bulk-upload" class="normal-case">
<ion-label>{{ "MANAGE_SESSION" | translate }}</ion-label>
</ion-segment-button>
</ion-segment>
</ion-header>
</div>
<div [ngSwitch]="segmentType">
<div>
<div *ngSwitchCase="'manage-session'">
<ion-card class="session-sqr-card">
<ion-card-content class="card-content">
<div class="segment-button d-flex flex-justify-center flex-align-items-flex-end">
{{"START_CREATE_SESSION"|translate}}
</div>
<ion-grid>
<ion-row class="d-flex flex-justify-center">
<ion-col padding size-xs="12" size-sm="12" size-md="8" size-lg="6" align-self-stretch>
<ion-button shape="round" strong="true" class="card-button" (click)="createSession()">
{{"CREATE_SESSION" | translate }} <ion-icon class="create-icon"name="add-circle-outline"></ion-icon>
</ion-button>
</ion-col>
</ion-row>
</ion-grid>
</ion-card-content>
</ion-card>
<div class="filter">
<p>{{"FILTER"|translate}}</p>
<div class="circle-container" (click)="onClickFilter()">
<ion-icon class="ion-funnel-icon" name="funnel"></ion-icon>
</div>
<ion-grid>
<ion-row class="d-flex flex-justify-center">
<ion-col padding size-xs="12" size-sm="12" size-md="8" size-lg="6" align-self-stretch>
<ion-button shape="round" strong="true" class="card-button" (click)="createSession()">
{{'CREATE_SESSION' | translate}} <ion-icon class="create-icon" name="add-circle-outline"></ion-icon>
</ion-button>
</ion-col>
</ion-row>
</ion-grid>
</ion-card-content>
</ion-card>
</div>
<div class="filter">
<p>{{"FILTER"|translate}}</p>
<div class="circle-container" (click)="onClickFilter()">
<ion-icon class="ion-funnel-icon" name="funnel"></ion-icon>
</div>
<div *ngIf="tableData">
<app-generic-table [headingText]="headingText"
[columnData]="columnData"
[noDataMessage]="noDataMessage"
[tableData]="tableData"
[totalCount]="totalCount"
(onClickEvent)="onCLickEvent($event)"
(paginatorChanged)="onPaginatorChange($event)"
(onSorting)="onSorting($event)"
[setPaginatorToFirstpage]="setPaginatorToFirstpage"
[showPaginator]="true">
<div class="download" (click)="onClickDownload()">{{ download | translate}}</div>
</app-generic-table>
</div>
</div>
<div *ngSwitchCase="'bulk-upload'" class="d-flex flex-justify-center flex-align-items-center">
<app-bulk-upload [data]="manageSessionUrls"></app-bulk-upload>
</div>
</div>
</div>
</div>
<div *ngIf="tableData">
<app-generic-table [headingText]="headingText" [columnData]="columnData" [noDataMessage]="noDataMessage" [tableData]="tableData" [totalCount]="totalCount" (onClickEvent)='onCLickEvent($event)' (paginatorChanged)="onPaginatorChange($event)" (onSorting)="onSorting($event)" [setPaginatorToFirstpage]="setPaginatorToFirstpage" [showPaginator]="true">
<div class="download" (click)="onClickDownload()">{{ download | translate}}</div>
</app-generic-table>
</div>
</ion-content>
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@
color: #6da6f2;
text-decoration: underline;
cursor: pointer;
}
.normal-case {
text-transform: none;
}
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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;
Expand Down Expand Up @@ -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' }],
Expand Down Expand Up @@ -208,5 +212,7 @@ export class ManageSessionComponent implements OnInit {
createSession(){
this.router.navigate([`${CommonRoutes.CREATE_SESSION}`]);
}

segmentChanged(event){
this.segmentType = event.target.value;
}
}
13 changes: 13 additions & 0 deletions src/app/shared/components/bulk-upload/bulk-upload.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ion-grid>
<ion-row class="d-flex flex-justify-center">
<div class="ion-margin ion-padding">
<ion-button class="btn-width-200"
(click)="downloadCSV()">{{"DOWNLOAD_SAMPLE_CSV"|translate}}</ion-button>
</div>
<div class="ion-margin ion-padding">
<ion-button class="btn-width-200"
(click)="upload.click()">{{"UPLOAD_CSV"|translate}}</ion-button>
<input type="file" accept=".csv" (change)="uploadCSV($event)" hidden #upload />
</div>
</ion-row>
</ion-grid>
Empty file.
Original file line number Diff line number Diff line change
@@ -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<BulkUploadComponent>;

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();
});
});
49 changes: 49 additions & 0 deletions src/app/shared/components/bulk-upload/bulk-upload.component.ts
Original file line number Diff line number Diff line change
@@ -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.downloadCsv(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='';
})
}
}

}
3 changes: 3 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -73,6 +74,7 @@ import { snakeCaseToUpperCasePipe } from '../core/pipes/snake-case-to-normal-cas
FilterTreeComponent,
FilterPopupComponent,
MenteeListPopupComponent,
BulkUploadComponent,
UserListModalComponent,
snakeCaseToUpperCasePipe
],
Expand Down Expand Up @@ -120,6 +122,7 @@ import { snakeCaseToUpperCasePipe } from '../core/pipes/snake-case-to-normal-cas
FilterTreeComponent,
FilterPopupComponent,
MenteeListPopupComponent,
BulkUploadComponent,
UserListModalComponent,
snakeCaseToUpperCasePipe
],
Expand Down

0 comments on commit c4fbc4f

Please sign in to comment.