consul-templaterb 1.15.2 → 1.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 265b3062a39b78eaa45775583d748de5c349ac21
4
- data.tar.gz: ad53bb875e0dabdf005c1081cd28b42c5e482bc5
2
+ SHA256:
3
+ metadata.gz: e5d7b1fe74f3740048aeef233a2f97097f90042fbdfa8a43776ec9b3ed1d3cab
4
+ data.tar.gz: 7bd5f3cea503187786e05b62d0748afaf0de8c1629333e70bec2689d88a2e79c
5
5
  SHA512:
6
- metadata.gz: a87af9eb230325e5d9f1f032e97e078c9ef2365e5ade766818eafd97dfdce9d537c1a2961a26aa50d8a0086ccc55ec20bbb7224dc5dd773486844dc4ceafcb11
7
- data.tar.gz: d09545ef6d131b6324c198a9eca24fea15a10a58fbce25da44a97e68b31726a5372929cd606cba35d2c2674927c986c88ef2e54d9407ea7df44038d7f761f7d3
6
+ metadata.gz: eabeef36879669e2dc937f06fcac7a7f92b1f107840a8717b11df2b9527df9da1b0bdc490c3db5c54b0e826502557e8a84f8ae72216e98736f95650893085d0a
7
+ data.tar.gz: f982bafbe7e6060f6db7ae0cf60b576ba4c3ff4c33b645636f6aa0b309108ba84f63fbc11941e3a0a692de1bb96343be18722611d21ca7f5ff09f330b67d030d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## (UNRELEASED)
4
4
 
5
+ ## 1.15.3 (June 20, 2019)
6
+
7
+ Improved consul-ui Javascript #37 thanks to [@warrenseine](https://github.com/warrenseine)
8
+
5
9
  ## 1.15.2 (June 12, 2019)
6
10
 
7
11
  IMPROVEMENTS
@@ -1,5 +1,5 @@
1
1
  module Consul
2
2
  module Async
3
- VERSION = '1.15.2'.freeze
3
+ VERSION = '1.15.3'.freeze
4
4
  end
5
5
  end
@@ -16,7 +16,7 @@
16
16
  }
17
17
 
18
18
  #service-wrapper, #instances-wrapper, #keys-wrapper {
19
- overflow: scroll;
19
+ overflow-y: scroll;
20
20
  border-top-left-radius: 0px;
21
21
  border-top-right-radius: 0px;
22
22
  border-style: solid;
@@ -4,7 +4,7 @@ class ConsulKeys {
4
4
  this.fetchRessource();
5
5
  this.keysList = $("#keys-list");
6
6
  this.keysFilter = $("#keys-filter");
7
- this.keysFilter.keyup(this.filterService);
7
+ this.keysFilter.keyup(debounce(this.filterService, 250));
8
8
  this.refresh = parseInt(refresh);
9
9
  this.keysFilterCounter = $("#keys-counter");
10
10
  this.keysFilterCount = 0;
@@ -3,10 +3,7 @@ class ConsulNodes {
3
3
  this.ressourceURL = ressourceURL;
4
4
  this.fetchRessource();
5
5
  this.instanceFilter = $("#instance-filter");
6
- this.instanceFilter.keyup(function (e) {
7
- clearTimeout(consulNodes.timeout);
8
- consulNodes.timeout = setTimeout(consulNodes.filterInstances, 400);
9
- });
6
+ this.instanceFilter.keyup(debounce(this.filterInstances, 400));
10
7
  this.refresh = parseInt(refresh);
11
8
  this.filterStatus = null;
12
9
  this.maxDisplayed = 100;
@@ -1,12 +1,12 @@
1
1
  class ConsulService {
2
- constructor(ressourceURL, refresh) {
3
- this.ressourceURL = ressourceURL;
2
+ constructor(resourceURL, refresh) {
3
+ this.resourceURL = resourceURL;
4
4
  this.fetchRessource();
5
5
  this.serviceList = $("#service-list");
6
6
  this.serviceFilter = $("#service-filter");
7
- this.serviceFilter.keyup(this.filterService);
7
+ this.serviceFilter.keyup(debounce(this.filterService, 250));
8
8
  this.instanceFilter = $("#instance-filter");
9
- this.instanceFilter.keyup(this.filterInstances);
9
+ this.instanceFilter.keyup(debounce(this.filterInstances, 250));
10
10
  this.refresh = parseInt(refresh);
11
11
  this.filterStatus = null;
12
12
  this.serviceFilterCounter = $("#service-counter");
@@ -33,135 +33,132 @@ class ConsulService {
33
33
  }
34
34
  }
35
35
 
36
- fetchRessource() {
37
- $.ajax({url: this.ressourceURL, cache: false, dataType: "json", sourceObject: this, success: function(result){
38
- consulService.initRessource(result);
39
- }});
36
+ async fetchRessource() {
37
+ const response = await fetch(this.resourceURL);
38
+ const result = await response.json();
39
+ await this.initRessource(result);
40
40
  }
41
41
 
42
- initRessource(data) {
42
+ async initRessource(data) {
43
43
  this.data = data;
44
- this.reloadServiceList();
44
+ await this.reloadServiceList();
45
45
  console.log('Data generated at: ' + data['generated_at']);
46
46
 
47
47
  var urlParam = new URL(location.href).searchParams.get('service');
48
- if (urlParam === null) {
49
- var servicePrefix = '#service_'
50
- if (location.hash.startsWith(servicePrefix)) {
51
- urlParam = location.hash.substr(servicePrefix.length)
52
- }
53
- }
48
+
54
49
  if (urlParam) {
55
50
  var nodes = document.getElementById('service-list').childNodes;
56
- for(var i in nodes) {
57
- if($(nodes[i]).find(".service-name").html() == urlParam) {
58
- var selectedElement = $(nodes[i])
51
+ for (const node of nodes) {
52
+ if($(node).find(".service-name").html() == urlParam) {
53
+ var selectedElement = $(node)
59
54
  this.selectService(selectedElement);
60
55
  selectedElement.focus()
61
56
  break;
62
57
  }
63
58
  }
64
- } else {
59
+ this.serviceFilter.val(urlParam);
60
+ this.filterService()
61
+ } else {
62
+ var servicePrefix = '#service_'
63
+ if (location.hash.startsWith(servicePrefix)) {
64
+ urlParam = location.hash.substr(servicePrefix.length)
65
+ }
65
66
  this.selectService(document.getElementById('service-list').firstElementChild);
66
67
  }
67
68
 
68
69
  if(this.refresh > 0) {
69
70
  setTimeout(this.fetchRessource, this.refresh * 1000);
70
71
  }
71
-
72
- let urlServiceParam = new URL(location.href).searchParams.get('filter');
73
- if (urlServiceParam === null) {
74
- return
75
- } else if (urlServiceParam) {
76
- this.serviceFilter.val(urlServiceParam);
77
- this.filterService()
78
- }
79
72
  }
80
73
 
81
- reloadServiceList() {
74
+ async reloadServiceList() {
82
75
  this.serviceList.html('');
83
76
  this.serviceFilterCount = 0;
84
77
 
85
- let idx = 0;
86
- let lastFav = null;
87
78
  if (!this.data || !this.data.services) {
88
79
  console.log("No data to display");
89
80
  } else {
90
- for (var serviceName in this.data.services) {
91
- var service = this.data.services[serviceName];
92
- var serviceStatus = buildServiceStatus(service);
93
-
94
- var listItem = document.createElement('li');
95
- listItem.setAttribute('onfocus','consulService.onClickServiceName(this)');
96
- listItem.setAttribute('onclick','consulService.onClickServiceName(this)');
97
- listItem.setAttribute('value',serviceName);
98
- listItem.setAttribute('data-fav', this.favorites[serviceName] ? 1 : 0);
99
- listItem.setAttribute('data-index', idx);
100
- var listItemClass = 'serviceListItem list-group-item list-group-item-action';
101
-
102
- var statuses = document.createElement('div');
103
- statuses.setAttribute('class','statuses float-right');
104
-
105
- if (!!serviceStatus['passing']) {
106
- statuses.appendChild(createBadge('badge-success passing', serviceStatus['passing']));
107
- listItem.setAttribute('status', 'passing');
108
- }
81
+ const services = Object.values(this.data.services).map((service, index) => ({ service, index }));
82
+ const favorites = services.filter(({ service }) => this.favorites[service.name]);
83
+ const others = services.filter(({ service }) => !this.favorites[service.name]);
84
+
85
+ const appendServiceAsync = ({ service, index }) =>
86
+ new Promise(resolve =>
87
+ setTimeout(() => {
88
+ this.appendService(service, index);
89
+ resolve();
90
+ }, 0)
91
+ );
92
+
93
+ await Promise.all([...favorites, ...others].map(appendServiceAsync));
94
+ }
109
95
 
110
- if (!!serviceStatus['warning']) {
111
- statuses.appendChild(createBadge('badge-warning warning', serviceStatus['warning']));
112
- listItem.setAttribute('status', 'warning');
113
- }
96
+ this.serviceFilterCounter.html(this.serviceFilterCount);
97
+ resizeWrapper('service-wrapper', 'service-list');
98
+ this.filterService();
99
+ }
114
100
 
115
- if (!!serviceStatus['critical']) {
116
- statuses.appendChild(createBadge('badge-danger critical', serviceStatus['critical']));
117
- listItem.setAttribute('status', 'critical');
118
- }
101
+ appendService(service, index) {
102
+ var serviceName = service.name;
103
+ var serviceStatus = buildServiceStatus(service);
119
104
 
120
- statuses.appendChild(createBadge('badge-dark', (serviceStatus['total'] || 0)));
105
+ var listItem = document.createElement('li');
106
+ listItem.setAttribute('onfocus','consulService.onClickServiceName(this)');
107
+ listItem.setAttribute('onclick','consulService.onClickServiceName(this)');
108
+ listItem.setAttribute('value', serviceName);
109
+ listItem.setAttribute('data-fav', this.favorites[serviceName] ? 1 : 0);
110
+ listItem.setAttribute('data-index', index);
111
+ var listItemClass = 'serviceListItem list-group-item list-group-item-action';
121
112
 
122
- statuses.append(this.buildFavButton(serviceName));
113
+ var statuses = document.createElement('div');
114
+ statuses.setAttribute('class','statuses float-right');
123
115
 
124
- listItem.appendChild(statuses);
125
- if (!!service['kind']) {
126
- var kind = document.createElement('div');
127
- kind.setAttribute('class','kind float-right');
128
- kind.appendChild(createBadge('badge-info kind', service['kind']));
129
- listItem.appendChild(kind);
130
- listItemClass+= " kind-" + service['kind'];
131
- }
132
- listItem.setAttribute('class', listItemClass);
116
+ if (!!serviceStatus['passing']) {
117
+ statuses.appendChild(createBadge('badge-success passing', serviceStatus['passing']));
118
+ listItem.setAttribute('status', 'passing');
119
+ }
133
120
 
134
- var serviceNameItem = document.createElement('div');
135
- serviceNameItem.setAttribute('class', 'service-name');
136
- serviceNameItem.appendChild(document.createTextNode(serviceName));
137
- listItem.appendChild(serviceNameItem);
121
+ if (!!serviceStatus['warning']) {
122
+ statuses.appendChild(createBadge('badge-warning warning', serviceStatus['warning']));
123
+ listItem.setAttribute('status', 'warning');
124
+ }
138
125
 
139
- var serviceTagsItem = document.createElement('div');
140
- serviceTagsItem.setAttribute('class', 'service-tags');
126
+ if (!!serviceStatus['critical']) {
127
+ statuses.appendChild(createBadge('badge-danger critical', serviceStatus['critical']));
128
+ listItem.setAttribute('status', 'critical');
129
+ }
141
130
 
142
- for (var i = 0; i < service.tags.length; i++) {
143
- serviceTagsItem.appendChild(createBadge('float-right badge-' + (i%2?'secondary':'info') , service.tags[i]));
144
- }
131
+ statuses.appendChild(createBadge('badge-dark', (serviceStatus['total'] || 0)));
145
132
 
146
- listItem.appendChild(serviceTagsItem);
147
- this.serviceFilterCount += 1;
133
+ statuses.append(this.buildFavButton(serviceName));
148
134
 
149
- if (this.favorites[serviceName] && lastFav) {
150
- lastFav.after(listItem);
151
- lastFav = listItem;
152
- } else if (this.favorites[serviceName] && !lastFav) {
153
- this.serviceList.prepend(listItem);
154
- lastFav = listItem;
155
- } else {
156
- this.serviceList.append(listItem);
157
- }
135
+ listItem.appendChild(statuses);
136
+ if (!!service['kind']) {
137
+ var kind = document.createElement('div');
138
+ kind.setAttribute('class','kind float-right');
139
+ kind.appendChild(createBadge('badge-info kind', service['kind']));
140
+ listItem.appendChild(kind);
141
+ listItemClass+= " kind-" + service['kind'];
142
+ }
143
+ listItem.setAttribute('class', listItemClass);
158
144
 
159
- idx++;
160
- }
145
+ var serviceNameItem = document.createElement('div');
146
+ serviceNameItem.setAttribute('class', 'service-name');
147
+ serviceNameItem.appendChild(document.createTextNode(serviceName));
148
+ listItem.appendChild(serviceNameItem);
149
+
150
+ var serviceTagsItem = document.createElement('div');
151
+ serviceTagsItem.setAttribute('class', 'service-tags');
152
+
153
+ for (var i = 0; i < service.tags.length; i++) {
154
+ serviceTagsItem.appendChild(createBadge('float-right badge-' + (i%2?'secondary':'info') , service.tags[i]));
161
155
  }
162
- this.serviceFilterCounter.html(this.serviceFilterCount);
163
- resizeWrapper('service-wrapper', 'service-list');
164
- this.filterService();
156
+
157
+ listItem.appendChild(serviceTagsItem);
158
+
159
+ this.serviceList.append(listItem);
160
+
161
+ this.serviceFilterCount += 1;
165
162
  }
166
163
 
167
164
  filterService() {
@@ -5,10 +5,10 @@ class ServiceTimeline {
5
5
  this.fetchRessource(true);
6
6
  this.serviceList = $("#service-list");
7
7
  this.serviceFilter = $("#service-filter");
8
- this.serviceFilter.keyup(this.filterService);
8
+ this.serviceFilter.keyup(debounce(this.filterService, 250));
9
9
  this.serviceInstanceFilter = '';
10
10
  this.instanceFilter = $("#instance-filter");
11
- this.instanceFilter.keyup(this.doFilter);
11
+ this.instanceFilter.keyup(debounce(this.doFilter, 250));
12
12
  this.refresh = parseInt(refresh);
13
13
  this.filterStatus = null;
14
14
  this.refreshTimeout = null;
@@ -12,6 +12,19 @@ function buildServiceStatus(service) {
12
12
  return serviceStatus;
13
13
  }
14
14
 
15
+ function debounce(func, wait) {
16
+ var timeout;
17
+ return function() {
18
+ var context = this, args = arguments;
19
+ var later = function() {
20
+ timeout = null;
21
+ func.apply(context, args);
22
+ };
23
+ clearTimeout(timeout);
24
+ timeout = setTimeout(later, wait);
25
+ };
26
+ };
27
+
15
28
  function padDateUnit(x) {
16
29
  return x > 9 ? x : '0' + x;
17
30
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consul-templaterb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.2
4
+ version: 1.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SRE Core Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-12 00:00:00.000000000 Z
11
+ date: 2019-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -242,8 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
242
  - !ruby/object:Gem::Version
243
243
  version: '0'
244
244
  requirements: []
245
- rubyforge_project:
246
- rubygems_version: 2.6.14.4
245
+ rubygems_version: 3.0.4
247
246
  signing_key:
248
247
  specification_version: 4
249
248
  summary: Implementation of Consul template using Ruby and .erb templating language