Report page prototype
This patch provides templates (Jinja-like) for single test run report and for comparison of two test runs. By default these templates display demo results. https://storyboard.openstack.org/#!/story/111 Change-Id: Icde3559216d3a7a38c7a8e6a54e7a53300d309e9
This commit is contained in:
parent
fbc79cfdb4
commit
3655f80021
@ -9,8 +9,6 @@
|
||||
<h2> {{release}} Tracked Capabilities</h2>
|
||||
</script>
|
||||
<script id="capabilities_template" type="x-tmpl-mustache">
|
||||
|
||||
|
||||
{{#capabilities}}
|
||||
<ul>
|
||||
<li> <a onclick="$('#{{class}}_tests').toggle(500);return false;" href="#"> {{class}} capabilities ({{count}} of {{total}} total) </a>
|
||||
@ -25,10 +23,10 @@
|
||||
<li>Achievements (met {{achievements_count}} of {{criteria_count}} total): {{#achievements}} <a href="#{{.}}">{{.}}</a> {{/achievements}}
|
||||
{{#admin}}<li>Admin rights required</li>{{/admin}}
|
||||
{{#core}}<li>Core test</li>{{/core}}</li>
|
||||
<li> <a onclick="$('#{{name}}').toggle(500);return false;" href="#"> Tests ({{tests_count}}) </a>
|
||||
<div id="{{name}}" style="display:none;">
|
||||
<li> <a onclick="toggle_one_item('{{class}}', '{{id}}', 'tests_list');return false;" href="#"> Tests ({{tests_count}}) </a>
|
||||
<div id="{{id}}_tests_list" class="{{class}}_tests_list" style="display:none;">
|
||||
<ul>
|
||||
{{#tests}} <li> {{.}} {{#code_url}} {{.}} {{/code_url}} </li> {{/tests}}
|
||||
{{#tests}} <li> {{.}} <a href="javascript:void(get_code_url('{{.}}'));"> [github] </a> </li> {{/tests}}
|
||||
</ul>
|
||||
<div>
|
||||
</li>
|
||||
@ -58,19 +56,23 @@
|
||||
{{/criteria}}
|
||||
</script>
|
||||
<script src="/js/helpers.js"></script>
|
||||
<script>
|
||||
window.render_page = function(){render_capabilities_page()};
|
||||
$(document).ready(window.render_page);
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="header"></div>
|
||||
|
||||
<input id="only_core" name="only_core" type="checkbox" checked onclick="create_caps()" />
|
||||
<input id="only_core" name="only_core" type="checkbox" checked onclick="render_page()" />
|
||||
<label for="only_core">Show only core tests</label>
|
||||
<br>
|
||||
<select id="admin" onclick="create_caps()">
|
||||
<option>All tests</option>
|
||||
<option>Tests require admin rights</option>
|
||||
<option>Tests don't require admin rights</option>
|
||||
<select id="admin" onchange="render_page()">
|
||||
<option value="all" >All tests</option>
|
||||
<option value="admin" >Tests require admin rights</option>
|
||||
<option value="noadmin">Tests don't require admin rights</option>
|
||||
</select>
|
||||
<div id="capabilities"></div>
|
||||
|
||||
@ -80,4 +82,4 @@
|
||||
|
||||
<div>Copyright OpenStack Foundation, 2014. Apache 2 License.</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
293
js/helpers.js
293
js/helpers.js
@ -1,140 +1,181 @@
|
||||
function has_upper_case(str) {
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
// not use this file except in compliance with the License. You may obtain
|
||||
// a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
/*global $:false */
|
||||
/*global Mustache:false */
|
||||
/*global window:false */
|
||||
/*global document:false */
|
||||
/*jslint devel: true*/
|
||||
/* jshint -W097 */
|
||||
/*jslint node: true */
|
||||
|
||||
'use strict';
|
||||
|
||||
var has_upper_case = function (str) {
|
||||
return (/[A-Z]/.test(str));
|
||||
}
|
||||
};
|
||||
|
||||
function capitaliseFirstLetter(string){
|
||||
var capitaliseFirstLetter = function (string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
};
|
||||
|
||||
function code_url(text, render){
|
||||
return render( '<a href="javascript:void(get_code_url(\'' +
|
||||
text + '\'));"> [github] </a>' );
|
||||
}
|
||||
|
||||
function get_code_url (test_id) {
|
||||
var id = test_id.split('/').join('.');
|
||||
var parts = id.split('.');
|
||||
var path_array = [];
|
||||
for (var i in parts){
|
||||
if (has_upper_case(parts[i])) { break }
|
||||
path_array.push(parts[i])
|
||||
}
|
||||
// Function searches for test with specified test_id on github and opens result in new window
|
||||
var get_code_url = function (test_id) {
|
||||
var id = test_id.split('/').join('.'),
|
||||
parts = id.split('.'),
|
||||
path_array = [],
|
||||
path,
|
||||
test,
|
||||
url;
|
||||
$(parts).each(function (i, part) {
|
||||
if (has_upper_case(part)) {return false; }
|
||||
path_array.push(part);
|
||||
});
|
||||
path_array.pop();
|
||||
var path = path_array.join('/');
|
||||
var test = parts.slice(-1)[0] + '(';
|
||||
path = path_array.join('/');
|
||||
test = parts.slice(-1)[0] + '(';
|
||||
test = test.replace(/\s+/g, '');
|
||||
path = path.replace(/\s+/g, '');
|
||||
var url = 'https://api.github.com/search/code?q=' + test +
|
||||
url = 'https://api.github.com/search/code?q=' + test +
|
||||
' repo:openstack/tempest extension:py path:' + path;
|
||||
console.log(url);
|
||||
$.when($.ajax({type: 'GET', url: url, dataType: 'json'})).done(
|
||||
function (data, status, xhr) {
|
||||
if (data['items'].length < 1) {
|
||||
alert('No test found !')
|
||||
}
|
||||
var html_url = data['items'][0]['html_url'];
|
||||
console.log(data['items'][0]['git_url']);
|
||||
$.when($.ajax({type: 'GET', url: data['items'][0]['git_url'], dataType: 'json'})).done(
|
||||
function (data, status, xhr) {
|
||||
var content = window.atob(data['content'].replace(/\s+/g, '')).split('\n');
|
||||
for (var i in content) {
|
||||
if (content[i].indexOf(test) > -1) {
|
||||
var line = parseInt(i) + 1;
|
||||
var url = html_url + '#L' + line;
|
||||
var win = window.open(url, '_blank');
|
||||
win.focus();
|
||||
}
|
||||
}
|
||||
function (data, status, xhr) {
|
||||
if (data.items.length < 1) {
|
||||
alert('No test found !');
|
||||
}
|
||||
var html_url = data.items[0].html_url;
|
||||
console.log(data.items[0].git_url);
|
||||
$.when($.ajax({type: 'GET', url: data.items[0].git_url, dataType: 'json'})).done(
|
||||
function (data, status, xhr) {
|
||||
var content = window.atob(data.content.replace(/\s+/g, '')).split('\n');
|
||||
content.forEach(function (line, i) {
|
||||
if (line.indexOf(test) > -1) {
|
||||
var github_url = html_url + '#L' + i.toString(),
|
||||
win = window.open(github_url, '_blank');
|
||||
win.focus();
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
}
|
||||
function render_header(data){
|
||||
var template = $('#header_template').html();
|
||||
data["release"] = capitaliseFirstLetter(data["release"]);
|
||||
var rendered = Mustache.render(template, data);
|
||||
$("div#header").html(rendered);
|
||||
}
|
||||
|
||||
function render_caps(only_core, admin_filter, data){
|
||||
var template = $('#capabilities_template').html();
|
||||
var criteria_count = Object.keys(data['criteria']).length;
|
||||
var caps_dict = {'capabilities': {}};
|
||||
var capabilities_count = 0;
|
||||
for(var id in data['capabilities']){
|
||||
var capability = data['capabilities'][id];
|
||||
capability['class'] = id.split('-')[0];
|
||||
capability['id'] = id;
|
||||
if (!(capability['class'] in caps_dict['capabilities'])){
|
||||
caps_dict['capabilities'][capability['class']] = {
|
||||
'items': [],
|
||||
'total': 0
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
caps_dict['capabilities'][capability['class']]['total'] += 1;
|
||||
if (only_core == true && (capability['core'] !== true)) {continue}
|
||||
if (admin_filter == 'Tests require admin rights' && (capability['admin'] !== true)) {continue}
|
||||
if (admin_filter == "Tests don't require admin rights" && (capability['admin'] == true)) {continue}
|
||||
capability['code_url'] = function(){
|
||||
return code_url
|
||||
);
|
||||
};
|
||||
|
||||
// Function builds list of capabilities from json schema and applies filters to this list
|
||||
var build_caps_list = function (data, filters) {
|
||||
var criteria_count = Object.keys(data.criteria).length,
|
||||
caps_dict = {'capabilities': {}},
|
||||
caps_list = {
|
||||
'release': data.release,
|
||||
'capabilities': [],
|
||||
'criteria_count': criteria_count,
|
||||
'global_test_list': [],
|
||||
"scope_tests_list": []
|
||||
};
|
||||
capability['achievements_count'] = capability['achievements'].length;
|
||||
capability['tests_count'] = capability['tests'].length;
|
||||
caps_dict['capabilities'][capability['class']]['items'].push(capability)
|
||||
}
|
||||
var caps_list={
|
||||
'capabilities': [],
|
||||
'criteria_count': criteria_count
|
||||
};
|
||||
for (var cls in caps_dict['capabilities']){
|
||||
if (caps_dict['capabilities'][cls]['items'].length == 0) {
|
||||
continue
|
||||
}
|
||||
caps_list['capabilities'].push({
|
||||
'class': cls,
|
||||
'items': caps_dict['capabilities'][cls]['items'],
|
||||
'count': caps_dict['capabilities'][cls]['items'].length,
|
||||
'total': caps_dict['capabilities'][cls]['total']
|
||||
})
|
||||
}
|
||||
var rendered = Mustache.render(template, caps_list);
|
||||
|
||||
$("div#capabilities").html(rendered);
|
||||
}
|
||||
|
||||
function render_criteria(data){
|
||||
var template = $('#criteria_template').html();
|
||||
var crits = {'criteria': []};
|
||||
for(var tag in data['criteria']){
|
||||
var criterion = data['criteria'][tag];
|
||||
criterion['tag'] = tag;
|
||||
crits['criteria'].push(criterion);
|
||||
}
|
||||
var rendered = Mustache.render(template, crits);
|
||||
|
||||
$("ul#criteria").html(rendered);
|
||||
}
|
||||
|
||||
function create_caps() {
|
||||
|
||||
if (document.getElementById('only_core')){
|
||||
only_core = document.getElementById('only_core').checked
|
||||
}
|
||||
else only_core = true;
|
||||
if (document.getElementById('admin')){
|
||||
admin_filter = document.getElementById('admin').value
|
||||
}
|
||||
else admin_filter = 'All tests';
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: 'json',
|
||||
url: 'havanacore.json',
|
||||
success: function(data, status, xhr) {
|
||||
render_caps(only_core, admin_filter, data);
|
||||
render_criteria(data);
|
||||
render_header(data)
|
||||
$.each(data.capabilities, function (id, capability) {
|
||||
capability.class = id.split('-')[0];
|
||||
capability.id = id;
|
||||
if (!(caps_dict.capabilities.hasOwnProperty(capability.class))) {
|
||||
caps_dict.capabilities[capability.class] = {
|
||||
'items': [],
|
||||
'total': 0
|
||||
};
|
||||
}
|
||||
capability.tests.forEach(function (test) {
|
||||
if (caps_list.global_test_list.indexOf(test) < 0) {
|
||||
caps_list.global_test_list.push(test);
|
||||
}
|
||||
});
|
||||
caps_dict.capabilities[capability.class].total += 1;
|
||||
if (filters.only_core === true && (capability.core !== true)) {return; }
|
||||
if (filters.admin_filter === 'admin' && (capability.admin !== true)) {return; }
|
||||
if (filters.admin_filter === 'noadmin' && (capability.admin === true)) {return; }
|
||||
capability.tests.forEach(function (test) {
|
||||
if (caps_list.scope_tests_list.indexOf(test) < 0) {
|
||||
caps_list.scope_tests_list.push(test);
|
||||
}
|
||||
});
|
||||
capability.achievements_count = capability.achievements.length;
|
||||
capability.tests_count = capability.tests.length;
|
||||
caps_dict.capabilities[capability.class].items.push(capability);
|
||||
});
|
||||
}
|
||||
window.onload = create_caps();
|
||||
caps_list.scope_tests_count = caps_list.scope_tests_list.length;
|
||||
$.each(caps_dict.capabilities, function (class_id, cap_class) {
|
||||
if (cap_class.items.length === 0) {return; }
|
||||
caps_list.capabilities.push({
|
||||
'class': class_id,
|
||||
'items': cap_class.items,
|
||||
'count': cap_class.items.length,
|
||||
'total': cap_class.total
|
||||
});
|
||||
});
|
||||
return caps_list;
|
||||
};
|
||||
|
||||
//Get admin and core filter values
|
||||
var get_filters_local = function () {
|
||||
if (document.getElementById('only_core')) {
|
||||
window.only_core = document.getElementById('only_core').checked;
|
||||
} else {
|
||||
window.only_core = true;
|
||||
}
|
||||
if (document.getElementById('admin')) {
|
||||
window.admin_filter = document.getElementById('admin').value;
|
||||
} else {
|
||||
window.admin_filter = 'all';
|
||||
}
|
||||
return {only_core: window.only_core, admin_filter: window.admin_filter};
|
||||
};
|
||||
|
||||
//Rendering page header
|
||||
var render_header = function (data) {
|
||||
var template = $('#header_template').html();
|
||||
data.release = capitaliseFirstLetter(data.release);
|
||||
$("div#header").html(Mustache.render(template, data));
|
||||
};
|
||||
|
||||
//Rendeirng capabilities list
|
||||
var render_caps = function (data) {
|
||||
var filters = get_filters_local(),
|
||||
template = $('#capabilities_template').html(),
|
||||
caps_list = build_caps_list(data, filters),
|
||||
rendered = Mustache.render(template, caps_list);
|
||||
$("div#capabilities").html(rendered);
|
||||
};
|
||||
|
||||
//Rendering criteria section
|
||||
var render_criteria = function (data) {
|
||||
var template = $('#criteria_template').html(),
|
||||
crits = {'criteria': []};
|
||||
$.map(data.criteria, function (criterion, tag) {
|
||||
criterion.tag = tag;
|
||||
crits.criteria.push(criterion);
|
||||
});
|
||||
|
||||
$("ul#criteria").html(Mustache.render(template, crits));
|
||||
};
|
||||
|
||||
//Rendering page
|
||||
var render_capabilities_page = function () {
|
||||
$.get('capabilities/havanacore.json').done(function (data) {
|
||||
render_caps(data);
|
||||
render_criteria(data);
|
||||
render_header(data);
|
||||
});
|
||||
};
|
||||
|
||||
//Helper for toggling one item in list
|
||||
var toggle_one_item = function (klass, id, postfix) {
|
||||
$('div.' + klass + '_' + postfix + ':not(div#' + id + '_' + postfix + ')').slideUp();
|
||||
$('div#' + id + '_' + postfix).slideToggle();
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user