Blame view

js/app/models/RequestParamObject.js 6.09 KB
bb6e93d9   Benjamin Renard   Implement templat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
 * Project      : AMDA-NG
 * Name         : RequestParamObject.js
 * Description  : Request Param Business Object Definition
 * @class amdaModel.RequestParamObject
 * @extends amdaModel.AmdaObject 
 * 
 * @author benjamin
 * @version $Id:  $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :13/06/2016: benjamin – creation 
 */
 
 		
Ext.define('amdaModel.RequestParamObject', {
	extend: 'amdaModel.AmdaObject',
29dfb596   Benjamin Renard   Rework of ParamAr...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

        statics: {
          getEmptyObj: function() {
            return {
            	'paramid': '',
		'is-init': false,
            	'type': 0,
            	'dim1-index': '*',
            	'dim1-sum-type': 0,
            	'dim1-min-value': 0.,
            	'dim1-max-value': 0.,
            	'dim1-min-index': 0,
            	'dim1-max-index': 0,
            	'dim2-index': '*',
            	'dim2-sum-type': 0,
            	'dim2-min-value': 0.,
            	'dim2-max-value': 0.,
            	'dim2-min-index': 0,
            	'dim2-max-index': 0,
            	'template_args': {}
            };
          },
        },
bb6e93d9   Benjamin Renard   Implement templat...
42
43
44
	
	idProperty: 'id',
    
29dfb596   Benjamin Renard   Rework of ParamAr...
45
46
47
        fields : [
          {name: 'type', type: 'int'}, /* Parameter type. 0: Scalar, 1: Tab1D, 2: Tab2D */
          {name: 'is-init', type: 'bool', default:false},
bb6e93d9   Benjamin Renard   Implement templat...
48
          {name: 'paramid', type: 'string'},
29dfb596   Benjamin Renard   Rework of ParamAr...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
          /* Fields for dim1 */
          {name: 'dim1-index', type: 'string', defaultValue: '*'},
          {name: 'dim1-sum-type', type: 'int', defaultValue: 0}, /* Sum type. 0: None, 1: sum into values range, 2: sum between indexes */
          {name: 'dim1-min-value', type: 'float', defaultValue: 0.},
          {name: 'dim1-max-value', type: 'float', defaultValue: 0.},
          {name: 'dim1-min-index', type: 'int', defaultValue: 0},
          {name: 'dim1-max-index', type: 'int', defaultValue: 0},
          /* Fields for dim2 */
          {name: 'dim2-index', type: 'string', defaultValue: '*'},
          {name: 'dim2-sum-type', type: 'int', defaultValue: 0}, /* Sum type. 0: None, 1: sum into values range, 2: sum between indexes */
          {name: 'dim1-min-value', type: 'float', defaultValue: 0.},
          {name: 'dim1-max-value', type: 'float', defaultValue: 0.},
          {name: 'dim1-min-index', type: 'int', defaultValue: 0},
          {name: 'dim1-max-index', type: 'int', defaultValue: 0},
          /* Field for arguments of a templated parameter */
          {name: 'template_args', type: 'auto', defaultValue: null},
          /* ?? */
          {name: 'plotonly', type: 'bool', defaultValue: false}
bb6e93d9   Benjamin Renard   Implement templat...
67
	],
1df8e90c   Benjamin Renard   Add selection for...
68

29dfb596   Benjamin Renard   Rework of ParamAr...
69
70
	getDimSum : function(dim) {
		switch (this.get(dim+'-sum-type')) {
1df8e90c   Benjamin Renard   Add selection for...
71
			case 1:
29dfb596   Benjamin Renard   Rework of ParamAr...
72
				return 'range[' + this.get(dim+'-min-value') + ',' + this.get(dim+'-max-value') + ']';
1df8e90c   Benjamin Renard   Add selection for...
73
			case 2:
29dfb596   Benjamin Renard   Rework of ParamAr...
74
				return 'indexes[' + this.get(dim+'-min-index') + ',' + this.get(dim+'-max-index') + ']';
1df8e90c   Benjamin Renard   Add selection for...
75
76
77
		}
		return false;
	},
bb6e93d9   Benjamin Renard   Implement templat...
78
79
80
	
	getParamFullName : function() {
		var paramIndexes = '';
29dfb596   Benjamin Renard   Rework of ParamAr...
81
82
		var sum_dim1 = this.getDimSum('dim1');
		var sum_dim2 = this.getDimSum('dim2');
bb6e93d9   Benjamin Renard   Implement templat...
83
84
85
86
87
88
		switch (this.get('type')) {
			case 0:
	  			//scalar - nothing to do
	  			break;
	  		case 1:
	  			//Tab1D
29dfb596   Benjamin Renard   Rework of ParamAr...
89
90
	  			if (sum_dim1 !== false) {
	  				paramIndexes = '(' + sum_dim1 + ')';
690e0a87   Benjamin Renard   Add sum in table ...
91
	  			}
29dfb596   Benjamin Renard   Rework of ParamAr...
92
93
	  			else if (sum_dim2 !== false) {
	  				paramIndexes = '(' + sum_dim2 + ')';
690e0a87   Benjamin Renard   Add sum in table ...
94
95
96
97
98
99
100
	  			}
	  			else {
	  				if ((this.get('dim1-index') != '') && (this.get('dim1-index') != '*'))
	  					paramIndexes = '('+this.get('dim1-index')+')';
	  				else if ((this.get('dim2-index') != '') && (this.get('dim2-index') != '*'))
	  					paramIndexes = '('+this.get('dim2-index')+')';
	  			}
bb6e93d9   Benjamin Renard   Implement templat...
101
102
103
	  			break;
	  		case 2:
	  			//Tab2D
690e0a87   Benjamin Renard   Add sum in table ...
104
	  			var dim1 = '';
29dfb596   Benjamin Renard   Rework of ParamAr...
105
106
	  			if (sum_dim1 !== false)
	  				dim1 = sum_dim1;
690e0a87   Benjamin Renard   Add sum in table ...
107
108
109
	  			else
		  			dim1 = this.get('dim1-index') != '' ? this.get('dim1-index') : "*";
	  			var dim2 = '';
29dfb596   Benjamin Renard   Rework of ParamAr...
110
111
	  			if (sum_dim2 !== false)
	  				dim2 = sum_dim2;
690e0a87   Benjamin Renard   Add sum in table ...
112
113
	  			else
	  				dim2 = this.get('dim2-index') != '' ? this.get('dim2-index') : "*";
bb6e93d9   Benjamin Renard   Implement templat...
114
115
116
117
118
119
120
121
	  			if ((dim1 != '*') || (dim2 != '*'))
	  				paramIndexes = '('+dim1+','+dim2+')';
		}
	
		var template_args = "";
		if (this.get('template_args')) {
			Ext.Object.each(this.get('template_args'), function (argKey, argValue) {
				template_args += "_";
3ad6d2e1   Benjamin Renard   Fix boolean argum...
122
123
124
125
126
127
				if (typeof(argValue) === "boolean") {
					template_args += (argValue ? 1 : 0);
				}
				else {
					template_args += argValue;
				}
bb6e93d9   Benjamin Renard   Implement templat...
128
129
130
131
132
133
134
135
136
137
138
139
140
			});
		}
		
		return this.get('paramid')+template_args+paramIndexes;
	},
	
	getJsonValues : function() 
    {
    	var paramValues  = new Object();
    	
    	paramValues['id'] = this.get('id');
    	paramValues['paramid'] = this.get('paramid');
    	paramValues['name'] = this.get('name');
690e0a87   Benjamin Renard   Add sum in table ...
141
    	
29dfb596   Benjamin Renard   Rework of ParamAr...
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
	paramValues['dim1-index'] = this.get('dim1-index');
    	paramValues['dim1-sum-type'] = this.get('dim1-sum-type');
	switch (this.get('dim1-sum-type')) {
		case 1:
			// Between values
			paramValues['dim1-sum-min'] = this.get('dim1-min-value');
			paramValues['dim1-sum-max'] = this.get('dim1-max-value');
			break;
		case 2:
			// Between components indexes
			paramValues['dim1-sum-min'] = this.get('dim1-min-index');
			paramValues['dim1-sum-max'] = this.get('dim1-max-index');
			break;
	}

	paramValues['dim2-index'] = this.get('dim2-index');
	paramValues['dim2-sum-type'] = this.get('dim2-sum-type');
	switch (this.get('dim2-sum-type')) {
		case 1:
			// Between values
			paramValues['dim2-sum-min'] = this.get('dim2-min-value');
			paramValues['dim2-sum-max'] = this.get('dim2-max-value');
			break;
		case 2:
			// Between components indexes
			paramValues['dim2-sum-min'] = this.get('dim2-min-index');
			paramValues['dim2-sum-max'] = this.get('dim2-max-index');
			break;
	}
   	
bb6e93d9   Benjamin Renard   Implement templat...
172
173
174
175
176
    	paramValues['type'] = this.get('type');
    	
    	if (this.get('template_args') != null) {
    		paramValues['template_args'] = new Object();
    		Ext.Object.each(this.get('template_args'), function (argKey, argValue) {
3ad6d2e1   Benjamin Renard   Fix boolean argum...
177
178
179
180
181
182
			if (typeof(argValue) === "boolean") {
				paramValues['template_args'][argKey] = (argValue ? 1 : 0);
			}
			else {
    				paramValues['template_args'][argKey] = argValue;
			}
bb6e93d9   Benjamin Renard   Implement templat...
183
184
185
186
187
188
    		});
    	}
    	
    	return paramValues;
    }
      
3ad6d2e1   Benjamin Renard   Fix boolean argum...
189
});