diff --git a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/index.jelly b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/index.jelly
index 91b844ff8..39ab26342 100644
--- a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/index.jelly
+++ b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/index.jelly
@@ -27,9 +27,6 @@
-
-
-
@@ -199,8 +196,7 @@
proxyProvider.configureProxiesUsing(window.bindings);
cookieJarProvider.describe({
- label: 'buildMonitor.' + hashCodeOf(document.body.dataset.displayName),
- shelfLife: 365
+ label: 'buildMonitor.' + hashCodeOf(document.body.dataset.displayName)
});
});
diff --git a/build-monitor-plugin/src/main/webapp/scripts/services.js b/build-monitor-plugin/src/main/webapp/scripts/services.js
index f4aecf5f6..0a1c7e156 100644
--- a/build-monitor-plugin/src/main/webapp/scripts/services.js
+++ b/build-monitor-plugin/src/main/webapp/scripts/services.js
@@ -3,7 +3,7 @@
angular.
module('buildMonitor.services', ['ui.bootstrap.dialog', 'buildMonitor.templates', 'buildMonitor.cron', 'template/dialog/message.html']).
- value('YahooCookie', YAHOO.util.Cookie).
+ value('persistentStorage', window.localStorage).
service('notifyUser',function ($dialog, $window) {
this.aboutInsufficientSupportOfCSS3 = function(feature) {
@@ -115,10 +115,9 @@ angular.
};
}]).
- provider('cookieJar',function () {
+ provider('cookieJar', function () {
var defaultAttributes = {
- label: '',
- shelfLife: 0
+ label: ''
},
attributes = {};
@@ -126,22 +125,11 @@ angular.
attributes = cookieJarAttributes;
}
- this.$get = ['YahooCookie', function (YahooCookie) {
- return new CookieJar(YahooCookie, angular.extend(defaultAttributes, attributes));
+ this.$get = ['persistentStorage', function (persistentStorage) {
+ return new CookieJar(persistentStorage, angular.extend(defaultAttributes, attributes));
}];
-
- function CookieJar(YahooCookie, attributes) {
-
- function expiryDetailsBasedOn(days) {
- if (days <= 0) {
- return {};
- }
-
- return {
- expires: new Date(+new Date() + (days * 1000 * 3600 * 24))
- }
- }
+ function CookieJar(persistentStorage, attributes) {
function prefixed(name) {
return attributes.label
@@ -151,11 +139,10 @@ angular.
return {
put: function (name, value) {
- YahooCookie.set(prefixed(name), value, expiryDetailsBasedOn(attributes.shelfLife));
+ persistentStorage.setItem(prefixed(name), value);
},
get: function (name, defaultValue) {
- var value = YahooCookie.get(prefixed(name));
-
+ var value = persistentStorage.getItem(prefixed(name));
return (value !== null)
? value
: defaultValue;
diff --git a/build-monitor-plugin/src/test/javascript/unit/services/cookieJarSpec.js b/build-monitor-plugin/src/test/javascript/unit/services/cookieJarSpec.js
index c32f9ce24..f33514a31 100644
--- a/build-monitor-plugin/src/test/javascript/unit/services/cookieJarSpec.js
+++ b/build-monitor-plugin/src/test/javascript/unit/services/cookieJarSpec.js
@@ -5,20 +5,30 @@ describe('buildMonitor', function () {
describe('cookieJar', function () {
var services,
- YahooCookie = YAHOO.util.Cookie,
- mockedCookie, // YAHOO.util.Cookie backend used by the cookieJar
-
+ fakeStorage,
NAME = 'numberOfColumns',
VALUE = 3,
DEFAULT_VALUE = 1;
beforeEach(function () {
services = angular.module('buildMonitor.services');
-
- mockedCookie = sinon.mock(YahooCookie);
-
+ var items = {};
+ var calls = 0;
+ fakeStorage = {
+ getItem: function(key){
+ calls++;
+ return key in items ? items[key] : null;
+ },
+ setItem: function(key, val) {
+ calls++;
+ items[key] = "" + val;
+ },
+ verify: function(expectedCalls) {
+ expect(calls).toBe(expectedCalls);
+ }
+ };
module('buildMonitor.services', function ($provide) {
- $provide.value('YahooCookie', YahooCookie);
+ $provide.value('persistentStorage', fakeStorage);
});
});
@@ -33,26 +43,10 @@ describe('buildMonitor', function () {
}));
it('allows for a value to be persisted and then retrieved', inject(function (cookieJar) {
- mockedCookie.expects("set").withArgs(NAME, VALUE);
- mockedCookie.expects("get").withArgs(NAME).returns(VALUE);
-
-
cookieJar.put(NAME, VALUE);
+ expect(cookieJar.get(NAME)).toBe(VALUE + "");
- expect(cookieJar.get(NAME)).toBe(VALUE);
-
- mockedCookie.verify()
- }));
-
- it('should use cookies that expire at the end of the session', inject(function (cookieJar) {
- var noExpiryDateSpecified = {};
-
- mockedCookie.expects("set").withArgs(NAME, VALUE, noExpiryDateSpecified);
-
-
- cookieJar.put(NAME, VALUE);
-
- mockedCookie.verify();
+ fakeStorage.verify(2)
}));
});
@@ -69,56 +63,20 @@ describe('buildMonitor', function () {
});
it('should prefix each cookie with a label', inject(function (cookieJar) {
- mockedCookie.expects("set").withArgs(prefixed(NAME), VALUE);
- mockedCookie.expects("get").withArgs(prefixed(NAME));
-
-
cookieJar.put(NAME, VALUE);
cookieJar.get(NAME);
-
- mockedCookie.verify();
+ expect(fakeStorage.getItem(prefixed(NAME))).toBe(VALUE + "");
+ fakeStorage.verify(3);
}));
afterEach(function() {
- mockedCookie.restore();
+ //storageSpy.restore();
});
function prefixed(name) {
return COOKIE_JAR_LABEL + '.' + name;
};
});
-
- describe('custom shelf life', function() {
-
- var SHELF_LIFE_IN_DAYS = 7;
-
- beforeEach(function () {
-
- services.config(function(cookieJarProvider) {
- cookieJarProvider.describe({
- shelfLife: SHELF_LIFE_IN_DAYS
- });
- });
- });
-
- it('should use cookies that expire when specified', inject(function (cookieJar) {
- mockedCookie.expects("set").withArgs(NAME, VALUE, {
- expires: dateIn(SHELF_LIFE_IN_DAYS)}
- );
-
- cookieJar.put(NAME, VALUE);
-
- mockedCookie.verify();
- }));
-
- afterEach(function() {
- mockedCookie.restore();
- });
-
- function dateIn(days) {
- return new Date(+new Date() + (days * 24 * 3600 * 1000));
- };
- });
});
});
});
\ No newline at end of file
diff --git a/build-monitor-plugin/src/test/resources/karma.conf.js b/build-monitor-plugin/src/test/resources/karma.conf.js
index 0d8924a72..067ad98cb 100644
--- a/build-monitor-plugin/src/test/resources/karma.conf.js
+++ b/build-monitor-plugin/src/test/resources/karma.conf.js
@@ -25,8 +25,6 @@ module.exports = function(config) {
'src/test/resources/vendor/angular-mocks-1.5.8.js',
'src/test/resources/vendor/sinon-1.17.7.js',
'src/test/resources/vendor/jasmine-sinon-0.4.0.js',
- 'src/test/resources/vendor/yahoo-2.9.0.min.js',
- 'src/test/resources/vendor/yahoo-cookie-2.9.0.min.js',
'src/main/webapp/scripts/**/*.js',
'src/test/javascript/**/*Spec.js', // todo: deprecate the "Spec" suffix in favour of ".spec.js"
'src/test/javascript/**/*.spec.js'
diff --git a/build-monitor-plugin/src/test/resources/vendor/yahoo-2.9.0.min.js b/build-monitor-plugin/src/test/resources/vendor/yahoo-2.9.0.min.js
deleted file mode 100644
index 4f1814008..000000000
--- a/build-monitor-plugin/src/test/resources/vendor/yahoo-2.9.0.min.js
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
-Copyright (c) 2011, Yahoo! Inc. All rights reserved.
-Code licensed under the BSD License:
-http://developer.yahoo.com/yui/license.html
-version: 2.9.0
-*/
-if(typeof YAHOO=="undefined"||!YAHOO){var YAHOO={};}YAHOO.namespace=function(){var b=arguments,g=null,e,c,f;for(e=0;e":">",'"':""","'":"'","/":"/","`":"`"},d=["toString","valueOf"],e={isArray:function(j){return a.toString.apply(j)===c;},isBoolean:function(j){return typeof j==="boolean";},isFunction:function(j){return(typeof j==="function")||a.toString.apply(j)===h;},isNull:function(j){return j===null;},isNumber:function(j){return typeof j==="number"&&isFinite(j);},isObject:function(j){return(j&&(typeof j==="object"||f.isFunction(j)))||false;},isString:function(j){return typeof j==="string";},isUndefined:function(j){return typeof j==="undefined";},_IEEnumFix:(YAHOO.env.ua.ie)?function(l,k){var j,n,m;for(j=0;j"'\/`]/g,function(k){return g[k];});},extend:function(m,n,l){if(!n||!m){throw new Error("extend failed, please check that "+"all dependencies are included.");}var k=function(){},j;k.prototype=n.prototype;m.prototype=new k();m.prototype.constructor=m;m.superclass=n.prototype;if(n.prototype.constructor==a.constructor){n.prototype.constructor=n;}if(l){for(j in l){if(f.hasOwnProperty(l,j)){m.prototype[j]=l[j];}}f._IEEnumFix(m.prototype,l);}},augmentObject:function(n,m){if(!m||!n){throw new Error("Absorb failed, verify dependencies.");}var j=arguments,l,o,k=j[2];if(k&&k!==true){for(l=2;l ";if(!f.isObject(j)){return j+"";}else{if(j instanceof Date||("nodeType" in j&&"tagName" in j)){return j;}else{if(f.isFunction(j)){return k;}}}p=(f.isNumber(p))?p:3;if(f.isArray(j)){r.push("[");for(l=0,n=j.length;l0)?f.dump(j[l],p-1):t);}else{r.push(j[l]);}r.push(q);}if(r.length>1){r.pop();}r.push("]");}else{r.push("{");for(l in j){if(f.hasOwnProperty(j,l)){r.push(l+m);if(f.isObject(j[l])){r.push((p>0)?f.dump(j[l],p-1):t);}else{r.push(j[l]);}r.push(q);}}if(r.length>1){r.pop();}r.push("}");}return r.join("");},substitute:function(x,y,E,l){var D,C,B,G,t,u,F=[],p,z=x.length,A="dump",r=" ",q="{",m="}",n,w;for(;;){D=x.lastIndexOf(q,z);if(D<0){break;}C=x.indexOf(m,D);if(D+1>C){break;}p=x.substring(D+1,C);G=p;u=null;B=G.indexOf(r);if(B>-1){u=G.substring(B+1);G=G.substring(0,B);}t=y[G];if(E){t=E(G,t,u);}if(f.isObject(t)){if(f.isArray(t)){t=f.dump(t,parseInt(u,10));}else{u=u||"";n=u.indexOf(A);if(n>-1){u=u.substring(4);}w=t.toString();if(w===i||n>-1){t=f.dump(t,parseInt(u,10));}else{t=w;}}}else{if(!f.isString(t)&&!f.isNumber(t)){t="~-"+F.length+"-~";F[F.length]=p;}}x=x.substring(0,D)+t+x.substring(C+1);if(l===false){z=D-1;}}for(D=F.length-1;D>=0;D=D-1){x=x.replace(new RegExp("~-"+D+"-~"),"{"+F[D]+"}","g");}return x;},trim:function(j){try{return j.replace(/^\s+|\s+$/g,"");}catch(k){return j;
-}},merge:function(){var n={},k=arguments,j=k.length,m;for(m=0;m0){for(var B=0,A=D.length;B0){var B=(A===false?function(L){return L;}:decodeURIComponent);var H=J.split(/;\s/g),I=null,C=null,E=null;for(var D=0,F=H.length;D