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
4a0ea020
authored
May 09, 2017
by
Jose Antonio
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Issue
#200
, ToDo: check constraint when delete student
parent
e5e03f41
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
10 deletions
sails/roles/database/files/pictodb-schema.sql
sails/roles/database/files/scene_adapt.sql
sails/roles/database/files/triggers-enrolments-integrity-constraints.sql
sails/src/CHANGES.md
sails/src/api/controllers/SceneController.js
sails/src/api/controllers/StudentController.js
sails/src/assets/scripts/modules/student/controllers/collections.js
sails/roles/database/files/pictodb-schema.sql
View file @
4a0ea020
...
...
@@ -451,6 +451,12 @@ CREATE TABLE IF NOT EXISTS `scene` (
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COLLATE
=
utf8_unicode_ci
AUTO_INCREMENT
=
1
COMMENT
=
"Scene table information. Every scene is related to some stu_pictos"
;
CREATE
TABLE
IF
NOT
EXISTS
`scene_aux`
(
`id_stu`
int
(
11
)
NOT
NULL
,
`id_scene`
int
(
11
)
NOT
NULL
)
ENGINE
=
MEMORY
DEFAULT
CHARSET
=
utf8
COLLATE
=
utf8_unicode_ci
COMMENT
=
"Aux table to use with triggers-enrolments-integrity-constraints when create a new student"
;
-- CREATE INDEX ix_ws_begin ON working_session (`begin`);
--
-- Restricciones para tablas volcadas
...
...
sails/roles/database/files/scene_adapt.sql
View file @
4a0ea020
...
...
@@ -43,11 +43,13 @@ BEGIN
END
IF
;
/* FIRST SCENE, ACTIVE, WITH CATEGORIES*/
INSERT
INTO
`scene`
(
name
,
active
,
categories
,
id_stu
)
VALUES
(
'with_categories'
,
_cat_active
,
1
,
_id_stu
);
INSERT
INTO
`scene`
(
name
,
categories
,
id_stu
)
VALUES
(
'with_categories'
,
_cat_active
,
_id_stu
);
SET
LID
=
LAST_INSERT_ID
();
UPDATE
student
SET
attributes
=
JSON_SET
(
attributes
,
"$.id_active_scene"
,
LID
)
WHERE
id
=
_id_stu
;
UPDATE
`stu_picto`
SET
`id_scene`
=
LID
WHERE
`id_stu`
=
_id_stu
...
...
@@ -55,8 +57,8 @@ BEGIN
AND
attributes
->
"$.free_category_coord_y"
IS
NULL
;
/* SECOND SCENE, NOT ACTIVE, NO CATEGORIES*/
INSERT
INTO
`scene`
(
name
,
active
,
categories
,
id_sup
,
id_stu
)
VALUES
(
'no_categories'
,
NOT
_cat_active
,
0
,
_id_sup
,
_id_stu
);
INSERT
INTO
`scene`
(
name
,
categories
,
id_sup
,
id_stu
)
VALUES
(
'no_categories'
,
NOT
_cat_active
,
_id_sup
,
_id_stu
);
SET
LID
=
LAST_INSERT_ID
();
...
...
sails/roles/database/files/triggers-enrolments-integrity-constraints.sql
View file @
4a0ea020
...
...
@@ -49,13 +49,36 @@ thisTrigger: BEGIN
LEAVE
thisTrigger
;
END
IF
;
-- Load core collection for student
INSERT
INTO
scene
(
id_stu
,
id_sup
,
name
,
categories
)
VALUES
(
new
.
id
,
null
,
'with_categories'
,
TRUE
);
SET
LID
=
LAST_INSERT_ID
();
CALL
scene_create_core
(
LID
,
new
.
id
);
UPDATE
student
SET
attributes
=
JSON_SET
(
attributes
,
"$.id_active_scene"
,
@
LID
);
INSERT
INTO
scene_aux
(
id_stu
,
id_scene
)
VALUES
(
new
.
id
,
LID
);
END
;;
DROP
PROCEDURE
IF
EXISTS
NEW_STUDENT_AUX
;
CREATE
PROCEDURE
NEW_STUDENT_AUX
()
BEGIN
DECLARE
_id_stu
INT
;
DECLARE
_id_scene
INT
;
DECLARE
done
INT
DEFAULT
FALSE
;
DECLARE
aux
CURSOR
FOR
SELECT
*
FROM
pictodb
.
scene_aux
;
DECLARE
CONTINUE
HANDLER
FOR
NOT
FOUND
SET
done
=
TRUE
;
OPEN
aux
;
read_loop
:
LOOP
FETCH
aux
INTO
_id_stu
,
_id_scene
;
IF
done
THEN
LEAVE
read_loop
;
END
IF
;
UPDATE
student
SET
attributes
=
JSON_SET
(
attributes
,
'$.id_active_scene'
,
_id_scene
)
WHERE
id
=
_id_stu
;
END
LOOP
;
CLOSE
aux
;
DELETE
FROM
scene_aux
;
END
;;
-- Procedure to add core when new scene is created
...
...
sails/src/CHANGES.md
View file @
4a0ea020
...
...
@@ -18,9 +18,20 @@ Changes to be performed manually in servers to upgrade
-
Alter table scene to add ON DELETE CASCADE constraint
`ALTER TABLE `
scene
` ADD CONSTRAINT `
stu_scene_fk
` FOREIGN KEY (`
id_stu
`) REFERENCES `
student
` (`
id
`) ON DELETE CASCADE;`
-
Create aux table for scene
`CREATE TABLE IF NOT EXISTS `
scene_aux
`(
`
id_stu
` int(11) NOT NULL,
`
id_scene
` int(11) NOT NULL
) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
COMMENT="Aux table to use with triggers-enrolments-integrity-constraints when create a new student";`
-
Reload enrolments trigger
`source /vagrant/roles/database/files/triggers-enrolments-integrity-constraints.sql;`
To Do only in PRE:
-
Load scene_adapt
`source /vagrant/roles/database/files/scene_adapt.sql`
(already done in dev)
-
update arasaac uri
...
...
sails/src/api/controllers/SceneController.js
View file @
4a0ea020
...
...
@@ -22,7 +22,7 @@ module.exports = {
student
:
params
.
id_stu
}).
then
(
scene
=>
{
if
(
scene
.
categories
){
Scene
.
query
(
'CALL scene
º
_create_core(?,?) '
,[
scene
.
id
,
scene
.
student
],
function
(
err
,
result
)
{
Scene
.
query
(
'CALL scene_create_core(?,?) '
,[
scene
.
id
,
scene
.
student
],
function
(
err
,
result
)
{
// if (err) {
// return res.serverError("Could not call stored procedure create scene picto core "+err);
// } else {
...
...
sails/src/api/controllers/StudentController.js
View file @
4a0ea020
...
...
@@ -187,6 +187,9 @@ module.exports = {
Student
.
create
(
params
)
.
then
(
function
(
created
)
{
Scene
.
query
(
'CALL NEW_STUDENT_AUX() '
,[],
function
(
err
,
result
)
{
});
sails
.
log
.
debug
(
'Student '
+
created
.
id
+
' created: '
+
JSON
.
stringify
(
created
));
License
.
activate
(
params
.
license_number
,
created
.
id
,
function
(
err
,
license
)
{
if
(
err
)
...
...
@@ -827,7 +830,7 @@ module.exports = {
if
(
typeof
req
.
params
.
id_stu
==
'undefined'
||
!
req
.
params
.
id_stu
)
return
res
.
badRequest
(
"id_stu not defined"
);
Student
.
findOne
({
id
:
req
.
params
.
id_stu
}).
then
(
function
(
student
){
Scene
.
findOne
({
id
:
student
.
id_active_scene
})
Scene
.
findOne
({
id
:
student
.
attributes
.
id_active_scene
})
.
then
(
function
(
scene
){
if
(
!
scene
)
return
res
.
badRequest
(
"Scene not found"
);
...
...
@@ -880,7 +883,7 @@ module.exports = {
getScenes
:
function
(
req
,
res
){
if
(
typeof
req
.
params
.
id_stu
==
'undefined'
||
!
req
.
params
.
id_stu
)
return
res
.
badRequest
(
"id_stu not defined"
);
Student
.
findOne
({
id
:
params
.
id_stu
})
Student
.
findOne
({
id
:
req
.
params
.
id_stu
})
.
then
(
student
=>
{
Scene
.
find
({
student
:
req
.
params
.
id_stu
})
.
then
(
function
(
scenes
){
...
...
sails/src/assets/scripts/modules/student/controllers/collections.js
View file @
4a0ea020
...
...
@@ -296,7 +296,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// Activate student scene
$scope
.
activate_scene
=
function
(
scene
)
{
$http
.
put
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/activeScene/'
+
scene
.
id
,
{})
$http
.
put
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/activeScene/'
+
scene
.
id
,
{
id_scene
:
scene
.
id
})
.
success
(
function
()
{
var
data
=
{
id
:
scene
.
id
};
...
...
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