Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 198eef70
authored
Aug 04, 2018
by
Aino Leppänen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rxjs update
1 parent
2266beb7
Pipeline
#79
failed
in 0 seconds
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
49 deletions
code/moya-angular/package.json
code/moya-angular/src/app/components/moya-locale/locale.service.ts
code/moya-angular/src/app/menu/left-menu/left-menu.component.ts
code/moya-angular/src/app/modules/old-moya/old-moya.component.ts
code/moya-angular/src/app/modules/viplist/info/info-viplist-page.component.ts
code/moya-angular/src/app/modules/viplist/viplist.service.ts
code/moya-angular/src/app/shared/interceptors/error.interceptor.ts
code/moya-angular/src/app/shared/services/cache.service.ts
code/moya-angular/src/app/shared/services/user.service.ts
code/moya-angular/package.json
View file @
198eef7
...
@@ -33,7 +33,6 @@
...
@@ -33,7 +33,6 @@
"core-js"
:
"^2.5.1"
,
"core-js"
:
"^2.5.1"
,
"ngx-bootstrap"
:
"^2.0.2"
,
"ngx-bootstrap"
:
"^2.0.2"
,
"rxjs"
:
"^6.2.2"
,
"rxjs"
:
"^6.2.2"
,
"rxjs-compat"
:
"^6.2.2"
,
"ts-helpers"
:
"^1.1.1"
,
"ts-helpers"
:
"^1.1.1"
,
"zone.js"
:
"^0.8.26"
"zone.js"
:
"^0.8.26"
},
},
...
...
code/moya-angular/src/app/components/moya-locale/locale.service.ts
View file @
198eef7
import
{
map
,
catchError
}
from
'rxjs/operators'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
Observable
}
from
'rxjs/Observable
'
;
import
{
Observable
,
of
}
from
'rxjs
'
;
import
{
MoyaLocale
}
from
'./moya-locale.model'
;
import
{
MoyaLocale
}
from
'./moya-locale.model'
;
import
{
MOYA_BASE_URL
}
from
'../../shared/tools/moya-rest.tool'
;
import
{
MOYA_BASE_URL
}
from
'../../shared/tools/moya-rest.tool'
;
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
HttpClient
}
from
'@angular/common/http'
;
import
'rxjs/add/operator/catch'
;
import
{
TranslateService
}
from
'@ngx-translate/core'
;
import
{
TranslateService
}
from
'@ngx-translate/core'
;
...
@@ -69,11 +71,11 @@ export class LocaleService {
...
@@ -69,11 +71,11 @@ export class LocaleService {
return
new
Observable
<
string
>
(
x
=>
x
.
next
(
this
.
selectedLocale
));
return
new
Observable
<
string
>
(
x
=>
x
.
next
(
this
.
selectedLocale
));
}
}
return
this
.
http
.
get
<
MoyaLocale
>
(
MOYA_BASE_URL
+
'/v3/locale/'
)
return
this
.
http
.
get
<
MoyaLocale
>
(
MOYA_BASE_URL
+
'/v3/locale/'
)
.
pipe
(
.
catch
(
x
=>
catchError
(
x
=>
Observable
.
of
({}
as
MoyaLocale
)
of
({}
as
MoyaLocale
)
)
)
,
.
map
(
locale
=>
{
map
(
locale
=>
{
if
(
locale
&&
locale
.
userLocale
)
{
if
(
locale
&&
locale
.
userLocale
)
{
return
this
.
selectLocale
(
locale
.
userLocale
);
return
this
.
selectLocale
(
locale
.
userLocale
);
}
}
...
@@ -89,7 +91,7 @@ export class LocaleService {
...
@@ -89,7 +91,7 @@ export class LocaleService {
}
}
return
this
.
selectLocale
(
DEFAULT_LOCALE
);
return
this
.
selectLocale
(
DEFAULT_LOCALE
);
});
})
,)
;
}
}
...
@@ -107,9 +109,9 @@ export class LocaleService {
...
@@ -107,9 +109,9 @@ export class LocaleService {
};
};
// let's save locale to database, if it fails, we save it into localstorage. No errors to show for user.
// let's save locale to database, if it fails, we save it into localstorage. No errors to show for user.
this
.
http
.
post
(
MOYA_BASE_URL
+
'/v3/locale/'
,
newLocale
).
catch
(
x
=>
{
this
.
http
.
post
(
MOYA_BASE_URL
+
'/v3/locale/'
,
newLocale
).
pipe
(
catchError
(
x
=>
{
localStorage
.
setItem
(
LOCALSTORAGE_NAME
,
locale
);
localStorage
.
setItem
(
LOCALSTORAGE_NAME
,
locale
);
return
'ok'
;
return
'ok'
;
}).
subscribe
();
})
)
.
subscribe
();
}
}
}
}
code/moya-angular/src/app/menu/left-menu/left-menu.component.ts
View file @
198eef7
import
{
filter
}
from
'rxjs/operators'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
MenuGroup
}
from
'../models/menu-group.model'
;
import
{
MenuGroup
}
from
'../models/menu-group.model'
;
import
{
MENU
}
from
'../defines/menu'
;
import
{
MENU
}
from
'../defines/menu'
;
...
@@ -33,7 +35,7 @@ export class LeftMenuComponent {
...
@@ -33,7 +35,7 @@ export class LeftMenuComponent {
constructor
(
private
route
:
Router
)
{
constructor
(
private
route
:
Router
)
{
route
.
events
.
filter
(
e
=>
e
instanceof
RouterEvent
).
subscribe
(
event
=>
{
route
.
events
.
pipe
(
filter
(
e
=>
e
instanceof
RouterEvent
)
).
subscribe
(
event
=>
{
const
revent
=
event
as
RouterEvent
;
const
revent
=
event
as
RouterEvent
;
...
...
code/moya-angular/src/app/modules/old-moya/old-moya.component.ts
View file @
198eef7
import
{
map
}
from
'rxjs/operators'
;
import
{
Component
,
OnInit
,
ViewChild
,
ElementRef
}
from
'@angular/core'
;
import
{
Component
,
OnInit
,
ViewChild
,
ElementRef
}
from
'@angular/core'
;
import
{
Location
,
LocationStrategy
,
HashLocationStrategy
,
PathLocationStrategy
}
from
'@angular/common'
;
import
{
Location
,
LocationStrategy
,
HashLocationStrategy
,
PathLocationStrategy
}
from
'@angular/common'
;
import
{
NavigationExtras
,
ActivatedRoute
,
Router
}
from
'@angular/router'
;
import
{
NavigationExtras
,
ActivatedRoute
,
Router
}
from
'@angular/router'
;
...
@@ -22,7 +24,7 @@ export class OldMoyaComponent implements OnInit {
...
@@ -22,7 +24,7 @@ export class OldMoyaComponent implements OnInit {
constructor
(
private
location
:
Location
,
private
route
:
ActivatedRoute
)
{
constructor
(
private
location
:
Location
,
private
route
:
ActivatedRoute
)
{
route
.
queryParamMap
.
map
(
a
=>
a
.
get
(
'p'
)).
subscribe
(
x
=>
{
route
.
queryParamMap
.
pipe
(
map
(
a
=>
a
.
get
(
'p'
)
)).
subscribe
(
x
=>
{
console
.
log
(
x
);
console
.
log
(
x
);
if
(
x
)
{
if
(
x
)
{
this
.
frameUrl
=
'/MoyaWeb/'
+
x
.
replace
(
'::'
,
'?'
);
this
.
frameUrl
=
'/MoyaWeb/'
+
x
.
replace
(
'::'
,
'?'
);
...
...
code/moya-angular/src/app/modules/viplist/info/info-viplist-page.component.ts
View file @
198eef7
import
{
Component
,
NgZone
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
NgZone
,
OnInit
}
from
'@angular/core'
;
import
{
Observable
}
from
'rxjs
/Observable
'
;
import
{
Observable
}
from
'rxjs'
;
import
{
Vip
}
from
'../models/vip.model'
;
import
{
Vip
}
from
'../models/vip.model'
;
import
{
ViplistService
}
from
'../viplist.service'
;
import
{
ViplistService
}
from
'../viplist.service'
;
import
{
TranslatePipe
}
from
'@ngx-translate/core'
;
import
{
TranslatePipe
}
from
'@ngx-translate/core'
;
...
...
code/moya-angular/src/app/modules/viplist/viplist.service.ts
View file @
198eef7
import
{
forkJoin
as
observableForkJoin
,
Observable
}
from
'rxjs'
;
import
{
first
,
switchMap
,
map
}
from
'rxjs/operators'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
Vip
}
from
'./models/vip.model'
;
import
{
Vip
}
from
'./models/vip.model'
;
import
{
User
}
from
'../../shared/models/user.model'
;
import
{
User
}
from
'../../shared/models/user.model'
;
import
{
UserService
}
from
'../../shared/services/user.service'
;
import
{
UserService
}
from
'../../shared/services/user.service'
;
import
{
Observable
}
from
'rxjs/Observable'
;
import
'rxjs/add/operator/map'
;
import
'rxjs/add/operator/switchMap'
;
import
'rxjs/add/observable/forkJoin'
;
import
'rxjs/add/operator/first'
;
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
MOYA_BASE_URL
}
from
'../../shared/tools/moya-rest.tool'
;
import
{
MOYA_BASE_URL
}
from
'../../shared/tools/moya-rest.tool'
;
...
@@ -25,12 +28,12 @@ export class ViplistService {
...
@@ -25,12 +28,12 @@ export class ViplistService {
public
get
(
searchString
?:
string
):
Observable
<
Array
<
Vip
>>
{
public
get
(
searchString
?:
string
):
Observable
<
Array
<
Vip
>>
{
if
(
!
searchString
)
{
if
(
!
searchString
)
{
return
this
.
http
.
get
(
MOYA_BASE_URL
+
'v3/vip/all'
)
return
this
.
http
.
get
(
MOYA_BASE_URL
+
'v3/vip/all'
)
.
pipe
(
.
switchMap
(
res
=>
Observable
.
forkJoin
(...(
res
as
Array
<
any
>
).
map
(
apiRow
=>
this
.
hostPopulator
(
apiRow
))));
switchMap
(
res
=>
observableForkJoin
(...(
res
as
Array
<
any
>
).
map
(
apiRow
=>
this
.
hostPopulator
(
apiRow
)
))));
}
}
return
this
.
http
.
get
(
MOYA_BASE_URL
+
'v3/vip/search/'
+
searchString
)
return
this
.
http
.
get
(
MOYA_BASE_URL
+
'v3/vip/search/'
+
searchString
)
.
pipe
(
.
switchMap
(
v
=>
Observable
.
forkJoin
(...(
v
as
Array
<
any
>
).
map
(
x
=>
this
.
hostPopulator
(
x
))));
switchMap
(
v
=>
observableForkJoin
(...(
v
as
Array
<
any
>
).
map
(
x
=>
this
.
hostPopulator
(
x
)
))));
}
}
...
@@ -46,8 +49,8 @@ export class ViplistService {
...
@@ -46,8 +49,8 @@ export class ViplistService {
throw
new
Error
(
'TODO: errori, tyhmä vippi'
);
throw
new
Error
(
'TODO: errori, tyhmä vippi'
);
}
}
const
res
:
any
=
await
this
.
http
.
delete
(
MOYA_BASE_URL
+
'v3/vip/'
+
vip
.
id
)
const
res
:
any
=
await
this
.
http
.
delete
(
MOYA_BASE_URL
+
'v3/vip/'
+
vip
.
id
)
.
pipe
(
.
first
(
)
first
()
)
.
toPromise
();
.
toPromise
();
return
res
.
ok
;
return
res
.
ok
;
...
@@ -55,19 +58,19 @@ export class ViplistService {
...
@@ -55,19 +58,19 @@ export class ViplistService {
public
getWithId
(
id
:
number
):
Observable
<
Vip
>
{
public
getWithId
(
id
:
number
):
Observable
<
Vip
>
{
return
this
.
http
.
get
(
MOYA_BASE_URL
+
'v3/vip/'
+
id
).
map
(
x
=>
x
as
Vip
);
return
this
.
http
.
get
(
MOYA_BASE_URL
+
'v3/vip/'
+
id
).
pipe
(
map
(
x
=>
x
as
Vip
)
);
}
}
public
create
(
vip
:
Vip
):
Observable
<
Vip
>
{
public
create
(
vip
:
Vip
):
Observable
<
Vip
>
{
return
this
.
http
.
post
(
MOYA_BASE_URL
+
'v3/vip/create'
,
vip
).
map
(
x
=>
x
as
Vip
);
return
this
.
http
.
post
(
MOYA_BASE_URL
+
'v3/vip/create'
,
vip
).
pipe
(
map
(
x
=>
x
as
Vip
)
);
}
}
private
hostPopulator
(
rawVip
:
any
):
Observable
<
Vip
>
{
private
hostPopulator
(
rawVip
:
any
):
Observable
<
Vip
>
{
return
this
.
userService
.
get
(
rawVip
.
hostId
)
return
this
.
userService
.
get
(
rawVip
.
hostId
)
.
pipe
(
.
map
((
u
:
User
)
=>
{
rawVip
.
host
=
u
;
return
<
Vip
>
rawVip
;
}).
map
(
x
=>
x
as
Vip
);
map
((
u
:
User
)
=>
{
rawVip
.
host
=
u
;
return
<
Vip
>
rawVip
;
}),
map
(
x
=>
x
as
Vip
),
);
}
}
...
...
code/moya-angular/src/app/shared/interceptors/error.interceptor.ts
View file @
198eef7
import
{
throwError
as
observableThrowError
,
Observable
}
from
'rxjs'
;
import
{
catchError
}
from
'rxjs/operators'
;
import
{
HttpEvent
,
HttpEventType
,
HttpHandler
,
HttpInterceptor
,
HttpRequest
,
HttpResponse
}
from
'@angular/common/http'
;
import
{
HttpEvent
,
HttpEventType
,
HttpHandler
,
HttpInterceptor
,
HttpRequest
,
HttpResponse
}
from
'@angular/common/http'
;
import
{
Observable
}
from
'rxjs/Observable'
;
import
'rxjs/add/operator/catch'
;
export
class
ErrorInterceptor
implements
HttpInterceptor
{
export
class
ErrorInterceptor
implements
HttpInterceptor
{
intercept
(
req
:
HttpRequest
<
any
>
,
next
:
HttpHandler
):
Observable
<
HttpEvent
<
HttpEventType
.
Response
>>
{
intercept
(
req
:
HttpRequest
<
any
>
,
next
:
HttpHandler
):
Observable
<
HttpEvent
<
HttpEventType
.
Response
>>
{
return
next
.
handle
(
req
).
catch
(
this
.
handleException
);
return
next
.
handle
(
req
).
pipe
(
catchError
(
this
.
handleException
)
);
}
}
...
@@ -17,6 +20,6 @@ export class ErrorInterceptor implements HttpInterceptor {
...
@@ -17,6 +20,6 @@ export class ErrorInterceptor implements HttpInterceptor {
// TODO: add handlers to 403's and other "not logged in" or "invalid permissions"
// TODO: add handlers to 403's and other "not logged in" or "invalid permissions"
// -statuscodes, and route them using some nice global parameter
// -statuscodes, and route them using some nice global parameter
return
Observable
.
throw
(
error
);
return
observableThrowError
(
error
);
}
}
}
}
code/moya-angular/src/app/shared/services/cache.service.ts
View file @
198eef7
import
{
of
as
observableOf
,
timer
as
observableTimer
,
Observable
,
forkJoin
,
Subscription
}
from
'rxjs'
;
import
{
refCount
,
publishLast
,
tap
}
from
'rxjs/operators'
;
import
{
Injectable
,
NgZone
}
from
'@angular/core'
;
import
{
Injectable
,
NgZone
}
from
'@angular/core'
;
import
{
Observable
}
from
'rxjs/Observable'
;
import
'rxjs/add/observable/timer'
;
import
{
forkJoin
}
from
'rxjs/observable/forkJoin'
;
import
'rxjs/add/operator/do'
;
import
'rxjs/add/operator/publishLast'
;
import
'rxjs/add/observable/of'
;
import
{
Subscription
}
from
'rxjs/Subscription'
;
const
DEFAULT_EXPIRE_MS
=
300000
;
// 5min
const
DEFAULT_EXPIRE_MS
=
300000
;
// 5min
...
@@ -53,7 +50,7 @@ export class CacheService {
...
@@ -53,7 +50,7 @@ export class CacheService {
constructor
(
private
zone
:
NgZone
)
{
constructor
(
private
zone
:
NgZone
)
{
this
.
cache
=
new
Map
<
string
,
CachedItem
>
();
this
.
cache
=
new
Map
<
string
,
CachedItem
>
();
this
.
timerObservable
=
Observable
.
t
imer
(
30000
,
30000
);
// afther 0.5min, every 0.5min.
this
.
timerObservable
=
observableT
imer
(
30000
,
30000
);
// afther 0.5min, every 0.5min.
}
}
...
@@ -88,9 +85,9 @@ export class CacheService {
...
@@ -88,9 +85,9 @@ export class CacheService {
console
.
log
(
cacheName
,
' not in cache'
);
console
.
log
(
cacheName
,
' not in cache'
);
const
hotSource
=
source
const
hotSource
=
source
.
pipe
(
.
do
(
val
=>
this
.
cache
.
set
(
cacheName
,
new
CachedItem
(
moduleName
,
cachePath
,
val
)))
tap
(
val
=>
this
.
cache
.
set
(
cacheName
,
new
CachedItem
(
moduleName
,
cachePath
,
val
))),
.
publishLast
().
refCount
(
);
publishLast
(),
refCount
(),
);
this
.
cache
.
set
(
cacheName
,
new
CachedItem
(
moduleName
,
cachePath
,
hotSource
,
true
));
this
.
cache
.
set
(
cacheName
,
new
CachedItem
(
moduleName
,
cachePath
,
hotSource
,
true
));
...
@@ -112,7 +109,7 @@ export class CacheService {
...
@@ -112,7 +109,7 @@ export class CacheService {
console
.
log
(
cacheName
,
' value in cache'
);
console
.
log
(
cacheName
,
' value in cache'
);
this
.
checkCleanTimer
();
this
.
checkCleanTimer
();
return
Observable
.
o
f
(
cacheItem
.
value
);
return
observableO
f
(
cacheItem
.
value
);
}
}
...
...
code/moya-angular/src/app/shared/services/user.service.ts
View file @
198eef7
import
{
tap
}
from
'rxjs/operators'
;
import
{
throwError
as
observableThrowError
,
Observable
}
from
'rxjs'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
User
}
from
'../models/user.model'
;
import
{
User
}
from
'../models/user.model'
;
import
{
CacheService
}
from
'./cache.service'
;
import
{
CacheService
}
from
'./cache.service'
;
import
{
Observable
}
from
'rxjs/Observable'
;
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
MOYA_BASE_URL
}
from
'../tools/moya-rest.tool'
;
import
{
MOYA_BASE_URL
}
from
'../tools/moya-rest.tool'
;
...
@@ -14,14 +15,13 @@ export class UserService {
...
@@ -14,14 +15,13 @@ export class UserService {
public
get
(
id
:
number
):
Observable
<
User
>
{
public
get
(
id
:
number
):
Observable
<
User
>
{
if
(
!
id
||
id
<
0
)
{
if
(
!
id
||
id
<
0
)
{
return
Observable
.
throw
(
'There should be userid'
);
return
observableThrowError
(
'There should be userid'
);
}
}
const
path
=
MOYA_BASE_URL
+
'v2/user/'
+
id
;
const
path
=
MOYA_BASE_URL
+
'v2/user/'
+
id
;
return
this
.
cacheService
.
cacheObservable
(
'moya:UserService'
,
path
,
return
this
.
cacheService
.
cacheObservable
(
'moya:UserService'
,
path
,
this
.
http
.
get
<
User
>
(
path
)
this
.
http
.
get
<
User
>
(
path
).
pipe
(
tap
(
v
=>
{
console
.
log
(
'getting user outside of cache'
,
path
);
})));
.
do
(
v
=>
{
console
.
log
(
'getting user outside of cache'
,
path
);
}));
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment