From 3655f8002105861e66bb120eca60861bbef72b4a Mon Sep 17 00:00:00 2001 From: sslypushenko Date: Thu, 16 Oct 2014 18:35:04 +0300 Subject: [PATCH] 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 --- capabilities.html | 24 ++-- js/helpers.js | 293 ++++++++++++++++++++++++++-------------------- 2 files changed, 180 insertions(+), 137 deletions(-) diff --git a/capabilities.html b/capabilities.html index 6350a6db..b723df95 100644 --- a/capabilities.html +++ b/capabilities.html @@ -9,8 +9,6 @@

{{release}} Tracked Capabilities

+ - +
- + + +
@@ -80,4 +82,4 @@
Copyright OpenStack Foundation, 2014. Apache 2 License.
- + diff --git a/js/helpers.js b/js/helpers.js index 0d1c00c4..f95a5b1f 100644 --- a/js/helpers.js +++ b/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( ' [github] ' ); -} - -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(); +}; \ No newline at end of file