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
900acc08
authored
Mar 05, 2016
by
Fernando Martínez Santiago
Committed by
Arturo Montejo Ráez
Mar 05, 2016
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Vocabulary management from PCB, upload and status images, implemented (SAILS side)
parent
b6c2e005
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
7 deletions
sails/src/api/controllers/PictoController.js
sails/src/api/controllers/StudentController.js
sails/src/config/routes.js
sails/src/api/controllers/PictoController.js
View file @
900acc08
...
@@ -79,6 +79,7 @@ module.exports = {
...
@@ -79,6 +79,7 @@ module.exports = {
if
(
!
params
.
picto
||
!
params
.
lang
||
!
params
.
text
)
{
if
(
!
params
.
picto
||
!
params
.
lang
||
!
params
.
text
)
{
return
res
.
json
(
500
,
{
error
:
"Not enough data: picto, lang or text"
});
return
res
.
json
(
500
,
{
error
:
"Not enough data: picto, lang or text"
});
}
}
console
.
log
(
"New Expression for picto id "
+
params
.
picto
+
": "
+
params
.
text
+
" ("
+
params
.
lang
+
")"
);
// If the expression exists, it's updated and if not, it's created
// If the expression exists, it's updated and if not, it's created
PictoExp
.
findOne
({
picto
:
params
.
picto
,
lang
:
params
.
lang
}).
exec
(
function
(
err
,
exp
){
PictoExp
.
findOne
({
picto
:
params
.
picto
,
lang
:
params
.
lang
}).
exec
(
function
(
err
,
exp
){
if
(
err
)
if
(
err
)
...
@@ -87,12 +88,14 @@ module.exports = {
...
@@ -87,12 +88,14 @@ module.exports = {
// Exists --> Update it
// Exists --> Update it
if
(
exp
){
if
(
exp
){
PictoExp
.
update
({
id
:
exp
.
id
},
params
).
exec
(
function
(
err
,
updated
)
{
PictoExp
.
update
({
id
:
exp
.
id
},
params
).
exec
(
function
(
err
,
updated
)
{
console
.
log
(
"Expression updated for expr. id "
+
exp
.
id
+
": "
+
params
.
text
);
if
(
err
)
throw
err
;
if
(
err
)
throw
err
;
return
res
.
json
(
updated
);
return
res
.
json
(
updated
);
});
});
// No exists --> Create it
// No exists --> Create it
}
else
{
}
else
{
PictoExp
.
create
(
params
).
exec
(
function
(
err
,
created
)
{
PictoExp
.
create
(
params
).
exec
(
function
(
err
,
created
)
{
console
.
log
(
"Expression inserted for picto expr. "
+
created
.
id
+
": "
+
params
.
text
);
if
(
err
)
throw
err
;
if
(
err
)
throw
err
;
return
res
.
json
(
created
);
return
res
.
json
(
created
);
});
});
...
@@ -100,6 +103,7 @@ module.exports = {
...
@@ -100,6 +103,7 @@ module.exports = {
});
});
},
},
// Upload a picto to the server (/upload/custompictos/)
// Upload a picto to the server (/upload/custompictos/)
upload
:
function
(
req
,
res
)
{
upload
:
function
(
req
,
res
)
{
if
(
req
.
method
===
'GET'
)
if
(
req
.
method
===
'GET'
)
...
@@ -107,13 +111,13 @@ module.exports = {
...
@@ -107,13 +111,13 @@ module.exports = {
// Call to /upload via GET is error
// Call to /upload via GET is error
console
.
log
(
"Nombre archivo: "
+
req
.
body
.
filename
);
var
fs
=
require
(
'fs'
),
path
=
require
(
'path'
),
dateFormat
=
require
(
'dateformat'
);
console
.
log
(
"Nombre carpeta: "
+
req
.
body
.
folder
);
console
.
log
(
"Nombre fuente: "
+
req
.
body
.
source
);
// req.body.filename = sailsHash.hashCode(req.body.filename + Date().toString()) + '.' + req.body.extension;
req
.
body
.
filename
=
'u'
+
req
.
body
.
owner
+
'd'
+
dateFormat
(
new
Date
(),
"yyyymmddHHMMss"
)
+
'.'
+
req
.
body
.
extension
;
var
fs
=
require
(
'fs'
),
path
=
require
(
'path'
);
console
.
log
(
"Uploading "
+
req
.
body
.
filename
+
' at '
+
req
.
body
.
folder
+
' from source '
+
req
.
body
.
source
+
req
.
body
.
filename
=
sailsHash
.
hashCode
(
req
.
body
.
filename
+
Date
().
toString
())
+
'.'
+
req
.
body
.
extension
;
'. Renamed as '
+
req
.
body
.
filename
)
;
var
uploadFile
=
req
.
file
(
'file'
);
var
uploadFile
=
req
.
file
(
'file'
);
var
dirUpload
=
path
.
join
(
process
.
cwd
(),
'/assets/upload/'
+
req
.
body
.
folder
);
var
dirUpload
=
path
.
join
(
process
.
cwd
(),
'/assets/upload/'
+
req
.
body
.
folder
);
...
...
sails/src/api/controllers/StudentController.js
View file @
900acc08
...
@@ -512,7 +512,7 @@ module.exports = {
...
@@ -512,7 +512,7 @@ module.exports = {
//
//
add_picto
:
function
(
req
,
res
)
{
add_picto
:
function
(
req
,
res
)
{
var
params
=
req
.
allParams
();
var
params
=
req
.
allParams
();
console
.
log
(
"Adding picto "
+
params
.
id_picto
+
" atts:"
+
params
.
attributes
);
console
.
log
(
JSON
.
stringify
(
params
)
);
StuPicto
.
create
({
StuPicto
.
create
({
student
:
params
.
id_stu
,
student
:
params
.
id_stu
,
picto
:
params
.
id_picto
,
picto
:
params
.
id_picto
,
...
@@ -560,8 +560,12 @@ module.exports = {
...
@@ -560,8 +560,12 @@ module.exports = {
//
//
update_picto
:
function
(
req
,
res
)
{
update_picto
:
function
(
req
,
res
)
{
var
params
=
req
.
allParams
();
var
params
=
req
.
allParams
();
console
.
log
(
"Updating attributes for picto student "
+
params
);
console
.
log
(
JSON
.
stringify
(
params
));
console
.
log
(
JSON
.
stringify
(
params
));
StuPicto
.
update
({
id
:
params
.
id_stuPicto
},
{
attributes
:
params
.
attributes
}).
exec
(
function
(
err
,
updated
)
{
query
=
params
.
id_stuPicto
?
{
id
:
params
.
id_stuPicto
}
:
{
id_stu
:
params
.
id_stu
,
id_pic
:
params
.
id_pic
}
StuPicto
.
update
(
query
,
{
attributes
:
params
.
attributes
}).
exec
(
function
(
err
,
updated
)
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
return
res
.
json
(
500
,
{
error
:
'Not updated picto for student'
});
return
res
.
json
(
500
,
{
error
:
'Not updated picto for student'
});
...
...
sails/src/config/routes.js
View file @
900acc08
...
@@ -93,6 +93,7 @@ module.exports.routes = {
...
@@ -93,6 +93,7 @@ module.exports.routes = {
'get /stu/:id_stu/pictos'
:
'StudentController.pictos'
,
'get /stu/:id_stu/pictos'
:
'StudentController.pictos'
,
'delete /stu/:id_stu/picto/:id_stuPicto'
:
'StudentController.delete_picto'
,
'delete /stu/:id_stu/picto/:id_stuPicto'
:
'StudentController.delete_picto'
,
'put /stu/:id_stu/picto/:id_stuPicto'
:
'StudentController.update_picto'
,
'put /stu/:id_stu/picto/:id_stuPicto'
:
'StudentController.update_picto'
,
'put /stu/:id_stu/picto'
:
'StudentController.update_picto'
,
'post /stu/:id_stu/picto/:id_picto'
:
'StudentController.add_picto'
,
'post /stu/:id_stu/picto/:id_picto'
:
'StudentController.add_picto'
,
// Students actions triggering WEBSOCKETS
// Students actions triggering WEBSOCKETS
...
...
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