Commit eabea625 by Arturo Montejo Ráez

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

parents 0d43cf5f e3b77e36
......@@ -145,7 +145,14 @@ public class RestapiWrapper {
if (Character.isAlphabetic(response.charAt(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 {
JSONresponse = new JSONObject("{ "+SERVER_RESULT+": " + response + (responseCode == HttpURLConnection.HTTP_OK
? "}"
......@@ -154,7 +161,7 @@ public class RestapiWrapper {
JSONresponse = null;
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;
}
......
......@@ -135,8 +135,8 @@ public class Vocabulary implements Iterable<Picto> {
private boolean synchronize_upload() {
boolean upload_pending=false;
try {
this.pictos.clear();
PCBcontext.getPcbdb().getStudentVocabulary(this);
if (this.pictos.isEmpty())
PCBcontext.getPcbdb().getStudentVocabulary(this);
} catch (JSONException e) {
Log.e(this.getClass().getName(), " Picto json error from local storage: " + e.getMessage());
}
......@@ -254,7 +254,7 @@ public class Vocabulary implements Iterable<Picto> {
pictos_cat = new LinkedList<>();
pictos.put(new Integer(picto.get_category()),pictos_cat);
}
pictos_cat.add(picto);
imgs.add(new Img(picto.get_id(), picto.get_url(), Img.VOCABULARY));
}
Log.d(this.getClass().getName(), "Vocabulary size: " + updated_collection.length);
......
......@@ -39,7 +39,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
private Vector<iNetServiceStatus> listeners;
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) {
this.updated=RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session);
......@@ -164,7 +164,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
Log.e(LOG_TAG, "PING JSON ERROR: " + result + " " + e.getMessage());
}
if (!updated) {
lastRestfullSynchro = new Date().getTime();
nextRestfullSynchro = new Date().getTime();
updated = true;
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
......@@ -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
long now = new Date().getTime();
if (PCBcontext.is_user_logged()) {
if (restfullSynchroTimming > 0 && (now - lastRestfullSynchro > restfullSynchroTimming)) {
if (restfullSynchroTimming > 0 && (now>= nextRestfullSynchro)) {
Log.i(LOG_TAG, "Vocabulary request.");
PCBcontext.getVocabulary().synchronize();
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 {
}
}
public void nextSynchro(long next) {
nextRestfullSynchro = next;
}
public long getSynchroTimingLength(){
return restfullSynchroTimming;
}
private void synchronizeStudentAttributes() {
int id=PCBcontext.getPcbdb().getCurrentUser().get_id_stu();
PCBcontext.getRestapiWrapper().ask("stu/" + id, new RestapiWrapper.iRestapiListener() {
......
......@@ -4,10 +4,13 @@ import android.util.Log;
import com.github.nkzawa.emitter.Emitter;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Date;
/**
* Websocket Vocabulary Room based on Room
* @author Fernando Martinez Santiago
......@@ -50,7 +53,7 @@ public class VocabularyTalk implements Emitter.Listener {
JSONObject picto_stupicto = stu_picto.optJSONObject(param_picto);
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;
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 +
"' for picto " + picto_id + " (cat " + picto_cat + ", picto: " + picto_stupicto);
for (iVocabularyListener listener: this.listeners)
......
......@@ -21,6 +21,7 @@ android {
resValue "bool","NotifyAllwaysVisible","false"
resValue "string", "VersionManagerClass", "com.yottacode.pictogram.supervisor_tablet.net.VersionManager"
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
}
productFlavors {
......
......@@ -26,8 +26,7 @@ public class VersionManager implements iVersionManager {
public void newVersionAlert(final float version, final Context context, final float vnew) {
final SpannableString s = new SpannableString(context.getResources().getString(R.string.server)
+ "/" + context.getResources().getString(com.yottacode.pictogram.R.string.apk));
final SpannableString s = new SpannableString(context.getResources().getString(R.string.google_play_apk));
final TextView tx1 = new TextView(context);
tx1.setText("\t"+context.getResources().getString(R.string.new_version_detail) +
......
......@@ -71,40 +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) {
final SessionFragment sessionFragment = (SessionFragment) getSupportFragmentManager().findFragmentByTag(SessionActivity.FRAGMENT_SESSION);
final int currentMsgId=SessionActivity.this.msgs.get(msg_pos);
SessionWrapper.evaluateTry(currentMsgId, msg_pos==this.msgs.size()-1, evaluation_value, new SessionWrapper.iTryUpdated() {
@Override
public void update(int next_try_id) {
addLogMsg("añadiendo "+ sessionFragment.get_current_msg_text()+".");
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),evaluation_bitmap);
sessionFragment.evaluateMsg(bitmap,getString(evaluation_translation),msg_pos);
addLogMsg("#"+(msg_pos<9 ? "0" : "")+(msg_pos+1)+sessionFragment.get_msg_text(msg_pos));
if (!msgs.containsValue(next_try_id))
new_try(sessionFragment, next_try_id);
if (evaluation_value!=null && msg_pos==msgs.size()-1){
SessionWrapper.newTry(id_session, new SessionWrapper.iTryUpdated() {
@Override
public void update(int id) {
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));
}
});
if (sessionFragment.get_current_msg_text().trim().length()>0) //no se permiten trys vacios
SessionWrapper.evaluateTry(currentMsgId, msg_pos==this.msgs.size()-1, evaluation_value, new SessionWrapper.iTryUpdated() {
@Override
public void update(int next_try_id) {
addLogMsg("añadiendo "+ sessionFragment.get_current_msg_text()+".");
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),evaluation_bitmap);
sessionFragment.evaluateMsg(bitmap,getString(evaluation_translation),msg_pos);
addLogMsg("#"+(msg_pos<9 ? "0" : "")+(msg_pos+1)+sessionFragment.get_msg_text(msg_pos));
if (!msgs.containsValue(next_try_id))
new_try(sessionFragment, next_try_id);
if (evaluation_value!=null && msg_pos==msgs.size()-1){
SessionWrapper.newTry(id_session, new SessionWrapper.iTryUpdated() {
@Override
public void update(int id) {
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)+":"+error);
Log.e(LOG_TAG,"server error:"+error+" when updating try "+currentMsgId+" to "+evaluation_value);
}
});
@Override
public void error(String error) {
addLogMsg(getString(R.string.session_error)+":"+error);
Log.e(LOG_TAG,"server error:"+error+" when updating try "+currentMsgId+" to "+evaluation_value);
}
});
......
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
......@@ -13,6 +13,11 @@ Changes to be performed manually in servers to upgrade
## Database
- update arasaac uri
`source update_arasaac_color_uri.sql`
- add B&W arasaac pictos
`source arasaac_byn.sql`
(already done in dev & pre)
- add arasaac to source table
......
......@@ -352,7 +352,7 @@ module.exports = {
var l = [];
var fs = require('fs');
Picto.find({ source: 3})
Picto.find({ source: req.params.source})
.paginate({page: req.params.page, limit:req.params.limit})
.populate('expressions', { lang: req.params.lang })
.then(function (pictos) {
......
......@@ -1189,70 +1189,41 @@ module.exports = {
/**
* Upload a custom sound associated to a picto
* @param {request} req
* id_sup,
* id_picto,
* id_stu_picto,
*
* @param {response} res
* {
* id: <stu_picto ID>,
* 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>
* }
* }
* stu_picto
* }
*/
upload_sound: function (req, res) {
console.log("sup id: " + req.params.id_supervisor );
Supervisor.findOne({ id: req.params.id_supervisor }).then(function (supervisor) {
var soundFileName;
var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory;
if (!supervisor)
throw new Error("No supervisor found");
soundFileName = sails.config.pictogram.paths.getSupervisorCustomPictoSoundFilename(supervisor.id);
req.file('file').upload({
maxBytes: 1048576,
dirname: soundDirectory,
saveAs: soundFileName
},function whenDone(err, uploadedFiles) {
var fs = require('fs');
if (err || (uploadedFiles.length === 0))
return res.serverError("Error uploading " + err ? err : "");
StuPicto.findOne({ id: req.body.id})
.then(picto => {
return res.ok(picto);
})
.catch(err => {
fs.unlink(uploadedFiles[0].fd);
return res.serverError("Error uploading " + err);
var soundFileName;
var soundDirectory = sails.config.pictogram.paths.pictoSoundDirectory;
soundFileName = sails.config.pictogram.paths.getCustomPictoSoundFilename(req.params.id_stu_picto);
req.file('file').upload({
maxBytes: 1048576,
dirname: soundDirectory,
saveAs: soundFileName
}, function whenDone(err, uploadedFiles) {
var fs = require('fs');
if (err || (uploadedFiles.length === 0))
return res.serverError("Error uploading " + err ? err : "");
StuPicto.findOne({ id: req.params.id_stu_picto })
.then((sp) => {
if (!sp)
throw Error("Not found");
sp.attributes.uri_sound = soundFileName;
sp.save(function (err) {
if (err) throw err;
return res.ok(sp);
});
})
.catch(err => {
fs.unlink(uploadedFiles[0].fd);
return res.serverError("Error uploading " + err);
});
})
.catch(function (err) {
return res.serverError("Error uploading sound: " + err);
});
},
......
......@@ -137,8 +137,8 @@ module.exports = {
if (!((/^#([0-9a-f]{3}){1,2}$/i).test(validAttributes.color))) {
delete validAttributes.color;
}
if (typeof validAttributes.sound_uri!== 'string') {
delete validAttributes.sound_uri;
if (typeof validAttributes.uri_sound!== 'string') {
delete validAttributes.uri_sound;
}
if (typeof validAttributes.user_avatar !== 'string') {
delete validAttributes.user_avatar;
......
......@@ -30,7 +30,7 @@
"apply":"Apply",
"annual": "Annual",
"April": "April",
"arasaac_license": "Los símbolos pictográficos utilizados en esta sección son propiedad de CATEDU (http://arasaac.org/) bajo licencia Creative Commons y han sido creados por Sergio Palao.",
"arasaac_license": "The pictographic symbols used in this section are the property of CATEDU (http://arasaac.org/) under a Creative Commons license and have been created by Sergio Palau.",
"arasaac_license_import": "The pictographic symbols used in this section are the property of CATEDU (http://arasaac.org/) under a Creative Commons license and have been created by Sergio Palau. By importing you accept the ",
"arasaac_license_import2": "terms of use",
"arasaac_license_link": "http://www.arasaac.org/condiciones_uso.php",
......@@ -43,6 +43,7 @@
"background": "Background",
"beep": "Beep",
"birthdate": "Birthdate",
"black_and_white": "B&W",
"cancel": "Cancel",
"cannot_delete_method": "Method could not be deleted, maybe due to existing recorded sessions.",
"cannot_delete_instruction": "Instruction could not be deleted, maybe due to existing recorded sessions.",
......
......@@ -43,6 +43,7 @@
"background": "Fondo",
"beep": "Pitido",
"birthdate": "Fecha de nacimiento",
"black_and_white": "ByN",
"cancel": "Cancelar",
"cannot_delete_method": "No se pudo eliminar el método, tal vez porque existen sesiones asociadas.",
"cannot_delete_instruction": "No se pudo eliminar la instrucción, tal vez porque existen sesiones asociadas.",
......
......@@ -94,10 +94,9 @@ dashboardControllers.controller('AddPictoCtrl', function (
if(!$scope.showArasaacLicense){
$scope.loadingCatPictos = true;
var request = "";
//Request page X from all pictos (symbolstx)
request = config.backend + '/picto/' + student.lang +
'/pic_fromArasaac/page/'+$scope.page+'/limit/'+$scope.limit;
'/pic_fromArasaac/page/'+$scope.page+'/limit/'+$scope.limit+'/source/3';
$http.get(request)
.success(function (data) {
......@@ -116,6 +115,34 @@ dashboardControllers.controller('AddPictoCtrl', function (
}
};
$scope.load_arasaac_byn_pictos = function () {
$scope.pictos = [];
$scope.page = 1;
if(!$scope.showArasaacLicense){
$scope.loadingCatPictos = true;
var request = "";
//Request page X from all pictos (symbolstx)
request = config.backend + '/picto/' + student.lang +
'/pic_fromArasaac/page/'+$scope.page+'/limit/'+$scope.limit+'/source/4';
$http.get(request)
.success(function (data) {
if (data && $scope.source == 'arasaac_byn'){
$scope.pictos = data;
}
$scope.loadingCatPictos = false;
setTimeout(function () { $scope.$apply(); });
})
.error(function () {
$translate('error_loading_pictos').then(function (translation) {
ngToast.danger({ content: translation });
});
$scope.loadingCatPictos = false;
});
}
};
//
// Load pictos owned by the actual supervisor
//
......
......@@ -16,7 +16,7 @@
<div class="row">
<div class="col-xs-6">
<div class="col-xs-8">
<div class="btn-group" ng-show="!onlyOwn">
<button class="btn btn-default" btn-radio="'symbolstx'" ng-model="source" ng-click="open_category_from_bc('0')">
<span class="glyphicon glyphicon-th"></span> SymbolStix
......@@ -24,6 +24,9 @@
<button class="btn btn-default" btn-radio="'arasaac'" ng-model="source" ng-click="load_arasaac_pictos()">
<i class="fa fa-th" aria-hidden="true"></i> ARASAAC
</button>
<button class="btn btn-default" btn-radio="'arasaac_byn'" ng-model="source" ng-click="load_arasaac_byn_pictos()">
<i class="fa fa-th" aria-hidden="true"></i> ARASAAC {{ 'black_and_white' | translate}}
</button>
<button class="btn btn-default" btn-radio="'ownpictos'" ng-model="source" ng-click="load_own_pictos()">
<span class="glyphicon glyphicon-picture"></span> {{ 'own_pictos' | translate }}
</button>
......@@ -31,7 +34,7 @@
</div>
<!-- Filter form -->
<div class="col-xs-6">
<div class="col-xs-4">
<form ng-submit="search()">
<div class="input-group" id="search_pictos_box">
<input type="text" class="form-control" placeholder="{{ 'filter' | translate }}"
......@@ -75,7 +78,7 @@
<!-- Collections row -->
<div class="row">
<div id="arasaac_agreement" class="col-md-12" ng-show="showArasaacLicense && source == 'arasaac'">
<div id="arasaac_agreement" class="col-md-12" ng-show="showArasaacLicense && (source == 'arasaac' || source == 'arasaac_byn')">
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title">ARASAAC</h3>
......@@ -119,7 +122,7 @@
</div><!-- /modal-body -->
<div class="modal-footer">
<div class="arasaac_license" ng-show="source == 'arasaac'">
<div class="arasaac_license" ng-show="source == 'arasaac' || source == 'arasaac_byn'">
<p><small>{{'arasaac_license' | translate}}</small></p>
</div>
<button class="btn btn-success pull-left" ng-show="source == 'ownpictos'" ngf-select ng-model="picFile" accept="image/*" ngf-change="addOwnPicto()">
......
......@@ -129,7 +129,7 @@ module.exports.pictogram = {
* @param {supervisorId} supervisorId supervisorId
* @return {string} fileName
*/
getSupervisorCustomPictoSoundFilename: function (supervisorId) {
getCustomPictoSoundFilename: function (supervisorId) {
return sails.config.pictogram.paths._getRandomSoundFileName(
'SUPERVISOR_CUSTOM_PICTO',
supervisorId
......
......@@ -105,7 +105,7 @@ module.exports.policies = {
login: true,
create: ['tokenAuth', 'isSupAdmin'],
upload: ['tokenAuth'],
upload_sound: ['tokenAuth', 'isSupervisorOfStudent'],
upload_sound: ['tokenAuth'],
add_picto: ['tokenAuth', 'isSupervisorOfStudent'],
subscribe: ['tokenAuth'],
unsubscribe: true,
......
......@@ -62,7 +62,7 @@ module.exports.routes = {
'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_fromArasaac/page/:page/limit/:limit/source/:source': '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',
......@@ -95,7 +95,7 @@ module.exports.routes = {
'POST /stu/login': 'StudentController.login',
'POST /stu': 'StudentController.create',
'POST /stu/upload': 'StudentController.upload',
'POST /stu/:id_sup/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/subscribe': 'StudentController.subscribe',
'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