Commit c966f723 authored by Adrien PARROT's avatar Adrien PARROT
Browse files

Add activation user interface

parent 796facb1
......@@ -16,8 +16,28 @@ function getUsers() {
"Content-Type": "application/json",
},
beforeSend: function(xhr, settings) { debugger; xhr.setRequestHeader('Authorization','Bearer ' + token); } ,
success: function(oData, response, xhr) {
var oModel = new sap.ui.model.json.JSONModel(oData);
success: function(data, response, xhr) {
debugger;
if (data.users) {
for (var i = 0; i < data.users.length; i++) {
var user = data.users[i];
// DELETE actions
if (user.m_invalid_reason === 'D') {
user.m_invalid_reason = 'Invalid'
} else {
user.m_invalid_reason = 'Valid'
}
}
}
sap.ui.getCore().byId('oUserTable').setVisibleRowCount(data.users_number);
var oModel = new sap.ui.model.json.JSONModel(data);
sap.ui.getCore().setModel(oModel, "usersModel");
console.log("connection");
},
......@@ -47,8 +67,15 @@ function getUser(username) {
"Content-Type": "application/json",
},
beforeSend: function(xhr, settings) { debugger; xhr.setRequestHeader('Authorization','Bearer ' + token); } ,
success: function(oData, response, xhr) {
var oModel = new sap.ui.model.json.JSONModel(oData);
success: function(data, response, xhr) {
if (data.m_invalid_reason === 'D') {
data.m_invalid_reason = 'Invalid'
} else {
data.m_invalid_reason = 'Valid'
}
var oModel = new sap.ui.model.json.JSONModel(data);
sap.ui.getCore().setModel(oModel, "userModel");
console.log("connection");
},
......@@ -94,12 +121,16 @@ function postUserAjax(oData, sUsername) {
}
var oItemTemplateAdmin = new sap.ui.core.Item({
key : "{isAdminModel>key}",
text : "{isAdminModel>text}",
enabled : "{isAdminModel>enabled}"
key : "{isAdminUserModel>key}",
text : "{isAdminUserModel>text}",
enabled : "{isAdminUserModel>enabled}"
});
var oItemTemplateValid = new sap.ui.core.Item({
key : "{isValidUserModel>key}",
text : "{isValidUserModel>text}",
enabled : "{isValidUserModel>enabled}"
});
......@@ -109,10 +140,6 @@ sap.ui.controller("conceptmapper.userPage", {
/******* CREATE *******/
openCreateDialog : function (oEvt) {
var URL_user = "http://omop-mapper.fgh.ovh/api/user/";
// var URL_user = "http://127.0.0.1:5000/user/";
var oCreateDialog = new sap.m.Dialog({
title : "{i18n>create_user}",
icon : "sap-icon://employee"
......@@ -130,18 +157,31 @@ sap.ui.controller("conceptmapper.userPage", {
text : "{i18n>username}"
}), new sap.ui.commons.TextField({
value : ""
}), new sap.m.Label({
text : "{i18n>status}"
}), new sap.m.ComboBox({
// width : "400px",
//placeholder : "Standard Concepts",
items : {
path : "isValidUserModel>/items",
template : oItemTemplateValid
},
selectedKeys : {
path : "isValidUserModel>/selected",
template : "{isValidUserModel>selected}"
},
}), new sap.m.Label({
text : "{i18n>is_admin}"
}), new sap.m.ComboBox({
// width : "400px",
//placeholder : "Standard Concepts",
items : {
path : "isAdminModel>/items",
path : "isAdminUserModel>/items",
template : oItemTemplateAdmin
},
selectedKeys : {
path : "isAdminModel>/selected",
template : "{isAdminModel>selected}"
path : "isAdminUserModel>/selected",
template : "{isAdminUserModel>selected}"
},
}), new sap.m.Label({
text : "{i18n>password}"
......@@ -176,19 +216,22 @@ sap.ui.controller("conceptmapper.userPage", {
press: function () {
var content = oSimpleForm.getContent();
var oData = {};
oData.m_username = content[2].getValue();
oData.m_is_admin = content[4].getValue();
oData.m_password = content[6].getValue();
oData.m_firstname = content[8].getValue();
oData.m_lastname = content[10].getValue();
oData.m_address = content[12].getValue();
oData.m_email = content[14].getValue();
oData.m_invalid_reason = (content[4].getValue() === 'Valid') ? null : 'D';
oData.m_is_admin = content[6].getValue();
oData.m_password = content[8].getValue();
oData.m_firstname = content[10].getValue();
oData.m_lastname = content[12].getValue();
oData.m_address = content[14].getValue();
oData.m_email = content[16].getValue();
if (oData.m_username !== "" && oData.m_password !== "" && oData.m_password !== ""
if (oData.m_username !== "" && oData.m_password !== ""
&& oData.m_firstname !== "" && oData.m_lastname !== ""
&& oData.m_address !== "" && oData.m_email !== ""){
......@@ -265,13 +308,23 @@ sap.ui.controller("conceptmapper.userPage", {
}), new sap.ui.commons.TextField({
enabled: false,
value : "{userModel>/m_username}"
}), new sap.m.Label({
text : "{i18n>status}"
}), new sap.m.ComboBox({
// width : "400px",
//placeholder : "Standard Concepts",
items : {
path : "isValidUserModel>/items",
template : oItemTemplateValid
},
selectedKey : "{userModel>/m_invalid_reason}"
}), new sap.m.Label({
text : "{i18n>is_admin}"
}), new sap.m.ComboBox({
// width : "400px",
//placeholder : "Standard Concepts",
items : {
path : "isAdminModel>/items",
path : "isAdminUserModel>/items",
template : oItemTemplateAdmin
},
selectedKey : "{userModel>/m_is_admin}"
......@@ -310,16 +363,21 @@ sap.ui.controller("conceptmapper.userPage", {
var content = oSimpleForm.getContent();
var oData = {};
oData.m_username = content[2].getValue();
oData.m_is_admin = content[4].getValue();
oData.m_password = content[6].getValue();
oData.m_firstname = content[8].getValue();
oData.m_lastname = content[10].getValue();
oData.m_address = content[12].getValue();
oData.m_email = content[14].getValue();
debugger;
oData.m_username = content[2].getValue();
oData.m_invalid_reason = (content[4].getValue() === 'Valid') ? null : 'D';
oData.m_is_admin = content[6].getValue();
if (content[8].getValue() !== "") {
oData.m_password = content[8].getValue();
}
oData.m_firstname = content[10].getValue();
oData.m_lastname = content[12].getValue();
oData.m_address = content[14].getValue();
oData.m_email = content[16].getValue();
if (oData.m_username !== "" && oData.m_password !== "" && oData.m_password !== ""
debugger;
if (oData.m_username !== ""
&& oData.m_firstname !== "" && oData.m_lastname !== ""
&& oData.m_address !== "" && oData.m_email !== ""){
......@@ -381,94 +439,94 @@ sap.ui.controller("conceptmapper.userPage", {
/******* DELETE *******/
openDeleteDialog : function (oEvt) {
var URL_user = "http://omop-mapper.fgh.ovh/api/user/";
// var URL_user = "http://127.0.0.1:5000/user/";
var button_press = oEvt.getParameters().id;
var oTable_ref = sap.ui.getCore().byId(button_press).getParent().getParent();
idx = oTable_ref.getSelectedIndices();
if (idx.length === 0) {
sap.m.MessageToast.show("Nobody to delete");
return;
} else if (idx.length > 1) {
sap.m.MessageToast.show("You can delete on user each time");
return;
}
var oDeleteDialog = new sap.m.Dialog({
title : "{i18n>delete_user}",
icon : "sap-icon://employee"
});
oDeleteDialog.addContent(new sap.m.Text({text: "You will suppress the select user. Are you sure?"}));
oDeleteDialog.addButton(
new sap.m.Button({
text: "Delete",
type: "Reject",
icon: "sap-icon://accept",
press: function () {
var oData = {};
oData.username = oTable_ref.getRows()[idx[0]].getCells()[0].getProperty('text');
if (sap.ui.getCore().getModel('loginModel') !== undefined) {
var token = sap.ui.getCore().getModel('loginModel').oData.access_token;
}
$.ajax({
method:'DELETE',
url:URL_user + oTable_ref.getRows()[idx[0]].getCells()[0].getProperty('text'),
dataType:"json",
data: oData,
async: false,
header: {
"Content-Type": "application/json",
},
beforeSend: function(xhr, settings) { debugger; xhr.setRequestHeader('Authorization','Bearer ' + token); } ,
success: function(data, response, xhr) {
// front update
// var oModel = sap.ui.getCore().getModel('usersModel');
// var aData = oModel.getProperty("/names");
// aData.splice(idx[0], 1);
// oModel.setProperty("/names", aData);
getUsers();
// backend creation
sap.m.MessageToast.show("New user : '" + oData.username + "' deleted");
console.log("connection");
},
error : function(error) {
sap.m.MessageToast.show("Connexion error");
console.log(error);
}
});
oDeleteDialog.close();
}
})
);
oDeleteDialog.addButton(
new sap.m.Button({
text: "Reject",
icon: "sap-icon://decline",
press: function () {
oDeleteDialog.close();
}
})
);
oDeleteDialog.open();
},
// /******* DELETE *******/
// openDeleteDialog : function (oEvt) {
//// var URL_user = "http://omop-mapper.fgh.ovh/api/user/";
// var URL_user = "http://127.0.0.1:5000/user/";s
//
//
// var button_press = oEvt.getParameters().id;
// var oTable_ref = sap.ui.getCore().byId(button_press).getParent().getParent();
// idx = oTable_ref.getSelectedIndices();
// if (idx.length === 0) {
// sap.m.MessageToast.show("Nobody to delete");
// return;
// } else if (idx.length > 1) {
// sap.m.MessageToast.show("You can delete on user each time");
// return;
// }
//
// var oDeleteDialog = new sap.m.Dialog({
// title : "{i18n>delete_user}",
// icon : "sap-icon://employee"
// });
//
// oDeleteDialog.addContent(new sap.m.Text({text: "You will suppress the select user. Are you sure?"}));
//
// oDeleteDialog.addButton(
// new sap.m.Button({
// text: "Delete",
// type: "Reject",
// icon: "sap-icon://accept",
//
// press: function () {
//
// var oData = {};
// oData.username = oTable_ref.getRows()[idx[0]].getCells()[0].getProperty('text');
//
// if (sap.ui.getCore().getModel('loginModel') !== undefined) {
// var token = sap.ui.getCore().getModel('loginModel').oData.access_token;
// }
//
// $.ajax({
// method:'DELETE',
// url:URL_user + oTable_ref.getRows()[idx[0]].getCells()[0].getProperty('text'),
// dataType:"json",
// data: oData,
// async: false,
// header: {
// "Content-Type": "application/json",
// },
// beforeSend: function(xhr, settings) { debugger; xhr.setRequestHeader('Authorization','Bearer ' + token); } ,
// success: function(data, response, xhr) {
// // front update
//// var oModel = sap.ui.getCore().getModel('usersModel');
//// var aData = oModel.getProperty("/names");
//// aData.splice(idx[0], 1);
//// oModel.setProperty("/names", aData);
//
// getUsers();
//
// // backend creation
// sap.m.MessageToast.show("New user : '" + oData.username + "' deleted");
// console.log("connection");
// },
// error : function(error) {
// sap.m.MessageToast.show("Connexion error");
// console.log(error);
//
// }
// });
// oDeleteDialog.close();
//
// }
//
// })
// );
//
//
// oDeleteDialog.addButton(
// new sap.m.Button({
// text: "Reject",
// icon: "sap-icon://decline",
// press: function () {
// oDeleteDialog.close();
// }
// })
// );
//
// oDeleteDialog.open();
// },
......@@ -507,9 +565,24 @@ onInit : function() {
}]
};
oModel.setData(mData);
sap.ui.getCore().setModel(oModel, "isAdminModel");
sap.ui.getCore().setModel(oModel, "isAdminUserModel");
// users initialisation = model "usersModel"
var oModel = new sap.ui.model.json.JSONModel();
var mData = {
"selected" : [],
"items" : [{
"key" : "Valid",
"text" : "Valid"
},
{
"key" : "Invalid",
"text" : "Invalid"
}]
};
oModel.setData(mData);
sap.ui.getCore().setModel(oModel, "isValidUserModel");
},
/**
......
......@@ -31,19 +31,23 @@ sap.ui.jsview("conceptmapper.userPage", {
}) ]
});
var oTable = new sap.ui.table.Table({
var oTable = new sap.ui.table.Table('oUserTable', {
toolbar : new sap.m.Toolbar({
content : [ new sap.m.Button({
text : "{i18n>create_user}",
type : "Accept",
press : [ oController.openCreateDialog, oController ],
}), new sap.m.Button({
text : "{i18n>update_user}",
press : [ oController.openUpdateDialog, oController ],
}), new sap.m.Button({
text : "{i18n>delete_user}",
type : "Reject",
press : [ oController.openDeleteDialog, oController ],
}) ]
press : [ oController.openUpdateDialog, oController ],
}),
// new sap.m.Button({
// text : "{i18n>delete_user}",
// type : "Reject",
// press : [ oController.openDeleteDialog, oController ],
// })
]
}),
});
......@@ -58,6 +62,18 @@ sap.ui.jsview("conceptmapper.userPage", {
sortProperty : "Username"
}));
oTable.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "{i18n>status}"
}),
template : new sap.m.Text({
text : "{usersModel>m_invalid_reason}"
}),
sortProperty : "invalid_reason",
// editable : false,
}));
oTable.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "{i18n>is_admin}"
......@@ -67,6 +83,7 @@ sap.ui.jsview("conceptmapper.userPage", {
}),
// editable : false,
}));
oTable.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
......@@ -114,7 +131,7 @@ sap.ui.jsview("conceptmapper.userPage", {
}));
oTable.bindRows({
path : "usersModel>/names"
path : "usersModel>/users"
});
var oPage = new sap.m.Page({
......
......@@ -15,6 +15,7 @@ update_user=Update
delete_user=Delete
username=Username
is_admin=Administrator
status=Status
firtname=Firtname
lastname=Lastname
address=Address
......
......@@ -15,6 +15,7 @@ update_user=Actualisation
delete_user=Suppression
username=Username
is_admin=Administrateur
status=Status
firstname=Pr\u00e9nom
lastname=Nom de famille
address=Adresse
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment