Commit 51132bc1 by Pablo Molina

Merge branch 'issue/363' into 'master'

Issue/363
parents c02ecc5e 6be3ab4e
Showing with 280 additions and 1248 deletions
deny from all
Este proyecto contiene el código de Pictogram, que se divide en tres: Este proyecto contiene el código de Pictogram, que se divide en tres:
* sails: API REST del servidor (sails.js) - [Servidor](sails): API REST del servidor
* angular: Aplicación web con el dashboard para supervisores (Angular.js) - [Cliente web](sails/src/assets/app): aplicación web con el dashboard para supervisores
* android: aplicación para tablet para estudiantes - [Cliente android](android/Pictogram): aplicación android para tablet para estudiantes
\ No newline at end of file
info: Starting app...
warn: Cannot read package.json in the current directory (/home/dofer/pictogram)
warn: Are you sure this is a Sails app?
warn: 
warn: The package.json in the current directory does not list Sails as a dependency...
warn: Are you sure `/home/dofer/pictogram` is a Sails app?
warn: 
info: 
info:  .-..-.
info: 
info:  Sails <| .-..-.
info:  v0.11.3 |\
info:  /|.\
info:  / || \
info:  ,' |' \
info:  .-'.-==|/_--'
info:  `--'-------'
info:  __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info: 
info: Server lifted in `/home/dofer/pictogram`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.

debug: --------------------------------------------------------
debug: :: Tue Dec 22 2015 21:34:51 GMT+0100 (CET)

debug: Environment : development
debug: Port : 1337
debug: --------------------------------------------------------
error: 
------------------------------------------------------------------------
grunt-cli: The grunt command line interface. (v0.1.13)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
------------------------------------------------------------------------

error: Looks like a Grunt error occurred--
error: Please fix it, then **restart Sails** to continue running tasks (e.g. watching for changes in assets)
error: Or if you're stuck, check out the troubleshooting tips below.

error: Troubleshooting tips:
error: 
error:  *-> Are "grunt" and related grunt task modules installed locally? Run `npm install` if you're not sure.
error: 
error:  *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.
error: 
error:  *-> Or maybe you don't have permissions to access the `.tmp` directory?
error:  e.g., `/home/dofer/pictogram/.tmp` ?
error: 
error:  If you think this might be the case, try running:
error:  sudo chown -R 1001 /home/dofer/pictogram/.tmp

# INSTALL
---
## Instalación previa
Instalar nodejs
```
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
```
(Sólo en Debian) Crear link simbólico por conflicto de nombre con el paquete para utilizar nodejs en lugar de node
```
sudo ln -s /usr/bin/nodejs /usr/bin/node
```
Instalar sails
```
sudo npm -g install sails
```
Fuente: http://sailsjs.org/#/getStarted
## Descarga y configuración del proyecto
Descarga del proyecto
```
git clone http://scm.ujaen.es/softuno/pictogram.git
```
Acceder a la carpeta `src` del proyecto e instalar las dependencias definidas en `package.json`
```
npm install
```
Descomprimir el archivo de pictogramas /pictogram/sails/conf/symbolstx.rar en /pictogram/sails
```
rar x symbolstx.rar
```
En carpeta `src` del proyecto levantar sails (comprobar en localhost:1337)
```
sails lift
```
O bien en modo consola para hacer pruebas (engloba a sails lift)
```
sails console
```
De las opciones que aparecen a continuación, seleccionar en producción `1. safe` o en desarrollo `2. alter`. Esta última reconstruye la BDD según los modelos definidos en sails sin eliminar la información que tuviera previamente.
```
1. safe - never auto-migrate my database(s). I will do it myself (by hand)
2. alter - auto-migrate, but attempt to keep my existing data (experimental)
3. drop - wipe/drop ALL my data and rebuild models every time I lift Sails
```
# Servidor de Pictogram e instalación del cliente web
En este directorio se encuentra el servidor web ([src](./src)) y la aplicación
web ([src/assets/app](./src/assets/app)). Los distintos ficheros de configuración
utilizados para la inicialización y el testeo de la aplicación se encuentran
en el directorio [conf](./conf).
## Dependencias
- Ubuntu >= 14.04
- Nodejs >= 0.10.37
- Npm >= 3.8.5
- Bower >= 1.4.1
## Instalación del servidor y el cliente web
- Ejecutar el script [install.sh](./install.sh) para instalar todas las
dependencias del servidor y el cliente web.
- Acceder al directorio [conf](./conf) para la instalación de la base de datos.
> **Importante**: el script utilizado creará un entorno para el servidor desde
> cero, por lo que **pueden perderse los datos** almacenados por usuarios.
## Desarrollo y pruebas
Para ejecutar el servidor como desarrollo se debe acceder al directorio
[conf](./conf) e instalar los datos de la base de datos necesarios.
## Ejecución
Para lanzar el servidor hay que acceder al directorio [src](./src) y ejecutar
uno de esos comandos:
- `sails lift`: para un servidor corriente
- `sails console`: para un servidor con un intérprete de nodejs con las
variables de sails expuestas
> El servidor se ejecutará en [localhost:1337/app](http://localhost:1337/app)
# Order of imports # Configuración de la base de datos
* `pictodb.sql` contains the SQL statements to create the schema of the database ## Scripts
* `pictodb-data.sql` contains first data load with basic information for the application to work
* `pictodb-test.sql` contains test data to be loaded in order to test the application in development
A script called `installdb.sh` will empty existing database and generate the new one and import the data, leaving you with a fresh database for development. - [installdb.sh](./installdb.sh) elimina la base de datos existente y realiza
una instalación limpia para producción.
- [installdb-tests.sh](./installdb-test.sh) realiza el mismo proceso
que [installdb.sh](./installdb.sh) pero añadiendo los datos de tests.
- [installdb-autismojaen.sh](./installdb-autismojaen.sh) realiza el mismo
proceso que [installdb.sh](./installdb.sh), pero añadiendo los datos de
autismojaen.
# Notes > **Importante**: para no añadir la biblioteca de symbolstix de nuevo
> y conservarla en el caso de que ya esté en la base de datos se puede
> añadir la opción `--ignore-symbolstix` a todos los scripts (por ejemplo
> `installdb.sh --ignore-symbolstix` no importará estos datos).
## Importing data ## Orden de la importación
To import `pictodb-data.sql` into MySQL without foreign key constraints, ensure that the imported file starts with `SET foreign_key_checks=0;` and then you turn on it again with `SET foreign_key_checks=1;`
### Datos necesarios
- [init.sql](./pictodb-init.sql) inicializa el usuario y permisos de la base de
datos.
- _[init-ignoresymbolstix.sql](./sql/init-ignoresymbolstix.sql) realiza el mismo
proceso que [init.sql](./sql/init.sql), pero ignorando a symbolstix._
- [pictodb-schema.sql](./sql/pictodb-schema.sql) contiene el esquema de la base de
datos.
- _[symbolstix-categories.sql](./sql/symbolstix-categories.sql) añade las
categorías de symbolstix._
- _[symbolstix-metadata.sql](./sql/symbolstix-metadata.sql) añade los
metadatos de symbolstix._
- [pictodb-data.sql](./sql/pictodb-data.sql) contiene la información básica que
la aplicación necesita para funcionar.
- [triggers-enrolments-integrity-constraints.sql](./pictodb-triggers-enrolments-integrity-constraints.sql)
añade disparadores para el control de integridad de inscripciones.
- [triggers-sessions-integrity-constraints.sql](./pictodb-triggers-enrolments-integrity-constraints.sql)
añade disparadores para el control de integridad de sesiones.
### Añadido de datos de desarrollo y pruebas
- [test.sql](./sql/test-autismojaen.sql) contiene datos para el desarrollo y
pruebas de la aplicación.
- [test-autismojaen.sql](./sql/test-autismojaen.sql) añade los datos de
autismojaen.
## Notes
### Importación de datos
To import `pictodb-data.sql` into MySQL without foreign key constraints, ensure
that the imported file starts with `SET foreign_key_checks=0;` and then you turn
on it again with `SET foreign_key_checks=1;`
### Eliminando la base de datos completa
## Droping all tables
```sql ```sql
SET foreign_key_checks=0; SET foreign_key_checks=0;
DROP TABLE `action`, `device`, `enrolment`, `instruction`, `license`, `license_activation`, `meta_picto`, `meta_stu`, `method`, `office`, `official_dev`, `picto`, `picto_acl`, `picto_core`, `picto_core_cat`, `picto_exp`, `picto_tag`, `picto_tag_sup`, `source`, `student`, `stu_picto`, `stu_sup`, `stu_sup_dev`, `supervisor`, `try`, `working_session`; DROP TABLE `action`, `device`, `enrolment`, `instruction`, `license`,
`license_activation`, `meta_picto`, `meta_stu`, `method`, `office`,
`official_dev`, `picto`, `picto_acl`, `picto_core`, `picto_core_cat`,
`picto_exp`, `picto_tag`, `picto_tag_sup`, `source`, `student`, `stu_picto`,
`stu_sup`, `stu_sup_dev`, `supervisor`, `try`, `working_session`;
SET foreign_key_checks=1; SET foreign_key_checks=1;
``` ```
\ No newline at end of file
#!/bin/bash
echo "SET foreign_key_checks=0;
TRUNCATE TABLE action;
TRUNCATE TABLE device;
TRUNCATE TABLE instruction;
TRUNCATE TABLE method;
TRUNCATE TABLE office;
TRUNCATE TABLE official_dev;
TRUNCATE TABLE picto_acl;
TRUNCATE TABLE picto_tag_sup;
TRUNCATE TABLE student;
TRUNCATE TABLE stu_dev;
TRUNCATE TABLE stu_picto;
TRUNCATE TABLE stu_sup;
TRUNCATE TABLE supervisor;
TRUNCATE TABLE try;
TRUNCATE TABLE working_session;
TRUNCATE TABLE meta_method;
TRUNCATE TABLE meta_picto;
TRUNCATE TABLE meta_stu;
TRUNCATE TABLE meta_instruction;
TRUNCATE TABLE source;
TRUNCATE picto_core_cat;
SET foreign_key_checks=1;" | mysql -u pictodbuser -pp1KT015 pictodb
#!/bin/bash
ROOT_PASSWD=passwd
IGNORE_SYMBOLSTIX=false
USAGE="Usage: ${0##*/} <mysql root pwd> [--ignore-symbolstix]"
DBUSER=pictodbuser
DBNAME=pictodb
function do_exit {
echo $USAGE
exit 1
}
function execute_db {
echo $1
mysql -u $DBUSER -pp1KT015 $DBNAME < $1
}
function main {
if [ $# -eq 0 ]; then do_exit; fi
if [ $# -gt 2 ]; then do_exit; fi
if [ $# -eq 1 ]; then ROOT_PASSWD=$1; fi
if [ $# -eq 2 ]; then
if [ $2 != '--ignore-symbolstix' ]; then do_exit; fi
ROOT_PASSWD=$1
IGNORE_SYMBOLSTIX=true
fi
if [ $IGNORE_SYMBOLSTIX == true ]; then
echo Init ignoring symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init-ignoresymbolstix.sql
else
echo Init with symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init.sql
fi
execute_db ./sql/pictodb-schema.sql
if [ $IGNORE_SYMBOLSTIX == false ]; then
execute_db ./sql/symbolstix-categories.sql
execute_db ./sql/symbolstix-metadata.sql
fi
execute_db ./sql/pictodb-data.sql
execute_db ./sql/test-autismojaen.sql
execute_db ./sql/triggers-enrolments-integrity-constraints.sql
execute_db ./sql/triggers-sessions-integrity-constraints.sql
}
main "$@"
#!/bin/bash
ROOT_PASSWD=passwdd
IGNORE_SYMBOLSTIX=false
USAGE="Usage: ${0##*/} <mysql root pwd> [--ignore-symbolstix]"
DBUSER=pictodbuser
DBNAME=pictodb
function do_exit {
echo $USAGE
exit 1
}
function execute_db {
echo $1
mysql -u $DBUSER -pp1KT015 $DBNAME < $1
}
function main {
if [ $# -eq 0 ]; then do_exit; fi
if [ $# -gt 2 ]; then do_exit; fi
if [ $# -eq 1 ]; then ROOT_PASSWD=$1; fi
if [ $# -eq 2 ]; then
if [ $2 != '--ignore-symbolstix' ]; then do_exit; fi
ROOT_PASSWD=$1
IGNORE_SYMBOLSTIX=true
fi
if [ $IGNORE_SYMBOLSTIX == true ]; then
echo Init ignoring symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init-ignoresymbolstix.sql
else
echo Init with symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init.sql
fi
execute_db ./sql/pictodb-schema.sql
if [ $IGNORE_SYMBOLSTIX == false ]; then
execute_db ./sql/symbolstix-categories.sql
execute_db ./sql/symbolstix-metadata.sql
fi
execute_db ./sql/pictodb-data.sql
execute_db ./sql/test.sql
execute_db ./sql/triggers-enrolments-integrity-constraints.sql
execute_db ./sql/triggers-sessions-integrity-constraints.sql
}
main "$@"
#!/bin/bash #!/bin/bash
echo "SET foreign_key_checks=0; ROOT_PASSWD=passwd
DROP TABLE action, catexp, device, instruction, meta_instruction, meta_method, IGNORE_SYMBOLSTIX=false
meta_picto, meta_stu, method, office, official_dev, picto, pictocat, picto_acl, picto_core, USAGE="Usage: ${0##*/} <mysql root pwd> [--ignore-symbolstix]"
picto_core_cat, picto_exp, picto_tag, picto_tag_sup, source, student, stu_dev, stu_picto, DBUSER=pictodbuser
stu_sup, supervisor, try, working_session; DBNAME=pictodb
SET foreign_key_checks=1;" | mysql -u pictodbuser -pp1KT015 pictodb
function do_exit {
mysql -u pictodbuser -pp1KT015 pictodb < pictodb.sql echo $USAGE
mysql -u pictodbuser -pp1KT015 pictodb < pictodb-data.sql exit 1
mysql -u pictodbuser -pp1KT015 pictodb < pictodb-test.sql }
mysql -u pictodbuser -pp1KT015 pictodb < pictodb-autismojaen.sql
# picto, picto_exp and picto_tag function execute_db {
mysql -u pictodbuser -pp1KT015 pictodb < symbolmetadata.sql echo $1
# pictocat and catexp mysql -u $DBUSER -pp1KT015 $DBNAME < $1
mysql -u pictodbuser -pp1KT015 pictodb < symbolcat.sql }
# Triggers for enrolments (office licenses) function main {
mysql -u pictodbuser -pp1KT015 pictodb < pictodb_enrolments_integrity_constraints.sql if [ $# -eq 0 ]; then do_exit; fi
if [ $# -gt 2 ]; then do_exit; fi
# Triggers and procedures for sessions if [ $# -eq 1 ]; then ROOT_PASSWD=$1; fi
mysql -u pictodbuser -pp1KT015 pictodb < pictodb_sessions_integrity_constraints.sql if [ $# -eq 2 ]; then
\ No newline at end of file if [ $2 != '--ignore-symbolstix' ]; then do_exit; fi
ROOT_PASSWD=$1
IGNORE_SYMBOLSTIX=true
fi
if [ $IGNORE_SYMBOLSTIX == true ]; then
echo Init ignoring symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init-ignoresymbolstix.sql
else
echo Init with symbolstix
mysql -u root -p$ROOT_PASSWD < ./sql/init.sql
fi
execute_db ./sql/pictodb-schema.sql
if [ $IGNORE_SYMBOLSTIX == false ]; then
execute_db ./sql/symbolstix-categories.sql
execute_db ./sql/symbolstix-metadata.sql
fi
execute_db ./sql/pictodb-data.sql
execute_db ./sql/triggers-enrolments-integrity-constraints.sql
execute_db ./sql/triggers-sessions-integrity-constraints.sql
}
main "$@"
set MYSQL=C:\wamp\bin\mysql\mysql5.6.17\bin\mysql.exe
echo Drop previous database
%MYSQL% -u root < pictodb_init.sql
echo Create schema
%MYSQL% -u pictodbuser -pp1KT015 pictodb < pictodb.sql
echo Insert data
%MYSQL% -u pictodbuser -pp1KT015 pictodb < pictodb-data.sql
%MYSQL% -u pictodbuser -pp1KT015 pictodb < pictodb-test-caja.sql
echo Insert symbols
%MYSQL% -u pictodbuser -pp1KT015 pictodb < symbolmetadata.sql
echo Insert cats
%MYSQL% -u pictodbuser -pp1KT015 pictodb < symbolcat.sql
echo Create constraints
%MYSQL% -u pictodbuser -pp1KT015 pictodb < pictodb_enrolments_integrity_constraints.sql
%MYSQL% -u pictodbuser -pp1KT015 pictodb < pictodb_sessions_integrity_constraints.sql
echo End
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Usage: ${0##*/} <mysql root pwd>"
exit 1
fi
echo Drop previous database
mysql -u root -p$1 < pictodb_init.sql
echo Create schema
mysql -u pictodbuser -pp1KT015 pictodb < pictodb.sql
# picto, picto_exp and picto_tag
echo Insert symbols
mysql -u pictodbuser -pp1KT015 pictodb < symbolmetadata.sql
# pictocat and catexp
echo Insert cats
mysql -u pictodbuser -pp1KT015 pictodb < symbolcat.sql
echo Insert data
mysql -u pictodbuser -pp1KT015 pictodb < pictodb-data.sql
mysql -u pictodbuser -pp1KT015 pictodb < pictodb-test-caja.sql
echo Create constraints
# Triggers for enrolments (office licenses)
mysql -u pictodbuser -pp1KT015 pictodb < pictodb_enrolments_integrity_constraints.sql
# Triggers and procedures for sessions
mysql -u pictodbuser -pp1KT015 pictodb < pictodb_sessions_integrity_constraints.sql
echo End
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Usage: ${0##*/} <mysql root pwd>"
exit 1
fi
echo Drop previous database
mysql -u root -p$1 < pictodb_init_keepsymbolstix.sql
echo Create schema
mysql -u pictodbuser -pp1KT015 pictodb < pictodb.sql
echo Insert data
mysql -u pictodbuser -pp1KT015 pictodb < pictodb-data.sql
mysql -u pictodbuser -pp1KT015 pictodb < pictodb-test-caja.sql
echo Create constraints
# Triggers for enrolments (office licenses)
mysql -u pictodbuser -pp1KT015 pictodb < pictodb_enrolments_integrity_constraints.sql
# Triggers and procedures for sessions
mysql -u pictodbuser -pp1KT015 pictodb < pictodb_sessions_integrity_constraints.sql
echo End
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Datos de prueba `pictodb`
--
SET foreign_key_checks=0;
--
-- Volcado de datos para la tabla `office`
--
INSERT INTO `office` (`name`, `address`, `country`, `contact_person`, `email`, `phone1`, `lang`) VALUES
('Deletrea, Centro de Psicología y Lenguaje',
'Calle Doctor Esquerdo, 82, 28007 Madrid',
'ES',
'Sandra Freire Prudencio',
'sandrafreire72@hotmail.com',
'+34 91 573 33 26',
'es-es'),
('Autismo Córdoba',
'Avenida Vía Augusta, Nú 3, 14011, Córdoba',
'ES',
'Miguel Ángel López Raso',
'administracion@autismocordoba.org',
'+34 957 492 527',
'es-es'),
('Autism Anglia',
'Century House. Riverside Office Centre. North Station Road. Colchester. Essex. CO1 1RE',
'UK',
'Clive Stobbs',
'info@autism-anglia.org.uk',
'+44 01206 577678',
'en-gb')
;
INSERT INTO `supervisor` (`name`, `surname`, `gender`, `address`, `email`, `phone`, `lang`, `password`, `active`, `id_off`)
(SELECT 'Álvaro','García Quesada','M', NULL, 'alvaro.garcia@autismojaen.es', '+34 953 236 158', 'es-es', '$2a$10$q5oA2oUvr5T9so3k.1FqZO5bfJlaGKu6JZ7/HyScsKqbFVhIlfg.O', true, id from office where name='Asociación Provincial de Autismo de Jaén');
-- Deletrea, Centro de Psicología y Lenguaje
INSERT INTO `supervisor` (`name`, `surname`, `gender`, `address`, `email`, `phone`, `lang`, `password`, `active`, `id_off`)
(SELECT 'Sandra','Freire Prudencio', 'F', NULL, 'sandrafreire72@hotmail.com', NULL, 'es-es', '$2a$10$ag8cJBLXKninY2tD1SOIj.narRJlRYSbOuM.be8xl/zcHiYR777LC', true, id from office where name='Deletrea, Centro de Psicología y Lenguaje');
INSERT INTO `supervisor` (`name`, `surname`, `gender`, `address`, `email`, `phone`, `lang`, `password`, `active`, `id_off`)
(SELECT 'Raquel','Ayuda Pascual', 'F', NULL, 'raquel.ayuda@autismojaen.es', NULL, 'es-es', '$2a$10$vBIXKS2gxlLvkykG3IMq8OXjMkE9zdZCk2MG3vQcxj6H/XnCYUA2K', true, id from office where name='Deletrea, Centro de Psicología y Lenguaje');
INSERT INTO `supervisor` (`name`, `surname`, `gender`, `address`, `email`, `phone`, `lang`, `password`, `active`, `id_off`)
(SELECT 'Ana','González Navarro', 'F', NULL, 'ana.gonzalez.navarro@gmail.com', NULL, 'es-es', '$2a$10$IC0bldbs5Fii29/vxTNuIO6KE9XvkwIomdImJMGtPLGm0NHOjsmWu', true, id from office where name='Deletrea, Centro de Psicología y Lenguaje');
-- Autismo Córdoba
INSERT INTO `supervisor` (`name`, `surname`, `gender`, `address`, `email`, `phone`, `lang`, `password`, `active`, `id_off`)
(SELECT 'María','Muñoz Reyes', 'F' , NULL, 'maria.psicologa@autismocordoba.org', '+34 957 492 527', 'es-es', '$2a$10$0ZXHK5j2TTpUS8BZdsAKluXRnqULL2/lW62k8EP9Y04V24R72enH2', true, id from office where name='Autismo Córdoba');
INSERT INTO `supervisor` (`name`, `surname`, `gender`, `address`, `email`, `phone`, `lang`, `password`, `active`, `id_off`)
(SELECT 'Lola','Ruíz García', 'F', NULL, 'administracion@autismocordoba.org', '+34 957 492 527', 'es-es', '$2a$10$xfYc.4Yh5n20/RfbJ0001.GMt4r6SD7Sitqi.9ePSiBA9816DP1lu', true, id from office where name='Autismo Córdoba');
-- Autism Anglia
INSERT INTO `supervisor` (`name`, `surname`, `gender`, `address`, `email`, `phone`, `lang`, `password`, `active`, `id_off`)
(SELECT 'Caroline','Wells', 'F', NULL, 'caroline@autism-anglia.org.uk', NULL, 'en-gb', '$2a$10$z1u15yNDhdtCxrMEQELFEev4cj8PHqdZ9oajgdSf40iTQEEiafJLy', true, id from office where name='Autism Anglia');
--
-- Tutores
--
INSERT INTO `supervisor` (`name`, `surname`, `gender`, `address`, `country`, `email`, `phone`, `lang`, `password`, `active`) VALUES
('José', 'García', 'M','C/ Mayor, 13. Jaén', 'es-es', 'jose@gmail.com', '+34 232 232 232', 'es-es', '$2a$10$uTcpix1hvVyyn.DJp0azkejVu2DCfWHkLza7rB7M/AagdraZ0Vhv.', true),
('Antonio', 'López', 'M','Avda. Andalucía 1. Jaén','es-es', 'antonio@gmail.com', NULL, 'es-es', '$2a$04$lHYt/FNZ/o05z0E8QOAu4ObcdxIIUfcroQ67Kz6uLxFEb2SxgNgFu', true),
('Luisa', 'Sánchez', 'F', 'C/ Calatrava, 13. Córdoba', 'es-es', 'luisa@hotmail.com', NULL, 'es-es', '$2a$10$uIQ9uIGaG1D2qMJzjF27iu9KsC7AcN3u7AbLhwxh4dqVlEjGLy/cq', true),
('Carlos', 'Díez', 'M','Avda. Barcelona 24. Córdoba', 'es-es', 'cdiez@mixmail.com', '+34 953 70 22 14', 'es-es', '$2a$10$h0eRuAksPrI2nRiUaqM8PO33Dv71k7gWl6Vg3/5kV83z2eZ3Dtgsa', true),
('Rocio', 'Martínez', 'F', 'C/ Ancha, 13. Jaén', 'es-es', 'romar@gmail.com', NULL, 'es-es', '$2a$10$mYV/M3NVbCgn6pmUcnqEGe3yQYEgOWTRwZueWffuDWx/3T9XtqKLW', true),
('Teresa', 'Ruano Torres', 'F', 'Avda. Arjona 1. Jaén','es-es', 'teresa.ruano.torres@hotmail.com', '+34 953 70 22 14', 'es-es', '$2a$10$GM4JJtO98QslPp0uezG5KOEq.bE29e6Ks4rz88yLhYDDu5H5iMJ0e', true),
('Sonia', 'García Quesada', 'F', 'C/ Pintor Torres, 13. Madrid', 'es-es', 'sonia70@facebook.mail.com', NULL, 'es-es', '$2a$10$Oy4q7dxNDxci0uS26QmP1uDzjE7pA33KHQnMEJIivF0.hLnqEdWdu', true),
('Roberto', 'Anguita', 'M', 'Avda. Andalucía 78. Madrid', 'es-es', 'robertoanguita67@gmail.com', '+34 953 70 22 14', 'es-es', '$2a$10$VBJQvmVnxtLXRj7VyYEzIu3YyqO1l8QR5snGc6ukBCZJl6XKToILO', true),
('Remedios', 'Romero', 'F', 'C/ Mayor, 113. Madrid', 'es-es', 'rromero@gmail.com', '+34 232 232 232', 'es-es', '$2a$10$hCnLEz5nQ3DW/NU38Wa.QuAapsyGU8mNH3k2fxo6lZKdg4HCJTcPe', true),
('Kim', 'Parsons', 'F', 'Doucecroft School. Abbotts Lane. Eight Ash Green. Colchester. Essex. CO6 3QL', 'UK', 'kinpar@gmail.com', '+44 01206 771234', 'en-gb', '$2a$10$tdJgHIyRXHzl/jtoLWms9upWKdUQUtJna7CQvEV6wvFVbPeNpqU8G', true),
('Tracey', 'Bayley', 'F', 'Old Pharmacy Yard. Church Street. Dereham. Norfolk. NR19 1DJ', 'UK', 'tracey@gmail.com', '+44 01362 853753', 'en-gb', '$2a$10$TzMqiH6bWaBXE.Y0Ss6AreIkOdlM4NFRJocb5YZkexGyqphEbX5BG', true),
('Marcos', 'Ledesma', 'M','C/ Tenorio 9. Córdoba', 'es-es', 'aledesma@ujaen.es', NULL, 'es-es', '$2a$10$Bj2NhxRM.EtlNLa.F/2CXuMPQs2t3G8D8dLRa/owNGmW8VobdalRq', true);
--
-- Actualización de `office` con el id del supervisor admin
--
UPDATE office SET admin=(SELECT id FROM supervisor where name='Sandra' and surname='Freire Prudencio') where name='Deletrea, Centro de Psicología y Lenguaje';
UPDATE office SET admin=(SELECT id FROM supervisor where name='María' and surname='Muñoz Reyes') where name='Autismo Córdoba';
UPDATE office SET admin=(SELECT id FROM supervisor where name='Caroline' and surname='Wells') where name='Autism Anglia';
UPDATE office SET admin=(SELECT id FROM supervisor where name='Fernando' and surname='Martínez Santiago') WHERE name='Comunicación Aumentativa JAén (CAJA)';
--
-- Fotos de algunos supervisores
--
UPDATE supervisor SET pic='/upload/supervisors/sandra_de.jpg' WHERE name='Sandra' and surname='Freire Prudencio';
UPDATE supervisor SET pic='/upload/supervisors/maria.jpg' WHERE name='María' and surname='Muñoz Reyes';
UPDATE supervisor SET pic='/upload/supervisors/caroline.jpg' WHERE name='Caroline' and surname='Wells';
UPDATE supervisor SET pic='/upload/supervisors/lola.jpg' WHERE name='Lola' AND surname='Ruíz García';
UPDATE supervisor SET pic='/upload/supervisors/marcos.jpg' WHERE name='Marcos' and surname='Ledesma';
UPDATE supervisor SET pic='/upload/supervisors/antonio.jpg' WHERE name='Roberto' and surname='Anguita';
UPDATE supervisor SET pic='/upload/supervisors/teresa.jpg' WHERE name='Teresa' and surname='Ruano Torres';
UPDATE supervisor SET pic='/upload/supervisors/kim.jpg' WHERE name='Kim' AND surname='Parsons';
UPDATE supervisor SET pic='/upload/supervisors/rocio.jpg' WHERE name='Rocio' and surname='Martínez';
--
-- Algunos usuarios especifican un TTS
--
UPDATE supervisor SET tts_engine='IVONA Text-to-Speech HQ' WHERE name='Belén' AND surname='Pérez Vílchez';
UPDATE supervisor SET tts_engine='IVONA Text-to-Speech HQ' WHERE name='Sandra' and surname='Freire Prudencio';
UPDATE supervisor SET tts_engine='SVOX Classic TTS' WHERE name='Roberto' and surname='Anguita';
--
-- Students
--
INSERT INTO `student` (`name`, `surname`, `birthdate`, `gender`, `country`, `pic`, `notes`, `lang`, `attributes`) VALUES
('Rosa', 'López Caro','2009-12-10','F','ES','/upload/students/rosa.jpg',NULL,'es-es', '{"stu-att" : [{ "categories" : "on", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "pictogram size" : "medium", "tts engine" : "IVONA Text-to-Speech HQ", "tts voice": "es" }]}'),
('Maria', 'Exposito Beltrán','2011-07-13','F','ES','/upload/students/maria.jpg',NULL,'es-es', '{"stu-att" : [{ "categories" : "on", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "pictogram size" : "medium", "tts engine" : "IVONA Text-to-Speech HQ", "tts voice": "es" }]}'),
('Juan', 'López Martínez','2005-06-20','M','ES','/upload/students/juan.jpg',NULL,'es-es', '{"stu-att" : [{ "categories" : "on", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "pictogram size" : "medium", "tts engine" : "IVONA Text-to-Speech HQ", "tts voice": "es" }]}'),
('Carlos', 'Torres Almagro','2009-12-21','M','ES','/upload/students/carlos.jpg',NULL,'es-es', NULL),
('Adela', 'Sevilla Caro','2003-05-19','F','ES','/upload/students/adela.jpg',NULL,'es-es', '{"stu-att" : [{ "input selection" : "press" }]}'),
('Francisco', 'Martos Domínguez','2010-07-30','M','ES','/upload/students/francisco.jpg',NULL,'es-es', '{"stu-att" : [{ "categories" : "on", "input feedback" : "light_up" , "input selection" : "drag", "pictogram size" : "large" }]}'),
('Rocio', 'Lallena Salido','2009-11-11','F','ES','/upload/students/rocio.jpg',NULL,'es-es', '{"stu-att" : [{ "categories" : "off", "tts engine" : "Acapela TTS" }]}'),
('Carlos', 'López Caro','2009-06-10','M','ES','/upload/students/carlos2.jpg',NULL,'es-es', '{"stu-att" : [{"input selection" : "press" }]}'),
('Nora', 'García Sanjuan','2008-07-21','F','ES','/upload/students/nora.jpg',NULL,'es-es', '{"stu-att" : [{ "categories" : "off", "pictogram size" : "large"}]}'),
('Maria del Carmen', 'Romero Alcalá','2009-08-28','F','es-es','/upload/students/mcarmen.jpg',NULL,'es-es', '{"stu-att" : [{ "categories" : "on", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "pictogram size" : "medium", "tts engine" : "SVOX Classic TTS" }]}'),
('Samuel', 'Jiménez Sahagún','2011-12-23','M','ES','/upload/students/samuel.jpg',NULL,'es-es', '{"stu-att" : [{ "categories" : "on", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "pictogram size" : "medium", "tts engine" : "IVONA Text-to-Speech HQ"}]}'),
('Marta', 'Zapatero Rayo','2012-06-15','F','ES',NULL,NULL,'es-es', '{"stu-att" : [{ "categories" : "on", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "tts engine" : "IVONA Text-to-Speech HQ", "tts voice": "es" }]}'),
('Luis', 'Rato Largo','2007-10-20','M','ES','/upload/students/luis.jpg',NULL,'es-es', '{"stu-att" : [{ "categories" : "on", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "pictogram size" : "medium", "tts engine" : "IVONA Text-to-Speech HQ", "tts voice": "es" }]}'),
('Pedro', 'Martínez García','2010-12-11','M','ES','/upload/students/pedro.jpg',NULL,'es-es', NULL),
('Marcos', 'Cortázar Delgado','2009-02-10','M','ES','/upload/students/marcos.jpg','Retraso mental severo','es-es', '{"stu-att" : [{ "categories" : "off", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "pictogram size" : "enormous"}]}'),
('Kate', 'Smith','2007-10-20','F','UK','/upload/students/kate.jpg',NULL,'en-gb', '{"stu-att" : [{ "categories" : "on", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "pictogram size" : "medium", "tts engine" : "IVONA Text-to-Speech HQ", "tts voice": "en" }]}'),
('Peter', 'White','2010-12-11','M','UK','/upload/students/peter.jpg',NULL,'en-gb', '{"stu-att" : [{ "categories" : "on", "input feedback" : [ "vibration", "tts" ], "input selection" : "click", "pictogram size" : "medium", "tts engine" : "IVONA Text-to-Speech HQ", "tts voice": "en" }]}')
;
--
-- Devices
--
INSERT INTO device (`id_firmware`, `desc`) VALUES
('ANDROID_01','Samsung Tab Pro 10.1'),
('ANDROID_02','BQ Curie 2'),
('ANDROID_03','Yottablet 7'),
('ANDROID_04','Samsung Tab Pro 10.1'),
('ANDROID_05','Yottablet 7'),
('ANDROID_06','Yottablet 10.1'),
('ANDROID_07','BQ Curie 2'),
('ANDROID_08','Yottablet 7'),
('ANDROID_09','Yottablet 7'),
('ANDROID_10','Yottablet 10'),
('ANDROID_11','Yottablet 7'),
('ANDROID_12','Samsung Tab Pro 10.1'),
('ANDROID_13','Yottablet 10'),
('ANDROID_14','Yottablet 10'),
('ANDROID_15','Yottablet 10'),
('ANDROID_16','Yottablet 7'),
('ANDROID_17','Google Nexus 5'),
('ANDROID_18','Google Nexus 7'),
('ANDROID_19','Yottablet 10'),
('ANDROID_20','Yottablet 10'),
('ANDROID_21','Yottablet 10'),
('ANDROID_22','Yottablet 7'),
('ANDROID_23','Yottablet 7'),
('ANDROID_24','Yottablet 10'),
('ANDROID_25','Yottablet 10'),
('ANDROID_26','Yottablet 10')
;
--
-- Official devices
--
INSERT INTO official_dev (`id_dev`, `serial`) SELECT `id`, REPLACE(`id_firmware`,'ANDROID','yttsrl') FROM device WHERE `desc` LIKE 'Yottablet%';
INSERT INTO `official_dev` (`id_dev`, `serial`) VALUES (NULL, 'test_serial_number');
--
-- Student-supervisor
--
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='francisco' and B.name='lola';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Juan' and B.name='lola';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Kate' and B.name='caroline';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Luis' and B.name='marcos';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Marcos' and B.name='María';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Maria' and B.name='María';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Maria del Carmen' and B.name='teresa';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Marta' and B.name='teresa';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Nora' and B.name='antonio';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Pedro' and B.name='antonio';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Peter' and B.name='tracey';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Rocio' and B.name='sandra';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Rosa' and B.name='sandra';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Samuel' and B.name='sandra';
--
-- Student's tutors
--
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Rosa' and B.name='José';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Samuel' and B.name='Antonio';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Pedro' and B.name='Luisa';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Marta' and B.name='Carlos';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Marcos' and B.name='Rocio';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Luis' and B.name='Teresa';
INSERT INTO `stu_sup`(id_stu,id_sup) SELECT DISTINCT A.id, B.id FROM student A, supervisor B WHERE A.name='Luis' and B.name='Remedios';
--
-- Student's offices
--
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='lola') WHERE student.name='francisco';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='lola') WHERE student.name='Juan';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='caroline') WHERE student.name='Kate';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='marcos') WHERE student.name='Luis';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='María') WHERE student.name='Marcos';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='María') WHERE student.name='Maria';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='teresa') WHERE student.name='Maria del Carmen';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='teresa') WHERE student.name='Marta';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='antonio') WHERE student.name='Nora';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='antonio') WHERE student.name='Pedro';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='tracey') WHERE student.name='Peter';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='sandra') WHERE student.name='Rocio';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='sandra') WHERE student.name='Rosa';
UPDATE student SET id_off=(SELECT id_off FROM supervisor WHERE supervisor.name='sandra') WHERE student.name='Samuel';
--
-- Student's official devices
--
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Adela' and B.serial='yttsrl_03';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Carlos' and B.serial='yttsrl_05';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='francisco' and B.serial='yttsrl_06';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Juan' and B.serial='yttsrl_08';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Kate' and B.serial='yttsrl_09';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Luis' and B.serial='yttsrl_10';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Marcos' and B.serial='yttsrl_11';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Maria' and B.serial='yttsrl_13';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Maria del Carmen' and B.serial='yttsrl_14';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Marta' and B.serial='yttsrl_15';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Nora' and B.serial='yttsrl_16';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Pedro' and B.serial='yttsrl_19';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Peter' and B.serial='yttsrl_20';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Rocio' and B.serial='yttsrl_21';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Rosa' and B.serial='yttsrl_22';
INSERT INTO `stu_dev`(id_stu,id_dev) SELECT DISTINCT A.id, B.id FROM student A, official_dev B WHERE A.name='Samuel' and B.serial='yttsrl_23';
--
-- sessions
--
insert into method (name,id_stu) values ('method1_stud19',19);
insert into method (name,id_stu) values ('method1_stud20',20);
insert into instruction (name,id_met) values ('instructon1_method1_stud19',1);
insert into instruction (name,id_met) values ('instructon2_method1_stud19',1);
insert into instruction (name,id_met) values ('instructon3_method1_stud19',1);
insert into instruction (name,id_met) values ('instructon1_method1_stud20',2);
insert into instruction (name,id_met) values ('instructon2_method1_stud20',2);
insert into instruction (name,id_met) values ('instructon3_method1_stud20',2);
--
-- Some queries
--
-- select E.id, B.name Student,C.name Supervisor
-- from student B,supervisor C, stu_sup E
-- where E.id_stu=B.id and E.id_sup=C.id
-- order by id;
-- select B.name Student,C.name Supervisor, D.*
-- from stu_dev A,student B,supervisor C,device D, stu_sup E
-- where A.id_stu=E.id and E.id_stu=B.id and E.id_sup=C.id and A.id_dev=D.id;
SET foreign_key_checks=1;
DROP TABLE stu_opentry;
DROP PROCEDURE newTry;
DROP TRIGGER TRG_TRY_EVALUATED;
DROP TRIGGER TRG_NEW_EVENT;
DROP TRIGGER TRG_SESSION_NEW;
DELIMITER ;;
CREATE TABLE stu_opentry (
id int NOT NULL AUTO_INCREMENT,
id_stu int NOT NULL,
id_sup int NOT NULL,
id_ws int NOT NULL,
id_opentry int ,
total_tries int DEFAULT 0,
begin timestamp NULL,
end timestamp NULL,
PRIMARY KEY(id),
UNIQUE(id_stu),
UNIQUE(id_sup),
UNIQUE(id_ws),
FOREIGN KEY (id_stu) REFERENCES student,
FOREIGN KEY (id_opentry) REFERENCES try,
INDEX USING HASH (id_stu),
INDEX USING HASH (id_ws)
) ENGINE=MEMORY;;
CREATE PROCEDURE newTry(idstu INT, idsup INT, idws INT)
MODIFIES SQL DATA
BEGIN
DECLARE idopentry int;
INSERT INTO try(`id_ws`)
VALUES (idws);
SET idopentry=LAST_INSERT_ID();
INSERT INTO stu_opentry(id_stu,id_sup,id_ws,id_opentry, total_tries,begin)
VALUES (
idstu,
idsup,
idws,
idopentry,
0,
NOW()
)
ON DUPLICATE KEY UPDATE id_stu=idstu, id_sup=idsup, id_ws=idws, id_opentry=idopentry;
END;;
CREATE TRIGGER TRG_TRY_EVALUATED
AFTER UPDATE ON try
FOR EACH ROW
BEGIN
DECLARE idopentry INT;
DECLARE idws INT;
DECLARE ws_end DATE;
IF ( (old.result IS NULL) and (new.result IS NOT NULL) and (new.end>ws_end)) THEN
SELECT id_ws, id_opentry,end INTO idws, idopentry, ws_end
FROM
stu_opentry
WHERE
id_ws = NEW.id_ws;
UPDATE stu_opentry
SET end=new.end, total_tries=total_tries+1
WHERE id_ws=idws;
END IF;
END;;
CREATE TRIGGER TRG_NEW_EVENT
AFTER INSERT ON action
FOR EACH ROW
BEGIN
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
FROM
stu_opentry
WHERE
id_stu = NEW.id_stu;
IF (idopentry IS NOT NULL and NEW.id_sup IS NULL) THEN
UPDATE `try`
SET end=NOW()
WHERE id=idopentry;
call newTry(new.id_stu, idsup_ws, idws);
END IF;
WHEN 'Pause' THEN
SELECT id_ws, id_opentry INTO idws, idopentry
FROM
stu_opentry
WHERE
id_stu = NEW.id_stu;
IF (idopentry IS NULL) THEN
call newTry(new.id_stu, new.id_sup,idws);
ELSE
call deleteOpenTry(idws);
END IF;
ELSE BEGIN END;
END CASE;
END;;
CREATE TRIGGER TRG_SESSION_NEW
AFTER INSERT ON working_session
FOR EACH ROW
BEGIN
DECLARE idstu INT;
SELECT DISTINCT M.id_stu INTO idstu
FROM
instruction I,
method M
WHERE
I.id=new.id_ins AND
I.id_met=M.id;
UPDATE instruction
SET status='started'
WHERE id=new.id_ins;
CALL newTry(idstu, new.id_sup, new.id);
END;;
DELIMITER ;

87.8 KB | W: | H:

87.8 KB | W: | H:

sails/conf/EC.png
sails/doc/EC.png
sails/conf/EC.png
sails/doc/EC.png
  • 2-up
  • Swipe
  • Onion skin
# Nodejs install
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install -y nodejs
sudo npm install -g npm
# Sails install
sudo npm install -g sails
# Sails log file
mkdir -p ./src/logs
touch ./src/logs/my_log_file.log
# Server dependencies installation
cd ./src && npm install
# Copy sails.io.js
cd /tmp && \
rm -rf sailstempapp && \
sails new sailstempapp &&
cp /tmp/sailstempapp/assets/js/dependecies/sails.io.js ./src/assets/app/js/lib/sails.io.js
rm -rf /tmp/sailstempapp
# Link configuration file
ln ./conf/js/config.js ./src/assets/app/js/config.js
ln ./conf/js/local.js ./src/assets/app/js/local.js
# Client dependencies installation
sudo npm install -g bower
cd ./src/assets/app && bower install
/**
* Gruntfile
*
* This Node script is executed when you run `grunt` or `sails lift`.
* It's purpose is to load the Grunt tasks in your project's `tasks`
* folder, and allow you to add and remove tasks as you see fit.
* For more information on how this works, check out the `README.md`
* file that was generated in your `tasks` folder.
*
* WARNING:
* Unless you know what you're doing, you shouldn't change this file.
* Check out the `tasks` directory instead.
*/
module.exports = function(grunt) {
// Load the include-all library in order to require all of our grunt
// configurations and task registrations dynamically.
var includeAll;
try {
includeAll = require('include-all');
} catch (e0) {
try {
includeAll = require('sails/node_modules/include-all');
}
catch(e1) {
console.error('Could not find `include-all` module.');
console.error('Skipping grunt tasks...');
console.error('To fix this, please run:');
console.error('npm install include-all --save`');
console.error();
grunt.registerTask('default', []);
return;
}
}
/**
* Loads Grunt configuration modules from the specified
* relative path. These modules should export a function
* that, when run, should either load/configure or register
* a Grunt task.
*/
function loadTasks(relPath) {
return includeAll({
dirname: require('path').resolve(__dirname, relPath),
filter: /(.+)\.js$/
}) || {};
}
/**
* Invokes the function from a Grunt configuration module with
* a single argument - the `grunt` object.
*/
function invokeConfigFn(tasks) {
for (var taskName in tasks) {
if (tasks.hasOwnProperty(taskName)) {
tasks[taskName](grunt);
}
}
}
// Load task functions
var taskConfigurations = loadTasks('./tasks/config'),
registerDefinitions = loadTasks('./tasks/register');
// (ensure that a default task exists)
if (!registerDefinitions.default) {
registerDefinitions.default = function (grunt) { grunt.registerTask('default', []); };
}
// Run task functions to configure Grunt.
invokeConfigFn(taskConfigurations);
invokeConfigFn(registerDefinitions);
};
:/**
* student.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 : 'student',
migrate : 'safe',
schema : true,
autoPK : false,
autoCreatedAt : false,
autoUpdatedAt : false,
attributes: {
id: {
type: "integer",
autoIncrement: true,
primaryKey: true,
unique: true
},
username: {
required: true,
type: "string",
size: 40
},
password: {
required: true,
type: "string",
size: 40
},
name: {
required: true,
type: "string",
size: 40
},
surname: {
required: true,
type: "string",
size: 60
},
birthdate: {
required: true,
type: "date"
},
gender:{
required: true,
type: "string",
size: 1
},
country:{
type: "string",
size: 2
},
pic:{
type: "string",
size: 255
},
notes: {
type: "string",
size: 1024
},
lang: {
columnName: "lang",
required: true,
type: "string",
size: 2
},
attributes: {
columnName: 'attributes',
type: 'json',
size: 1024
},
office: {
columnName: 'id_off',
type: 'integer',
required: false,
model: 'Office'
},
// Relación con StuSup
stuSup: {
collection: "StuSup",
via: "student"
},
// Relación con StuDev
stuDevs: {
collection: 'StuDev',
via: 'student'
},
// Relación con Method. [1 Student to N Method]
methods: {
collection: "Method",
via: "student"
},
// Relación con StuPicto. [1 Student to N StuPicto]
stuPicto: {
collection: "StuPicto",
via: "student"
},
//
// JSON limitations
//
toJSON: function() {
var obj = this.toObject();
// avoid sending this fields
delete obj.password;
return obj;
},
},
//
// Model hook for storing default device configuration adding a new account
//
beforeCreate: function(attrs, next) {
MetaStu.find().exec(function(err, metaStu) {
if (err || !metaStu || metaStu.length == 0)
return next(err);
/* Default Configuration:
var configuration = {
"categories":"on",
"input_feedback":{"vibration":true,"click":false,"read":false,"highlight":false},
"input_selection":"drag",
"pictogram_size":"normal",
"tts_engine":"IVONA Text-to-Speech HQ",
"tts_voice":"child", -- NO USADO
"picto_select":"enlarge", -- NO USADO
"legend":"yes",
"legendsize":"50",
"animation":"yes", -- NO USADO
"tts_options":{phrase":true},
"picto_background":"#000000",
"phrase_background":"#ff0000"};
*/
var configuration = [];
// The default configuration is built by meta_stu fields and its default values
for (var i = 0; i < metaStu.length; i++) {
configuration.push('"' + metaStu[i].name + '":' + metaStu[i].default_val);
}
attrs.attributes = JSON.parse("{" + configuration.toString() + "}");
//attrs.attributes = "{" + configuration.toString() + "}";
//console.log(attrs.attributes);
//
// Encrypt password before insertion
//
var bcrypt = require('bcrypt-nodejs');
bcrypt.genSalt(10, function(err, salt) {
if (err)
return next(err);
bcrypt.hash(attrs.password, salt, function(err, hash) {
if (err)
return next(err);
attrs.password = hash;
next();
});
});
});
},
//
// Class method for getting the list of supervisors (therapist + tutors) associated to a given
// student
supervisors: function(id_stu, callback) {
StuSup.find({id_stu: id_stu}).populate('supervisor').exec(function(err, stuSups) {
var l = [];
if (err || !stuSups || stuSups.length == 0)
return callback(err, l);
async.eachSeries(stuSups,
function(stuSup, next) {
delete stuSup.supervisor.password;
l.push(stuSup.supervisor);
next();
},
function (err) {
return callback(err, l);
}
);
});
},
//
// Class method for getting the list of therapists associated to a given
// student
therapists: function(id_stu, callback) {
StuSup.find({id_stu: id_stu}).populate('supervisor').exec(function(err, stuSups) {
var l = [];
if (err || !stuSups || stuSups.length == 0)
return callback(err, l);
async.eachSeries(stuSups,
function(stuSup, next) {
// stuSup.supervisor.id > 0 for not retrieving the -1 default supervisor
if (stuSup.supervisor && stuSup.supervisor.office && stuSup.supervisor.id > 0) {
delete stuSup.supervisor.password;
l.push(stuSup.supervisor);
}
next();
},
function (err) {
return callback(err, l);
}
);
});
},
//
// Class method for getting the list of tutors associated to a given
// student
tutors: function(id_stu, callback) {
StuSup.find({id_stu: id_stu}).populate('supervisor').exec(function(err, stuSups) {
var l = [];
if (err || !stuSups || stuSups.length == 0)
return callback(err, l);
async.eachSeries(stuSups,
function(stuSup, next) {
// stuSup.supervisor.id > 0 for not retrieving the -1 default supervisor
if (stuSup.supervisor && !stuSup.supervisor.office && stuSup.supervisor.id > 0) {
delete stuSup.supervisor.password;
l.push(stuSup.supervisor);
}
next();
},
function (err) {
return callback(err, l);
}
);
});
},
//
// Class method for getting the list of pictos associated to a given
// student
pictos: function(id_stu, callback) {
Student.findOne(id_stu).exec(function(err, student) {
if (student){
StuPicto.find({student: id_stu}).populate('picto').exec(function(err, stuPictos) {
var l = [];
if (err || !stuPictos || stuPictos.length == 0)
return callback(err, l);
async.eachSeries(stuPictos, function(stuPicto, cb) {
// Populate expressions to get it with the picto
Picto.findOne(stuPicto.picto.id)
.populate('expressions', {lang: student.lang})
.exec(function(err, picto) {
if (err) throw err;
var stuPictoToAdd = {
"id": stuPicto.id,
"picto": stuPicto.picto,
"expression": picto.expressions[0],
"attributes": stuPicto.attributes
};
l.push(stuPictoToAdd);
cb(); // next in the series
});
},
function(err) {
callback(err, l); // out loop finished, return result
});
});
}
});
},
//
// Class method for getting devices associated to student
//
devices: function(id_stu, callback) {
var list = [];
// Get devices for that student id
StuDev.find({student: id_stu})
.exec(function(err, stuDevs) {
if (err) return callback(err, []);
async.eachSeries(stuDevs, function(stuDev, cb) {
Device.findOne(stuDev.device)
.exec(function(err, dev) {
if (err) throw err;
list.push(dev);
cb(); // next in the series
});
},
function(err) {
if (err) throw err;
return callback(err, list); // loop finished, next in the outer loop
});
});
},
//
// Class method for link a device to a student (stu_dev)
//
link_device: function(id_stu, id_dev_firm, callback) {
// Find the student by student id
Student.findOne({id: id_stu}).exec(function(err, student) {
if (err || !student){
console.log("student not found");
return callback(err, null);
}
// Find the device id by device id firmware
Device.findOne({idFirmware: id_dev_firm}).exec(function(err, device){
if (err || !device){
console.log("Device not found");
return callback(err, null);
}
// Create a new entry in stuDev by id_stu and id_dev
StuDev.create({student: student.id, device: device.id}).exec(function(err, stuDev){
if (err || !stuDev){
console.log("StuDev not created");
return callback(err, null);
}
// Concat the description of device to stuDev and get it back
console.log(JSON.stringify(stuDev));
// It is is created
return callback(err, device);
});
});
});
},
//
// Returns all the tries of the student
//
tries: function(id_stu, callback) {
var l_met = [];
Method.find({ id_stu: id_stu }).exec(function(err, methods) {
if (err || !methods || methods.length == 0)
return callback(err, []);
// eachSeries
async.eachSeries(
// 1st array of items
methods,
// 2nd function to operate over one item
function(method, next) {
// Original: Devolver el objeto con el método completo / instructions / workinSessions / Tries
// y controlar en Angular
//Instruction.find({ id_met: method.id }).populate('tries').exec(function(err, instructions) {
Instruction.find({ id_met: method.id }).populate('workingSessions').exec(function(err, instructions) {
if (err || !instructions || instructions.length == 0)
console.log("error finding instructions");
// Push method
l_met.push({
"id": method.id,
"name": method.name,
"description": method.description,
"student": method.student,
"registration": method.registration,
"notes": method.notes,
"instructions": instructions,
});
next();
});
},
// 3rd final function when all is ready
function (err){
console.log("Final function");
console.log(JSON.stringify(l_met));
return callback(err, l_met);
// If one iteration give an error it is sent to the controller
// with the list
}
);
});
},
// Removes logically a student
logical_delete: function(id_stu, cb) {
Student.findOne(id_stu).exec(function(err, student) {
if (err || !student)
throw err;
// set office to NULL to unlink it
student.office = null;
student.save(function(err, saved) {});
// Remove associations to supervisors
// (Commented out as this is performed by the TRG_UPDATE_STUDENT_ENROLMENTS TRIGGER
//StuSup.destroy({id_stu: id_stu}).exec(function(err, deleted) {
// return cb(err, student);
//});
});
},
sqlquery: function(query, callback) {
//code
Student.query(query, function (err,result) {
// Error handling
if (err) {
sails.log.debug(err);
return callback(err, {});
} else {
console.log("Data from raw sql query:", result);
return callback(err, result);
}
});
},
//
// Model hook for storing encrypted password when updating an account
// and to check that the user new username is not already registered
//
beforeUpdate: function(attrs, next) {
// remove username as it shouldn't be changed
delete attrs.username;
//
// Encrypt password before insertion
//
var bcrypt = require('bcrypt');
bcrypt.genSalt(10, function(err, salt) {
if (err || !attrs.password)
return next(err);
bcrypt.hash(attrs.password, salt, function(err, hash) {
if (err)
return next(err);
attrs.password = hash;
next();
});
});
},
};
...@@ -33,5 +33,8 @@ ...@@ -33,5 +33,8 @@
"url": "http://scm.ujaen.es/softuno/pictogram.git" "url": "http://scm.ujaen.es/softuno/pictogram.git"
}, },
"author": "emblanco, amontejo", "author": "emblanco, amontejo",
"license": "" "license": "",
"devDependencies": {
"node-inspector": "^0.12.8"
}
} }
{
"name": "sails_demo",
"private": true,
"version": "0.0.0",
"description": "a Sails application",
"keywords": [],
"dependencies": {
"sails": "~0.10.5",
"sails-disk": "~0.10.0",
"rc": "~0.5.0",
"include-all": "~0.1.3",
"ejs": "~0.8.4",
"grunt": "0.4.2",
"grunt-sync": "~0.0.4",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-sails-linker": "~0.9.5",
"grunt-contrib-jst": "~0.6.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-cssmin": "~0.9.0",
"grunt-contrib-less": "0.11.1",
"grunt-contrib-coffee": "~0.10.1",
"jsonwebtoken": "~0.4.0",
"bcrypt": "~0.7.8"
},
"scripts": {
"start": "node app.js",
"debug": "node debug app.js"
},
"main": "app.js",
"repository": {
"type": "git",
"url": "git://github.com/emblanco/sails_demo.git"
},
"author": "emblanco",
"license": ""
}
\ No newline at end of file
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