| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 this.swarming = this.swarming || function() { | 5 this.swarming = this.swarming || function() { |
| 6 | 6 |
| 7 var swarming = {}; | 7 var swarming = {}; |
| 8 | 8 |
| 9 swarming.stableSort = function(arr, comp) { | 9 swarming.stableSort = function(arr, comp) { |
| 10 if (!arr || !comp) { | 10 if (!arr || !comp) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 swarming.naturalCompare = function(a, b) { | 43 swarming.naturalCompare = function(a, b) { |
| 44 // Try numeric, aka "natural" sort and use it if ns is not NaN. | 44 // Try numeric, aka "natural" sort and use it if ns is not NaN. |
| 45 // Javascript will try to corece these to numbers or return NaN. | 45 // Javascript will try to corece these to numbers or return NaN. |
| 46 var ns = a - b; | 46 var ns = a - b; |
| 47 if (!isNaN(ns)) { | 47 if (!isNaN(ns)) { |
| 48 return ns; | 48 return ns; |
| 49 } | 49 } |
| 50 return String(a).localeCompare(b); | 50 return String(a).localeCompare(b); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // postWithToast makes a post request and updates the error-toast |
| 54 // element with the response, regardless of failure. See error-toast.html |
| 55 // for more information. |
| 56 swarming.postWithToast = function(url, msg, auth_headers) { |
| 57 // Keep toast displayed until we hear back from the request. |
| 58 sk.errorMessage(msg, 0); |
| 59 |
| 60 sk.request("POST", url, undefined, auth_headers).then(function(response) { |
| 61 sk.errorMessage("Request sent. Response: "+response, 3000); |
| 62 }).catch(function(reason) { |
| 63 console.log("Request failed", reason); |
| 64 sk.errorMessage("Request failed. Reason: "+reason, 5000); |
| 65 }); |
| 66 } |
| 67 |
| 53 return swarming; | 68 return swarming; |
| 54 }(); | 69 }(); |
| OLD | NEW |