Chromium Code Reviews| 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> |