Commit 900acc08 by Fernando Martínez Santiago Committed by Arturo Montejo Ráez

Vocabulary management from PCB, upload and status images, implemented (SAILS side)

parent b6c2e005
...@@ -79,6 +79,7 @@ module.exports = { ...@@ -79,6 +79,7 @@ module.exports = {
if (!params.picto || !params.lang || !params.text) { if (!params.picto || !params.lang || !params.text) {
return res.json(500, {error: "Not enough data: picto, lang or text"}); return res.json(500, {error: "Not enough data: picto, lang or text"});
} }
console.log("New Expression for picto id "+params.picto+": "+params.text+" ("+params.lang+")");
// If the expression exists, it's updated and if not, it's created // If the expression exists, it's updated and if not, it's created
PictoExp.findOne({picto: params.picto, lang: params.lang}).exec(function(err, exp){ PictoExp.findOne({picto: params.picto, lang: params.lang}).exec(function(err, exp){
if(err) if(err)
...@@ -87,12 +88,14 @@ module.exports = { ...@@ -87,12 +88,14 @@ module.exports = {
// Exists --> Update it // Exists --> Update it
if(exp){ if(exp){
PictoExp.update({id: exp.id}, params).exec(function (err, updated) { PictoExp.update({id: exp.id}, params).exec(function (err, updated) {
console.log("Expression updated for expr. id "+exp. id+": "+params.text);
if (err) throw err; if (err) throw err;
return res.json(updated); return res.json(updated);
}); });
// No exists --> Create it // No exists --> Create it
}else{ }else{
PictoExp.create(params).exec(function (err, created) { PictoExp.create(params).exec(function (err, created) {
console.log("Expression inserted for picto expr. "+created.id+": "+params.text);
if (err) throw err; if (err) throw err;
return res.json(created); return res.json(created);
}); });
...@@ -100,21 +103,22 @@ module.exports = { ...@@ -100,21 +103,22 @@ module.exports = {
}); });
}, },
// Upload a picto to the server (/upload/custompictos/) // Upload a picto to the server (/upload/custompictos/)
upload: function (req, res) { upload: function (req, res) {
if(req.method === 'GET') if(req.method === 'GET')
return res.json({'status':'GET not allowed'}); return res.json({'status':'GET not allowed'});
// Call to /upload via GET is error // Call to /upload via GET is error
console.log("Nombre archivo: " + req.body.filename); var fs = require('fs'), path = require('path'), dateFormat = require('dateformat');
console.log("Nombre carpeta: " + req.body.folder);
console.log("Nombre fuente: " + req.body.source);
var fs = require('fs'), path = require('path'); // req.body.filename = sailsHash.hashCode(req.body.filename + Date().toString()) + '.' + req.body.extension;
req.body.filename = sailsHash.hashCode(req.body.filename + Date().toString()) + '.' + req.body.extension; req.body.filename = 'u'+ req.body.owner+'d'+dateFormat(new Date(),"yyyymmddHHMMss")+ '.' + req.body.extension;
console.log("Uploading " + req.body.filename +' at ' + req.body.folder + ' from source '+ req.body.source +
'. Renamed as '+req.body.filename );
var uploadFile = req.file('file'); var uploadFile = req.file('file');
var dirUpload = path.join(process.cwd(), '/assets/upload/' + req.body.folder); var dirUpload = path.join(process.cwd(), '/assets/upload/' + req.body.folder);
......
...@@ -512,7 +512,7 @@ module.exports = { ...@@ -512,7 +512,7 @@ module.exports = {
// //
add_picto: function(req, res) { add_picto: function(req, res) {
var params = req.allParams(); var params = req.allParams();
console.log("Adding picto "+params.id_picto+" atts:"+params.attributes); console.log(JSON.stringify(params));
StuPicto.create({ StuPicto.create({
student: params.id_stu, student: params.id_stu,
picto: params.id_picto, picto: params.id_picto,
...@@ -560,8 +560,12 @@ module.exports = { ...@@ -560,8 +560,12 @@ 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(JSON.stringify(params)); console.log(JSON.stringify(params));
StuPicto.update({id: params.id_stuPicto}, {attributes: params.attributes}).exec(function (err, updated) {
query=params.id_stuPicto ? {id: params.id_stuPicto}
: {id_stu:params.id_stu, id_pic:params.id_pic}
StuPicto.update(query, {attributes: params.attributes}).exec(function (err, updated) {
if (err) { if (err) {
console.log(err); console.log(err);
return res.json(500, {error: 'Not updated picto for student'}); return res.json(500, {error: 'Not updated picto for student'});
......
...@@ -93,6 +93,7 @@ module.exports.routes = { ...@@ -93,6 +93,7 @@ module.exports.routes = {
'get /stu/:id_stu/pictos': 'StudentController.pictos', 'get /stu/:id_stu/pictos': 'StudentController.pictos',
'delete /stu/:id_stu/picto/:id_stuPicto': 'StudentController.delete_picto', 'delete /stu/:id_stu/picto/:id_stuPicto': 'StudentController.delete_picto',
'put /stu/:id_stu/picto/:id_stuPicto': 'StudentController.update_picto', 'put /stu/:id_stu/picto/:id_stuPicto': 'StudentController.update_picto',
'put /stu/:id_stu/picto': 'StudentController.update_picto',
'post /stu/:id_stu/picto/:id_picto': 'StudentController.add_picto', 'post /stu/:id_stu/picto/:id_picto': 'StudentController.add_picto',
// Students actions triggering WEBSOCKETS // Students actions triggering WEBSOCKETS
......
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