Commit 2f52c277 by Fernando Martínez Santiago

Merge branch 'develop' of http://scm.ujaen.es/softuno/pictogram into develop

parents 029bf19d f268ffab
......@@ -49,3 +49,8 @@ UNLOCK TABLES;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2017-01-17 9:48:07
--
-- Creacion y volcado de datos para la tabla `pictocattree`
--
source /vagrant/roles/database/files/pictocat_tree_populate.sql
DROP TABLE IF EXISTS `pictocattree`;
CREATE TABLE pictocattree(
id_cat INT,
id_ancestor INT,
CONSTRAINT pk_primary_key PRIMARY KEY (id_cat, id_ancestor),
INDEX (id_ancestor)
);
DELIMITER $$
DROP PROCEDURE IF EXISTS picto_cat_tree $$
CREATE PROCEDURE picto_cat_tree()
BEGIN
DECLARE done, populated INT DEFAULT FALSE;
DECLARE _id, _id_supercat, x, _id_cat, _id_ancestor INT;
DECLARE pictocat CURSOR FOR SELECT id,id_supercat FROM pictodb.pictocat;
DECLARE pictocattree CURSOR FOR SELECT id_cat, id_ancestor FROM pictodb.pictocattree where id_cat = x;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN pictocat;
DELETE FROM pictocattree;
read_loop: LOOP
FETCH pictocat INTO _id, _id_supercat;
IF done THEN
LEAVE read_loop;
END IF;
INSERT INTO pictocattree (id_cat,id_ancestor) VALUES (_id, _id_supercat);
IF _id_supercat != 0 THEN
SET populated = 0;
populate_loop: LOOP
SET x = _id_supercat;
OPEN pictocattree;
FETCH pictocattree INTO _id_cat, _id_ancestor;
INSERT INTO pictocattree (id_cat, id_ancestor) VALUES (_id, _id_ancestor);
IF _id_ancestor = 0 THEN
LEAVE populate_loop;
END IF;
END LOOP;
CLOSE pictocattree;
END IF;
END LOOP;
CLOSE pictocat;
END $$
DELIMITER ;
CALL picto_cat_tree();
......@@ -24,6 +24,14 @@
state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/symbolstix.sql"
- name: Imports symbolstix categories
mysql_db:
login_user: "{{ database_user }}"
login_password: "{{ database_user_passwd }}"
name: "{{ database_name }}"
state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/pictocat.sql"
- name: Imports application essential data
mysql_db:
login_user: "{{ database_user }}"
......
......@@ -148,18 +148,18 @@ module.exports = {
var fs = require('fs');
// return empty for category 0 (that represents category pictos and all custom pictos)
if (req.params.id_cat == 0)
return res.ok(l);
// if (req.params.id_cat == 0)
// return res.ok(l);
Supervisor.findOne({ id: req.params.id }).then(function (supervisor) {
if (supervisor) {
PictoCat
.find({select: ['id'], id_supercat: req.params.id_cat })
PictoCatTree
.find({select: ['id_cat'], id_ancestor: req.params.id_cat })
.then(function (categories) {
var filtered = [req.params.id_cat];
for(var i =0; i<categories.length;i++){
filtered.push(categories[i].id);
var filtered = [req.params.id_cat]; // Category itself
for(var i =0; i<categories.length;i++){ //All subcategories
filtered.push(categories[i].id_cat);
}
Picto.find({ category: filtered })
.paginate({ page: req.params.page, limit: req.params.limit})
......@@ -193,67 +193,11 @@ module.exports = {
.catch(function (err) {
throw err;
});
//get all categories under id_cat
// var promise = new Promise(function(resolve, reject){
// var cats = [];
// var catsFiltered = [];
// cats = getCategories(req.params.id_cat);
// while(cats.length > 1){
// var cat = cats.pop().id;
// catsFiltered.push(cat);
// cats = cats.concat(getCategories(cat));
// }
// console.log(catsFiltered);
// resolve(catsFiltered);
// });
//promise.then(function(catsFiltered){
// Picto.find({ category: catsFiltered })
// .paginate({ page: req.params.page, limit: req.params.limit})
// .populate('expressions', { lang: supervisor.lang })
// .then(function (pictos) {
// async.eachSeries(pictos, function(picto, next_cb) {
//
// // check picto has expressions associated in student language
// if (picto.expressions.length == 0 || picto.expressions[0].text.length == 0)
// return next_cb();
//
// // check picto image is available
// picto.imageFileExists((found) => {
// if (found) {
// l.push(picto);
// next_cb();
// }
// else
// next_cb();
// });
// },
// function (err) { // loop has end
// if (err) throw err;
// sails.log.debug(pictos.length + " pictos sent for category " + req.params.id_cat + " in language " + supervisor.lang);
// return res.ok(l);
// }); // end async.eachSeries
// })
// .catch(() => res.badRequest());
//});
} else {
return res.badRequest();
}
})
.catch(() => res.serverError());
// function getCategories(id_cat){
// PictoCat
// .find({select: ['id'], id_supercat: id_cat })
// .then(function (categories) {
// console.log(categories);
// return categories;
// })
// .catch(function (err) {
// throw err;
// });
// }
},
/**
......@@ -287,12 +231,12 @@ module.exports = {
if (req.params.id_cat == 0){ //Search in all categories
getPictos(0, supervisor.lang, supervisor.id);
}else{//Get selected category and subcategories
PictoCat
.find({select: ['id'], id_supercat: req.params.id_cat })
PictoCatTree
.find({select: ['id_cat'], id_ancestor: req.params.id_cat })
.then(function (categories) {
var filtered = [Number(req.params.id_cat)]; //Get returned ID
for(var i =0; i<categories.length;i++){
filtered.push(categories[i].id);
var filtered = [req.params.id_cat]; //Category itself
for(var i =0; i<categories.length;i++){ //All subcategories
filtered.push(categories[i].id_cat);
}
getPictos(filtered, supervisor.lang, supervisor.id);
})
......
/**
* pictocat.js
*
* @description :: TODO: Write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
tableName : 'pictocattree',
migrate : 'safe',
schema : true,
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id_cat: {
type: "integer",
primaryKey: true,
unique: true
},
id_ancestor: {
type: "integer",
primaryKey: true,
required: false
}
}
};
......@@ -295,8 +295,8 @@ dashboardControllers.controller('AddPictoCtrl', function (
//Triggered when scrolling to bottom
$scope.scroll = function(){
if ($scope.onlyOwn)
return;
if ($scope.onlyOwn || $scope.source == 'ownpictos')
return; //When ownpictos is active, load whole own pictos at once
$scope.loadingCatPictos = true;
$scope.page += 1;
......
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