Skip to content

Commit

Permalink
Changes to font size and number of columns are now persisted
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-molak committed Jul 6, 2013
1 parent 6932472 commit e4c1f3c
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<ul id="job-views"
style="font-size: {{fontSize}}em"
class="columns-{{ numberOfColumns }}">

<li ng-repeat="job in jobs" class="{{job.status}}">
<div class="progress" style="width: {{job.progress}}%">
<span>{{job.progress}}%</span>
</div>

<div class="meta">
<h2>
<a title="{{job.name}}"
href="${jobsURL}/{{job.name}}">{{job.name}}</a>
</h2>
<ul data-ng-show="job.culprits.size() > 0" class="culprits">
<li data-ng-repeat="name in job.culprits">
{{name}}
</li>
</ul>
<a data-ng-show="!!job.buildNumber" class="build-number"
title="Console output for {{job.name}}, build #{{job.buildNumber}}"
href="${jobsURL}/{{job.name}}/{{job.buildNumber}}/console">#{{job.buildNumber}}</a>
</div>
</li>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -17,77 +17,11 @@
<link rel="stylesheet" href="${resourcesURL}/themes/industrial.css"/>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/${angularVersion}/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/${angularVersion}/angular-cookies.min.js"></script>
<script>window.angular || document.write('\x3Cscript src="${resourcesURL}/libs/angular-${angularVersion}.min.js">\x3C/script>')</script>
<script>window.angular || document.write('\x3Cscript src="${resourcesURL}/libs/angular-cookies-${angularVersion}.min.js">\x3C/script>')</script>
<script src="${resourcesURL}/libs/ui-bootstrap-custom-tpls-0.4.0.js"></script>
<script src="${resourcesURL}/libs/angular-slider.js"></script>

<script>
var buildMonitor = angular.
module('buildMonitor', ['ui.bootstrap.dialog', 'template/dialog/message.html', 'uiSlider']).
service('notifyUser', function($dialog, $window) {
this.about = function(problemStatus) {

var title = "Sorry to bother you, but there is a slight issue ..."
var message = "Jenkins returned a \"" + problemStatus + "\" response " +
"causing the last request to fail. " +
"This usually means a network connection problem " +
"or that Jenkins is being restarted. " +
"Don't worry, reloading the page should help :-)";

$dialog.messageBox(title, message, [
{ result: "reload", label: "Reload the page"}
]).open().then(function(result) {
$window.location.reload();
});
}
}).
service('fetch', function($q, $rootScope) {
// TODO: This seems to be a cool way of integrating legacy code: http://jsfiddle.net/d8vX3/1/
var proxy = <st:bind value="${it}"/>;

this.current = function() {
var deferred = $q.defer();

proxy.fetchJobViews(function(response) {

if (response.status === 200) {
deferred.resolve(response.responseObject());
} else {
deferred.reject({ status: response.status });
}

$rootScope.$apply();
});

return deferred.promise;
}
}).

controller('JobViews', function($scope, $dialog, $timeout, fetch) {
$scope.fontSize = 1;
$scope.numberOfColumns = 2;

$scope.jobs = {};
var update = function() {
var updating;
fetch.current().then(function(current) {
$scope.jobs = current.jobs;
updating = $timeout(update, 5000)
}, function(error) {
$timeout.cancel(updating);
$rootScope.$broadcast("communication-error", error);
});
}

update();
}).

run(function($rootScope, notifyUser) {
$rootScope.$on('communication-error', function(event, error) {
notifyUser.about(error.status);
});
});
</script>
</l:header>

<l:main-panel>
Expand All @@ -98,36 +32,26 @@

<st:include page="main-config.jelly"/>

<ul id="job-views"
style="font-size: {{fontSize}}em"
class="columns-{{ numberOfColumns }}">

<li ng-repeat="job in jobs" class="{{job.status}}">
<div class="progress" style="width: {{job.progress}}%">
<span>{{job.progress}}%</span>
</div>

<div class="meta">
<h2>
<a title="{{job.name}}"
href="${jobsURL}/{{job.name}}">{{job.name}}</a>
</h2>
<ul data-ng-show="job.culprits.size() > 0" class="culprits">
<li data-ng-repeat="name in job.culprits">
{{name}}
</li>
</ul>
<a data-ng-show="!!job.buildNumber" class="build-number"
title="Console output for {{job.name}}, build #{{job.buildNumber}}"
href="${jobsURL}/{{job.name}}/{{job.buildNumber}}/console">#{{job.buildNumber}}</a>
</div>
</li>
</ul>
<st:include page="main-jobViews.jelly"/>

<footer>
<a href="http://smartcodeltd.co.uk" rel="external">Build Monitor plugin developed by Jan Molak</a>
</footer>
</div>

<script src="${resourcesURL}/scripts/app.js"></script>
<script src="${resourcesURL}/scripts/services.js"></script>
<script>
'use strict';

