@eurosat/http 10.0.0 → 14.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/eurosat-http.mjs +5 -0
- package/esm2020/lib/http.component.mjs +22 -0
- package/esm2020/lib/http.module.mjs +26 -0
- package/esm2020/lib/http.service.mjs +144 -0
- package/esm2020/public_api.mjs +7 -0
- package/fesm2015/{eurosat-http.js → eurosat-http.mjs} +184 -278
- package/fesm2015/eurosat-http.mjs.map +1 -0
- package/fesm2020/eurosat-http.mjs +196 -0
- package/fesm2020/eurosat-http.mjs.map +1 -0
- package/{eurosat-http.d.ts → index.d.ts} +5 -4
- package/lib/http.component.d.ts +8 -5
- package/lib/http.module.d.ts +8 -2
- package/lib/http.service.d.ts +36 -33
- package/package.json +24 -12
- package/public_api.d.ts +3 -3
- package/bundles/eurosat-http.umd.js +0 -297
- package/bundles/eurosat-http.umd.js.map +0 -1
- package/bundles/eurosat-http.umd.min.js +0 -2
- package/bundles/eurosat-http.umd.min.js.map +0 -1
- package/esm2015/eurosat-http.js +0 -10
- package/esm2015/lib/http.component.js +0 -27
- package/esm2015/lib/http.module.js +0 -24
- package/esm2015/lib/http.service.js +0 -232
- package/esm2015/public_api.js +0 -12
- package/eurosat-http.metadata.json +0 -1
- package/fesm2015/eurosat-http.js.map +0 -1
|
@@ -1,290 +1,196 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, Component, NgModule } from '@angular/core';
|
|
3
|
+
import * as i1 from '@angular/common/http';
|
|
4
|
+
import { HttpResponse, HttpParams, HttpHeaders, HttpClientModule } from '@angular/common/http';
|
|
5
|
+
import * as i2 from '@angular/material/snack-bar';
|
|
6
|
+
import { MatSnackBarConfig } from '@angular/material/snack-bar';
|
|
4
7
|
import { throwError } from 'rxjs';
|
|
5
8
|
import { catchError } from 'rxjs/operators';
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* @param {?} url
|
|
135
|
-
* @param {?=} options
|
|
136
|
-
* @return {?}
|
|
137
|
-
*/
|
|
138
|
-
get(url, options) {
|
|
139
|
-
if (!options) {
|
|
140
|
-
options = {};
|
|
141
|
-
}
|
|
142
|
-
if (!options.params) {
|
|
143
|
-
options.params = new HttpParams();
|
|
144
|
-
}
|
|
145
|
-
options.params = options.params.set('_req_s', HttpService.ANGULAR_REQUEST_CONST); // pridava se nejakej param na formy pro angular
|
|
146
|
-
return this.http.get(url, options)
|
|
147
|
-
.pipe(catchError(HttpService.handleError));
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* @param {?} url
|
|
151
|
-
* @param {?} body
|
|
152
|
-
* @param {?=} options
|
|
153
|
-
* @return {?}
|
|
154
|
-
*/
|
|
155
|
-
post(url, body, options) {
|
|
156
|
-
if (!options) {
|
|
157
|
-
options = {};
|
|
158
|
-
}
|
|
159
|
-
if (!options.params) {
|
|
160
|
-
options.params = new HttpParams();
|
|
161
|
-
}
|
|
162
|
-
options.params = options.params.set('_req_s', HttpService.ANGULAR_REQUEST_CONST);
|
|
163
|
-
return this.http.post(url, body, options)
|
|
164
|
-
.pipe(catchError(HttpService.handleError));
|
|
165
|
-
}
|
|
166
|
-
// upload file s vypnutym service workerem -> header{disable-ngsw: true}
|
|
167
|
-
// v ekj projektu fix-ngsw.sh
|
|
168
|
-
// sed -i '/onFetch(event) {/,/const req = event.request;/c onFetch(event){const req=event.request;if(req.headers.get('disable-ngsw')==="true")return;' ./front/ngsw-worker.js
|
|
169
|
-
/**
|
|
170
|
-
* @param {?} url
|
|
171
|
-
* @param {?} body
|
|
172
|
-
* @param {?=} options
|
|
173
|
-
* @return {?}
|
|
174
|
-
*/
|
|
175
|
-
postFiles(url, body, options) {
|
|
176
|
-
if (!options) {
|
|
177
|
-
options = {};
|
|
178
|
-
}
|
|
179
|
-
if (!options.params) {
|
|
180
|
-
options.params = new HttpParams();
|
|
181
|
-
}
|
|
182
|
-
options.params = options.params.set('_req_s', HttpService.ANGULAR_REQUEST_CONST);
|
|
183
|
-
/** @type {?} */
|
|
184
|
-
const headers = new HttpHeaders();
|
|
185
|
-
options['headers'] = headers.set('disable-ngsw', 'true');
|
|
186
|
-
return this.http.post(url, body, options)
|
|
187
|
-
.pipe(catchError(HttpService.handleError));
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* @param {?} url
|
|
191
|
-
* @param {?=} options
|
|
192
|
-
* @return {?}
|
|
193
|
-
*/
|
|
194
|
-
delete(url, options) {
|
|
195
|
-
return this.http.delete(url, options)
|
|
196
|
-
.pipe(catchError(HttpService.handleError));
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
HttpService.ANGULAR_REQUEST_CONST = '2';
|
|
200
|
-
HttpService.decorators = [
|
|
201
|
-
{ type: Injectable, args: [{
|
|
202
|
-
providedIn: 'root'
|
|
203
|
-
},] }
|
|
204
|
-
];
|
|
205
|
-
/** @nocollapse */
|
|
206
|
-
HttpService.ctorParameters = () => [
|
|
207
|
-
{ type: HttpClient },
|
|
208
|
-
{ type: MatSnackBar }
|
|
209
|
-
];
|
|
210
|
-
/** @nocollapse */ HttpService.ɵprov = ɵɵdefineInjectable({ factory: function HttpService_Factory() { return new HttpService(ɵɵinject(HttpClient), ɵɵinject(MatSnackBar)); }, token: HttpService, providedIn: "root" });
|
|
211
|
-
if (false) {
|
|
212
|
-
/** @type {?} */
|
|
213
|
-
HttpService.ANGULAR_REQUEST_CONST;
|
|
214
|
-
/**
|
|
215
|
-
* @type {?}
|
|
216
|
-
* @private
|
|
217
|
-
*/
|
|
218
|
-
HttpService.instance;
|
|
219
|
-
/**
|
|
220
|
-
* @type {?}
|
|
221
|
-
* @private
|
|
222
|
-
*/
|
|
223
|
-
HttpService.prototype.http;
|
|
224
|
-
/**
|
|
225
|
-
* @type {?}
|
|
226
|
-
* @private
|
|
227
|
-
*/
|
|
228
|
-
HttpService.prototype.snackBar;
|
|
10
|
+
// @dynamic --> NEMAZAT https://github.com/dherges/ng-packagr/issues/641
|
|
11
|
+
class HttpService {
|
|
12
|
+
constructor(http, snackBar) {
|
|
13
|
+
this.http = http;
|
|
14
|
+
this.snackBar = snackBar;
|
|
15
|
+
if (!HttpService.instance) { // není to prasárna?
|
|
16
|
+
HttpService.instance = this;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static handleError(error) {
|
|
20
|
+
HttpService.errorStatus(error);
|
|
21
|
+
// Todo: In a real world app, you might use a remote logging infrastructure
|
|
22
|
+
let errMsg;
|
|
23
|
+
if (error instanceof HttpResponse) {
|
|
24
|
+
const body = error.body || '';
|
|
25
|
+
const err = body.error || JSON.stringify(body);
|
|
26
|
+
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
errMsg = error.message ? error.message : error.toString();
|
|
30
|
+
}
|
|
31
|
+
console.error(errMsg);
|
|
32
|
+
return throwError(errMsg);
|
|
33
|
+
}
|
|
34
|
+
static errorStatus(err) {
|
|
35
|
+
switch (err.status) {
|
|
36
|
+
case 300:
|
|
37
|
+
case 301:
|
|
38
|
+
HttpService.handleRedirect(err);
|
|
39
|
+
break;
|
|
40
|
+
// case 302:
|
|
41
|
+
// HttpService.handleRedirect(err);
|
|
42
|
+
// break;
|
|
43
|
+
case 403:
|
|
44
|
+
HttpService.handleErrorMessage(err);
|
|
45
|
+
break;
|
|
46
|
+
case 503:
|
|
47
|
+
HttpService.handleErrorMessage(err);
|
|
48
|
+
break;
|
|
49
|
+
case 601:
|
|
50
|
+
HttpService.handleRedirect(err);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
// todo 413 Request Entity Too Large - upload file z formu
|
|
54
|
+
}
|
|
55
|
+
// private static handleLoginRedirect(res: HttpResponse<any>) {
|
|
56
|
+
// const error = res['error'];
|
|
57
|
+
//
|
|
58
|
+
// }
|
|
59
|
+
static handleRedirect(res) {
|
|
60
|
+
const error = res['error'];
|
|
61
|
+
if (error.login) {
|
|
62
|
+
let path = window.location.pathname;
|
|
63
|
+
path = path[0] === '/' ? path.substr(1) : path; // '/front/' => 'front/'
|
|
64
|
+
// console.log('Redirect ' + `${error.url}?r=${path}`);
|
|
65
|
+
window.location.href = `${error.url}?r=${path}`;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
window.location.href = `${error.url}`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
static handleErrorMessage(res) {
|
|
72
|
+
const message = res['error'];
|
|
73
|
+
if (res['error'] instanceof Blob) {
|
|
74
|
+
const reader = new FileReader();
|
|
75
|
+
reader.addEventListener('loadend', (e) => {
|
|
76
|
+
HttpService.createSnackBar(e.srcElement['result']);
|
|
77
|
+
});
|
|
78
|
+
reader.readAsText(res['error']);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
HttpService.createSnackBar(message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
static createSnackBar(message) {
|
|
85
|
+
const config = new MatSnackBarConfig();
|
|
86
|
+
config.duration = 2000;
|
|
87
|
+
config.panelClass = 'es-snackbar-alert-danger'; // AppSnackbarPanelClass.DANGER;
|
|
88
|
+
HttpService.instance.snackBar.open(message, null, config);
|
|
89
|
+
}
|
|
90
|
+
get(url, options) {
|
|
91
|
+
if (!options) {
|
|
92
|
+
options = {};
|
|
93
|
+
}
|
|
94
|
+
if (!options.params) {
|
|
95
|
+
options.params = new HttpParams();
|
|
96
|
+
}
|
|
97
|
+
options.params = options.params.set('_req_s', HttpService.ANGULAR_REQUEST_CONST); // pridava se nejakej param na formy pro angular
|
|
98
|
+
return this.http.get(url, options)
|
|
99
|
+
.pipe(catchError(HttpService.handleError));
|
|
100
|
+
}
|
|
101
|
+
// tslint:disable-next-line:max-line-length
|
|
102
|
+
post(url, body, options) {
|
|
103
|
+
if (!options) {
|
|
104
|
+
options = {};
|
|
105
|
+
}
|
|
106
|
+
if (!options.params) {
|
|
107
|
+
options.params = new HttpParams();
|
|
108
|
+
}
|
|
109
|
+
options.params = options.params.set('_req_s', HttpService.ANGULAR_REQUEST_CONST);
|
|
110
|
+
return this.http.post(url, body, options)
|
|
111
|
+
.pipe(catchError(HttpService.handleError));
|
|
112
|
+
}
|
|
113
|
+
// upload file s vypnutym service workerem -> header{disable-ngsw: true}
|
|
114
|
+
// v ekj projektu fix-ngsw.sh
|
|
115
|
+
// tslint:disable-next-line:max-line-length
|
|
116
|
+
// sed -i '/onFetch(event) {/,/const req = event.request;/c onFetch(event){const req=event.request;if(req.headers.get('disable-ngsw')==="true")return;' ./front/ngsw-worker.js
|
|
117
|
+
// tslint:disable-next-line:max-line-length
|
|
118
|
+
postFiles(url, body, options) {
|
|
119
|
+
if (!options) {
|
|
120
|
+
options = {};
|
|
121
|
+
}
|
|
122
|
+
if (!options.params) {
|
|
123
|
+
options.params = new HttpParams();
|
|
124
|
+
}
|
|
125
|
+
options.params = options.params.set('_req_s', HttpService.ANGULAR_REQUEST_CONST);
|
|
126
|
+
const headers = new HttpHeaders();
|
|
127
|
+
options['headers'] = headers.set('disable-ngsw', 'true');
|
|
128
|
+
return this.http.post(url, body, options)
|
|
129
|
+
.pipe(catchError(HttpService.handleError));
|
|
130
|
+
}
|
|
131
|
+
delete(url, options) {
|
|
132
|
+
return this.http.delete(url, options)
|
|
133
|
+
.pipe(catchError(HttpService.handleError));
|
|
134
|
+
}
|
|
229
135
|
}
|
|
136
|
+
HttpService.ANGULAR_REQUEST_CONST = '2';
|
|
137
|
+
/** @nocollapse */ HttpService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: HttpService, deps: [{ token: i1.HttpClient }, { token: i2.MatSnackBar }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
138
|
+
/** @nocollapse */ HttpService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: HttpService, providedIn: 'root' });
|
|
139
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: HttpService, decorators: [{
|
|
140
|
+
type: Injectable,
|
|
141
|
+
args: [{
|
|
142
|
+
providedIn: 'root'
|
|
143
|
+
}]
|
|
144
|
+
}], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: i2.MatSnackBar }]; } });
|
|
230
145
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
</p>
|
|
251
|
-
`
|
|
252
|
-
}] }
|
|
253
|
-
];
|
|
254
|
-
/** @nocollapse */
|
|
255
|
-
HttpComponent.ctorParameters = () => [];
|
|
146
|
+
class HttpComponent {
|
|
147
|
+
constructor() { }
|
|
148
|
+
ngOnInit() {
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** @nocollapse */ HttpComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: HttpComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
152
|
+
/** @nocollapse */ HttpComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: HttpComponent, selector: "es-http", ngImport: i0, template: `
|
|
153
|
+
<p>
|
|
154
|
+
http works!
|
|
155
|
+
</p>
|
|
156
|
+
`, isInline: true });
|
|
157
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: HttpComponent, decorators: [{
|
|
158
|
+
type: Component,
|
|
159
|
+
args: [{ selector: 'es-http', template: `
|
|
160
|
+
<p>
|
|
161
|
+
http works!
|
|
162
|
+
</p>
|
|
163
|
+
` }]
|
|
164
|
+
}], ctorParameters: function () { return []; } });
|
|
256
165
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
*/
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
HttpModule
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
]
|
|
166
|
+
class HttpModule {
|
|
167
|
+
}
|
|
168
|
+
/** @nocollapse */ HttpModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: HttpModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
169
|
+
/** @nocollapse */ HttpModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: HttpModule, declarations: [HttpComponent], imports: [HttpClientModule] });
|
|
170
|
+
/** @nocollapse */ HttpModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: HttpModule, providers: [
|
|
171
|
+
HttpService
|
|
172
|
+
], imports: [HttpClientModule] });
|
|
173
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: HttpModule, decorators: [{
|
|
174
|
+
type: NgModule,
|
|
175
|
+
args: [{
|
|
176
|
+
imports: [
|
|
177
|
+
HttpClientModule
|
|
178
|
+
],
|
|
179
|
+
declarations: [HttpComponent],
|
|
180
|
+
providers: [
|
|
181
|
+
HttpService
|
|
182
|
+
],
|
|
183
|
+
exports: [],
|
|
184
|
+
}]
|
|
185
|
+
}] });
|
|
276
186
|
|
|
277
|
-
|
|
278
|
-
*
|
|
279
|
-
* Generated from: public_api.ts
|
|
280
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
187
|
+
/*
|
|
188
|
+
* Public API Surface of http
|
|
281
189
|
*/
|
|
282
190
|
|
|
283
|
-
/**
|
|
284
|
-
*
|
|
285
|
-
* Generated from: eurosat-http.ts
|
|
286
|
-
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
191
|
+
/**
|
|
192
|
+
* Generated bundle index. Do not edit.
|
|
287
193
|
*/
|
|
288
194
|
|
|
289
195
|
export { HttpComponent, HttpModule, HttpService };
|
|
290
|
-
//# sourceMappingURL=eurosat-http.
|
|
196
|
+
//# sourceMappingURL=eurosat-http.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eurosat-http.mjs","sources":["../../../projects/http/src/lib/http.service.ts","../../../projects/http/src/lib/http.component.ts","../../../projects/http/src/lib/http.module.ts","../../../projects/http/src/public_api.ts","../../../projects/http/src/eurosat-http.ts"],"sourcesContent":["import {Injectable} from '@angular/core';\nimport {HttpClient, HttpHeaders, HttpParams, HttpResponse} from '@angular/common/http';\nimport {MatSnackBar, MatSnackBarConfig} from '@angular/material/snack-bar';\nimport {Observable, throwError} from 'rxjs';\nimport {catchError} from 'rxjs/operators';\n// @dynamic --> NEMAZAT https://github.com/dherges/ng-packagr/issues/641\n@Injectable({\n providedIn: 'root'\n})\nexport class HttpService {\n\n public static ANGULAR_REQUEST_CONST = '2';\n\n private static instance: HttpService; // není to prasárna?\n\n constructor(\n private http: HttpClient,\n private snackBar: MatSnackBar,\n ) {\n if (!HttpService.instance) { // není to prasárna?\n HttpService.instance = this;\n }\n }\n\n public static handleError (error: HttpResponse<any> | any) {\n HttpService.errorStatus(error);\n\n // Todo: In a real world app, you might use a remote logging infrastructure\n let errMsg: string;\n if (error instanceof HttpResponse) {\n const body = error.body || '';\n const err = body.error || JSON.stringify(body);\n errMsg = `${error.status} - ${error.statusText || ''} ${err}`;\n } else {\n errMsg = error.message ? error.message : error.toString();\n }\n console.error(errMsg);\n return throwError(errMsg);\n }\n\n private static errorStatus(err: HttpResponse<any>) {\n switch (err.status) {\n case 300:\n case 301:\n HttpService.handleRedirect(err);\n break;\n // case 302:\n // HttpService.handleRedirect(err);\n // break;\n case 403:\n HttpService.handleErrorMessage(err);\n break;\n case 503:\n HttpService.handleErrorMessage(err);\n break;\n case 601:\n HttpService.handleRedirect(err);\n break;\n }\n\n // todo 413 Request Entity Too Large - upload file z formu\n }\n\n // private static handleLoginRedirect(res: HttpResponse<any>) {\n // const error = res['error'];\n //\n // }\n\n private static handleRedirect(res: HttpResponse<any>) {\n const error = res['error'];\n if (error.login) {\n let path = window.location.pathname;\n path = path[0] === '/' ? path.substr(1) : path; // '/front/' => 'front/'\n // console.log('Redirect ' + `${error.url}?r=${path}`);\n window.location.href = `${error.url}?r=${path}`;\n } else {\n window.location.href = `${error.url}`;\n }\n }\n\n private static handleErrorMessage(res: HttpResponse<any>) {\n const message = res['error'];\n if (res['error'] instanceof Blob) {\n const reader = new FileReader();\n\n reader.addEventListener('loadend', (e) => {\n HttpService.createSnackBar(e.srcElement['result']);\n });\n\n reader.readAsText(res['error']);\n } else {\n HttpService.createSnackBar(message);\n }\n }\n\n private static createSnackBar(message) {\n const config = new MatSnackBarConfig();\n config.duration = 2000;\n config.panelClass = 'es-snackbar-alert-danger'; // AppSnackbarPanelClass.DANGER;\n HttpService.instance.snackBar.open(message, null, config);\n }\n\n get(url: string, options?: {params?: HttpParams, responseType?, observe?}): Observable<any> {\n if (!options) { options = {}; }\n if (!options.params) {\n options.params = new HttpParams();\n }\n options.params = options.params.set('_req_s', HttpService.ANGULAR_REQUEST_CONST); // pridava se nejakej param na formy pro angular\n return this.http.get(url, options)\n .pipe(catchError(HttpService.handleError));\n }\n\n // tslint:disable-next-line:max-line-length\n post(url: string, body: any | null, options?: {params?: HttpParams, responseType?, reportProgress?: boolean, observe?: any}): Observable<any> {\n if (!options) { options = {}; }\n if (!options.params) {\n options.params = new HttpParams();\n }\n options.params = options.params.set('_req_s', HttpService.ANGULAR_REQUEST_CONST);\n\n return this.http.post(url, body, options)\n .pipe(catchError(HttpService.handleError));\n }\n\n // upload file s vypnutym service workerem -> header{disable-ngsw: true}\n // v ekj projektu fix-ngsw.sh\n // tslint:disable-next-line:max-line-length\n // sed -i '/onFetch(event) {/,/const req = event.request;/c onFetch(event){const req=event.request;if(req.headers.get('disable-ngsw')===\"true\")return;' ./front/ngsw-worker.js\n // tslint:disable-next-line:max-line-length\n postFiles(url: string, body: any | null, options?: {params?: HttpParams, responseType?, reportProgress?: boolean, observe?: any}): Observable<any> {\n if (!options) { options = {}; }\n if (!options.params) {\n options.params = new HttpParams();\n }\n options.params = options.params.set('_req_s', HttpService.ANGULAR_REQUEST_CONST);\n const headers = new HttpHeaders();\n options['headers'] = headers.set('disable-ngsw', 'true');\n return this.http.post(url, body, options)\n .pipe(catchError(HttpService.handleError));\n }\n\n delete(url: string, options?: {}): Observable<Object> {\n return this.http.delete(url, options)\n .pipe(catchError(HttpService.handleError));\n }\n\n\n // private extractMsgpack(res: Response) {\n //\n // let buffer = res.arrayBuffer();\n // // console.log(buffer);\n //\n // let array = new Uint8Array(buffer);\n // // console.log(array);\n // // console.log('Decode ' + msgpack.decode(array));\n //\n // return msgpack.decode(array);\n // }\n\n\n\n}\n","import { Component, OnInit } from '@angular/core';\n\n@Component({\n selector: 'es-http',\n template: `\n <p>\n http works!\n </p>\n `,\n styles: []\n})\nexport class HttpComponent implements OnInit {\n\n constructor() { }\n\n ngOnInit() {\n }\n\n}\n","import {NgModule} from '@angular/core';\nimport {HttpComponent} from './http.component';\nimport {HttpClientModule} from '@angular/common/http';\nimport {HttpService} from './http.service';\n\n@NgModule({\n imports: [\n HttpClientModule\n ],\n declarations: [HttpComponent],\n providers: [\n HttpService\n ],\n exports: [],\n})\nexport class HttpModule { }\n","/*\n * Public API Surface of http\n */\n\nexport * from './lib/http.service';\nexport * from './lib/http.component';\nexport * from './lib/http.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;AAKA;MAIa,WAAW,CAAA;IAMpB,WACY,CAAA,IAAgB,EAChB,QAAqB,EAAA;AADrB,QAAA,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAY;AAChB,QAAA,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAa;AAE7B,QAAA,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE;AACvB,YAAA,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC/B,SAAA;KACJ;IAEM,OAAO,WAAW,CAAE,KAA8B,EAAA;AACrD,QAAA,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;;AAG/B,QAAA,IAAI,MAAc,CAAC;QACnB,IAAI,KAAK,YAAY,YAAY,EAAE;AAC/B,YAAA,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;AAC9B,YAAA,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC/C,YAAA,MAAM,GAAG,CAAA,EAAG,KAAK,CAAC,MAAM,CAAM,GAAA,EAAA,KAAK,CAAC,UAAU,IAAI,EAAE,CAAI,CAAA,EAAA,GAAG,EAAE,CAAC;AACjE,SAAA;AAAM,aAAA;AACH,YAAA,MAAM,GAAG,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC7D,SA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