Commit 385ff3d0 by Jose Antonio

Working on scenes - collections controller

parent 7c9d9a5b
......@@ -48,6 +48,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$scope.freeCategoryPictos = null;
$scope.loadingPictos = true;
$scope.viewingScene = null;
$scope.scenesList = null;
$scope.isCategory = function (studentPicto) {
return studentPicto.attributes.id_cat === null &&
......@@ -120,26 +121,61 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
};
// Reload student pictos (back from addpicto)
$scope.loadPictos = function () {
$scope.loadPictos = function (scene) {
// Fill with grid (if not done before)
$scope.freeCategoryPictos = $scope.freeCategoryPictos || generateGrid();
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] =
$scope.studentPictos[$scope.getCategoryId($scope.selectedCategory)] || generateGrid();
scene.pictos.forEach(placePicto);
$scope.loadingPictos = false;
};
// get active scene
$scope.showActiveScene = function (scene) {
// Get user's pictos
$http.get(config.backend + '/stu/' + $scope.studentData.id + '/activeScene')
.success(function (activeScene) {
$scope.showFreeCategory = !$scope.studentData.attributes.categories;
$scope.viewingScene = activeScene.id;
activeScene.pictos.forEach(placePicto);
//studentPictos.forEach(placePicto);
$scope.showFreeCategory = !activeScene.categories;
$scope.viewingScene = activeScene;
$scope.loadPictos(activeScene);
//setTimeout(function () { $scope.$apply(); });
})
.error(function () {
$translate('error_loading_scene').then(function (translation) {
ngToast.danger({ content: translation });
});
});
};
$scope.loadingPictos = false;
setTimeout(function () { $scope.$apply(); });
// get active scene
$scope.showScene = function (idScene) {
$http.get(config.backend + '/scene/' + idScene)
.success(function (scene) {
$scope.showFreeCategory = !scene.categories;
$scope.viewingScene = scene;
$scope.loadPictos(scene);
//setTimeout(function () { $scope.$apply(); });
})
.error(function () {
$translate('error_loading_pictos').then(function (translation) {
$translate('error_loading_scene').then(function (translation) {
ngToast.danger({ content: translation });
});
});
};
// get active scene
$scope.loadScenesList = function () {
$http.get(config.backend + '/stu/' + $scope.studentData.id +'/scenes')
.success(function (scenes) {
$scope.scenesList = scenes;
//setTimeout(function () { $scope.$apply(); });
})
.error(function () {
$translate('error_loading_scenes').then(function (translation) {
ngToast.danger({ content: translation });
});
});
......@@ -169,6 +205,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
action: 'delete',
attributes: {
id_stu: $scope.studentData.id,
id_scene: $scope.viewingScene.id,
stu_picto: studentPicto
}
}, function () {});
......@@ -182,6 +219,58 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
});
};
// Delete student picto
$scope.delete_scene = function (idScene) {
$translate('confirmation').then(t => {
if ($window.confirm(t)) {
$http.delete(config.backend + '/scene/' + idScene)
.success(function () {
// io.socket.post('/stu/vocabulary', {
// action: 'delete',
// attributes: {
// id_stu: $scope.studentData.id,
// id_scene: $scope.viewingScene.id,
// stu_picto: studentPicto
// }
// }, function () {});
//
// $translate('picto_removed').then(function (translation) {
// ngToast.success({ content: translation });
// });
}).error(function () {});
}
});
};
// Delete student picto
$scope.update_scene = function (scene) {
$http.put(config.backend + '/scene/' + idScene, {
name: scene.name,
active: scene.active})
.success(function () {
var data= {name: scene.name,
active: scene.active,
categories: scene.categories,
student: scene.student,
supervisor: scene.supervisor};
io.socket.post('/scene', {
action: 'update',
scene: data
}, function () {});
$translate('scene_updated').then(function (translation) {
ngToast.success({ content: translation });
});
}).error(function () {});
};
$scope.deleteFreePicto = function (studentPicto) {
$translate('confirmation').then(t => {
if ($window.confirm(t)) {
......@@ -195,6 +284,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
action: 'delete',
attributes: {
id_stu: $scope.studentData.id,
id_scene: $scope.viewingScene.id,
stu_picto: studentPicto
}
}, function () {});
......@@ -226,6 +316,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
action: 'update',
attributes: {
id_stu: $scope.studentData.id,
id_scene: $scope.viewingScene.id,
stu_picto: newStuPicto
}
}, function () {});
......@@ -288,6 +379,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
action: 'update',
attributes: {
id_stu: $scope.studentData.id,
id_scene: $scope.viewingScene.id,
stu_picto: newStudentPicto
}
}, function () {
......@@ -333,13 +425,14 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
new_id_pic: pictoId
})
.success(function (studentPicto) {
$scope.loadPictos();
$scope.loadPictos($scope.viewingScene);
// notify
io.socket.post('/stu/vocabulary', {
action: 'update_category',
attributes: {
id_stu: $scope.studentData.id,
id_scene: $scope.viewingScene.id,
stu_picto: studentPicto
}
}, function () {});
......@@ -388,7 +481,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
free_category_coord_x: $scope.showFreeCategory ? col : null,
free_category_coord_y: $scope.showFreeCategory ? row : null
},
id_scene: $scope.viewingScene
id_scene: $scope.viewingScene.id
})
.success(function (studentPicto) {
placePicto(studentPicto);
......@@ -397,6 +490,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
action: 'add',
attributes: {
id_stu: $scope.studentData.id,
id_scene: $scope.viewingScene.id,
stu_picto: studentPicto
}
}, function () {});
......@@ -462,23 +556,31 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
// Add new listener to the event
io.socket.off('vocabulary');
io.socket.on('vocabulary', function (data) {
switch (data.action) {
case 'add':
$scope.loadPictos();
break;
case 'update':
$scope.loadPictos();
break;
case 'delete':
$scope.loadPictos();
break;
default:
$scope.loadPictos();
break;
// switch (data.action) {
// case 'add':
// $scope.loadPictos();
// break;
// case 'update':
// $scope.loadPictos();
// break;
// case 'delete':
// $scope.loadPictos();
// break;
// default:
// $scope.loadPictos();
// break;
// }
if(data.attributes.id_scene == $scope.viewingScene.id){
//Reload scene
$translate('reload_scene').then(function (translation) {
ngToast.success({ content: translation });
});
$scope.showScene(data.attributes.id_scene);
}
$scope.$apply();
});
// Load pictos
$scope.loadPictos();
$scope.showActiveScene();
$scope.loadScenesList();
});
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