angular.
module('buildMonitor.services').
service('jenkins', function() {
this.proxy = <st:bind value="${it}"/>;
this.buildMonitorName = '${it.displayName}';
});
</script>
<script src="${resourcesURL}/scripts/controllers.js"></script>
</l:main-panel>
</l:layout>
</j:jelly>
7 changes: 7 additions & 0 deletions src/main/webapp/libs/angular-cookies-1.1.5.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
AngularJS v1.1.5
(c) 2010-2012 Google, Inc. http://angularjs.org
License: MIT
*/
(function(m,f,l){'use strict';f.module("ngCookies",["ng"]).factory("$cookies",["$rootScope","$browser",function(d,b){var c={},g={},h,i=!1,j=f.copy,k=f.isUndefined;b.addPollFn(function(){var a=b.cookies();h!=a&&(h=a,j(a,g),j(a,c),i&&d.$apply())})();i=!0;d.$watch(function(){var a,e,d;for(a in g)k(c[a])&&b.cookies(a,l);for(a in c)e=c[a],f.isString(e)?e!==g[a]&&(b.cookies(a,e),d=!0):f.isDefined(g[a])?c[a]=g[a]:delete c[a];if(d)for(a in e=b.cookies(),c)c[a]!==e[a]&&(k(e[a])?delete c[a]:c[a]=e[a])});return c}]).factory("$cookieStore",
["$cookies",function(d){return{get:function(b){return(b=d[b])?f.fromJson(b):b},put:function(b,c){d[b]=f.toJson(c)},remove:function(b){delete d[b]}}}])})(window,window.angular);
2 changes: 1 addition & 1 deletion src/main/webapp/libs/angular-slider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// contains fix https://raw.github.com/costasovo/angular-slider/39ecbab86ea0cfbcc30958fd0171127208ea1535/angular-slider.js
// contains "32px" hack on line 186
// contains "145px" hack on line 186
(function() {
var MODULE_NAME, SLIDER_TAG, angularize, bindHtml, gap, halfWidth, hide, inputEvents, module, offset, offsetLeft, pixelize, qualifiedDirectiveDefinition, roundStep, show, sliderDirective, width;

Expand Down
9 changes: 9 additions & 0 deletions src/main/webapp/scripts/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

angular.
module('buildMonitor', [ 'buildMonitor.controllers', 'uiSlider' ]).
run(function($rootScope, notifyUser) {
$rootScope.$on('communication-error', function(event, error) {
notifyUser.about(error.status);
});
});
31 changes: 31 additions & 0 deletions src/main/webapp/scripts/controllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

angular.
module('buildMonitor.controllers', [ 'buildMonitor.services', 'uiSlider']).

controller('JobViews', function($scope, $dialog, $timeout, fetch, storage) {
$scope.fontSize = storage.retrieve('fontSize', 1);
$scope.numberOfColumns = storage.retrieve('numberOfColumns', 2);

$scope.$watch('fontSize', function(currentFontSize) {
storage.persist('fontSize', currentFontSize);
});
$scope.$watch('numberOfColumns', function(currentNumberOfColumns) {
storage.persist('numberOfColumns', currentNumberOfColumns);
});


$scope.jobs = {};
var update = function() {
var updating;
fetch.current().then(function(current) {
$scope.jobs = current.jobs;
updating = $timeout(update, 5000)
}, function(error) {
$timeout.cancel(updating);
$rootScope.$broadcast("communication-error", error);
});
}

update();
});
78 changes: 78 additions & 0 deletions src/main/webapp/scripts/services.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'use strict';

angular.module('buildMonitor.services', ['ui.bootstrap.dialog', 'template/dialog/message.html', 'ngCookies']).

service('notifyUser',function ($dialog, $window) {
this.about = function (problemStatus) {

var title = "Sorry to bother you, but there is a slight issue ..."
var message = "Jenkins returned a \"" + problemStatus + "\" response " +
"causing the last request to fail. " +
"This usually means a network connection problem " +
"or that Jenkins is being restarted. " +
"Don't worry, reloading the page should help :-)";

$dialog.messageBox(title, message, [
{ result: "reload", label: "Reload the page"}
]).open().then(function (result) {
$window.location.reload();
});
}
}).

service('fetch',function ($q, $rootScope, jenkins) {
this.current = function () {
var deferred = $q.defer();

jenkins.proxy.fetchJobViews(function (response) {

if (response.status === 200) {
deferred.resolve(response.responseObject());
} else {
deferred.reject({ status: response.status });
}

$rootScope.$apply();
});

return deferred.promise;
}
}).

service('storage',function ($cookies, jenkins, hashCode) {
this.persist = function (name, value) {
$cookies[prefix(name)] = value;
}

this.retrieve = function (name, defaultValue) {
var value = $cookies[prefix(name)];

return (typeof value !== 'undefined')
? value
: defaultValue;
}

function prefix(name) {
return 'buildMonitor.' + hashCode.of(jenkins.buildMonitorName) + '.' + name;
}
}).

service('hashCode', function() {
this.of = function(name) {
var hash = 0,
char;

if (name.length == 0) {
return hash;
}

for (var i = 0; i < name.length; i++) {
char = name.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
}

return hash;
}
})
;

0 comments on commit e4c1f3c

Please sign in to comment.