Fix JavaScript lint errors

This commit fixes the errors raised by eslint using openstack
configurations.

Change-Id: I3aa0c91e77f40c6383ac73850f5b93ebae9af323
Co-Authored-By: Caio Carrara <ccarrara@thoughtworks.com>
This commit is contained in:
Glauco Oliveira 2015-10-14 18:58:58 -03:00
parent 7c58be1a32
commit 1e7615fd52
10 changed files with 97 additions and 81 deletions

View File

@ -3,4 +3,5 @@ build
node_modules
coverage
doc
app/vendor-js
app/vendor-js
gulp

View File

@ -9,3 +9,6 @@ globals:
env:
browser: true
jasmine: true
rules:
module-setter: 0

View File

@ -1,3 +1,7 @@
# Enable eslint-plugin-angular
plugins:
- angular
rules:
angular/module-setter: 0
angular/module-getter: 0

View File

@ -11,7 +11,7 @@
<link rel="stylesheet" href="css/main.css">
</head>
<body class="ng-cloak" ng-controller="MainCtrl">
<body class="ng-cloak" ng-controller="MainController">
<header class="navbar navbar-default navbar-fixed-top navbar-inner">
<div class="container">
<div class="navbar-header">

View File

@ -5,7 +5,7 @@ var controllersModule = require('./_index');
/**
* @ngInject
*/
function HomeCtrl(healthService) {
function HomeController(healthService) {
// ViewModel
var vm = this;
@ -15,55 +15,61 @@ function HomeCtrl(healthService) {
var passEntries = [];
var failEntries = [];
var failRateEntries = [];
for (var dateString in data.runs) {
var date = dateString;
var totalPass = 0;
var totalFail = 0;
var reqProjects = data.runs[date];
for (var projectName in reqProjects) {
reqProjects[projectName].forEach(function(project) {
var sumProject = projects[projectName];
if (typeof sumProject === "undefined") {
// create initial data containers for each gauge chart on-the-fly
sumProject = {
name: projectName,
data: [
{ key: 'Passes', value: 0, color: 'blue' },
{ key: 'Failures', value: 0, color: 'red' }
]
};
projects[projectName] = sumProject;
}
if (project.fail > 0) {
totalFail += 1;
sumProject.data[1].value += 1;
} else {
totalPass += 1;
sumProject.data[0].value += 1;
}
});
var sumProjectMetrics = function(project) {
var sumProject = projects[projectName];
if (typeof sumProject === "undefined") {
// create initial data containers for each gauge chart on-the-fly
sumProject = {
name: projectName,
data: [
{ key: 'Passes', value: 0, color: 'blue' },
{ key: 'Failures', value: 0, color: 'red' }
]
};
projects[projectName] = sumProject;
}
// parse dates and create data series' for the main chart
var time = new Date(date).getTime();
if (project.fail > 0) {
totalFail += 1;
sumProject.data[1].value += 1;
} else {
totalPass += 1;
sumProject.data[0].value += 1;
}
};
passEntries.push({
x: time,
y: totalPass
});
for (var dateString in data.runs) {
if (data.runs.hasOwnProperty(dateString)) {
var date = dateString;
var totalPass = 0;
var totalFail = 0;
failEntries.push({
x: time,
y: totalFail
});
var reqProjects = data.runs[date];
var projectName = '';
for (projectName in reqProjects) {
if (reqProjects.hasOwnProperty(projectName)) {
reqProjects[projectName].forEach(sumProjectMetrics);
}
}
failRateEntries.push({
x: new Date(date).getTime(),
y: (totalFail / (totalFail + totalPass)) * 100
});
// parse dates and create data series' for the main chart
var time = new Date(date).getTime();
passEntries.push({
x: time,
y: totalPass
});
failEntries.push({
x: time,
y: totalFail
});
failRateEntries.push({
x: new Date(date).getTime(),
y: (totalFail / (totalFail + totalPass)) * 100
});
}
}
vm.chartData = [
@ -75,7 +81,6 @@ function HomeCtrl(healthService) {
{ key: '% Failures', values: failRateEntries }
];
vm.projects = Object.keys(projects).map(function(name) {
return projects[name];
});
@ -87,7 +92,7 @@ function HomeCtrl(healthService) {
healthService.getRunsGroupedByMetadataPerDatetime('project', {
start_date: start,
datetime_resolution: 'hour',
datetime_resolution: 'hour'
}).then(function(response) {
vm.processData(response.data);
});
@ -95,4 +100,4 @@ function HomeCtrl(healthService) {
vm.loadData();
}
controllersModule.controller('HomeCtrl', HomeCtrl);
controllersModule.controller('HomeController', HomeController);

View File

@ -5,10 +5,10 @@ var controllersModule = require('./_index');
/**
* @ngInject
*/
function MainCtrl($window, $scope) {
function MainController($window, $scope) {
$window.addEventListener('resize', function () {
$scope.$broadcast('windowResize');
});
}
controllersModule.controller('MainCtrl', MainCtrl);
controllersModule.controller('MainController', MainController);

View File

@ -5,7 +5,7 @@ var controllersModule = require('./_index');
/**
* @ngInject
*/
function ProjectCtrl($http, healthService, projectName) {
function ProjectController($http, healthService, projectName) {
// ViewModel
var vm = this;
@ -32,13 +32,13 @@ function ProjectCtrl($http, healthService, projectName) {
timedelta.job_data.forEach(function(job) {
if (!jobs[job.job_name]) {
var job_metrics = {
var jobMetrics = {
name: job.job_name,
passes: 0,
failures: 0,
failures_rate: 0
};
jobs[job.job_name] = job_metrics;
jobs[job.job_name] = jobMetrics;
}
totalPass += job.pass;
@ -79,7 +79,7 @@ function ProjectCtrl($http, healthService, projectName) {
];
vm.jobs = jobs;
}
};
vm.loadData = function() {
var start = new Date();
@ -87,14 +87,13 @@ function ProjectCtrl($http, healthService, projectName) {
healthService.getRunsFromProject(vm.name, {
start_date: start,
datetime_resolution: 'hour',
datetime_resolution: 'hour'
}).then(function(response) {
vm.processData(response.data);
});
}
};
vm.loadData();
}
controllersModule.controller('ProjectCtrl', ProjectCtrl);
controllersModule.controller('ProjectController', ProjectController);

View File

@ -30,7 +30,7 @@ function chartLine() {
chart.xAxis.tickFormat(function(d) { return d3.time.format("%x")(new Date(d)); });
if (attrs.forcey) {
chart.forceY(JSON.parse(attrs.forcey));
chart.forceY(angular.fromJson(attrs.forcey));
}
svg.datum(data).call(chart);

View File

@ -11,28 +11,32 @@ require('./controllers/_index');
require('./services/_index');
require('./directives/_index');
var $injector = angular.injector(['ng']);
// create and bootstrap application
angular.element(document).ready(function() {
$injector.invoke(function($window) {
var requires = [
'ui.router',
'ui.bootstrap',
'picardy.fontawesome',
'templates',
'app.controllers',
'app.services',
'app.directives'
];
var requires = [
'ui.router',
'ui.bootstrap',
'picardy.fontawesome',
'templates',
'app.controllers',
'app.services',
'app.directives'
];
// mount on window for testing
$window.app = angular.module('app', requires);
// mount on window for testing
window.app = angular.module('app', requires);
angular.module('app').constant('AppSettings', require('./constants'));
angular.module('app').constant('AppSettings', require('./constants'));
var onConfig = require('./on_config');
angular.module('app').config(onConfig);
angular.module('app').config(require('./on_config'));
angular.module('app').run(require('./on_run'));
angular.bootstrap(document, ['app']);
var onRun = require('./on_run');
angular.module('app').run(onRun);
angular.bootstrap(document, ['app']);
});
});

View File

@ -8,18 +8,18 @@ function OnConfig($stateProvider, $locationProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
controller: 'HomeCtrl as home',
controller: 'HomeController as home',
templateUrl: 'home.html',
title: 'Home'
})
.state('project', {
url: '/project/*projectName',
controller: 'ProjectCtrl as project',
controller: 'ProjectController as project',
templateUrl: 'project.html',
title: 'Project',
resolve: {
"projectName": function($stateParams) {
return $stateParams.projectName;
return $stateParams.projectName;
}
}
});