Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1304)

Unified Diff: appengine/config_service/ui/common/common-behaviors.html

Issue 2991013002: config_service: Added revision and timestamp to config-set-cards and config-set pages (Closed)
Patch Set: Refactored test to give each function its own suite Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/config_service/ui/src/config-ui/config-set.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/config_service/ui/common/common-behaviors.html
diff --git a/appengine/config_service/ui/common/common-behaviors.html b/appengine/config_service/ui/common/common-behaviors.html
new file mode 100644
index 0000000000000000000000000000000000000000..efa9e858177e7e33f4e413cd4227673e1ba9bbf4
--- /dev/null
+++ b/appengine/config_service/ui/common/common-behaviors.html
@@ -0,0 +1,105 @@
+<!--
+ Copyright 2017 The LUCI Authors. All rights reserved.
+ Use of this source code is governed under the Apache License, Version 2.0
+ that can be found in the LICENSE file.
+
+ It contains the definition of the following Behaviors:
+
+ ConfigUIBehaviors.CommonBehavior
+
+ To use it, include
+ behaviors: [ConfigUIBehaviors.CommonBehavior]
+ in the creation of any Polymer element.
+
+ ConfigUIBehaviors.CommonBehavior contains shared methods to ease
+ templating, such _isEmpty() and _not(), as well as general utility methods
+ such as _formatDate and _getTimestamp.
+ -->
+
+ <script>
+ window.ConfigUIBehaviors = window.ConfigUIBehaviors || {};
+ (function(){
+ // This behavior wraps up all the shared config UI functionality.
+ ConfigUIBehaviors.CommonBehavior = {
+
+ _formatDate: function(timestamp) {
+ if (timestamp === null) return "Not Found";
+
+ var date = new Date(timestamp / 1000);
+ var seconds = Math.floor((new Date() - date) / 1000);
+
+ var interval = Math.floor(seconds / 31536000);
+ if (interval > 1) {
+ return interval + " years ago";
+ }
+ interval = Math.floor(seconds / 2592000);
+ if (interval > 1) {
+ return interval + " months ago";
+ }
+ interval = Math.floor(seconds / 86400);
+ if (interval > 1) {
+ return interval + " days ago";
+ }
+ interval = Math.floor(seconds / 3600);
+ if (interval > 1) {
+ return interval + " hours ago";
+ }
+ interval = Math.floor(seconds / 60);
+ if (interval > 1) {
+ return interval + " minutes ago";
+ }
+ return Math.floor(seconds) + " seconds ago";
+ },
+
+ _formatRevision: function(revision) {
+ if (revision === "Not Found") return revision;
+ return revision.substring(0, 7);
+ },
+
+ _frontPageIsActive: function() {
+ if (this.frontPageIsActive === false) {
+ this.isLoading = true;
+ if (!this.initialized) {
+ document.addEventListener('fetch-configs', function() {
+ this.$.requestConfigs.generateRequest();
+ }.bind(this));
+ } else {
+ this.$.requestConfigs.generateRequest();
+ }
+ }
+ },
+
+ _getExactTime: function(timestamp) {
+ if (timestamp === null) return "Not Found";
+ var date = new Date(timestamp / 1000);
+ return date.toString();
+ },
+
+ _getTimestamp: function(lastImportAttempt, revision) {
+ if (lastImportAttempt && lastImportAttempt.success) {
+ return lastImportAttempt.revision.timestamp;
+ } else if (revision && revision.timestamp) {
+ return revision.timestamp;
+ } else {
+ return null;
+ }
+ },
+
+ _getRevision: function(revision) {
+ if (revision) {
+ return revision.id;
+ } else {
+ return "Not Found"
+ }
+ },
+
+ _isEmpty: function(list) {
+ return list.length === 0;
+ },
+
+ _not: function(a) {
+ return !a;
+ },
+ };
+ })();
+</script>
« no previous file with comments | « no previous file | appengine/config_service/ui/src/config-ui/config-set.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698