Commit 734fbc3c authored by Flavio TARSETTI's avatar Flavio TARSETTI

[reports] new added items are now dynamic. This patch fixes

adding/removing items as well as item numbering Fixes #320
parent 3785178d
Pipeline #298 passed with stage
......@@ -276,8 +276,8 @@ app.controller('reportController',['$scope', 'reportFactory', 'experimentFactory
{
a = a.split("_");
b = b.split("_");
a_num = parseInt(a[a.length-1]);
b_num = parseInt(b[b.length-1]);
a_num = parseInt(a[a.length-1]) || -1;
b_num = parseInt(b[b.length-1]) || -1;
return a_num - b_num;
});
......
......@@ -165,11 +165,34 @@ app.directive("addreportitem", function($compile)
{
scope.$on("addSavedElement", function(event, id_content, type)
{
var num_tables_in_content = 0;
var num_figures_in_content = 0;
for(var i = 0; i < Object.keys(scope.report.content).length; i++)
{
if(Object.keys(scope.report.content)[i].indexOf("table_") == 0)
{
num_tables_in_content++;
}
else if(Object.keys(scope.report.content)[i].indexOf("chart_") == 0)
{
num_figures_in_content++;
}
}
if(type == "table")
{
var table_id = id_content;
var table_details = undefined;
var table_details = scope.report.content[id_content];
//take the one with more elements
if(Object.keys(scope.tables_details).length > num_tables_in_content)
{
table_details = scope.tables_details[id_content];
}
else
{
table_details = scope.report.content[id_content];
}
var name_to_remove = "experiment";
for(var i = 0; i < table_details.length; i++)
......@@ -207,19 +230,34 @@ app.directive("addreportitem", function($compile)
var content_detail = {};
var chart_id = id_content;
content_detail["name"] = scope.report.content[chart_id].data.output[0];
var plot_details = undefined;
//take the one with more elements
if(Object.keys(scope.plots_details).length > num_figures_in_content)
{
plot_details = scope.plots_details[chart_id];
}
else
{
plot_details = scope.report.content[chart_id];
}
content_detail["name"] = plot_details.data.output[0];
//content_detail["description"] = scope.report.content[chart_id].data.plotter;
if(scope.report.content[chart_id].data.plotter != undefined)
if(plot_details.data.plotter != undefined)
{
content_detail["selected_plotter"] = scope.report.content[chart_id].data.plotter;
content_detail["selected_plotter"] = plot_details.data.plotter;
}
if(scope.report.content[chart_id].data.parameter != undefined)
if(plot_details.data.parameter != undefined)
{
content_detail["selected_template"] = scope.report.content[chart_id].data.parameter;
content_detail["selected_template"] = plot_details.data.parameter;
}
if(scope.report.content[chart_id].data.merged != undefined)
if(plot_details.data.merged != undefined)
{
content_detail["merged"] = scope.report.content[chart_id].data.merged;
content_detail["merged"] = plot_details.data.merged;
}
var html_div_code = '<div class="panel panel-default" id="' + chart_id + '"><div class="panel-heading" role="tab"><h4 class="panel-title"><a role="button" data-toggle="collapse" data-parent="#info-heading" href="#collapse-' + chart_id + '" aria-expanded="true" aria-controls="collapse-info"><i class="fa fa-area-chart"> ' + content_detail.name + '</i></a></h4></div><div id="collapse-' + chart_id + '" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="info-heading"><div id="'+chart_id+'" class="panel-body chart {$ report.status $}"></div></div></div>';
......@@ -410,6 +448,7 @@ app.directive("addreportitem", function($compile)
angular.element(document.getElementById('space-for-report-items')).append($compile(html_div_code)(scope));
scope.report.orderedcontent.push(table_id);
scope.num_report_items++;
}
}
......@@ -639,6 +678,7 @@ app.directive("addreportitem", function($compile)
angular.element(document.getElementById('space-for-report-items')).append($compile(element)(scope));
_retrieve_chart(scope, sub_content, element);
scope.report.orderedcontent.push(chart_id);
break;
}
......@@ -1690,7 +1730,7 @@ app.directive("aliasexperiment", function($compile)
var id_content = parent_scope.report.orderedcontent[i];
var type = id_content.split("_")[0];
parent_scope.$broadcast("addSavedElement", id_content, type);
parent_scope.$parent.$broadcast("addSavedElement", id_content, type);
}
}
}
......
......@@ -459,6 +459,15 @@ beat.ui.report.remove_item = function(dialog_id, elementToRemove, scope)
delete scope.plots_details[elementToRemove.id];
}
var index = scope.report.orderedcontent.indexOf(elementToRemove.id);
if(index > -1)
{
scope.report.orderedcontent.splice(index, 1);
}
delete scope.report.content[elementToRemove.id];
$("#" + elementToRemove.id).remove();
$('#' + dialog_id).dialog("close");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment