Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
674fa6da
authored
Apr 11, 2016
by
Pablo Molina
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Eliminados ficheros innecesarios
parent
30012267
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
451 deletions
sails/src/api/policies/#tokenAuth.js#
sails/src/assets/app/modules/student/controllers/#collections.js#
sails/src/api/policies/#tokenAuth.js#
deleted
100644 → 0
View file @
30012267
module.exports = function(req, res, next) {
var token;
//
// Token comes in the header
//
if (req.headers && req.headers.authorization) {
var parts = req.headers.authorization.split(' ');
if (parts.length == 2) {
var scheme = parts[0],
credentials = parts[1];
if (/^Bearer$/i.test(scheme)) {
token = credentials;
}
} else {
return res.json(401, {err: 'Format is Authorization: Bearer [token]'});
}
//
// Token comes as a parameter
//
} else if (req.param('token')) {
token = req.param('token');
// We delete the token from param to not mess with blueprints
delete req.query.token;
: } else {
return res.json(401, {err: 'No Authorization header was found'});
}
//
// We have a token, let's verify it
//
sailsTokenAuth.verifyToken(token, function(err, token) {
if (err) return res.json(401, {err: 'Invalid token'});
req.token = token;
next();
});
};
\ No newline at end of file
sails/src/assets/app/modules/student/controllers/#collections.js#
deleted
100644 → 0
View file @
30012267
'use strict';
//-----------------------
// Student Collections Controller
//-----------------------
dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollectionsCtrl($scope, $stateParams, $http, config, $window, $filter, $modal) {
// For tab navigation (here too, if the user refresh the page...)
$scope.nav.tab = 'collections';
// List of all student pictos
$scope.studentPictos = [];
// List of categories pictos
$scope.pictosCategory = [];
// List of pictos from a catgory
$scope.pictosFromCategory = [];
// The view of pictos: All | Categories
$scope.pictos = {
category: null,
idCat: null
};
// Initialization of PCB (the tablet view) and PCB-Categories
var rows = 5, cols = 10;
$scope.pcb = new Array(); $scope.pcb_cat = new Array();
// Set te empty elements
for (var i=0;i<rows;i++) {
$scope.pcb[i]=new Array(); $scope.pcb_cat[i]=new Array();
for (var j=0;j<cols; j++) {
// Default value
$scope.pcb[i][j]={'picto': {'uri': '/app/img/empty.gif'}, 'attributes': {'coord_x': i, 'coord_y': j}};
$scope.pcb_cat[i][j]={'picto': {'uri': '/app/img/empty.gif'}, 'attributes': {'coord_x': i, 'coord_y': j}};
}
}
$http
.get(config.backend+'/stu/'+ $scope.studentUser.id +'/pictos')
.success(function(data, status, headers, config) {
// Add to list
$scope.studentPictos = data;
//console.log(JSON.stringify($scope.studentPictos));
console.log("Student pictos listed");
// Filtered only the categories pictos
$scope.pictosCategory = $filter('filter')($scope.studentPictos, {attributes: { id_cat: null }});
console.log("Pictos Categories: " + JSON.stringify($scope.pictosCategory));
// Build the pcb_cat with the coords of the pictos
for(var i=0; i < $scope.pictosCategory.length; i++) {
var pic = $scope.pictosCategory[i];
$scope.pcb_cat[pic.attributes.coord_x][pic.attributes.coord_y] = pic;
console.log("Pic " + pic.id + ": " + pic.attributes.color + " - " + pic.attributes.color.toString(16));
}
//console.log(JSON.stringify($scope.pcb_cat));
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
// Reload student pictos (back from addpicto)
$scope.reload_pictos = function(){
$http
.get(config.backend+'/stu/'+ $scope.studentUser.id +'/pictos')
.success(function(data, status, headers, config) {
// Add to list
$scope.studentPictos = data;
//console.log(JSON.stringify($scope.studentPictos));
console.log("Student pictos reloaded");
// Filtered only the categories pictos
$scope.pictosCategory = $filter('filter')($scope.studentPictos, {at
tributes: { id_cat: null }});
// Build the pcb_cat with the coords of the pictos
for(var i=0; i < $scope.pictosCategory.length; i++) {
var pic = $scope.pictosCategory[i];
$scope.pcb_cat[pic.attributes.coord_x][pic.attributes.coord_y] = pic;
}
// If a category is open ($scope.pictos.idCat != null) it is showed
if($scope.pictos.idCat)
$scope.show_category($scope.pictos.idCat, $scope.pictos.category);
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
}
// Show the pictograms of a category when it is clicked
$scope.show_category = function(idCat, nameCat, colorCat){
$scope.pictos.category = nameCat;
$scope.pictos.idCat = idCat;
$scope.pictos.colorCat = colorCat;
// $filter('filter')(array, expression, comparator) --> comparator = true is
// a shorthand for function(actual, expected) { return angular.equals(actual, expected)}.
// This is essentially strict comparison of expected and actual.
$scope.pictosFromCategory = $filter('filter')($scope.studentPictos, { attributes: { id_cat: idCat }}, true);
//console.log("Category: " + idCat + " - " + nameCat);
//console.log(JSON.stringify($scope.pictosFromCategory));
// Clean the pcb
for (var i=0;i<rows;i++) {
for (var j=0;j<cols; j++) {
$scope.pcb[i][j]={'picto': {'uri': '/app/img/empty.gif'}, 'attributes': {'coord_x': i, 'coord_y': j}};
}
}
// Build the pcb with the coords of the pictos
for(var i=0; i < $scope.pictosFromCategory.length; i++) {
var pic = $scope.pictosFromCategory[i];
$scope.pcb[pic.attributes.coord_x][pic.attributes.coord_y] = pic;
}
//console.log(JSON.stringify($scope.pcb));
};
// Delete student picto
$scope.delete_picto = function (stuPicto){
console.log("delete_studentPicto:" + stuPicto.id);
var deleteStuPicto = $window.confirm('Are you absolutely sure you want to delete?');
if(deleteStuPicto){
$http
.delete(config.backend+'/stu/'+ $scope.studentUser.id + '/picto/' + stuPicto.id)
.success(function(data, status, headers, config) {
// Eliminar de la vista: Se recorre el array de objetos json para buscarlo
$scope.pcb[stuPicto.attributes.coord_x][stuPicto.attributes.coord_y]={'picto': {'uri': '/app/img/empty.gif'}, 'attributes': {'coord_x': stuPicto.attributes.coord_x, 'coord_y': stuPicto.attributes.coord_y}};
console.log("Picto deleted: " + JSON.stringify($scope.pcb[stuPicto.attributes.coord_x][stuPicto.attributes.coord_y]));
// Eliminar de la colección de pictos
for(var i=0; i < $scope.studentPictos.length; i++) {
var pic = $scope.studentPictos[i];
if(pic.id == stuPicto.id){
$scope.studentPictos.splice(i,1);
break;
}
}
console.log("Student picto deleted");
//////////////////////////////////////////////////////////////////////
// websocket emit vocabulary delete action
io.socket.post('/stu/vocabulary', {
action: 'delete',
attributes: {
id_stu: $scope.studentUser.id,
picto: data
}
},
function(res) {
console.log("Vocabulary emitted: " + JSON.stringify(res.msg));
});
//////////////////////////////////////////////////////////////////////
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
}
};
// View student picto
$scope.view_picto = function (stuPicto){
console.log("update_studentPicto:" + stuPicto.id);
console.log(JSON.stringify(stuPicto));
if(stuPicto.attributes.status == "enabled") stuPicto.attributes.status = "disabled";
else if(stuPicto.attributes.status == "disabled") stuPicto.attributes.status = "invisible";
else stuPicto.attributes.status = "enabled";
$http
.put(config.backend+'/stu/'+ $scope.studentUser.id + '/picto/' + stuPicto.id, { 'attributes': stuPicto.attributes })
.success(function(data, status, headers, config) {
// Actualizar la vista: Se recorre el array de objetos json para buscarlo
console.log("Attributes for student picto updated");
//////////////////////////////////////////////////////////////////////
// websocket emit vocabulary update action
io.socket.post('/stu/vocabulary', {
action: 'update',
attributes: {
id_stu: $scope.studentUser.id,
picto: data
}
},
function(res) {
console.log("Vocabulary emitted: " + JSON.stringify(res.msg));
});
//////////////////////////////////////////////////////////////////////
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
};
$scope.handleDrop = function(origin, destination) {
var c_ori = origin.split("_");
var c_des = destination.split("_");
// Update the coords in pictos view
$scope.pcb[c_ori[0]][c_ori[1]].attributes.coord_x = c_des[0];
$scope.pcb[c_ori[0]][c_ori[1]].attributes.coord_y = c_des[1];
$scope.pcb[c_des[0]][c_des[1]].attributes.coord_x = c_ori[0];
$scope.pcb[c_des[0]][c_des[1]].attributes.coord_y = c_ori[1];
// Update the ORIGIN picto coords in server (if the picto is not empty)
if($scope.pcb[c_ori[0]][c_ori[1]].id){
$http
.put(config.backend+'/stu/'+ $scope.studentUser.id + '/picto/' +
$scope.pcb[c_ori[0]][c_ori[1]].id, { 'attributes': $scope.pcb[c_ori[0]][c_ori[1]].attributes })
.success(function(data, status, headers, config) {
console.log("Coords for picto origin updated");
// /////////////////////////////////////////////////////////////
// Websocket: Emit vocabulary update action
io.socket.post('/stu/vocabulary', {
action: 'update',
attributes: {
id_stu: $scope.studentUser.id,
picto: data
}
},
function(res) {
console.log("Vocabulary emitted: " + JSON.stringify(res.msg));
});
///////////////////////////////////////////////////////////////
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
}
// Update the DESTINATION picto coords in server (if the picto is not empty)
if($scope.pcb[c_des[0]][c_des[1]].id){
$http
.put(config.backend+'/stu/'+ $scope.studentUser.id + '/picto/' +
$scope.pcb[c_des[0]][c_des[1]].id, { 'attributes': $scope.pcb[c_des[0]][c_des[1]].attributes })
.success(function(data, status, headers, config) {
console.log("Coords for picto destination updated");
// /////////////////////////////////////////////////////////////
// Websocket: Emit vocabulary update action
io.socket.post('/stu/vocabulary', {
action: 'update',
attributes: {
id_stu: $scope.studentUser.id,
picto: data
}
},
function(res) {
console.log("Vocabulary emitted: " + JSON.stringify(res.msg));
});
///////////////////////////////////////////////////////////////
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
}
// Swap the pictos
var aux = $scope.pcb[c_des[0]][c_des[1]];
$scope.pcb[c_des[0]][c_des[1]] = $scope.pcb[c_ori[0]][c_ori[1]];
$scope.pcb[c_ori[0]][c_ori[1]] = aux;
console.log('Picto (' + c_ori[0] + ',' + c_ori[1] + ') has been dropped into picto (' + c_des[0] + ',' + c_des[1] + ')');
};
// Modal window to add pictos
$scope.open = function (size) {
// Close category that it's open
//$scope.pictos.category = null;
//$scope.pictos.idCat = null;
var modalInstance = $modal.open({
animation: true,
templateUrl: 'modules/student/views/addpicto.html',
controller: 'AddPictoCtrl',
size: size,
resolve: { // Passing data to the controller of the window
stu_id: function(){
return $scope.studentUser.id;
},
sup: function(){
return $scope.user;
},
studentPictos: function(){
return $scope.studentPictos; // To calcultate the position of added pictos
},
categories: function(){ // Only the categories are passed (not row 0 pictos)
return $filter('filter')($scope.pictosCategory, { attributes: { coord_x: '!'+0 }});
}
}
});
// Returned data from the modal window
modalInstance.result.then(
/* function (returnedItem) { // Output from the window by clicking ok button
console.log("Returned value from window: " + returnedItem);
},*/
function () {
// Output from the window by clicking cancel or outside its borders
console.log("Modal dismissed at: " + new Date());
// Reload the student pictos
$scope.reload_pictos();
}
);
};
// End Modal window to add pictos
// Modal window to manage picto tags
$scope.open_tags = function (stuPicto) {
var modalInstance = $modal.open({
animation: true,
templateUrl: 'modules/student/views/tags.html',
controller: 'TagsCtrl',
size: 'md',
resolve: { // Passing data to the controller of the window
stuPicto: function(){
return stuPicto;
},
sup: function(){
return $scope.user;
}
}
});
// Returned data from the modal window
modalInstance.result.then(
function () {
// Output from the window by clicking cancel or outside its borders
console.log("Modal dismissed at: " + new Date());
}
);
};
// End Modal window to manage picto tags
// Modal window to open picto config
$scope.open_config = function (stuPicto) {
var modalInstance = $modal.open({
animation: true,
templateUrl: 'modules/student/views/pictoconfig.html',
controller: 'PictoConfigCtrl',
size: 'md',
resolve: { // Passing data to the controller of the window
stuPicto: function(){
return stuPicto;
},
sup: function(){
return $scope.user;
},
stu: function(){
return $scope.studentUser
}
}
});
// Returned data from the modal window
modalInstance.result.then(
function (exp) {
// Output from the window by clicking cancel or outside its borders
console.log(exp);
stuPicto.expression.text = exp;
}
);
};
// End Modal window to manage picto config
//////////////////////////////////////////////////////////////////////
// websockets events handling
io.socket.on('vocabulary', function(data) {
console.log('Vocabulary '+ data.action +' event received with the following data:');
console.log(JSON.stringify(data.attributes));
//$scope.pictos.push(data.attributes.picto.picto);
switch(data.action){
case 'add':
console.log("add action!!!!!!!!!!!!!");
$scope.reload_pictos();
break;
case 'update':
console.log("update action!!!!!!!!!!!!!");
$scope.reload_pictos();
break;
case 'delete':
console.log("delete action!!!!!!!!!!!!");
$scope.reload_pictos();
break;
}
// Socket.io does not live inside the angular lifecycle, and thus Angular
// doesn't know new data has come in. Inside the socket.io callback,
// as the last action, added $scope.apply() that lets angular know
// what data has updated, and refresh what needs to be refreshed.
$scope.$apply();
});
//////////////////////////////////////////////////////////////////////
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment