Skip to content

Commit 4a637aa

Browse files
improves importing of data
1 parent 094cb5b commit 4a637aa

File tree

5 files changed

+35
-58
lines changed

5 files changed

+35
-58
lines changed

back-end/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "api",
3-
"version": "preview-2.0.2",
3+
"version": "preview-2.0.3",
44
"description": "Climsoft API",
55
"author": "Climsoft Foundation",
66
"private": true,

front-end/pwa/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "climsoftweb",
3-
"version": "preview-2.0.2",
3+
"version": "preview-2.0.3",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",

front-end/pwa/src/app/core/dashboard/dashboard.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ <h2>
3333
</div>
3434

3535
<footer class="text-muted text-center mt-5 small">
36-
Climsoft Web (preview-2.0.2-alpha) is a free and open-source modern climate and hydrology data management platform.
36+
Climsoft Web (preview-2.0.3) is a free and open-source modern climate and hydrology data management platform.
3737
</footer>
3838
</div>

front-end/pwa/src/app/data-ingestion/import-entry/import-entry.component.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<div *ngIf="viewSource" class="card border-0">
22
<div class="card-header d-flex px-1 py-0 flex-column">
33
<div *ngIf="showStationSelection" class="mt-1">
4-
<app-station-selector-single [label]="'Station'" [includeOnlyIds]="onlyIncludeStationIds" [(selectedId)]="selectedStationId" />
4+
<app-station-selector-single [label]="'Station'" [includeOnlyIds]="onlyIncludeStationIds"
5+
[(selectedId)]="selectedStationId" />
56
</div>
67
<div class="mt-1 mb-1 d-flex justify-content-between align-items-center">
78
<div>
@@ -22,12 +23,9 @@
2223
<div class="mt-4" [class.text-danger]="uploadError">
2324
{{ uploadMessage }}
2425
</div>
25-
2626
<div class="mt-4 px-4 w-100" *ngIf="showUploadProgress">
2727
<div class="progress">
28-
<div class="progress-bar progress-bar-striped" style="width: 100%" [style.width.%]="uploadProgress">
29-
{{ uploadProgress === 100? 'Processing...': uploadProgress + '%'}}
30-
</div>
28+
<div class="progress-bar progress-bar-striped progress-bar-animated" style="width: 100%"> </div>
3129
</div>
3230
</div>
3331

front-end/pwa/src/app/data-ingestion/import-entry/import-entry.component.ts

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class ImportEntryComponent implements OnInit, OnDestroy {
2121
protected uploadMessage: string = "Upload File";
2222
protected uploadError: boolean = false;
2323
protected showUploadProgress: boolean = false;
24-
protected uploadProgress: number = 0;
2524

2625
protected showStationSelection: boolean = false;
2726
protected selectedStationId!: string | null;
@@ -53,7 +52,6 @@ export class ImportEntryComponent implements OnInit, OnDestroy {
5352
} else {
5453
this.onlyIncludeStationIds = [];
5554
}
56-
console.log('station permission: ', user.permissions.entryPermissions.stationIds)
5755
} else {
5856
throw new Error('Data entry not allowed');
5957
}
@@ -86,7 +84,6 @@ export class ImportEntryComponent implements OnInit, OnDestroy {
8684
this.destroy$.complete();
8785
}
8886

89-
9087
protected onFileSelected(fileInputEvent: any): void {
9188
if (fileInputEvent.target.files.length === 0) {
9289
return;
@@ -100,68 +97,50 @@ export class ImportEntryComponent implements OnInit, OnDestroy {
10097

10198
this.disableUpload = true;
10299
this.showUploadProgress = true;
103-
this.uploadProgress = 0;
104100
this.uploadError = false;
105-
this.uploadMessage = "Uploading file..."
101+
this.uploadMessage = "Uploading and processing file..."
106102

107103
// Get the file and append it as the form data to be sent
108104
const selectedFile = fileInputEvent.target.files[0] as File;
109105
const formData = new FormData();
110106
formData.append('file', selectedFile);
111107

112-
const params = new HttpParams();
113108
let url = `${this.appConfigService.apiBaseUrl}/observations/upload/${this.viewSource.id}`;
114109
// If station id is provided, append it as a route parameter
115110
if (this.showStationSelection && this.selectedStationId) {
116111
url = url + "/" + this.selectedStationId;
117112
}
118113

119-
this.http.post(
120-
url,
121-
formData,
122-
{
123-
reportProgress: true,
124-
observe: 'events',
125-
params: params
126-
}).pipe(
127-
catchError(error => {
128-
console.log("Error returned: ", error);
129-
return throwError(() => new Error('Something bad happened. Please try again later.'));
130-
})
131-
).subscribe(event => {
132-
if (event.type === HttpEventType.UploadProgress) {
133-
if (event.total) {
134-
this.uploadProgress = Math.round(100 * (event.loaded / event.total));
135-
this.uploadMessage = this.uploadProgress < 100 ? "Uploading file..." : "Processing file...";
136-
}
137-
} else if (event.type === HttpEventType.Response) {
138-
this.disableUpload = false;
139-
// Clear the file input
140-
fileInputEvent.target.value = null;
141-
142-
// Reset upload progress
143-
this.showUploadProgress = false;
144-
this.uploadProgress = 0;
145-
this.uploadError = false;
146-
147-
if (!event.body) {
148-
this.uploadMessage = "Something went wrong!";
149-
this.uploadError = true;
150-
return;
151-
}
152-
153-
let response: string = (event.body as any).message;
154-
if (response === "success") {
155-
this.uploadMessage = "Imported data successfully saved!";
156-
} else {
157-
this.uploadMessage = response;
158-
this.uploadError = true;
159-
}
114+
this.http.post(url, formData).pipe(
115+
take(1),
116+
catchError(error => {
117+
this.disableUpload = false;
118+
this.showUploadProgress = false;
119+
this.uploadMessage = 'Something bad happened. Please try again later.';
120+
this.uploadError = true;
121+
console.log("Error returned: ", error);
122+
return error;
123+
}),
124+
).subscribe(res => {
125+
this.disableUpload = false;
126+
this.showUploadProgress = false;
127+
// Clear the file input
128+
fileInputEvent.target.value = null;
129+
130+
if (res) {
131+
let message: string = (res as any).message;
132+
if (message === "success") {
133+
this.uploadMessage = "File successfully uploaded and processed!";
134+
} else {
135+
this.uploadMessage = message;
136+
this.uploadError = true;
160137
}
161-
});
138+
} else {
139+
this.uploadMessage = "Something went wrong!";
140+
this.uploadError = true;
141+
}
162142

143+
});
163144
}
164145

165-
166-
167146
}

0 commit comments

Comments
 (0)