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
f268ffab
authored
Feb 15, 2017
by
Jose Antonio
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use Pictocattree instead of recursive select of categories
parent
d8aa30a6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
68 deletions
sails/src/api/controllers/PictoController.js
sails/src/api/models/PictoCatTree.js
sails/src/api/controllers/PictoController.js
View file @
f268ffab
...
@@ -148,18 +148,18 @@ module.exports = {
...
@@ -148,18 +148,18 @@ module.exports = {
var
fs
=
require
(
'fs'
);
var
fs
=
require
(
'fs'
);
// return empty for category 0 (that represents category pictos and all custom pictos)
// return empty for category 0 (that represents category pictos and all custom pictos)
if
(
req
.
params
.
id_cat
==
0
)
//
if (req.params.id_cat == 0)
return
res
.
ok
(
l
);
//
return res.ok(l);
Supervisor
.
findOne
({
id
:
req
.
params
.
id
}).
then
(
function
(
supervisor
)
{
Supervisor
.
findOne
({
id
:
req
.
params
.
id
}).
then
(
function
(
supervisor
)
{
if
(
supervisor
)
{
if
(
supervisor
)
{
PictoCat
PictoCat
Tree
.
find
({
select
:
[
'id
'
],
id_supercat
:
req
.
params
.
id_cat
})
.
find
({
select
:
[
'id
_cat'
],
id_ancestor
:
req
.
params
.
id_cat
})
.
then
(
function
(
categories
)
{
.
then
(
function
(
categories
)
{
var
filtered
=
[
req
.
params
.
id_cat
];
var
filtered
=
[
req
.
params
.
id_cat
];
// Category itself
for
(
var
i
=
0
;
i
<
categories
.
length
;
i
++
){
for
(
var
i
=
0
;
i
<
categories
.
length
;
i
++
){
//All subcategories
filtered
.
push
(
categories
[
i
].
id
);
filtered
.
push
(
categories
[
i
].
id
_cat
);
}
}
Picto
.
find
({
category
:
filtered
})
Picto
.
find
({
category
:
filtered
})
.
paginate
({
page
:
req
.
params
.
page
,
limit
:
req
.
params
.
limit
})
.
paginate
({
page
:
req
.
params
.
page
,
limit
:
req
.
params
.
limit
})
...
@@ -193,67 +193,11 @@ module.exports = {
...
@@ -193,67 +193,11 @@ module.exports = {
.
catch
(
function
(
err
)
{
.
catch
(
function
(
err
)
{
throw
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
{
}
else
{
return
res
.
badRequest
();
return
res
.
badRequest
();
}
}
})
})
.
catch
(()
=>
res
.
serverError
());
.
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 = {
...
@@ -287,12 +231,12 @@ module.exports = {
if
(
req
.
params
.
id_cat
==
0
){
//Search in all categories
if
(
req
.
params
.
id_cat
==
0
){
//Search in all categories
getPictos
(
0
,
supervisor
.
lang
,
supervisor
.
id
);
getPictos
(
0
,
supervisor
.
lang
,
supervisor
.
id
);
}
else
{
//Get selected category and subcategories
}
else
{
//Get selected category and subcategories
PictoCat
PictoCat
Tree
.
find
({
select
:
[
'id
'
],
id_supercat
:
req
.
params
.
id_cat
})
.
find
({
select
:
[
'id
_cat'
],
id_ancestor
:
req
.
params
.
id_cat
})
.
then
(
function
(
categories
)
{
.
then
(
function
(
categories
)
{
var
filtered
=
[
Number
(
req
.
params
.
id_cat
)];
//Get returned ID
var
filtered
=
[
req
.
params
.
id_cat
];
//Category itself
for
(
var
i
=
0
;
i
<
categories
.
length
;
i
++
){
for
(
var
i
=
0
;
i
<
categories
.
length
;
i
++
){
//All subcategories
filtered
.
push
(
categories
[
i
].
id
);
filtered
.
push
(
categories
[
i
].
id
_cat
);
}
}
getPictos
(
filtered
,
supervisor
.
lang
,
supervisor
.
id
);
getPictos
(
filtered
,
supervisor
.
lang
,
supervisor
.
id
);
})
})
...
...
sails/src/api/models/PictoCatTree.js
0 → 100644
View file @
f268ffab
/**
* 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
}
}
};
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