notificación de nuevo picto desde el PDB al PCB solucionado

parent 69441fe7
......@@ -73,7 +73,11 @@ public class Vocabulary implements Iterable<Picto> {
}
case update:{
Log.i(this.getClass().getCanonicalName(), "Picto update "+args.toString());
modifyAttsPicto(picto_cat, picto_id, args);
try {
modifyAttsPicto(picto_cat, picto_id, args.getJSONObject("attributes"));
} catch (JSONException e) {
e.printStackTrace();
}
break;
}
......
package com.yottacode.pictogram.grammar; import android.util.Log; import com.github.nkzawa.emitter.Emitter; import org.json.JSONException;import org.json.JSONObject; import com.yottacode.pictogram.dao.Picto;import com.yottacode.pictogram.action.Room; /** * Websocket Vocabulary Room based on Room * @author Fernando Martinez Santiago * @version 1.0 */public class VocabularyTalk implements Emitter.Listener { private static final String URL ="vocabulary"; private Room room; iVocabularyListener listeners[]; public VocabularyTalk(Room room, iVocabularyListener listeners[]) { this.room = room; this.room.listen(URL, this); this.listeners=listeners; } @Override public void call(Object... args) { final String param_action="action"; final String param_attributes="attributes"; final String param_picto="picto"; final String param_picto_id="id"; final String param_picto_cat="id_cat"; final String action_update="update"; final String action_add="add"; final String action_delete="delete"; JSONObject msg = (JSONObject) args[0]; try { Log.i(this.getClass().getName(), "raw Received message " +msg.toString()); String action = msg.getString(param_action).toLowerCase(); JSONObject picto= msg.getJSONObject(param_attributes).getJSONObject(param_picto); JSONObject attrs_picto = picto.optJSONObject(param_attributes); int picto_id = picto.getJSONObject(param_picto).getInt(param_picto_id); int picto_cat = attrs_picto!=null ? attrs_picto.optInt(param_picto_cat, Picto.NO_CATEGORY) : 0; Log.i(this.getClass().getName(), "Received message '" + action + "' for picto " + picto_id + " (cat " + picto_cat + ", attrs: " + attrs_picto); for (iVocabularyListener listener: this.listeners) listener.change(action.equals(action_update) ? iVocabularyListener.action.update : action.equals(action_add) ? iVocabularyListener.action.add : iVocabularyListener.action.delete , picto_cat, picto_id, attrs_picto); } catch (JSONException e) { Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + "--" + e); } }}
\ No newline at end of file
package com.yottacode.pictogram.grammar; import android.util.Log; import com.github.nkzawa.emitter.Emitter; import org.json.JSONException;import org.json.JSONObject; import com.yottacode.pictogram.dao.Picto;import com.yottacode.pictogram.action.Room; /** * Websocket Vocabulary Room based on Room * @author Fernando Martinez Santiago * @version 1.0 */public class VocabularyTalk implements Emitter.Listener { private static final String URL ="vocabulary"; private Room room; iVocabularyListener listeners[]; public VocabularyTalk(Room room, iVocabularyListener listeners[]) { this.room = room; this.room.listen(URL, this); this.listeners=listeners; } @Override public void call(Object... args) { final String param_action="action"; final String param_attributes="attributes"; final String param_picto="picto"; final String param_stu_picto="stu_picto"; final String param_picto_id="id"; final String param_picto_cat="id_cat"; final String action_update="update"; final String action_add="add"; final String action_delete="delete"; JSONObject msg = (JSONObject) args[0]; try { Log.i(this.getClass().getName(), "raw Received message " +msg.toString()); String action = msg.getString(param_action).toLowerCase(); JSONObject stu_picto= msg.getJSONObject(param_attributes).getJSONObject(param_stu_picto); JSONObject attrs_stu_picto = stu_picto.optJSONObject(param_attributes); JSONObject attrs_picto = stu_picto.optJSONObject(param_picto); int picto_id = attrs_picto.getInt(param_picto_id); int picto_cat = attrs_stu_picto!=null ? attrs_stu_picto.optInt(param_picto_cat, Picto.NO_CATEGORY) : 0; Log.i(this.getClass().getName(), "Received message '" + action + "' for picto " + picto_id + " (cat " + picto_cat + ", attrs: " + attrs_picto); for (iVocabularyListener listener: this.listeners) listener.change(action.equals(action_update) ? iVocabularyListener.action.update : action.equals(action_add) ? iVocabularyListener.action.add : iVocabularyListener.action.delete , picto_cat, picto_id, stu_picto); } catch (JSONException e) { Log.e(this.getClass().getCanonicalName(), e.getClass().getCanonicalName() + "--" + e); } }}
\ No newline at end of file
......
......@@ -270,9 +270,9 @@ module.exports = {
Supervisor.findOne({ id: req.body.owner }).then(function (supervisor) {
var pictoFileName;
var pictoDirectory = sails.config.pictogram.paths.supervisorCustomPictoDirectory;
if (!supervisor) {
throw new Error();
}
if (!supervisor)
throw new Error("No supervisor found");
pictoFileName = sails.config.pictogram.paths.getSupervisorCustomPictoFileName(supervisor.id);
sails.log.debug("Uploading picto with FileName: " + pictoFileName);
......@@ -280,29 +280,28 @@ module.exports = {
maxBytes: 1000000,
dirname: pictoDirectory,
saveAs: pictoFileName
}, function whenDone(error, uploadedFiles) {
}, function whenDone(err, uploadedFiles) {
var fs = require('fs');
if (error || (uploadedFiles.length === 0)) {
throw new Error();
}
if (err || (uploadedFiles.length === 0))
return res.serverError("Error uploading " + err ? err : "");
Picto.create({
uri: pictoFileName,
source: 1, // @TODO check for other sources
owner: supervisor.id
})
.then(function (picto) {
res.ok(picto);
.then(picto => {
return res.ok(picto);
})
.catch(function () {
.catch(err => {
fs.unlink(uploadedFiles[0].fd);
res.serverError();
return res.serverError("Error uploading " + err);
});
});
})
.catch(function () {
res.serverError();
.catch(function (err) {
return res.serverError("Error uploading picto: " + err);
});
}
};
......@@ -807,54 +807,52 @@ module.exports = {
*/
add_picto: function (req, res) {
var params = req.allParams();
var student;
var picto;
Student.findOne({ id: params.id_stu })
.then((studentData) => {
if (studentData) {
student = studentData;
} else {
.then((student) => {
if (!student) {
sails.log.error(`Student ${params.id_stu} not found`);
throw new Error();
throw new Error("Student not found");
}
Picto.findOne({ id: params.id_picto })
.populate('expressions', {
lang: student.lang
})
.then((pictoData) => {
if (pictoData) {
picto = pictoData;
} else {
sails.log.error(`Picto ${params.id_picto} not found`);
throw new Error();
}
return [
Picto.findOne({ id: params.id_picto })
.populate('expressions', {
lang: student.lang
})
,
student
];
})
.spread((picto, student) => {
if (!picto) {
sails.log.error(`Picto ${params.id_picto} not found`);
throw new Error("Picto not found");
}
return [
StuPicto.create({
student: student.id,
picto: picto.id,
attributes: params.attributes
})
.then((stuPicto) => {
if (stuPicto) {
sails.log.debug('StuPicto created: %j', stuPicto);
res.ok(Object.assign(
{},
stuPicto.toObject(),
{ picto: picto.toObject() },
{ expression: picto.expressions.pop() }
));
} else {
sails.log.error('StuPicto not created');
throw new Error();
}
})
.catch(() => res.serverError());
})
.catch(() => res.badRequest());
,
picto
];
})
.spread((stuPicto, picto) => {
if (!stuPicto)
throw new Error("stu_picto not created");
sails.log.debug("->>" + JSON.stringify(picto));
return res.ok({
id: stuPicto.id,
student: params.id_stu,
attributes: stuPicto.attributes,
picto: picto,
expression: picto.expressions[0]
});
})
.catch(() => res.badRequest());
.catch(err => res.serverError("Error adding picto: " + err));
},
/**
......@@ -867,19 +865,15 @@ module.exports = {
delete_picto: function (req, res) {
var params = req.allParams();
StuPicto.destroy({
id: params.id_stuPicto
})
.exec(function (err, destroyed) {
if (err) {
return res.json(500, {
error: 'Not removed picto for student'
});
}
if (destroyed) {
return res.ok();
}
});
StuPicto.destroy({ id: params.id_stuPicto })
.then(destroyed => {
if (!destroyed)
throw new Error();
return res.ok();
})
.catch(err => {
return res.serverError('Not removed picto for student: ' + err);
});
},
// update action
......@@ -896,28 +890,27 @@ module.exports = {
id_stu: params.id_stu,
id_pic: params.id_pic
}
StuPicto.update(query, {
attributes: params.attributes
})
.exec(function (err, updated) {
if (err) {
console.log(err);
return res.json(500, {
error: 'Not updated picto for student'
});
}
if (updated) {
console.log('Updated attributes for picto student:' + JSON.stringify(updated[0]));
// return res.json(updated[0]);
return res.json({
id: updated[0].id,
attributes: updated[0].attributes,
picto: {
id: updated[0].picto
}
});
attributes: params.attributes
})
.then(updated => {
if (!updated)
throw new Error ("error on update");
console.log('Updated attributes for picto student:' + JSON.stringify(updated[0]));
// return res.json(updated[0]);
return res.ok({
id: updated[0].id, // id of stu_picto
attributes: updated[0].attributes, // picto attributes for student
picto: {
id: updated[0].picto // picto information
}
});
})
.catch(err => {
return res.serverError('Unable to update picto for student: ' + err);
});
},
/**
......
......@@ -186,6 +186,7 @@
"picto_labels": "Pictogram labels",
"picto_style": "Pictogram style",
"picto_upload_error": "Error uploading picto",
"picto_upload_limit": "Image size is too large",
"picto_upload_success": "Picto uploaded successfully",
"pictogram": "Pictogram",
"pictogram_setup": "Pictogram setup",
......
......@@ -186,6 +186,7 @@
"picto_labels": "Etiquetas del pictograma",
"picto_style": "Aspecto de los pictogramas",
"picto_upload_error": "Hubo un error al guardar el picto",
"picto_upload_limit": "El tamaño del picto es demasiado grande",
"picto_upload_success": "Picto almacenado correctamente",
"pictogram": "Pictograma",
"pictogram_setup": "Configuración del pictograma",
......
......@@ -168,10 +168,15 @@ dashboardControllers.controller('AddPictoCtrl', function (
picto.expressions = [];
$scope.pictos.push(picto);
$scope.open_exp(picto);
}).error(function () {
$translate('picto_upload_error').then(function (translation) {
ngToast.danger(translation);
});
}).error(function (err) {
if (err.code == "E_EXCEEDS_UPLOAD_LIMIT")
$translate('picto_upload_limit').then(function (translation) {
ngToast.danger(translation);
});
else
$translate('picto_upload_error').then(function (translation) {
ngToast.danger(translation);
});
});
} else {
$translate('invalid_file_type').then(function (translation) {
......@@ -225,6 +230,15 @@ dashboardControllers.controller('AddPictoCtrl', function (
studentPicto.picto.uri = pictoURI;
categoryGrid[positionX][positionY] = studentPicto;
$scope.addedPictos[categoryId].push(studentPicto);
io.socket.post('/stu/vocabulary', {
action: 'add',
attributes: {
id_stu: student.id,
stu_picto: studentPicto
}
}, function () {});
})
.error(function () {
$translate('error_adding_picto').then(function (translation) {
......@@ -233,6 +247,9 @@ dashboardControllers.controller('AddPictoCtrl', function (
});
};
/**
* A picto is added to the "free" category
*/
$scope.handleDropAddFreePicto = function (addedPictoId) {
var pictoId = parseInt(document.getElementById(addedPictoId).dataset.pictoId, 10);
var pictoURI = document.getElementById(addedPictoId).dataset.pictoUri;
......@@ -241,7 +258,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
// Check if there is space in category
for (positionX = 0; positionX < freeCategoryPictos.length; positionX++) {
for (positionY = 0; positionY < freeCategoryPictos[positionY].length; positionY++) {
for (positionY = 0; positionY < freeCategoryPictos[positionX].length; positionY++) {
if (freeCategoryPictos[positionX][positionY] === emptyStudentPicto) {
break;
}
......@@ -271,6 +288,15 @@ dashboardControllers.controller('AddPictoCtrl', function (
studentPicto.picto.uri = pictoURI;
freeCategoryPictos[positionX][positionY] = studentPicto;
$scope.freeAddedPictos.push(studentPicto);
io.socket.post('/stu/vocabulary', {
action: 'add',
attributes: {
id_stu: student.id,
stu_picto: studentPicto
}
}, function () {});
})
.error(function () {
$translate('error_adding_picto').then(function (translation) {
......@@ -304,7 +330,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
action: 'delete',
attributes: {
id_stu: student.id,
picto: studentPicto
stu_picto: studentPicto
}
}, function () {});
})
......
......@@ -141,7 +141,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
action: 'delete',
attributes: {
id_stu: $scope.studentData.id,
picto: studentPicto
stu_picto: studentPicto
}
}, function () {});
}).error(function () {});
......@@ -161,7 +161,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
action: 'delete',
attributes: {
id_stu: $scope.studentData.id,
picto: studentPicto
stu_picto: studentPicto
}
}, function () {});
}).error(function () {});
......@@ -186,7 +186,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
action: 'update',
attributes: {
id_stu: $scope.studentData.id,
picto: newStuPicto
stu_picto: newStuPicto
}
}, function () {});
}).error(function () {});
......@@ -246,7 +246,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
action: 'update',
attributes: {
id_stu: $scope.studentData.id,
picto: newStudentPicto
stu_picto: newStudentPicto
}
}, function () {
setTimeout(function () {
......
......@@ -302,8 +302,8 @@ textarea.editable{
.picto{
margin: 0.4%;
width: 9.2%;
height: 9.2%;
width: 80px;
height: 80px;
border: 1px solid #bbb;
border-radius: 4px;
padding: 2px;
......
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