-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #252 from e-picsa/ft-enable-xls-parsing
Ft enable xls parsing
- Loading branch information
Showing
10 changed files
with
290 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.../dashboard/src/app/modules/monitoring/pages/update/update-monitoring-forms.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="page-content"> | ||
<div style="display: flex; align-items: center"> | ||
<h2 style="flex: 1">Update Form</h2> | ||
</div> | ||
@if(form){ | ||
<form class="form-content"> | ||
<h2 style="flex: 1">Upload new Form excel file</h2> | ||
<picsa-supabase-upload | ||
[fileTypes]="allowedFileTypes" | ||
[autoUpload]="false" | ||
[storageBucketName]="storageBucketName" | ||
[storageFolderPath]="storageFolderPath" | ||
(uploadComplete)="handleUploadComplete($event)" | ||
> | ||
</picsa-supabase-upload> | ||
</form> | ||
} @if(updateFeedbackMessage) { | ||
<div>{{ updateFeedbackMessage }}</div> | ||
} @if(uploading==true) { | ||
<div>Uploading form...</div> | ||
} | ||
</div> |
28 changes: 28 additions & 0 deletions
28
.../dashboard/src/app/modules/monitoring/pages/update/update-monitoring-forms.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.form-content { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1.4rem; | ||
} | ||
.submitButton { | ||
width: 7rem; | ||
margin-bottom: 1rem; | ||
} | ||
.form-data { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
} | ||
|
||
.data-container { | ||
margin-left: 2rem; | ||
max-height: 25rem; | ||
overflow-y: auto; | ||
} | ||
label { | ||
font-weight: 700; | ||
} | ||
.action-button-section { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 5px; | ||
} |
22 changes: 22 additions & 0 deletions
22
...shboard/src/app/modules/monitoring/pages/update/update-monitoring-forms.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { UpdateMonitoringFormsComponent } from './update-monitoring-forms.component'; | ||
|
||
describe('UpdateMonitoringFormsComponent', () => { | ||
let component: UpdateMonitoringFormsComponent; | ||
let fixture: ComponentFixture<UpdateMonitoringFormsComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [UpdateMonitoringFormsComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(UpdateMonitoringFormsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
103 changes: 103 additions & 0 deletions
103
...ps/dashboard/src/app/modules/monitoring/pages/update/update-monitoring-forms.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | ||
import { ActivatedRoute, RouterModule } from '@angular/router'; | ||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
import type { Database } from '@picsa/server-types'; | ||
import { | ||
IUploadResult, | ||
SupabaseStoragePickerDirective, | ||
SupabaseUploadComponent, | ||
} from '@picsa/shared/services/core/supabase'; | ||
import { SupabaseStorageService } from '@picsa/shared/services/core/supabase/services/supabase-storage.service'; | ||
import { NgxJsonViewerModule } from 'ngx-json-viewer'; | ||
|
||
import { DashboardMaterialModule } from '../../../../material.module'; | ||
import { MonitoringFormsDashboardService } from '../../monitoring.service'; | ||
|
||
export type IMonitoringFormsRow = Database['public']['Tables']['monitoring_forms']['Row']; | ||
|
||
@Component({ | ||
selector: 'dashboard-monitoring-update', | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
DashboardMaterialModule, | ||
FormsModule, | ||
ReactiveFormsModule, | ||
RouterModule, | ||
NgxJsonViewerModule, | ||
SupabaseUploadComponent, | ||
SupabaseStoragePickerDirective, | ||
], | ||
templateUrl: './update-monitoring-forms.component.html', | ||
styleUrls: ['./update-monitoring-forms.component.scss'], | ||
}) | ||
export class UpdateMonitoringFormsComponent implements OnInit { | ||
public form: IMonitoringFormsRow; | ||
public updateFeedbackMessage = ''; | ||
public uploading = false; | ||
public allowedFileTypes = ['xlsx', 'xls'].map((ext) => `.${ext}`); | ||
public storageBucketName = 'global'; | ||
public storageFolderPath = 'monitoring/forms'; | ||
constructor( | ||
private service: MonitoringFormsDashboardService, | ||
private route: ActivatedRoute, | ||
private storageService: SupabaseStorageService | ||
) {} | ||
async ngOnInit() { | ||
await this.service.ready(); | ||
this.route.params.subscribe(async (params) => { | ||
const id = params['id']; | ||
this.service | ||
.getFormById(id) | ||
.then((data) => { | ||
this.form = data; | ||
}) | ||
.catch((error) => { | ||
console.error('Error fetching Form:', error); | ||
}); | ||
}); | ||
} | ||
|
||
public async handleUploadComplete(res: IUploadResult[]) { | ||
if (res.length === 0) { | ||
return; | ||
} | ||
// As conversion is a 2-step process (xls file -> xml form -> enketo form) track progress | ||
// so that uploaded file can be removed if not successful | ||
let xformConversionSuccess = false; | ||
this.uploading = true; | ||
const [{ data, entry }] = res; | ||
|
||
const xform = await this.service.submitFormToConvertXlsToXForm(data as File); | ||
|
||
if (xform) { | ||
const blob = new Blob([xform], { type: 'text/xml' }); | ||
const xmlFile = new File([blob], 'form.xml', { type: 'text/xml' }); | ||
const formData = new FormData(); | ||
formData.append('files', xmlFile); | ||
|
||
const enketoContent = await this.service.submitFormToConvertXFormToEnketo(formData); | ||
if (enketoContent) { | ||
const { form, languageMap, model, theme } = enketoContent; | ||
// Update db entry with form_xlsx | ||
this.form = await this.service.updateFormById(this.form.id, { | ||
form_xlsx: `${this.storageBucketName}/${this.storageFolderPath}/${entry.name}`, | ||
enketo_form: form, | ||
enketo_model: model, | ||
enketo_definition: { ...(this.form.enketo_definition as any), languageMap, theme }, | ||
}); | ||
this.updateFeedbackMessage = 'Form updated successfully!'; | ||
this.uploading = false; | ||
xformConversionSuccess = true; | ||
} | ||
} | ||
// If conversion not successful delete file from storage | ||
if (!xformConversionSuccess) { | ||
const storagePath = `${this.storageFolderPath}/${entry.name}`; | ||
const { error } = await this.storageService.deleteFile(this.storageBucketName, storagePath); | ||
if (error) throw error; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 23 additions & 19 deletions
42
...apps/dashboard/src/app/modules/monitoring/pages/view/view-monitoring-forms.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
.form-content{ | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1.4rem; | ||
.form-content { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1.4rem; | ||
} | ||
.submitButton{ | ||
width: 7rem; | ||
margin-bottom: 1rem; | ||
.submitButton { | ||
width: 7rem; | ||
margin-bottom: 1rem; | ||
} | ||
.form-data{ | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
.form-data { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
} | ||
|
||
.data-container{ | ||
margin-left: 2rem; | ||
max-height: 25rem; | ||
overflow-y: auto; | ||
.data-container { | ||
margin-left: 2rem; | ||
max-height: 25rem; | ||
overflow-y: auto; | ||
} | ||
label { | ||
font-weight: 700; | ||
} | ||
.action-button-section { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 5px; | ||
} | ||
label{ | ||
font-weight: 700; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters