Skip to content
Snippets Groups Projects
Commit 4510d16c authored by Samuel Eickelberg's avatar Samuel Eickelberg
Browse files

FIXED: DCC upload by re-implementing the entire feature. I have no idea why...

FIXED: DCC upload by re-implementing the entire feature. I have no idea why the previous approach stopped working entirely.
parent 0dc9d5bc
Branches
Tags
No related merge requests found
......@@ -3,6 +3,12 @@
"development"
],
"hints": {
"no-inline-styles": "off"
"no-inline-styles": "off",
"axe/forms": [
"default",
{
"label": "off"
}
]
}
}
\ No newline at end of file
......@@ -26,5 +26,16 @@
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<input #fileUpload (change)="onFileSelected($event)" class="file-input" type="file">
<button (click)="fileUpload.click()" color="primary" mat-raised-button>{{'dcc.dccUpload' | translate}}</button>
<input
#fileUpload
(change)="onChange($event)"
class="file-input"
type="file"
[accept]="requiredFileType"
>
<button
(click)="fileUpload.click()"
color="primary"
mat-raised-button>
{{'dcc.dccUpload' | translate}}
</button>
......@@ -27,7 +27,7 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
import { Component } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { DccComponent } from '../dcc.component';
import { CalibrationCertificateDto } from 'src/app/generated/dcc/model/calibrationCertificateDto';
......@@ -39,21 +39,20 @@ import { ErrorService } from 'src/app/services/common/error/error.service';
templateUrl: './dcc-upload.component.html',
styleUrls: ['./dcc-upload.component.scss']
})
export class DccUploadComponent {
reader = new FileReader();
xml = '';
export class DccUploadComponent implements OnInit {
@Input() requiredFileType: string = "applcation/xml"
constructor(private parent: DccComponent, private dccService: DccService, private errorService: ErrorService) {
this.reader.addEventListener("loadend", () => {
this.xml = this.reader.result as string;
}, false);
}
ngOnInit(): void {
}
onFileSelected(event: any) {
async onChange(event: any) {
const file: File = event.target.files[0];
if (file && file.name.endsWith('.xml')) {
this.reader.readAsText(file);
this.dccService.xmlToJson(this.xml).subscribe({
if (file) {
const xml = await this.readFile(file);
this.dccService.xmlToJson(xml).subscribe({
next: (json: CalibrationCertificateDto) => {
this.parent.dcc = this.parent.initialiseEmptyFields(json);
},
......@@ -64,4 +63,12 @@ export class DccUploadComponent {
});
}
}
readFile(file: File): Promise<string> {
return new Promise((resolve) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.readAsText(file);
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment