bx-rest 0.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/.editorconfig +17 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/package.json +36 -0
- package/src/const/time.ts +3 -0
- package/src/index.ts +0 -0
- package/src/rest/user/user.ts +341 -0
- package/src/services/base.ts +187 -0
- package/src/services/http/HttpData.ts +142 -0
- package/src/services/http/base/HttpData.ts +140 -0
- package/src/services/http/base/base.ts +39 -0
- package/src/services/http/base/http.ts +67 -0
- package/src/services/http/http.ts +182 -0
- package/src/services/snack-bar/snack-bar.service.ts +40 -0
- package/src/services/snack-bar/toast-message/toast-message.component.html +13 -0
- package/src/services/snack-bar/toast-message/toast-message.component.scss +53 -0
- package/src/services/snack-bar/toast-message/toast-message.component.spec.ts +24 -0
- package/src/services/snack-bar/toast-message/toast-message.component.ts +26 -0
- package/src/typification/rest/base/ApiPaginationBX.ts +3 -0
- package/src/typification/rest/base/OrderOptions.ts +3 -0
- package/src/typification/rest/base/YesNo.ts +1 -0
- package/src/typification/rest/base/fieldBXType.ts +1 -0
- package/src/typification/rest/base/filterGenerator.ts +3 -0
- package/src/typification/rest/base/httpAnswerBX.ts +15 -0
- package/src/typification/rest/settings.ts +7 -0
- package/src/typification/rest/support/param.ts +8 -0
- package/src/typification/rest/user/CustomUserFieldInfo.ts +70 -0
- package/src/typification/rest/user/UserFilterSearch.ts +43 -0
- package/src/typification/rest/user/get.ts +17 -0
- package/src/typification/rest/user/user.ts +68 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { BaseServices } from '@/services/base'
|
|
2
|
+
import { HttpParams } from '@angular/common/http'
|
|
3
|
+
import { iHttpParamSettings } from '@/typification/rest/settings'
|
|
4
|
+
import iHttpAnswerBX from '@/typification/rest/base/httpAnswerBX'
|
|
5
|
+
|
|
6
|
+
export class HttpData extends BaseServices {
|
|
7
|
+
|
|
8
|
+
defSettings: iHttpParamSettings = {
|
|
9
|
+
timeZone: {
|
|
10
|
+
calc: true,
|
|
11
|
+
levelOut: false
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getHttpParamsGet( // не так уж и сложно сделать сложенный HttpParams, да гугл?
|
|
16
|
+
obj: any,
|
|
17
|
+
sendHttpParams: HttpParams = new HttpParams(),
|
|
18
|
+
thisArray = false,
|
|
19
|
+
nesting: string[] = [],
|
|
20
|
+
// settings = this.defSettings
|
|
21
|
+
_ = this.defSettings
|
|
22
|
+
): any {
|
|
23
|
+
for (const key in obj) {
|
|
24
|
+
let setKey = ''
|
|
25
|
+
if (nesting.length) {
|
|
26
|
+
let first = nesting[0]
|
|
27
|
+
setKey = (nesting.length > 1)
|
|
28
|
+
? first + '[' + nesting.slice(1).join('][') + '][' + key + ']'
|
|
29
|
+
: first + '[' + key + ']'
|
|
30
|
+
} else {
|
|
31
|
+
setKey = key
|
|
32
|
+
}
|
|
33
|
+
switch (typeof obj[key]) {
|
|
34
|
+
case 'string':
|
|
35
|
+
sendHttpParams = sendHttpParams.set(setKey, obj[key])
|
|
36
|
+
break
|
|
37
|
+
case 'symbol':
|
|
38
|
+
case 'number':
|
|
39
|
+
case 'bigint':
|
|
40
|
+
case 'boolean':
|
|
41
|
+
sendHttpParams = sendHttpParams.set(setKey, String(obj[key]))
|
|
42
|
+
break
|
|
43
|
+
case 'object':
|
|
44
|
+
nesting.push(key)
|
|
45
|
+
sendHttpParams = this.getHttpParamsGet(obj[key], sendHttpParams, false, nesting)
|
|
46
|
+
nesting.pop()
|
|
47
|
+
break
|
|
48
|
+
case 'function':
|
|
49
|
+
case 'undefined':
|
|
50
|
+
default:
|
|
51
|
+
console.error('Ты отправил что-то не то', obj[key], typeof obj[key], typeof obj)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return sendHttpParams
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getHttpParamsPost(
|
|
58
|
+
obj: any,
|
|
59
|
+
sendHttpParams: FormData = new FormData(),
|
|
60
|
+
thisArray = false,
|
|
61
|
+
nesting: string[] = [],
|
|
62
|
+
settings = this.defSettings
|
|
63
|
+
): any {
|
|
64
|
+
|
|
65
|
+
if (obj instanceof Blob) {
|
|
66
|
+
let first = nesting[0]
|
|
67
|
+
let setKey = (nesting.length > 1)
|
|
68
|
+
? first + '[' + nesting.slice(1).join('][') + ']'
|
|
69
|
+
: first
|
|
70
|
+
sendHttpParams.set(setKey, obj)
|
|
71
|
+
return sendHttpParams
|
|
72
|
+
} else if (obj instanceof Date) {
|
|
73
|
+
let first = nesting[0]
|
|
74
|
+
let tzoffset = (settings.timeZone.calc) ? obj.getTimezoneOffset() * 60000 : 0 // вычисляем влияние часового пояса
|
|
75
|
+
let levelOut = (settings.timeZone.levelOut) ? obj.getTimezoneOffset() * 60000 : 0 // вычисляем влияние часового пояса
|
|
76
|
+
let setKey = (nesting.length > 1)
|
|
77
|
+
? first + '[' + nesting.slice(1).join('][') + ']'
|
|
78
|
+
: first
|
|
79
|
+
sendHttpParams.set(setKey, (new Date(obj.valueOf() + tzoffset - levelOut)).toISOString())
|
|
80
|
+
return sendHttpParams
|
|
81
|
+
} else {
|
|
82
|
+
for (const key in obj) {
|
|
83
|
+
let setKey = ''
|
|
84
|
+
if (nesting.length) {
|
|
85
|
+
let first = nesting[0]
|
|
86
|
+
setKey = (nesting.length > 1)
|
|
87
|
+
? first + '[' + nesting.slice(1).join('][') + '][' + key + ']'
|
|
88
|
+
: first + '[' + key + ']'
|
|
89
|
+
} else {
|
|
90
|
+
setKey = key
|
|
91
|
+
}
|
|
92
|
+
switch (typeof obj[key]) {
|
|
93
|
+
case 'string':
|
|
94
|
+
sendHttpParams.set(setKey, obj[key])
|
|
95
|
+
break
|
|
96
|
+
case 'symbol':
|
|
97
|
+
case 'number':
|
|
98
|
+
case 'bigint':
|
|
99
|
+
case 'boolean':
|
|
100
|
+
sendHttpParams.set(setKey, String(obj[key]))
|
|
101
|
+
break
|
|
102
|
+
case 'object':
|
|
103
|
+
nesting.push(key)
|
|
104
|
+
sendHttpParams = this.getHttpParamsPost(
|
|
105
|
+
obj[key],
|
|
106
|
+
sendHttpParams,
|
|
107
|
+
false,
|
|
108
|
+
nesting,
|
|
109
|
+
settings
|
|
110
|
+
)
|
|
111
|
+
nesting.pop()
|
|
112
|
+
break
|
|
113
|
+
case 'function':
|
|
114
|
+
case 'undefined':
|
|
115
|
+
default:
|
|
116
|
+
console.error('Ты отправил что-то не то', obj[key], typeof obj[key], typeof obj)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return sendHttpParams
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
mapResult<T>(v: iHttpAnswerBX<T> | undefined): T | undefined {
|
|
124
|
+
if (v && (v.result || typeof v.result === 'boolean')) {
|
|
125
|
+
return v.result
|
|
126
|
+
}
|
|
127
|
+
return undefined
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
sliceArrayIntoChunks(arr: any[], chunkSize: number) {
|
|
131
|
+
const res = [];
|
|
132
|
+
for (let i = 0; i < arr.length; i += chunkSize) {
|
|
133
|
+
const chunk = arr.slice(i, i + chunkSize);
|
|
134
|
+
res.push(chunk);
|
|
135
|
+
}
|
|
136
|
+
return res;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
removingMultipleSlashes(str: string) {
|
|
140
|
+
return str.replace(/\/{2,}/g, '/')
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import BaseServices from '@/lib/services/base'
|
|
2
|
+
import { HttpParams } from '@angular/common/http'
|
|
3
|
+
import { iHttpParamSettings } from '@/lib/typification/bitrix/api/rest/settings'
|
|
4
|
+
import iHttpAnswerBX from '@/lib/typification/bitrix/api/rest/base/httpAnswerBX';
|
|
5
|
+
|
|
6
|
+
export class HttpData extends BaseServices {
|
|
7
|
+
|
|
8
|
+
defSettings: iHttpParamSettings = {
|
|
9
|
+
timeZone: {
|
|
10
|
+
calc: true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getHttpParamsGet( // не так уж и сложно сделать сложенный HttpParams, да гугл?
|
|
15
|
+
obj: any,
|
|
16
|
+
sendHttpParams: HttpParams = new HttpParams(),
|
|
17
|
+
thisArray = false,
|
|
18
|
+
nesting: string[] = [],
|
|
19
|
+
// settings = this.defSettings
|
|
20
|
+
_ = this.defSettings
|
|
21
|
+
): any {
|
|
22
|
+
for (const key in obj) {
|
|
23
|
+
let setKey = ''
|
|
24
|
+
if (nesting.length) {
|
|
25
|
+
let first = nesting[0]
|
|
26
|
+
setKey = (nesting.length > 1)
|
|
27
|
+
? first + '[' + nesting.slice(1).join('][') + '][' + key + ']'
|
|
28
|
+
: first + '[' + key + ']'
|
|
29
|
+
} else {
|
|
30
|
+
setKey = key
|
|
31
|
+
}
|
|
32
|
+
switch (typeof obj[key]) {
|
|
33
|
+
case 'string':
|
|
34
|
+
sendHttpParams = sendHttpParams.set(setKey, obj[key])
|
|
35
|
+
break
|
|
36
|
+
case 'symbol':
|
|
37
|
+
case 'number':
|
|
38
|
+
case 'bigint':
|
|
39
|
+
case 'boolean':
|
|
40
|
+
sendHttpParams = sendHttpParams.set(setKey, String(obj[key]))
|
|
41
|
+
break
|
|
42
|
+
case 'object':
|
|
43
|
+
nesting.push(key)
|
|
44
|
+
sendHttpParams = this.getHttpParamsGet(obj[key], sendHttpParams, false, nesting)
|
|
45
|
+
nesting.pop()
|
|
46
|
+
break
|
|
47
|
+
case 'function':
|
|
48
|
+
case 'undefined':
|
|
49
|
+
default:
|
|
50
|
+
console.error('Ты отправил что-то не то', obj[key], typeof obj[key], typeof obj)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return sendHttpParams
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getHttpParamsPost(
|
|
57
|
+
obj: any,
|
|
58
|
+
sendHttpParams: FormData = new FormData(),
|
|
59
|
+
thisArray = false,
|
|
60
|
+
nesting: string[] = [],
|
|
61
|
+
settings = this.defSettings
|
|
62
|
+
): any {
|
|
63
|
+
|
|
64
|
+
if (obj instanceof Blob) {
|
|
65
|
+
let first = nesting[0]
|
|
66
|
+
let setKey = (nesting.length > 1)
|
|
67
|
+
? first + '[' + nesting.slice(1).join('][') + ']'
|
|
68
|
+
: first
|
|
69
|
+
sendHttpParams.set(setKey, obj)
|
|
70
|
+
return sendHttpParams
|
|
71
|
+
} else if (obj instanceof Date) {
|
|
72
|
+
let first = nesting[0]
|
|
73
|
+
let tzoffset = (settings.timeZone.calc) ? obj.getTimezoneOffset() * 60000 : 0 // вычисляем влияние часового пояса
|
|
74
|
+
let setKey = (nesting.length > 1)
|
|
75
|
+
? first + '[' + nesting.slice(1).join('][') + ']'
|
|
76
|
+
: first
|
|
77
|
+
sendHttpParams.set(setKey, (new Date(obj.valueOf() + tzoffset)).toISOString())
|
|
78
|
+
return sendHttpParams
|
|
79
|
+
} else {
|
|
80
|
+
for (const key in obj) {
|
|
81
|
+
let setKey = ''
|
|
82
|
+
if (nesting.length) {
|
|
83
|
+
let first = nesting[0]
|
|
84
|
+
setKey = (nesting.length > 1)
|
|
85
|
+
? first + '[' + nesting.slice(1).join('][') + '][' + key + ']'
|
|
86
|
+
: first + '[' + key + ']'
|
|
87
|
+
} else {
|
|
88
|
+
setKey = key
|
|
89
|
+
}
|
|
90
|
+
switch (typeof obj[key]) {
|
|
91
|
+
case 'string':
|
|
92
|
+
sendHttpParams.set(setKey, obj[key])
|
|
93
|
+
break
|
|
94
|
+
case 'symbol':
|
|
95
|
+
case 'number':
|
|
96
|
+
case 'bigint':
|
|
97
|
+
case 'boolean':
|
|
98
|
+
sendHttpParams.set(setKey, String(obj[key]))
|
|
99
|
+
break
|
|
100
|
+
case 'object':
|
|
101
|
+
nesting.push(key)
|
|
102
|
+
sendHttpParams = this.getHttpParamsPost(
|
|
103
|
+
obj[key],
|
|
104
|
+
sendHttpParams,
|
|
105
|
+
false,
|
|
106
|
+
nesting,
|
|
107
|
+
settings
|
|
108
|
+
)
|
|
109
|
+
nesting.pop()
|
|
110
|
+
break
|
|
111
|
+
case 'function':
|
|
112
|
+
case 'undefined':
|
|
113
|
+
default:
|
|
114
|
+
console.error('Ты отправил что-то не то', obj[key], typeof obj[key], typeof obj)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return sendHttpParams
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
mapResult<T>(v: iHttpAnswerBX<T> | undefined): T | undefined {
|
|
122
|
+
if (v && (v.result || typeof v.result === 'boolean')) {
|
|
123
|
+
return v.result
|
|
124
|
+
}
|
|
125
|
+
return undefined
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
sliceArrayIntoChunks(arr: any[], chunkSize: number) {
|
|
129
|
+
const res = [];
|
|
130
|
+
for (let i = 0; i < arr.length; i += chunkSize) {
|
|
131
|
+
const chunk = arr.slice(i, i + chunkSize);
|
|
132
|
+
res.push(chunk);
|
|
133
|
+
}
|
|
134
|
+
return res;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
removingMultipleSlashes(str: string) {
|
|
138
|
+
return str.replace(/\/{2,}/g, '/')
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { iHttpParamSettings } from '@/typification/rest/settings'
|
|
2
|
+
import { HttpClient } from '@angular/common/http'
|
|
3
|
+
import SnackBarService from '@/services/snack-bar/snack-bar.service'
|
|
4
|
+
import { Observable, of, } from 'rxjs'
|
|
5
|
+
import { HttpData } from '@/services/http/HttpData'
|
|
6
|
+
import { Injectable } from '@angular/core'
|
|
7
|
+
|
|
8
|
+
@Injectable({
|
|
9
|
+
providedIn: 'root'
|
|
10
|
+
})
|
|
11
|
+
export abstract class BaseHttp extends HttpData {
|
|
12
|
+
|
|
13
|
+
protected constructor(public http: HttpClient, public snackBar: SnackBarService) {
|
|
14
|
+
super()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
abstract httpGet<T>(
|
|
18
|
+
url: string,
|
|
19
|
+
params: any,
|
|
20
|
+
textError: string,
|
|
21
|
+
settings: iHttpParamSettings
|
|
22
|
+
): Observable<T | undefined>
|
|
23
|
+
|
|
24
|
+
abstract httpPost<T>(url: string,
|
|
25
|
+
params: any ,
|
|
26
|
+
textError: string,
|
|
27
|
+
settings: iHttpParamSettings
|
|
28
|
+
): Observable<T | undefined>
|
|
29
|
+
|
|
30
|
+
handleError<T>(
|
|
31
|
+
result?: T,
|
|
32
|
+
textError = 'получения данных') {
|
|
33
|
+
return (error: Error): Observable<T> => {
|
|
34
|
+
console.error(`failed: ${error.message}`)
|
|
35
|
+
this.snackBar.error('Ошибка: ' + textError)
|
|
36
|
+
return of(result as T)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Observable, throwError } from 'rxjs'
|
|
2
|
+
import { catchError } from 'rxjs/operators'
|
|
3
|
+
import { HttpParams } from '@angular/common/http'
|
|
4
|
+
import { iHttpParamSettings } from '@/typification/rest/settings'
|
|
5
|
+
import { BaseHttp } from '@/services/http/base/base'
|
|
6
|
+
|
|
7
|
+
export class BaseHttpServices extends BaseHttp {
|
|
8
|
+
|
|
9
|
+
public httpGet<T>(
|
|
10
|
+
url: string,
|
|
11
|
+
params = {},
|
|
12
|
+
textError = '',
|
|
13
|
+
settings: iHttpParamSettings = this.defSettings
|
|
14
|
+
): Observable<T | undefined> {
|
|
15
|
+
return this.http.get<T | undefined>(url, {
|
|
16
|
+
params: this.getHttpParamsGet(params, new HttpParams(), false, [], settings)
|
|
17
|
+
}).pipe(
|
|
18
|
+
catchError(err => {
|
|
19
|
+
if (!textError.length && err.error.error_description) {
|
|
20
|
+
textError = err.error.error_description
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.snackBar.error('Ошибка: ' + textError)
|
|
24
|
+
return throwError(() => err)
|
|
25
|
+
})
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public httpPost<T>(url: string,
|
|
30
|
+
params: any = {},
|
|
31
|
+
textError = '',
|
|
32
|
+
settings: iHttpParamSettings = this.defSettings
|
|
33
|
+
): Observable<T | undefined> {
|
|
34
|
+
return this.http.post<T | undefined>(
|
|
35
|
+
url,
|
|
36
|
+
this.getHttpParamsPost(params, new FormData(), false, [], settings)
|
|
37
|
+
).pipe(
|
|
38
|
+
catchError(err => {
|
|
39
|
+
if (!textError.length && err.error.error_description) {
|
|
40
|
+
textError = err.error.error_description
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.snackBar.error('Ошибка: ' + textError)
|
|
44
|
+
console.error(err)
|
|
45
|
+
return throwError(() => err)
|
|
46
|
+
})
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// TODO: доделать
|
|
51
|
+
// httpPostBaseWithFile<T>(url: string,
|
|
52
|
+
// params: any = {},
|
|
53
|
+
// textError = ''): Observable<T | undefined> {
|
|
54
|
+
// let searchFile = Object.values(params).find((i: any) => i instanceof Blob)
|
|
55
|
+
// if (searchFile) {
|
|
56
|
+
// return this.http.post<T | undefined>(url, this.getHttpParamsPost(params)).pipe(
|
|
57
|
+
// catchError(err => {
|
|
58
|
+
// this.snackBar.error('Ошибка: ' + textError)
|
|
59
|
+
// console.error(err)
|
|
60
|
+
// return throwError(() => err)
|
|
61
|
+
// })
|
|
62
|
+
// )
|
|
63
|
+
// } else {
|
|
64
|
+
// return this.httpPost(url, params, textError)
|
|
65
|
+
// }
|
|
66
|
+
// }
|
|
67
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { Observable, throwError, take, mergeMap, forkJoin } from 'rxjs'
|
|
2
|
+
import { catchError, map } from 'rxjs/operators'
|
|
3
|
+
import { Injectable } from '@angular/core'
|
|
4
|
+
import { HttpClient } from '@angular/common/http'
|
|
5
|
+
import SnackBarService from '@/lib/services/snack-bar/snack-bar.service'
|
|
6
|
+
import SessionKeyServices from '@/lib/services/api/bitrix/http/sessionKey'
|
|
7
|
+
import clone from 'just-clone'
|
|
8
|
+
import { iHttpParamSettings } from '@/lib/typification/bitrix/api/rest/settings'
|
|
9
|
+
import BaseHttpServices from '@/lib/services/http/http'
|
|
10
|
+
import {
|
|
11
|
+
iBatchRequestAnswer, iBatchRequestParam,
|
|
12
|
+
iBatchRequestParamArr,
|
|
13
|
+
iBatchRequestParamHttp, keyBatch
|
|
14
|
+
} from '@/lib/typification/bitrix/api/rest/batch/batchRequestParam'
|
|
15
|
+
import flatten from 'just-flatten-it'
|
|
16
|
+
|
|
17
|
+
@Injectable({
|
|
18
|
+
providedIn: 'root'
|
|
19
|
+
})
|
|
20
|
+
export default class HttpServices extends BaseHttpServices {
|
|
21
|
+
|
|
22
|
+
constructor(http: HttpClient, snackBar: SnackBarService, public session: SessionKeyServices) {
|
|
23
|
+
super(http, snackBar)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
timeNowOnServer() {
|
|
27
|
+
return this.httpGet<{ result?: Date, error?: string }>('server.time').pipe(
|
|
28
|
+
map(v => {
|
|
29
|
+
if (v && v.result) {
|
|
30
|
+
return new Date(v.result)
|
|
31
|
+
}
|
|
32
|
+
return undefined
|
|
33
|
+
}),
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Это пиздец а не метод
|
|
39
|
+
* @param param
|
|
40
|
+
*/
|
|
41
|
+
branch<T, A>(param: iBatchRequestParamArr<T> | iBatchRequestParam<T>[]): Observable<iBatchRequestAnswer<A>[] | undefined> {
|
|
42
|
+
let prepareParam = Object.entries<string>(this.prepareBatch<T>(param))
|
|
43
|
+
const size = 50 // больше не отдаст
|
|
44
|
+
let subarray = [] //массив в который будет выведен результат.
|
|
45
|
+
for (let i = 0; i < Math.ceil(prepareParam.length / size); i++) {
|
|
46
|
+
subarray[i] = prepareParam.slice((i * size), (i * size) + size)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return forkJoin(
|
|
50
|
+
subarray.map(i => {
|
|
51
|
+
return this.httpPost('batch.json', {
|
|
52
|
+
halt: 0,
|
|
53
|
+
cmd: Object.assign({}, ...i.map(x => {
|
|
54
|
+
return {[x[0]]: x[1]}
|
|
55
|
+
}))
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
) as Observable<iBatchRequestAnswer<A>[]>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
prepareBatch<T>(param: iBatchRequestParamArr<T> | iBatchRequestParam<T>[]): iBatchRequestParamHttp {
|
|
62
|
+
let res: iBatchRequestParamHttp = Object.keys(param).reduce(
|
|
63
|
+
(obj, key) => {
|
|
64
|
+
obj[key] = '';
|
|
65
|
+
return obj;
|
|
66
|
+
},
|
|
67
|
+
{} as iBatchRequestParamHttp
|
|
68
|
+
);
|
|
69
|
+
for (let key in param) {
|
|
70
|
+
if(typeof key === 'string' || typeof key === 'number' && param[key].param) {
|
|
71
|
+
res[key] = param[key].name + '?' + this.getHttpParamsGet(param[key].param).toString()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return res
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
mapBranchResult<T>(res: iBatchRequestAnswer<T>[]){
|
|
78
|
+
return Object.assign([], ...res.map(i => (i.result && i.result.result) ? i.result.result : undefined)) as {[key:keyBatch]: T}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
mapBranchResultWithoutKey<T>(res: iBatchRequestAnswer<T>[]): T[]{
|
|
82
|
+
return flatten<T>(Object.assign([], ...res.map(i => (i.result && i.result.result) ? i.result.result : undefined)))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
post<T>(name: string[],
|
|
86
|
+
params: any = {},
|
|
87
|
+
textError = '',
|
|
88
|
+
settings: iHttpParamSettings = this.defSettings) {
|
|
89
|
+
return this.httpPost<T>(this.getNameMethod(name), params, textError, settings)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get<T>(name: string[],
|
|
93
|
+
params: any = {},
|
|
94
|
+
textError = '',
|
|
95
|
+
settings: iHttpParamSettings = this.defSettings) {
|
|
96
|
+
return this.httpGet<T>(this.getNameMethod(name), params, textError, settings)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
override httpPost<T>(url: string,
|
|
100
|
+
params: any = {},
|
|
101
|
+
textError = '',
|
|
102
|
+
settings: iHttpParamSettings = this.defSettings
|
|
103
|
+
): Observable<T | undefined> {
|
|
104
|
+
return this.session.getAuthParams().pipe(
|
|
105
|
+
mergeMap(auth => {
|
|
106
|
+
if (auth) {
|
|
107
|
+
const paramsClone = clone(params)
|
|
108
|
+
paramsClone[this.session.getKeyAuth()] = auth
|
|
109
|
+
return this.session.getBaseUrl().pipe(mergeMap(v => {
|
|
110
|
+
if (v) {
|
|
111
|
+
return this.http.post<T | undefined>(
|
|
112
|
+
this.prepareBaseAddress(v) + url,
|
|
113
|
+
this.getHttpParamsPost(paramsClone, new FormData(), false, [], settings))
|
|
114
|
+
.pipe(
|
|
115
|
+
take(1),
|
|
116
|
+
catchError(err => {
|
|
117
|
+
if (!textError.length && err.error.error_description) {
|
|
118
|
+
textError = err.error.error_description
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
this.snackBar.error('Ошибка: ' + textError)
|
|
122
|
+
return throwError(() => err)
|
|
123
|
+
})
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
return throwError(() => 'get base url error')
|
|
127
|
+
}))
|
|
128
|
+
} else {
|
|
129
|
+
this.snackBar.error('Error: Auth not get')
|
|
130
|
+
return throwError(() => 'auth not get')
|
|
131
|
+
}
|
|
132
|
+
}))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
override httpGet<T>(
|
|
136
|
+
url: string,
|
|
137
|
+
params: any = {},
|
|
138
|
+
textError = '',
|
|
139
|
+
settings: iHttpParamSettings = this.defSettings
|
|
140
|
+
): Observable<T | undefined> {
|
|
141
|
+
return this.session.getAuthParams().pipe(
|
|
142
|
+
mergeMap(auth => {
|
|
143
|
+
if (auth) {
|
|
144
|
+
if (params === null) {
|
|
145
|
+
params = {}
|
|
146
|
+
}
|
|
147
|
+
const paramsClone = clone(params)
|
|
148
|
+
paramsClone[this.session.getKeyAuth()] = auth
|
|
149
|
+
let options = {
|
|
150
|
+
params: this.getHttpParamsGet(paramsClone)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return this.session.getBaseUrl().pipe(
|
|
154
|
+
mergeMap(v => {
|
|
155
|
+
if (v) {
|
|
156
|
+
return this.http.get<T>(this.prepareBaseAddress(v) + url, options).pipe(
|
|
157
|
+
take(1),
|
|
158
|
+
catchError(err => {
|
|
159
|
+
if (!textError.length && err.error.error_description) {
|
|
160
|
+
textError = err.error.error_description
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.snackBar.error('Ошибка: ' + textError)
|
|
164
|
+
return throwError(() => err)
|
|
165
|
+
}))
|
|
166
|
+
}
|
|
167
|
+
return throwError(() => 'get base url error')
|
|
168
|
+
})
|
|
169
|
+
)
|
|
170
|
+
} else {
|
|
171
|
+
this.snackBar.error('Error: Auth not get')
|
|
172
|
+
return throwError(() => 'auth not get')
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
getNameMethod(arr: string[]) {
|
|
179
|
+
return arr.join('.')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Сервис для вывода сообщений пользователю
|
|
3
|
+
* TODO: логирование
|
|
4
|
+
*/
|
|
5
|
+
import { Injectable } from '@angular/core'
|
|
6
|
+
import { ToastMessageComponent } from '@/lib/services/snack-bar/toast-message/toast-message.component'
|
|
7
|
+
import { MatSnackBar } from '@angular/material/snack-bar'
|
|
8
|
+
|
|
9
|
+
@Injectable({
|
|
10
|
+
providedIn: 'root'
|
|
11
|
+
})
|
|
12
|
+
export default class SnackBarService {
|
|
13
|
+
|
|
14
|
+
constructor(private snackBar: MatSnackBar) {
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
error(message: string, sec = 12): void {
|
|
18
|
+
this.standardMessage(message, sec, 'error')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
warning(message: string, sec = 7): void {
|
|
22
|
+
this.standardMessage(message, sec, 'warning');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
success(message: string, sec = 7): void {
|
|
26
|
+
this.standardMessage(message, sec, 'success');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
standardMessage(message: string, sec = 5, name = 'error'): void{
|
|
30
|
+
this.snackBar.open(message);
|
|
31
|
+
this.snackBar.openFromComponent(ToastMessageComponent, {
|
|
32
|
+
duration: sec * 1000,
|
|
33
|
+
data: {
|
|
34
|
+
message: message,
|
|
35
|
+
type: name
|
|
36
|
+
},
|
|
37
|
+
panelClass: name + '-box'
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<div class="w-100 d-flex">
|
|
2
|
+
<span matSnackBarLabel [class]="getClass()">
|
|
3
|
+
{{ data.message }}
|
|
4
|
+
</span>
|
|
5
|
+
<span matSnackBarActions [class]="getClass()">
|
|
6
|
+
<button mat-button matSnackBarAction (click)="snackBarRef.dismissWithAction()">
|
|
7
|
+
<mat-icon>
|
|
8
|
+
close
|
|
9
|
+
</mat-icon>
|
|
10
|
+
</button>
|
|
11
|
+
</span>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
|
|
3
|
+
display: flex;
|
|
4
|
+
background-color: red;
|
|
5
|
+
|
|
6
|
+
.mdc-snackbar__surface{
|
|
7
|
+
padding: 0;
|
|
8
|
+
margin: 0;
|
|
9
|
+
}
|
|
10
|
+
.error-message {
|
|
11
|
+
color: red;
|
|
12
|
+
}
|
|
13
|
+
&.error-box {
|
|
14
|
+
background-color: #eec1c1;
|
|
15
|
+
|
|
16
|
+
.error-message {
|
|
17
|
+
color: red;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
mat-snack-bar-container.mdc-snackbar {
|
|
23
|
+
|
|
24
|
+
&.error-box {
|
|
25
|
+
.mdc-snackbar__surface{
|
|
26
|
+
background-color: #eec1c1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.error-message {
|
|
30
|
+
color: red;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&.warning-box {
|
|
35
|
+
.mdc-snackbar__surface {
|
|
36
|
+
background-color: #f0f2b9;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.warning-message {
|
|
40
|
+
color: #15140f;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&.success-box {
|
|
45
|
+
.mdc-snackbar__surface {
|
|
46
|
+
background-color: #daf7d1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.success-message {
|
|
50
|
+
color: #423f31;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|