[IMP] invert tests and bail out early in order to reduce excessive nesting of functions

bzr revid: xmo@openerp.com-20110617133156-g3fk9f386tdrdcje
This commit is contained in:
Xavier Morel 2011-06-17 15:31:56 +02:00
parent 5e516e5331
commit 872f7e163d
1 changed files with 50 additions and 53 deletions

View File

@ -91,56 +91,52 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
schedule_chart: function(results) {
this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'view_id': this.view_id}));
if (results.length){
_.each(results, function (result) {
_.each(result, function (field_value, field_name) {
if (typeof field_value == 'object') {
result[field_name] = field_value[field_value.length - 1];
}
if (typeof field_value == 'string'){
var choices = this.all_fields[field_name]['selection'];
_.each(choices, function (choice) {
if(field_value == choice[0]){
result[field_name] = choice;
}
});
}
}, this);
}, this);
var opration_fld = {};
_.each(results, function (result) {
var gen_key = result[this.chart_info_fields]+"_"+result[this.group_field];
var map_val = {};
if (opration_fld[gen_key] == undefined){
map_val[this.operator_field] = result[this.operator_field];
if (this.operator.length > 1){
map_val[this.operator_field_one] = result[this.operator_field_one];
}
map_val[this.chart_info_fields] = result[this.chart_info_fields];
if (this.group_field){
map_val[this.group_field] = (typeof result[this.group_field] == 'object')?result[this.group_field][1]:result[this.group_field];
}
} else {
map_val = opration_fld[gen_key];
map_val[this.operator_field] += result[this.operator_field];
if (this.operator.length > 1){
map_val[this.operator_field_one] += result[this.operator_field_one];
}
if (!results.length) {
return;
}
_.each(results, function (result) {
_.each(result, function (field_value, field_name) {
if (typeof field_value == 'object') {
result[field_name] = field_value[field_value.length - 1];
}
if (typeof field_value == 'string') {
var choices = this.all_fields[field_name]['selection'];
_.each(choices, function (choice) {
if (field_value == choice[0]) {
result[field_name] = choice;
}
});
}
opration_fld[gen_key] = map_val;
}, this);
}, this);
var graph_data = [];
_.each(opration_fld, function (column_data) {
graph_data.push(column_data);
});
if(this.chart == 'bar') {
return this.schedule_bar(graph_data);
} else if(this.chart == "pie") {
return this.schedule_pie(graph_data);
var opration_fld = {};
_.each(results, function (result) {
var gen_key = result[this.chart_info_fields] + "_" + result[this.group_field];
var map_val = {};
if (opration_fld[gen_key] == undefined) {
map_val[this.operator_field] = result[this.operator_field];
if (this.operator.length > 1) {
map_val[this.operator_field_one] = result[this.operator_field_one];
}
map_val[this.chart_info_fields] = result[this.chart_info_fields];
if (this.group_field) {
map_val[this.group_field] = (typeof result[this.group_field] == 'object') ? result[this.group_field][1] : result[this.group_field];
}
} else {
map_val = opration_fld[gen_key];
map_val[this.operator_field] += result[this.operator_field];
if (this.operator.length > 1) {
map_val[this.operator_field_one] += result[this.operator_field_one];
}
}
opration_fld[gen_key] = map_val;
}, this);
if (this.chart == 'bar') {
return this.schedule_bar(_.values(opration_fld));
} else if (this.chart == "pie") {
return this.schedule_pie(_.values(opration_fld));
}
},
@ -158,18 +154,19 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
}
_.each(results, function (result) {
if (self.group_field && (this.operator.length <= 1)){
if (self.group_field && (this.operator.length <= 1)) {
newkey = result[self.group_field].split(' ').join('_');
} else {
newkey = "val";
}
if (jQuery.inArray(newkey, group_list) == -1){
group_list.push(newkey);
if(this.operator.length > 1){
newkey_one = "val1";
group_list.push(newkey_one);
}
if (_.contains(group_list, newkey)) {
return;
}
group_list.push(newkey);
if (this.operator.length > 1) {
newkey_one = "val1";
group_list.push(newkey_one);
}
}, this);