Commit fb7fb727 by Fernando Martínez Santiago

working on PCB bugs: upload imgs from PCB(I)

parents 2b1dfc05 e58cd715
Showing with 898 additions and 1153 deletions
...@@ -16,7 +16,7 @@ Para comprobar que todo funciona correctamente se ha habilitado un servidor con ...@@ -16,7 +16,7 @@ Para comprobar que todo funciona correctamente se ha habilitado un servidor con
comprueba que el código está bien escrito y funciona correctamente (actualmente sólo para el comprueba que el código está bien escrito y funciona correctamente (actualmente sólo para el
código JavaScript). Datos del servidor: código JavaScript). Datos del servidor:
- Dirección: [ararat.ujaen.es:9537][5] - Dirección: [ararat.ujaen.es][5]
- Usuario: `uruk` - Usuario: `uruk`
- Contraseña: `saruman es et` - Contraseña: `saruman es et`
...@@ -27,4 +27,4 @@ código JavaScript). Datos del servidor: ...@@ -27,4 +27,4 @@ código JavaScript). Datos del servidor:
[2]: /softuno/pictogram/tree/develop/sails [2]: /softuno/pictogram/tree/develop/sails
[3]: /softuno/pictogram/tree/develop/sails/src/assets/app [3]: /softuno/pictogram/tree/develop/sails/src/assets/app
[4]: /softuno/pictogram/tree/develop/android/Pictogram [4]: /softuno/pictogram/tree/develop/android/Pictogram
[5]: http://ararat.ujaen.es:9537/job/pictogram-dev/ [5]: https://ararat.ujaen.es/jenkins
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="10daeba4-0692-476d-a3da-642b4123cfdd" name="Default" comment=""> <list default="true" id="10daeba4-0692-476d-a3da-642b4123cfdd" name="Default" comment="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
</list>
<ignored path="android.iws" /> <ignored path="android.iws" />
<ignored path=".idea/workspace.xml" /> <ignored path=".idea/workspace.xml" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
...@@ -38,10 +36,10 @@ ...@@ -38,10 +36,10 @@
</option> </option>
</component> </component>
<component name="ProjectFrameBounds"> <component name="ProjectFrameBounds">
<option name="x" value="44" /> <option name="x" value="65" />
<option name="y" value="23" /> <option name="y" value="24" />
<option name="width" value="1397" /> <option name="width" value="1615" />
<option name="height" value="877" /> <option name="height" value="1026" />
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true"> <component name="ProjectLevelVcsManager" settingsEditedManually="true">
<OptionsSetting value="true" id="Add" /> <OptionsSetting value="true" id="Add" />
...@@ -57,7 +55,7 @@ ...@@ -57,7 +55,7 @@
<option name="STATE" value="0" /> <option name="STATE" value="0" />
</component> </component>
<component name="ProjectView"> <component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1"> <navigator currentView="Scope" currentSubView="Project Files" proportions="" version="1">
<flattenPackages /> <flattenPackages />
<showMembers /> <showMembers />
<showModules /> <showModules />
...@@ -71,9 +69,6 @@ ...@@ -71,9 +69,6 @@
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
</navigator> </navigator>
<panes> <panes>
<pane id="AndroidView">
<subPane />
</pane>
<pane id="ProjectPane"> <pane id="ProjectPane">
<subPane> <subPane>
<PATH> <PATH>
...@@ -84,10 +79,13 @@ ...@@ -84,10 +79,13 @@
</PATH> </PATH>
</subPane> </subPane>
</pane> </pane>
<pane id="PackagesPane">
<subPane />
</pane>
<pane id="Scope"> <pane id="Scope">
<subPane subId="Project Files" /> <subPane subId="Project Files" />
</pane> </pane>
<pane id="PackagesPane"> <pane id="AndroidView">
<subPane /> <subPane />
</pane> </pane>
<pane id="Scratches" /> <pane id="Scratches" />
...@@ -295,7 +293,7 @@ ...@@ -295,7 +293,7 @@
<servers /> <servers />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="44" y="23" width="1397" height="877" extended-state="0" /> <frame x="65" y="24" width="1615" height="1026" extended-state="6" />
<editor active="false" /> <editor active="false" />
<layout> <layout>
<window_info id="Palette&#9;" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Palette&#9;" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
...@@ -303,8 +301,8 @@ ...@@ -303,8 +301,8 @@
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" /> <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" /> <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" /> <window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.2494465" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24905898" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.1744186" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" /> <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.17440401" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" /> <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
...@@ -314,19 +312,19 @@ ...@@ -314,19 +312,19 @@
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" /> <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Android Monitor" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" /> <window_info id="Android Monitor" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Build Variants" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="true" content_ui="tabs" />
<window_info id="Gradle Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" /> <window_info id="Gradle Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Build Variants" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="true" content_ui="tabs" />
<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" /> <window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" /> <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Memory Monitor" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" /> <window_info id="Memory Monitor" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" /> <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Android Model" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="true" content_ui="tabs" />
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> <window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Android Model" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="true" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" /> <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Captures" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> <window_info id="Captures" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> <window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" /> <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
</layout> </layout>
</component> </component>
......
...@@ -38,37 +38,32 @@ android { ...@@ -38,37 +38,32 @@ android {
resValue "integer", "rows", "5" resValue "integer", "rows", "5"
resValue "integer", "columns", "10" resValue "integer", "columns", "10"
} }
} }
productFlavors { productFlavors {
fernandoFlavor { FernandoFlavor {
resValue "string", "server", "https://pre.yottacode.com" resValue "string", "server", "https://127.0.0.1:9944"
applicationId "com.yottacode.pictogrammar" applicationId "com.yottacode.pictogrammar"
} }
ArturoFlavor { LocalFlavor {
resValue "string", "server", "https://192.168.1.37:1337" resValue "string", "server", "https://192.168.1.37:1337"
} }
DevFlavor {
resValue "string", "server", "https://dev.yottacode.com"
}
DefaultFlavor { DefaultFlavor {
resValue "string", "server", "https://pre.yottacode.com" resValue "string", "server", "https://pre.yottacode.com"
signingConfig signingConfigs.release_config signingConfig signingConfigs.release_config
} }
ArturoFlavorNoSSL {
resValue "string", "server", "http://192.168.1.37:1337"
}
} }
} }
dependencies { dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.5.87' compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.github.nkzawa:socket.io-client:0.5.0' compile 'com.github.nkzawa:socket.io-client:0.5.0'
compile 'com.koushikdutta.async:androidasync:2.+' compile 'com.koushikdutta.async:androidasync:2.+'
compile 'com.android.support:support-v4:21.0.+' compile 'com.android.support:support-v4:21.0.+'
compile 'com.koushikdutta.ion:ion:2.+' compile 'com.koushikdutta.ion:ion:2.+' //required for upload images
//required for upload images
fernandoFlavorCompile files('src/fernandoFlavor/libs/jpgf.jar')
fernandoFlavorCompile fileTree(dir: 'libs')
}
}
#Thu May 26 14:03:38 CEST 2016 #Mon Jun 06 22:38:39 CEST 2016
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
echo "-- Running pictogram server" echo "-- Running pictogram server"
if [ -e "src/app.js" ]; then if [ -e "src/app.js" ]; then
cd src && npm start cd src && forever start app.js --debug
elif [ -e "/vagrant/src/app.js" ]; then elif [ -e "/vagrant/src/app.js" ]; then
cd /vagrant/src && npm start cd /vagrant/src && forever start app.js --debug
elif [ -e "/home/vagrant/sync/src/app.js" ]; then elif [ -e "/home/vagrant/sync/src/app.js" ]; then
cd /home/vagrant/sync/src && npm start cd /home/vagrant/sync/src && forever start app.js --debug
else else
echo "-- app.js not found, cannot run pictogram server" echo "-- app.js not found, cannot run pictogram server"
exit exit
......
...@@ -6,3 +6,4 @@ ...@@ -6,3 +6,4 @@
roles: roles:
- webapp - webapp
- server - server
...@@ -10,9 +10,9 @@ Los ficheros SQL que importará este rol son los siguientes: ...@@ -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 - [init-ignoresymbolstix][2] realiza el mismo proceso que [init][1], pero manteniendo
los datos almacenados por symbolstx. los datos almacenados por symbolstx.
- [pictodb-schema][3] contiene el esquema de la base de datos. - [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. - [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. - [symbolstx-categories][5] añade las categorías de symbolstx en las tablas `pictocat` y `catexp`.
- [symbolstix-metadata][6] añade traducciones para symbolstx. - [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 - [triggers-enrolments-integrity-constraints][7] añade disparadores para el control de
integridad de inscripciones. integridad de inscripciones.
- [triggers-sessions-integrity-constraints][8] añade disparadores para el control de integridad - [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;
SET @TRIGGER_CHECKS=FALSE;
DELETE FROM picto_tag WHERE `id_sup` IS NOT NULL;
DELETE FROM picto WHERE `id_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;
DROP TRIGGER IF EXISTS TRG_NEW_STUDENT_MAXENROLMENTS;
DROP TRIGGER IF EXISTS TRG_NEW_STUDENT_UPDATE_ENROLMENTS;
DROP TRIGGER IF EXISTS TRG_MODIFY_STUDENT_ENROLMENTS;
DROP TRIGGER IF EXISTS TRG_DELETE_STUDENT_ENROLMENTS;
DROP TRIGGER IF EXISTS TRG_SESSION_NEW;
DROP TRIGGER IF EXISTS TRG_SESSION_CLOSED;
DROP TRIGGER IF EXISTS TRG_NEW_EVENT_ONSESSION;
DROP TRIGGER IF EXISTS TRG_NEW_EVENT;
DROP TRIGGER IF EXISTS TRG_SESSION_CLOSING;
DROP TRIGGER IF EXISTS TRG_TRY_EVALUATED;
SET @TRIGGER_CHECKS=TRUE;
SET foreign_key_checks=1;
...@@ -51,10 +51,10 @@ INSERT INTO `source` (`id`, `name`, `description`) VALUES ...@@ -51,10 +51,10 @@ INSERT INTO `source` (`id`, `name`, `description`) VALUES
SET foreign_key_checks=0; 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 (1, 2982, NULL, 0, 0, NULL), -- yes
(2, 4391, NULL, 0, 1, NULL), -- no (2, 4391, NULL, 0, 1, NULL), -- no
(3, 2284, NULL, 0, 2, NULL), -- please (3, 2284, NULL, 0, 2, NULL), -- please
......
...@@ -41,7 +41,8 @@ CREATE TABLE IF NOT EXISTS `action` ( ...@@ -41,7 +41,8 @@ CREATE TABLE IF NOT EXISTS `action` (
KEY `fk_sup_act` (`id_sup`), KEY `fk_sup_act` (`id_sup`),
KEY `fk_stu_act` (`id_stu`), KEY `fk_stu_act` (`id_stu`),
KEY `id_try` (`id_try`) KEY `id_try` (`id_try`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="This table registers and action performed by a user at a given time, all information of the action is in JSON format in the 'description' column and the operation performed is one of the possible for the 'type' column";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -51,13 +52,14 @@ CREATE TABLE IF NOT EXISTS `action` ( ...@@ -51,13 +52,14 @@ CREATE TABLE IF NOT EXISTS `action` (
-- --
CREATE TABLE IF NOT EXISTS `catexp`( CREATE TABLE IF NOT EXISTS `catexp`(
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`id_cat` int(11) NOT NULL REFERENCES `pictocat`, `id_cat` int(11) NOT NULL,
`lang` char(5), `lang` char(5),
`exp` varchar(30) NOT NULL, `exp` varchar(30) NOT NULL,
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
UNIQUE(exp,lang), UNIQUE(exp,lang),
CHECK (lang IN ('es-es','en-gb','en-us')) CHECK (lang IN ('es-es','en-gb','en-us'))
); )
COMMENT="Stores the expressions available in several languages for a given category (id_cat)";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -74,7 +76,8 @@ CREATE TABLE IF NOT EXISTS `method` ( ...@@ -74,7 +76,8 @@ CREATE TABLE IF NOT EXISTS `method` (
`notes` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL, `notes` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `fk_stu_met` (`id_stu`) KEY `fk_stu_met` (`id_stu`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="Information for a method. A method is composed by a set of instructions";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -91,7 +94,8 @@ CREATE TABLE IF NOT EXISTS `instruction` ( ...@@ -91,7 +94,8 @@ CREATE TABLE IF NOT EXISTS `instruction` (
`begin` timestamp NULL, `begin` timestamp NULL,
`end` timestamp NULL, `end` timestamp NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="An instruction is a 'phase' in a method for learning AAC";
...@@ -107,7 +111,8 @@ CREATE TABLE IF NOT EXISTS `meta_instruction` ( ...@@ -107,7 +111,8 @@ CREATE TABLE IF NOT EXISTS `meta_instruction` (
`objective` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL, `objective` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL,
`id_met` tinyint(4) NOT NULL, `id_met` tinyint(4) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="One in a set of instructions predefined or stored by users. They are related to a metamethod (id_met)";
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
...@@ -121,7 +126,8 @@ CREATE TABLE IF NOT EXISTS `meta_method` ( ...@@ -121,7 +126,8 @@ CREATE TABLE IF NOT EXISTS `meta_method` (
`id_sup` INT( 11 ) DEFAULT NULL, `id_sup` INT( 11 ) DEFAULT NULL,
UNIQUE(name,id_sup), UNIQUE(name,id_sup),
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="Methods predefined in the platform or stored by users for cloning";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -145,7 +151,8 @@ CREATE TABLE IF NOT EXISTS `office` ( ...@@ -145,7 +151,8 @@ CREATE TABLE IF NOT EXISTS `office` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`), UNIQUE KEY `email` (`email`),
KEY `fk_admin_tea` (`admin`) KEY `fk_admin_tea` (`admin`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=383 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=383
COMMENT="Information about a therapists' office (cabinet)";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -156,13 +163,14 @@ CREATE TABLE IF NOT EXISTS `office` ( ...@@ -156,13 +163,14 @@ CREATE TABLE IF NOT EXISTS `office` (
CREATE TABLE IF NOT EXISTS `picto` ( CREATE TABLE IF NOT EXISTS `picto` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`uri` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `uri` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
`id_src` tinyint(4) NOT NULL REFERENCES `source`, `id_src` tinyint(4) NOT NULL,
`id_owner` int(11) DEFAULT NULL REFERENCES `supervisor`, `id_owner` int(11) DEFAULT NULL,
`id_cat` int(11) DEFAULT NULL REFERENCES `pictocat`, `id_cat` int(11) DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `ck_pic` (`id_owner`,`id_src`,`uri`), UNIQUE KEY `ck_pic` (`id_owner`,`id_src`,`uri`),
KEY `fk_sou_pic` (`id_src`) KEY `fk_sou_pic` (`id_src`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=104142 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=104142
COMMENT="Main information about a pictogram, either coming from a source like Symbolstix or added by a supervisor. It can belongs to a category (id_cat)";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -172,14 +180,15 @@ CREATE TABLE IF NOT EXISTS `picto` ( ...@@ -172,14 +180,15 @@ CREATE TABLE IF NOT EXISTS `picto` (
CREATE TABLE IF NOT EXISTS `pictocat`( CREATE TABLE IF NOT EXISTS `pictocat`(
`id` int(11) PRIMARY KEY, `id` int(11) PRIMARY KEY,
`id_supercat` int(11) REFERENCES `pictocat` `id_supercat` int(11)
); )
COMMENT="Identifies a category, which, itself, may belong to another category";
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Estructura de tabla para la tabla `picto_acl` -- Estructura de tabla para la tabla `picto_acl`
-- -- NOT IN USE (candidate for removal)
CREATE TABLE IF NOT EXISTS `picto_acl` ( CREATE TABLE IF NOT EXISTS `picto_acl` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
...@@ -190,7 +199,8 @@ CREATE TABLE IF NOT EXISTS `picto_acl` ( ...@@ -190,7 +199,8 @@ CREATE TABLE IF NOT EXISTS `picto_acl` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `k_pic_aclp` (`id_pic`), KEY `k_pic_aclp` (`id_pic`),
KEY `k_sup_aclp` (`id_sup`) KEY `k_sup_aclp` (`id_sup`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="Stablish access rights to pictos";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -200,23 +210,7 @@ CREATE TABLE IF NOT EXISTS `picto_acl` ( ...@@ -200,23 +210,7 @@ CREATE TABLE IF NOT EXISTS `picto_acl` (
CREATE TABLE IF NOT EXISTS `picto_core` ( CREATE TABLE IF NOT EXISTS `picto_core` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`id_pic` int(11) NOT NULL, `id_pic` int(11) DEFAULT NULL COMMENT 'This is the id of the pictogram',
`coord_x` tinyint(4) NOT NULL,
`coord_y` tinyint(4) NOT NULL,
`color` int NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uq_coord_pc` (`coord_x`,`coord_y`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `picto_core_cat`
--
CREATE TABLE IF NOT EXISTS `picto_core_cat` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_pic` int(11) DEFAULT NULL,
`id_cat_pic` int(11) DEFAULT NULL COMMENT 'This is the id of the pictogram that represents the category this entry belongs to', `id_cat_pic` int(11) DEFAULT NULL COMMENT 'This is the id of the pictogram that represents the category this entry belongs to',
`coord_x` tinyint(4) NOT NULL, `coord_x` tinyint(4) NOT NULL,
`coord_y` tinyint(4) NOT NULL, `coord_y` tinyint(4) NOT NULL,
...@@ -224,7 +218,8 @@ CREATE TABLE IF NOT EXISTS `picto_core_cat` ( ...@@ -224,7 +218,8 @@ CREATE TABLE IF NOT EXISTS `picto_core_cat` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `id_pic` (`id_pic`), KEY `id_pic` (`id_pic`),
KEY `id_cat_pic` (`id_cat_pic`) KEY `id_cat_pic` (`id_cat_pic`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=124 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=124
COMMENT="Default pictos and categories available for a newly created student with default coordinates";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -234,12 +229,13 @@ CREATE TABLE IF NOT EXISTS `picto_core_cat` ( ...@@ -234,12 +229,13 @@ CREATE TABLE IF NOT EXISTS `picto_core_cat` (
CREATE TABLE IF NOT EXISTS `picto_exp` ( CREATE TABLE IF NOT EXISTS `picto_exp` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`id_pic` int(11) NOT NULL REFERENCES `picto`, `id_pic` int(11) NOT NULL,
`lang` char(5) COLLATE utf8_unicode_ci NOT NULL, `lang` char(5) COLLATE utf8_unicode_ci NOT NULL,
`text` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `text` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `id_pic` (`id_pic`) KEY `id_pic` (`id_pic`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=72565 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=72565
COMMENT="Expression (text label) for a picto in different languages. This is used by the TTS engine";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -249,29 +245,15 @@ CREATE TABLE IF NOT EXISTS `picto_exp` ( ...@@ -249,29 +245,15 @@ CREATE TABLE IF NOT EXISTS `picto_exp` (
CREATE TABLE IF NOT EXISTS `picto_tag` ( CREATE TABLE IF NOT EXISTS `picto_tag` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`id_sup` int(11) DEFAULT NULL COMMENT 'If NULL then is a default tag',
`id_pic` int(11) NOT NULL, `id_pic` int(11) NOT NULL,
`tag` varchar(60) COLLATE utf8_unicode_ci NOT NULL, `tag` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
`lang` char(5) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `id_pic` (`id_pic`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=36536 ;
-- --------------------------------------------------------
--
-- Estructura de tabla para la tabla `picto_tag_sup`
--
CREATE TABLE IF NOT EXISTS `picto_tag_sup` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_sup` int(11) NOT NULL,
`id_pic` int(11) NOT NULL,
`tag` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`lang` char(5) COLLATE utf8_unicode_ci NOT NULL, `lang` char(5) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `id_pic` (`id_pic`), KEY `id_pic` (`id_pic`),
KEY `id_sup` (`id_sup`) KEY `id_sup` (`id_sup`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="Labels assigned to pictos by default or by supervisors";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -284,7 +266,8 @@ CREATE TABLE IF NOT EXISTS `source` ( ...@@ -284,7 +266,8 @@ CREATE TABLE IF NOT EXISTS `source` (
`name` varchar(40) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL, `description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2
COMMENT="Contains all possible sources of pictos";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -305,11 +288,12 @@ CREATE TABLE IF NOT EXISTS `student` ( ...@@ -305,11 +288,12 @@ CREATE TABLE IF NOT EXISTS `student` (
`notes` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL, `notes` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
`lang` varchar(5) COLLATE utf8_unicode_ci NOT NULL, `lang` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
`attributes` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Attributes describing student along with his/her configuration', `attributes` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Attributes describing student along with his/her configuration',
`id_off` int(11) DEFAULT NULL COMMENT 'office', `id_off` int(11) DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`), UNIQUE KEY `username` (`username`),
KEY `id_off` (`id_off`) KEY `id_off` (`id_off`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=19 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=19
COMMENT="Students information";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -326,7 +310,8 @@ CREATE TABLE IF NOT EXISTS `stu_picto` ( ...@@ -326,7 +310,8 @@ CREATE TABLE IF NOT EXISTS `stu_picto` (
KEY `fk_picto` (`id_pic`), KEY `fk_picto` (`id_pic`),
KEY `id_stu` (`id_stu`), KEY `id_stu` (`id_stu`),
UNIQUE `uq_stupicto` (`id_stu`,`id_pic`) UNIQUE `uq_stupicto` (`id_stu`,`id_pic`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="This table relates a student with the pictos in her vocabulary";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -342,7 +327,8 @@ CREATE TABLE IF NOT EXISTS `stu_sup` ( ...@@ -342,7 +327,8 @@ CREATE TABLE IF NOT EXISTS `stu_sup` (
UNIQUE KEY `fk_stu_sup_ss` (`id_stu`,`id_sup`), UNIQUE KEY `fk_stu_sup_ss` (`id_stu`,`id_sup`),
KEY `fk_sup_ss` (`id_sup`), KEY `fk_sup_ss` (`id_sup`),
KEY `id_stu` (`id_stu`) KEY `id_stu` (`id_stu`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=26 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=26
COMMENT="This table relates students and supervisors";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -363,12 +349,13 @@ CREATE TABLE IF NOT EXISTS `supervisor` ( ...@@ -363,12 +349,13 @@ CREATE TABLE IF NOT EXISTS `supervisor` (
`lang` varchar(5) COLLATE utf8_unicode_ci NOT NULL, `lang` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
`tts_engine` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `tts_engine` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`password` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'Encrypted password using the BCrypt algorithm', `password` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'Encrypted password using the BCrypt algorithm',
`id_off` int(11) DEFAULT NULL COMMENT 'office', `id_off` int(11) DEFAULT NULL,
`active` boolean DEFAULT FALSE, `active` boolean DEFAULT FALSE,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`), UNIQUE KEY `email` (`email`),
KEY `id_off` (`id_off`) KEY `id_off` (`id_off`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=23 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=23
COMMENT="Supervisors information";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -385,7 +372,8 @@ CREATE TABLE IF NOT EXISTS `try` ( ...@@ -385,7 +372,8 @@ CREATE TABLE IF NOT EXISTS `try` (
`description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL, `description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `id_ws` (`id_ws`) KEY `id_ws` (`id_ws`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="This table contains tries information (they belong to a working session)";
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -406,8 +394,17 @@ CREATE TABLE IF NOT EXISTS `working_session` ( ...@@ -406,8 +394,17 @@ CREATE TABLE IF NOT EXISTS `working_session` (
`description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL, `description` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `id_sup` (`id_sup`), KEY `id_sup` (`id_sup`),
KEY `id_ins` (`id_ins`) KEY `id_ins` (`id_ins`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-- Integrity rule 6: It is not possible to open a new session when a previous session is opened for a given supervisor
-- when: state SES and PAU, event a2
-- (see triggers-sessions-integrity-constraints for the rest of rules)
--
CONSTRAINT `idx_ws_supcur` UNIQUE (id_sup, current)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="This table stores working session information. Every working session is related to one instruction and one supervisor (and the instruction is related to one method which is related to one student)";
-- --
-- Restricciones para tablas volcadas -- Restricciones para tablas volcadas
...@@ -420,6 +417,12 @@ ALTER TABLE `action` ...@@ -420,6 +417,12 @@ ALTER TABLE `action`
ADD CONSTRAINT `fk_stu_act` FOREIGN KEY (`id_stu`) REFERENCES `student` (`id`), ADD CONSTRAINT `fk_stu_act` FOREIGN KEY (`id_stu`) REFERENCES `student` (`id`),
ADD CONSTRAINT `fk_sup_act` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`); ADD CONSTRAINT `fk_sup_act` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`);
-- Integrity rule 8: Every action requires a valid try or null
-- when: state SES, event a3 and a5
-- (see triggers-sessions-integrity-constraints for the rest of rules)
--
ALTER TABLE `action`
ADD CONSTRAINT `fk_try_act` FOREIGN KEY (`id_try`) REFERENCES `try` (`id`) ON DELETE SET NULL;;
-- --
...@@ -465,17 +468,11 @@ ALTER TABLE `picto_acl` ...@@ -465,17 +468,11 @@ ALTER TABLE `picto_acl`
ADD CONSTRAINT `fk_sup_aclp` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`); ADD CONSTRAINT `fk_sup_aclp` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`);
-- --
-- Filtros para la tabla `picto_core`
--
ALTER TABLE `picto_core`
ADD CONSTRAINT `picto_core_ibfk_1` FOREIGN KEY (`id`) REFERENCES `picto` (`id`);
--
-- Filtros para la tabla `picto_core_cat` -- Filtros para la tabla `picto_core_cat`
-- --
ALTER TABLE `picto_core_cat` ALTER TABLE `picto_core`
ADD CONSTRAINT `picto_core_cat_ibfk_1` FOREIGN KEY (`id_cat_pic`) REFERENCES `picto` (`id`), ADD CONSTRAINT `picto_core_ibfk_1` FOREIGN KEY (`id_cat_pic`) REFERENCES `picto` (`id`),
ADD CONSTRAINT `picto_core_cat_ibfk_2` FOREIGN KEY (`id_pic`) REFERENCES `picto` (`id`); ADD CONSTRAINT `picto_core_ibfk_2` FOREIGN KEY (`id_pic`) REFERENCES `picto` (`id`);
-- --
...@@ -487,9 +484,9 @@ ALTER TABLE `picto_tag` ...@@ -487,9 +484,9 @@ ALTER TABLE `picto_tag`
-- --
-- Filtros para la tabla `picto_tag_sup` -- Filtros para la tabla `picto_tag_sup`
-- --
ALTER TABLE `picto_tag_sup` ALTER TABLE `picto_tag`
ADD CONSTRAINT `picto_tag_sup_ibfk_1` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`), ADD CONSTRAINT `picto_tag_ibfk_1` FOREIGN KEY (`id_sup`) REFERENCES `supervisor` (`id`),
ADD CONSTRAINT `picto_tag_sup_ibfk_2` FOREIGN KEY (`id_pic`) REFERENCES `picto` (`id`); ADD CONSTRAINT `picto_tag_ibfk_2` FOREIGN KEY (`id_pic`) REFERENCES `picto` (`id`);
-- --
-- Filtros para la tabla `stu_picto` -- Filtros para la tabla `stu_picto`
...@@ -523,6 +520,7 @@ ALTER TABLE `supervisor` ...@@ -523,6 +520,7 @@ ALTER TABLE `supervisor`
ALTER TABLE `try` ALTER TABLE `try`
ADD CONSTRAINT `try_ibfk_1` FOREIGN KEY (`id_ws`) REFERENCES `working_session` (`id`) ON DELETE CASCADE; ADD CONSTRAINT `try_ibfk_1` FOREIGN KEY (`id_ws`) REFERENCES `working_session` (`id`) ON DELETE CASCADE;
-- --
-- Filtros para la tabla `working_session` -- Filtros para la tabla `working_session`
-- --
...@@ -538,7 +536,7 @@ ALTER TABLE `working_session` ...@@ -538,7 +536,7 @@ ALTER TABLE `working_session`
CREATE ALGORITHM=UNDEFINED CREATE ALGORITHM=UNDEFINED
VIEW `v_stu_last_ws_time` AS VIEW `v_stu_last_ws_time` AS
SELECT M.`id_stu`AS id_stu, SELECT M.`id_stu` AS id_stu,
MAX(WS.begin) AS time MAX(WS.begin) AS time
FROM FROM
`working_session` AS WS join `working_session` AS WS join
...@@ -549,6 +547,7 @@ SELECT M.`id_stu`AS id_stu, ...@@ -549,6 +547,7 @@ SELECT M.`id_stu`AS id_stu,
and I.`id_met` = M.`id` and I.`id_met` = M.`id`
group by M.`id_stu`; group by M.`id_stu`;
CREATE ALGORITHM=UNDEFINED CREATE ALGORITHM=UNDEFINED
VIEW `v_stu_last_instruction` AS VIEW `v_stu_last_instruction` AS
select select
......
The file could not be displayed because it is too large.
...@@ -6,7 +6,7 @@ SET foreign_key_checks = 0; ...@@ -6,7 +6,7 @@ SET foreign_key_checks = 0;
-- Oficina Autismo Jaen -- Oficina Autismo Jaen
-- --
INSERT INTO `office` ( INSERT IGNORE INTO `office` (
`name`, `name`,
`address`, `address`,
`country`, `country`,
...@@ -29,7 +29,7 @@ INSERT INTO `office` ( ...@@ -29,7 +29,7 @@ INSERT INTO `office` (
-- La contraseña es la primera parte del email (ej: manuel.colmenero) -- La contraseña es la primera parte del email (ej: manuel.colmenero)
-- --
INSERT INTO `supervisor` ( INSERT IGNORE INTO `supervisor` (
`name`, `name`,
`surname`, `surname`,
`gender`, `gender`,
...@@ -65,7 +65,7 @@ UPDATE office ...@@ -65,7 +65,7 @@ UPDATE office
-- La contraseña es la primera parte del email (ej: manuel.colmenero) -- La contraseña es la primera parte del email (ej: manuel.colmenero)
-- --
INSERT INTO `supervisor` ( INSERT IGNORE INTO `supervisor` (
`name`, `name`,
`surname`, `surname`,
`gender`, `gender`,
...@@ -116,7 +116,7 @@ INSERT INTO `supervisor` ( ...@@ -116,7 +116,7 @@ INSERT INTO `supervisor` (
-- La contraseña es la primera parte del email (ej: manuel.colmenero) -- La contraseña es la primera parte del email (ej: manuel.colmenero)
-- --
INSERT INTO `supervisor` ( INSERT IGNORE INTO `supervisor` (
`name`, `name`,
`surname`, `surname`,
`gender`, `gender`,
...@@ -163,7 +163,7 @@ INSERT INTO `supervisor` ( ...@@ -163,7 +163,7 @@ INSERT INTO `supervisor` (
-- La contraseña es el nombre de usuario -- La contraseña es el nombre de usuario
-- --
INSERT INTO `student` ( INSERT IGNORE INTO `student` (
`username`, `username`,
`password`, `password`,
`name`, `name`,
...@@ -287,7 +287,7 @@ INSERT INTO `student` ( ...@@ -287,7 +287,7 @@ INSERT INTO `student` (
-- Student pictos -- Student pictos
-- --
INSERT INTO `stu_picto` ( INSERT IGNORE INTO `stu_picto` (
`id_stu`, `id_stu`,
`id_pic`, `id_pic`,
`attributes` `attributes`
...@@ -300,7 +300,7 @@ SELECT S.id, P.id_pic, concat('{', ...@@ -300,7 +300,7 @@ SELECT S.id, P.id_pic, concat('{',
',"highlight":false', ',"highlight":false',
',"color":', if (P.color is null, 'null', concat('"', P.color,'"')), ',"color":', if (P.color is null, 'null', concat('"', P.color,'"')),
'}') as attributes '}') as attributes
FROM student S, picto_core_cat P FROM student S, picto_core P
WHERE WHERE
S.id_off=(SELECT id S.id_off=(SELECT id
FROM office FROM office
......
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00"; SET time_zone = "+00:00";
SET foreign_key_checks = 0; SET foreign_key_checks = 0;
SET @TRIGGER_CHECKS = FALSE;
-- --
-- Oficina -- Oficina
...@@ -394,7 +395,7 @@ SELECT S.id,P.id_pic, concat('{"id_cat":', if (id_cat_pic is null, 'null',id_cat ...@@ -394,7 +395,7 @@ SELECT S.id,P.id_pic, concat('{"id_cat":', if (id_cat_pic is null, 'null',id_cat
',"highlight":false', ',"highlight":false',
',"color":', if (color is null, 'null',concat('"',color,'"')), ',"color":', if (color is null, 'null',concat('"',color,'"')),
'}') as attributes '}') 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)'); 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 ( ...@@ -417,4 +418,5 @@ INSERT INTO working_session (id_sup, id_ins) VALUES (
(SELECT id FROM instruction WHERE name='Test Instruction') (SELECT id FROM instruction WHERE name='Test Instruction')
); );
SET @TRIGGER_CHECKS = TRUE;
SET foreign_key_checks=1; SET foreign_key_checks=1;
...@@ -5,11 +5,20 @@ DELIMITER ;; ...@@ -5,11 +5,20 @@ DELIMITER ;;
-- Integrity rule 1: It is not possible to enrol a higer number of student than office.max_enrolments -- 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 CREATE TRIGGER TRG_NEW_STUDENT_MAXENROLMENTS
BEFORE INSERT ON student BEFORE INSERT ON student
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
DECLARE max_enr,curr_enr INT; DECLARE max_enr,curr_enr INT;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_BEFORE_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
IF new.id_off IS NOT NULL THEN IF new.id_off IS NOT NULL THEN
SELECT SELECT
max_students, current_students INTO max_enr, curr_enr max_students, current_students INTO max_enr, curr_enr
...@@ -27,10 +36,17 @@ BEGIN ...@@ -27,10 +36,17 @@ BEGIN
END;; END;;
-- Integrity rule 2: office.current_enrolments updating -- Integrity rule 2: office.current_enrolments updating
DROP TRIGGER IF EXISTS TRG_NEW_STUDENT_UPDATE_ENROLMENTS;
CREATE TRIGGER TRG_NEW_STUDENT_UPDATE_ENROLMENTS CREATE TRIGGER TRG_NEW_STUDENT_UPDATE_ENROLMENTS
AFTER INSERT ON student AFTER INSERT ON student
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
UPDATE UPDATE
office office
...@@ -41,10 +57,18 @@ BEGIN ...@@ -41,10 +57,18 @@ BEGIN
END;; END;;
-- Integrity rule 3: office.current_enrolments and supervisor assigments updating. -- Integrity rule 3: office.current_enrolments and supervisor assigments updating.
DROP TRIGGER IF EXISTS TRG_MODIFY_STUDENT_ENROLMENTS;
CREATE TRIGGER TRG_MODIFY_STUDENT_ENROLMENTS CREATE TRIGGER TRG_MODIFY_STUDENT_ENROLMENTS
AFTER UPDATE ON student AFTER UPDATE ON student
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_UPDATE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
IF NOT (old.id_off<=>new.id_off) THEN IF NOT (old.id_off<=>new.id_off) THEN
IF (old.id_off IS NOT NULL) THEN IF (old.id_off IS NOT NULL) THEN
UPDATE UPDATE
...@@ -72,10 +96,18 @@ BEGIN ...@@ -72,10 +96,18 @@ BEGIN
END;; 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 -- 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 CREATE TRIGGER TRG_DELETE_STUDENT_ENROLMENTS
AFTER DELETE ON student AFTER DELETE ON student
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_DELETE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
IF old.id_off IS NULL THEN IF old.id_off IS NULL THEN
UPDATE UPDATE
office office
......
...@@ -7,28 +7,30 @@ DELIMITER ;; ...@@ -7,28 +7,30 @@ DELIMITER ;;
-- --
-- Get the current try for a given session by reading disk-based tables only -- Get the current try for a given session by reading disk-based tables only
-- --
DROP FUNCTION IF EXISTS getOpenTry;
CREATE FUNCTION getOpenTry(idstu INT) CREATE FUNCTION getOpenTry(idstu INT)
RETURNS INT RETURNS INT
READS SQL DATA READS SQL DATA
BEGIN BEGIN
DECLARE id_opentry INT; DECLARE id_opentry INT;
SELECT T.id INTO id_opentry SELECT T.id INTO id_opentry
FROM FROM
try T, try T,
working_session WS, working_session WS,
instruction I, instruction I,
method M method M
WHERE WHERE
T.id_ws=WS.id AND T.id_ws=WS.id AND
WS.id_ins=I.id AND WS.id_ins=I.id AND
I.id_met=M.id AND I.id_met=M.id AND
M.id_stu=idstu AND T.end IS NULL; M.id_stu=idstu AND T.end IS NULL;
return id_opentry; return id_opentry;
END;; END;;
-- --
-- Memory table in order to recover data about current working sessions -- Memory table in order to recover data about current working sessions
-- --
DROP TABLE IF EXISTS stu_opentry;
CREATE TABLE stu_opentry ( CREATE TABLE stu_opentry (
id int(11) NOT NULL AUTO_INCREMENT, id int(11) NOT NULL AUTO_INCREMENT,
id_stu int(11) NOT NULL, id_stu int(11) NOT NULL,
...@@ -51,12 +53,13 @@ FOREIGN KEY (id_ws) REFERENCES working_session(id) ON DELETE CASCADE ...@@ -51,12 +53,13 @@ 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 -- 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 -- 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) CREATE PROCEDURE newTry(idstu INT, idsup INT, idws INT)
MODIFIES SQL DATA MODIFIES SQL DATA
BEGIN BEGIN
DECLARE idopentry int; DECLARE idopentry int;
INSERT INTO try(`id_ws`) INSERT INTO try(`id_ws`)
VALUES (idws); VALUES (idws);
SET idopentry=LAST_INSERT_ID(); SET idopentry=LAST_INSERT_ID();
...@@ -67,45 +70,54 @@ BEGIN ...@@ -67,45 +70,54 @@ BEGIN
idws, idws,
idopentry, idopentry,
0, 0,
NOW() NOW()
) )
ON DUPLICATE KEY UPDATE id_stu=idstu, id_sup=idsup, id_ws=idws, id_opentry=idopentry; ON DUPLICATE KEY UPDATE id_stu=idstu, id_sup=idsup, id_ws=idws, id_opentry=idopentry;
END;; END;;
-- --
-- It deletes current try for a given session -- It deletes current try for a given session
DROP PROCEDURE IF EXISTS deleteOpenTry;
CREATE PROCEDURE deleteOpenTry(ws INT) CREATE PROCEDURE deleteOpenTry(ws INT)
BEGIN BEGIN
DECLARE idopentry INT; DECLARE idopentry INT;
SELECT id_opentry INTO idopentry SELECT id_opentry INTO idopentry
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_ws = ws; id_ws = ws;
IF (idopentry IS NOT NULL) THEN IF (idopentry IS NOT NULL) THEN
DELETE FROM try DELETE FROM try
WHERE id = idopentry; WHERE id = idopentry;
END IF; END IF;
END;; END;;
-- Integrity rule 1: A new session begins and in turn a new try is created -- 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 -- Integrity rule 8: Any instruction with a new session has a "started" state
-- when: state COM, event a2 -- when: state COM, event a2
DROP TRIGGER IF EXISTS TRG_SESSION_NEW;
CREATE TRIGGER TRG_SESSION_NEW CREATE TRIGGER TRG_SESSION_NEW
AFTER INSERT ON working_session AFTER INSERT ON working_session
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
DECLARE idstu INT; DECLARE idstu INT;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
SELECT DISTINCT M.id_stu INTO idstu SELECT DISTINCT M.id_stu INTO idstu
FROM FROM
instruction I, instruction I,
method M method M
WHERE WHERE
I.id=new.id_ins AND I.id=new.id_ins AND
I.id_met=M.id; I.id_met=M.id;
UPDATE instruction UPDATE instruction
SET status='started' SET status='started'
WHERE id=new.id_ins; WHERE id=new.id_ins;
...@@ -113,15 +125,23 @@ BEGIN ...@@ -113,15 +125,23 @@ BEGIN
CALL newTry(idstu, new.id_sup, new.id); CALL newTry(idstu, new.id_sup, new.id);
END;; END;;
-- Integrity rule 2: when a session is closed, last try must be discharged -- Integrity rule 2: when a session is closed, last try must be discharged
-- when: state COM, event a4 -- when: state COM, event a4
-- current is to NULL (integrity rule 6) -- current is to NULL (integrity rule 6)
-- --
DROP TRIGGER IF EXISTS TRG_SESSION_CLOSED;
CREATE TRIGGER TRG_SESSION_CLOSED CREATE TRIGGER TRG_SESSION_CLOSED
AFTER UPDATE ON working_session AFTER UPDATE ON working_session
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_UPDATE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
IF ((old.end IS NULL) and (new.end IS NOT NULL)) THEN IF ((old.end IS NULL) and (new.end IS NOT NULL)) THEN
CALL deleteOpenTry(new.id); CALL deleteOpenTry(new.id);
END IF; END IF;
...@@ -131,118 +151,133 @@ END;; ...@@ -131,118 +151,133 @@ END;;
-- Integrity rule 3: every event is required to have the id try whenver a try happens -- Integrity rule 3: every event is required to have the id try whenver a try happens
-- when: state COM, event a4 -- when: state COM, event a4
-- --
DROP TRIGGER IF EXISTS TRG_NEW_EVENT_ONSESSION;
CREATE TRIGGER TRG_NEW_EVENT_ONSESSION CREATE TRIGGER TRG_NEW_EVENT_ONSESSION
BEFORE INSERT ON action BEFORE INSERT ON action
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
DECLARE idstu INT; DECLARE idstu INT;
DECLARE idtry INT; DECLARE idtry INT;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_BEFORE_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
SET idstu=NEW.id_stu; SET idstu=NEW.id_stu;
SELECT id_opentry INTO idtry SELECT id_opentry INTO idtry
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_stu = idstu; id_stu = idstu;
IF (idtry IS NOT NULL) THEN IF (idtry IS NOT NULL) THEN
SET NEW.id_try=idtry; SET NEW.id_try=idtry;
END IF; END IF;
END;; END;;
-- Integrity rule 7: when a sentence is finished, previous try is closed -- Integrity rule 7: when a sentence is finished, previous try is closed
-- and new try is created in case of working session happening -- and new try is created in case of working session happening
-- when: state COM, event a4 -- when: state COM, event a4
-- Integrity rule 5: when a session is continued after a pause and new try is created -- Integrity rule 5: when a session is continued after a pause and new try is created
-- when: state PAU, event a3 -- when: state PAU, event a3
-- Integrity rule 4: when a session is paused, last try must be discharged -- Integrity rule 4: when a session is paused, last try must be discharged
-- when: state SES, event a3 -- when: state SES, event a3
DROP TRIGGER IF EXISTS TRG_NEW_EVENT;
CREATE TRIGGER TRG_NEW_EVENT CREATE TRIGGER TRG_NEW_EVENT
AFTER INSERT ON action AFTER INSERT ON action
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
DECLARE idopentry INT; DECLARE idopentry INT;
DECLARE idsup_ws INT; DECLARE idsup_ws INT;
DECLARE idws INT; DECLARE idws INT;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
CASE NEW.type CASE NEW.type
WHEN 'Show' THEN WHEN 'Show' THEN
SELECT id_ws, id_sup, id_opentry INTO idws, idsup_ws, idopentry SELECT id_ws, id_sup, id_opentry INTO idws, idsup_ws, idopentry
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_stu = NEW.id_stu; id_stu = NEW.id_stu;
IF (idopentry IS NOT NULL and NEW.id_sup IS NULL) THEN IF (idopentry IS NOT NULL and NEW.id_sup IS NULL) THEN
UPDATE `try` UPDATE `try`
SET end=NOW() SET end=NOW()
WHERE id=idopentry; WHERE id=idopentry;
call newTry(new.id_stu, idsup_ws, idws); call newTry(new.id_stu, idsup_ws, idws);
END IF; END IF;
WHEN 'Pause' THEN WHEN 'Pause' THEN
SELECT id_ws, id_opentry INTO idws, idopentry SELECT id_ws, id_opentry INTO idws, idopentry
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_stu = NEW.id_stu; id_stu = NEW.id_stu;
IF (idopentry IS NULL) THEN IF (idopentry IS NULL) THEN
call newTry(new.id_stu, new.id_sup,idws); call newTry(new.id_stu, new.id_sup,idws);
ELSE ELSE
call deleteOpenTry(idws); call deleteOpenTry(idws);
END IF; END IF;
ELSE BEGIN END; ELSE BEGIN END;
END CASE; END CASE;
END;; END;;
-- Integrity rule 6: It is not possible to open a new session when a previous session is opened for a given supervisor
-- when: state SES and PAU, event a2
--
ALTER TABLE `working_session`
ADD CONSTRAINT `idx_ws_supcur` UNIQUE (id_sup, current);;
-- Integrity rule 2: when a session is closed, last try must be discharged -- Integrity rule 2: when a session is closed, last try must be discharged
-- when: state COM, event a4 -- when: state COM, event a4
-- current is to NULL (integrity rule 6) -- current is to NULL (integrity rule 6)
-- --
DROP TRIGGER IF EXISTS TRG_SESSION_CLOSING;
CREATE TRIGGER TRG_SESSION_CLOSING CREATE TRIGGER TRG_SESSION_CLOSING
BEFORE UPDATE ON working_session BEFORE UPDATE ON working_session
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((new.end IS NOT NULL) AND (new.current IS NOT NULL)) THEN IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_BEFORE_UPDATE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
IF ((new.end IS NOT NULL) AND (new.current IS NOT NULL)) THEN
SET new.current=NULL; SET new.current=NULL;
END IF; END IF;
END;; END;;
-- Integrity rule 8: Every action requires a valid try or null
-- when: state SES, event a3 and a5
--
ALTER TABLE `action`
ADD CONSTRAINT `fk_try_act` FOREIGN KEY (`id_try`) REFERENCES `try` (`id`) ON DELETE SET NULL;;
-- --
-- Required for not closed sessions policy retrieving -- Required for not closed sessions policy retrieving
-- --
DROP TRIGGER IF EXISTS TRG_TRY_EVALUATED;
CREATE TRIGGER TRG_TRY_EVALUATED CREATE TRIGGER TRG_TRY_EVALUATED
AFTER UPDATE ON try AFTER UPDATE ON try
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
DECLARE idopentry INT; DECLARE idopentry INT;
DECLARE idws INT; DECLARE idws INT;
DECLARE ws_end DATE; DECLARE ws_end DATE;
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_UPDATE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
SELECT id_ws, id_opentry,end INTO idws, idopentry, ws_end SELECT id_ws, id_opentry,end INTO idws, idopentry, ws_end
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_ws = NEW.id_ws; id_ws = NEW.id_ws;
IF ( (old.result IS NULL) and (new.result IS NOT NULL) and (new.end>ws_end)) THEN IF ( (old.result IS NULL) and (new.result IS NOT NULL) and (new.end>ws_end)) THEN
UPDATE stu_opentry UPDATE stu_opentry
SET end=new.end, total_tries=total_tries+1 SET end=new.end, total_tries=total_tries+1
WHERE id_ws=idws; WHERE id_ws=idws;
END IF; END IF;
END;; END;;
DELIMITER ; DELIMITER ;
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
name: all name: all
state: import state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/init.sql" target: "{{ server_path }}/{{ database_files_relative_path }}/init.sql"
tags: reset-test-database
- name: Imports the pictodb Schema - name: Imports the pictodb Schema
mysql_db: mysql_db:
...@@ -15,6 +16,8 @@ ...@@ -15,6 +16,8 @@
name: "{{ database_name }}" name: "{{ database_name }}"
state: import state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/pictodb-schema.sql" target: "{{ server_path }}/{{ database_files_relative_path }}/pictodb-schema.sql"
tags:
- reset-test-database
- name: Imports symbolstx categories and metadata - name: Imports symbolstx categories and metadata
mysql_db: mysql_db:
...@@ -23,6 +26,8 @@ ...@@ -23,6 +26,8 @@
name: "{{ database_name }}" name: "{{ database_name }}"
state: import state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/symbolstx-{{ item }}.sql" target: "{{ server_path }}/{{ database_files_relative_path }}/symbolstx-{{ item }}.sql"
tags:
- reset-test-database
with_items: with_items:
- categories - categories
- metadata - metadata
...@@ -34,6 +39,8 @@ ...@@ -34,6 +39,8 @@
name: "{{ database_name }}" name: "{{ database_name }}"
state: import state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/pictodb-data.sql" target: "{{ server_path }}/{{ database_files_relative_path }}/pictodb-data.sql"
tags:
- reset-test-database
- name: Imports selected tests - name: Imports selected tests
mysql_db: mysql_db:
...@@ -42,6 +49,8 @@ ...@@ -42,6 +49,8 @@
name: "{{ database_name }}" name: "{{ database_name }}"
state: import state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/test-{{ item }}.sql" target: "{{ server_path }}/{{ database_files_relative_path }}/test-{{ item }}.sql"
tags:
- reset-test-database
with_items: "{{ database_tests }}" with_items: "{{ database_tests }}"
- name: Creates triggers - name: Creates triggers
...@@ -51,6 +60,8 @@ ...@@ -51,6 +60,8 @@
name: "{{ database_name }}" name: "{{ database_name }}"
state: import state: import
target: "{{ server_path }}/{{ database_files_relative_path }}/triggers-{{ item }}.sql" target: "{{ server_path }}/{{ database_files_relative_path }}/triggers-{{ item }}.sql"
tags:
- reset-test-database
with_items: with_items:
- enrolments-integrity-constraints - enrolments-integrity-constraints
- sessions-integrity-constraints - sessions-integrity-constraints
...@@ -4,4 +4,4 @@ database_root_passwd: root ...@@ -4,4 +4,4 @@ database_root_passwd: root
database_name: pictodb database_name: pictodb
database_user: pictodbuser database_user: pictodbuser
database_user_passwd: p1KT015 database_user_passwd: p1KT015
database_tests: [caja, autismojaen] # can be empty database_tests: [caja] #[caja, autismojaen] # can be empty
/* global sails, Picto, Supervisor, PictoCat, PictoTagSup, PictoExp */ /* global sails, Picto, Supervisor, PictoCat, PictoTag, PictoExp */
/** /**
* PictoController * PictoController
...@@ -125,14 +125,14 @@ module.exports = { ...@@ -125,14 +125,14 @@ module.exports = {
throw new Error('Picto not found'); throw new Error('Picto not found');
} }
PictoTagSup.create({ PictoTag.create({
tag: params.tag, tag: params.tag,
lang: params.lang, lang: params.lang,
picto: picto.id, picto: picto.id,
supervisor: supervisor.id supervisor: supervisor.id
}).then(function (pictoTagSup) { }).then(function (pictoTag) {
if (pictoTagSup) { if (pictoTag) {
res.ok(pictoTagSup); res.ok(pictoTag);
} else { } else {
res.serverError(); res.serverError();
} }
...@@ -153,16 +153,19 @@ module.exports = { ...@@ -153,16 +153,19 @@ module.exports = {
/** /**
* Removes a picto tag created by the supervisor * 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 {} * @param {response} res {}
*/ */
del_tag: function (req, res) { del_tag: function (req, res) {
var params = req.params.all(); var params = req.params.all();
if (!params.id_tag) { if (!params.id_tag || !params.id_sup) {
res.badRequest(); res.badRequest();
} else { } else {
PictoTagSup.destroy({ id: params.id_tag }).then(function () { PictoTag.destroy({ id: params.id_tag, id_sup: params.id_sup }).then(function () {
res.ok(); res.ok();
}) })
.catch(function () { .catch(function () {
...@@ -171,17 +174,26 @@ module.exports = { ...@@ -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) { destroy: function(req, res) {
var params = req.params.all(); var params = req.params.all();
if (!params.id) { if (!params.id) {
return res.json(500, {error: "No id picto defined"}); res.badRequest();
} } else {
Picto.update({ id: params.id }, { owner: null}).exec(function (err, updated) { Picto.update({ id: params.id }, { owner: null}).then(function (updated) {
if (err) throw err; res.ok(updated[0]);
return res.json(updated[0]); })
}); .catch(function() {
res.serverError();
});
}
}, },
/** /**
......
/* global Student, PictoCoreCat, VStuLastInstruction, StuPicto, StuSup, sailsTokenAuth, sails, /* global Student, PictoCore, VStuLastInstruction, StuPicto, StuSup, sailsTokenAuth, sails,
Picto */ Picto */
/** /**
...@@ -41,7 +41,6 @@ module.exports = { ...@@ -41,7 +41,6 @@ module.exports = {
*/ */
login: function (req, res) { login: function (req, res) {
var bcrypt = require('bcrypt-nodejs'); var bcrypt = require('bcrypt-nodejs');
Student.findOne({ Student.findOne({
username: req.body.username username: req.body.username
}) })
...@@ -113,7 +112,7 @@ module.exports = { ...@@ -113,7 +112,7 @@ module.exports = {
} }
res.ok(student); res.ok(student);
}) })
.catch(function () { .catch(function (error) {
res.serverError(); res.serverError();
}); });
} else { } else {
...@@ -141,34 +140,34 @@ module.exports = { ...@@ -141,34 +140,34 @@ module.exports = {
sails.log.debug('Student ' + created.id + ' created: ' + JSON.stringify(created)); sails.log.debug('Student ' + created.id + ' created: ' + JSON.stringify(created));
// Assign the initial collection of pictos to the student // Assign the initial collection of pictos to the student
PictoCoreCat.find() PictoCore.find()
.exec(function (pictoCoreCatError, pictoCoreCat) { .exec(function (pictoCoreError, pictoCore) {
var i; var i;
if (pictoCoreCatError || !pictoCoreCat || pictoCoreCat.length === 0) { if (pictoCoreError || !pictoCore || pictoCore.length === 0) {
sails.log.debug('PictoCoreCat: ' + pictoCoreCatError); sails.log.debug('PictoCore: ' + pictoCoreError);
return; return;
} }
sails.log.debug('PictoCoreCat Length: ' + pictoCoreCat.length); sails.log.debug('PictoCore Length: ' + pictoCore.length);
sails.log.debug(pictoCoreCat); sails.log.debug(pictoCore);
// Every picto from 'picto_core_cat' is going to be created // Every picto from 'picto_core_cat' is going to be created
// in 'stu_picto' // 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('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); sails.log.debug('User id: ' + created.id);
StuPicto.create({ StuPicto.create({
student: created.id, student: created.id,
picto: pictoCoreCat[i].picto, picto: pictoCore[i].picto,
attributes: { attributes: {
id_cat: pictoCoreCat[i].category, id_cat: pictoCore[i].category,
coord_x: pictoCoreCat[i].coord_x, coord_x: pictoCore[i].coord_x,
coord_y: pictoCoreCat[i].coord_y, coord_y: pictoCore[i].coord_y,
status: 'invisible', // Default, the pictos don't appear to the user status: 'invisible', // Default, the pictos don't appear to the user
color: pictoCoreCat[i].color color: pictoCore[i].color
} }
}) })
.exec(function (stuPictoError, added) { .exec(function (stuPictoError, added) {
...@@ -217,34 +216,30 @@ module.exports = { ...@@ -217,34 +216,30 @@ module.exports = {
// Updates student information // Updates student information
// //
update: function (req, res) { update: function (req, res) {
if (!req.params.id_stu) { if (!req.params.id_stu) {
return res.json(500, { res.badRequest();
error: 'No student defined'
});
} }
Student.findOne(req.params.id_stu)
.exec(function (err, stu) {
var k;
if (err || !stu)
return res.json(500, {
error: "No student found"
});
if (!req.body.password) { Student.findOne(req.params.id_stu).then(function(stu) {
delete req.body.password; var k;
}
// copy attributes // copy attributes
for (k in req.body) stu[k] = req.body[k]; for (k in req.body) stu[k] = req.body[k];
stu.save(function (stuSaveError, saved) {
if (stuSaveError) { if (!req.body.password) // to avoid change password when no one is provided
return res.json(500, { delete stu.password;
error: 'Error when saving student'
}); stu.save().then(function (saved) {
} res.ok(stu);
return res.json(stu); })
}); .catch(function(err) {
res.severError();
}); });
})
.catch(function (err) {
res.notFound();
});
}, },
...@@ -947,26 +942,13 @@ module.exports = { ...@@ -947,26 +942,13 @@ module.exports = {
var action = req.param('action'); var action = req.param('action');
var attributes = req.param('attributes'); var attributes = req.param('attributes');
var roomName = 'studentRoom' + attributes.id_stu;
sails.log.debug("Inside /stu/subscribe. Action: " + action);
if (req.isSocket) { if (req.isSocket) {
sails.log.debug("Inside /stu/subscribe - isSocket"); sails.hooks.rooms.subscribeToRoom(
sails.sockets.join(req.socket, roomName); sails.hooks.rooms.student(attributes.id_stu),
sails.io.sockets.in(roomName) req.socket
.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
});
} }
res.ok({msg: "Subscribed to student "});
}, },
// //
...@@ -976,10 +958,7 @@ module.exports = { ...@@ -976,10 +958,7 @@ module.exports = {
var action = req.param('action'); var action = req.param('action');
//var attributes = req.param('attributes'); //var attributes = req.param('attributes');
sails.log.debug("Inside /stu/unsubscribe. Action: " + action);
if (req.isSocket) { if (req.isSocket) {
sails.log.debug("Inside /stu/unsubscribe - isSocket");
var rooms = sails.sockets.socketRooms(req.socket); var rooms = sails.sockets.socketRooms(req.socket);
console.log("Subscribed rooms in socket: " + JSON.stringify(rooms)); console.log("Subscribed rooms in socket: " + JSON.stringify(rooms));
...@@ -1027,17 +1006,18 @@ module.exports = { ...@@ -1027,17 +1006,18 @@ module.exports = {
action: function (req, res) { action: function (req, res) {
var action = req.param('action'); var action = req.param('action');
var attributes = req.param('attributes'); var attributes = req.param('attributes');
var roomName = 'studentRoom' + attributes.id_stu;
sails.log.debug("Inside action. Student:" + attributes.id_stu); sails.log.debug("Inside action. Student:" + attributes.id_stu);
if (req.isSocket) { if (req.isSocket) {
sails.log.debug("websockets - room " + roomName); sails.log.debug("websockets - room " + sails.hooks.rooms.student(attributes.id_stu));
// BROADCAST to everyone subscribed to this student // BROADCAST to everyone subscribed to this student
sails.sockets.broadcast(roomName, 'action', { const socketToOmit = (req.isSocket) ? req.socket : undefined;
"action": action, sails.hooks.events.broadcastEvent(
"attributes": attributes sails.hooks.rooms.student(attributes.id_stu),
}); sails.hooks.events.actionPerformed(action, attributes),
socketToOmit
);
var sup = null; var sup = null;
if (attributes.supervisor) sup = attributes.supervisor; if (attributes.supervisor) sup = attributes.supervisor;
...@@ -1054,8 +1034,10 @@ module.exports = { ...@@ -1054,8 +1034,10 @@ module.exports = {
description: desc description: desc
}) })
.exec(function (err, created) { .exec(function (err, created) {
if (err) if (err) {
sails.log.error(err.details);
res.serverError(err.details); res.serverError(err.details);
}
else if (created) else if (created)
res.json({ res.json({
action: created action: created
...@@ -1067,6 +1049,8 @@ module.exports = { ...@@ -1067,6 +1049,8 @@ module.exports = {
msg: "Action "+ action +" action from student " + attributes.id_stu msg: "Action "+ action +" action from student " + attributes.id_stu
}); });
*/ */
} else {
sails.log.debug("No socket request for action");
} }
}, },
...@@ -1077,20 +1061,21 @@ module.exports = { ...@@ -1077,20 +1061,21 @@ module.exports = {
config: function (req, res) { config: function (req, res) {
var action = req.param('action'); var action = req.param('action');
var attributes = req.param('attributes'); var attributes = req.param('attributes');
var roomName = 'studentRoom' + attributes.id_stu;
sails.log.debug("Inside config"); sails.log.debug("Inside config");
if (req.isSocket) { if (req.isSocket) {
sails.log.debug("Inside config - isSocket"); const socketToOmit = (req.isSocket) ? req.socket : undefined;
sails.hooks.events.broadcastEvent(
sails.sockets.broadcast(roomName, 'config', { sails.hooks.rooms.student(attributes.id_stu),
"action": action, 'action',
"attributes": attributes {
}); "action": action,
"attributes": attributes
res.json({ },
socketToOmit
);
} else {
res.ok({
msg: "Config " + action + " action from student " + attributes.id_stu 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 // @TODO 357
module.exports = { module.exports = {
// create action // create action
// adds a try // adds a try
// //
create: function(req, res) { create: function(req, res) {
var params = req.allParams(); var params = req.allParams();
if (!params.ws) return res.json(500, {error: "No workingSession defined"}); if (!params.ws) return res.json(500, {error: "No workingSession defined"});
if (!params.begin) return res.json(500, {error: "No begin defined"}); if (!params.begin) return res.json(500, {error: "No begin defined"});
if (!params.end) return res.json(500, {error: "No end defined"}); if (!params.end) return res.json(500, {error: "No end defined"});
if (!params.actions) return res.json(500, {error: "No actions in try defined"}); if (!params.actions) return res.json(500, {error: "No actions in try defined"});
if (!params.supervisor) return res.json(500, {error: "No supervisor in try defined"}); if (!params.supervisor) return res.json(500, {error: "No supervisor in try defined"});
if (!params.student) return res.json(500, {error: "No student in try defined"}); if (!params.student) return res.json(500, {error: "No student in try defined"});
Try.create({ Try.create({
"workingSession":params.ws, "workingSession":params.ws,
"begin": params.begin, "begin": params.begin,
"end": params.end "end": params.end
}).exec(function(err, tr){ }).exec(function(err, tr){
if(err || !tr){ if(err || !tr){
sails.log.debug("Creating new Try: " + err); sails.log.debug("Creating new Try: " + err);
return res.json(500, {error: 'Try not created'}); return res.json(500, {error: 'Try not created'});
} }
if(tr){ if(tr){
var l_actions = []; var l_actions = [];
// with .eachSeries the order of resulting array will be equal // with .eachSeries the order of resulting array will be equal
// to the original array // to the original array
async.eachSeries(params.actions, function(a, callback) { async.eachSeries(params.actions, function(a, callback) {
sails.log.debug("Loop adding actions: " + a.action + " to try " + tr.id); sails.log.debug("Loop adding actions: " + a.action + " to try " + tr.id);
var desc = null; var desc = null;
if(a.attributes.picto) desc = a.attributes.picto; // select, add and delete actions data if(a.attributes.picto) desc = a.attributes.picto; // select, add and delete actions data
if(a.attributes.pictos) desc = a.attributes.pictos; // show action data if(a.attributes.pictos) desc = a.attributes.pictos; // show action data
Action.create({ Action.create({
type: a.action, type: a.action,
timestamp: a.attributes.timestamp, timestamp: a.attributes.timestamp,
supervisor: params.supervisor, supervisor: params.supervisor,
student: params.student, student: params.student,
description: desc, description: desc,
_try: tr.id _try: tr.id
}).exec(function(err, action){ }).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new "+ a.action +" action: " + err); if(err || !action) sails.log.debug("Creating new "+ a.action +" action: " + err);
if(action){ if(action){
sails.log.debug("Action Created: " + action.type); sails.log.debug("Action Created: " + action.type);
l_actions.push(action); l_actions.push(action);
} }
callback(); callback();
}); });
// Finish function when each callback is done // Finish function when each callback is done
// Optionaly it can be passed and err parameter // Optionaly it can be passed and err parameter
}, function(err){ }, function(err){
if( err ) { if( err ) {
// One of the iterations produced an error. // One of the iterations produced an error.
// All processing will now stop. // All processing will now stop.
console.log('An error ocurred with an action'); console.log('An error ocurred with an action');
} else { } else {
console.log('All actions have been processed successfully'); console.log('All actions have been processed successfully');
// Return the try // Return the try
// with the array of actions // with the array of actions
return res.json({ return res.json({
"id": tr.id, "id": tr.id,
"workingSession": tr.workingSession, "workingSession": tr.workingSession,
"begin": tr.begin, "begin": tr.begin,
"end": tr.end, "end": tr.end,
"actions": l_actions "actions": l_actions
}); });
} }
}); });
/* /*
// InitSession Action // InitSession Action
Action.create({ Action.create({
"type": "InitSession", "type": "InitSession",
"timestamp": ws.begin, "timestamp": ws.begin,
"supervisor": ws.supervisor, "supervisor": ws.supervisor,
"student": ws.student, "student": ws.student,
}).exec(function(err, action){ }).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new Action InitSession: " + err); if(err || !action) sails.log.debug("Creating new Action InitSession: " + err);
if(action) sails.log.debug("Created Action: " + action.type); if(action) sails.log.debug("Created Action: " + action.type);
}); });
// TryInit Action // TryInit Action
Action.create({ Action.create({
"type": "TryInit", "type": "TryInit",
"timestamp": ws.begin, "timestamp": ws.begin,
"supervisor": ws.supervisor, "supervisor": ws.supervisor,
"student": ws.student, "student": ws.student,
"_try": tr.id "_try": tr.id
}).exec(function(err, action){ }).exec(function(err, action){
if(err || !action) sails.log.debug("Creating new Action TryInit: " + err); if(err || !action) sails.log.debug("Creating new Action TryInit: " + err);
if(action){ if(action){
sails.log.debug("Created Action: " + action.type); sails.log.debug("Created Action: " + action.type);
// Return the working session created // Return the working session created
// with the array of one try (the first) // with the array of one try (the first)
// with the array of one action (the first too) // with the array of one action (the first too)
return res.json({ return res.json({
"id": ws.id, "id": ws.id,
"begin": ws.begin, "begin": ws.begin,
"student": ws.student, "student": ws.student,
"supervisor": ws.supervisor, "supervisor": ws.supervisor,
"tries": [ "tries": [
{ {
"id": tr.id, "id": tr.id,
"instruction": tr.instruction, "instruction": tr.instruction,
"begin": tr.begin, "begin": tr.begin,
"workingSession": tr.workingSession, "workingSession": tr.workingSession,
"actions": [ action ] "actions": [ action ]
} }
] ]
}); });
} }
}); });
*/ */
} }
}); });
} }
}; };
// @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
});
}
}
);
}
}
);
}
};
...@@ -7,246 +7,246 @@ ...@@ -7,246 +7,246 @@
module.exports = { module.exports = {
// //
//close action //close action
// close a WS // close a WS
// //
close: function(req, res) { close: function(req, res) {
if (!req.params.id_ws) return res.json(500, {error: "No working session defined"}); if (!req.params.id_ws) return res.json(500, {error: "No working session defined"});
StuOpenTry.findOne( { id_ws : req.params.id_ws } ).exec(function(err, t) { StuOpenTry.findOne( { id_ws : req.params.id_ws } ).exec(function(err, t) {
if (err) { if (err) {
sails.log.error("Error Recovering from ws "+err); sails.log.error("Error Recovering from ws "+err);
return res.json(500, {error: 'recovering from ws:'+err}); return res.json(500, {error: 'recovering from ws:'+err});
} }
if(t && t.openTry!=null) /*WS recovery*/ { if(t && t.openTry!=null) /*WS recovery*/ {
sails.log.debug("Recovering WS required for WS "+req.params.id_ws); sails.log.debug("Recovering WS required for WS "+req.params.id_ws);
var ws_end; var ws_end;
if (t.end==null) ws_end = t.begin; if (t.end==null) ws_end = t.begin;
else ws_end = t.end; else ws_end = t.end;
WorkingSession.update({id: t.id_ws}, {end: ws_end.toISOString()}).exec(function(err,u) { WorkingSession.update({id: t.id_ws}, {end: ws_end.toISOString()}).exec(function(err,u) {
if (err) { if (err) {
sails.log.error("Error updating no closed WS " + t.id_ws); sails.log.error("Error updating no closed WS " + t.id_ws);
return res.json(500, {error: 'Working Session could not be closed'}); return res.json(500, {error: 'Working Session could not be closed'});
}}); }});
return res.json(200, {end: ws_end.toISOString()}); return res.json(200, {end: ws_end.toISOString()});
} }
else else
return res.json(200, {result:'no recovery required'}); return res.json(200, {result:'no recovery required'});
}); });
}, },
// create action // create action
// adds a working session and a InitSession action // adds a working session and a InitSession action
// //
// @TODO 357 // @TODO 357
create: function(req, res) { create: function(req, res) {
var params = req.allParams(); var params = req.allParams();
if (!params.id_sup) return res.json(500, {error: "No supervisor defined"}); if (!params.id_sup) return res.json(500, {error: "No supervisor defined"});
if (!params.id_ins) return res.json(500, {error: "No instruction defined"}); if (!params.id_ins) return res.json(500, {error: "No instruction defined"});
if (!params.id_stu) return res.json(500, {error: "No student defined"}); if (!params.id_stu) return res.json(500, {error: "No student defined"});
if (!params.desc) params.desc = ""; if (!params.desc) params.desc = "";
var data = {}; var data = {};
data.supervisor = params.id_sup; data.supervisor = params.id_sup;
data.instruction = params.id_ins; data.instruction = params.id_ins;
data.description = params.desc; data.description = params.desc;
StuOpenTry.findOne( {or: [ StuOpenTry.findOne( {or: [
{ id_sup : params.id_sup }, { id_sup : params.id_sup },
{ id_stu : params.id_stu } { id_stu : params.id_stu }
]} ).exec(function(err, t) { ]} ).exec(function(err, t) {
if (err) { if (err) {
sails.log.error("Error Recovering from ws "+err); sails.log.error("Error Recovering from ws "+err);
return res.json(500, {error: 'recovering from ws:'+err}); return res.json(500, {error: 'recovering from ws:'+err});
} }
if(!t || t.openTry==null) //WS closed correctly if(!t || t.openTry==null) //WS closed correctly
WorkingSession.create(data).exec(function(err, ws){ WorkingSession.create(data).exec(function(err, ws){
if(err || !ws){ if(err || !ws){
sails.log.error("Creating new Working Sesion error "+err); sails.log.error("Creating new Working Sesion error "+err);
return res.json(500, {error: 'Working Session not created'}); return res.json(500, {error: 'Working Session not created'});
} }
// Create the InitSession Action // Create the InitSession Action
Action.create({ Action.create({
"type": "initsession", "type": "initsession",
"timestamp": ws.begin, "timestamp": ws.begin,
"supervisor": ws.supervisor, "supervisor": ws.supervisor,
"student": params.id_stu "student": params.id_stu
}).exec(function(err, action){ }).exec(function(err, action){
if(err || !action) { if(err || !action) {
sails.log.error("Creating initial action for new Working Sesion. Error "+err); sails.log.error("Creating initial action for new Working Sesion. Error "+err);
return res.json(500, {error: 'Working Session not created'}); return res.json(500, {error: 'Working Session not created'});
} }
StuOpenTry.findOne( {id_stu : params.id_stu } ).exec(function(err, t) { StuOpenTry.findOne( {id_stu : params.id_stu } ).exec(function(err, t) {
if (err) { if (err) {
sails.log.error("Error Recovering from ws "+err); sails.log.error("Error Recovering from ws "+err);
return res.json(500, {error: 'recovering from ws:'+err}); return res.json(500, {error: 'recovering from ws:'+err});
} }
// Return the working session and try created // Return the working session and try created
sails.log.debug("Initial action for new Working Sesion "+JSON.stringify(ws)+". Action:"+JSON.stringify(action)); sails.log.debug("Initial action for new Working Sesion "+JSON.stringify(ws)+". Action:"+JSON.stringify(action));
return res.json({ return res.json({
"id": ws.id, "id": ws.id,
"first_try_id":t.openTry, "first_try_id":t.openTry,
"recovered_ws": null "recovered_ws": null
}) })
}) })
}); });
}); });
else { //Not closed previous WS must be recovered and closed else { //Not closed previous WS must be recovered and closed
sails.log.debug("Recovering WS required for student "+params.id_stu); sails.log.debug("Recovering WS required for student "+params.id_stu);
var ws_end; var ws_end;
if (t.end==null) ws_end = t.begin; if (t.end==null) ws_end = t.begin;
else ws_end = t.end; else ws_end = t.end;
WorkingSession.update({id: t.id_ws}, {end: ws_end.toISOString()}).exec(function(err,u) { WorkingSession.update({id: t.id_ws}, {end: ws_end.toISOString()}).exec(function(err,u) {
if (err) { if (err) {
sails.log.error("Error updating no closed WS " + t.id_ws); sails.log.error("Error updating no closed WS " + t.id_ws);
return res.json(500, {error: 'Working Session not created'}); return res.json(500, {error: 'Working Session not created'});
} }
WorkingSession.create(data).exec(function(err, ws){ WorkingSession.create(data).exec(function(err, ws){
if(err || !ws){ if(err || !ws){
sails.log.error("Creating new Working Sesion error "+err); sails.log.error("Creating new Working Sesion error "+err);
return res.json(500, {error: 'Working Session not created'}); return res.json(500, {error: 'Working Session not created'});
} }
// Create the InitSession Action // Create the InitSession Action
Action.create({ Action.create({
"type": "initsession", "type": "initsession",
"timestamp": ws.begin, "timestamp": ws.begin,
"supervisor": ws.supervisor, "supervisor": ws.supervisor,
"student": params.id_stu "student": params.id_stu
}).exec(function(err, action){ }).exec(function(err, action){
if(err || !action) { if(err || !action) {
sails.log.error("Creating initial action for new Working Sesion. Error "+err); sails.log.error("Creating initial action for new Working Sesion. Error "+err);
return res.json(500, {error: 'Working Session not created'}); return res.json(500, {error: 'Working Session not created'});
} }
StuOpenTry.findOne( {id_stu : params.id_stu} ).exec(function(err, t) { StuOpenTry.findOne( {id_stu : params.id_stu} ).exec(function(err, t) {
if (err) { if (err) {
sails.log.error("Error Recovering from ws "+err); sails.log.error("Error Recovering from ws "+err);
return res.json(500, {error: 'recovering from ws:'+err}); return res.json(500, {error: 'recovering from ws:'+err});
} }
// Return the working session and try created // Return the working session and try created
sails.log.debug("Initial action for new Working Sesion "+JSON.stringify(action)); sails.log.debug("Initial action for new Working Sesion "+JSON.stringify(action));
return res.json({ return res.json({
"id": ws.id, "id": ws.id,
"first_try_id":t.openTry, "first_try_id":t.openTry,
"recovered_ws": null "recovered_ws": null
}) })
}) })
}); });
}); });
}); });
} }
}); });
}, },
// update action // update action
// ends a working session and a creates an EndSession action // ends a working session and a creates an EndSession action
// //
// @TODO 357 // @TODO 357
update: function(req, res) { update: function(req, res) {
var params = req.allParams(); var params = req.allParams();
WorkingSession.update({id:params.id}, params).exec(function(err, ws){ WorkingSession.update({id:params.id}, params).exec(function(err, ws){
if(err || !ws){ if(err || !ws){
sails.log.error("Updating Working Sesion error: " + err); sails.log.error("Updating Working Sesion error: " + err);
return res.json(500, {error: 'Working Session not updated'}); return res.json(500, {error: 'Working Session not updated'});
} }
sails.log.debug("Working session updated: " + JSON.stringify(ws[0])); sails.log.debug("Working session updated: " + JSON.stringify(ws[0]));
if(params.end!=null){ //Closing WS if(params.end!=null){ //Closing WS
// Create the EndSession Action // Create the EndSession Action
Action.create({ Action.create({
"type": "endsession", "type": "endsession",
"timestamp": ws[0].end, "timestamp": ws[0].end,
"supervisor": ws[0].supervisor, "supervisor": ws[0].supervisor,
"student": params.id_stu "student": params.id_stu
}).exec(function(err, action){ }).exec(function(err, action){
if(err || !action) { if(err || !action) {
sails.log.debug("Error creating new Action EndSession: " + err); sails.log.debug("Error creating new Action EndSession: " + err);
return res.json(500, {error: 'Working Session not updated'}); return res.json(500, {error: 'Working Session not updated'});
} }
}); });
// Implementation of Integrity rule #8 for sessions management // Implementation of Integrity rule #8 for sessions management
Try.findOne( { id_ws : params.id } ).exec(function(err, t) { //Deleting empty WS (no tries) Try.findOne( { id_ws : params.id } ).exec(function(err, t) { //Deleting empty WS (no tries)
if (err) { if (err) {
sails.log.error("Error Recovering from ws "+err); sails.log.error("Error Recovering from ws "+err);
return res.json(500, {error: 'recovering from ws:'+err}); return res.json(500, {error: 'recovering from ws:'+err});
} }
if (typeof(t) == 'undefined') /*Empty WS must be deleted*/{ if (typeof(t) == 'undefined') /*Empty WS must be deleted*/{
sails.log.debug("Empty WS to be deleted, id: "+params.id); sails.log.debug("Empty WS to be deleted, id: "+params.id);
WorkingSession.destroy({id: params.id}).exec(function(err,u) { WorkingSession.destroy({id: params.id}).exec(function(err,u) {
if (err) { if (err) {
sails.log.error("Error deleting empty WS (no tries) " + t.id_ws); sails.log.error("Error deleting empty WS (no tries) " + t.id_ws);
return res.json(500, {error: 'Error deleting empty WS (no tries)'}); return res.json(500, {error: 'Error deleting empty WS (no tries)'});
}}); }});
} }
}); });
} }
// Return the working session updated // Return the working session updated
return res.json(ws); return res.json(ws);
}); });
}, },
// //
// Returns the number of working sessions per year (REPORTS) // Returns the number of working sessions per year (REPORTS)
// //
per_year: function(req, res) { per_year: function(req, res) {
if (!req.params.id_stu) if (!req.params.id_stu)
return res.json(500, {error: "No student defined"}); return res.json(500, {error: "No student defined"});
if (!req.params.year) if (!req.params.year)
return res.json(500, {error: "No year defined"}); return res.json(500, {error: "No year defined"});
WorkingSession.per_year(req.params.id_stu, req.params.year, function(err, l_ws) { WorkingSession.per_year(req.params.id_stu, req.params.year, function(err, l_ws) {
if (err) throw err; if (err) throw err;
return res.json(l_ws); return res.json(l_ws);
}); });
}, },
// //
// Returns the number of working sessions per month (REPORTS) // Returns the number of working sessions per month (REPORTS)
// //
per_month: function(req, res) { per_month: function(req, res) {
if (!req.params.id_stu) if (!req.params.id_stu)
return res.json(500, {error: "No student defined"}); return res.json(500, {error: "No student defined"});
if (!req.params.month) if (!req.params.month)
return res.json(500, {error: "No month defined"}); return res.json(500, {error: "No month defined"});
WorkingSession.per_month(req.params.id_stu, req.params.month, function(err, l_ws) { WorkingSession.per_month(req.params.id_stu, req.params.month, function(err, l_ws) {
if (err) throw err; if (err) throw err;
return res.json(l_ws); return res.json(l_ws);
}); });
}, },
// //
// Returns all tries for the given instruction // Returns all tries for the given instruction
// //
// @TODO 357 // @TODO 357
tries: function(req, res) { tries: function(req, res) {
if (!req.params.id_ws) { if (!req.params.id_ws) {
return res.json(500, {error: "No working session defined"}); return res.json(500, {error: "No working session defined"});
} }
Try.find({ Try.find({
WorkingSession: req.params.id_ws, // With this working session id WorkingSession: req.params.id_ws, // With this working session id
or : [ or : [
{ result: null }, // This is necessary here because it's not enough with the following query to recover null results { result: null }, // This is necessary here because it's not enough with the following query to recover null results
{ result: { '!' : ['BROKEN', 'DISCARDED'] }} // And without this results { result: { '!' : ['BROKEN', 'DISCARDED'] }} // And without this results
] ]
}).populate('actions').exec(function(err, tries) { }).populate('actions').exec(function(err, tries) {
if (err) throw err; if (err) throw err;
if(!tries || tries.length == 0) return res.json([]); // Empty array of tries if(!tries || tries.length == 0) return res.json([]); // Empty array of tries
else return res.json(tries); else return res.json(tries);
}); });
}, },
}; };
...@@ -100,6 +100,23 @@ module.exports = function eventsHook(sails) { ...@@ -100,6 +100,23 @@ module.exports = function eventsHook(sails) {
count: subscriberCount count: subscriberCount
} }
}; };
},
/**
* A new action is performed by the user in the tablet
* @param {action} type of the action
* @param {attributes} attributes of the action (e.g. picto attributes when
* clicking on it)
* @return {Object} {name, data}
*/
actionPerformed: function (action, attributes) {
return {
name: 'action',
data: {
action: action,
attributes: attributes
}
};
} }
}; };
}; };
/**
* 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 = { ...@@ -52,10 +52,6 @@ module.exports = {
collection: 'PictoTag', collection: 'PictoTag',
via: 'picto' via: 'picto'
}, },
tagsSup: {
collection: 'PictoTagSup',
via: 'picto'
},
pictoAcls: { // 1 Picto to N PictoAcl pictoAcls: { // 1 Picto to N PictoAcl
collection: 'PictoAcl', collection: 'PictoAcl',
via: 'picto' via: 'picto'
......
/** /**
* PictoAcl.js * 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 * @docs :: http://sailsjs.org/#!documentation/models
*/ */
...@@ -12,7 +12,7 @@ module.exports = { ...@@ -12,7 +12,7 @@ module.exports = {
autoPK : false, autoPK : false,
autoCreatedAt : false, autoCreatedAt : false,
autoUpdatedAt : false, autoUpdatedAt : false,
attributes: { attributes: {
id: { id: {
type: "integer", type: "integer",
...@@ -41,4 +41,4 @@ module.exports = { ...@@ -41,4 +41,4 @@ module.exports = {
type: "datetime" type: "datetime"
} }
} }
}; };
\ No newline at end of file
...@@ -12,7 +12,7 @@ module.exports = { ...@@ -12,7 +12,7 @@ module.exports = {
autoPK : false, autoPK : false,
autoCreatedAt : false, autoCreatedAt : false,
autoUpdatedAt : false, autoUpdatedAt : false,
attributes: { attributes: {
id: { id: {
type: "integer", type: "integer",
...@@ -26,6 +26,12 @@ module.exports = { ...@@ -26,6 +26,12 @@ module.exports = {
required: true, required: true,
model: 'Picto' model: 'Picto'
}, },
category: {
columnName: 'id_cat_pic',
type: 'integer',
required: false,
model: 'Picto'
},
coord_x: { coord_x: {
type: 'integer', type: 'integer',
required: false required: false
...@@ -40,4 +46,3 @@ module.exports = { ...@@ -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 = { ...@@ -12,7 +12,7 @@ module.exports = {
autoPK : false, autoPK : false,
autoCreatedAt : false, autoCreatedAt : false,
autoUpdatedAt : false, autoUpdatedAt : false,
attributes: { attributes: {
id: { id: {
type: "integer", type: "integer",
...@@ -26,6 +26,12 @@ module.exports = { ...@@ -26,6 +26,12 @@ module.exports = {
type: "integer", type: "integer",
model: "Picto" 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 tag: { // FK de Tag. 1 a N
columnName: "tag", columnName: "tag",
required: true, required: true,
...@@ -39,4 +45,4 @@ module.exports = { ...@@ -39,4 +45,4 @@ module.exports = {
required: true 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 * 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 * @docs :: http://sailsjs.org/#!documentation/models
*/ */
module.exports = { module.exports = {
...@@ -11,7 +14,7 @@ module.exports = { ...@@ -11,7 +14,7 @@ module.exports = {
autoPK : false, autoPK : false,
autoCreatedAt : false, autoCreatedAt : false,
autoUpdatedAt : false, autoUpdatedAt : false,
attributes: { attributes: {
id: { id: {
type: "integer", type: "integer",
...@@ -25,25 +28,25 @@ module.exports = { ...@@ -25,25 +28,25 @@ module.exports = {
id_sup: { id_sup: {
type: "integer", type: "integer",
}, },
id_ws: { id_ws: {
type: "integer", type: "integer",
}, },
openTry: { openTry: {
columnName: "id_opentry", columnName: "id_opentry",
type: "integer", type: "integer",
unique: true unique: true
}, },
total_tries: { total_tries: {
columnName: "total_tries", columnName: "total_tries",
type: "integer", type: "integer",
}, },
begin: { begin: {
columnName: "begin", columnName: "begin",
type: "datetime", type: "datetime",
}, },
end: { end: {
columnName: "end", columnName: "end",
type: "datetime", type: "datetime",
} }
} }
} }
\ No newline at end of file
...@@ -240,7 +240,10 @@ module.exports = { ...@@ -240,7 +240,10 @@ module.exports = {
beforeUpdate: function (attrs, next) { beforeUpdate: function (attrs, next) {
delete attrs.username; delete attrs.username;
attrs.attributes = Student.getValidAttributes(attrs.attributes); attrs.attributes = Student.getValidAttributes(attrs.attributes);
attrs.password = bcrypt.hashSync(attrs.password, bcrypt.genSaltSync()); if (attrs.password) {
sails.log.debug('password changed');
attrs.password = bcrypt.hashSync(attrs.password, bcrypt.genSaltSync());
}
next(); next();
}, },
......
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
"enlarge": "Enlarge", "enlarge": "Enlarge",
"enormous": "Enormous", "enormous": "Enormous",
"error_adding_picto": "Error adding picto", "error_adding_picto": "Error adding picto",
"error_deleting_picto": "Error deleting picto",
"error_downloading_supervisors": "Error downloading supervisors", "error_downloading_supervisors": "Error downloading supervisors",
"error_downloading_offices": "Error downloading offices", "error_downloading_offices": "Error downloading offices",
"error_only_support_images": "Only images are supported (JPG, PNG or GIF files)", "error_only_support_images": "Only images are supported (JPG, PNG or GIF files)",
...@@ -249,6 +250,7 @@ ...@@ -249,6 +250,7 @@
"supervisor_updated": "Supervisor updated", "supervisor_updated": "Supervisor updated",
"supervisors": "Therapist", "supervisors": "Therapist",
"surname": "Surname", "surname": "Surname",
"tag_deleted": "Tag deleted",
"tape_background": "Tape background", "tape_background": "Tape background",
"time_instruction_method": "Time instructions of method", "time_instruction_method": "Time instructions of method",
"time_hours": "Time: {{hours}} hours", "time_hours": "Time: {{hours}} hours",
......
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
"expand_navigation": "Desplegar navegación", "expand_navigation": "Desplegar navegación",
"expression": "Expresión:", "expression": "Expresión:",
"error_adding_picto": "Error al añadir el picto", "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_supervisors": "Error al descargar los supervisores",
"error_downloading_offices": "Error al descargar las oficinas", "error_downloading_offices": "Error al descargar las oficinas",
"error_only_support_images": "Sólo se soportan imágenes (ficheros JPG, PNG o GIF)", "error_only_support_images": "Sólo se soportan imágenes (ficheros JPG, PNG o GIF)",
...@@ -250,6 +251,7 @@ ...@@ -250,6 +251,7 @@
"supervisor_updated": "Supervisor actualizado", "supervisor_updated": "Supervisor actualizado",
"supervisors": "Terapeutas", "supervisors": "Terapeutas",
"surname": "Apellidos", "surname": "Apellidos",
"tag_deleted": "Etiqueta borrada",
"tape_background": "Fondo de la cinta", "tape_background": "Fondo de la cinta",
"time_hours": "Tiempo: {{hours}} horas", "time_hours": "Tiempo: {{hours}} horas",
"time_instruction_method": "Tiempo instrucciones del método", "time_instruction_method": "Tiempo instrucciones del método",
......
...@@ -180,7 +180,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -180,7 +180,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.close_ws = function (){ $scope.close_ws = function (){
$http $http
.post(config.backend+ '/workingsession/'+$scope.wsessions[0].id+'/close') .post(config.backend+ '/ws/'+$scope.wsessions[0].id+'/close')
.then( .then(
function(data, status, headers, config) { function(data, status, headers, config) {
...@@ -203,7 +203,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -203,7 +203,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.sessionRunning = true; $scope.sessionRunning = true;
$http $http
.post(config.backend+'/workingsession', { .post(config.backend+'/ws', {
"id_sup": $scope.user.id, "id_sup": $scope.user.id,
"id_stu": $scope.studentData.id, "id_stu": $scope.studentData.id,
"id_ins": $scope.selectedIns "id_ins": $scope.selectedIns
...@@ -239,7 +239,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -239,7 +239,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.update_ws = function (ws){ $scope.update_ws = function (ws){
$http $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) { .then(function(data, status, headers, config) {
...@@ -259,7 +259,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr ...@@ -259,7 +259,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$scope.ws.end = new Date(); $scope.ws.end = new Date();
$http $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 "id_stu": $scope.studentData.id
}) })
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
......
...@@ -48,16 +48,20 @@ dashboardControllers.controller('TagsCtrl', function TagsCtrl( ...@@ -48,16 +48,20 @@ dashboardControllers.controller('TagsCtrl', function TagsCtrl(
$scope.tagToAdd = ''; $scope.tagToAdd = '';
}) })
.error(function () { .error(function () {
// TODO show error with ngToast $translate('error_adding_tag').then(function (translation) {
ngToast.danger({ content: translation });
});
}); });
}; };
// Destroy own tag // Destroy own tag
$scope.del = function (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 () { .success(function () {
var i; 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 // Eliminar de la vista: Se recorre el array de objetos json para buscarlo
for (i = 0; i < $scope.ownTags.length; i++) { for (i = 0; i < $scope.ownTags.length; i++) {
if (tag.id === $scope.ownTags[i].id) { if (tag.id === $scope.ownTags[i].id) {
...@@ -66,7 +70,9 @@ dashboardControllers.controller('TagsCtrl', function TagsCtrl( ...@@ -66,7 +70,9 @@ dashboardControllers.controller('TagsCtrl', function TagsCtrl(
} }
}) })
.error(function () { .error(function () {
// TODO show error with ngToast $translate('error_deleting_tag').then(function (translation) {
ngToast.danger({ content: translation });
});
}); });
}; };
......
...@@ -26,7 +26,7 @@ customLogger.add(winston.transports.File, { ...@@ -26,7 +26,7 @@ customLogger.add(winston.transports.File, {
json: true, json: true,
tailable: true, tailable: true,
maxsize: 5 * 1024 * 1024, // 5 MegaByte maxsize: 5 * 1024 * 1024, // 5 MegaByte
filename: path.resolve(__dirname, '..', 'logs', 'silly.json') filename: path.resolve(__dirname, '../..', 'logs', 'silly.json')
}); });
customLogger.add(winston.transports.File, { customLogger.add(winston.transports.File, {
...@@ -39,7 +39,7 @@ customLogger.add(winston.transports.File, { ...@@ -39,7 +39,7 @@ customLogger.add(winston.transports.File, {
json: true, json: true,
tailable: true, tailable: true,
maxsize: 5 * 1024 * 1024, // 5 MegaByte maxsize: 5 * 1024 * 1024, // 5 MegaByte
filename: path.resolve(__dirname, '..', 'logs', 'debug.json') filename: path.resolve(__dirname, '../..', 'logs', 'debug.json')
}); });
customLogger.add(winston.transports.File, { customLogger.add(winston.transports.File, {
...@@ -52,7 +52,7 @@ customLogger.add(winston.transports.File, { ...@@ -52,7 +52,7 @@ customLogger.add(winston.transports.File, {
json: true, json: true,
tailable: true, tailable: true,
maxsize: 5 * 1024 * 1024, // 5 MegaByte maxsize: 5 * 1024 * 1024, // 5 MegaByte
filename: path.resolve(__dirname, '..', 'logs', 'error.json') filename: path.resolve(__dirname, '../..', 'logs', 'error.json')
}); });
module.exports.log = { module.exports.log = {
......
...@@ -50,7 +50,7 @@ module.exports.routes = { ...@@ -50,7 +50,7 @@ module.exports.routes = {
'POST /picto/tag': 'PictoController.add_tag', 'POST /picto/tag': 'PictoController.add_tag',
'POST /picto/exp': 'PictoController.change_exp', 'POST /picto/exp': 'PictoController.change_exp',
'DELETE /picto/:id': 'PictoController.destroy', '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': 'ServerController.ping',
'GET /server/ping_session': 'ServerController.ping_session', 'GET /server/ping_session': 'ServerController.ping_session',
...@@ -103,7 +103,7 @@ module.exports.routes = { ...@@ -103,7 +103,7 @@ module.exports.routes = {
'GET /ws/:id_stu/year/:year': 'WorkingSessionController.per_year', 'GET /ws/:id_stu/year/:year': 'WorkingSessionController.per_year',
'GET /ws/:id_stu/month/:month': 'WorkingSessionController.per_month', 'GET /ws/:id_stu/month/:month': 'WorkingSessionController.per_month',
'GET /ws/:id_ws/tries': 'WorkingSessionController.tries', 'GET /ws/:id_ws/tries': 'WorkingSessionController.tries',
'PUT /workingsession/:id': 'WorkingSessionController.update', 'PUT /ws/:id': 'WorkingSessionController.update',
'POST /workingsession': 'WorkingSessionController.create', 'POST /ws': 'WorkingSessionController.create',
'POST /workingsession/:id_ws/close': 'WorkingSessionController.close' 'POST /ws/:id_ws/close': 'WorkingSessionController.close'
}; };
...@@ -70,9 +70,9 @@ describe('Picto API', function () { ...@@ -70,9 +70,9 @@ describe('Picto API', function () {
.end(done); .end(done);
}); });
}); });
it('DELETE /picto/tag/:id_tag', function (done) { it('DELETE /picto/:id_sup/tag/:id_tag', function (done) {
supervisorAgent supervisorAgent
.delete('/picto/tag/' + 1234) .delete('/picto/'+supervisorAgent.data.id+'/tag/' + 1234)
.send() .send()
.expect(200) .expect(200)
.end(done); .end(done);
......
...@@ -9,13 +9,17 @@ describe('Student API', function () { ...@@ -9,13 +9,17 @@ describe('Student API', function () {
delete studentAgentData.password; delete studentAgentData.password;
studentAgentData.current_method = 'Test Method'; studentAgentData.current_method = 'Test Method';
studentAgentData.current_instruction = 'Test Instruction'; studentAgentData.current_instruction = 'Test Instruction';
supervisorAgent supervisorAgent
.get('/stu/' + studentAgent.data.id) .get('/stu/' + studentAgent.data.id)
.send() .send()
.expect(200) .expect(200)
.expect(studentAgentData) .expect(studentAgentData)
.end(done); .end((error) => {
if (error) {
throw error;
};
done();
});
}); });
it('GET /stu/:id_stu/supervisors', function (done) { it('GET /stu/:id_stu/supervisors', function (done) {
supervisorAgent supervisorAgent
......
...@@ -71,6 +71,7 @@ describe('Supervisor API', function () { ...@@ -71,6 +71,7 @@ describe('Supervisor API', function () {
.expect(200) .expect(200)
.expect(function (response) { .expect(function (response) {
assert.isArray(response.body); assert.isArray(response.body);
assert.isAtLeast(response.body.length, 1, 'category 41 is empty');
response.body.forEach(function (picto) { response.body.forEach(function (picto) {
assert.isObject(picto); assert.isObject(picto);
assert.isNumber(picto.source); assert.isNumber(picto.source);
......
/* eslint-disable no-console */ /* eslint-disable no-console */
var DATABASE_BACKUP_FILE = '/tmp/pictogram_test_backup.sql'; var DATABASE_BACKUP_FILE = '/tmp/pictogram_test_backup.sql';
var DATABASE_RESET_FILE = '../roles/database/files/init-ignoresymbolstix.sql'
var DATABASE_SESSION_TRIGGERS_FILE = '../roles/database/files/triggers-sessions-integrity-constraints.sql'
var DATABASE_ENROLMENT_TRIGGERS_FILE = '../roles/database/files/triggers-enrolments-integrity-constraints.sql'
var DATABASE_TESTDATA_FILE = '../roles/database/files/test-caja.sql'
var UPLOAD_FOLDER; var UPLOAD_FOLDER;
var UPLOAD_FOLDER_BACKUP; var UPLOAD_FOLDER_BACKUP;
var Agent = require('supertest').agent; var Agent = require('supertest').agent;
...@@ -16,14 +20,32 @@ before(function (serverLoadDone) { ...@@ -16,14 +20,32 @@ before(function (serverLoadDone) {
sails = new Sails(); sails = new Sails();
// Backup the whole database // Backup the whole database
console.log('-- Backing up database');
childProcess.execSync('mysqldump -u pictodbuser -pp1KT015 pictodb > ' + DATABASE_BACKUP_FILE); childProcess.execSync('mysqldump -u pictodbuser -pp1KT015 pictodb > ' + DATABASE_BACKUP_FILE);
// Prepare with test data
console.log('-- Preparing test database');
childProcess.execSync('mysql -u pictodbuser -pp1KT015 pictodb < ' + DATABASE_RESET_FILE);
childProcess.execSync('mysql -u pictodbuser -pp1KT015 pictodb < ' + DATABASE_TESTDATA_FILE);
childProcess.execSync('mysql -u pictodbuser -pp1KT015 pictodb < ' + DATABASE_SESSION_TRIGGERS_FILE);
childProcess.execSync('mysql -u pictodbuser -pp1KT015 pictodb < ' + DATABASE_ENROLMENT_TRIGGERS_FILE);
console.log('-- Lifting Sails');
sails.lift({}, function (error) { sails.lift({}, function (error) {
if (error) {
console.log(error.stack);
throw error;
}
console.log('-- Importing bcrypt ');
var bcrypt = require('bcrypt-nodejs'); var bcrypt = require('bcrypt-nodejs');
// Backup the sail's upload folder // Backup the sail's upload folder
UPLOAD_FOLDER = sails.config.pictogram.paths.upload; UPLOAD_FOLDER = sails.config.pictogram.paths.upload;
UPLOAD_FOLDER_BACKUP = UPLOAD_FOLDER + '.backup'; UPLOAD_FOLDER_BACKUP = UPLOAD_FOLDER + '.backup';
console.log('-- Backing up ' + UPLOAD_FOLDER);
childProcess.execSync('cp -r ' + UPLOAD_FOLDER + ' ' + UPLOAD_FOLDER_BACKUP); childProcess.execSync('cp -r ' + UPLOAD_FOLDER + ' ' + UPLOAD_FOLDER_BACKUP);
// Publish chai testing methods // Publish chai testing methods
...@@ -72,9 +94,10 @@ before(function (serverLoadDone) { ...@@ -72,9 +94,10 @@ before(function (serverLoadDone) {
}); });
after(function (done) { after(function (done) {
console.log('-- Restoring backups');
// Restore the database and the upload folder // Restore the database and the upload folder
if (UPLOAD_FOLDER && UPLOAD_FOLDER_BACKUP) { if (UPLOAD_FOLDER && UPLOAD_FOLDER_BACKUP) {
childProcess.execSync('mysql -u pictodbuser -pp1KT015 pictodb < ' + DATABASE_BACKUP_FILE); childProcess.execSync('mysql -u root -proot pictodb < ' + DATABASE_BACKUP_FILE);
childProcess.execSync('rm ' + DATABASE_BACKUP_FILE); childProcess.execSync('rm ' + DATABASE_BACKUP_FILE);
childProcess.execSync('rm -r ' + UPLOAD_FOLDER); childProcess.execSync('rm -r ' + UPLOAD_FOLDER);
childProcess.execSync('mv ' + UPLOAD_FOLDER_BACKUP + ' ' + UPLOAD_FOLDER); childProcess.execSync('mv ' + UPLOAD_FOLDER_BACKUP + ' ' + UPLOAD_FOLDER);
......
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