Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLASweb
Commits
36b97bc0
Commit
36b97bc0
authored
Nov 18, 2019
by
Laura Fuentes Grau
Browse files
wip
#210
added requestURL function to RestDataManager
parent
700c64fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/common/data-managers/rest-data-manager.js
View file @
36b97bc0
...
@@ -52,57 +52,42 @@ class RestDataManager {
...
@@ -52,57 +52,42 @@ class RestDataManager {
return
object
;
return
object
;
}
}
sendRequest
(
form
,
id
,
token
,
param
,
object
=
null
,
obj
=
null
)
{
requestURL
(
form
,
id
,
param
,
object
=
null
){
switch
(
form
)
{
switch
(
form
){
case
'
load
'
:
case
'
load/add
'
:
if
(
param
===
null
)
{
if
(
param
===
null
){
if
(
id
!=
null
)
{
if
(
id
!=
null
){
// load single object
return
this
.
url
+
'
/
'
+
id
;
return
RestAPI
.
get
(
this
.
makeURL
(
this
.
url
+
'
/
'
+
id
),
token
);
}
else
{
// load all objects
return
RestAPI
.
get
(
this
.
makeURL
(
this
.
url
),
token
);
}
}
}
else
{
else
{
return
this
.
makeURL
(
this
.
url
);
if
(
id
!=
null
)
{
// load single object
return
RestAPI
.
get
(
this
.
makeURL
(
this
.
url
+
'
/
'
+
id
+
'
?
'
+
param
),
token
)
}
else
{
// load all objects
return
RestAPI
.
get
(
this
.
makeURL
(
this
.
url
)
+
'
?
'
+
param
,
token
)
}
}
}
case
'
add
'
:
if
(
param
===
null
)
{
return
RestAPI
.
post
(
this
.
makeURL
(
this
.
url
),
obj
,
token
);
}
else
{
return
RestAPI
.
post
(
this
.
makeURL
(
this
.
url
)
+
"
?
"
+
param
,
obj
,
token
);
}
case
'
remove
'
:
if
(
param
===
null
)
{
return
RestAPI
.
delete
(
this
.
makeURL
(
this
.
url
+
'
/
'
+
object
.
id
),
token
)
}
}
else
{
else
{
return
RestAPI
.
delete
(
this
.
makeURL
(
this
.
url
+
'
/
'
+
object
.
id
+
'
?
'
+
param
))
if
(
id
!=
null
){
return
this
.
url
+
'
/
'
+
id
+
'
?
'
+
param
;
}
else
{
return
this
.
makeURL
(
this
.
url
)
+
'
?
'
+
param
}
}
}
case
'
update
'
:
case
'
remove/
update
'
:
if
(
param
===
null
)
{
if
(
param
===
null
){
return
RestAPI
.
put
(
this
.
makeURL
(
this
.
url
+
'
/
'
+
object
.
id
)
,
obj
,
token
)
;
return
this
.
makeURL
(
this
.
url
+
'
/
'
+
object
.
id
);
}
}
else
{
else
{
return
RestAPI
.
put
(
this
.
makeURL
(
this
.
url
+
'
/
'
+
object
.
id
+
'
?
'
+
param
)
,
obj
,
token
)
;
return
this
.
makeURL
(
this
.
url
+
'
/
'
+
object
.
id
+
'
?
'
+
param
);
}
}
default
:
default
:
console
.
log
(
"
something went wrong
"
);
console
.
log
(
"
something went wrong
"
);
break
;
break
;
}
}
}
}
load
(
id
,
token
=
null
,
param
=
null
)
{
load
(
id
,
token
=
null
,
param
=
null
)
{
if
(
id
!=
null
)
{
if
(
id
!=
null
)
{
// load single object
// load single object
this
.
sendR
equest
(
'
load
'
,
id
,
token
,
param
).
then
(
response
=>
{
RestAPI
.
get
(
this
.
r
equest
URL
(
'
load
/add
'
,
id
,
param
),
token
).
then
(
response
=>
{
const
data
=
this
.
filterKeys
(
response
[
this
.
type
]);
const
data
=
this
.
filterKeys
(
response
[
this
.
type
]);
AppDispatcher
.
dispatch
({
AppDispatcher
.
dispatch
({
...
@@ -121,7 +106,7 @@ class RestDataManager {
...
@@ -121,7 +106,7 @@ class RestDataManager {
});
});
}
else
{
}
else
{
// load all objects
// load all objects
this
.
sendR
equest
(
'
load
'
,
id
,
token
,
param
).
then
(
response
=>
{
RestAPI
.
get
(
this
.
r
equest
URL
(
'
load
/add
'
,
id
,
param
),
token
).
then
(
response
=>
{
const
data
=
response
[
this
.
type
+
'
s
'
].
map
(
element
=>
{
const
data
=
response
[
this
.
type
+
'
s
'
].
map
(
element
=>
{
return
this
.
filterKeys
(
element
);
return
this
.
filterKeys
(
element
);
});
});
...
@@ -148,7 +133,7 @@ class RestDataManager {
...
@@ -148,7 +133,7 @@ class RestDataManager {
var
obj
=
{};
var
obj
=
{};
obj
[
this
.
type
]
=
this
.
filterKeys
(
object
);
obj
[
this
.
type
]
=
this
.
filterKeys
(
object
);
this
.
sendRequest
(
'
add
'
,
null
,
token
,
param
,
null
,
obj
).
then
(
response
=>
{
RestAPI
.
post
(
this
.
requestURL
(
'
load/add
'
,
null
,
param
),
obj
,
token
).
then
(
response
=>
{
AppDispatcher
.
dispatch
({
AppDispatcher
.
dispatch
({
type
:
this
.
type
+
'
s/added
'
,
type
:
this
.
type
+
'
s/added
'
,
data
:
response
[
this
.
type
]
data
:
response
[
this
.
type
]
...
@@ -162,7 +147,7 @@ class RestDataManager {
...
@@ -162,7 +147,7 @@ class RestDataManager {
}
}
remove
(
object
,
token
=
null
,
param
=
null
)
{
remove
(
object
,
token
=
null
,
param
=
null
)
{
this
.
sendR
equest
(
'
remove
'
,
null
,
token
,
param
,
object
).
then
(
response
=>
{
RestAPI
.
delete
(
this
.
r
equest
URL
(
'
remove
/update
'
,
null
,
param
,
object
)
,
token
)
.
then
(
response
=>
{
AppDispatcher
.
dispatch
({
AppDispatcher
.
dispatch
({
type
:
this
.
type
+
'
s/removed
'
,
type
:
this
.
type
+
'
s/removed
'
,
data
:
response
[
this
.
type
],
data
:
response
[
this
.
type
],
...
@@ -180,7 +165,7 @@ class RestDataManager {
...
@@ -180,7 +165,7 @@ class RestDataManager {
var
obj
=
{};
var
obj
=
{};
obj
[
this
.
type
]
=
this
.
filterKeys
(
object
);
obj
[
this
.
type
]
=
this
.
filterKeys
(
object
);
this
.
sendRequest
(
'
update
'
,
null
,
token
,
param
,
object
,
obj
).
then
(
response
=>
{
RestAPI
.
put
(
this
.
requestURL
(
'
remove/
update
'
,
null
,
param
,
object
),
obj
,
token
).
then
(
response
=>
{
AppDispatcher
.
dispatch
({
AppDispatcher
.
dispatch
({
type
:
this
.
type
+
'
s/edited
'
,
type
:
this
.
type
+
'
s/edited
'
,
data
:
response
[
this
.
type
]
data
:
response
[
this
.
type
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment