Commit 01bcb078 by Sebastián Collado Montañez

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

parents a3958968 8892d4de
......@@ -78,7 +78,7 @@ public class Vocabulary implements Iterable<Picto> {
modifyAttsPicto(picto_cat, picto_id, args.getJSONObject("attributes"));
} catch (JSONException e) {
e.printStackTrace();
Log.e(LOG_TAG,e.getMessage());
Log.e(LOG_TAG,"Error updating picto:"+e.getMessage());
}
break;
}
......@@ -457,7 +457,7 @@ public class Vocabulary implements Iterable<Picto> {
});
} catch (Exception e) {
e.printStackTrace();
Log.e(Vocabulary.class.getCanonicalName(), e.getMessage());
Log.e(Vocabulary.class.getCanonicalName(), "Error saving picto:"+e.getMessage());
}
}
......
......@@ -102,10 +102,10 @@ public class PictoUploader {
boolean success;
Response<JsonObject> response=null;
String [] path = audioFile.getPath().split("\\.");
String extension = path[1];
if (extension != "mp3")
String extension = audioFile.getName().substring(audioFile.getName().lastIndexOf('.')+1);
if (!extension.equalsIgnoreCase("mp3"))
throw new UnsupportedEncodingException("Extension "+extension+" is not supported. Only mp3 files");
Ion ion = Ion.getDefault(PCBcontext.getContext());
......@@ -114,7 +114,7 @@ public class PictoUploader {
response=ion.with(PCBcontext.getContext())
.load("POST", PCBcontext.getContext().getResources().getString(R.string.server) + "/picto/upload_sound/"+picto.get_stupicto_id())
.setMultipartParameter("filename", "id_del _sonido")
.setMultipartParameter("filename", audioFile.getName())
.setMultipartParameter("extension", "mp3")
.setMultipartParameter("owner", Integer.toString(PCBcontext.getPcbdb().getCurrentUser().get_id_sup()))
.setMultipartParameter("folder", "pictoSound")
......@@ -138,7 +138,7 @@ public class PictoUploader {
success=false;
Log.i(LOG_TAG, "Uploaded Sound failed ");
if (response != null)
Log.i(LOG_TAG, "Uploaded Sound failed, headers: " + response.getHeaders());
Log.i(LOG_TAG, "Uploaded Sound failed, headers: " + response.getHeaders().message()+"("+response.getHeaders().code()+")");
}
} catch (InterruptedException e) {
Log.e(LOG_TAG, "Sound upload error: " + e.getMessage()+ "Code: "+
......@@ -300,14 +300,15 @@ public class PictoUploader {
if (imgUpload_success){
if(this.picto.getUriSound() != "" && this.picto.getUriSound() != null ){ //Si el picto tiene audio en local
Log.i("TAG_PRUEBAS","Hay uri: "+this.picto.getUriSound()+" -Procede a subir archivo");
Log.i(LOG_TAG,"Uploading sound "+this.picto.getUriSound());
File file = new File(picto.getUriSound()); //Obtengo el fichero de audio local
boolean soundUpload_success = uploadSound(file); //Llamo a la subida
if(soundUpload_success) {
Log.i("TAG_PRUEBAS","Se sube sonido hay EXITO");
Log.i(LOG_TAG,"Sound uploaded");
}else {
GUITools.show_alert(PCBcontext.getActivityContext(),Integer.parseInt(R.string.upload_error+"Audio"), PictoUploader.this.picto.get_translation());
Log.e(LOG_TAG, "Uploading sound error");
GUITools.show_alert(PCBcontext.getActivityContext(),R.string.upload_error, PictoUploader.this.picto.get_translation());
}
}
if (stupicto_id!=Picto.STUPICTO_NULL) {
......
......@@ -26,6 +26,7 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
......@@ -38,7 +39,6 @@ import android.widget.TextView;
import android.widget.Toast;
import com.yottacode.pictogram.dao.Picto;
import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.tabletlibrary.R;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.BotonCircular;
import com.yottacode.pictogram.tabletlibrary.gui.communicator.PictoMenu;
......@@ -55,7 +55,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Random;
import java.util.Vector;
import pl.droidsonroids.gif.GifTextView;
......@@ -225,6 +224,7 @@ public class EditPictoActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
setContentView(R.layout.edit_picto_layout);
//Persmisos para grabar audio
......
......@@ -117,6 +117,50 @@ module.exports = {
});
},
/**
* Copies a scene with its stu_pictos
* @param {request} req {} (id of source scene)
*/
duplicate: function(req,res){
Scene.findOne({id:req.params.id})
.populate('stuPictos').then(function(scene){
Scene.create({
name: scene.name,
active: false,
categories: scene.categories,
supervisor: scene.supervisor,
student: scene.student
}).then(scene=>{
async.forEach(scene.stuPictos, function (stuPicto, cb) {
StuPicto.create({
student: stuPicto.student,
picto: stuPicto.picto,
scene: scene.id,
attributes: stuPicto.attributes
}).catch(function (err){
console.log("Error creating stu_picto "+err.details);
sails.log.error(err.details);
});
},
function (err) { // function called when loop is done
if (err) {
console.log(err.details);
sails.log.error(err.details);
return res.json({
'error': err.details
});
} else
return res.ok(scene);
});
}).catch(function (err){
return res.serverError("Error creating scene: " + err);
});
});
},
//
// Logs a scene action and broadcast to anyone subscribed to this student
scene: function (req, res) {
......
......@@ -892,8 +892,9 @@ module.exports = {
/**
* Add an existing picto to the student's collection
* @param {request} req (with id_stu and id_picto as url parameters)
* @param {request} req (with id_scene,id_stu and id_picto as url parameters)
* {
* id_scene,
* id_stu,
* id_picto,
* attributes: { @see StuPicto.getValidAttributes() }
......@@ -928,7 +929,7 @@ module.exports = {
add_picto: function (req, res) {
var params = req.allParams();
StuPicto.find({id_pic: params.id_picto, id_stu: params.id_stu})
StuPicto.find({id_pic: params.id_picto, id_stu: params.id_stu, id_scene:params.id_scene})
.then((entries) => {
if (entries && entries.length > 0) {
var err = new Error("Picto already in student's vocabulary");
......
......@@ -56,7 +56,6 @@ module.exports = {
pictos: function(id_scene, callback) {
var l = [];
var fs = require('fs');
console.log("metodo pictos scene");
Scene.findOne(id_scene)
.then((scene) => {
if (!scene)
......
......@@ -120,26 +120,19 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
}
};
// Reload student pictos (back from addpicto)
$scope.loadPictos = function (scene) {
// Fill with grid (if not done before)
$scope.freeCategoryPictos = $scope.freeCategoryPictos || generateGrid();
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] =
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] || generateGrid();
scene.pictos.forEach(placePicto);
$scope.loadingPictos = false;
};
// get active scene
$scope.showActiveScene = function (scene) {
$scope.loadingPictos = true;
$scope.freeCategoryPictos = $scope.freeCategoryPictos || generateGrid();
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] =
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] || generateGrid();
$http.get(config.backend + '/stu/' + $scope.studentData.id + '/activeScene')
.success(function (activeScene) {
$scope.showFreeCategory = !activeScene.categories;
$scope.viewingScene = activeScene;
$scope.loadPictos(activeScene);
activeScene.pictos.forEach(placePicto);
$scope.loadingPictos = false;
//setTimeout(function () { $scope.$apply(); });
})
.error(function () {
......@@ -151,12 +144,17 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// get active scene
$scope.showScene = function (idScene) {
$scope.loadingPictos = true;
$scope.freeCategoryPictos = $scope.freeCategoryPictos || generateGrid();
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] =
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] || generateGrid();
$http.get(config.backend + '/scene/' + idScene)
.success(function (scene) {
$scope.showFreeCategory = !scene.categories;
$scope.viewingScene = scene;
$scope.loadPictos(scene);
scene.pictos.forEach(placePicto);
$scope.loadingPictos = false;
//setTimeout(function () { $scope.$apply(); });
})
.error(function () {
......@@ -219,28 +217,43 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
});
};
// Delete student picto
// Delete student scene, if is not active
//If scene is viewingScene, load activeScene
$scope.delete_scene = function (idScene) {
var active = false;
var viewing = idScene == $scope.viewingScene.id;
for(var i=0; i<$scope.scenesList; i++){
if($scope.scenesList[i].id == idScene){
active=$scope.scenesList[i].active;
}
}
$translate('confirmation').then(t => {
if ($window.confirm(t)) {
$http.delete(config.backend + '/scene/' + idScene)
.success(function () {
// io.socket.post('/stu/vocabulary', {
// action: 'delete',
// attributes: {
// id_stu: $scope.studentData.id,
// id_scene: $scope.viewingScene.id,
// stu_picto: studentPicto
// }
// }, function () {});
//
// $translate('picto_removed').then(function (translation) {
// ngToast.success({ content: translation });
// });
}).error(function () {});
if(!active){
$http.delete(config.backend + '/scene/' + idScene)
.success(function () {
io.socket.post('/scene', {
action: 'delete',
data: {id:idScene}
}, function () {});
if(viewing){
$scope.showActiveScene();
}
$scope.loadScenesList();
$translate('scene_deleted').then(function (translation) {
ngToast.success({ content: translation });
});
}).error(function () {
$translate('scene_already_deleted').then(function (translation) {
ngToast.warning({ content: translation });
});
});
}else{
$translate('cant_delete_active_scene').then(function (translation) {
ngToast.warning({ content: translation });
});
}
}
});
};
......@@ -248,7 +261,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// Delete student picto
$scope.update_scene = function (scene) {
$http.put(config.backend + '/scene/' + idScene, {
$http.put(config.backend + '/scene/' + scene.id, {
name: scene.name,
active: scene.active})
.success(function () {
......@@ -271,6 +284,25 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
};
// Duplicate viewing scene
$scope.copy_scene = function () {
$http.get(config.backend + '/scene/'+$scope.viewingScene.id+'/copy' )
.success(function (newScene) {
io.socket.post('/scene', {
action: 'add',
data: newScene
}, function () {});
$scope.loadScenesList();
$translate('scene_duplicated').then(function (translation) {
ngToast.success({ content: translation });
});
}).error(function () {});
};
$scope.deleteFreePicto = function (studentPicto) {
$translate('confirmation').then(t => {
if ($window.confirm(t)) {
......@@ -425,7 +457,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
new_id_pic: pictoId
})
.success(function (studentPicto) {
$scope.loadPictos($scope.viewingScene);
$scope.showScene($scope.viewingScene.id);
// notify
io.socket.post('/stu/vocabulary', {
......@@ -502,9 +534,6 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
else
ngToast.danger({ content: $translate.instant('error_adding_picto') });
});
// not needed
// $scope.loadPictos();
});
};
......
......@@ -84,8 +84,10 @@ module.exports.policies = {
create: ['tokenAuth', 'isSupervisorOfStudent'],
update: ['tokenAuth', 'isSupervisorOfStudent'],
destroy: ['tokenAuth', 'isSupervisorOfStudent'],
duplicate: ['tokenAuth', 'isSupervisorOfStudent'],
getScene: ['tokenAuth'],
getStudentScenes: ['tokenAuth']
getStudentScenes: ['tokenAuth'],
scene: true
},
ServerController: {
......
......@@ -77,6 +77,7 @@ module.exports.routes = {
'POST /scene': 'SceneController.scene',
'GET /scene/:id': 'SceneController.getScene',
'GET /scene/:id/copy': 'SceneController.duplicate',
'POST /scene/:id': 'SceneController.create',
'PUT /scene/:id': 'SceneController.update',
'DELETE /scene/:id': 'SceneController.destroy',
......
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