Commit 1488a819 by Jose Antonio

Merged branch develop into develop

parents f373d407 e2ef3827
...@@ -5,7 +5,7 @@ buildscript { ...@@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
...@@ -145,7 +145,14 @@ public class RestapiWrapper { ...@@ -145,7 +145,14 @@ public class RestapiWrapper {
if (Character.isAlphabetic(response.charAt(0))) if (Character.isAlphabetic(response.charAt(0)))
response.append('\'').insert(0,'\''); response.append('\'').insert(0,'\'');
Log.i(LOG_TAG, "Raw server answer: " + response);
for (int i=0;i<(int)(((float)response.length())/3000)+1;i++) {
int begin= i * 3000;
int end = (i+1) * 3000;
if (end>response.length()) end=response.length();
Log.d(LOG_TAG, "Raw server answer(" + i+ "): " + response.substring(begin, end));
}
try { try {
JSONresponse = new JSONObject("{ "+SERVER_RESULT+": " + response + (responseCode == HttpURLConnection.HTTP_OK JSONresponse = new JSONObject("{ "+SERVER_RESULT+": " + response + (responseCode == HttpURLConnection.HTTP_OK
? "}" ? "}"
...@@ -154,7 +161,7 @@ public class RestapiWrapper { ...@@ -154,7 +161,7 @@ public class RestapiWrapper {
JSONresponse = null; JSONresponse = null;
Log.e(RestapiWrapper.class.getCanonicalName(),e.getMessage()); Log.e(RestapiWrapper.class.getCanonicalName(),e.getMessage());
} }
Log.i(LOG_TAG, "server answer: " + JSONresponse.toString()); Log.i(LOG_TAG, "Server answer: " + JSONresponse.toString());
return JSONresponse; return JSONresponse;
} }
......
...@@ -39,7 +39,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -39,7 +39,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
private Vector<iNetServiceStatus> listeners; private Vector<iNetServiceStatus> listeners;
private static final long restfullSynchroTimming=PCBcontext.getContext().getResources().getInteger(R.integer.netservice_force_restfull_synchro)*1000; private static final long restfullSynchroTimming=PCBcontext.getContext().getResources().getInteger(R.integer.netservice_force_restfull_synchro)*1000;
private long lastRestfullSynchro; private long nextRestfullSynchro;
public NetService(int delay, iNetServiceStatus listener) { public NetService(int delay, iNetServiceStatus listener) {
this.updated=RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session); this.updated=RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session);
...@@ -164,7 +164,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -164,7 +164,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
Log.e(LOG_TAG, "PING JSON ERROR: " + result + " " + e.getMessage()); Log.e(LOG_TAG, "PING JSON ERROR: " + result + " " + e.getMessage());
} }
if (!updated) { if (!updated) {
lastRestfullSynchro = new Date().getTime(); nextRestfullSynchro = new Date().getTime();
updated = true; updated = true;
if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada
// Comprobar si hay usuario offline, para hacer login transparente // Comprobar si hay usuario offline, para hacer login transparente
...@@ -183,13 +183,13 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -183,13 +183,13 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
//cada restfullSynchroTimming aprox. se fuerza sincronización de vocabulario y configuración de usuario //cada restfullSynchroTimming aprox. se fuerza sincronización de vocabulario y configuración de usuario
long now = new Date().getTime(); long now = new Date().getTime();
if (PCBcontext.is_user_logged()) { if (PCBcontext.is_user_logged()) {
if (restfullSynchroTimming > 0 && (now - lastRestfullSynchro > restfullSynchroTimming)) { if (restfullSynchroTimming > 0 && (now>= nextRestfullSynchro)) {
Log.i(LOG_TAG, "Vocabulary request."); Log.i(LOG_TAG, "Vocabulary request.");
PCBcontext.getVocabulary().synchronize(); PCBcontext.getVocabulary().synchronize();
synchronizeStudentAttributes(); synchronizeStudentAttributes();
lastRestfullSynchro = now; nextSynchro(now+restfullSynchroTimming);
} }
} else lastRestfullSynchro = new Date().getTime(); } else nextSynchro(now+restfullSynchroTimming);
} }
} }
...@@ -206,6 +206,13 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -206,6 +206,13 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
} }
} }
public void nextSynchro(long next) {
nextRestfullSynchro = next;
}
public long getSynchroTimingLength(){
return restfullSynchroTimming;
}
private void synchronizeStudentAttributes() { private void synchronizeStudentAttributes() {
int id=PCBcontext.getPcbdb().getCurrentUser().get_id_stu(); int id=PCBcontext.getPcbdb().getCurrentUser().get_id_stu();
PCBcontext.getRestapiWrapper().ask("stu/" + id, new RestapiWrapper.iRestapiListener() { PCBcontext.getRestapiWrapper().ask("stu/" + id, new RestapiWrapper.iRestapiListener() {
......
...@@ -4,10 +4,13 @@ import android.util.Log; ...@@ -4,10 +4,13 @@ import android.util.Log;
import com.github.nkzawa.emitter.Emitter; import com.github.nkzawa.emitter.Emitter;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Date;
/** /**
* Websocket Vocabulary Room based on Room * Websocket Vocabulary Room based on Room
* @author Fernando Martinez Santiago * @author Fernando Martinez Santiago
...@@ -50,7 +53,7 @@ public class VocabularyTalk implements Emitter.Listener { ...@@ -50,7 +53,7 @@ public class VocabularyTalk implements Emitter.Listener {
JSONObject picto_stupicto = stu_picto.optJSONObject(param_picto); JSONObject picto_stupicto = stu_picto.optJSONObject(param_picto);
int picto_id = picto_stupicto.getInt(param_picto_id); int picto_id = picto_stupicto.getInt(param_picto_id);
int picto_cat = attrs_stu_picto!=null ? attrs_stu_picto.optInt(param_picto_cat, Picto.NO_CATEGORY) : 0; int picto_cat = attrs_stu_picto!=null ? attrs_stu_picto.optInt(param_picto_cat, Picto.NO_CATEGORY) : 0;
PCBcontext.getNetService().nextSynchro(new Date().getTime()+PCBcontext.getNetService().getSynchroTimingLength()*2); //nos saltamos una sincronización para evitar que llegue antes que los websockets
Log.i(LOG_TAG, "Received message '" + action + Log.i(LOG_TAG, "Received message '" + action +
"' for picto " + picto_id + " (cat " + picto_cat + ", picto: " + picto_stupicto); "' for picto " + picto_id + " (cat " + picto_cat + ", picto: " + picto_stupicto);
for (iVocabularyListener listener: this.listeners) for (iVocabularyListener listener: this.listeners)
......
...@@ -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);
......
...@@ -21,6 +21,7 @@ android { ...@@ -21,6 +21,7 @@ android {
resValue "bool","NotifyAllwaysVisible","false" resValue "bool","NotifyAllwaysVisible","false"
resValue "string", "VersionManagerClass", "com.yottacode.pictogram.supervisor_tablet.net.VersionManager" resValue "string", "VersionManagerClass", "com.yottacode.pictogram.supervisor_tablet.net.VersionManager"
resValue "string","apk","pictograms.apk" resValue "string","apk","pictograms.apk"
resValue "string","google_play_apk","https://play.google.com/store/apps/details?id=com.yottacode.supervisor_tablet"
// signingConfig signingConfigs.config // signingConfig signingConfigs.config
} }
productFlavors { productFlavors {
......
...@@ -26,8 +26,7 @@ public class VersionManager implements iVersionManager { ...@@ -26,8 +26,7 @@ public class VersionManager implements iVersionManager {
public void newVersionAlert(final float version, final Context context, final float vnew) { public void newVersionAlert(final float version, final Context context, final float vnew) {
final SpannableString s = new SpannableString(context.getResources().getString(R.string.server) final SpannableString s = new SpannableString(context.getResources().getString(R.string.google_play_apk));
+ "/" + context.getResources().getString(com.yottacode.pictogram.R.string.apk));
final TextView tx1 = new TextView(context); final TextView tx1 = new TextView(context);
tx1.setText("\t"+context.getResources().getString(R.string.new_version_detail) + tx1.setText("\t"+context.getResources().getString(R.string.new_version_detail) +
......
...@@ -10,7 +10,6 @@ import android.content.DialogInterface; ...@@ -10,7 +10,6 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.Point;
import android.media.Ringtone; import android.media.Ringtone;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
...@@ -538,7 +537,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -538,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;
} }
} }
...@@ -869,7 +868,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -869,7 +868,8 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (p == null) { if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria // No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (getCurrentCategory() != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) { if (getCurrentCategory() != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), currentCategory.get_id()); int cat = getCurrentCategory() != null ? currentCategory.get_id() : Picto.NO_CATEGORY;
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), cat);
} else } else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show(); Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
......
...@@ -71,39 +71,42 @@ public class SessionActivity extends FragmentActivity implements ListInstruction ...@@ -71,39 +71,42 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
} }
private void evaluateMsg(final int msg_pos, final String evaluation_value, final int evaluation_translation, final int evaluation_bitmap) { private void evaluateMsg(final int msg_pos, final String evaluation_value, final int evaluation_translation, final int evaluation_bitmap) {
final SessionFragment sessionFragment = (SessionFragment) getSupportFragmentManager().findFragmentByTag(SessionActivity.FRAGMENT_SESSION); final SessionFragment sessionFragment = (SessionFragment) getSupportFragmentManager().findFragmentByTag(SessionActivity.FRAGMENT_SESSION);
final int currentMsgId=SessionActivity.this.msgs.get(msg_pos); final int currentMsgId=SessionActivity.this.msgs.get(msg_pos);
SessionWrapper.evaluateTry(currentMsgId, msg_pos==this.msgs.size()-1, evaluation_value, new SessionWrapper.iTryUpdated() { if (sessionFragment.get_current_msg_text().trim().length()>0) //no se permiten trys vacios
@Override SessionWrapper.evaluateTry(currentMsgId, msg_pos==this.msgs.size()-1, evaluation_value, new SessionWrapper.iTryUpdated() {
public void update(int next_try_id) { @Override
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),evaluation_bitmap); public void update(int next_try_id) {
sessionFragment.evaluateMsg(bitmap,getString(evaluation_translation),msg_pos); addLogMsg("añadiendo "+ sessionFragment.get_current_msg_text()+".");
addLogMsg("#"+(msg_pos<9 ? "0" : "")+(msg_pos+1)+sessionFragment.get_msg_text(msg_pos)); Bitmap bitmap = BitmapFactory.decodeResource(getResources(),evaluation_bitmap);
if (!msgs.containsValue(next_try_id)) sessionFragment.evaluateMsg(bitmap,getString(evaluation_translation),msg_pos);
new_try(sessionFragment, next_try_id); addLogMsg("#"+(msg_pos<9 ? "0" : "")+(msg_pos+1)+sessionFragment.get_msg_text(msg_pos));
if (evaluation_value!=null && msg_pos==msgs.size()-1){ if (!msgs.containsValue(next_try_id))
SessionWrapper.newTry(id_session, new SessionWrapper.iTryUpdated() { new_try(sessionFragment, next_try_id);
@Override if (evaluation_value!=null && msg_pos==msgs.size()-1){
public void update(int id) { SessionWrapper.newTry(id_session, new SessionWrapper.iTryUpdated() {
int pos_newmsg = sessionFragment.newMsg(); @Override
msgs.put(pos_newmsg, id); public void update(int id) {
addLogMsg(getString(R.string.session_log_newtry)); int pos_newmsg = sessionFragment.newMsg();
} msgs.put(pos_newmsg, id);
addLogMsg(getString(R.string.session_log_newtry));
@Override }
public void error(String error) {
addLogMsg(getString(R.string.session_error)); @Override
} public void error(String error) {
}); addLogMsg(getString(R.string.session_error));
}
});
}
} }
}
@Override @Override
public void error(String error) { public void error(String error) {
addLogMsg(getString(R.string.session_error)+":"+error); addLogMsg(getString(R.string.session_error)+":"+error);
Log.e(LOG_TAG,"server error:"+error+" when updating try "+currentMsgId+" to "+evaluation_value); Log.e(LOG_TAG,"server error:"+error+" when updating try "+currentMsgId+" to "+evaluation_value);
} }
}); });
......
...@@ -98,6 +98,6 @@ public class NetServiceTablet implements NetService.iNetServiceDevice { ...@@ -98,6 +98,6 @@ public class NetServiceTablet implements NetService.iNetServiceDevice {
} }
public void setPictogramActivity(PictogramActivity pictogramActivity) {this.pictogramActivity=pictogramActivity;} public void setPictogramActivity(PictogramActivity pictogramActivity) {this.pictogramActivity=pictogramActivity;}
public void updateUserConfig(User user) { public void updateUserConfig(User user) {
this.pictogramActivity.setConfig(); if (this.pictogramActivity!=null) this.pictogramActivity.setConfig();
} }
} }
...@@ -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,75 +1189,47 @@ module.exports = { ...@@ -1189,75 +1189,47 @@ 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_stu_picto,
* id_picto, *
* attributes: { @see StuPicto.getValidAttributes() }
* @param {response} res * @param {response} res
* { * {
* id: <stu_picto ID>, * stu_picto
* student: <student ID>,
* attributes: {
* id_cat: categoryId or null,
* coord_x: 1 .. 5 or null,
* coord_y: 1 .. 10 or null,
* free_category_coord_x: 0 .. 4 or null,
* free_category_coord_y: 0 .. 9 or null,
* status: '[invisible]/enabled/disabled',
* highlight: true/[false],
* color: any valid HEX color or [null],
* expression: 'custom expression',
* legend: true/[false],
* uri_sound: 'path of sound associated',
* user_avatar:
* },
* picto: {
* id: <pictoID>,
* source: <sourceID>,
* owner: <ownerID> or null,
* id: <pictoID>,
* uri: <URL to image>,
* category: <categoryID>
* }
* }
* } * }
*/ */
upload_sound: function (req, res) { upload_sound: function (req, res) {
Supervisor.findOne({ id: req.body.owner }).then(function (supervisor) { var soundFileName;
var soundFileName; var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory;
var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory; console.log("Llega aqui 1");
if (!supervisor) soundFileName = sails.config.pictogram.paths.getCustomPictoSoundFilename(req.params.id_stu_picto);
throw new Error("No supervisor found"); console.log("Llega aqui 2");
req.file('file').upload({
soundFileName = sails.config.pictogram.paths.getSupervisorCustomPictoFileName(supervisor.id) maxBytes: 1048576,
+ "_sound"; dirname: soundDirectory,
sails.log.debug("Uploading sound with FileName: " + soundFileName); saveAs: soundFileName
}, function whenDone(err, uploadedFiles) {
req.file('file').upload({ console.log("Llega aqui 3");
maxBytes: 1048576, var fs = require('fs');
dirname: soundDirectory,
saveAs: soundFileName if (err || (uploadedFiles.length === 0))
},function whenDone(err, uploadedFiles) { return res.serverError("Error uploading " + err ? err : "");
var fs = require('fs');
console.log("Llega aqui 4");
if (err || (uploadedFiles.length === 0)) StuPicto.findOne({ id: req.params.id_stu_picto})
return res.serverError("Error uploading " + err ? err : ""); .then(sp => {
console.log("Picto encontrado")
StuPicto.findOne({ id: req.body.id}) sp.attributes.uri_sound = soundFileName;
.then(picto => { sp.save(function (err) {
return res.ok(picto); if (err) throw err;
}) return res.ok(sp);
.populate('uri_sound',soundFileName)
.catch(err => {
fs.unlink(uploadedFiles[0].fd);
return res.serverError("Error uploading " + err);
}); });
})
.catch(err => {
fs.unlink(uploadedFiles[0].fd);
return res.serverError("Error uploading " + err);
}); });
})
.catch(function (err) {
return res.serverError("Error uploading sound: " + err);
}); });
}, },
// *************************************************************** // ***************************************************************
// WEBSOCKETS // WEBSOCKETS
// *************************************************************** // ***************************************************************
......
...@@ -591,7 +591,7 @@ module.exports = { ...@@ -591,7 +591,7 @@ module.exports = {
PictoExp.findOne({id_pic: sp.picto.id, lang: sp.student.lang}) PictoExp.findOne({id_pic: sp.picto.id, lang: sp.student.lang})
.then(pe => { .then(pe => {
if (typeof sp.attributes.expression == 'undefined' || sp.attributes.expression == null) if (typeof sp.attributes.expression == 'undefined' || sp.attributes.expression == null)
sp.attributes.expression = pe.text; sp.attributes.expression = pe.text;
sp.student = sp.student.id; sp.student = sp.student.id;
delete sp.picto.expressions; delete sp.picto.expressions;
cb(null,sp); cb(null,sp);
......
...@@ -51,10 +51,10 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -51,10 +51,10 @@ dashboardControllers.controller('AddPictoCtrl', function (
var request = ""; var request = "";
if(categoryId == 0){ if(categoryId == 0){
//Request page X from all pictos (symbolstx) //Request page X from all pictos (symbolstx)
request = config.backend + '/sup/' + supervisor.id + request = config.backend + '/picto/' + student.lang +
'/pic_fromSymbolStx/page/'+$scope.page+'/limit/'+$scope.limit; '/pic_fromSymbolStx/page/'+$scope.page+'/limit/'+$scope.limit;
}else{ }else{
request = config.backend + '/sup/' + supervisor.id + request = config.backend + '/picto/' + student.lang +
'/pic_fromCatSubcat/category/'+categoryId+'/page/'+$scope.page+'/limit/'+$scope.limit; '/pic_fromCatSubcat/category/'+categoryId+'/page/'+$scope.page+'/limit/'+$scope.limit;
} }
$http.get(request) $http.get(request)
...@@ -96,7 +96,7 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -96,7 +96,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
var request = ""; var request = "";
//Request page X from all pictos (symbolstx) //Request page X from all pictos (symbolstx)
request = config.backend + '/sup/' + supervisor.id + request = config.backend + '/picto/' + student.lang +
'/pic_fromArasaac/page/'+$scope.page+'/limit/'+$scope.limit; '/pic_fromArasaac/page/'+$scope.page+'/limit/'+$scope.limit;
$http.get(request) $http.get(request)
...@@ -142,7 +142,7 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -142,7 +142,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
// //
$scope.load_category = function (categoryId){ $scope.load_category = function (categoryId){
$scope.page = 1; $scope.page = 1;
$http.get(config.backend+'/sup/'+ supervisor.id +'/pic_categories/' + categoryId) $http.get(config.backend + '/picto/' + student.lang + '/pic_categories/' + categoryId)
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Add to list // Add to list
if (data && $scope.source == 'symbolstx'){ if (data && $scope.source == 'symbolstx'){
...@@ -335,16 +335,16 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -335,16 +335,16 @@ dashboardControllers.controller('AddPictoCtrl', function (
if($scope.source == "symbolstx"){ if($scope.source == "symbolstx"){
if($scope.breadcrumbs.length == 1) { if($scope.breadcrumbs.length == 1) {
//Request page X from all pictos (symbolstx) //Request page X from all pictos (symbolstx)
request = config.backend + '/sup/' + supervisor.id + request = config.backend + '/picto/' + student.lang +
'/pic_fromSymbolStx/page/'+$scope.page+'/limit/'+$scope.limit; '/pic_fromSymbolStx/page/'+$scope.page+'/limit/'+$scope.limit;
}else{ }else{
request = config.backend + '/sup/' + supervisor.id + request = config.backend + '/picto/' + student.lang +
'/pic_fromCatSubcat/category/'+$scope.breadcrumbs[$scope.breadcrumbs.length-1].id '/pic_fromCatSubcat/category/'+$scope.breadcrumbs[$scope.breadcrumbs.length-1].id
+'/page/'+$scope.page+'/limit/'+$scope.limit; +'/page/'+$scope.page+'/limit/'+$scope.limit;
} }
}else if($scope.source == "arasaac"){ }else if($scope.source == "arasaac"){
//Request page X from all pictos (symbolstx) //Request page X from all pictos (symbolstx)
request = config.backend + '/sup/' + supervisor.id + request = config.backend + '/picto/' + student.lang +
'/pic_fromArasaac/page/'+$scope.page+'/limit/'+$scope.limit; '/pic_fromArasaac/page/'+$scope.page+'/limit/'+$scope.limit;
} }
...@@ -399,7 +399,7 @@ dashboardControllers.controller('AddPictoCtrl', function ( ...@@ -399,7 +399,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
}else if($scope.source == "arasaac"){ }else if($scope.source == "arasaac"){
source = 3; source = 3;
} }
request = config.backend + '/sup/' + supervisor.id + request = config.backend + '/picto/' + student.lang + '/' + supervisor.id +
'/pic_fromSearch/'+$scope.srch_term_picto+'/category/'+category+ '/pic_fromSearch/'+$scope.srch_term_picto+'/category/'+category+
'/source/'+source; '/source/'+source;
......
...@@ -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
*/
getCustomPictoSoundFilename: 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,
......
...@@ -105,7 +105,7 @@ module.exports.policies = { ...@@ -105,7 +105,7 @@ module.exports.policies = {
login: true, login: true,
create: ['tokenAuth', 'isSupAdmin'], create: ['tokenAuth', 'isSupAdmin'],
upload: ['tokenAuth'], upload: ['tokenAuth'],
upload_sound: ['tokenAuth', 'isSupervisorOfStudent'], upload_sound: ['tokenAuth'],
add_picto: ['tokenAuth', 'isSupervisorOfStudent'], add_picto: ['tokenAuth', 'isSupervisorOfStudent'],
subscribe: ['tokenAuth'], subscribe: ['tokenAuth'],
unsubscribe: true, unsubscribe: true,
......
...@@ -59,6 +59,13 @@ module.exports.routes = { ...@@ -59,6 +59,13 @@ module.exports.routes = {
'GET /office/get/:id': 'OfficeController.get', 'GET /office/get/:id': 'OfficeController.get',
'GET /office/get/:id/supervisors': 'OfficeController.supervisors', 'GET /office/get/:id/supervisors': 'OfficeController.supervisors',
'GET /picto/:lang/pic_categories/:id_cat': 'PictoController.categories',
'GET /picto/:lang/pic_fromcategory/:id_cat': 'PictoController.fromcategory',
'GET /picto/:lang/pic_fromSymbolStx/page/:page/limit/:limit': 'PictoController.fromSymbolStx',
'GET /picto/:lang/pic_fromArasaac/page/:page/limit/:limit': 'PictoController.fromArasaac',
'GET /picto/:lang/pic_fromCatSubcat/category/:id_cat/page/:page/limit/:limit': 'PictoController.fromCatSubcat',
'GET /picto/:lang/:id_sup/pic_fromSearch/:text/category/:id_cat/source/:source': 'PictoController.fromSearch',
'POST /picto/upload': 'PictoController.upload', 'POST /picto/upload': 'PictoController.upload',
'POST /picto/tag': 'PictoController.add_tag', 'POST /picto/tag': 'PictoController.add_tag',
'POST /picto/exp': 'PictoController.change_exp', 'POST /picto/exp': 'PictoController.change_exp',
...@@ -74,6 +81,7 @@ module.exports.routes = { ...@@ -74,6 +81,7 @@ module.exports.routes = {
'GET /stu/:id_stu/tutors': 'StudentController.tutors', 'GET /stu/:id_stu/tutors': 'StudentController.tutors',
'POST /stu/:id_stu/sup/:id_sup': 'StudentController.link_supervisor', 'POST /stu/:id_stu/sup/:id_sup': 'StudentController.link_supervisor',
'GET /stu/:id_stu/pictos': 'StudentController.pictos', 'GET /stu/:id_stu/pictos': 'StudentController.pictos',
'GET /stu/:id_stu/methods': 'StudentController.methods', 'GET /stu/:id_stu/methods': 'StudentController.methods',
'GET /stu/:id_stu/lasttries': 'StudentController.lasttries', 'GET /stu/:id_stu/lasttries': 'StudentController.lasttries',
'GET /stu/:id_stu/tries': 'StudentController.tries', 'GET /stu/:id_stu/tries': 'StudentController.tries',
...@@ -87,7 +95,7 @@ module.exports.routes = { ...@@ -87,7 +95,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/upload/:id_stu_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',
...@@ -105,12 +113,7 @@ module.exports.routes = { ...@@ -105,12 +113,7 @@ module.exports.routes = {
'GET /sup/all': 'SupervisorController.list', 'GET /sup/all': 'SupervisorController.list',
'GET /sup/:id/students': 'SupervisorController.students', 'GET /sup/:id/students': 'SupervisorController.students',
'GET /sup/:id/pictos': 'SupervisorController.pictos', 'GET /sup/:id/pictos': 'SupervisorController.pictos',
'GET /sup/:id/pic_categories/:id_cat': 'PictoController.categories',
'GET /sup/:id/pic_fromcategory/:id_cat': 'PictoController.fromcategory',
'GET /sup/:id/pic_fromSymbolStx/page/:page/limit/:limit': 'PictoController.fromSymbolStx',
'GET /sup/:id/pic_fromArasaac/page/:page/limit/:limit': 'PictoController.fromArasaac',
'GET /sup/:id/pic_fromCatSubcat/category/:id_cat/page/:page/limit/:limit': 'PictoController.fromCatSubcat',
'GET /sup/:id/pic_fromSearch/:text/category/:id_cat/source/:source': 'PictoController.fromSearch',
'GET /sup/email/:email': 'SupervisorController.getByEmail', 'GET /sup/email/:email': 'SupervisorController.getByEmail',
'GET /sup/changepass/:email': 'SupervisorController.request_change_password', 'GET /sup/changepass/:email': 'SupervisorController.request_change_password',
'GET /sup/arasaac_license/:id': 'SupervisorController.accept_arasaac', 'GET /sup/arasaac_license/:id': 'SupervisorController.accept_arasaac',
......
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