Code coverage report for Model/FlowsModel/TableFlow.js

Statements: 100% (64 / 64)      Branches: 75% (24 / 32)      Functions: 92.86% (13 / 14)      Lines: 100% (64 / 64)      Ignored: none     

All files » Model/FlowsModel/ » TableFlow.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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144                                                    1     1 75 75   75 60 4     60 6       75               1 74 74   74 74 74   74   74 5       45 1 1 1 1   1 1     1 1 1           45 18 34 31 7 24 24       3 1 1 2 2 2         45 2   45 2 2 2       45 2   45 2 2 2         45 2   45 110   45 3     1   45 74     45    
/*jshint node: true */
'use strict';
 
/*
* Name :  TableFlow.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-22  Maria Giovanna Chinellato	Tested
*
* 0.2.0         2015-05-16  Maria Giovanna Chinellato	Modified general structure, some fixes
*
* 0.1.1         2015-05-15  Maria Giovanna Chinellato	Various fix
*
* 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('TableFlowFactory', ['FlowFactory', function(FlowFactory){
 
	function split(json) {
        var flowJson = {};
        var tableFlowJson = {};
 
        if(json !== undefined) {
	        if (json.name !== undefined) {
	            flowJson.name = json.name;
	        }
 
	        if (json.maxItems !== undefined) {
	            tableFlowJson.maxItems = json.maxItems;
	        }
	    }
 
        return {
            'flowJson' : flowJson,
            'tableFlowJson' : tableFlowJson
        };
    }
 
    //TableFlow.prototype.test = function _Test(expressionStr) { return eval(expressionStr); };
 
    function TableFlow(info) {
    	this._data = [];
		this._maxItems = null;
		
		var json = split(info);
		var fJson = json.flowJson;
		var tfJson = json.tableFlowJson;
 
		this._flow = FlowFactory.build(fJson);
 
        if (tfJson.maxItems !== undefined) {
            this._maxItems = tfJson.maxItems;
        }
	}
 
	TableFlow.prototype.updateParameters = function(info) { // abstract
		Eif (info !== undefined) {
	    	var json = split(info);
			var fJson = json.flowJson;
			var tfJson = json.tableFlowJson;
 
			Eif (Object.keys(fJson).length !== 0) {
				this._flow.updateParameters(fJson);
			}
 
			Eif (Object.keys(tfJson).length !== 0) {
		        Eif (tfJson.maxItems !== undefined) {
		            this._maxItems = tfJson.maxItems;
		        }
		    }
		}
	};
 
	TableFlow.prototype.initializeData = function(newData, addRowOn) {
		for (var i=0; i<newData.records.length; i++) {
			if (this._maxItems === null || this._data.length < this._maxItems){
				if (addRowOn === 'bottom') {
					this._data.push(newData.records[i]);
				} else Eif (addRowOn === 'top') {
					this._data.unshift(newData.records[i]);
				}
			}
			else{
				if (addRowOn === 'bottom') {
					this._data.splice(0,1);
					this._data.push(newData.records[i]);
				} else Eif (addRowOn === 'top') {
					this._data.splice(this._data.length-1,1);
					this._data.unshift(newData.records[i]);
				}
			}
		}
	};
	TableFlow.prototype.emptyData = function() {
		this._data.splice(0);
	};
	TableFlow.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 };
            }
        }
    };
    TableFlow.prototype.streamUpdate = function(newData, addRowOn) {
		this.initializeData(newData, addRowOn);
    };
    TableFlow.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);
            }
        }
    };
 
    TableFlow.prototype.getName = function() {
    	return this._flow.getName();
    };
	TableFlow.prototype.getData = function() {
		return this._data;
	};
	TableFlow.prototype.getMaxItem = function() {
		return this._maxItems;
	};
 
	function TableFlowFactory() {}
 
	TableFlowFactory.build = function(info) {
		return new TableFlow(info);
	};
 
	return TableFlowFactory;
 
}]);