Code coverage report for Controller/GraphsControllers/MapChartController.js

Statements: 46.3% (25 / 54)      Branches: 10% (1 / 10)      Functions: 33.33% (3 / 9)      Lines: 46.3% (25 / 54)      Ignored: none     

All files » Controller/GraphsControllers/ » MapChartController.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104                                        1     10 10 10     10 10 8 8 8 8 8       10 10 10 10     10 8                   8       8           8       8               8                                       10     10 10    
/*jshint node: true */
'use strict';
 
/*
* Name :  MapChartController.js
* Module : FrontEnd::Controller::GraphsController
* Location : /frontend/app/Controller/GraphsController
*
* History :
* Version       Date        Programmer                  Description
* =================================================================================================
* 1.0.0         2015-05-25  Francesco Rossetto		   Tested
*
* 0.1.0         2015-05-25  Maria Giovanna Chinellato   Add all attributes and all methods
*
* 0.0.1         2015-05-25  Maria Giovanna Chinellato   Initial code      
* =================================================================================================
*
*/
 
angular.module('norris-nrti')
.controller('MapChartController', function($scope, $location, MapChartFactory, MapChartFlowFactory, SocketServicesFactory){
 
	var socket;
	var mapChart = MapChartFactory.build(); // crea un map chart di default
	$scope.mapChart = mapChart;
 
	// funzione che connette il socket all'url e chiama la funzione listenOnEvent
	var count1 = 0;
	this.socketConnection = function(url){
		Eif (count1 === 0) {
			socket = SocketServicesFactory.build(url);
			$scope.socket = socket;
			this.listenOnEvents();
			count1++;
		}
	};
 
	var count = 0;
	$scope.changedP = true;
	$scope.changedD = true;
	$scope.changedF = true;
 
	// funzione che mette in ascolto il socket su alcuni eventi
	this.listenOnEvents = function(){
		socket.on('configGraph', function(info){ // ascolta sull'evento 'configGraph' (ricevuto come risposta alla connessione)
			if (count === 0) {
				console.log('configGraph mapChart');
				count++;
				$scope.mapChart.updateParameters(info.properties); // aggiorna le proprietà del map chart di default con i dati appena ricevuti
				$scope.mapChart.initializeData(info.data); // inizializza i flussi con i dati
				$scope.changedP = !$scope.changedP; // 'notifica' cambiamento proprietà
				$scope.changedD = !$scope.changedD; // 'notifica' cambiamento dati
	        }
		});
		socket.on('updateGraphProp', function(info){ // ascolta sull'evento 'updateGraphProp'
			$scope.mapChart.updateParameters(info); // aggiorna le proprietà del map chart con i dati appena ricevuti
			$scope.changedP = !$scope.changedP; // 'notifica' cambiamento proprietà
		});
		socket.on('insertFlow', function(info){ // ascolta sull'evento 'insertFlow'
			var flow = MapChartFlowFactory.build(info.properties); // crea un flusso di default
			flow.initializeData(info); // inizializzail flusso
			$scope.mapChart.addFlow(info.ID, flow); // aggiunge il flusso al grafico
			$scope.changedD = !$scope.changedD; // 'notifica' cambiamento dati
		});
		socket.on('deleteFlow', function(info){ // ascolta sull'evento 'deleteFlow'
			$scope.mapChart.deleteFlow(info.ID); // elimina un flusso
			$scope.changedD = !$scope.changedD; // 'notifica' cambiamento dati
		});
		socket.on('updateFlowProp', function(info){ // ascolta sull'evento 'updateFlowProp'
			for (var i=0; i<$scope.mapChart.getFlowList().length; i++){
				if ($scope.mapChart.getFlowList()[i].id === info.ID){
					$scope.mapChart.getFlowList()[i].flow.updateParameters(info); // aggiorna le proprietà dei flussi
				}
			}
			$scope.changedD = !$scope.changedD; // 'notifica' cambiamento dati
		});
		socket.on('updateFlowData', function(data){ // ascolta sull'evento 'updateFlowData'
			switch (data.action){
				case 'insertRecords':
					$scope.mapChart.streamUpdate(data); // effettua un aggiornamento di tipo stream
					break;
				case 'deleteRecord':
					$scope.mapChart.deleteData(data); // elimina dei dati
					break;
				case 'updateRecord':
					$scope.mapChart.inPlaceUpdate(data); // effettua aggiornamento di tipo in place
					break;
				case 'replaceData':
					$scope.mapChart.replaceData(data); // rimpiazza dei dati
					break;
			}
			$scope.changedD = !$scope.changedD; // 'notifica' cambiamento dati
		});
 
	};
	// variabili e funzioni a disposizione dei test
	$scope.socket = socket;
 
	// mette a disposizione delle funzioni sullo scope
	$scope.socketConnection = this.socketConnection;
	$scope.listenOnEvents = this.listenOnEvents;
 
});