Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2f52c277
authored
Feb 15, 2017
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'develop' of
http://scm.ujaen.es/softuno/pictogram
into develop
parents
029bf19d
f268ffab
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
70 deletions
sails/roles/database/files/pictocat.sql
sails/roles/database/files/pictocat_tree_populate.sql
sails/roles/database/tasks/main.yml
sails/src/api/controllers/PictoController.js
sails/src/api/models/PictoCatTree.js
sails/src/assets/scripts/modules/student/controllers/addpicto.js
sails/roles/database/files/pictocat.sql
View file @
2f52c277
...
...
@@ -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
sails/roles/database/files/pictocat_tree_populate.sql
0 → 100644
View file @
2f52c277
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
();
sails/roles/database/tasks/main.yml
View file @
2f52c277
...
...
@@ -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
}}"
...
...
sails/src/api/controllers/PictoController.js
View file @
2f52c277
...
...
@@ -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
})
PictoCat
Tree
.
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
})
PictoCat
Tree
.
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
);
})
...
...
sails/src/api/models/PictoCatTree.js
0 → 100644
View file @
2f52c277
/**
* 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
}
}
};
sails/src/assets/scripts/modules/student/controllers/addpicto.js
View file @
2f52c277
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment