Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Linnea Samila
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4936c494
authored
Feb 22, 2018
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
1 parent
c87cf192
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
670 additions
and
17 deletions
code/moya-angular/package.json
code/moya-angular/src/app/app.module.ts
code/moya-angular/src/app/menu/admin-menu/admin-menu.component.ts
code/moya-angular/src/app/menu/defines/menu.ts
code/moya-angular/src/app/menu/info-menu/info-menu.component.ts
code/moya-angular/src/app/menu/left-menu/left-menu.component.ts
code/moya-angular/src/app/models/menu-group.model.ts → code/moya-angular/src/app/menu/models/menu-group.model.ts
code/moya-angular/src/app/models/menu-item.model.ts → code/moya-angular/src/app/menu/models/menu-item.model.ts
code/moya-angular/src/app/menu/user-menu/user-menu.component.ts
code/moya-angular/src/app/moya-rest/index.ts
code/moya-angular/src/app/moya-rest/moya-rest.module.ts
code/moya-angular/src/app/shared/models/user.model.ts
code/moya-angular/src/app/shared/models/vip-product-delivery.model.ts
code/moya-angular/src/app/shared/models/vip-product.model.ts
code/moya-angular/src/app/shared/models/vip.model.ts
code/moya-angular/src/app/shared/services/cache.service.spec.ts
code/moya-angular/src/app/shared/services/cache.service.ts
code/moya-angular/src/app/shared/services/moya-rest.service.spec.ts
code/moya-angular/src/app/shared/services/moya-rest.service.ts
code/moya-angular/src/app/shared/services/user.service.spec.ts
code/moya-angular/src/app/shared/services/user.service.ts
code/moya-angular/src/app/shared/services/viplist.service.spec.ts
code/moya-angular/src/app/shared/services/viplist.service.ts
code/moya-angular/src/app/viplist/viplist.component.ts
code/moya-angular/src/tsconfig.json
code/moya-angular/package.json
View file @
4936c49
...
@@ -24,10 +24,9 @@
...
@@ -24,10 +24,9 @@
"@angular/platform-browser-dynamic"
:
"^5.2.4"
,
"@angular/platform-browser-dynamic"
:
"^5.2.4"
,
"@angular/platform-server"
:
"^5.2.4"
,
"@angular/platform-server"
:
"^5.2.4"
,
"@angular/router"
:
"^5.2.4"
,
"@angular/router"
:
"^5.2.4"
,
"bootstrap"
:
"^4.0.0
-beta
"
,
"bootstrap"
:
"^4.0.0"
,
"core-js"
:
"^2.5.1"
,
"core-js"
:
"^2.5.1"
,
"moya-angular-common"
:
"file:../moya-angular-common/src"
,
"ngx-bootstrap"
:
"^2.0.2"
,
"ng2-bootstrap"
:
"^1.3.3"
,
"rxjs"
:
"^5.4.3"
,
"rxjs"
:
"^5.4.3"
,
"ts-helpers"
:
"^1.1.1"
,
"ts-helpers"
:
"^1.1.1"
,
"zone.js"
:
"^0.8.19"
"zone.js"
:
"^0.8.19"
...
@@ -50,7 +49,7 @@
...
@@ -50,7 +49,7 @@
"protractor"
:
"^5.1.2"
,
"protractor"
:
"^5.1.2"
,
"raw-loader"
:
"^0.5.1"
,
"raw-loader"
:
"^0.5.1"
,
"sass-loader"
:
"^6.0.6"
,
"sass-loader"
:
"^6.0.6"
,
"ts-node"
:
"
4.1
.0"
,
"ts-node"
:
"
5.0
.0"
,
"tslint"
:
"^5.9.1"
,
"tslint"
:
"^5.9.1"
,
"typescript"
:
"^2.5.3"
"typescript"
:
"^2.5.3"
}
}
...
...
code/moya-angular/src/app/app.module.ts
View file @
4936c49
...
@@ -4,8 +4,8 @@ import {FormsModule} from '@angular/forms';
...
@@ -4,8 +4,8 @@ import {FormsModule} from '@angular/forms';
import
{
AppComponent
}
from
'./app.component'
;
import
{
AppComponent
}
from
'./app.component'
;
import
{
ViplistComponent
}
from
'./viplist/viplist.component'
;
import
{
ViplistComponent
}
from
'./viplist/viplist.component'
;
import
{
AlertModule
}
from
'ng
2
-bootstrap'
;
import
{
AlertModule
}
from
'ng
x
-bootstrap'
;
import
{
MoyaRestModule
}
from
'moya-angular-common'
;
import
{
RouterModule
,
Routes
}
from
'@angular/router'
;
import
{
RouterModule
,
Routes
}
from
'@angular/router'
;
import
{
OldMoyaComponent
}
from
'./old-moya/old-moya.component'
;
import
{
OldMoyaComponent
}
from
'./old-moya/old-moya.component'
;
...
@@ -22,9 +22,10 @@ import {AdminComponent} from './admin/admin.component';
...
@@ -22,9 +22,10 @@ import {AdminComponent} from './admin/admin.component';
import
{
I18nPipe
}
from
'./pipes/i18n.pipe'
;
import
{
I18nPipe
}
from
'./pipes/i18n.pipe'
;
import
{
HttpClientModule
,
HttpHandler
}
from
'@angular/common/http'
;
import
{
HttpClientModule
,
HttpHandler
}
from
'@angular/common/http'
;
import
{
HttpModule
}
from
'@angular/http'
;
import
{
HttpModule
}
from
'@angular/http'
;
import
{
CacheService
}
from
"moya-angular-common"
;
import
{
StaticInjector
}
from
"@angular/core/src/di/injector"
;
import
{
StaticInjector
}
from
"@angular/core/src/di/injector"
;
import
{
CommonModule
}
from
"@angular/common"
;
import
{
CommonModule
}
from
"@angular/common"
;
import
{
CacheService
}
from
"./shared/services/cache.service"
;
import
{
MoyaRestModule
}
from
"./moya-rest"
;
const
appRoutes
:
Routes
=
[
const
appRoutes
:
Routes
=
[
{
{
...
@@ -85,8 +86,7 @@ const appRoutes: Routes = [
...
@@ -85,8 +86,7 @@ const appRoutes: Routes = [
//MoyaRestModule.forRoot(),
//MoyaRestModule.forRoot(),
RouterModule
.
forRoot
(
appRoutes
)
RouterModule
.
forRoot
(
appRoutes
)
],
],
providers
:
[
CacheService
,
providers
:
[
CacheService
],
{
provide
:
Injector
,
useFactory
:
()
=>
Injector
.
create
({
providers
:
[]})
}],
bootstrap
:
[
AppComponent
]
bootstrap
:
[
AppComponent
]
})
})
export
class
AppModule
{
export
class
AppModule
{
...
...
code/moya-angular/src/app/menu/admin-menu/admin-menu.component.ts
View file @
4936c49
import
{
Component
}
from
'@angular/core'
;
import
{
Component
}
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'
;
@
Component
({
@
Component
({
...
...
code/moya-angular/src/app/menu/defines/menu.ts
View file @
4936c49
import
{
MenuGroup
}
from
'../
../
models/menu-group.model'
;
import
{
MenuGroup
}
from
'../models/menu-group.model'
;
/**
/**
* Created by tuukka on 13/05/17.
* Created by tuukka on 13/05/17.
*/
*/
...
...
code/moya-angular/src/app/menu/info-menu/info-menu.component.ts
View file @
4936c49
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'
;
@
Component
({
@
Component
({
...
...
code/moya-angular/src/app/menu/left-menu/left-menu.component.ts
View file @
4936c49
import
{
Component
,
OnInit
,
Input
}
from
'@angular/core'
;
import
{
Component
,
OnInit
,
Input
}
from
'@angular/core'
;
import
{
MenuGroup
}
from
'../
../
models/menu-group.model'
;
import
{
MenuGroup
}
from
'../models/menu-group.model'
;
@
Component
({
@
Component
({
selector
:
'left-menu'
,
selector
:
'left-menu'
,
...
...
code/moya-angular/src/app/models/menu-group.model.ts
→
code/moya-angular/src/app/m
enu/m
odels/menu-group.model.ts
View file @
4936c49
File moved
code/moya-angular/src/app/models/menu-item.model.ts
→
code/moya-angular/src/app/m
enu/m
odels/menu-item.model.ts
View file @
4936c49
File moved
code/moya-angular/src/app/menu/user-menu/user-menu.component.ts
View file @
4936c49
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'
;
@
Component
({
@
Component
({
...
...
code/moya-angular/src/app/moya-rest/index.ts
0 → 100644
View file @
4936c49
export
*
from
"./moya-rest.module"
code/moya-angular/src/app/moya-rest/moya-rest.module.ts
0 → 100644
View file @
4936c49
import
{
NgModule
,
ModuleWithProviders
,
NgZone
,
Injector
}
from
'@angular/core'
;
import
{
CommonModule
}
from
'@angular/common'
;
import
{
MoyaRestService
}
from
"../shared/services/moya-rest.service"
;
import
{
ViplistService
}
from
"../shared/services/viplist.service"
;
import
{
CacheService
}
from
"../shared/services/cache.service"
;
import
{
UserService
}
from
"../shared/services/user.service"
;
import
{
HttpClientModule
}
from
"@angular/common/http"
;
import
{
HttpModule
}
from
"@angular/http"
;
export
*
from
"../shared/services/moya-rest.service"
;
export
*
from
"../shared/services/viplist.service"
;
export
*
from
"../shared/services/cache.service"
;
export
*
from
"../shared/services/user.service"
;
export
*
from
"../shared/models/user.model"
;
export
*
from
"../shared/models/vip.model"
;
export
*
from
"../shared/models/vip-product.model"
;
export
*
from
"../shared/models/vip-product-delivery.model"
;
@
NgModule
({
imports
:
[
CommonModule
,
HttpClientModule
],
declarations
:
[
],
providers
:
[
MoyaRestService
,
ViplistService
,
CacheService
,
UserService
,
HttpClientModule
/*{ provide: NgZone, useFactory: () => new NgZone({}) },
{ provide: Injector, useFactory: () => Injector.create({providers: []}) } */
],
exports
:
[
],
})
export
class
MoyaRestModule
{
/*
static forRoot(): ModuleWithProviders {
return {
ngModule: MoyaRestModule,
providers: [
MoyaRestService,
ViplistService,
CacheService,
UserService,
HttpClientModule
/*{ provide: NgZone, useFactory: () => new NgZone({}) },
{ provide: Injector, useFactory: () => Injector.create({providers: []}) }
]
};
}*/
}
code/moya-angular/src/app/shared/models/user.model.ts
0 → 100644
View file @
4936c49
/**
* Created by tuukka on 15/02/17.
*/
// vim magic: %s/^\s*\w\+\s\+\(\w\+\)\s\+\(\w\+\)\s*.*;$/ \2: \L\1;/
export
enum
UserGender
{
MALE
,
FEMALE
,
UNSPECIFIED
}
export
class
User
{
nick
:
string
;
login
:
string
;
eventuserId
:
number
;
userId
:
number
;
firstname
:
string
;
lastname
:
string
;
password
:
string
;
birthday
:
Date
;
gender
:
UserGender
;
phoneNumber
:
string
;
email
:
string
;
streetAddress
:
string
;
zipCode
:
string
;
postOffice
:
string
;
constructor
()
{
}
}
code/moya-angular/src/app/shared/models/vip-product-delivery.model.ts
0 → 100644
View file @
4936c49
/**
* Created by tuukka on 04/02/17.
*/
export
class
VipProductDelivery
{
/*
public Integer id;
public Integer delivererId;
public BigDecimal quantity;
public Date deliveryTime;
public String notes;
*/
id
:
number
;
delivererId
:
number
;
quantity
:
number
;
deliveryTime
:
Date
;
notes
:
string
;
constructor
()
{}
}
code/moya-angular/src/app/shared/models/vip-product.model.ts
0 → 100644
View file @
4936c49
import
{
VipProductDelivery
}
from
"./vip-product-delivery.model"
;
/**
* Created by tuukka on 04/02/17.
*/
export
class
VipProduct
{
/*
public Integer id;
public String name;
public Integer productId;
public String notes;
public BigDecimal quantity;
public BigDecimal delivered;
public List<VipProductDeliveryPojo> deliveries = new ArrayList<>();
*/
id
:
number
;
name
:
string
;
productId
:
number
;
notes
:
string
;
quantity
:
number
;
delivered
:
number
;
deliveries
:
VipProductDelivery
[];
constructor
()
{}
}
code/moya-angular/src/app/shared/models/vip.model.ts
0 → 100644
View file @
4936c49
import
{
VipProduct
}
from
"./vip-product.model"
;
import
{
User
}
from
"./user.model"
;
/**
* Created by tuukka on 04/02/17.
*/
export
class
Vip
{
/*
public Integer id;
public String description;
public String shortdescr;
public Date created;
public Integer eventuserId;
public Integer creatorId;
public Integer hostId;
public List<VipProductPojo> products = new ArrayList<>();
*/
id
:
number
;
description
:
string
;
shortdescr
:
string
;
created
:
Date
;
eventuserId
:
number
;
creatorId
:
number
;
host
:
User
;
products
:
VipProduct
[];
constructor
()
{
}
}
code/moya-angular/src/app/shared/services/cache.service.spec.ts
0 → 100644
View file @
4936c49
/* tslint:disable:no-unused-variable */
import
{
TestBed
,
async
,
inject
}
from
'@angular/core/testing'
;
import
{
CacheService
}
from
'./cache.service'
;
describe
(
'CacheService'
,
()
=>
{
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
providers
:
[
CacheService
]
});
});
it
(
'should ...'
,
inject
([
CacheService
],
(
service
:
CacheService
)
=>
{
expect
(
service
).
toBeTruthy
();
}));
});
code/moya-angular/src/app/shared/services/cache.service.ts
0 → 100644
View file @
4936c49
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
class
CachedItem
{
moduleName
:
string
;
path
:
string
;
value
:
any
;
expires
:
Date
;
isObservable
:
boolean
;
constructor
(
moduleName
:
string
,
path
:
string
,
value
:
any
,
isObservable
?
:
boolean
)
{
this
.
moduleName
=
moduleName
;
this
.
path
=
path
;
this
.
value
=
value
;
this
.
expires
=
new
Date
();
this
.
expires
.
setTime
(
Date
.
now
()
+
DEFAULT_EXPIRE_MS
);
this
.
isObservable
=
isObservable
;
}
public
isExpired
():
boolean
{
return
this
.
expires
.
getTime
()
<
Date
.
now
();
}
}
/**
* Basic cacheService.
*
* First this was part of moyaRestService, but I thinked that if cache is too easy to use, someone will kill this application with it.
* So let's make it litlebit harder
*/
@
Injectable
()
export
class
CacheService
{
private
timerSubscription
:
Subscription
;
private
timerObservable
:
Observable
<
any
>
;
private
cache
:
Map
<
string
,
CachedItem
>
;
// TODO: timed clearup for cache to save memory
constructor
(
private
zone
:
NgZone
)
{
this
.
cache
=
new
Map
<
string
,
CachedItem
>
();
this
.
timerObservable
=
Observable
.
timer
(
30000
,
30000
);
// afther 0.5min, every 0.5min.
}
/**
* This will return observable with value from cache, or cache value from your observable and return it in observable.
*
* example: return cacheService.cacheObservable("mymodule",<url>, http.get(<url>).map(v => v.json()));
*
* @param moduleName
* @param cachePath
* @param source: {Observable<any>} Observable where the values, which are cached, is coming from
* @return {Observable<any>}: if value is in cache, this is observable made from this value. Otherwise this is source observable.
*/
public
cacheObservable
(
moduleName
:
string
,
cachePath
:
string
,
source
:
Observable
<
any
>
):
Observable
<
any
>
{
let
cacheName
=
this
.
generateCachename
(
moduleName
,
cachePath
);
if
(
this
.
cache
.
has
(
cacheName
)
&&
this
.
cache
.
get
(
cacheName
).
expires
.
getTime
()
<
Date
.
now
())
{
console
.
log
(
cacheName
,
" Expired version in cache"
);
this
.
cache
.
delete
(
cacheName
);
}
if
(
!
this
.
cache
.
has
(
cacheName
))
{
/*
not in cache, let's change source to hot -observable, and return one instance from it
problem is, that before this observable is runned, there can be queries for this value from cache.
So, let's change this to hot-observable, and put that hot-observable into the cache.
And in first run, we change this hot observable to it's value.
Javascript is asynchronous, so there is no need to worry some weird things that could happen in multithreaded languages.
*/
console
.
log
(
cacheName
,
" not in cache"
);
let
hotSource
=
source
.
do
(
val
=>
this
.
cache
.
set
(
cacheName
,
new
CachedItem
(
moduleName
,
cachePath
,
val
)))
.
publishLast
().
refCount
();
this
.
cache
.
set
(
cacheName
,
new
CachedItem
(
moduleName
,
cachePath
,
hotSource
,
true
));
this
.
checkCleanTimer
();
return
hotSource
;
}
let
cacheItem
=
this
.
cache
.
get
(
cacheName
);
// if value is hotObservable, return it, otherwise create observable from value
if
(
cacheItem
.
isObservable
)
{
console
.
log
(
cacheName
,
" hot observable in cache "
);
return
cacheItem
.
value
;
}
console
.
log
(
cacheName
,
" value in cache"
);
this
.
checkCleanTimer
();
return
Observable
.
of
(
cacheItem
.
value
);
}
public
clean
():
void
{
this
.
cache
.
clear
();
this
.
checkCleanTimer
();
}
public
cleanExpired
():
void
{
this
.
cache
.
forEach
((
v
,
k
)
=>
{
if
(
v
.
isExpired
())
{
console
.
log
(
k
,
" Cache expired"
);
this
.
cache
.
delete
(
k
);
}});
this
.
checkCleanTimer
();
}
private
checkCleanTimer
()
{
if
(
this
.
cache
.
size
>
0
)
{
if
(
!
this
.
timerSubscription
)
{
console
.
log
(
"adding clearing timer"
);
this
.
zone
.
runOutsideAngular
(()
=>
{
this
.
timerSubscription
=
this
.
timerObservable
.
subscribe
(
v
=>
{
this
.
cleanExpired
();
});
});
}
}
else
{
if
(
this
.
timerSubscription
)
{
console
.
log
(
"removing clearing timer"
);
this
.
timerSubscription
.
unsubscribe
();
}
}
}
/**
*
* @param moduleName
* @param cachePath
* @param value
*/
private
set
(
moduleName
:
string
,
cachePath
:
string
,
value
:
any
):
void
{
let
cacheName
=
this
.
generateCachename
(
moduleName
,
cachePath
);
this
.
cache
.
set
(
cacheName
,
new
CachedItem
(
moduleName
,
cachePath
,
value
));
}
/**
* Get one value from cache.
*
* Now when there is this observablethingy. Make public afther rethinking this.
*
* @param moduleName
* @param cachePath
* @return {any|null} Null if nothing is in cache.
*/
private
get
(
moduleName
:
string
,
cachePath
:
string
):
CachedItem
{
let
cacheName
=
this
.
generateCachename
(
moduleName
,
cachePath
);
if
(
this
.
cache
.
has
(
cacheName
)
&&
this
.
cache
.
get
(
cacheName
).
expires
.
getTime
()
<
Date
.
now
())
{
this
.
cache
.
delete
(
cacheName
);
}
if
(
this
.
cache
.
has
(
cacheName
))
{
return
this
.
cache
.
get
(
cacheName
);
}
return
null
;
}
private
generateCachename
(
moduleName
:
string
,
cachePath
:
string
):
string
{
return
moduleName
+
"::"
+
cachePath
;
}
}
code/moya-angular/src/app/shared/services/moya-rest.service.spec.ts
0 → 100644
View file @
4936c49
/* tslint:disable:no-unused-variable */
import
{
TestBed
,
async
,
inject
}
from
'@angular/core/testing'
;
import
{
MoyaRestService
}
from
'./moya-rest.service'
;
describe
(
'MoyaRestService'
,
()
=>
{
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
providers
:
[
MoyaRestService
]
});
});
it
(
'should ...'
,
inject
([
MoyaRestService
],
(
service
:
MoyaRestService
)
=>
{
expect
(
service
).
toBeTruthy
();
}));
});
code/moya-angular/src/app/shared/services/moya-rest.service.ts
0 → 100644
View file @
4936c49
import
{
Injectable
}
from
'@angular/core'
;
import
{
Observable
}
from
"rxjs/Observable"
;
import
{
HttpClient
,
HttpResponse
}
from
"@angular/common/http"
;
import
"rxjs/add/operator/catch"
;
import
"rxjs/add/observable/throw"
;
@
Injectable
()
export
class
MoyaRestService
{
constructor
(
private
http
:
HttpClient
)
{
}
post
(
subUrl
:
string
,
body
:
any
,
pathParameters
?:
Map
<
string
,
string
>
):
Observable
<
HttpResponse
<
any
>
>
{
return
this
.
http
.
post
(
this
.
genUrl
(
subUrl
,
pathParameters
),
body
)
.
map
(
this
.
handleResponse
)
.
catch
(
this
.
handleException
);
}
put
(
subUrl
:
string
,
body
:
any
,
pathParameters
?:
Map
<
string
,
string
>
):
Observable
<
HttpResponse
<
any
>>
{
return
this
.
http
.
put
(
this
.
genUrl
(
subUrl
,
pathParameters
),
body
)
.
map
(
this
.
handleResponse
)
.
catch
(
this
.
handleException
);
}
delete
(
subUrl
:
string
,
pathParameters
?:
Map
<
string
,
string
>
):
Observable
<
HttpResponse
<
any
>
>
{
return
this
.
http
.
delete
(
this
.
genUrl
(
subUrl
,
pathParameters
))
.
map
(
this
.
handleResponse
)
.
catch
(
this
.
handleException
);
}
get
(
subUrl
:
string
,
pathParameters
?:
Map
<
string
,
string
>
):
Observable
<
HttpResponse
<
any
>
>
{
return
this
.
http
.
get
(
this
.
genUrl
(
subUrl
,
pathParameters
))
.
map
(
this
.
handleResponse
)
.
catch
(
this
.
handleException
);
}
private
genUrl
(
subUrl
:
string
,
urlParams
?:
Map
<
string
,
string
>
):
string
{
let
suffix
=
""
;
if
(
urlParams
)
{
urlParams
.
forEach
(
function
(
value
:
string
,
key
:
string
)
{
if
(
suffix
.
length
<=
0
)
{
suffix
=
"?"
;
}
else
{
suffix
+=
"&"
;
}
suffix
+=
key
+
"="
+
value
;
});
}
return
"/MoyaWeb/rest/"
+
subUrl
+
suffix
;
// <-- TODO: kauneista
}
private
handleResponse
(
res
:
HttpResponse
<
any
>
)
{
// basicly, 200 statuscodes means success
if
(
!
(
res
.
status
>=
200
&&
res
.
status
<=
299
))
{
console
.
log
(
"statuscode not between 200 and 299"
,
res
.
status
);
// next stop: handlerException
throw
res
;
}
return
res
;
}
private
handleException
(
error
:
HttpResponse
<
any
>
|
any
)
{
console
.
log
(
"error on jira rest connection"
,
error
);
// TODO: add handlers to 403's and other "not logged in" or "invalid permissions"
// -statuscodes, and route them using some nice global parameter
return
Observable
.
throw
(
error
);
}
}
code/moya-angular/src/app/shared/services/user.service.spec.ts
0 → 100644
View file @
4936c49
/* tslint:disable:no-unused-variable */
import
{
TestBed
,
async
,
inject
}
from
'@angular/core/testing'
;
import
{
UserService
}
from
'./user.service'
;
describe
(
'UserService'
,
()
=>
{
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
providers
:
[
UserService
]
});
});
it
(
'should ...'
,
inject
([
UserService
],
(
service
:
UserService
)
=>
{
expect
(
service
).
toBeTruthy
();
}));
});
code/moya-angular/src/app/shared/services/user.service.ts
0 → 100644
View file @
4936c49
import
{
Injectable
}
from
"@angular/core"
;
import
{
User
}
from
"../models/user.model"
;
import
{
MoyaRestService
}
from
"./moya-rest.service"
;
import
{
CacheService
}
from
"./cache.service"
;
import
{
Observable
}
from
"rxjs/Observable"
;
@
Injectable
()
export
class
UserService
{
constructor
(
private
moyaRest
:
MoyaRestService
,
private
cacheService
:
CacheService
)
{
}
public
get
(
id
:
number
):
Observable
<
User
>
{
if
(
!
id
||
id
<
0
)
{
return
Observable
.
throw
(
"There should be userid"
);
}
let
path
=
"v2/user/"
+
id
;
return
this
.
cacheService
.
cacheObservable
(
"moya:UserService"
,
path
,
this
.
moyaRest
.
get
(
path
)
.
do
(
v
=>
{
console
.
log
(
"getting user outside of cache"
,
path
)})
.
map
(
res
=>
(
<
User
>
res
.
body
)));
}
}
code/moya-angular/src/app/shared/services/viplist.service.spec.ts
0 → 100644
View file @
4936c49
/* tslint:disable:no-unused-variable */
import
{
TestBed
,
async
,
inject
}
from
'@angular/core/testing'
;
import
{
ViplistService
}
from
'./viplist.service'
;
describe
(
'ViplistService'
,
()
=>
{
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
providers
:
[
ViplistService
]
});
});
it
(
'should ...'
,
inject
([
ViplistService
],
(
service
:
ViplistService
)
=>
{
expect
(
service
).
toBeTruthy
();
}));
});
code/moya-angular/src/app/shared/services/viplist.service.ts
0 → 100644
View file @
4936c49
import
{
Injectable
}
from
'@angular/core'
;
import
{
MoyaRestService
}
from
"./moya-rest.service"
;
import
{
Vip
}
from
"../models/vip.model"
;
import
{
Response
}
from
"@angular/http"
;
import
{
User
}
from
"../models/user.model"
;
import
{
UserService
}
from
"./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
{
HttpResponse
}
from
"@angular/common/http"
;
@
Injectable
()
export
class
ViplistService
{
constructor
(
private
moyaRestService
:
MoyaRestService
,
private
userService
:
UserService
)
{
}
/**
* get vips
* @param searchString: searchString, skip to return all vips
*/
public
get
(
searchString
?:
string
):
Observable
<
Array
<
Vip
>>
{
if
(
!
searchString
)
{
return
this
.
moyaRestService
.
get
(
"v3/vip/all"
)
.
switchMap
(
res
=>
Observable
.
forkJoin
(...
res
.
body
.
map
(
apiRow
=>
this
.
hostPopulator
(
apiRow
))));
}
return
this
.
moyaRestService
.
get
(
"v3/vip/search/"
+
searchString
)
.
switchMap
(
v
=>
Observable
.
forkJoin
(...
v
.
body
.
map
(
x
=>
this
.
hostPopulator
(
x
))));
}
/**
* Delete vip.
*
* @param vip
* @return Promise
*/
public
async
delete
(
vip
:
Vip
):
Promise
<
boolean
>
{
if
(
!
vip
.
id
)
throw
new
Error
(
"TODO: errori, tyhmä vippi"
);
let
res
:
HttpResponse
<
any
>
=
await
this
.
moyaRestService
.
delete
(
"v3/vip/"
+
vip
.
id
)
.
first
()
.
toPromise
();
return
res
.
ok
;
}
public
getWithId
(
id
:
number
):
Observable
<
Vip
>
{
return
this
.
moyaRestService
.
get
(
"v3/vip/"
+
id
)
.
map
(
v
=>
v
.
body
);
}
public
create
(
vip
:
Vip
):
Observable
<
Vip
>
{
return
this
.
moyaRestService
.
post
(
"v3/vip/create"
,
vip
)
.
map
(
v
=>
v
.
body
);
}
private
hostPopulator
(
rawVip
:
any
):
Observable
<
Vip
>
{
return
this
.
userService
.
get
(
rawVip
.
hostId
)
.
map
((
u
:
User
)
=>
{
rawVip
.
host
=
u
;
return
<
Vip
>
rawVip
});
}
}
code/moya-angular/src/app/viplist/viplist.component.ts
View file @
4936c49
import
{
Component
,
NgZone
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
NgZone
,
OnInit
}
from
'@angular/core'
;
import
{
Observable
}
from
"rxjs/Observable"
;
import
{
Observable
}
from
"rxjs/Observable"
;
import
{
ViplistService
,
Vip
}
from
'moya-angular-common'
;
import
{
Vip
}
from
"../shared/models/vip.model"
;
import
{
ViplistService
}
from
"../shared/services/viplist.service"
;
@
Component
({
@
Component
({
selector
:
'moya-viplist'
,
selector
:
'moya-viplist'
,
...
...
code/moya-angular/src/tsconfig.json
View file @
4936c49
...
@@ -20,7 +20,5 @@
...
@@ -20,7 +20,5 @@
},
},
"include"
:
[
"include"
:
[
"**/*.ts"
,
"**/*.ts"
,
"../node_modules/moya-angular-common/*.ts"
,
"../node_modules/moya-angular-common/moya-rest/**/*.ts"
]
]
}
}
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