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
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
45 additions
and
56 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 = {
...
@@ -219,32 +219,22 @@ module.exports = {
var
params
=
req
.
params
.
all
();
var
params
=
req
.
params
.
all
();
if
(
!
params
.
lang
||
!
params
.
text
)
if
(
!
params
.
lang
||
!
params
.
text
)
return
res
.
badRequest
();
return
res
.
badRequest
(
"Invalid parameters"
);
PictoExp
.
findOne
({
id
:
params
.
picto
,
lang
:
params
.
lang
})
PictoExp
.
findOrCreate
(
.
then
(
function
(
pictoExpression
)
{
{
// find criteria
if
(
!
pictoExpression
)
{
picto
:
params
.
picto
Picto
.
findOne
({
id
:
params
.
picto
}).
then
(
function
(
picto
)
{
},
if
(
!
picto
)
{
// if not found, create it
return
res
.
badRequest
(
'Error: Picto not found'
);
picto
:
params
.
picto
,
PictoExp
.
create
({
lang
:
params
.
lang
,
lang
:
params
.
lang
,
text
:
params
.
text
,
text
:
params
.
text
picto
:
picto
.
id
}
}).
then
(
function
(
newPictoExpression
)
{
)
if
(
!
newPictoExpression
)
.
then
(
function
(
pictoExpression
)
{
throw
new
Error
(
"Could not create picto expression"
);
return
res
.
ok
(
newPictoExpression
);
});
});
}
else
{
pictoExpression
.
text
=
params
.
text
;
pictoExpression
.
text
=
params
.
text
;
pictoExpression
.
save
(
function
(
error
)
{
pictoExpression
.
save
();
if
(
error
)
throw
new
Error
(
"Could not save expression"
);
return
res
.
ok
(
pictoExpression
);
return
res
.
ok
(
pictoExpression
);
});
}
})
})
.
catch
(
function
(
err
)
{
.
catch
(
function
(
err
)
{
return
res
.
serverError
(
"Error from server: "
+
err
);
return
res
.
serverError
(
"Error from server: "
+
err
);
...
...
sails/src/api/controllers/StudentController.js
View file @
b9d580e1
...
@@ -758,8 +758,9 @@ module.exports = {
...
@@ -758,8 +758,9 @@ module.exports = {
sails
.
log
.
debug
(
'Pictos requested for student '
+
req
.
params
.
id_stu
);
sails
.
log
.
debug
(
'Pictos requested for student '
+
req
.
params
.
id_stu
);
Student
.
pictos
(
req
.
params
.
id_stu
,
function
(
err
,
pictos
)
{
Student
.
pictos
(
req
.
params
.
id_stu
,
function
(
err
,
pictos
)
{
if
(
err
)
throw
err
;
if
(
err
)
return
res
.
json
(
pictos
);
return
res
.
serverError
(
"Error obtaining pictos: "
+
err
);
return
res
.
ok
(
pictos
);
});
});
},
},
...
@@ -817,9 +818,7 @@ module.exports = {
...
@@ -817,9 +818,7 @@ module.exports = {
return
[
return
[
Picto
.
findOne
({
id
:
params
.
id_picto
})
Picto
.
findOne
({
id
:
params
.
id_picto
})
.
populate
(
'expressions'
,
{
.
populate
(
'expressions'
,
{
lang
:
student
.
lang
})
lang
:
student
.
lang
})
,
,
student
student
];
];
...
...
sails/src/api/controllers/SupervisorController.js
View file @
b9d580e1
...
@@ -447,6 +447,7 @@ module.exports = {
...
@@ -447,6 +447,7 @@ module.exports = {
Picto
Picto
.
find
({
owner
:
supervisor
.
id
})
.
find
({
owner
:
supervisor
.
id
})
.
populate
(
'expressions'
,
{
lang
:
supervisor
.
lang
})
.
populate
(
'expressions'
,
{
lang
:
supervisor
.
lang
})
.
populate
(
'tags'
,
{
lang
:
supervisor
.
lang
})
.
then
(
function
(
pictos
)
{
.
then
(
function
(
pictos
)
{
res
.
ok
(
pictos
);
res
.
ok
(
pictos
);
})
})
...
...
sails/src/api/models/Picto.js
View file @
b9d580e1
...
@@ -67,6 +67,18 @@ module.exports = {
...
@@ -67,6 +67,18 @@ module.exports = {
picto
.
uri
=
sails
.
config
.
pictogram
.
urls
.
getSupervisorCustomPictoUrl
(
picto
.
uri
);
picto
.
uri
=
sails
.
config
.
pictogram
.
urls
.
getSupervisorCustomPictoUrl
(
picto
.
uri
);
}
}
return
picto
;
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 = {
...
@@ -358,21 +358,14 @@ module.exports = {
.
then
((
picto
)
=>
{
.
then
((
picto
)
=>
{
// check picto has expressions associated in student language
// check picto has expressions associated in student language
if
(
picto
.
expressions
.
length
==
0
||
picto
.
expressions
[
0
].
text
.
length
==
0
)
{
if
(
picto
.
expressions
.
length
==
0
||
picto
.
expressions
[
0
].
text
.
length
==
0
)
sails
.
log
.
debug
(
"No expression for picto "
+
picto
.
id
);
return
next_cb
();
return
;
}
// check picto image is available
// check picto image is available
var
fs
=
require
(
'fs'
);
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
)
{
fs
.
access
(
img_path
,
fs
.
F_OK
,
function
(
err
)
{
if
(
err
)
{
if
(
err
)
return
next_cb
();
sails
.
log
.
debug
(
"No image file for "
+
img_path
);
return
;
}
//sails.log.debug("Tags: " + JSON.stringify(stuPicto.picto.tags));
// Now we have everything, so we add the picto to the list
// Now we have everything, so we add the picto to the list
var
stuPictoToAdd
=
{
var
stuPictoToAdd
=
{
...
@@ -384,21 +377,18 @@ module.exports = {
...
@@ -384,21 +377,18 @@ module.exports = {
};
};
l
.
push
(
stuPictoToAdd
);
l
.
push
(
stuPictoToAdd
);
next_cb
();
});
});
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
sails
.
log
.
debug
(
"Error found obtaining pictos: "
+
err
);
next_cb
(
err
);
})
});
.
then
(()
=>
next_cb
());
// end Picto.findOne
},
},
function
(
err
)
{
// loop has end
function
(
err
)
{
// loop has end
if
(
err
)
sails
.
log
.
debug
(
"Error found obtaining pictos: "
+
err
);
callback
(
err
,
l
);
callback
(
err
,
l
);
});
// end async.eachSeries
});
// end async.eachSeries
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
sails
.
log
.
debug
(
"Error found obtaining pictos: "
+
err
);
callback
(
err
,
l
);
callback
(
err
,
l
);
});
// end Student.findOne
});
// end Student.findOne
},
},
...
...
sails/src/assets/scripts/modules/student/controllers/addpicto.js
View file @
b9d580e1
...
@@ -341,8 +341,8 @@ dashboardControllers.controller('AddPictoCtrl', function (
...
@@ -341,8 +341,8 @@ dashboardControllers.controller('AddPictoCtrl', function (
// Delete own picto
// Delete own picto
//
//
$scope
.
remove_own_picto
=
function
(
pictoId
)
{
$scope
.
remove_own_picto
=
function
(
pictoId
)
{
var
deletePicto
=
$window
.
confirm
(
'Are you absolutely sure you want to delete?'
);
$translate
(
'confirmation'
).
then
(
t
=>
{
if
(
deletePicto
)
{
if
(
$window
.
confirm
(
t
))
$http
.
delete
(
config
.
backend
+
'/picto/'
+
pictoId
)
$http
.
delete
(
config
.
backend
+
'/picto/'
+
pictoId
)
.
success
(
function
()
{
.
success
(
function
()
{
var
i
;
var
i
;
...
@@ -353,7 +353,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
...
@@ -353,7 +353,7 @@ dashboardControllers.controller('AddPictoCtrl', function (
}
}
})
})
.
error
(
function
()
{});
.
error
(
function
()
{});
}
}
);
};
};
$scope
.
close
=
function
()
{
$scope
.
close
=
function
()
{
...
@@ -384,10 +384,8 @@ dashboardControllers.controller('AddPictoCtrl', function (
...
@@ -384,10 +384,8 @@ dashboardControllers.controller('AddPictoCtrl', function (
});
});
// Returned data from the modal window
// Returned data from the modal window
modalInstance
.
result
.
then
(
modalInstance
.
result
.
then
((
exp
)
=>
{
function
(
exp
)
{
picto
.
expressions
.
push
(
exp
);
picto
.
expressions
.
push
(
exp
);
}
});
);
};
};
});
});
sails/src/assets/scripts/modules/supervisor/controllers/students.js
View file @
b9d580e1
...
@@ -136,9 +136,8 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
...
@@ -136,9 +136,8 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
// Delete Student
// Delete Student
$scope
.
delete_student
=
function
(
student
)
{
$scope
.
delete_student
=
function
(
student
)
{
var
deleteStudent
=
$window
.
confirm
(
'Are you absolutely sure you want to delete?'
);
$translate
(
'confirmation'
).
then
(
t
=>
{
if
(
$window
.
confirm
(
t
))
if
(
deleteStudent
)
{
$http
.
delete
(
config
.
backend
+
'/stu/'
+
student
.
id
)
$http
.
delete
(
config
.
backend
+
'/stu/'
+
student
.
id
)
.
success
(
function
()
{
.
success
(
function
()
{
var
i
;
var
i
;
...
@@ -160,7 +159,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
...
@@ -160,7 +159,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
ngToast
.
danger
({
content
:
translation
});
ngToast
.
danger
({
content
:
translation
});
});
});
});
});
}
}
);
};
};
// When a new student is added to the supervisor, we should update
// 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 = {
...
@@ -64,7 +64,7 @@ module.exports.pictogram = {
[
randomString
,
randomDate
,
randomNumber
,
randomFloat
].
join
(
''
),
[
randomString
,
randomDate
,
randomNumber
,
randomFloat
].
join
(
''
),
bcrypt
.
genSaltSync
()
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