refactored database, models and controllers

parent d36e04ff
......@@ -10,9 +10,9 @@ Los ficheros SQL que importará este rol son los siguientes:
- [init-ignoresymbolstix][2] realiza el mismo proceso que [init][1], pero manteniendo
los datos almacenados por symbolstx.
- [pictodb-schema][3] contiene el esquema de la base de datos.
- [pictodb-data][4] contiene la información básica que la aplicación necesita para funcionar.
- [symbolstx-categories][5] añade las categorías de symbolstx.
- [symbolstix-metadata][6] añade traducciones para symbolstx.
- [pictodb-data][4] contiene la información básica que la aplicación necesita para funcionar. Añade información a las tablas `meta_method`, `meta_instruction`, `source`, `picto_core` y `picto_exp`.
- [symbolstx-categories][5] añade las categorías de symbolstx en las tablas `pictocat` y `catexp`.
- [symbolstix-metadata][6] añade traducciones para symbolstx y los pictos (tablas `picto_exp`, `picto_tag` y `picto`).
- [triggers-enrolments-integrity-constraints][7] añade disparadores para el control de
integridad de inscripciones.
- [triggers-sessions-integrity-constraints][8] añade disparadores para el control de integridad
......
--
-- All data is deleted from the database except symbolstix tables and basic metadata
-- Afterwords, test data can be loaded
--
--
-- TO BE DONE!!!
SET foreign_key_checks=0;
GRANT USAGE ON *.* TO 'pictodbuser'@'localhost';
DROP USER 'pictodbuser'@'localhost';
CREATE USER 'pictodbuser'@'localhost' identified by 'p1KT015';
DROP DATABASE IF EXISTS pictodb;
CREATE DATABASE pictodb;
SET @TRIGGER_CHECKS=FALSE;
DELETE FROM picto_tag WHERE `id_sup` IS NOT NULL;
DELETE FROM picto WHERE `owner` IS NOT NULL;
TRUNCATE office;
TRUNCATE supervisor;
TRUNCATE student;
TRUNCATE stu_sup;
TRUNCATE stu_picto;
TRUNCATE method;
TRUNCATE instruction;
TRUNCATE try;
TRUNCATE working_session;
SET @TRIGGER_CHECKS=TRUE;
SET foreign_key_checks=1;
grant all privileges on pictodb.* to pictodbuser;
flush privileges;
......@@ -51,10 +51,10 @@ INSERT INTO `source` (`id`, `name`, `description`) VALUES
SET foreign_key_checks=0;
--
-- Volcado de datos para la tabla `picto_core_cat`
-- Volcado de datos para la tabla `picto_core`
--
INSERT INTO `picto_core_cat` (`id`, `id_pic`, `id_cat_pic`, `coord_x`, `coord_y`,`color`) VALUES
INSERT INTO `picto_core` (`id`, `id_pic`, `id_cat_pic`, `coord_x`, `coord_y`,`color`) VALUES
(1, 2982, NULL, 0, 0, NULL), -- yes
(2, 4391, NULL, 0, 1, NULL), -- no
(3, 2284, NULL, 0, 2, NULL), -- please
......
The file could not be displayed because it is too large.
......@@ -6,7 +6,7 @@ SET foreign_key_checks = 0;
-- Oficina Autismo Jaen
--
INSERT INTO `office` (
INSERT IGNORE INTO `office` (
`name`,
`address`,
`country`,
......@@ -29,7 +29,7 @@ INSERT INTO `office` (
-- La contraseña es la primera parte del email (ej: manuel.colmenero)
--
INSERT INTO `supervisor` (
INSERT IGNORE INTO `supervisor` (
`name`,
`surname`,
`gender`,
......@@ -65,7 +65,7 @@ UPDATE office
-- La contraseña es la primera parte del email (ej: manuel.colmenero)
--
INSERT INTO `supervisor` (
INSERT IGNORE INTO `supervisor` (
`name`,
`surname`,
`gender`,
......@@ -116,7 +116,7 @@ INSERT INTO `supervisor` (
-- La contraseña es la primera parte del email (ej: manuel.colmenero)
--
INSERT INTO `supervisor` (
INSERT IGNORE INTO `supervisor` (
`name`,
`surname`,
`gender`,
......@@ -163,7 +163,7 @@ INSERT INTO `supervisor` (
-- La contraseña es el nombre de usuario
--
INSERT INTO `student` (
INSERT IGNORE INTO `student` (
`username`,
`password`,
`name`,
......@@ -287,7 +287,7 @@ INSERT INTO `student` (
-- Student pictos
--
INSERT INTO `stu_picto` (
INSERT IGNORE INTO `stu_picto` (
`id_stu`,
`id_pic`,
`attributes`
......@@ -300,7 +300,7 @@ SELECT S.id, P.id_pic, concat('{',
',"highlight":false',
',"color":', if (P.color is null, 'null', concat('"', P.color,'"')),
'}') as attributes
FROM student S, picto_core_cat P
FROM student S, picto_core P
WHERE
S.id_off=(SELECT id
FROM office
......
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
SET foreign_key_checks = 0;
SET @TRIGGER_CHECKS = FALSE;
--
-- Oficina
......@@ -394,7 +395,7 @@ SELECT S.id,P.id_pic, concat('{"id_cat":', if (id_cat_pic is null, 'null',id_cat
',"highlight":false',
',"color":', if (color is null, 'null',concat('"',color,'"')),
'}') as attributes
FROM student S, picto_core_cat P
FROM student S, picto_core P
WHERE S.id_off =(SELECT id from office where name='Comunicación Aumentativa JAén (CAJA)');
--
......@@ -417,4 +418,5 @@ INSERT INTO working_session (id_sup, id_ins) VALUES (
(SELECT id FROM instruction WHERE name='Test Instruction')
);
SET @TRIGGER_CHECKS = TRUE;
SET foreign_key_checks=1;
......@@ -5,10 +5,13 @@ DELIMITER ;;
-- Integrity rule 1: It is not possible to enrol a higer number of student than office.max_enrolments
DROP TRIGGER IF EXISTS TRG_NEW_STUDENT_MAXENROLMENTS;
CREATE TRIGGER TRG_NEW_STUDENT_MAXENROLMENTS
BEFORE INSERT ON student
FOR EACH ROW
thisTrigger: BEGIN
DECLARE max_enr,curr_enr INT;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_BEFORE_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
......@@ -16,7 +19,6 @@ thisTrigger: BEGIN
LEAVE thisTrigger;
END IF;
DECLARE max_enr,curr_enr INT;
IF new.id_off IS NOT NULL THEN
SELECT
max_students, current_students INTO max_enr, curr_enr
......@@ -34,6 +36,7 @@ thisTrigger: BEGIN
END;;
-- Integrity rule 2: office.current_enrolments updating
DROP TRIGGER IF EXISTS TRG_NEW_STUDENT_UPDATE_ENROLMENTS;
CREATE TRIGGER TRG_NEW_STUDENT_UPDATE_ENROLMENTS
AFTER INSERT ON student
FOR EACH ROW
......@@ -54,6 +57,7 @@ thisTrigger: BEGIN
END;;
-- Integrity rule 3: office.current_enrolments and supervisor assigments updating.
DROP TRIGGER IF EXISTS TRG_MODIFY_STUDENT_ENROLMENTS;
CREATE TRIGGER TRG_MODIFY_STUDENT_ENROLMENTS
AFTER UPDATE ON student
FOR EACH ROW
......@@ -92,6 +96,7 @@ thisTrigger: BEGIN
END;;
-- Integrity rule 4: office.current_enrolments when deleting student. Note that is not required to delete stu_sup because stu_sup.id_stu is a foreign key of student
DROP TRIGGER IF EXISTS TRG_DELETE_STUDENT_ENROLMENTS;
CREATE TRIGGER TRG_DELETE_STUDENT_ENROLMENTS
AFTER DELETE ON student
FOR EACH ROW
......
......@@ -7,6 +7,7 @@ DELIMITER ;;
--
-- Get the current try for a given session by reading disk-based tables only
--
DROP FUNCTION IF EXISTS getOpenTry;
CREATE FUNCTION getOpenTry(idstu INT)
RETURNS INT
READS SQL DATA
......@@ -29,6 +30,7 @@ END;;
--
-- Memory table in order to recover data about current working sessions
--
DROP TABLE IF EXISTS stu_opentry;
CREATE TABLE stu_opentry (
id int(11) NOT NULL AUTO_INCREMENT,
id_stu int(11) NOT NULL,
......@@ -51,6 +53,7 @@ FOREIGN KEY (id_ws) REFERENCES working_session(id) ON DELETE CASCADE
-- It creates a new try and notes down the try into the STU_OPENTRY memory table
-- additional notes: For the sake of efficiency, memory table STU_OPENTRY is updated
--
DROP PROCEDURE IF EXISTS newTry;
CREATE PROCEDURE newTry(idstu INT, idsup INT, idws INT)
MODIFIES SQL DATA
BEGIN
......@@ -74,6 +77,7 @@ END;;
--
-- It deletes current try for a given session
DROP PROCEDURE IF EXISTS deleteOpenTry;
CREATE PROCEDURE deleteOpenTry(ws INT)
BEGIN
DECLARE idopentry INT;
......@@ -92,17 +96,19 @@ END;;
-- Integrity rule 1: A new session begins and in turn a new try is created
-- Integrity rule 8: Any instruction with a new session has a "started" state
-- when: state COM, event a2
DROP TRIGGER IF EXISTS TRG_SESSION_NEW;
CREATE TRIGGER TRG_SESSION_NEW
AFTER INSERT ON working_session
FOR EACH ROW
thisTrigger: BEGIN
DECLARE idstu INT;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
DECLARE idstu INT;
SELECT DISTINCT M.id_stu INTO idstu
FROM
......@@ -124,6 +130,7 @@ END;;
-- when: state COM, event a4
-- current is to NULL (integrity rule 6)
--
DROP TRIGGER IF EXISTS TRG_SESSION_CLOSED;
CREATE TRIGGER TRG_SESSION_CLOSED
AFTER UPDATE ON working_session
FOR EACH ROW
......@@ -144,18 +151,20 @@ END;;
-- Integrity rule 3: every event is required to have the id try whenver a try happens
-- when: state COM, event a4
--
DROP TRIGGER IF EXISTS TRG_NEW_EVENT_ONSESSION;
CREATE TRIGGER TRG_NEW_EVENT_ONSESSION
BEFORE INSERT ON action
FOR EACH ROW
thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
DECLARE idstu INT;
DECLARE idtry INT;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_BEFORE_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
DECLARE idstu INT;
DECLARE idtry INT;
SET idstu=NEW.id_stu;
SELECT id_opentry INTO idtry
FROM
......@@ -174,21 +183,22 @@ END;;
-- when: state PAU, event a3
-- Integrity rule 4: when a session is paused, last try must be discharged
-- when: state SES, event a3
DROP TRIGGER IF EXISTS TRG_NEW_EVENT;
CREATE TRIGGER TRG_NEW_EVENT
AFTER INSERT ON action
FOR EACH ROW
thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
DECLARE idopentry INT;
DECLARE idsup_ws INT;
DECLARE idws INT;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
DECLARE idopentry INT;
DECLARE idsup_ws INT;
DECLARE idws INT;
CASE NEW.type
WHEN 'Show' THEN
SELECT id_ws, id_sup, id_opentry INTO idws, idsup_ws, idopentry
......@@ -230,6 +240,7 @@ ALTER TABLE `working_session`
-- when: state COM, event a4
-- current is to NULL (integrity rule 6)
--
DROP TRIGGER IF EXISTS TRG_SESSION_CLOSING;
CREATE TRIGGER TRG_SESSION_CLOSING
BEFORE UPDATE ON working_session
FOR EACH ROW
......@@ -255,19 +266,21 @@ ALTER TABLE `action`
--
-- Required for not closed sessions policy retrieving
--
DROP TRIGGER IF EXISTS TRG_TRY_EVALUATED;
CREATE TRIGGER TRG_TRY_EVALUATED
AFTER UPDATE ON try
FOR EACH ROW
thisTrigger: BEGIN
DECLARE idopentry INT;
DECLARE idws INT;
DECLARE ws_end DATE;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_UPDATE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
DECLARE idopentry INT;
DECLARE idws INT;
DECLARE ws_end DATE;
SELECT id_ws, id_opentry,end INTO idws, idopentry, ws_end
FROM
stu_opentry
......
/* global sails, Picto, Supervisor, PictoCat, PictoTagSup, PictoExp */
/* global sails, Picto, Supervisor, PictoCat, PictoTag, PictoExp */
/**
* PictoController
......@@ -125,14 +125,14 @@ module.exports = {
throw new Error('Picto not found');
}
PictoTagSup.create({
PictoTag.create({
tag: params.tag,
lang: params.lang,
picto: picto.id,
supervisor: supervisor.id
}).then(function (pictoTagSup) {
if (pictoTagSup) {
res.ok(pictoTagSup);
}).then(function (pictoTag) {
if (pictoTag) {
res.ok(pictoTag);
} else {
res.serverError();
}
......@@ -153,16 +153,19 @@ module.exports = {
/**
* Removes a picto tag created by the supervisor
* @param {request} req {} (with pictoTagId specified in parameters)
* @param {request} {
* "id_tag": 1234,
* "id_sup": 123
* }
* @param {response} res {}
*/
del_tag: function (req, res) {
var params = req.params.all();
if (!params.id_tag) {
if (!params.id_tag || !params.id_sup) {
res.badRequest();
} else {
PictoTagSup.destroy({ id: params.id_tag }).then(function () {
PictoTag.destroy({ id: params.id_tag, id_sup: params.id_sup }).then(function () {
res.ok();
})
.catch(function () {
......@@ -171,17 +174,26 @@ module.exports = {
}
},
// Destroy don't delete the picto, it removes the owner to students still having it
/**
* Destroy don't delete the picto, it removes the link to students
* @param {request} {
* "id": 2343
* }
* @param {response} res {}
*/
destroy: function(req, res) {
var params = req.params.all();
if (!params.id) {
return res.json(500, {error: "No id picto defined"});
}
Picto.update({ id: params.id }, { owner: null}).exec(function (err, updated) {
if (err) throw err;
return res.json(updated[0]);
});
res.badRequest();
} else {
Picto.update({ id: params.id }, { owner: null}).then(function (updated) {
res.ok(updated[0]);
})
.catch(function() {
res.serverError();
});
}
},
/**
......
/* global Student, PictoCoreCat, VStuLastInstruction, StuPicto, StuSup, sailsTokenAuth, sails,
/* global Student, PictoCore, VStuLastInstruction, StuPicto, StuSup, sailsTokenAuth, sails,
Picto */
/**
......@@ -141,34 +141,34 @@ module.exports = {
sails.log.debug('Student ' + created.id + ' created: ' + JSON.stringify(created));
// Assign the initial collection of pictos to the student
PictoCoreCat.find()
.exec(function (pictoCoreCatError, pictoCoreCat) {
PictoCore.find()
.exec(function (pictoCoreError, pictoCore) {
var i;
if (pictoCoreCatError || !pictoCoreCat || pictoCoreCat.length === 0) {
sails.log.debug('PictoCoreCat: ' + pictoCoreCatError);
if (pictoCoreError || !pictoCore || pictoCore.length === 0) {
sails.log.debug('PictoCore: ' + pictoCoreError);
return;
}
sails.log.debug('PictoCoreCat Length: ' + pictoCoreCat.length);
sails.log.debug(pictoCoreCat);
sails.log.debug('PictoCore Length: ' + pictoCore.length);
sails.log.debug(pictoCore);
// Every picto from 'picto_core_cat' is going to be created
// in 'stu_picto'
for (i = 0; i < pictoCoreCat.length; i++) {
for (i = 0; i < pictoCore.length; i++) {
sails.log.debug('Loop: ' + i);
sails.log.debug('Picto Category: ' + pictoCoreCat[i].category);
sails.log.debug('Picto Category: ' + pictoCore[i].category);
sails.log.debug('User id: ' + created.id);
StuPicto.create({
student: created.id,
picto: pictoCoreCat[i].picto,
picto: pictoCore[i].picto,
attributes: {
id_cat: pictoCoreCat[i].category,
coord_x: pictoCoreCat[i].coord_x,
coord_y: pictoCoreCat[i].coord_y,
id_cat: pictoCore[i].category,
coord_x: pictoCore[i].coord_x,
coord_y: pictoCore[i].coord_y,
status: 'invisible', // Default, the pictos don't appear to the user
color: pictoCoreCat[i].color
color: pictoCore[i].color
}
})
.exec(function (stuPictoError, added) {
......@@ -947,26 +947,13 @@ module.exports = {
var action = req.param('action');
var attributes = req.param('attributes');
var roomName = 'studentRoom' + attributes.id_stu;
sails.log.debug("Inside /stu/subscribe. Action: " + action);
if (req.isSocket) {
sails.log.debug("Inside /stu/subscribe - isSocket");
sails.sockets.join(req.socket, roomName);
sails.io.sockets.in(roomName)
.clients(function (err, ids) {
sails.log.debug("number of clients in room: " + ids.length);
if (!err)
sails.io.to(roomName)
.emit('update_peers', {
count: ids.length
});
});
res.json({
msg: "Subscribed to student " + roomName
});
sails.hooks.rooms.subscribeToRoom(
sails.hooks.rooms.student(attributes.id_stu),
req.socket
);
}
res.ok({msg: "Subscribed to student "});
},
//
......@@ -976,10 +963,7 @@ module.exports = {
var action = req.param('action');
//var attributes = req.param('attributes');
sails.log.debug("Inside /stu/unsubscribe. Action: " + action);
if (req.isSocket) {
sails.log.debug("Inside /stu/unsubscribe - isSocket");
var rooms = sails.sockets.socketRooms(req.socket);
console.log("Subscribed rooms in socket: " + JSON.stringify(rooms));
......@@ -1027,17 +1011,22 @@ module.exports = {
action: function (req, res) {
var action = req.param('action');
var attributes = req.param('attributes');
var roomName = 'studentRoom' + attributes.id_stu;
sails.log.debug("Inside action. Student:" + attributes.id_stu);
if (req.isSocket) {
sails.log.debug("websockets - room " + roomName);
// BROADCAST to everyone subscribed to this student
sails.sockets.broadcast(roomName, 'action', {
"action": action,
"attributes": attributes
});
const socketToOmit = (req.isSocket) ? req.socket : undefined;
sails.hooks.events.broadcast(
sails.hooks.rooms.student(attributes.id_stu),
'action',
{
"action": action,
"attributes": attributes
},
socketToOmit
);
var sup = null;
if (attributes.supervisor) sup = attributes.supervisor;
......@@ -1077,20 +1066,21 @@ module.exports = {
config: function (req, res) {
var action = req.param('action');
var attributes = req.param('attributes');
var roomName = 'studentRoom' + attributes.id_stu;
sails.log.debug("Inside config");
if (req.isSocket) {
sails.log.debug("Inside config - isSocket");
sails.sockets.broadcast(roomName, 'config', {
"action": action,
"attributes": attributes
});
res.json({
const socketToOmit = (req.isSocket) ? req.socket : undefined;
sails.hooks.events.broadcast(
sails.hooks.rooms.student(attributes.id_stu),
'action',
{
"action": action,
"attributes": attributes
},
socketToOmit
);
} else {
res.ok({
msg: "Config " + action + " action from student " + attributes.id_stu
});
}
......
// @TODO 357
module.exports = {
// Mostrar etiquetas propias del supervisor para un pictograma
// Blueprint
// GET /supervisor/:idSup/pictos/:idAclPicto/tags -> Tutor.find
// NO BORRAR: Necesario cuando hay más de 2 niveles en la URL
find: function(req, res){
var idAclPicto = req.param('idAclPicto');
// Comprobación de que se envían los campos
if(!idAclPicto){
return res.json(401, {err: 'Required field: ID of picto permission'});
}
// Crear tutor (en tabla tutor y supervisor)
SupPictoTag.find({
idAclPicto: idAclPicto
}).exec(
function (err, tags) {
if(err){
res.json(err.status, {err: err});
return;
}else{
res.json({tags: tags});
}
}
);
}
};
// @TODO 357
module.exports = {
// Crear teacher/supervisor
create: function(req, res){
var name = req.param('name');
var surname = req.param('surname');
var contactEmail = req.param('contactEmail');
var preferedLanguage = req.param('preferedLanguage');
var idOff = req.param('idOff');
// Comprobación de que se envían ambos campos
if(!name || !surname || !contactEmail || !preferedLanguage || !idOff){
return res.json(401, {err: 'Required fields: Name, surname, contact email, prefered language and Office ID'});
}
// Crear teacher (en tabla teacher y supervisor)
Teacher.create({
// id: "17", Es autoincrement
idOff: idOff,
supervisor:{
name: name,
surname: surname,
contactEmail: contactEmail,
preferedLanguage: preferedLanguage
}
}).exec(
function (err, teacher) {
if(err){
res.json(err.status, {err: err});
return;
}else{
res.json({teacher: teacher});
}
}
);
},
// Elimina teacher/supervisor
// CUSTOM Blueprint
// DELETE /teacher/:idSup -> Teacher.destroy
destroy: function(req, res){
var idSup = req.param('idSup');
// Comprobación de que se envían los campos
if(!idSup){
return res.json(400, {err: 'Required fields: Teacher/Supervisor ID'});
}
// Eliminar entrada de tutor
Teacher.destroy(
{"supervisor": idSup}
).exec(
function (err, teacher) {
if(err){
res.json(err.status, {err: err});
return;
}else{
// Eliminar entrada de supervisor
Supervisor.destroy(
idSup
).exec(
function (err, supervisor) {
if(err){
res.json(err.status, {err: err});
return;
}else{
res.json({
teacher: teacher,
supervisor: supervisor
});
}
}
);
}
}
);
}
};
// @TODO 357
module.exports = {
// Crear tutor/supervisor
// Blueprint
// POST /tutor -> Tutor.create
create: function(req, res){
var name = req.param('name');
var surname = req.param('surname');
var contactEmail = req.param('contactEmail');
var preferedLanguage = req.param('preferedLanguage');
// Comprobación de que se envían ambos campos
if(!name || !surname || !contactEmail || !preferedLanguage){
return res.json(401, {err: 'Required fields: Name, surname, contact email and prefered language'});
}
// Crear tutor (en tabla tutor y supervisor)
Tutor.create({
// id: "17", Es autoincrement
supervisor:{
name: name,
surname: surname,
contactEmail: contactEmail,
preferedLanguage: preferedLanguage
}
}).exec(
function (err, tutor) {
if(err){
res.json(err.status, {err: err});
return;
}else{
res.json({tutor: tutor});
}
}
);
},
// Elimina tutor/supervisor
// CUSTOM Blueprint
// DELETE /tutor/:idSup -> Tutor.destroy
destroy: function(req, res){
var idSup = req.param('idSup');
// Comprobación de que se envían los campos
if(!idSup){
return res.json(400, {err: 'Required fields: Tutor/Supervisor ID'});
}
// Eliminar entrada de tutor
Tutor.destroy(
{"supervisor": idSup}
).exec(
function (err, tutor) {
if(err){
res.json(err.status, {err: err});
return;
}else{
// Eliminar entrada de supervisor
Supervisor.destroy(
idSup
).exec(
function (err, supervisor) {
if(err){
res.json(err.status, {err: err});
return;
}else{
res.json({
tutor: tutor,
supervisor: supervisor
});
}
}
);
}
}
);
}
};
/**
* License.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
tableName : 'license',
migrate : 'safe',
schema : true,
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id: {
type: "integer",
autoIncrement: true,
primaryKey: true,
unique: true
},
supervisor: { // relation 1 supervisor to N licences
type: 'integer',
required: true,
model: 'Supervisor',
columnName: 'id_sup'
},
number: {
type: 'string',
required: true
},
maxStu: { // maximum number of students that can be associated with this license
type: 'integer',
required: true,
columnName: 'max_stu'
},
duration: { // number of days per student that the license lasts
type: 'integer',
required: true
},
created: { // date when the license was created
type: 'date',
required: true
},
activations: {
collection: 'LicenseActivation',
via: 'license'
}
}
};
/**
* LicenseActivation.js
*
* @description :: Activations of terapeuthical access to students by spending license
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
identity : 'LicenseActivation',
tableName : 'license_activation',
migrate : 'safe',
schema : true,
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id: {
type: "integer",
autoIncrement: true,
primaryKey: true,
unique: true
},
stuSup: {
columnName: "id_stu_sup",
required: true,
type: "integer",
model: "StuSup"
},
license: {
columnName: "id_lic",
required: true,
type: "integer",
model: "License"
},
activation: {
columnName: 'activation',
type: 'date',
required: false
},
expiration: {
columnName: 'expiration',
type: 'date',
required: false
}
}
}
\ No newline at end of file
/**
* PendingRegistration.js
*
* @description :: This are official devices sold by us
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
tableName : 'pending_registration',
migrate : 'safe',
schema : true,
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
idSup: {
columnName: 'id_sup',
type: "integer",
size: 11
},
hash: {
type: 'integer',
size: 32
},
timestamp: {
type: 'date'
}
}
};
......@@ -52,10 +52,6 @@ module.exports = {
collection: 'PictoTag',
via: 'picto'
},
tagsSup: {
collection: 'PictoTagSup',
via: 'picto'
},
pictoAcls: { // 1 Picto to N PictoAcl
collection: 'PictoAcl',
via: 'picto'
......
/**
* PictoAcl.js
*
* @description :: TODO: Write a short summary of how this model works and what it represents here.
* @description :: THIS CLASS IS NOT BEING USED (candidate for removal)
* @docs :: http://sailsjs.org/#!documentation/models
*/
......@@ -12,7 +12,7 @@ module.exports = {
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id: {
type: "integer",
......@@ -41,4 +41,4 @@ module.exports = {
type: "datetime"
}
}
};
\ No newline at end of file
};
......@@ -12,7 +12,7 @@ module.exports = {
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id: {
type: "integer",
......@@ -26,6 +26,12 @@ module.exports = {
required: true,
model: 'Picto'
},
category: {
columnName: 'id_cat_pic',
type: 'integer',
required: false,
model: 'Picto'
},
coord_x: {
type: 'integer',
required: false
......@@ -40,4 +46,3 @@ module.exports = {
}
}
};
/**
* PictoCoreCat.js
*
* @description :: This are the pictos that represent a category.
* This model is to store pos x and y when picto is presented as category
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
tableName : 'picto_core_cat',
migrate : 'safe',
schema : true,
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id: {
type: "integer",
autoIncrement: true,
primaryKey: true,
unique: true
},
picto: {
columnName: 'id_pic',
type: 'integer',
required: true,
model: 'Picto'
},
category: {
columnName: 'id_cat_pic',
type: 'integer',
required: true,
model: 'Picto'
},
coord_x: {
type: 'integer',
required: false
},
coord_y: {
type: 'integer',
required: false
},
color:{
type: 'integer',
required: false
}
}
};
......@@ -12,7 +12,7 @@ module.exports = {
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id: {
type: "integer",
......@@ -26,6 +26,12 @@ module.exports = {
type: "integer",
model: "Picto"
},
supervisor:{ // FK de Tag. 1 a N
columnName: "id_sup",
required: false,
type: "integer",
model: "Supervisor"
},
tag: { // FK de Tag. 1 a N
columnName: "tag",
required: true,
......@@ -39,4 +45,4 @@ module.exports = {
required: true
}
}
};
\ No newline at end of file
};
/**
* PictoTagSup.js
*
* @description :: TODO: Write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
tableName : 'picto_tag_sup',
migrate : 'safe',
schema : true,
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id: {
type: "integer",
autoIncrement: true,
primaryKey: true,
unique: true
},
picto:{ // FK de Picto. 1 a N
columnName: "id_pic",
required: true,
type: "integer",
model: 'Picto'
},
supervisor:{ // FK de Tag. 1 a N
columnName: "id_sup",
required: true,
type: "integer",
model: "Supervisor"
},
tag:{
type: "string",
size: 20,
required: true
},
lang:{
type: "string",
size: 2,
required: true
}
}
};
\ No newline at end of file
/**
* StuOpenTry.js
*
* @description :: TODO: Write a short summary of how this model works and what it represents here.
* @description :: This model is the Active Record of the table stu_opentry,
* which is defined in triggers-sessions-integrity-constraints.sql. It is used
* to avoid losing initiated tries within a session.
*
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
......@@ -11,7 +14,7 @@ module.exports = {
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id: {
type: "integer",
......@@ -25,25 +28,25 @@ module.exports = {
id_sup: {
type: "integer",
},
id_ws: {
type: "integer",
id_ws: {
type: "integer",
},
openTry: {
openTry: {
columnName: "id_opentry",
type: "integer",
unique: true
},
total_tries: {
total_tries: {
columnName: "total_tries",
type: "integer",
type: "integer",
},
begin: {
begin: {
columnName: "begin",
type: "datetime",
type: "datetime",
},
end: {
end: {
columnName: "end",
type: "datetime",
type: "datetime",
}
}
}
\ No newline at end of file
}
......@@ -80,6 +80,7 @@
"enlarge": "Enlarge",
"enormous": "Enormous",
"error_adding_picto": "Error adding picto",
"error_deleting_picto": "Error deleting picto",
"error_downloading_supervisors": "Error downloading supervisors",
"error_downloading_offices": "Error downloading offices",
"error_only_support_images": "Only images are supported (JPG, PNG or GIF files)",
......@@ -249,6 +250,7 @@
"supervisor_updated": "Supervisor updated",
"supervisors": "Therapist",
"surname": "Surname",
"tag_deleted": "Tag deleted",
"tape_background": "Tape background",
"time_instruction_method": "Time instructions of method",
"time_hours": "Time: {{hours}} hours",
......
......@@ -83,6 +83,7 @@
"expand_navigation": "Desplegar navegación",
"expression": "Expresión:",
"error_adding_picto": "Error al añadir el picto",
"error_deleting_picto": "Error borrando el picto",
"error_downloading_supervisors": "Error al descargar los supervisores",
"error_downloading_offices": "Error al descargar las oficinas",
"error_only_support_images": "Sólo se soportan imágenes (ficheros JPG, PNG o GIF)",
......@@ -250,6 +251,7 @@
"supervisor_updated": "Supervisor actualizado",
"supervisors": "Terapeutas",
"surname": "Apellidos",
"tag_deleted": "Etiqueta borrada",
"tape_background": "Fondo de la cinta",
"time_hours": "Tiempo: {{hours}} horas",
"time_instruction_method": "Tiempo instrucciones del método",
......
......@@ -180,7 +180,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.close_ws = function (){
$http
.post(config.backend+ '/workingsession/'+$scope.wsessions[0].id+'/close')
.post(config.backend+ '/ws/'+$scope.wsessions[0].id+'/close')
.then(
function(data, status, headers, config) {
......@@ -203,7 +203,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.sessionRunning = true;
$http
.post(config.backend+'/workingsession', {
.post(config.backend+'/ws', {
"id_sup": $scope.user.id,
"id_stu": $scope.studentData.id,
"id_ins": $scope.selectedIns
......@@ -239,7 +239,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.update_ws = function (ws){
$http
.put(config.backend+'/workingsession/' + ws.id, { "description" : ws.description })
.put(config.backend+'/ws/' + ws.id, { "description" : ws.description })
.then(function(data, status, headers, config) {
......@@ -259,7 +259,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.ws.end = new Date();
$http
.put(config.backend+'/workingsession/' + $scope.ws.id, { "end": $scope.ws.end,
.put(config.backend+'/ws/' + $scope.ws.id, { "end": $scope.ws.end,
"id_stu": $scope.studentData.id
})
.success(function(data, status, headers, config) {
......
......@@ -48,16 +48,20 @@ dashboardControllers.controller('TagsCtrl', function TagsCtrl(
$scope.tagToAdd = '';
})
.error(function () {
// TODO show error with ngToast
$translate('error_adding_tag').then(function (translation) {
ngToast.danger({ content: translation });
});
});
};
// Destroy own tag
$scope.del = function (tag) {
$http.delete(config.backend + '/picto/tag/' + tag.id)
$http.delete(config.backend + '/picto/' + $scope.sup.id + '/tag/' + tag.id)
.success(function () {
var i;
// TODO show success with ngToast
$translate('tag_deleted').then(function (translation) {
ngToast.success({ content: translation });
});
// Eliminar de la vista: Se recorre el array de objetos json para buscarlo
for (i = 0; i < $scope.ownTags.length; i++) {
if (tag.id === $scope.ownTags[i].id) {
......@@ -66,7 +70,9 @@ dashboardControllers.controller('TagsCtrl', function TagsCtrl(
}
})
.error(function () {
// TODO show error with ngToast
$translate('error_deleting_tag').then(function (translation) {
ngToast.danger({ content: translation });
});
});
};
......
......@@ -50,7 +50,7 @@ module.exports.routes = {
'POST /picto/tag': 'PictoController.add_tag',
'POST /picto/exp': 'PictoController.change_exp',
'DELETE /picto/:id': 'PictoController.destroy',
'DELETE /picto/tag/:id_tag': 'PictoController.del_tag',
'DELETE /picto/:id_sup/tag/:id_tag': 'PictoController.del_tag',
'GET /server/ping': 'ServerController.ping',
'GET /server/ping_session': 'ServerController.ping_session',
......@@ -103,7 +103,7 @@ module.exports.routes = {
'GET /ws/:id_stu/year/:year': 'WorkingSessionController.per_year',
'GET /ws/:id_stu/month/:month': 'WorkingSessionController.per_month',
'GET /ws/:id_ws/tries': 'WorkingSessionController.tries',
'PUT /workingsession/:id': 'WorkingSessionController.update',
'POST /workingsession': 'WorkingSessionController.create',
'POST /workingsession/:id_ws/close': 'WorkingSessionController.close'
'PUT /ws/:id': 'WorkingSessionController.update',
'POST /ws': 'WorkingSessionController.create',
'POST /ws/:id_ws/close': 'WorkingSessionController.close'
};
......@@ -70,9 +70,9 @@ describe('Picto API', function () {
.end(done);
});
});
it('DELETE /picto/tag/:id_tag', function (done) {
it('DELETE /picto/:id_sup/tag/:id_tag', function (done) {
supervisorAgent
.delete('/picto/tag/' + 1234)
.delete('/picto/'+supervisorAgent.data.id+'/tag/' + 1234)
.send()
.expect(200)
.end(done);
......
/* eslint-disable no-console */
var DATABASE_BACKUP_FILE = '/tmp/pictogram_test_backup.sql';
var DATABASE_RESET_FILE = '../roles/database/files/init-ignoresymbolstix.sql'
var DATABASE_TESTDATA_FILE = '../roles/database/files/test-caja.sql'
var UPLOAD_FOLDER;
var UPLOAD_FOLDER_BACKUP;
var Agent = require('supertest').agent;
......@@ -17,6 +19,9 @@ before(function (serverLoadDone) {
// Backup the whole database
childProcess.execSync('mysqldump -u pictodbuser -pp1KT015 pictodb > ' + DATABASE_BACKUP_FILE);
// Prepare with test data
childProcess.execSync('mysql -u pictodbuser -pp1KT015 pictodb < ' + DATABASE_RESET_FILE);
childProcess.execSync('mysql -u pictodbuser -pp1KT015 pictodb < ' + DATABASE_TESTDATA_FILE);
sails.lift({}, function (error) {
var bcrypt = require('bcrypt-nodejs');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment