|
1 |
| -import { HttpResponse, HttpErrorResponse, HttpClient } from '@angular/common/http'; |
| 1 | +import { HttpResponse, HttpErrorResponse, HttpClient, HttpEvent, HttpEventType, HttpProgressEvent } from '@angular/common/http'; |
2 | 2 | import { Component, OnInit, OnDestroy, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
|
3 | 3 | import { Router } from '@angular/router';
|
4 | 4 | import { Subscription } from 'rxjs';
|
@@ -36,6 +36,7 @@ export class AddPropertyDetailsOwnerComponent implements OnInit, OnDestroy, Afte
|
36 | 36 |
|
37 | 37 | showLoadingDone: boolean;
|
38 | 38 | public host = environment.apiUrl;
|
| 39 | + fileStatus = { status: '', requestType: '', percent: 0 }; |
39 | 40 |
|
40 | 41 |
|
41 | 42 |
|
@@ -133,31 +134,66 @@ export class AddPropertyDetailsOwnerComponent implements OnInit, OnDestroy, Afte
|
133 | 134 | formData.append("propertyId", String(this.propertyId));
|
134 | 135 | }
|
135 | 136 |
|
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) => { |
143 | 140 |
|
| 141 | + /* this.reportProgress(event); */ |
| 142 | + this.pictureShowLoading = false |
| 143 | + this.pictureshowLoading = false; |
| 144 | + this.sendNotification(NotificationType.SUCCESS, `Images uploaded successfully.`); |
144 | 145 |
|
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 | + ); |
147 | 154 |
|
148 |
| - this.sendNotification(NotificationType.ERROR, errorResponse.error.message); |
149 |
| - this.pictureShowLoading = false; |
150 |
| - this.pictureshowLoading = false; |
151 |
| - } |
152 |
| - ) |
153 | 155 |
|
154 | 156 |
|
155 | 157 | }
|
156 | 158 |
|
157 | 159 |
|
158 | 160 |
|
159 | 161 |
|
| 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 | + } |
160 | 195 |
|
| 196 | +*/ |
161 | 197 |
|
162 | 198 |
|
163 | 199 | private sendNotification(notificationType: NotificationType, message: string) {
|
|
0 commit comments