Commit ae3d9e03 by Fernando Martínez Santiago

Merge branch 'develop' of http://gitlab.ujaen.es/yotta/pictogram into develop

parents 5d0886c7 d8df45b8
...@@ -92,7 +92,9 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -92,7 +92,9 @@ public class Vocabulary implements Iterable<Picto> {
JSONObject attrs_picto = args.getJSONObject("attributes"); JSONObject attrs_picto = args.getJSONObject("attributes");
attrs_picto.put(Picto.JSON_ATTTRS.STUPICTO_ID,args.getInt("id")); attrs_picto.put(Picto.JSON_ATTTRS.STUPICTO_ID,args.getInt("id"));
Picto newPicto=new Picto(picto_id, uri, attrs_picto); Picto newPicto=new Picto(picto_id, uri, attrs_picto);
Picto prev_picto=find_picto(newPicto.get_category(), newPicto.get_row(),newPicto.get_column()); Picto prev_picto=PCBcontext.getPcbdb().getCurrentUser().has_categories()
? find_picto(newPicto.get_category(), newPicto.get_row(),newPicto.get_column())
: find_picto(newPicto.getFreeRow(),newPicto.getFreeColumn());
if (prev_picto!=null) { if (prev_picto!=null) {
Log.i(LOG_TAG, "Pictogram "+prev_picto.get_translation()+":"+prev_picto.get_id()+" to be replaced by "+newPicto.get_translation()+":"+newPicto.get_id()); Log.i(LOG_TAG, "Pictogram "+prev_picto.get_translation()+":"+prev_picto.get_id()+" to be replaced by "+newPicto.get_translation()+":"+newPicto.get_id());
...@@ -298,7 +300,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -298,7 +300,7 @@ public class Vocabulary implements Iterable<Picto> {
return index; return index;
} }
//case:categories
private Picto find_picto(int pic_cat, int row,int column) { private Picto find_picto(int pic_cat, int row,int column) {
LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat); LinkedList<Picto> pictos_cat=this.pictos.get(pic_cat);
Picto picto=null; Picto picto=null;
...@@ -307,6 +309,15 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -307,6 +309,15 @@ public class Vocabulary implements Iterable<Picto> {
return picto; return picto;
} }
// CASE: no categories
private Picto find_picto(int row,int column) {
LinkedList<Picto> pictos_cat=this.pictos.get(Picto.NO_CATEGORY);
Picto picto=null;
for (int i=0; i<pictos_cat.size() && picto==null; i++)
if (pictos_cat.get(i).getFreeColumn()==column && pictos_cat.get(i).getFreeRow()==row) picto=pictos_cat.get(i);
return picto;
}
/** /**
* *
* @param pic_cat Category id of the picto * @param pic_cat Category id of the picto
...@@ -416,7 +427,7 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -416,7 +427,7 @@ public class Vocabulary implements Iterable<Picto> {
public void saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y, int free_category_coord_x, int free_category_coord_y,String uri_sound,String user_avatar,String associated_person, final iLocalPicto listener) { public void saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y, int free_category_coord_x, int free_category_coord_y,String uri_sound,String user_avatar,String associated_person, final iLocalPicto listener) {
Picto prev_picto=find_picto(cat, coord_x,coord_y); //¿estamos reemplazanddo un picto que ya existe? Picto prev_picto=PCBcontext.getPcbdb().getCurrentUser().has_categories() ? find_picto(cat, coord_x,coord_y) : find_picto(coord_x,coord_y); //¿estamos reemplazanddo un picto que ya existe?
if (prev_picto!=null) { //El picto ya existe if (prev_picto!=null) { //El picto ya existe
removePicto(prev_picto.get_category(),prev_picto.get_id()); //borramos el picto local actual removePicto(prev_picto.get_category(),prev_picto.get_id()); //borramos el picto local actual
......
...@@ -78,7 +78,7 @@ public final class PCBcontext { ...@@ -78,7 +78,7 @@ public final class PCBcontext {
public void change(User updatedStudent) { public void change(User updatedStudent) {
PCBcontext.getDevice().insertUser(updatedStudent); PCBcontext.getDevice().insertUser(updatedStudent);
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() || updatedStudent.has_categories()!=getPcbdb().getCurrentUser().has_categories()) if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() || updatedStudent.has_categories()!=getPcbdb().getCurrentUser().has_categories())
PCBcontext.getNetService().restart_app(true); PCBcontext.getNetService().restart_app(false);
else { else {
PCBcontext.getPcbdb().setCurrentUser(updatedStudent); PCBcontext.getPcbdb().setCurrentUser(updatedStudent);
PCBcontext.getNetService().getNetServiceDevice().updateUserConfig(updatedStudent); PCBcontext.getNetService().getNetServiceDevice().updateUserConfig(updatedStudent);
......
...@@ -537,7 +537,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -537,7 +537,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
} }
} else { } else {
if (p.getFreeColumn() != -1 && p.getFreeRow() != -1 if (p.getFreeColumn() != -1 && p.getFreeRow() != -1
&& p.get_column() < maxRows && p.get_row() < maxColumns) { && p.getFreeColumn() < maxRows && p.getFreeRow() < maxColumns) {
mp[p.getFreeColumn()][p.getFreeRow()] = p; mp[p.getFreeColumn()][p.getFreeRow()] = p;
} }
} }
......
...@@ -97,27 +97,28 @@ ...@@ -97,27 +97,28 @@
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-24.2.1" level="project" /> <orderEntry type="library" exported="" name="support-v4-24.2.1" level="project" />
<orderEntry type="library" exported="" name="support-compat-24.2.1" level="project" /> <orderEntry type="library" exported="" name="support-compat-24.2.1" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-24.2.1" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-24.2.1" level="project" /> <orderEntry type="library" exported="" name="animated-vector-drawable-24.2.1" level="project" />
<orderEntry type="library" exported="" name="support-fragment-24.2.1" level="project" /> <orderEntry type="library" exported="" name="support-fragment-24.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-base-9.2.1" level="project" />
<orderEntry type="library" exported="" name="androidasync-2.1.9" level="project" />
<orderEntry type="library" exported="" name="play-services-clearcut-9.2.1" level="project" />
<orderEntry type="library" exported="" name="android-gif-drawable-1.1.7" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.0" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-24.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-gcm-9.2.1" level="project" /> <orderEntry type="library" exported="" name="play-services-gcm-9.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-auth-base-9.2.1" level="project" /> <orderEntry type="library" exported="" name="play-services-auth-base-9.2.1" level="project" />
<orderEntry type="library" exported="" name="support-core-ui-24.2.1" level="project" /> <orderEntry type="library" exported="" name="support-core-ui-24.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-base-9.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-gass-9.2.1" level="project" /> <orderEntry type="library" exported="" name="play-services-gass-9.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-iid-9.2.1" level="project" /> <orderEntry type="library" exported="" name="play-services-iid-9.2.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-24.2.1" level="project" /> <orderEntry type="library" exported="" name="appcompat-v7-24.2.1" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-24.2.1" level="project" /> <orderEntry type="library" exported="" name="support-vector-drawable-24.2.1" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-24.2.1" level="project" /> <orderEntry type="library" exported="" name="support-core-utils-24.2.1" level="project" />
<orderEntry type="library" exported="" name="androidasync-2.1.9" level="project" />
<orderEntry type="library" exported="" name="play-services-clearcut-9.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-basement-9.2.1" level="project" /> <orderEntry type="library" exported="" name="play-services-basement-9.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-tasks-9.2.1" level="project" /> <orderEntry type="library" exported="" name="play-services-tasks-9.2.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-24.2.1" level="project" /> <orderEntry type="library" exported="" name="support-annotations-24.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-auth-9.2.1" level="project" /> <orderEntry type="library" exported="" name="play-services-auth-9.2.1" level="project" />
<orderEntry type="library" exported="" name="play-services-ads-9.2.1" level="project" /> <orderEntry type="library" exported="" name="play-services-ads-9.2.1" level="project" />
<orderEntry type="library" exported="" name="ion-2.1.9" level="project" /> <orderEntry type="library" exported="" name="ion-2.1.9" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.0" level="project" />
<orderEntry type="library" exported="" name="play-services-ads-lite-9.2.1" level="project" /> <orderEntry type="library" exported="" name="play-services-ads-lite-9.2.1" level="project" />
<orderEntry type="module" module-name="commonlibrary" exported="" /> <orderEntry type="module" module-name="commonlibrary" exported="" />
<orderEntry type="library" exported="" name="android-android-24" level="project" /> <orderEntry type="library" exported="" name="android-android-24" level="project" />
......
...@@ -1189,9 +1189,9 @@ module.exports = { ...@@ -1189,9 +1189,9 @@ module.exports = {
/** /**
* Upload a custom sound associated to a picto * Upload a custom sound associated to a picto
* @param {request} req * @param {request} req
* id_stu, * id_sup,
* id_picto, * id_picto,
* attributes: { @see StuPicto.getValidAttributes() } *
* @param {response} res * @param {response} res
* { * {
* id: <stu_picto ID>, * id: <stu_picto ID>,
...@@ -1222,15 +1222,14 @@ module.exports = { ...@@ -1222,15 +1222,14 @@ module.exports = {
* } * }
*/ */
upload_sound: function (req, res) { upload_sound: function (req, res) {
Supervisor.findOne({ id: req.body.owner }).then(function (supervisor) { console.log("sup id: " + req.params.id_supervisor );
Supervisor.findOne({ id: req.params.id_supervisor }).then(function (supervisor) {
var soundFileName; var soundFileName;
var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory; var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory;
if (!supervisor) if (!supervisor)
throw new Error("No supervisor found"); throw new Error("No supervisor found");
soundFileName = sails.config.pictogram.paths.getSupervisorCustomPictoFileName(supervisor.id) soundFileName = sails.config.pictogram.paths.getSupervisorCustomPictoSoundFilename(supervisor.id);
+ "_sound";
sails.log.debug("Uploading sound with FileName: " + soundFileName);
req.file('file').upload({ req.file('file').upload({
maxBytes: 1048576, maxBytes: 1048576,
...@@ -1246,7 +1245,6 @@ module.exports = { ...@@ -1246,7 +1245,6 @@ module.exports = {
.then(picto => { .then(picto => {
return res.ok(picto); return res.ok(picto);
}) })
.populate('uri_sound',soundFileName)
.catch(err => { .catch(err => {
fs.unlink(uploadedFiles[0].fd); fs.unlink(uploadedFiles[0].fd);
return res.serverError("Error uploading " + err); return res.serverError("Error uploading " + err);
...@@ -1257,7 +1255,7 @@ module.exports = { ...@@ -1257,7 +1255,7 @@ module.exports = {
return res.serverError("Error uploading sound: " + err); return res.serverError("Error uploading sound: " + err);
}); });
}, },
// *************************************************************** // ***************************************************************
// WEBSOCKETS // WEBSOCKETS
// *************************************************************** // ***************************************************************
......
...@@ -75,6 +75,18 @@ module.exports.pictogram = { ...@@ -75,6 +75,18 @@ module.exports.pictogram = {
.replace(/\W/g, '') + ".jpg"; .replace(/\W/g, '') + ".jpg";
}, },
_getRandomSoundFileName: function (randomString, randomNumber) {
var bcrypt = require('bcrypt-nodejs');
var randomDate = (new Date())
.getTime();
var randomFloat = Math.random();
return bcrypt.hashSync(
[randomString, randomDate, randomNumber, randomFloat].join(''),
bcrypt.genSaltSync()
)
.replace(/\W/g, '') + "_sound.mp3";
},
/** /**
* Gets the supervisor avatar filename * Gets the supervisor avatar filename
* @param {supervisorId} supervisorId * @param {supervisorId} supervisorId
...@@ -109,9 +121,21 @@ module.exports.pictogram = { ...@@ -109,9 +121,21 @@ module.exports.pictogram = {
'SUPERVISOR_CUSTOM_PICTO', 'SUPERVISOR_CUSTOM_PICTO',
supervisorId supervisorId
); );
},
/**
* Gets the supervisor custom picto filename
* @param {supervisorId} supervisorId supervisorId
* @return {string} fileName
*/
getSupervisorCustomPictoSoundFilename: function (supervisorId) {
return sails.config.pictogram.paths._getRandomSoundFileName(
'SUPERVISOR_CUSTOM_PICTO',
supervisorId
);
} }
}, },
// TODO: errores should have a code (number) and a name (string) like "TokenExpired", "UserNotFound"... // TODO: errores should have a code (number) and a name (string) like "TokenExpired", "UserNotFound"...
error_codes: { error_codes: {
'DUPLICATED_PICTO': 1, 'DUPLICATED_PICTO': 1,
......
...@@ -87,7 +87,7 @@ module.exports.routes = { ...@@ -87,7 +87,7 @@ module.exports.routes = {
'POST /stu/login': 'StudentController.login', 'POST /stu/login': 'StudentController.login',
'POST /stu': 'StudentController.create', 'POST /stu': 'StudentController.create',
'POST /stu/upload': 'StudentController.upload', 'POST /stu/upload': 'StudentController.upload',
'POST /stu/:id_stu/upload/:id_picto': 'StudentController.upload_sound', 'POST /stu/:id_sup/upload/:id_picto': 'StudentController.upload_sound',
'POST /stu/:id_stu/picto/:id_picto': 'StudentController.add_picto', 'POST /stu/:id_stu/picto/:id_picto': 'StudentController.add_picto',
'POST /stu/subscribe': 'StudentController.subscribe', 'POST /stu/subscribe': 'StudentController.subscribe',
'POST /stu/unsubscribe': 'StudentController.unsubscribe', 'POST /stu/unsubscribe': 'StudentController.unsubscribe',
......
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