[llvm-commits] [LNT] r155714 - in /lnt/trunk/lnt/server/ui: static/v4_summary_report_ui.js templates/v4_summary_report_ui.html views.py
Daniel Dunbar
daniel at zuster.org
Fri Apr 27 09:06:20 PDT 2012
Author: ddunbar
Date: Fri Apr 27 11:06:20 2012
New Revision: 155714
URL: http://llvm.org/viewvc/llvm-project?rev=155714&view=rev
Log:
[Summary Report] Add a simple but functional UI for defining the summary report.
Added:
lnt/trunk/lnt/server/ui/static/v4_summary_report_ui.js
lnt/trunk/lnt/server/ui/templates/v4_summary_report_ui.html
Modified:
lnt/trunk/lnt/server/ui/views.py
Added: lnt/trunk/lnt/server/ui/static/v4_summary_report_ui.js
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/static/v4_summary_report_ui.js?rev=155714&view=auto
==============================================================================
--- lnt/trunk/lnt/server/ui/static/v4_summary_report_ui.js (added)
+++ lnt/trunk/lnt/server/ui/static/v4_summary_report_ui.js Fri Apr 27 11:06:20 2012
@@ -0,0 +1,139 @@
+// Register our initialization function.
+window.onload = function() { init(); }
+
+var g = {};
+
+// These values are set up by the template.
+g.config = g.all_orders = g.all_machines = g.save_url = null;
+
+// Save the current configuration.
+function save_config() {
+ $.post(g.save_url, { 'config' : JSON.stringify(g.config) },
+ function (data) {});
+}
+
+// Initialization function.
+function init() {
+ // Initialize some globals.
+ g.selected_order = null;
+ g.selected_order_index = null;
+
+ // Initialize the "report order" list.
+ var order_list = $('#report-order-list');
+ order_list.empty();
+ g.list_items = []
+ for (var i = 0; i != g.config.orders.length; ++i) {
+ var order = g.config.orders[i];
+ var name = order[0];
+ var item = $('<li class="list-item"></li>');
+ g.list_items.push(item);
+
+ // Add the item contents.
+ item.append(name);
+
+ // Add a click event handler to select this item.
+ item.click(function(index) {
+ return function() { select_order(index); }; }(i));
+
+ order_list.append(item);
+ }
+
+ // Initialize the selected order items.
+ select_order(0);
+
+ // Initialize the machines list.
+ var machines = $('#report-machines');
+ machines.empty();
+ var machine_select = $('<select multiple="multiple" size="10"></select>');
+ for (var i = 0; i != g.all_machines.length; ++i) {
+ var selected_str = '';
+ if ($.inArray(g.all_machines[i], g.config.machine_names) != -1)
+ selected_str = ' selected';
+ machine_select.append('<option value="' + i.toString() + '"' +
+ selected_str + '>' +
+ g.all_machines[i] +
+ '</option>');
+ }
+ machine_select.appendTo(machines);
+ machine_select.change(function() { update_machine_items(machine_select[0]); });
+}
+
+// Add a new report order entry.
+function add_order() {
+ var order = ['(New Order)', []];
+ g.config.orders.push(order);
+ init();
+}
+
+// Delete a report order entry.
+function delete_order(index) {
+ g.config.orders.splice(index, 1);
+ init();
+}
+
+// Update the selected order name.
+function update_selected_order_name(name_elt) {
+ g.selected_order[0] = name_elt.value;
+
+ var item = g.list_items[g.selected_order_index];
+ item.empty();
+ item.append(g.selected_order[0]);
+}
+
+// Update the selected orders for the active items.
+function update_selected_order_items(select_elt) {
+ g.selected_order[1] = [];
+ for (var i = 0; i != select_elt.options.length; ++i) {
+ var option = select_elt.options[i];
+ if (option.selected)
+ g.selected_order[1].push(g.all_orders[option.value]);
+ }
+}
+
+// Update the machine list.
+function update_machine_items(select_elt) {
+ // We don't support a UI for machine patterns yet.
+ g.config.machine_patterns = [];
+
+ g.config.machine_names = [];
+ for (var i = 0; i != select_elt.options.length; ++i) {
+ var option = select_elt.options[i];
+ if (option.selected)
+ g.config.machine_names.push(g.all_machines[option.value]);
+ }
+}
+
+// Select a report order entry to edit.
+function select_order(index) {
+ g.selected_order_index = index;
+ g.selected_order = g.config.orders[index];
+
+ var elt = $('#report-order-items');
+ elt.empty();
+
+ var name_elt = $('<input type="text" value="' + g.selected_order[0] + '">');
+ name_elt.appendTo(elt);
+ name_elt.change(function() { update_selected_order_name(name_elt[0]) });
+
+ elt.append('<br>');
+ var order_select = $('<select multiple="multiple" size="10"></select>');
+ for (var i = 0; i != g.all_orders.length; ++i) {
+ var selected_str = '';
+ if ($.inArray(g.all_orders[i], g.selected_order[1]) != -1)
+ selected_str = ' selected';
+ order_select.append('<option value="' + i.toString() + '"' +
+ selected_str + '>' +
+ g.all_orders[i] +
+ '</option>');
+ }
+ order_select.appendTo(elt);
+ order_select.change(function() {
+ update_selected_order_items(order_select[0]);
+ });
+
+ elt.append('<br>')
+
+ var del_button = $('<input type="button" value="Delete Order">');
+ del_button.click(function() { delete_order(index); });
+ del_button.appendTo(elt);
+}
Added: lnt/trunk/lnt/server/ui/templates/v4_summary_report_ui.html
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/templates/v4_summary_report_ui.html?rev=155714&view=auto
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/v4_summary_report_ui.html (added)
+++ lnt/trunk/lnt/server/ui/templates/v4_summary_report_ui.html Fri Apr 27 11:06:20 2012
@@ -0,0 +1,67 @@
+{% extends "layout.html" %}{
+{% set components = [("report", db_url_for("v4_summary_report"))] %}
+{% block head %}
+ <script src="{{ url_for('.static', filename='popup.js') }}"></script>
+ <script src="{{ url_for('.static',filename='json2.js')}}"></script>
+ <script language="javascript" type="text/javascript"
+ src="{{ url_for('.static',
+ filename='jquery/1.5/jquery.min.js') }}"></script>
+ <script src="{{ url_for('.static',filename='v4_summary_report_ui.js')}}"></script>
+
+<style>
+.ui-box {
+ border : 1px dashed #000;
+ padding : 3px;
+ margin : 20px;
+}
+
+.list {
+ list-style-type : none;
+ margin: 0;
+ padding : 0;
+}
+
+.list-item {
+ border : 1px solid #672;
+ padding : 1px;
+ margin : 2px;
+}
+</style>
+
+<script>
+g.config = {{ config|tojson(indent=2)|safe }};
+g.all_orders = {{ all_orders|tojson(indent=2)|safe }};
+g.all_machines = {{ all_machines|tojson(indent=2)|safe }};
+g.save_url = {{ db_url_for("v4_summary_report_ui")|tojson|safe }};
+</script>
+{% endblock %}
+{% block title %}Summary Report Editor{% endblock %}
+{% block body %}
+
+<div>
+<div style="width : 250px; float : left;">
+ <h2><center>Report Orders</center></h2>
+ <div class="ui-box" style="width : 200px; height : 200px">
+ <ul class="list" id="report-order-list">
+ </ul>
+
+ <br>
+ <input type="button" value="Add" onclick="add_order();">
+ </div>
+</div>
+<div style="width : 250px; float : left;">
+ <h2><center>Order Items</center></h2>
+ <div class="ui-box" style="width : 200px; height : 200px;" id="report-order-items">
+ </div>
+</div>
+<div style="width : 280px; float : left;">
+ <h2><center>Machines</center></h2>
+ <div class="ui-box" style="width : 230px; height : 200px" id="report-machines">
+ </div>
+</div>
+<br style="clear: left;" />
+</div>
+
+<input type="button" value="Save" onclick="save_config();">
+
+{% endblock %}
Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=155714&r1=155713&r2=155714&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Fri Apr 27 11:06:20 2012
@@ -1076,6 +1076,51 @@
return os.path.join(current_app.old_config.tempDir,
'summary_report_config.json')
+ at db_route("/summary_report/edit", only_v3=False, methods=('GET', 'POST'))
+def v4_summary_report_ui():
+ # If this is a POST request, update the saved config.
+ if request.method == 'POST':
+ # Parse the config data.
+ config_data = request.form.get('config')
+ config = flask.json.loads(config_data)
+
+ # Write the updated config.
+ with open(get_summary_config_path(), 'w') as f:
+ flask.json.dump(config, f, indent=2)
+
+ # Redirect to the summary report.
+ return redirect(db_url_for("v4_summary_report"))
+
+ config_path = get_summary_config_path()
+ if os.path.exists(config_path):
+ with open(config_path) as f:
+ config = flask.json.load(f)
+ else:
+ config = {}
+
+ # Get the list of available test suites.
+ testsuites = request.get_db().testsuite.values()
+
+ # Gather the list of all run orders and all machines.
+ def to_key(name):
+ first = name.split('.', 1)[0]
+ if first.isdigit():
+ return (int(first), name)
+ return (first, name)
+ all_machines = set()
+ all_orders = set()
+ for ts in testsuites:
+ for name, in ts.query(ts.Machine.name):
+ all_machines.add(name)
+ for name, in ts.query(ts.Order.llvm_project_revision):
+ all_orders.add(name)
+ all_machines = sorted(all_machines)
+ all_orders = sorted(all_orders, key=to_key)
+
+ return render_template("v4_summary_report_ui.html",
+ config=config, all_machines=all_machines,
+ all_orders=all_orders)
+
@db_route("/summary_report", only_v3=False)
def v4_summary_report():
# FIXME: Add a UI for defining the report configuration.
More information about the llvm-commits
mailing list