Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
InterHop
Omop
susana-front
Commits
e227a5c8
Commit
e227a5c8
authored
Jan 08, 2019
by
Adrien PARROT
Browse files
API connection ok (CRUD on users)
parent
c235e637
Changes
2
Hide whitespace changes
Inline
Side-by-side
WebContent/conceptmapper/userPage.controller.js
View file @
e227a5c8
...
...
@@ -9,26 +9,48 @@ sap.ui.controller("conceptmapper.userPage", {
* @memberOf conceptmapper.userPage
*/
onInit
:
function
()
{
var
oData
=
{
"
names
"
:
[
{
username
:
"
aparrot
"
,
password
:
"
toto
"
,
firstname
:
"
adrien
"
,
lastname
:
"
parrot
"
,
address
:
"
142
"
,
email
:
"
adrien.parrot@caramail.fr
"
,
}
,
{
username
:
"
mpondi
"
,
password
:
"
toto
"
,
firstname
:
"
marcy
"
,
lastname
:
"
pondi
"
,
address
:
"
142
"
,
email
:
"
marcy.pondi@caramail.fr
"
,
}
]
};
var
oModel
=
new
sap
.
ui
.
model
.
json
.
JSONModel
(
oData
);
sap
.
ui
.
getCore
().
setModel
(
oModel
,
"
user
"
);
$
.
ajax
({
type
:
"
GET
"
,
url
:
"
http://127.0.0.1:5000/users
"
,
dataType
:
"
json
"
,
async
:
false
,
header
:
{
"
Content-Type
"
:
"
application/json
"
,
},
success
:
function
(
oData
,
response
,
xhr
)
{
//debugger;
var
oModel
=
new
sap
.
ui
.
model
.
json
.
JSONModel
(
oData
);
sap
.
ui
.
getCore
().
setModel
(
oModel
,
"
user
"
);
console
.
log
(
"
connection
"
);
},
error
:
function
(
error
)
{
alert
(
"
pb in the connection
"
);
console
.
log
(
error
);
}
});
// var oData1 = {
// "names" : [ {
// username : "aparrot",
// password : "toto",
// firstname : "adrien",
// lastname : "parrot",
// address : "142",
// email : "adrien.parrot@caramail.fr",
// } , {
// username : "mpondi",
// password : "toto",
// firstname : "marcy",
// lastname : "pondi",
// address : "142",
// email : "marcy.pondi@caramail.fr",
// } ]
// };
//
//debugger;
// var oModel = new sap.ui.model.json.JSONModel(oData);
// sap.ui.getCore().setModel(oModel, "user");
},
/******* CREATE *******/
...
...
@@ -80,9 +102,10 @@ sap.ui.controller("conceptmapper.userPage", {
icon
:
"
sap-icon://accept
"
,
press
:
function
()
{
var
content
=
oSimpleForm
.
getContent
();
var
oData
=
{};
oData
.
username
=
content
[
2
].
getValue
();
oData
.
password
=
content
[
4
].
getValue
();
oData
.
firstname
=
content
[
6
].
getValue
();
...
...
@@ -92,10 +115,33 @@ sap.ui.controller("conceptmapper.userPage", {
if
(
oData
.
username
!==
""
&&
oData
.
password
!==
""
&&
oData
.
firstname
&&
oData
.
lastname
&&
oData
.
address
&&
oData
.
email
){
var
oModel
=
sap
.
ui
.
getCore
().
getModel
(
'
user
'
);
var
aData
=
oModel
.
getProperty
(
"
/names
"
);
aData
.
push
(
oData
);
oModel
.
setProperty
(
"
/names
"
,
aData
);
$
.
ajax
({
type
:
"
POST
"
,
url
:
"
http://127.0.0.1:5000/user/
"
+
oData
.
username
,
dataType
:
"
json
"
,
data
:
oData
,
async
:
false
,
header
:
{
"
Content-Type
"
:
"
application/json
"
,
},
success
:
function
(
data
,
response
,
xhr
)
{
// front update
var
oModel
=
sap
.
ui
.
getCore
().
getModel
(
'
user
'
);
var
aData
=
oModel
.
getProperty
(
"
/names
"
);
aData
.
push
(
oData
);
oModel
.
setProperty
(
"
/names
"
,
aData
);
// backend creation
sap
.
m
.
MessageToast
.
show
(
"
New user : '
"
+
oData
.
username
+
"
' created
"
);
console
.
log
(
"
connection
"
);
},
error
:
function
(
error
)
{
sap
.
m
.
MessageToast
.
show
(
"
Connexion error
"
);
console
.
log
(
error
);
}
});
}
else
{
sap
.
m
.
MessageToast
.
show
(
"
Nothing created!!
\n
You have to file all the fields
"
);
}
...
...
@@ -146,6 +192,7 @@ sap.ui.controller("conceptmapper.userPage", {
}),
new
sap
.
m
.
Label
({
text
:
"
{i18n>username}
"
}),
new
sap
.
ui
.
commons
.
TextField
({
enabled
:
false
,
value
:
user
[
0
].
getProperty
(
'
text
'
)
}),
new
sap
.
m
.
Label
({
text
:
"
{i18n>password}
"
...
...
@@ -188,11 +235,37 @@ sap.ui.controller("conceptmapper.userPage", {
oData
.
lastname
=
content
[
8
].
getValue
();
oData
.
address
=
content
[
10
].
getValue
();
oData
.
email
=
content
[
12
].
getValue
();
var
oModel
=
sap
.
ui
.
getCore
().
getModel
(
'
user
'
);
var
aData
=
oModel
.
getProperty
(
"
/names
"
);
aData
.
splice
(
idx
[
0
],
1
,
oData
);
oModel
.
setProperty
(
"
/names
"
,
aData
);
$
.
ajax
({
type
:
"
PUT
"
,
url
:
"
http://127.0.0.1:5000/user/
"
+
oData
.
username
,
dataType
:
"
json
"
,
data
:
oData
,
async
:
false
,
header
:
{
"
Content-Type
"
:
"
application/json
"
,
},
success
:
function
(
data
,
response
,
xhr
)
{
// front update
var
oModel
=
sap
.
ui
.
getCore
().
getModel
(
'
user
'
);
var
aData
=
oModel
.
getProperty
(
"
/names
"
);
aData
.
splice
(
idx
[
0
],
1
,
oData
);
oModel
.
setProperty
(
"
/names
"
,
aData
);
// backend creation
sap
.
m
.
MessageToast
.
show
(
"
New user : '
"
+
oData
.
username
+
"
'updated
"
);
console
.
log
(
"
connection
"
);
},
error
:
function
(
error
)
{
sap
.
m
.
MessageToast
.
show
(
"
Connexion error
"
);
console
.
log
(
error
);
}
});
oUpdateDialog
.
close
();
}
...
...
@@ -210,10 +283,7 @@ sap.ui.controller("conceptmapper.userPage", {
oUpdateDialog
.
open
();
},
/******* DELETE *******/
openDeleteDialog
:
function
(
oEvt
)
{
var
button_press
=
oEvt
.
getParameters
().
id
;
...
...
@@ -241,12 +311,39 @@ sap.ui.controller("conceptmapper.userPage", {
icon
:
"
sap-icon://accept
"
,
press
:
function
()
{
var
oModel
=
sap
.
ui
.
getCore
().
getModel
(
'
user
'
);
var
aData
=
oModel
.
getProperty
(
"
/names
"
);
aData
.
splice
(
idx
[
0
],
1
);
oModel
.
setProperty
(
"
/names
"
,
aData
);
var
URL
=
"
http://127.0.0.1:5000/user/
"
;
URL
=
URL
+
oTable_ref
.
getRows
()[
idx
[
0
]].
getCells
()[
0
].
getProperty
(
'
text
'
);
$
.
ajax
({
type
:
"
DELETE
"
,
url
:
URL
,
dataType
:
"
json
"
,
async
:
false
,
header
:
{
"
Content-Type
"
:
"
application/json
"
,
},
success
:
function
(
data
,
response
,
xhr
)
{
// front update
var
oModel
=
sap
.
ui
.
getCore
().
getModel
(
'
user
'
);
var
aData
=
oModel
.
getProperty
(
"
/names
"
);
aData
.
splice
(
idx
[
0
],
1
);
oModel
.
setProperty
(
"
/names
"
,
aData
);
oDeleteDialog
.
close
();
// backend creation
sap
.
m
.
MessageToast
.
show
(
"
New user : '
"
+
oData
.
username
+
"
'updated
"
);
console
.
log
(
"
connection
"
);
},
error
:
function
(
error
)
{
sap
.
m
.
MessageToast
.
show
(
"
Connexion error
"
);
console
.
log
(
error
);
}
});
oDeleteDialog
.
close
();
}
}
})
);
...
...
WebContent/index.html
View file @
e227a5c8
...
...
@@ -17,7 +17,7 @@
// create an app
var
app
=
new
sap
.
m
.
App
({
initialPage
:
"
id
Home
Page
"
initialPage
:
"
id
User
Page
"
});
// Adding all the pages to the app
...
...
Write
Preview
Supports
Markdown
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