| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 Copyright 2017 The LUCI Authors. All rights reserved. |
| 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 that can be found in the LICENSE file. |
| 5 |
| 6 It contains the definition of the following Behaviors: |
| 7 |
| 8 ConfigUIBehaviors.CommonBehavior |
| 9 |
| 10 To use it, include |
| 11 behaviors: [ConfigUIBehaviors.CommonBehavior] |
| 12 in the creation of any Polymer element. |
| 13 |
| 14 ConfigUIBehaviors.CommonBehavior contains shared methods to ease |
| 15 templating, such _isEmpty() and _not(), as well as general utility methods |
| 16 such as _formatDate and _getTimestamp. |
| 17 --> |
| 18 |
| 19 <script> |
| 20 window.ConfigUIBehaviors = window.ConfigUIBehaviors || {}; |
| 21 (function(){ |
| 22 // This behavior wraps up all the shared config UI functionality. |
| 23 ConfigUIBehaviors.CommonBehavior = { |
| 24 |
| 25 _formatDate: function(timestamp) { |
| 26 if (timestamp === null) return "Not Found"; |
| 27 |
| 28 var date = new Date(timestamp / 1000); |
| 29 var seconds = Math.floor((new Date() - date) / 1000); |
| 30 |
| 31 var interval = Math.floor(seconds / 31536000); |
| 32 if (interval > 1) { |
| 33 return interval + " years ago"; |
| 34 } |
| 35 interval = Math.floor(seconds / 2592000); |
| 36 if (interval > 1) { |
| 37 return interval + " months ago"; |
| 38 } |
| 39 interval = Math.floor(seconds / 86400); |
| 40 if (interval > 1) { |
| 41 return interval + " days ago"; |
| 42 } |
| 43 interval = Math.floor(seconds / 3600); |
| 44 if (interval > 1) { |
| 45 return interval + " hours ago"; |
| 46 } |
| 47 interval = Math.floor(seconds / 60); |
| 48 if (interval > 1) { |
| 49 return interval + " minutes ago"; |
| 50 } |
| 51 return Math.floor(seconds) + " seconds ago"; |
| 52 }, |
| 53 |
| 54 _formatRevision: function(revision) { |
| 55 if (revision === "Not Found") return revision; |
| 56 return revision.substring(0, 7); |
| 57 }, |
| 58 |
| 59 _frontPageIsActive: function() { |
| 60 if (this.frontPageIsActive === false) { |
| 61 this.isLoading = true; |
| 62 if (!this.initialized) { |
| 63 document.addEventListener('fetch-configs', function() { |
| 64 this.$.requestConfigs.generateRequest(); |
| 65 }.bind(this)); |
| 66 } else { |
| 67 this.$.requestConfigs.generateRequest(); |
| 68 } |
| 69 } |
| 70 }, |
| 71 |
| 72 _getExactTime: function(timestamp) { |
| 73 if (timestamp === null) return "Not Found"; |
| 74 var date = new Date(timestamp / 1000); |
| 75 return date.toString(); |
| 76 }, |
| 77 |
| 78 _getTimestamp: function(lastImportAttempt, revision) { |
| 79 if (lastImportAttempt && lastImportAttempt.success) { |
| 80 return lastImportAttempt.revision.timestamp; |
| 81 } else if (revision && revision.timestamp) { |
| 82 return revision.timestamp; |
| 83 } else { |
| 84 return null; |
| 85 } |
| 86 }, |
| 87 |
| 88 _getRevision: function(revision) { |
| 89 if (revision) { |
| 90 return revision.id; |
| 91 } else { |
| 92 return "Not Found" |
| 93 } |
| 94 }, |
| 95 |
| 96 _isEmpty: function(list) { |
| 97 return list.length === 0; |
| 98 }, |
| 99 |
| 100 _not: function(a) { |
| 101 return !a; |
| 102 }, |
| 103 }; |
| 104 })(); |
| 105 </script> |
| OLD | NEW |