Code coverage report for Model/GraphsModel/Table.js

Statements: 100% (121 / 121)      Branches: 62.9% (39 / 62)      Functions: 95.83% (23 / 24)      Lines: 100% (121 / 121)      Ignored: none     

All files » Model/GraphsModel/ » Table.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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238                                                    1       1 19 19 19   19 19   19 19   19 12   19 12       19 19 19   19 13   19 12   19 19   19 19   19 19     19             1 40 40 40 40 40 40 40       33 19 19 19 19   19 19   19 19 19 19 50     19 13   19 12   19 19   19 19   19 19     19 18 54 54             33 62 62       33 1     33 1 1 1 1           33 7 7 7 13 7               33 1 1 1 1 1           33 1 1 1 1 1           33 1 1 1 1 1           33 5   33 9   33 9   33 1   33 116   33 222   33 6   33 2   33 16   33 41   33 168       1   33 40     33  
/*jshint node: true */
'use strict';
 
/*
* Name :  Table.js
* Module : FrontEnd::Model::GraphsModel
* Location : /frontend/app/Model/GraphsModel
*
* History :
* Version       Date        Programmer                  Description
* ===============================================================================================================
* 1.0.0         2015-05-21  Maria Giovanna Chinellato   Tested
*
* 0.3.0         2015-05-18  Maria Giovanna Chinellato   Modified general structure, some fixes
*
* 0.2.1         2015-05-15  Maria Giovanna Chinellato   Fix methods test
*
* 0.1.1         2015-05-15  Francesco Rossetto          Various fix, insert inzializeData
*
* 0.1.0         2015-05-14  Maria Giovanna Chinellato   Add all attributes and all methods
*
* 0.0.1         2015-05-14  Maria Giovanna Chinellato   Initial code          
* ===============================================================================================================
*
*/
 
