Skip to content

Commit 086941a

Browse files
authored
Merge pull request #16 from Azo-hub/newFeature
update 4.5
2 parents d396baf + badfdc8 commit 086941a

File tree

3 files changed

+63
-16
lines changed

3 files changed

+63
-16
lines changed

src/app/add-property-details-owner/add-property-details-owner.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,12 @@ <h5 class="card-title">Add Property Image <small class="text-muted">Multiple Ima
401401
<input type="file" class="form-control"
402402
(change)="onFileSelected($any($event).target.files)" name="propertyImage"
403403
multiple />
404+
405+
<!-- <div *ngIf="fileStatus.status === 'progress'" class="progress" role="progressbar" aria-label="Basic example"
406+
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
407+
<div class="progress-bar progress-bar-animated bg-info" [style.width.%]="fileStatus.percent">
408+
{{fileStatus.requestType}} {{fileStatus.percent}}%</div>
409+
</div> -->
404410
</div>
405411
<div class="col-sm-5">
406412
<i class="fa fa-spinner fa-spin " *ngIf="pictureShowLoading"></i>&nbsp;&nbsp;

src/app/add-property-details-owner/add-property-details-owner.component.ts

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpResponse, HttpErrorResponse, HttpClient } from '@angular/common/http';
1+
import { HttpResponse, HttpErrorResponse, HttpClient, HttpEvent, HttpEventType, HttpProgressEvent } from '@angular/common/http';
22
import { Component, OnInit, OnDestroy, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
33
import { Router } from '@angular/router';
44
import { Subscription } from 'rxjs';
@@ -36,6 +36,7 @@ export class AddPropertyDetailsOwnerComponent implements OnInit, OnDestroy, Afte
3636

3737
showLoadingDone: boolean;
3838
public host = environment.apiUrl;
39+
fileStatus = { status: '', requestType: '', percent: 0 };
3940

4041

4142

@@ -133,31 +134,66 @@ export class AddPropertyDetailsOwnerComponent implements OnInit, OnDestroy, Afte
133134
formData.append("propertyId", String(this.propertyId));
134135
}
135136

136-
const upload$ = this.http.post(`${this.host}/uploadPropertyImages`, formData);
137-
138-
upload$.subscribe(
139-
(response: any) => {
140-
this.pictureShowLoading = false
141-
this.pictureshowLoading = false;
142-
this.sendNotification(NotificationType.SUCCESS, `Images uploaded successfully.`);
137+
this.subscriptions.push(
138+
this.propertyService.uploadPropertyImages(formData).subscribe(
139+
(response: CustomHttpResponse) => {
143140

141+
/* this.reportProgress(event); */
142+
this.pictureShowLoading = false
143+
this.pictureshowLoading = false;
144+
this.sendNotification(NotificationType.SUCCESS, `Images uploaded successfully.`);
144145

145-
},
146-
(errorResponse: HttpErrorResponse) => {
146+
},
147+
(errorResponse: HttpErrorResponse) => {
148+
this.sendNotification(NotificationType.ERROR, errorResponse.error.message);
149+
this.pictureShowLoading = false;
150+
this.pictureshowLoading = false;
151+
}
152+
)
153+
);
147154

148-
this.sendNotification(NotificationType.ERROR, errorResponse.error.message);
149-
this.pictureShowLoading = false;
150-
this.pictureshowLoading = false;
151-
}
152-
)
153155

154156

155157
}
156158

157159

158160

159161

162+
/* private reportProgress(httpEvent: HttpEvent<any | Blob>): void {
163+
switch (httpEvent.type) {
164+
case HttpEventType.UploadProgress:
165+
this.updateStatus(httpEvent.loaded, httpEvent.total!, 'Uploading...');
166+
break;
167+
168+
case HttpEventType.DownloadProgress:
169+
this.updateStatus(httpEvent.loaded, httpEvent.total!, 'Downloading...');
170+
break;
171+
172+
case HttpEventType.ResponseHeader:
173+
console.log('Header returned', httpEvent);
174+
break;
175+
176+
case HttpEventType.Response:
177+
if (httpEvent.body instanceof Array) {
178+
this.fileStatus.status = 'done';
179+
180+
}
181+
break;
182+
183+
default:
184+
console.log(httpEvent);
185+
break;
186+
}
187+
}
188+
189+
private updateStatus(loaded: number, total: number, requestType: string) {
190+
this.fileStatus.status = 'progress';
191+
this.fileStatus.requestType = requestType;
192+
this.fileStatus.percent = Math.round(100 * loaded / total);
193+
194+
}
160195
196+
*/
161197

162198

163199
private sendNotification(notificationType: NotificationType, message: string) {

src/app/service/property.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpClient, HttpResponse } from '@angular/common/http';
1+
import { HttpClient, HttpEvent, HttpProgressEvent, HttpResponse } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
33
import { Observable } from 'rxjs';
44
import { environment } from 'src/environments/environment';
@@ -68,6 +68,11 @@ export class PropertyService {
6868

6969
}
7070

71+
uploadPropertyImages(formData: FormData): Observable<CustomHttpResponse> {
72+
return this.http.post<CustomHttpResponse>(`${this.host}/uploadPropertyImages`, formData);
73+
74+
}
75+
7176
public addPropertiesToLocalCache(properties: Property[]): void {
7277
localStorage.setItem('properties', JSON.stringify(properties));
7378
}

0 commit comments

Comments
 (0)