Commit cde7a3cb by Fernando Martínez Santiago

Merge branch 'master' of http://scm.ujaen.es/softuno/pictogram

parents 7737f075 889b9572
...@@ -108,7 +108,6 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -108,7 +108,6 @@ public class SerialActivity extends Activity implements iRestapiListener {
password = ""; password = "";
} }
// Escribo los últimos valores indicados // Escribo los últimos valores indicados
mSerialViewMail.setText(username); mSerialViewMail.setText(username);
//mSerialViewPass.setText(password); //mSerialViewPass.setText(password);
...@@ -124,78 +123,74 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -124,78 +123,74 @@ public class SerialActivity extends Activity implements iRestapiListener {
Log.d(LOG_TAG, "PCBcontext iniciado"); Log.d(LOG_TAG, "PCBcontext iniciado");
//if (PCBcontext.getDevice().getLastStuId() != 0) { //if (PCBcontext.getDevice().getLastStuId() != 0) {
if (!username.equals("") && !password.equals("")){ if (!username.equals("") && !password.equals("")){ // Tengo usuario, sigo con este usuario
// Tengo usuario, sigo con este usuario if (RestapiWrapper.ping(context.getResources().getString(R.string.server),"server/ping",this)) {
RestapiWrapper wrapper = PCBcontext.getRestapiWrapper(); // Tengo conexión a internet. Compruebo ONLINE
if (username.contains("@")){ RestapiWrapper wrapper = PCBcontext.getRestapiWrapper();
// Es un supervisor if (username.contains("@")){
String operation = "sup/login"; // Es un supervisor
Hashtable<String, String> postDataParams = new Hashtable<String, String>(); String operation = "sup/login";
Hashtable<String, String> postDataParams = new Hashtable<String, String>();
postDataParams.put("email", username);
postDataParams.put("password", password); postDataParams.put("email", username);
postDataParams.put("password", password);
/* /*
postDataParams.put("idFirmware", _ANDROIDID); postDataParams.put("idFirmware", _ANDROIDID);
postDataParams.put("desc", _MODEL); postDataParams.put("desc", _MODEL);
postDataParams.put("serial", serial); postDataParams.put("serial", serial);
*/ */
wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context); wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context);
} else{ } else{
// Es un estudiante // Es un estudiante
Log.d(LOG_TAG, "Entro con usuario y password"); Log.d(LOG_TAG, "Entro con usuario y password");
String operation = "stu/login"; String operation = "stu/login";
Hashtable<String, String> postDataParams = new Hashtable<String, String>(); Hashtable<String, String> postDataParams = new Hashtable<String, String>();
postDataParams.put("username", username); postDataParams.put("username", username);
postDataParams.put("password", password); postDataParams.put("password", password);
/* /*
postDataParams.put("idFirmware", _ANDROIDID); postDataParams.put("idFirmware", _ANDROIDID);
postDataParams.put("desc", _MODEL); postDataParams.put("desc", _MODEL);
postDataParams.put("serial", serial); postDataParams.put("serial", serial);
*/ */
wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context); wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context);
} }
} else{ } else{
// Compruebo si tengo acceso a internet // NO Tengo conexión a internet. Compruebo OFFLINE
//modificación FERNANDO if (username.contains("@")) {
if (!RestapiWrapper.ping(context.getResources().getString(R.string.server),"server/ping",this)) { // Es un supervisor
// No puedo comprobar si el serial es válido. Muestro un alertdialog de error, y cierro la aplicación } else {
AlertDialog alertDialog = new AlertDialog.Builder( // Es un estudiante
SerialActivity.this).create(); }
alertDialog.setTitle("Mensaje del sistema"); // ....
alertDialog.setMessage("No hay conexión a Internet. Inténtelo más tarde");
//alertDialog.setIcon(R.drawable.tick);
/*
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Saliendo de la aplicación", Toast.LENGTH_SHORT).show();
} }
});
*/
alertDialog.show();
// ¿QUÉ HACEMOS CON LA APP?
} else {
Button mEntrarButton = (Button) findViewById(R.id.entrar_button);
mEntrarButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
String username = mSerialViewMail.getText().toString();
String password = mSerialViewPass.getText().toString();
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
// DE PRUEBA
// Alumno
//username = "faf0001";
//password = "faf0001";
// Supervisor
//username = "dofer@ujaen.es";
//password = "dofer";
} else{ // No tengo aún usuario. Espero a que lo indique
Button mEntrarButton = (Button) findViewById(R.id.entrar_button);
mEntrarButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
String username = mSerialViewMail.getText().toString();
String password = mSerialViewPass.getText().toString();
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
// DE PRUEBA
// Alumno
username = "faf0001";
password = "faf0001";
// Supervisor
//username = "dofer@ujaen.es";
//password = "dofer";
// IMPORTANTE. FERNANDO: ¿Para qué el último argumento del listener?
if (RestapiWrapper.ping(context.getResources().getString(R.string.server),"server/ping",null)) {
// Tengo conexión a internet. Compruebo ONLINE
RestapiWrapper wrapper = PCBcontext.getRestapiWrapper(); RestapiWrapper wrapper = PCBcontext.getRestapiWrapper();
if (username.contains("@")){ if (username.contains("@")){
// Es un supervisor // Es un supervisor
...@@ -204,11 +199,6 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -204,11 +199,6 @@ public class SerialActivity extends Activity implements iRestapiListener {
postDataParams.put("email", username); postDataParams.put("email", username);
postDataParams.put("password", password); postDataParams.put("password", password);
/*
postDataParams.put("idFirmware", _ANDROIDID);
postDataParams.put("desc", _MODEL);
postDataParams.put("serial", serial);
*/
wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context); wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context);
} else{ } else{
// Es un estudiante // Es un estudiante
...@@ -217,16 +207,21 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -217,16 +207,21 @@ public class SerialActivity extends Activity implements iRestapiListener {
postDataParams.put("username", username); postDataParams.put("username", username);
postDataParams.put("password", password); postDataParams.put("password", password);
/*
postDataParams.put("idFirmware", _ANDROIDID);
postDataParams.put("desc", _MODEL);
postDataParams.put("serial", serial);
*/
wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context); wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context);
} }
} else{
// NO Tengo conexión a internet. Compruebo OFFLINE
if (username.contains("@")) {
// Es un supervisor
// Necesito una función local que dado el username y pass me devuelva el listado de usuarios o el usuario, si es correcto
// ....
} else {
// Es un estudiante
}
// ....
} }
}); }
} });
} }
} }
...@@ -250,7 +245,7 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -250,7 +245,7 @@ public class SerialActivity extends Activity implements iRestapiListener {
Log.d(LOG_TAG, "JSON en result:"+result.toString()); Log.d(LOG_TAG, "JSON en result:"+result.toString());
if (result.toString().contains("error")){ if (result.toString().contains("error")){
progressDialog.dismiss(); if (progressDialog!=null) progressDialog.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
...@@ -308,7 +303,8 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -308,7 +303,8 @@ public class SerialActivity extends Activity implements iRestapiListener {
PCBcontext.set_user(student, jsonToken, new iImgDownloaderListener() { PCBcontext.set_user(student, jsonToken, new iImgDownloaderListener() {
@Override @Override
public void loadComplete() { public void loadComplete() {
progressDialog.dismiss(); if (progressDialog!=null)
progressDialog.dismiss();
Intent pictogramActivity = new Intent(SerialActivity.this, PictogramActivity.class); Intent pictogramActivity = new Intent(SerialActivity.this, PictogramActivity.class);
startActivity(pictogramActivity); startActivity(pictogramActivity);
} }
...@@ -341,7 +337,7 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -341,7 +337,7 @@ public class SerialActivity extends Activity implements iRestapiListener {
int su_id_int = su_id.intValue(); int su_id_int = su_id.intValue();
//close the progress dialog //close the progress dialog
if (!username.contains("@")){ if (!username.contains("@") && progressDialog!=null){
progressDialog.dismiss(); progressDialog.dismiss();
} }
...@@ -379,10 +375,10 @@ public class SerialActivity extends Activity implements iRestapiListener { ...@@ -379,10 +375,10 @@ public class SerialActivity extends Activity implements iRestapiListener {
Log.e(this.getClass().getName(), " Server restapi error: " + e.getLocalizedMessage()); Log.e(this.getClass().getName(), " Server restapi error: " + e.getLocalizedMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
builder.setMessage(getString(R.string.serverError)+":"+e.getLocalizedMessage()) builder.setMessage(getString(R.string.serverError) + ":" + e.getLocalizedMessage())
.setCancelable(false) .setCancelable(false)
.setPositiveButton("Entendido", new DialogInterface.OnClickListener() { .setPositiveButton("Entendido", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
//do things //do things
} }
}); });
......
...@@ -46,9 +46,9 @@ ...@@ -46,9 +46,9 @@
<!--Semantic grammar --> <!--Semantic grammar -->
<string name="loadingGrammar">Por favor espere, cargando gramática semántica</string> <string name="loadingGrammar">Por favor espere, cargando gramática semántica</string>
<string name="naturalgrammar">SUpO_ES</string> <string name="naturalgrammar">SUpO_ES</string>
<string name="pictogrammar">SUpO_PICTOES</string> <string name="grammar">SUpO_ES</string>
<string name="nogrammar">Advertencia: Lenguaje no soportado</string> <string name="nogrammar">Advertencia: Lenguaje no soportado</string>
<string name="pictogrammar">SUpO_PICTOES</string>
<item type="integer" name="maxInTape">8</item> <item type="integer" name="maxInTape">8</item>
......
...@@ -45,8 +45,10 @@ ...@@ -45,8 +45,10 @@
<!--Semantic grammar --> <!--Semantic grammar -->
<string name="loadingGrammar">Please wait, loading semmantic grammar</string> <string name="loadingGrammar">Please wait, loading semmantic grammar</string>
<string name="naturalgrammar">SUpO_EN</string>
<string name="grammar">SUpO_EN</string> <string name="grammar">SUpO_EN</string>
<string name="nogrammar">Warning: unknown language</string> <string name="nogrammar">Warning: unknown language</string>
<string name="pictogrammar">SUpO_PICTOEN</string>
<!--Upload local img --> <!--Upload local img -->
<string name="enterImgLabel">Introduzca etiqueta de la imagen</string> <string name="enterImgLabel">Introduzca etiqueta de la imagen</string>
......
...@@ -538,6 +538,7 @@ module.exports = { ...@@ -538,6 +538,7 @@ module.exports = {
// //
delete_picto: function(req, res) { delete_picto: function(req, res) {
var params = req.allParams(); var params = req.allParams();
console.log(JSON.stringify(params)); console.log(JSON.stringify(params));
StuPicto.destroy({id: params.id_stuPicto}).exec(function (err, destroyed) { StuPicto.destroy({id: params.id_stuPicto}).exec(function (err, destroyed) {
if (err) { if (err) {
...@@ -545,11 +546,11 @@ module.exports = { ...@@ -545,11 +546,11 @@ module.exports = {
return res.json(500, {error: 'Not removed picto for student'}); return res.json(500, {error: 'Not removed picto for student'});
} }
if (destroyed) { if (destroyed) {
console.log("Removed picto for the student" ); console.log("Removed picto "+destroyed[0].id_pic+ "for the student ");
return res.json({ return res.json({
"id": destroyed[0].id, id: destroyed[0].id,
"attributes": JSON.parse(destroyed[0].attributes), attributes: JSON.parse(destroyed[0].attributes),
"picto": destroyed[0].id_pic picto: { id: destroyed[0].id_pic }
}); });
} }
}); });
...@@ -560,7 +561,7 @@ module.exports = { ...@@ -560,7 +561,7 @@ module.exports = {
// //
update_picto: function(req, res) { update_picto: function(req, res) {
var params = req.allParams(); var params = req.allParams();
console.log("Updating attributes for picto student "+ params); console.log("Updating attributes for picto student "+ JSON.stringify(params));
console.log(JSON.stringify(params)); console.log(JSON.stringify(params));
query=params.id_stuPicto ? {id: params.id_stuPicto} query=params.id_stuPicto ? {id: params.id_stuPicto}
...@@ -572,7 +573,12 @@ module.exports = { ...@@ -572,7 +573,12 @@ module.exports = {
} }
if (updated) { if (updated) {
console.log("Updated attributes for picto student:"+JSON.stringify(updated[0])); console.log("Updated attributes for picto student:"+JSON.stringify(updated[0]));
return res.json(updated[0]); // return res.json(updated[0]);
return res.json({
id: updated[0].id,
attributes: updated[0].attributes,
picto: { id:updated[0].picto }
});
} }
}); });
}, },
...@@ -665,6 +671,11 @@ module.exports = { ...@@ -665,6 +671,11 @@ module.exports = {
if (req.isSocket) { if (req.isSocket) {
sails.log.debug("Inside /stu/subscribe - isSocket"); sails.log.debug("Inside /stu/subscribe - isSocket");
sails.sockets.join(req.socket, roomName); sails.sockets.join(req.socket, roomName);
sails.io.sockets.in(roomName).clients(function(err, ids) {
sails.log.debug("number of clients in room: " + ids.length);
if (!err)
sails.io.to(roomName).emit('update_peers', {count: ids.length});
});
res.json({ res.json({
msg: "Subscribed to student " + roomName msg: "Subscribed to student " + roomName
}); });
...@@ -691,8 +702,8 @@ module.exports = { ...@@ -691,8 +702,8 @@ module.exports = {
sails.sockets.leave(req.socket, rooms[i]); sails.sockets.leave(req.socket, rooms[i]);
sails.log.debug("Unsusbscribe from room " + rooms[i]); sails.log.debug("Unsusbscribe from room " + rooms[i]);
} }
res.json({ res.json({
msg: "Unsubscribed from all rooms" msg: "Unsubscribed from all rooms"
}); });
} }
......
...@@ -143,6 +143,7 @@ ...@@ -143,6 +143,7 @@
"normal": "Normal", "normal": "Normal",
"notes": "Notes", "notes": "Notes",
"November": "November", "November": "November",
"num_peers": "Peers",
"num_sessions_per_day_in": "Sessions per day in", "num_sessions_per_day_in": "Sessions per day in",
"num_sessions_per_month_in": "Sessions per months in", "num_sessions_per_month_in": "Sessions per months in",
"objetive": "Objetive", "objetive": "Objetive",
......
...@@ -143,6 +143,7 @@ ...@@ -143,6 +143,7 @@
"normal": "Normal", "normal": "Normal",
"notes": "Notas", "notes": "Notas",
"November": "Noviembre", "November": "Noviembre",
"num_peers": "Conectados",
"num_sessions_per_day_in": "Número de sesiones por día en", "num_sessions_per_day_in": "Número de sesiones por día en",
"num_sessions_per_month_in": "Número de sesiones por meses en", "num_sessions_per_month_in": "Número de sesiones por meses en",
"objetive": "Objetivo", "objetive": "Objetivo",
......
...@@ -136,7 +136,7 @@ dashboardControllers.controller('AddPictoCtrl', function ($scope, $modalInstance ...@@ -136,7 +136,7 @@ dashboardControllers.controller('AddPictoCtrl', function ($scope, $modalInstance
}; };
$scope.alert = { type: 'danger', msg: 'Category is full of pictos.', show: false }; $scope.alert = { type: 'danger', msg: 'Category is full of pictos.', show: false };
// //
// Close alert message // Close alert message
// //
...@@ -352,6 +352,7 @@ dashboardControllers.controller('AddPictoCtrl', function ($scope, $modalInstance ...@@ -352,6 +352,7 @@ dashboardControllers.controller('AddPictoCtrl', function ($scope, $modalInstance
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
console.log("Error from API: " + data.error); console.log("Error from API: " + data.error);
alert('Pictogram is already part of this vocabulary');
}); });
} }
......
...@@ -23,7 +23,8 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl($scope, conf ...@@ -23,7 +23,8 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl($scope, conf
id: '', id: '',
name: '' name: ''
}, },
stuSup: [] stuSup: [],
num_peers: 1
}; };
// For the user form data in setup section // For the user form data in setup section
...@@ -34,6 +35,30 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl($scope, conf ...@@ -34,6 +35,30 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl($scope, conf
// from the abstract parent (it has no url) // from the abstract parent (it has no url)
$scope.studentData.id = $state.$current.locals.globals.$stateParams.idStudent; $scope.studentData.id = $state.$current.locals.globals.$stateParams.idStudent;
//
// WebSockets communication
//
io.socket.on('update_peers', function(data) {
console.log(data.count + ' peers connected');
$scope.studentData.num_peers = data.count;
});
io.socket.on('reconnect', function () {
// Subscribe to student's socket room
console.log("reconnecting to socket");
io.socket.post('/stu/subscribe', {
action: 'subscribe',
attributes:{
id_stu: $scope.studentData.id
},
token: $window.sessionStorage.token
},
function(res) {
console.log("Connected to student: " + res.msg);
});
});
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// Load student account information // Load student account information
...@@ -244,24 +269,6 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl($scope, conf ...@@ -244,24 +269,6 @@ dashboardControllers.controller('StudentCtrl', function StudentCtrl($scope, conf
console.log("Error from API: " + data.error); console.log("Error from API: " + data.error);
}); });
//
// WebSockets communication
//
io.socket.on('reconnect', function () {
// Subscribe to student's socket room
console.log("reconnecting to socket");
io.socket.post('/stu/subscribe', {
action: 'subscribe',
attributes:{
id_stu: $scope.studentData.id
},
token: $window.sessionStorage.token
},
function(res) {
console.log("Connected to student: " + res.msg);
});
});
/* /*
// Events handling // Events handling
io.socket.on('action', function(data) { io.socket.on('action', function(data) {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<div style="margin-left: 5px"><h4>{{studentData.name}} {{studentData.surname}}</h4></div> <div style="margin-left: 5px"><h4>{{studentData.name}} {{studentData.surname}}</h4></div>
<div style="margin-left: 5px" class="text-left">{{studentData.current_method | translate}}</div> <div style="margin-left: 5px" class="text-left">{{studentData.current_method | translate}}</div>
<div style="margin-left: 5px" class="text-left">{{studentData.current_instruction | translate}}</div> <div style="margin-left: 5px" class="text-left">{{studentData.current_instruction | translate}}</div>
<div style="margin-left: 5px; color: green" class="text-left">{{ 'num_peers' | translate}} : {{studentData.num_peers}}</div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
...@@ -49,4 +50,4 @@ ...@@ -49,4 +50,4 @@
</div> </div>
</div> </div>
</nav> </nav>
<!-- Fin cabecera alumno --> <!-- Fin cabecera alumno -->
\ No newline at end of file
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 sign in to comment