| <!-- The <query2-count-sk> custom element declaration. |
| |
| Reports the number of matches for a given query. |
| |
| Attributes: |
| current_query - The current query to count against. |
| |
| url - The URL to POST the query to. |
| |
| Events: |
| None. |
| |
| Methods: |
| None. |
| --> |
| |
| <dom-module id="query2-count-sk"> |
| <style> |
| </style> |
| <template> |
| <div id=matches></div> |
| </template> |
| </dom-module> |
| |
| <script> |
| Polymer({ |
| is: "query2-count-sk", |
| |
| properties: { |
| current_query: { |
| type: String, |
| value: "", |
| reflectToAttribute: true, |
| observer: "_currentQueryChange", |
| }, |
| url: { |
| type: String, |
| value: "/_/count/", |
| reflectToAttribute: true, |
| }, |
| _countInProgress: { |
| type: Boolean, |
| value: false, |
| reflectToAttribute: true, |
| }, |
| }, |
| |
| _currentQueryChange: function() { |
| if (this._countInProgress === true) { |
| return |
| } |
| this._countInProgress = true; |
| let now = Math.floor(Date.now()/1000); |
| let body = { |
| q: this.current_query, |
| end: now, |
| begin: now - 24*60*60, |
| }; |
| sk.post(this.url, JSON.stringify(body)).then(JSON.parse).then(function(json) { |
| this._countInProgress = false; |
| this.$.matches.textContent = json.count; |
| }.bind(this)).catch(function() { |
| this._countInProgress = false; |
| }); |
| }, |
| |
| }); |
| </script> |