angular.module('norris-nrti')
.factory('TableFactory', ['GraphFactory', 'TableFlowFactory', function(GraphFactory, TableFlowFactory){
 
    // funzione di utilità che ha lo scopo di separare le proprietà legate al grafico generale da quelle legate al bar chart
	function split(json) {
		var graphJson = {};
		Eif (json.title !== undefined) {
			graphJson.title = json.title;
		}
		Eif (json.height !== undefined) {
			graphJson.height = json.height;
		}
		Eif (json.width !== undefined) {
			graphJson.width = json.width;
		}
		if (json.horizontalGrid !== undefined) {
			graphJson.horizontalGrid = json.horizontalGrid;
		}
		if (json.verticalGrid !== undefined) {
			graphJson.verticalGrid = json.verticalGrid;
		}
 
 
		var tableJson = {};
		Eif (json.headers !== undefined) {
			tableJson.headers = json.headers;
		}
		if (json.maxItemsPage !== undefined) {
			tableJson.maxItemsPage = json.maxItemsPage;
		}
		if (json.addRowOn !== undefined) {
			tableJson.addRowOn = json.addRowOn;
		}
		Eif (json.sortable !== undefined) {
			tableJson.sortable = json.sortable;
		}
        Eif (json.sort !== undefined) {
            tableJson.sort = json.sort;
        }
        Eif (json.appearance !== undefined) {
            tableJson.appearance = json.appearance;
        }
 
		return {
			'graphJson' : graphJson,
			'tableJson' : tableJson
		};
	}
 
    // costruttore di default di una Table
    function Table(info) {
        this._headers = [];
        this._maxItemsPage = 20;
        this._addRowOn = 'top';
        this._sortable = true;
        this._sort = null;
        this._appearance = null;
        this._graph = GraphFactory.build(info);
    }
 
    // funzione che ha lo scopo di aggiornare i campi dati dela table
    Table.prototype.updateParameters = function(info) {
        Eif (info !== undefined) {
            var json = split(info);
            var gJson = json.graphJson;
            var tJson = json.tableJson;
            
            Eif (Object.keys(gJson).length !== 0) {
                this._graph.updateParameters(gJson);
            } 
            Eif (Object.keys(tJson).length !== 0) {
                Eif (tJson.headers !== undefined) {
                    this._headers = [];
                    for (var z=0; z<tJson.headers.length; z++) { 
                        this._headers.push(tJson.headers[z]);
                    }
                }
                if (tJson.maxItemsPage !== undefined) {
                    this._maxItemsPage = tJson.maxItemsPage;
                }
                if (tJson.addRowOn !== undefined) {
                    this._addRowOn = tJson.addRowOn;
                }
                Eif (tJson.sortable !== undefined) {
                    this._sortable = tJson.sortable;
                }
                Eif (tJson.sort !== undefined) {
                    this._sort = tJson.sort;
                }
                Eif (tJson.appearance !== undefined) {
                    this._appearance = tJson.appearance;
                }
            }
            if (info.flows !== undefined) {
                for (var y=0; y<info.flows.length; y++) {
                    var newflow = TableFlowFactory.build(info.flows[y]);
                    this.addFlow(info.flows[y].ID, newflow);
                }
            }
        }
    };
 
    // aggiunge un nuovo flusso alla lista di flussi
    Table.prototype.addFlow = function(ID, newFlow) {
        Eif (newFlow.constructor.name === 'TableFlow') { // controlla che il flusso da inserire sia del tipo giusto
            this._graph.addFlow(ID, newFlow);
        }
    };
    // elimina il flusso con id === ID
    Table.prototype.deleteFlow = function(ID) {
        this._graph.deleteFlow(ID);
    };
    // rimpiazza i dati di un flusso con altri dati
    Table.prototype.replaceData = function(newData){
        for (var i = 0;i<this._graph.getFlowList().length; i++) {
            Eif (this._graph.getFlowList()[i].id === newData.ID){
                this._graph.getFlowList()[i].flow.emptyData();
                this._graph.getFlowList()[i].flow.initializeData(newData, this._addRowOn);
            }
        }
    };
 
    // inizializza i dati dei flussi presenti nella lista
    Table.prototype.initializeData = function(newData) {  //inizialization data of flows
        Eif (newData !== undefined) {
            for (var i=0; i<newData.length; i++) {
                for (var j=0; j<this._graph.getFlowList().length; j++) {
                    if (this._graph.getFlowList()[j].id === newData[i].ID) {
                        this._graph.getFlowList()[j].flow.initializeData(newData[i], this._addRowOn);
                    }
                }
            }
        }
    };
 
    // funzione che permette l'aggiornamento di tipo in place dei dati
    Table.prototype.inPlaceUpdate = function(newData) {
        Eif (newData !== undefined) {
            var fList = this._graph.getFlowList();
            for (var j=0; j<fList.length; j++) {
                Eif (fList[j].id === newData.ID) {
                    fList[j].flow.inPlaceUpdate(newData);
                }
            }
        }
    };
    // funzione che permette l'aggiornamento di tipo stream dei dati
    Table.prototype.streamUpdate = function(newData) {
        Eif (newData !== undefined) {
            var fList = this._graph.getFlowList();
            for (var j=0; j<fList.length; j++) {
                Eif (fList[j].id === newData.ID) {
                    fList[j].flow.streamUpdate(newData, this._addRowOn);
                }
            }
        }
    };
    // funzione che permette di eliminare i dati di un flusso
    Table.prototype.deleteData = function(delData) {
        Eif (delData !== undefined){
            var fList = this._graph.getFlowList();
            for (var j=0; j<fList.length; j++) {
                Eif (fList[j].id === delData.ID) {
                    fList[j].flow.deleteData(delData);
                }
            }
        }
    };
 
    Table.prototype.getTitle = function() {
        return this._graph.getTitle(); // ritorna il titolo del grafico
    };
    Table.prototype.getHeight = function() {
        return this._graph.getHeight(); // ritorna l'altezza del grafico
    };
    Table.prototype.getWidth = function() {
        return this._graph.getWidth(); // ritorna la larghezza del grafico
    };
    Table.prototype.getUrl = function() {
        return this._graph.getUrl(); // ritorna l'url relativo al grafico
    };
    Table.prototype.getFlowList = function() {
        return this._graph.getFlowList(); // ritorna la lista dei flussi presenti nel grafico
    };
    Table.prototype.getHeaders = function() {
    return this._headers; // ritorna gli header della tabella
    };
    Table.prototype.getMaxItemsPage = function() {
        return this._maxItemsPage; // ritorna il massimo numero di elementi visualizzabili per pagina di tabella
    };
    Table.prototype.getAddRowOn = function() {
        return this._addRowOn; // ritorna la posizione di aggiunta record (top o bottom)
    };
    Table.prototype.getSortable = function() {
        return this._sortable; // ritorna true se è disponibile la funzionalità di ordinamento della tabella per colonne
    };
    Table.prototype.getSort = function() {
        return this._sort; // ritorna le colonne su cui è possibile ordinare la tabella
    };
    Table.prototype.getAppearance = function() {
        return this._appearance; // ritorna un array che definisce l'aspetto delle celle
    };
 
    // costruttore di default di TableFactory
    function TableFactory() {}
 
    TableFactory.build = function(info) {
        return new Table(info); // ritorna una nuova istanza di Table
    };
 
    return TableFactory;
}]);