Skip to content

Commit

Permalink
release 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Wolfes committed Jul 3, 2017
1 parent 76fc905 commit ee452f9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 41 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adf-widget-jenkins",
"version": "0.2.0",
"version": "0.2.2",
"main": "dist/adf-widget-jenkins.js",
"ignore": [
"bower.json",
Expand Down
92 changes: 54 additions & 38 deletions dist/adf-widget-jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function registerWidget(dashboardProvider) {
registerWidget.$inject = ["dashboardProvider"];

angular.module("adf.widget.jenkins").run(["$templateCache", function($templateCache) {$templateCache.put("{widgetsPath}/jenkins/src/edit.html","<form role=form><div class=form-group><label ng-if=!vm.url>Connection Setup</label><p ng-if=!vm.url><input class=form-control id=apiUrl ng-model=config.apiUrl placeholder=\"Enter Api-Url\" type=text ng-change=vm.updateProjectList(config.apiUrl)></p><label>Project</label> <input type=text ng-model=config.project uib-typeahead=\"project.name for project in vm.projects | filter:$viewValue | limitTo:10\" class=form-control></div></form>");
$templateCache.put("{widgetsPath}/jenkins/src/view.html","<style type=text/css>\n\n .statusImg {\n max-width: 100px;\n }\n\n</style><div><div class=content><div class=\"alert alert-info\" ng-if=!vm.data>Please configure a project</div><div ng-if=vm.data><div class=\"col-md-6 col-xs-6\"><a href=\'{{vm.data.url}}target=\"_blank\"\'><h4>{{vm.data.projectFullName}}</h4></a><p><b>Last Commit:</b> {{vm.data.lastCommitMsg}}</p><p><b>Author:</b> {{vm.data.lastCommitBy}}</p></div><div ng-if=vm.data.imgSource class=\"col-md-6 col-xs-6 pull-right\"><img ng-src={{vm.data.imgSource}} class=\"statusImg pull-right\"></div></div></div></div>");
$templateCache.put("{widgetsPath}/jenkins/src/view.html","<style type=text/css>\n .statusImg {\n max-width: 100px;\n }\n .break-word {\n word-wrap: break-word\n }\n</style><div><div class=content><div class=\"alert alert-info\" ng-if=!vm.data>Please configure a project</div><div ng-if=vm.data><div class=\"col-md-7 col-xs-7\"><a href={{vm.data.url}} target=_blank class=break-word><h4>{{vm.data.projectFullName}}</h4></a><p><b>Last Commit:</b> {{vm.data.lastCommitMsg}}</p><p><b>Author:</b> {{vm.data.lastCommitBy}}</p></div><div ng-if=vm.data.imgSource class=\"col-md-5 col-xs-5 pull-right\"><img ng-src={{vm.data.imgSource}} class=\"statusImg pull-right\"></div></div></div></div>");
$templateCache.put("{widgetsPath}/jenkins/src/charts/edit.html","<form role=form><div ng-if=!vm.url class=form-group><label>Connection Setup</label><p><input class=form-control id=apiUrl ng-model=config.apiUrl placeholder=\"Enter Api-Url\" type=text></p></div></form>");
$templateCache.put("{widgetsPath}/jenkins/src/charts/view.html","<style type=text/css>\n #stable{\n background-color: #B5CA00;\n }\n #failed{\n background-color: #E43B53;\n }\n #unstable{\n background-color: #DD7800;\n }\n #disabled{\n background-color: #777777;\n }\n .content>.counter>h1{\n color:white;\n }\n .content>.counter {\n outline: 2px solid #ddd;\n height: 100px;\n color: white;\n }\n #doughnut.center{\n margin: 0 auto;\n }\n</style><div><div class=content><canvas id=doughnut class=\"chart chart-doughnut center\" chart-data=jc.chartValues chart-labels=jc.chartLabels chart-colors=jc.chartColors></canvas><div class=\"counter col-md-6\" id=stable><h1>{{jc.data.stable || 0}}</h1>stable builds</div><div class=\"counter col-md-6\" id=unstable><h1>{{jc.data.unstable || 0}}</h1>unstable builds</div><div class=\"counter col-md-6\" id=failed><h1>{{jc.data.fail || 0}}</h1>failed builds</div><div class=\"counter col-md-6\" id=disabled><h1>{{jc.data.aborted+jc.data.disabled || 0}}</h1>disabled builds</div></div></div>");}]);
'use strict'
Expand All @@ -85,7 +85,6 @@ jenkinsWidget.controller('jenkinsChart', ["data", function(data) {
jenkinsWidget.controller('jenkinsJobList', ["data", function(data) {
var vm = this;
vm.data = data;

}]);


Expand Down Expand Up @@ -115,8 +114,14 @@ function jenkinsApi($http) {
}

//get info about specific project
function createProjectConnection(apiUrl, project) {
return apiUrl + '/job/' + project + '/lastBuild/api/json';
function createProjectConnection(apiUrl, jobName) {
var convertedJobName = convertJobName(jobName);
return apiUrl + '/job/' + convertedJobName + '/lastBuild/api/json';
}

// convert compound job names (e.g. for organizations or folders) to fit jenkins rest api
function convertJobName(jobName) {
return jobName.replace(/\//g, "/job/");
}


Expand Down Expand Up @@ -156,7 +161,6 @@ function jenkinsApi($http) {

}


function crawlJenkinsJobs(instanceURL) {
var connection = instanceURL + '/api/json?tree=jobs[name,buildable,color,jobs[name,buildable,color,jobs[name,buildable,color,jobs[name,buildable,color,jobs]]]]&pretty';
return $http({
Expand All @@ -166,23 +170,29 @@ function jenkinsApi($http) {
'Accept': 'application/json'
}
}).then(function (response) {
return resolveJobFolder(response.data);
return resolveJobFolder(response.data, "");
})
}

function resolveJobFolder(job) {
var folderName = job.name;
function resolveJobFolder(job, folder) {
var folderName = folder;
if (job.name) {
if (folderName) {
folderName += '/';
}
folderName += job.name;
}
var jobItems = [];
job.jobs.forEach(function (job) {
if (job.buildable) {
if (folderName === undefined || folderName == null) {
jobItems.push({name: job.name, color: job.color});
job.jobs.forEach(function (childJob) {
if (childJob.buildable) {
if (!folderName) {
jobItems = jobItems.concat({ name: childJob.name, color: childJob.color });
} else {
jobItems.push({name: folderName + " / " + job.name, color: job.color});
jobItems = jobItems.concat({ name: folderName + "/" + childJob.name, color: childJob.color });
}
}
if (job.jobs) {
jobItems.push(resolveJobFolder(job));
if (childJob.jobs) {
jobItems = jobItems.concat(resolveJobFolder(childJob, folderName));
}
});
return jobItems;
Expand Down Expand Up @@ -229,12 +239,21 @@ function jenkinsApi($http) {
imgSource = imgBuildFailed;
}

var lastCommit = response.data.changeSet.items[0];
var changeset = response.data.changeSet;
if (!changeset) {
if (response.data.changeSets) {
changeset = response.data.changeSets[0];
}
}
var lastCommitMsg = defaultMsgNoCommitInfo;
var lastCommitBy = defaultMsgNoAuthor;
if (lastCommit) {
lastCommitBy = lastCommit.author.fullName;
lastCommitMsg = lastCommit.msg;
if (changeset && changeset.items) {
var lastIndex = changeset.items.length - 1;
var lastCommit = changeset.items[lastIndex];
if (lastCommit) {
lastCommitBy = lastCommit.author.fullName;
lastCommitMsg = lastCommit.msg;
}
}

return {
Expand Down Expand Up @@ -268,33 +287,30 @@ jenkinsApi.$inject = ["$http"];


angular.module('adf.widget.jenkins')
.controller('projectViewEditController', ["jenkinsApi", "$scope", "jenkinsEndpoint", function(jenkinsApi, $scope, jenkinsEndpoint) {
.controller('projectViewEditController', ["jenkinsApi", "$scope", "jenkinsEndpoint", function (jenkinsApi, $scope, jenkinsEndpoint) {

var vm = this;

vm.updateProjectList = updateProjectList;

if (jenkinsEndpoint.url){
vm.url = jenkinsEndpoint.url;
}

if (jenkinsEndpoint.url) {
vm.url = jenkinsEndpoint.url;
}

updateProjectList(vm.url);
updateProjectList(vm.url);

function updateProjectList(url){
var projects = [];
jenkinsApi.crawlJenkinsJobs(url).then(function(data) {
data.forEach(function(project) {
var proj = {
name: project.name
};
projects.push(proj);
});
function updateProjectList(url) {
var projects = [];
jenkinsApi.crawlJenkinsJobs(url).then(function (data) {
data.forEach(function (project) {
var proj = {
name: project.name
};
projects.push(proj);
});
vm.projects = projects;
}


});
vm.projects = projects;
}

}]);
})(window);
Loading

0 comments on commit ee452f9

Please sign in to comment.