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
b9d580e1
authored
Aug 01, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Problems adding custom pictos in PDB solved
parent
43deb2f6
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
77 additions
and
88 deletions
sails/src/api/controllers/PictoController.js
sails/src/api/controllers/StudentController.js
sails/src/api/controllers/SupervisorController.js
sails/src/api/models/Picto.js
sails/src/api/models/Student.js
sails/src/assets/scripts/modules/student/controllers/addpicto.js
sails/src/assets/scripts/modules/supervisor/controllers/students.js
sails/src/config/pictogram.js
sails/src/api/controllers/PictoController.js
View file @
b9d580e1
...
...
@@ -219,32 +219,22 @@ module.exports = {
var
params
=
req
.
params
.
all
();
if
(
!
params
.
lang
||
!
params
.
text
)
return
res
.
badRequest
();
return
res
.
badRequest
(
"Invalid parameters"
);
PictoExp
.
findOne
({
id
:
params
.
picto
,
lang
:
params
.
lang
})
PictoExp
.
findOrCreate
(
{
// find criteria
picto
:
params
.
picto
},
{
// if not found, create it
picto
:
params
.
picto
,
lang
:
params
.
lang
,
text
:
params
.
text
}
)
.
then
(
function
(
pictoExpression
)
{
if
(
!
pictoExpression
)
{
Picto
.
findOne
({
id
:
params
.
picto
}).
then
(
function
(
picto
)
{
if
(
!
picto
)
return
res
.
badRequest
(
'Error: Picto not found'
);
PictoExp
.
create
({
lang
:
params
.
lang
,
text
:
params
.
text
,
picto
:
picto
.
id
}).
then
(
function
(
newPictoExpression
)
{
if
(
!
newPictoExpression
)
throw
new
Error
(
"Could not create picto expression"
);
return
res
.
ok
(
newPictoExpression
);
});
});
}
else
{
pictoExpression
.
text
=
params
.
text
;
pictoExpression
.
save
(
function
(
error
)
{
if
(
error
)
throw
new
Error
(
"Could not save expression"
);
return
res
.
ok
(
pictoExpression
);
});
}
pictoExpression
.
save
();
return
res
.
ok
(
pictoExpression
);
})
.
catch
(
function
(
err
)
{
return
res
.
serverError
(
"Error from server: "
+
err
);
...
...
@@ -287,7 +277,7 @@ module.exports = {
return
res
.
serverError
(
"Error uploading "
+
err
?
err
:
""
);
Picto
.
create
({
uri
:
pictoFileName
,
uri
:
pictoFileName
,
source
:
1
,
// @TODO check for other sources
owner
:
supervisor
.
id
})
...
...
sails/src/api/controllers/StudentController.js
View file @
b9d580e1
...
...
@@ -758,8 +758,9 @@ module.exports = {
sails
.
log
.
debug
(
'Pictos requested for student '
+
req
.
params
.
id_stu
);
Student
.
pictos
(
req
.
params
.
id_stu
,
function
(
err
,
pictos
)
{
if
(
err
)
throw
err
;
return
res
.
json
(
pictos
);
if
(
err
)
return
res
.
serverError
(
"Error obtaining pictos: "
+
err
);
return
res
.
ok
(
pictos
);
});
},
...
...
@@ -817,9 +818,7 @@ module.exports = {
return
[
Picto
.
findOne
({
id
:
params
.
id_picto
})
.
populate
(
'expressions'
,
{
lang
:
student
.
lang
})
.
populate
(
'expressions'
,
{
lang
:
student
.
lang
})
,
student
];
...
...
@@ -845,7 +844,7 @@ module.exports = {
throw
new
Error
(
"stu_picto not created"
);
sails
.
log
.
debug
(
"->>"
+
JSON
.
stringify
(
picto
));
return
res
.
ok
({
id
:
stuPicto
.
id
,
id
:
stuPicto
.
id
,
student
:
params
.
id_stu
,
attributes
:
stuPicto
.
attributes
,
picto
:
picto
,
...
...
sails/src/api/controllers/SupervisorController.js
View file @
b9d580e1
...
...
@@ -447,6 +447,7 @@ module.exports = {
Picto
.
find
({
owner
:
supervisor
.
id
})
.
populate
(
'expressions'
,
{
lang
:
supervisor
.
lang
})
.
populate
(
'tags'
,
{
lang
:
supervisor
.
lang
})
.
then
(
function
(
pictos
)
{
res
.
ok
(
pictos
);
})
...
...
sails/src/api/models/Picto.js
View file @
b9d580e1
...
...
@@ -67,6 +67,18 @@ module.exports = {
picto
.
uri
=
sails
.
config
.
pictogram
.
urls
.
getSupervisorCustomPictoUrl
(
picto
.
uri
);
}
return
picto
;
},
/**
* Returns the server's filesystem path to the image
*/
getPath
:
function
()
{
var
picto
=
this
.
toObject
();
var
path
=
require
(
'path'
);
if
(
picto
.
owner
!==
null
)
return
path
.
join
(
sails
.
config
.
pictogram
.
paths
.
supervisorCustomPictoDirectory
,
picto
.
uri
);
else
return
path
.
join
(
sails
.
config
.
pictogram
.
paths
.
public
,
picto
.
uri
);
}
}
};
sails/src/api/models/Student.js
View file @
b9d580e1
...
...
@@ -358,21 +358,14 @@ module.exports = {
.
then
((
picto
)
=>
{
// 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
;
}
if
(
picto
.
expressions
.
length
==
0
||
picto
.
expressions
[
0
].
text
.
length
==
0
)
return
next_cb
();
// check picto image is available
var
fs
=
require
(
'fs'
);
var
img_path
=
sails
.
config
.
pictogram
.
paths
.
public
+
stuPicto
.
picto
.
uri
;
var
img_path
=
picto
.
getPath
()
;
fs
.
access
(
img_path
,
fs
.
F_OK
,
function
(
err
)
{
if
(
err
)
{
sails
.
log
.
debug
(
"No image file for "
+
img_path
);
return
;
}
//sails.log.debug("Tags: " + JSON.stringify(stuPicto.picto.tags));
if
(
err
)
return
next_cb
();
// Now we have everything, so we add the picto to the list
var
stuPictoToAdd
=
{
...
...
@@ -384,21 +377,18 @@ module.exports = {
};
l
.
push
(
stuPictoToAdd
);
next_cb
();
});
})
.
catch
((
err
)
=>
{
sails
.
log
.
debug
(
"Error found obtaining pictos: "
+
err
);
})
.
then
(()
=>
next_cb
());
// end Picto.findOne
next_cb
(
err
);
});
},
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
},
...
...
sails/src/assets/scripts/modules/student/controllers/addpicto.js
View file @
b9d580e1
...
...
@@ -341,19 +341,19 @@ dashboardControllers.controller('AddPictoCtrl', function (
// Delete own picto
//
$scope
.
remove_own_picto
=
function
(
pictoId
)
{
var
deletePicto
=
$window
.
confirm
(
'Are you absolutely sure you want to delete?'
);
if
(
deletePicto
)
{
$http
.
delete
(
config
.
backend
+
'/picto/'
+
pictoId
)
.
success
(
function
()
{
var
i
;
for
(
i
=
0
;
i
<
$scope
.
pictos
.
length
;
i
++
)
{
if
(
pictoId
===
$scope
.
pictos
[
i
].
id
)
{
$scope
.
pictos
.
splice
(
i
,
1
);
$translate
(
'confirmation'
).
then
(
t
=>
{
if
(
$window
.
confirm
(
t
))
$http
.
delete
(
config
.
backend
+
'/picto/'
+
pictoId
)
.
success
(
function
()
{
var
i
;
for
(
i
=
0
;
i
<
$scope
.
pictos
.
length
;
i
++
)
{
if
(
pictoId
===
$scope
.
pictos
[
i
].
id
)
{
$scope
.
pictos
.
splice
(
i
,
1
);
}
}
}
})
.
error
(
function
()
{});
}
})
.
error
(
function
()
{});
});
};
$scope
.
close
=
function
()
{
...
...
@@ -384,10 +384,8 @@ dashboardControllers.controller('AddPictoCtrl', function (
});
// Returned data from the modal window
modalInstance
.
result
.
then
(
function
(
exp
)
{
picto
.
expressions
.
push
(
exp
);
}
);
modalInstance
.
result
.
then
((
exp
)
=>
{
picto
.
expressions
.
push
(
exp
);
});
};
});
sails/src/assets/scripts/modules/supervisor/controllers/students.js
View file @
b9d580e1
...
...
@@ -136,31 +136,30 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
// Delete Student
$scope
.
delete_student
=
function
(
student
)
{
var
deleteStudent
=
$window
.
confirm
(
'Are you absolutely sure you want to delete?'
);
if
(
deleteStudent
)
{
$http
.
delete
(
config
.
backend
+
'/stu/'
+
student
.
id
)
.
success
(
function
()
{
var
i
;
for
(
i
=
0
;
i
<
$scope
.
students
.
length
;
i
++
)
{
if
(
student
.
id
===
$scope
.
students
[
i
].
id
)
{
$scope
.
students
.
splice
(
i
,
1
);
$translate
(
'confirmation'
).
then
(
t
=>
{
if
(
$window
.
confirm
(
t
))
$http
.
delete
(
config
.
backend
+
'/stu/'
+
student
.
id
)
.
success
(
function
()
{
var
i
;
for
(
i
=
0
;
i
<
$scope
.
students
.
length
;
i
++
)
{
if
(
student
.
id
===
$scope
.
students
[
i
].
id
)
{
$scope
.
students
.
splice
(
i
,
1
);
}
}
}
$translate
(
'student_deleted'
).
then
(
function
(
translation
)
{
ngToast
.
success
({
content
:
translation
});
});
IOService
.
post
(
'/stu/unsubscribe'
,
{
action
:
'unsubscribe'
})
;
})
.
error
(
function
(
)
{
$translate
(
'student_not_deleted'
).
then
(
function
(
translation
)
{
ngToast
.
danger
({
content
:
translation
});
$translate
(
'student_deleted'
).
then
(
function
(
translation
)
{
ngToast
.
success
({
content
:
translation
});
});
IOService
.
post
(
'/stu/unsubscribe'
,
{
action
:
'unsubscribe'
});
})
.
error
(
function
()
{
$translate
(
'student_not_deleted'
).
then
(
function
(
translation
)
{
ngToast
.
danger
({
content
:
translation
});
});
});
});
}
});
};
// When a new student is added to the supervisor, we should update
...
...
sails/src/config/pictogram.js
View file @
b9d580e1
...
...
@@ -64,7 +64,7 @@ module.exports.pictogram = {
[
randomString
,
randomDate
,
randomNumber
,
randomFloat
].
join
(
''
),
bcrypt
.
genSaltSync
()
)
.
replace
(
/
\W
/g
,
''
)
+
'.jpg'
;
.
replace
(
/
\W
/g
,
''
)
+
".jpg"
;
},
/**
...
...
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