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
a0cc67ce
authored
Jul 28, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issue #511 resolved
parent
01353467
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
20 deletions
sails/src/api/models/Student.js
sails/src/api/models/Student.js
View file @
a0cc67ce
...
@@ -328,24 +328,50 @@ module.exports = {
...
@@ -328,24 +328,50 @@ module.exports = {
// Class method for getting the list of pictos associated to a given
// Class method for getting the list of pictos associated to a given
// student
// student
pictos
:
function
(
id_stu
,
callback
)
{
pictos
:
function
(
id_stu
,
callback
)
{
Student
.
findOne
(
id_stu
).
exec
(
function
(
err
,
student
)
{
if
(
student
){
StuPicto
.
find
({
student
:
id_stu
}).
populate
(
'picto'
).
exec
(
function
(
err
,
stuPictos
)
{
var
l
=
[];
var
l
=
[];
if
(
err
||
!
stuPictos
||
stuPictos
.
length
==
0
)
Student
.
findOne
(
id_stu
)
return
callback
(
err
,
l
);
.
then
((
student
)
=>
{
if
(
!
student
)
throw
new
Error
(
"No student found"
);
var
stuPictos
=
StuPicto
.
find
({
student
:
id_stu
})
.
populate
(
'picto'
)
.
then
((
stuPictos
)
=>
{
if
(
!
stuPictos
||
stuPictos
.
length
==
0
)
return
[];
return
stuPictos
;
})
.
catch
((
err
)
=>
{
throw
err
;
});
async
.
eachSeries
(
stuPictos
,
function
(
stuPicto
,
cb
)
{
return
[
student
,
stuPictos
];
})
.
spread
((
student
,
stuPictos
)
=>
{
async
.
eachSeries
(
stuPictos
,
function
(
stuPicto
,
next_cb
)
{
// Populate expressions to get it with the picto
// Populate expressions to get it with the picto
Picto
.
findOne
(
stuPicto
.
picto
.
id
)
Picto
.
findOne
(
stuPicto
.
picto
.
id
)
.
populate
(
'expressions'
,
{
lang
:
student
.
lang
})
.
populate
(
'expressions'
,
{
lang
:
student
.
lang
})
.
exec
(
function
(
err
,
picto
)
{
.
then
((
picto
)
=>
{
if
(
err
)
throw
err
;
// check picto has expressions associated in student language
if
(
picto
.
expressions
.
length
==
0
||
picto
.
expressions
[
0
].
text
.
length
==
0
)
{
sails
.
log
.
debug
(
"No expression for picto "
+
picto
.
id
);
return
;
}
// check picto image is available
var
fs
=
require
(
'fs'
);
var
img_path
=
sails
.
config
.
pictogram
.
paths
.
public
+
stuPicto
.
picto
.
uri
;
fs
.
access
(
img_path
,
fs
.
F_OK
,
function
(
err
)
{
if
(
err
)
{
sails
.
log
.
debug
(
"No image file for "
+
img_path
);
return
;
}
// Now we have everythin, so we add the picto to the list
var
stuPictoToAdd
=
{
var
stuPictoToAdd
=
{
"id"
:
stuPicto
.
id
,
"id"
:
stuPicto
.
id
,
"picto"
:
stuPicto
.
picto
,
"picto"
:
stuPicto
.
picto
,
...
@@ -354,17 +380,23 @@ module.exports = {
...
@@ -354,17 +380,23 @@ module.exports = {
};
};
l
.
push
(
stuPictoToAdd
);
l
.
push
(
stuPictoToAdd
);
cb
();
// next in the series
});
},
function
(
err
)
{
callback
(
err
,
l
);
// out loop finished, return result
});
});
}
});
});
})
.
catch
((
err
)
=>
{
sails
.
log
.
debug
(
"Error found obtaining pictos: "
+
err
);
})
.
then
(()
=>
next_cb
());
// end Picto.findOne
},
function
(
err
)
{
// loop has end
if
(
err
)
sails
.
log
.
debug
(
"Error found obtaining pictos: "
+
err
);
callback
(
err
,
l
);
});
// end async.eachSeries
})
.
catch
((
err
)
=>
{
sails
.
log
.
debug
(
"Error found obtaining pictos: "
+
err
);
callback
(
err
,
l
);
});
// end Student.findOne
},
},
//
//
...
...
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