bx-rest 0.0.5 → 0.0.7
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/README.md +24 -0
- package/bx-rest.service.d.ts +6 -0
- package/consts/time.d.ts +3 -0
- package/esm2020/bx-rest.mjs +5 -0
- package/esm2020/bx-rest.service.mjs +14 -0
- package/esm2020/consts/time.mjs +4 -0
- package/esm2020/public-api.mjs +7 -0
- package/esm2020/rest/bx-rest.module.mjs +28 -0
- package/esm2020/services/base.mjs +174 -0
- package/fesm2015/bx-rest.mjs +225 -0
- package/fesm2015/bx-rest.mjs.map +1 -0
- package/fesm2020/bx-rest.mjs +222 -0
- package/fesm2020/bx-rest.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/package.json +40 -138
- package/public-api.d.ts +3 -0
- package/rest/bx-rest.module.d.ts +8 -0
- package/services/base.d.ts +32 -0
- package/LICENSE +0 -21
- package/src/consts/part-name-metods.ts +0 -11
- package/src/consts/time.ts +0 -3
- package/src/functions/isDate.ts +0 -8
- package/src/functions/isEqual.ts +0 -17
- package/src/functions/isValidDate.ts +0 -9
- package/src/functions/serializeJavascript.ts +0 -229
- package/src/index.d.ts +0 -19
- package/src/index.ts +0 -3
- package/src/rest/user/user.ts +0 -342
- package/src/services/base.ts +0 -187
- package/src/services/http/HttpBX.ts +0 -176
- package/src/services/http/HttpData.ts +0 -142
- package/src/services/http/base/HttpData.ts +0 -141
- package/src/services/http/base/base.ts +0 -40
- package/src/services/http/base/http.ts +0 -67
- package/src/services/http/http.ts +0 -182
- package/src/services/http/sessionKey.ts +0 -205
- package/src/services/map/base.ts +0 -8
- package/src/services/map/rest/user.ts +0 -82
- package/src/services/snack-bar/snack-bar.service.ts +0 -40
- package/src/services/snack-bar/toast-message/toast-message.component.html +0 -13
- package/src/services/snack-bar/toast-message/toast-message.component.scss +0 -53
- package/src/services/snack-bar/toast-message/toast-message.component.ts +0 -26
- package/src/services/vanilla/JSON.ts +0 -15
- package/src/services/vanilla/iframe.ts +0 -57
- package/src/services/vanilla/localStorage.ts +0 -42
- package/src/services/vanilla//321/201ookies.ts +0 -43
- package/src/store/auth.ts +0 -46
- package/src/store/users.ts +0 -88
- package/src/tsconfig.base.json +0 -6
- package/src/tsconfig.cjs.json +0 -10
- package/src/tsconfig.cjs.spec.json +0 -10
- package/src/tsconfig.esm.json +0 -9
- package/src/tsconfig.esm5.json +0 -11
- package/src/tsconfig.esm5.rollup.json +0 -8
- package/src/tsconfig.types.json +0 -14
- package/src/tsconfig.types.spec.json +0 -7
- package/src/typification/auth/OAuthBXParam.ts +0 -6
- package/src/typification/auth/application.ts +0 -8
- package/src/typification/auth/save.ts +0 -14
- package/src/typification/auth/urlData.ts +0 -4
- package/src/typification/rest/api-lib.ts +0 -18
- package/src/typification/rest/base/ApiPaginationBX.ts +0 -3
- package/src/typification/rest/base/OrderOptions.ts +0 -3
- package/src/typification/rest/base/YesNo.ts +0 -1
- package/src/typification/rest/base/fieldBXType.ts +0 -1
- package/src/typification/rest/base/filterGenerator.ts +0 -3
- package/src/typification/rest/base/httpAnswerBX.ts +0 -15
- package/src/typification/rest/batch/batchRequestParam.ts +0 -14
- package/src/typification/rest/lib.ts +0 -19
- package/src/typification/rest/settings.ts +0 -7
- package/src/typification/rest/support/param.ts +0 -8
- package/src/typification/rest/user/CustomUserFieldInfo.ts +0 -70
- package/src/typification/rest/user/UserFilterSearch.ts +0 -43
- package/src/typification/rest/user/get.ts +0 -17
- package/src/typification/rest/user/user.ts +0 -68
- package/src/typification/rest/user/userFilter.ts +0 -17
- package/tsconfig.json +0 -24
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Observable, throwError } from 'rxjs'
|
|
2
|
-
import { catchError } from 'rxjs/operators'
|
|
3
|
-
import { HttpParams } from '@angular/common/http'
|
|
4
|
-
import { iHttpParamSettings } from 'bx-rest/src/typification/rest/settings'
|
|
5
|
-
import { BaseHttp } from 'bx-rest/src/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
|
-
}
|
|
@@ -1,182 +0,0 @@
|
|
|
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 'bx-rest/src/services/snack-bar/snack-bar.service'
|
|
6
|
-
import SessionKeyServices from 'bx-rest/src/services/http/sessionKey'
|
|
7
|
-
import clone from 'just-clone'
|
|
8
|
-
import { iHttpParamSettings } from 'bx-rest/src/typification/rest/settings'
|
|
9
|
-
import {
|
|
10
|
-
iBatchRequestAnswer, iBatchRequestParam,
|
|
11
|
-
iBatchRequestParamArr,
|
|
12
|
-
iBatchRequestParamHttp, keyBatch
|
|
13
|
-
} from 'bx-rest/src/typification/rest/batch/batchRequestParam'
|
|
14
|
-
import flatten from 'just-flatten-it'
|
|
15
|
-
import { BaseHttpServices } from './base/http'
|
|
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
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core'
|
|
2
|
-
import Cookies from 'bx-rest/src/services/vanilla/сookies'
|
|
3
|
-
import { Store } from '@ngrx/store'
|
|
4
|
-
import saveApplicationAuth from 'bx-rest/src/typification/auth/save'
|
|
5
|
-
// import { environment as env } from 'bx-rest/src/environments/environment'
|
|
6
|
-
import { filter, Observable, of, Subscription, take } from 'rxjs'
|
|
7
|
-
import { ActivatedRoute, ParamMap } from '@angular/router'
|
|
8
|
-
import { saveAccessToken, saveApplicationAuthPath } from 'bx-rest/src/store/auth'
|
|
9
|
-
import { map } from 'rxjs/operators'
|
|
10
|
-
import { BaseServices } from 'bx-rest/src/services/base'
|
|
11
|
-
import { LocalStorageServices as LocalStorage } from 'bx-rest/src/services/vanilla/localStorage'
|
|
12
|
-
import { RestServices } from 'bx-rest/src/typification/rest/api-lib'
|
|
13
|
-
|
|
14
|
-
type IKeyAuth = 'sessid' | 'auth' | string
|
|
15
|
-
|
|
16
|
-
@Injectable({
|
|
17
|
-
providedIn: 'root'
|
|
18
|
-
})
|
|
19
|
-
export default class SessionKeyServices extends BaseServices {
|
|
20
|
-
|
|
21
|
-
authHave = false
|
|
22
|
-
authData$: Observable<saveApplicationAuth>
|
|
23
|
-
authData: saveApplicationAuth | undefined
|
|
24
|
-
subscribe = {
|
|
25
|
-
authData: new Subscription()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
constructor(
|
|
29
|
-
public store: Store<{ auth: saveApplicationAuth }>,
|
|
30
|
-
private route: ActivatedRoute,
|
|
31
|
-
public BxApiLib: RestServices,
|
|
32
|
-
) {
|
|
33
|
-
super()
|
|
34
|
-
this.authData$ = this.store.select('auth')
|
|
35
|
-
this.authData$.subscribe(authData => {
|
|
36
|
-
if ((authData && !authData.access_token.length) || !authData) {
|
|
37
|
-
// получаем токен по собственным каналом (в битриксе приложение trace:apps.trace)
|
|
38
|
-
window.addEventListener('message', (event: MessageEvent) => {
|
|
39
|
-
if (event.origin !== window.origin) { // проверяем что это не наше сообщение (с текущего приложения)
|
|
40
|
-
if (event.data && event.data.param) {
|
|
41
|
-
if (typeof event.data.param === 'string') {
|
|
42
|
-
event.data.param = JSON.parse(event.data.param)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let save: saveApplicationAuthPath = {}
|
|
46
|
-
|
|
47
|
-
if (event.data.param.access_token) {
|
|
48
|
-
let param = event.data.param;
|
|
49
|
-
save.access_token = event.data.param.access_token
|
|
50
|
-
save = {
|
|
51
|
-
access_token: (param.access_token) ? param.access_token : undefined,
|
|
52
|
-
client_endpoint: (param.client_endpoint) ? param.client_endpoint : undefined,
|
|
53
|
-
domain: (param.domain) ? param.domain : undefined,
|
|
54
|
-
expires: (param.expires) ? param.expires : undefined,
|
|
55
|
-
expires_in: (param.expires_in) ? param.expires_in : undefined,
|
|
56
|
-
member_id: (param.member_id) ? param.member_id : undefined,
|
|
57
|
-
refresh_token: (param.refresh_token) ? param.refresh_token : undefined,
|
|
58
|
-
scope: (param.scope) ? param.scope : undefined,
|
|
59
|
-
server_endpoint: (param.server_endpoint) ? param.server_endpoint : undefined,
|
|
60
|
-
status: (param.status) ? param.status : undefined,
|
|
61
|
-
user_id: (param.user_id) ? param.user_id : undefined,
|
|
62
|
-
type: (param.type) ? param.type : undefined,
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (Object.keys(save).length && save.access_token) {
|
|
67
|
-
this.store.dispatch(saveAccessToken(save))
|
|
68
|
-
this.subscribeAll()
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
this.subscribe.authData = this.route.queryParamMap
|
|
75
|
-
.pipe(
|
|
76
|
-
filter(param =>
|
|
77
|
-
param.has('AUTH_ID')
|
|
78
|
-
|| param.has('access_token')
|
|
79
|
-
|| param.has('REFRESH_ID')
|
|
80
|
-
|| param.has('DOMAIN')
|
|
81
|
-
)
|
|
82
|
-
)
|
|
83
|
-
.subscribe((param: ParamMap) => {
|
|
84
|
-
let save: saveApplicationAuthPath = {}
|
|
85
|
-
if (param.has('AUTH_ID') && !authData.access_token.length) {
|
|
86
|
-
const get = param.get('AUTH_ID')
|
|
87
|
-
if (get) {
|
|
88
|
-
Cookies.set('auth', get) // потом убрать
|
|
89
|
-
save.access_token = get
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (param.has('access_token') && !authData.access_token.length) {
|
|
94
|
-
const get = param.get('access_token')
|
|
95
|
-
if (get) {
|
|
96
|
-
Cookies.set('auth', get) // потом убрать
|
|
97
|
-
save.access_token = get
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (param.has('REFRESH_ID') && !authData.refresh_token.length) {
|
|
102
|
-
const get = param.get('REFRESH_ID')
|
|
103
|
-
if (get) {
|
|
104
|
-
save.refresh_token = get
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (param.has('DOMAIN') && !authData.domain.length) {
|
|
109
|
-
const get = param.get('DOMAIN')
|
|
110
|
-
if (get) {
|
|
111
|
-
save.domain = get
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (Object.keys(save).length && save.access_token) {
|
|
115
|
-
this.store.dispatch(saveAccessToken(save))
|
|
116
|
-
this.subscribeAll()
|
|
117
|
-
} else {
|
|
118
|
-
// если битрикс не шлёт нужные мне параметры на прямую
|
|
119
|
-
// просим их мне отдать так как описано это в документации
|
|
120
|
-
let f = () => {
|
|
121
|
-
if (this.BxApiLib.BX24) {
|
|
122
|
-
const initDate = this.BxApiLib.BX24.getAuth()
|
|
123
|
-
this.store.dispatch(saveAccessToken(initDate))
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
this.BxApiLib.init(f)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
})
|
|
131
|
-
} else if (this.getAuth().length) {
|
|
132
|
-
this.authHave = true
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this.authData = authData
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
subscribeAll() {
|
|
140
|
-
this.subscribe.authData.unsubscribe()
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getAuth(): string {
|
|
144
|
-
if ((<any>window).BX && (<any>window).BX.bitrix_sessid()) {
|
|
145
|
-
return (<any>window).BX.bitrix_sessid()
|
|
146
|
-
} else if (this.getSessid().length) {
|
|
147
|
-
let str = this.getSessid()
|
|
148
|
-
return (str) ? str : ''
|
|
149
|
-
} else {
|
|
150
|
-
return Cookies.get('auth')
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getKeyAuth(): IKeyAuth {
|
|
155
|
-
if ((<any>window).BX && (<any>window).BX.bitrix_sessid()
|
|
156
|
-
|| this.getSessid().length) {
|
|
157
|
-
return 'sessid'
|
|
158
|
-
} else {
|
|
159
|
-
return 'auth'
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
getSessid() {
|
|
164
|
-
const check = new URLSearchParams(document.location.search).get('sessid')
|
|
165
|
-
if (check) {
|
|
166
|
-
LocalStorage.set('sessid', check)
|
|
167
|
-
return check
|
|
168
|
-
} else if (LocalStorage.get('sessid')) {
|
|
169
|
-
return LocalStorage.get('sessid')
|
|
170
|
-
}
|
|
171
|
-
return ''
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
setAuthParams<T>(params: any): boolean {
|
|
175
|
-
const keyAuth = this.getKeyAuth()
|
|
176
|
-
if (params[keyAuth]) {
|
|
177
|
-
return true
|
|
178
|
-
} else if (keyAuth) {
|
|
179
|
-
params[keyAuth] = this.getAuth()
|
|
180
|
-
return true
|
|
181
|
-
}
|
|
182
|
-
return false
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
getAuthParams(): Observable<string | undefined> {
|
|
186
|
-
// if (env.production && !env.component) {
|
|
187
|
-
return this.authData$.pipe(
|
|
188
|
-
take(1),
|
|
189
|
-
map(v => (v) ? v.access_token : undefined)
|
|
190
|
-
)
|
|
191
|
-
// } else {
|
|
192
|
-
// return of(this.getAuth())
|
|
193
|
-
// }
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
getBaseUrl(): Observable<string | undefined> {
|
|
197
|
-
return this.authData$.pipe(
|
|
198
|
-
map(v => (v && v.domain) ? this.prepareBaseAddress(v.domain, 'b24.trace-studio.com') : undefined)
|
|
199
|
-
)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// getHomeUrl(): string {
|
|
203
|
-
// return env.urls.home
|
|
204
|
-
// }
|
|
205
|
-
}
|
package/src/services/map/base.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core'
|
|
2
|
-
import BaseMapServices from 'bx-rest/src/services/map/base'
|
|
3
|
-
import { iBXRestUser, iBXRestUserHttp } from 'bx-rest/src/typification/rest/user/user'
|
|
4
|
-
import clone from 'just-clone'
|
|
5
|
-
|
|
6
|
-
@Injectable({
|
|
7
|
-
providedIn: 'root'
|
|
8
|
-
})
|
|
9
|
-
export class BitrixApiUserMapServices extends BaseMapServices {
|
|
10
|
-
|
|
11
|
-
HttpToBX(user: iBXRestUserHttp): iBXRestUser {
|
|
12
|
-
let res: iBXRestUser = Object.assign(clone(user), {
|
|
13
|
-
ID: this.toNumber(user.ID),
|
|
14
|
-
IS_ONLINE: this.toBool(user.IS_ONLINE),
|
|
15
|
-
DATE_REGISTER: this.toDate(user.DATE_REGISTER),
|
|
16
|
-
PERSONAL_BIRTHDAY: this.toDate(user.PERSONAL_BIRTHDAY),
|
|
17
|
-
})
|
|
18
|
-
if (user.LAST_LOGIN) {
|
|
19
|
-
res.LAST_LOGIN = this.toDate(user.LAST_LOGIN)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return res
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
BXtoHttp(user: iBXRestUser): iBXRestUserHttp {
|
|
26
|
-
return Object.assign(clone(user), {
|
|
27
|
-
ID: this.toStr(user.ID),
|
|
28
|
-
IS_ONLINE: this.toBXYorN(user.IS_ONLINE),
|
|
29
|
-
DATE_REGISTER: this.getBXStrTime(user.DATE_REGISTER),
|
|
30
|
-
PERSONAL_BIRTHDAY: this.toStr(user.PERSONAL_BIRTHDAY),
|
|
31
|
-
LAST_LOGIN: this.toStr(user.LAST_LOGIN)
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
getFIO(user: iBXRestUser): string {
|
|
36
|
-
let res = ''
|
|
37
|
-
if (!user.LAST_NAME) {
|
|
38
|
-
const SECOND_NAME = (user.SECOND_NAME) ? user.SECOND_NAME : ''
|
|
39
|
-
const NAME = (user.NAME) ? user.NAME : ''
|
|
40
|
-
res = NAME + ' ' + SECOND_NAME
|
|
41
|
-
} else if (!user.NAME) {
|
|
42
|
-
res = user.LAST_NAME
|
|
43
|
-
} else if (!user.SECOND_NAME) {
|
|
44
|
-
res = user.LAST_NAME + ' ' + user.NAME
|
|
45
|
-
} else {
|
|
46
|
-
res = user.LAST_NAME + ' ' + user.NAME + ' ' + user.SECOND_NAME
|
|
47
|
-
}
|
|
48
|
-
return res.trim()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
getFI(user: iBXRestUser): string {
|
|
52
|
-
let res = ''
|
|
53
|
-
if (!user.LAST_NAME) {
|
|
54
|
-
const NAME = (user.NAME) ? user.NAME : ''
|
|
55
|
-
res = NAME
|
|
56
|
-
} else if (!user.NAME) {
|
|
57
|
-
res = user.LAST_NAME
|
|
58
|
-
} else {
|
|
59
|
-
res = user.LAST_NAME + ' ' + user.NAME
|
|
60
|
-
}
|
|
61
|
-
return res.trim()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getFIOShort(user: iBXRestUser): string {
|
|
65
|
-
let res = ''
|
|
66
|
-
if (!user.LAST_NAME) {
|
|
67
|
-
const SECOND_NAME = (user.SECOND_NAME) ? user.SECOND_NAME : ''
|
|
68
|
-
const NAME = (user.NAME) ? user.NAME : ''
|
|
69
|
-
res = NAME + ' ' + SECOND_NAME
|
|
70
|
-
} else if (!user.NAME) {
|
|
71
|
-
res = user.LAST_NAME
|
|
72
|
-
} else if (!user.SECOND_NAME) {
|
|
73
|
-
res = user.LAST_NAME + ' ' + user.NAME.charAt(0).toUpperCase() + '.'
|
|
74
|
-
} else {
|
|
75
|
-
res =
|
|
76
|
-
user.LAST_NAME + ' ' +
|
|
77
|
-
user.NAME.charAt(0).toUpperCase() + '.' +
|
|
78
|
-
user.SECOND_NAME.charAt(0).toUpperCase() + '.'
|
|
79
|
-
}
|
|
80
|
-
return res.trim()
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Сервис для вывода сообщений пользователю
|
|
3
|
-
* TODO: логирование
|
|
4
|
-
*/
|
|
5
|
-
import { Injectable } from '@angular/core'
|
|
6
|
-
import { ToastMessageComponent } from 'bx-rest/src/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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Component, inject, Inject, ViewEncapsulation } from '@angular/core'
|
|
2
|
-
import { MAT_SNACK_BAR_DATA, MatSnackBarRef } from '@angular/material/snack-bar'
|
|
3
|
-
|
|
4
|
-
@Component({
|
|
5
|
-
selector: 'app-view',
|
|
6
|
-
templateUrl: './toast-message.component.html',
|
|
7
|
-
styleUrls: ['./toast-message.component.scss'],
|
|
8
|
-
encapsulation: ViewEncapsulation.None,
|
|
9
|
-
})
|
|
10
|
-
export class ToastMessageComponent {
|
|
11
|
-
|
|
12
|
-
snackBarRef = inject(MatSnackBarRef)
|
|
13
|
-
|
|
14
|
-
constructor(@Inject(MAT_SNACK_BAR_DATA) public data: { message: string, type: 'error' | 'warning' | 'success' }) {
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getClass():string{
|
|
18
|
-
switch (this.data.type){
|
|
19
|
-
case 'error':
|
|
20
|
-
case 'warning':
|
|
21
|
-
case 'success':
|
|
22
|
-
return this.data.type + '-message';
|
|
23
|
-
}
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
}
|