Code coverage report for Model/FlowsModel/BarChartFlow.js

Statements: 100% (53 / 53)      Branches: 75% (12 / 16)      Functions: 92.86% (13 / 14)      Lines: 100% (53 / 53)      Ignored: none     

All files » Model/FlowsModel/ » BarChartFlow.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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126                                                    1     1 89 89   89 74 5     74 9       89               1 88 88 88   88 88 88 88   88 8         58 1 1 1   1   1 1 1         58 12 21     58 2   58 2 2 2       58 2   58 1 1 1         58 27   58 71   58 33     1   58 88     58    
/*jshint node: true */
'use strict';
 
/*
* Name :  BarChartFlow.js
* Module : FrontEnd::Model::FlowsModel
* Location : /frontend/app/Model/FlowsModel
*
* History :
* Version       Date        Programmer                  Description
* =================================================================================================
* 1.0.1         2015-06-25  Maria Giovanna Chinellato	Fix initializeData
*
* 1.0.0			2015-05-20	Francesco Rossetto			Tested
*
* 0.2.0			2015-05-18	Francesco Rossetto			Modified general structure, some fixes
*
* 0.1.1         2015-05-15  Maria Giovanna Chinellato	Various fixes
*
* 0.1.0         2015-05-12  Maria Giovanna Chinellato	Add attributes and methods
*
* 0.0.1         2015-05-12  Maria Giovanna Chinellato	Initial code
* =================================================================================================
*
*/
 
angular.module('norris-nrti')
.factory('BarChartFlowFactory', ['FlowFactory', function(FlowFactory){
 
	function split(json) {
        var flowJson = {};
        var barFlowJson = {};
 
        if (json !== undefined){
	        if (json.name !== undefined) {
	            flowJson.name = json.name;
	        }
 
	        if (json.flowColor !== undefined) {
	            barFlowJson.flowColor = json.flowColor;
	        }
	    }
 
        return {
            'flowJson' : flowJson,
            'barFlowJson' : barFlowJson
        };
    }
 
    //BarChartFlow.prototype.test = function _Test(expressionStr) { return eval(expressionStr); };
 
    function BarChartFlow(info) {
    	this._data = [];
		this._flowColor = undefined;
		this._flow = null;
 
		var json = split(info);
		var fJson = json.flowJson;
		var bfJson = json.barFlowJson;
		this._flow = FlowFactory.build(fJson);
 
		if (bfJson.flowColor !== undefined) {
            this._flowColor = bfJson.flowColor;
        }
 
	}
 
	BarChartFlow.prototype.updateParameters = function(info) {
    	var json = split(info);
		var fJson = json.flowJson;
		var bfJson = json.barFlowJson;
 
		this._flow.updateParameters(fJson);
 
		Eif (Object.keys(bfJson).length !== 0) {
			Eif (bfJson.flowColor !== undefined) {
	            this._flowColor = bfJson.flowColor;
	        }
	    }
	};
 
	BarChartFlow.prototype.initializeData = function(newData) {
		for (var i=0; i<newData.records.length; i++) {
			this._data.push(newData.records[i]);
		}
	};
	BarChartFlow.prototype.emptyData = function() {
		this._data.splice(0);
	};
	BarChartFlow.prototype.inPlaceUpdate = function(newData) {
        for (var i = 0; i<this._data.length; i++){
            Eif (this._data[i].norrisRecordID === newData.norrisRecordID){
                this._data[i] = { 'norrisRecordID' : newData.norrisRecordID, 'value' : newData.value };
            }
        }
    };
    BarChartFlow.prototype.addRecords = function(newData) {
		this.initializeData(newData);
    };
    BarChartFlow.prototype.deleteData = function(delData) {
    	for (var i = 0; i<this._data.length; i++){
            Eif (this._data[i].norrisRecordID === delData.norrisRecordID){
                this._data.splice(i,1);
            }
        }
    };
 
    BarChartFlow.prototype.getName = function() {
    	return this._flow.getName();
    };
	BarChartFlow.prototype.getData = function() {
		return this._data;
	};
	BarChartFlow.prototype.getFlowColor = function() {
		return this._flowColor;
	};
 
    function BarChartFlowFactory(){}
 
    BarChartFlowFactory.build = function(info) {
        return new BarChartFlow(info);
    };
 
	return BarChartFlowFactory;
 
}]);