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

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: Nit: forgot to add launch icon to config set page 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
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..cd99384acba84d296a0a422233e06eafa4e66ca4
--- /dev/null
+++ b/appengine/config_service/ui/common/common-behaviors.html
@@ -0,0 +1,87 @@
+<!--
+ 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 = {
Sergey Berezin 2017/07/31 20:21:18 Could you add unittests for these functions?
cwpayton 2017/07/31 23:40:52 Done.
+
+ _formatDate: function(timestamp) {
+ var date = new Date(timestamp / 1000);
+ var month = date.getMonth() + 1;
+ if (month < 10) {
+ month = "0" + month;
+ }
+ var day = date.getDate();
+ if (day < 10) {
+ day = "0" + day;
+ }
+ var hours = date.getHours();
+ if (hours < 10) {
+ hours = "0" + hours;
+ }
+ var minutes = date.getMinutes();
+ if (minutes < 10) {
+ minutes = "0" + minutes;
+ }
+ return month + "/" + day + "/" + date.getFullYear() +
+ " " + hours + ":" + minutes;
Sergey Berezin 2017/07/31 20:21:18 Why not just use date.toString()? In particular, i
cwpayton 2017/07/31 23:40:52 Done.
+ },
+
+ _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();
+ }
+ }
+ },
+
+ _getTimestamp: function(lastImportAttempt, revision) {
+ if (lastImportAttempt && lastImportAttempt.success) {
+ return this._formatDate(lastImportAttempt.revision.timestamp);
+ } else if (revision && revision.timestamp) {
+ return this._formatDate(revision.timestamp);
+ } else {
+ return "Not Found"
+ }
+ },
+
+ _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>

Powered by Google App Engine
This is Rietveld 408576698