Commit 61cf8f44 by Jeffrey Phillips Committed by GitHub

Merge pull request #27 from dtaylor113/master

Added more date filters, version bump
parents e9e4e50f 5b186fa1
{ {
"name": "origin-web-common", "name": "origin-web-common",
"version": "0.0.9", "version": "0.0.10",
"main": [ "main": [
"dist/origin-web-common.js", "dist/origin-web-common.js",
"dist/origin-web-common.css" "dist/origin-web-common.css"
......
...@@ -810,6 +810,70 @@ angular ...@@ -810,6 +810,70 @@ angular
;'use strict'; ;'use strict';
angular.module('openshiftCommonUI') angular.module('openshiftCommonUI')
.filter('isNewerResource', function() {
// Checks if candidate is newer than other.
return function(candidate, other) {
var candidateCreation = _.get(candidate, 'metadata.creationTimestamp');
if (!candidateCreation) {
return false;
}
var otherCreation = _.get(other, 'metadata.creationTimestamp');
if (!otherCreation) {
return true;
}
// The date format can be compared using straight string comparison.
// Example Date: 2016-02-02T21:53:07Z
return candidateCreation > otherCreation;
};
})
.filter('mostRecent', function(isNewerResourceFilter) {
return function(objects) {
var mostRecent = null;
_.each(objects, function(object) {
if (!mostRecent || isNewerResourceFilter(object, mostRecent)) {
mostRecent = object;
}
});
return mostRecent;
};
})
.filter('orderObjectsByDate', function(toArrayFilter) {
return function(items, reverse) {
items = toArrayFilter(items);
/*
* Note: This is a hotspot in our code. We sort frequently by date on
* the overview and browse pages.
*/
items.sort(function (a, b) {
if (!a.metadata || !a.metadata.creationTimestamp || !b.metadata || !b.metadata.creationTimestamp) {
throw "orderObjectsByDate expects all objects to have the field metadata.creationTimestamp";
}
// The date format can be sorted using straight string comparison.
// Compare as strings for performance.
// Example Date: 2016-02-02T21:53:07Z
if (a.metadata.creationTimestamp < b.metadata.creationTimestamp) {
return reverse ? 1 : -1;
}
if (a.metadata.creationTimestamp > b.metadata.creationTimestamp) {
return reverse ? -1 : 1;
}
return 0;
});
return items;
};
});
;'use strict';
angular.module('openshiftCommonUI')
.filter('highlightKeywords', function(KeywordService) { .filter('highlightKeywords', function(KeywordService) {
// Returns HTML wrapping the matching words in a `mark` tag. // Returns HTML wrapping the matching words in a `mark` tag.
return function(str, keywords, caseSensitive) { return function(str, keywords, caseSensitive) {
...@@ -863,40 +927,6 @@ angular.module('openshiftCommonUI') ...@@ -863,40 +927,6 @@ angular.module('openshiftCommonUI')
;'use strict'; ;'use strict';
angular.module('openshiftCommonUI') angular.module('openshiftCommonUI')
.filter('orderObjectsByDate', function(toArrayFilter) {
return function(items, reverse) {
items = toArrayFilter(items);
/*
* Note: This is a hotspot in our code. We sort frequently by date on
* the overview and browse pages.
*/
items.sort(function (a, b) {
if (!a.metadata || !a.metadata.creationTimestamp || !b.metadata || !b.metadata.creationTimestamp) {
throw "orderObjectsByDate expects all objects to have the field metadata.creationTimestamp";
}
// The date format can be sorted using straight string comparison.
// Compare as strings for performance.
// Example Date: 2016-02-02T21:53:07Z
if (a.metadata.creationTimestamp < b.metadata.creationTimestamp) {
return reverse ? 1 : -1;
}
if (a.metadata.creationTimestamp > b.metadata.creationTimestamp) {
return reverse ? -1 : 1;
}
return 0;
});
return items;
};
});
;'use strict';
angular.module('openshiftCommonUI')
.filter('parseJSON', function() { .filter('parseJSON', function() {
return function(json) { return function(json) {
// return original value if its null or undefined // return original value if its null or undefined
......
...@@ -1017,6 +1017,70 @@ angular ...@@ -1017,6 +1017,70 @@ angular
;'use strict'; ;'use strict';
angular.module('openshiftCommonUI') angular.module('openshiftCommonUI')
.filter('isNewerResource', function() {
// Checks if candidate is newer than other.
return function(candidate, other) {
var candidateCreation = _.get(candidate, 'metadata.creationTimestamp');
if (!candidateCreation) {
return false;
}
var otherCreation = _.get(other, 'metadata.creationTimestamp');
if (!otherCreation) {
return true;
}
// The date format can be compared using straight string comparison.
// Example Date: 2016-02-02T21:53:07Z
return candidateCreation > otherCreation;
};
})
.filter('mostRecent', ["isNewerResourceFilter", function(isNewerResourceFilter) {
return function(objects) {
var mostRecent = null;
_.each(objects, function(object) {
if (!mostRecent || isNewerResourceFilter(object, mostRecent)) {
mostRecent = object;
}
});
return mostRecent;
};
}])
.filter('orderObjectsByDate', ["toArrayFilter", function(toArrayFilter) {
return function(items, reverse) {
items = toArrayFilter(items);
/*
* Note: This is a hotspot in our code. We sort frequently by date on
* the overview and browse pages.
*/
items.sort(function (a, b) {
if (!a.metadata || !a.metadata.creationTimestamp || !b.metadata || !b.metadata.creationTimestamp) {
throw "orderObjectsByDate expects all objects to have the field metadata.creationTimestamp";
}
// The date format can be sorted using straight string comparison.
// Compare as strings for performance.
// Example Date: 2016-02-02T21:53:07Z
if (a.metadata.creationTimestamp < b.metadata.creationTimestamp) {
return reverse ? 1 : -1;
}
if (a.metadata.creationTimestamp > b.metadata.creationTimestamp) {
return reverse ? -1 : 1;
}
return 0;
});
return items;
};
}]);
;'use strict';
angular.module('openshiftCommonUI')
.filter('highlightKeywords', ["KeywordService", function(KeywordService) { .filter('highlightKeywords', ["KeywordService", function(KeywordService) {
// Returns HTML wrapping the matching words in a `mark` tag. // Returns HTML wrapping the matching words in a `mark` tag.
return function(str, keywords, caseSensitive) { return function(str, keywords, caseSensitive) {
...@@ -1070,40 +1134,6 @@ angular.module('openshiftCommonUI') ...@@ -1070,40 +1134,6 @@ angular.module('openshiftCommonUI')
;'use strict'; ;'use strict';
angular.module('openshiftCommonUI') angular.module('openshiftCommonUI')
.filter('orderObjectsByDate', ["toArrayFilter", function(toArrayFilter) {
return function(items, reverse) {
items = toArrayFilter(items);
/*
* Note: This is a hotspot in our code. We sort frequently by date on
* the overview and browse pages.
*/
items.sort(function (a, b) {
if (!a.metadata || !a.metadata.creationTimestamp || !b.metadata || !b.metadata.creationTimestamp) {
throw "orderObjectsByDate expects all objects to have the field metadata.creationTimestamp";
}
// The date format can be sorted using straight string comparison.
// Compare as strings for performance.
// Example Date: 2016-02-02T21:53:07Z
if (a.metadata.creationTimestamp < b.metadata.creationTimestamp) {
return reverse ? 1 : -1;
}
if (a.metadata.creationTimestamp > b.metadata.creationTimestamp) {
return reverse ? -1 : 1;
}
return 0;
});
return items;
};
}]);
;'use strict';
angular.module('openshiftCommonUI')
.filter('parseJSON', function() { .filter('parseJSON', function() {
return function(json) { return function(json) {
// return original value if its null or undefined // return original value if its null or undefined
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"author": "Red Hat", "author": "Red Hat",
"name": "origin-web-common", "name": "origin-web-common",
"version": "0.0.9", "version": "0.0.10",
"license": "Apache-2.0", "license": "Apache-2.0",
"description": "Library of common services and components for OpenShift Web Console.", "description": "Library of common services and components for OpenShift Web Console.",
"homepage": "https://github.com/openshift/origin-web-common.git", "homepage": "https://github.com/openshift/origin-web-common.git",
......
'use strict'; 'use strict';
angular.module('openshiftCommonUI') angular.module('openshiftCommonUI')
.filter('isNewerResource', function() {
// Checks if candidate is newer than other.
return function(candidate, other) {
var candidateCreation = _.get(candidate, 'metadata.creationTimestamp');
if (!candidateCreation) {
return false;
}
var otherCreation = _.get(other, 'metadata.creationTimestamp');
if (!otherCreation) {
return true;
}
// The date format can be compared using straight string comparison.
// Example Date: 2016-02-02T21:53:07Z
return candidateCreation > otherCreation;
};
})
.filter('mostRecent', function(isNewerResourceFilter) {
return function(objects) {
var mostRecent = null;
_.each(objects, function(object) {
if (!mostRecent || isNewerResourceFilter(object, mostRecent)) {
mostRecent = object;
}
});
return mostRecent;
};
})
.filter('orderObjectsByDate', function(toArrayFilter) { .filter('orderObjectsByDate', function(toArrayFilter) {
return function(items, reverse) { return function(items, reverse) {
items = toArrayFilter(items); items = toArrayFilter(items);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment