Lint js and css files

This commit lints js file of the project, fixing all of the errors
reported by eslint. Makes indentation consistent.
Marks 'camelcase' rule as warning (will be fixed in a separate commit,
after making sure, that none of them are required in html
Also fixes a typo in css.

Change-Id: If53345cb8dd100dac352c0e53c1a0093d3f0c1b9
This commit is contained in:
Kirill Zaitsev 2015-07-29 00:59:14 +03:00
parent 9d7a3a58d0
commit 9fac22bc82
3 changed files with 253 additions and 233 deletions

View File

@ -4,3 +4,10 @@ extends: openstack
env:
# browser global variables.
browser: true
rules:
# Require camel case names
# http://eslint.org/docs/rules/camelcase
camelcase:
- 1 # report camelcase properties as warnings
- properties: "never"

View File

@ -25,7 +25,7 @@ a {
.navbar {
margin: 0;
border-radius: 0;
border: none:
border: none;
}
.navbar-brand {
width: 136px;

View File

@ -1,55 +1,63 @@
function getUrlVars() {
"use strict";
var vars = {};
var parts = window.location.href.replace(/[?&#]+([^=&]+)=([^&#]*)/gi, function (m, key, value) {
window.location.href.replace(/[?&#]+([^=&]+)=([^&#]*)/gi, function (m, key, value) {
vars[key] = decodeURIComponent(value);
});
return vars;
}
function make_uri(uri, options) {
"use strict";
var ops = {};
$.extend(ops, getUrlVars());
if (options != null) {
if (options !== null) {
$.extend(ops, options);
}
var str = $.map(ops, function (val, index) {
return index + "=" + encodeURIComponent(val).toLowerCase();
}).join("&");
return (str == "") ? uri : uri + "?" + str;
return (str === "") ? uri : uri + "?" + str;
}
function reload(extra) {
"use strict";
window.location.search = make_uri ("", extra);
}
function update_url(extra) {
var ops = {};
$.extend(ops, getUrlVars ());
if (extra != null) {
if (extra !== null) {
$.extend(ops, extra);
}
window.location.hash = $.map(ops, function (val, index) {
return val ? (index + "=" + encodeURIComponent(val)) : null;
}).join("&")
}).join("&");
}
function initSingleSelector(selector_id, property, dataSet, update_handler) {
var values = {};
var result = [];
var value, key;
for (var i = 0; i < dataSet.length; i++) {
var element = dataSet[i][property];
if (element instanceof Array) {
for (var key in element)
for (key in element)
if (key) {
values[element[key]] = element[key];
} else
}
} else {
values[element] = element;
}
}
var result = [];
for (var value in values)
if (value)
for (value in values)
if (value) {
result.push({"id": value, "text": value});
}
$("#" + selector_id).
val (getUrlVars()[property]).
@ -70,26 +78,30 @@ function initSingleSelector(selector_id, property, dataSet, update_handler) {
function filterData (tableData, filters) {
var filteredData = [];
var key, column;
for (var i = 0; i < tableData.length; i++) {
var row = tableData[i];
var filtered = true;
for (var column in filters) {
for (column in filters) {
if (column in row) {
if (row[column] instanceof Array) {
filtered = false;
for (var key in row[column])
if (filters[column] == row[column][key])
for (key in row[column])
if (filters[column] == row[column][key]) {
filtered = true;
}
} else {
if (filters[column] != row[column])
if (filters[column] != row[column]) {
filtered = false;
}
}
if (filtered == false)
}
if (filtered == false) {
break;
}
}
if (filtered) {
filteredData.push(row);
@ -105,10 +117,11 @@ function populate_table (table_id, table_column_names, tableData)
for (var i = 0; i < table_column_names.length; i++) {
tableColumns.push({"mData": table_column_names[i]});
for (var j = 0; j < tableData.length; j++) {
if (!(table_column_names[i] in tableData[j]))
if (!(table_column_names[i] in tableData[j])) {
tableData[j][table_column_names[i]] = "";
}
}
}
if (table_id) {
$("#" + table_id).dataTable({
@ -147,7 +160,8 @@ function showInfoPage (tab, info)
}
function setupInfoHandler (tab, element_id, info) {
info.name_html = "<a id=\"" + tab +"-" + element_id + "\" href=\"#\" title=\"Show details\">" + info.name + "</a>";
info.name_html = "<a id=\"" + tab + "-" + element_id +
"\" href=\"#\" title=\"Show details\">" + info.name + "</a>";
$("#" + tab + "-table").on("click", "#" + tab + "-" + element_id, function (event) {
event.preventDefault();
@ -163,7 +177,7 @@ function show_glance_images ()
{
populate_table ("glance-images-table",
["name_html", "description", "disk_format", "license"],
filterData (glance_images["images"], getUrlVars ()));
filterData (glance_images.images, getUrlVars ()));
}
var heat_templates = { templates: [] };
@ -172,7 +186,7 @@ function show_heat_templates ()
{
populate_table ("heat-templates-table",
["name_html", "description", "release_html", "format"],
filterData (heat_templates["templates"], getUrlVars ()));
filterData (heat_templates.templates, getUrlVars ()));
}
var murano_apps = { applications: [] };
@ -181,7 +195,7 @@ function show_murano_apps ()
{
populate_table ("murano-apps-table",
["name_html", "description", "release_html", "format"],
filterData (murano_apps["applications"], getUrlVars ()));
filterData (murano_apps.applications, getUrlVars ()));
}
function initTabs ()
@ -200,13 +214,14 @@ function initTabs ()
function show_asset (tab, tableData)
{
var options = getUrlVars ();
if ((tab == options["tab"]) && ("asset" in options)) {
for (var i = 0; i < tableData.length; ++i)
if (tableData[i].name == options["asset"]) {
if ((tab == options.tab) && ("asset" in options)) {
for (var i = 0; i < tableData.length; ++i) {
if (tableData[i].name == options.asset) {
showInfoPage (tab, tableData[i]);
}
}
}
}
function initMarketPlace ()
{
@ -231,9 +246,8 @@ function initMarketPlace ()
try {
glance_images = jsyaml.safeLoad (data);
} catch (e) {
console.log ("Failed to load YAML\n" + data);
}
var tableData = glance_images["images"];
var tableData = glance_images.images;
for (var i = 0; i < tableData.length; i++) {
setupInfoHandler ("glance-images", i, tableData[i]);
}
@ -247,9 +261,8 @@ function initMarketPlace ()
try {
heat_templates = jsyaml.safeLoad (data);
} catch (e) {
console.log ("Failed to load YAML\n" + data);
}
var tableData = heat_templates["templates"];
var tableData = heat_templates.templates;
for (var i = 0; i < tableData.length; i++) {
tableData[i].release_html = tableData[i].release.join (", ");
setupInfoHandler ("heat-templates", i, tableData[i]);
@ -266,9 +279,8 @@ function initMarketPlace ()
try {
murano_apps = jsyaml.safeLoad (data);
} catch (e) {
console.log ("Failed to load YAML\n" + e);
}
var tableData = murano_apps["applications"];
var tableData = murano_apps.applications;
for (var i = 0; i < tableData.length; i++) {
tableData[i].release_html = tableData[i].release.join (", ");
setupInfoHandler ("murano-apps", i, tableData[i]);
@ -291,10 +303,11 @@ function navigate ()
if ("tab" in options) {
for (var i = 0; i < tabs_list.length; ++i) {
var tab_name = tabs_list[i].children[0].hash.substring (1);
if (tab_name == options["tab"]) {
if (tab_name == options.tab) {
selected_tab_name = tab_name;
if (!("asset" in options))
if (!("asset" in options)) {
tabs_list[i].className = "active";
}
break;
}
}
@ -302,15 +315,15 @@ function navigate ()
$( ".content" ).hide ();
if (selected_tab_name == null) {
if (selected_tab_name === null) {
$( "#landing-page" ).show ();
} else if ("asset" in options) {
show_asset ("murano-apps", murano_apps["applications"]);
show_asset ("heat-templates", heat_templates["templates"]);
show_asset ("glance-images", glance_images["images"]);
show_asset ("murano-apps", murano_apps.applications);
show_asset ("heat-templates", heat_templates.templates);
show_asset ("glance-images", glance_images.images);
} else {
$( "#" + selected_tab_name ).show ();
}
}
window.onhashchange = navigate
window.onhashchange = navigate;