Toggle navigation
Toggle navigation
This project
Loading...
Sign in
digsig
/
digsig-services
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Stefan Huber
2017-03-08 09:49:11 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5fbb7d8543e24282cee845dd8a5b71e970ec6004
5fbb7d85
1 parent
a18d8786
recent changes
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
29 deletions
dist/services/repository.d.ts
dist/services/repository.js
dist/services/rest.js
src/services/repository.ts
tsconfig.json
dist/services/repository.d.ts
View file @
5fbb7d8
...
...
@@ -6,7 +6,8 @@ export declare class Repository {
protected
device
:
Device
;
protected
_db
:
any
;
protected
_params
:
any
;
readonly
db
:
any
;
db
:
any
;
params
:
any
;
constructor
(
rest
:
Rest
,
device
:
Device
);
findById
(
id
:
string
):
Promise
<
any
>
;
findByIds
(
ids
:
Array
<
string
>
):
Promise
<
Array
<
any
>>
;
...
...
dist/services/repository.js
View file @
5fbb7d8
...
...
@@ -5,7 +5,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
else
for
(
var
i
=
decorators
.
length
-
1
;
i
>=
0
;
i
--
)
if
(
d
=
decorators
[
i
])
r
=
(
c
<
3
?
d
(
r
)
:
c
>
3
?
d
(
target
,
key
,
r
)
:
d
(
target
,
key
))
||
r
;
return
c
>
3
&&
r
&&
Object
.
defineProperty
(
target
,
key
,
r
),
r
;
};
var
__metadata
=
(
this
&&
this
.
__metadata
)
||
function
(
k
,
v
)
{
if
(
typeof
Reflect
===
"object"
&&
typeof
Reflect
.
metadata
===
"function"
)
return
Reflect
.
metadata
(
k
,
v
);
};
var
core_1
=
require
(
"@angular/core"
);
var
rest_1
=
require
(
"./rest"
);
var
device_1
=
require
(
"./device"
);
var
Repository
=
(
function
()
{
function
Repository
(
rest
,
device
)
{
this
.
rest
=
rest
;
...
...
@@ -15,16 +20,29 @@ var Repository = (function () {
get
:
function
()
{
return
this
.
_db
;
},
set
:
function
(
db
)
{
this
.
_db
=
db
;
},
enumerable
:
true
,
configurable
:
true
});
Object
.
defineProperty
(
Repository
.
prototype
,
"params"
,
{
get
:
function
()
{
return
this
.
_params
;
},
set
:
function
(
params
)
{
this
.
_params
=
params
;
},
enumerable
:
true
,
configurable
:
true
});
Repository
.
prototype
.
findById
=
function
(
id
)
{
return
this
.
_
db
.
get
(
id
);
return
this
.
db
.
get
(
id
);
};
Repository
.
prototype
.
findByIds
=
function
(
ids
)
{
var
_this
=
this
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
_this
.
_
db
_this
.
db
.
allDocs
({
include_docs
:
true
,
keys
:
ids
...
...
@@ -44,7 +62,7 @@ var Repository = (function () {
options
[
'key'
]
=
type
;
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
_this
.
_
db
_this
.
db
.
query
(
'index_type/type'
,
options
)
.
then
(
function
(
res
)
{
resolve
(
_this
.
prepareDocs
(
res
));
...
...
@@ -69,7 +87,7 @@ var Repository = (function () {
}
}).
then
(
function
()
{
var
changes
=
false
;
_this
.
_db
.
replicate
.
from
(
_this
.
_
params
.
url
)
_this
.
db
.
replicate
.
from
(
_this
.
params
.
url
)
.
once
(
'change'
,
function
(
info
)
{
changes
=
true
;
})
.
once
(
'complete'
,
function
()
{
resolve
(
changes
);
})
.
once
(
'error'
,
function
(
error
)
{
reject
(
'replication error'
);
});
...
...
@@ -80,22 +98,22 @@ var Repository = (function () {
Repository
.
prototype
.
prepare
=
function
(
url
)
{
var
_this
=
this
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
_this
.
_
params
=
_this
.
parseUrl
(
url
);
if
(
!
_this
.
_
params
)
{
_this
.
params
=
_this
.
parseUrl
(
url
);
if
(
!
_this
.
params
)
{
reject
();
}
if
(
_this
.
_db
&&
_this
.
_db
.
name
==
_this
.
_
params
.
db_name
)
{
if
(
_this
.
db
&&
_this
.
db
.
name
==
_this
.
params
.
db_name
)
{
resolve
();
}
else
if
(
!
_this
.
_
db
)
{
_this
.
init
(
_this
.
_
params
.
db_name
).
then
(
function
()
{
else
if
(
!
_this
.
db
)
{
_this
.
init
(
_this
.
params
.
db_name
).
then
(
function
()
{
resolve
();
});
}
else
{
_this
.
_
db
.
destroy
()
_this
.
db
.
destroy
()
.
then
(
function
()
{
return
_this
.
init
(
_this
.
_
params
.
db_name
);
return
_this
.
init
(
_this
.
params
.
db_name
);
}).
then
(
function
()
{
resolve
();
});
...
...
@@ -104,9 +122,9 @@ var Repository = (function () {
};
Repository
.
prototype
.
init
=
function
(
db_name
)
{
if
(
window
[
'PouchDB'
])
{
this
.
_
db
=
new
window
[
'PouchDB'
](
db_name
);
this
.
db
=
new
window
[
'PouchDB'
](
db_name
);
}
return
this
.
_
db
.
putIfNotExists
(
"_design/index_type"
,
{
return
this
.
db
.
putIfNotExists
(
"_design/index_type"
,
{
views
:
{
type
:
{
map
:
(
function
(
doc
)
{
...
...
@@ -146,6 +164,8 @@ var Repository = (function () {
return
Repository
;
}());
Repository
=
__decorate
([
core_1
.
Injectable
()
core_1
.
Injectable
(),
__metadata
(
"design:paramtypes"
,
[
rest_1
.
Rest
,
device_1
.
Device
])
],
Repository
);
exports
.
Repository
=
Repository
;
...
...
dist/services/rest.js
View file @
5fbb7d8
...
...
@@ -5,6 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
else
for
(
var
i
=
decorators
.
length
-
1
;
i
>=
0
;
i
--
)
if
(
d
=
decorators
[
i
])
r
=
(
c
<
3
?
d
(
r
)
:
c
>
3
?
d
(
target
,
key
,
r
)
:
d
(
target
,
key
))
||
r
;
return
c
>
3
&&
r
&&
Object
.
defineProperty
(
target
,
key
,
r
),
r
;
};
var
__metadata
=
(
this
&&
this
.
__metadata
)
||
function
(
k
,
v
)
{
if
(
typeof
Reflect
===
"object"
&&
typeof
Reflect
.
metadata
===
"function"
)
return
Reflect
.
metadata
(
k
,
v
);
};
var
core_1
=
require
(
"@angular/core"
);
var
http_1
=
require
(
"@angular/http"
);
exports
.
ERROR_CODE_UNAUTHORIZED
=
"unauthorized"
;
...
...
@@ -89,7 +92,8 @@ var Rest = Rest_1 = (function () {
}());
Rest
.
serviceUrl
=
"http://someurl.com"
;
Rest
=
Rest_1
=
__decorate
([
core_1
.
Injectable
()
core_1
.
Injectable
(),
__metadata
(
"design:paramtypes"
,
[
http_1
.
Http
])
],
Rest
);
exports
.
Rest
=
Rest
;
var
Rest_1
;
...
...
src/services/repository.ts
View file @
5fbb7d8
...
...
@@ -15,18 +15,30 @@ export class Repository {
return
this
.
_db
;
}
set
db
(
db
)
{
this
.
_db
=
db
;
}
get
params
()
{
return
this
.
_params
;
}
set
params
(
params
)
{
this
.
_params
=
params
;
}
constructor
(
protected
rest
:
Rest
,
protected
device
:
Device
)
{}
findById
(
id
:
string
)
:
Promise
<
any
>
{
return
this
.
_
db
.
get
(
id
);
return
this
.
db
.
get
(
id
);
}
findByIds
(
ids
:
Array
<
string
>
)
:
Promise
<
Array
<
any
>>
{
return
new
Promise
<
Array
<
any
>>
((
resolve
,
reject
)
=>
{
this
.
_
db
this
.
db
.
allDocs
({
include_docs
:
true
,
keys
:
ids
...
...
@@ -48,7 +60,7 @@ export class Repository {
}
return
new
Promise
<
Array
<
any
>>
((
resolve
,
reject
)
=>
{
this
.
_
db
this
.
db
.
query
(
'index_type/type'
,
options
)
.
then
((
res
)
=>
{
resolve
(
this
.
prepareDocs
(
res
));
...
...
@@ -71,7 +83,7 @@ export class Repository {
}
}).
then
(()
=>
{
let
changes
=
false
;
this
.
_db
.
replicate
.
from
(
this
.
_
params
.
url
)
this
.
db
.
replicate
.
from
(
this
.
params
.
url
)
.
once
(
'change'
,
(
info
)
=>
{
changes
=
true
;
})
.
once
(
'complete'
,
()
=>
{
resolve
(
changes
);
})
.
once
(
'error'
,
(
error
)
=>
{
reject
(
'replication error'
);
});
...
...
@@ -82,22 +94,22 @@ export class Repository {
prepare
(
url
:
string
)
:
Promise
<
any
>
{
return
new
Promise
<
any
>
((
resolve
,
reject
)
=>
{
this
.
_
params
=
this
.
parseUrl
(
url
);
this
.
params
=
this
.
parseUrl
(
url
);
if
(
!
this
.
_
params
)
{
if
(
!
this
.
params
)
{
reject
();
}
if
(
this
.
_db
&&
this
.
_db
.
name
==
this
.
_
params
.
db_name
)
{
if
(
this
.
db
&&
this
.
db
.
name
==
this
.
params
.
db_name
)
{
resolve
();
}
else
if
(
!
this
.
_
db
)
{
this
.
init
(
this
.
_
params
.
db_name
).
then
(()
=>
{
}
else
if
(
!
this
.
db
)
{
this
.
init
(
this
.
params
.
db_name
).
then
(()
=>
{
resolve
();
});
}
else
{
this
.
_
db
.
destroy
()
this
.
db
.
destroy
()
.
then
(()
=>
{
return
this
.
init
(
this
.
_
params
.
db_name
);
return
this
.
init
(
this
.
params
.
db_name
);
}).
then
(()
=>
{
resolve
();
});
...
...
@@ -108,9 +120,9 @@ export class Repository {
init
(
db_name
:
string
)
:
Promise
<
any
>
{
if
(
window
[
'PouchDB'
])
{
this
.
_
db
=
new
window
[
'PouchDB'
](
db_name
);
this
.
db
=
new
window
[
'PouchDB'
](
db_name
);
}
return
this
.
_
db
.
putIfNotExists
(
"_design/index_type"
,
{
return
this
.
db
.
putIfNotExists
(
"_design/index_type"
,
{
views
:
{
type
:
{
map
:
(
function
(
doc
)
{
...
...
tsconfig.json
View file @
5fbb7d8
...
...
@@ -3,6 +3,7 @@
"allowSyntheticDefaultImports"
:
true
,
"declaration"
:
true
,
"experimentalDecorators"
:
true
,
"emitDecoratorMetadata"
:
true
,
"lib"
:
[
"dom"
,
"es2015"
],
"noImplicitAny"
:
false
,
"outDir"
:
"./dist/"
,
...
...
Please
register
or
login
to post a comment