Skip to content

Commit 65e0e03

Browse files
committed
Change some function references to ES6 style.
Convert some var to let. Lock in container image title color, add a thing border with varied color. Tested on Docker for Mac
1 parent 1f3b103 commit 65e0e03

File tree

3 files changed

+61
-69
lines changed

3 files changed

+61
-69
lines changed

src/data-provider.js

+44-37
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import {
1212
getWebSocket
1313
} from './utils/request';
1414

15-
var STARTED = 0;
15+
let STARTED = 0;
1616

17-
let SINGLETON,
18-
CURRENT_SERVICES_URIS;
17+
let SINGLETON;
18+
let CURRENT_SERVICES_URIS;
1919

2020
let PHYSICAL_STRUCT;
2121

22-
function tutumEventHandler(e) {
22+
let tutumEventHandler = (e) => {
2323
console.log(e);
24-
}
24+
};
2525

2626
let nodeOrContainerExists = (arr, value) => {
2727

@@ -40,16 +40,18 @@ let strToHash = (str) => {
4040
return hash;
4141
};
4242

43-
let stringToColour = (str) => {
44-
let hash = strToHash(str);
45-
46-
// int/hash to hex
47-
let colour = "#";
43+
let hashToHexColor = (hash) => {
44+
let color = "#";
4845
for (var i = 0; i < 3; ) {
49-
colour += ("00" + ((hash >> i++ * 8) & 0xFF).toString(16)).slice(-2);
46+
color += ("00" + ((hash >> i++ * 8) & 0xFF).toString(16)).slice(-2);
5047
}
48+
return color;
49+
}
5150

52-
return colour;
51+
let stringToColor = (str) => {
52+
let hash = strToHash(str);
53+
let color = hashToHexColor(hash);
54+
return color;
5355
};
5456

5557
let physicalStructProvider = ([initialNodes, initialContainers]) => {
@@ -65,23 +67,25 @@ let physicalStructProvider = ([initialNodes, initialContainers]) => {
6567
var node = _.find(cluster.children,{ ID:NodeID });
6668
if(!node) return;
6769
var dt = new Date(cloned.UpdatedAt);
68-
var color= stringToColour(cloned.ServiceID);
70+
var color = stringToColor(cloned.ServiceID);
6971
let tagName = cloned.Spec.ContainerSpec.Image.split(':')[1];
70-
if(!tagName) {
71-
tagName = "latest";
72-
}
73-
74-
let imageTag ="<span style='color:" + color+"; font-weight: bold;font-size: 12px'>"+ cloned.Spec.ContainerSpec.Image.split(':')[0] +"</span>"+
75-
"<br/> tag : "+ tagName +
76-
"<br/>" + (cloned.Spec.ContainerSpec.Args?" cmd : "+cloned.Spec.ContainerSpec.Args:"" ) +
77-
"<br/> updated : "+dt.getDate()+"/"+(dt.getMonth()+1)+" "+ dt.getHours()+":"+dt.getMinutes()+
78-
"<br/> ID : "+cloned.Status.ContainerStatus.ContainerID+
79-
"<br/>";
72+
let dateStamp = dt.getDate()+"/"+(dt.getMonth()+1)+" "+ dt.getHours()+":"+dt.getMinutes();
73+
74+
let imageTag ="<div style='height: 100%; padding: 5px 5px 5px 5px; border: 1px solid "+color+"'>"+
75+
"<span style='color: white; font-weight: bold;font-size: 12px'>"+ cloned.Spec.ContainerSpec.Image.split(':')[0] +"</span>"+
76+
"<br/> tag : " + (tagName ? tagName : "latest") +
77+
"<br/>" + (cloned.Spec.ContainerSpec.Args?" cmd : "+cloned.Spec.ContainerSpec.Args:"" ) +
78+
"<br/> updated : " + dateStamp +
79+
"<br/> ID : "+cloned.Status.ContainerStatus.ContainerID+
80+
"<br/>"+
81+
"</div>";
82+
8083
cloned.tag = imageTag;
8184
node.children.push(cloned);
8285
return true;
8386
});
8487
},
88+
8589
updateContainer = (container) => {
8690
let {uuid, node} = container;
8791
let [nodeUuid] = uuidRegExp.exec(node);
@@ -96,6 +100,7 @@ let physicalStructProvider = ([initialNodes, initialContainers]) => {
96100
return true;
97101
});
98102
},
103+
99104
data = () => {
100105
let clone = _.cloneDeep(root);
101106
_.remove(clone,({uuid,children}) => {
@@ -104,19 +109,23 @@ let physicalStructProvider = ([initialNodes, initialContainers]) => {
104109

105110
return {root: clone};
106111
},
112+
107113
addNodeCluster = (nodeCluster) => {
108114
var cloned = Object.assign({},nodeCluster);
109115
cloned.children = [];
110116
console.log(cloned);
111117
root.push(cloned);
112118
},
119+
113120
removeNodeCluster = (nodeCluster) => {
114121
_.remove(root,{ uuid: nodeCluster.uuid });
115122
},
123+
116124
updateNodeCluster = (nodeCluster) => {
117125
var currentCluster = _.findWhere(root,{ uuid: nodeCluster.uuid });
118126
Object.assign(currentCluster,nodeCluster);
119127
},
128+
120129
addNode = (node) => {
121130
let cloned = Object.assign({},node);
122131
cloned.children = [];
@@ -206,15 +215,12 @@ let physicalStructProvider = ([initialNodes, initialContainers]) => {
206215
};
207216
}
208217

209-
210-
211218
class DataProvider extends EventEmitter {
212-
constructor(){
219+
constructor() {
213220
super()
214-
215221
}
216222

217-
start(){
223+
start() {
218224
STARTED = 1;
219225
//console.log(STARTED);
220226
var clusterInit = Promise.all([
@@ -226,16 +232,18 @@ class DataProvider extends EventEmitter {
226232
return resources;
227233
});
228234

229-
Promise.all([ clusterInit ])
235+
Promise.all([ clusterInit ])
230236
.then(([resources]) => {
231-
PHYSICAL_STRUCT = physicalStructProvider(resources);
232-
this.emit('infrastructure-data',PHYSICAL_STRUCT.data());
233-
this.emit('start-reload');
237+
PHYSICAL_STRUCT = physicalStructProvider(resources);
238+
this.emit('infrastructure-data',PHYSICAL_STRUCT.data());
239+
this.emit('start-reload');
234240
});
235241
}
242+
236243
reload() {
237-
if(STARTED ==0) return;
244+
if(STARTED == 0) return;
238245
STARTED++;
246+
239247
// console.log(STARTED);
240248
var clusterInit = Promise.all([
241249
getAllNodes(),
@@ -246,13 +254,12 @@ class DataProvider extends EventEmitter {
246254
return resources;
247255
});
248256

249-
Promise.all([ clusterInit ])
250-
.then(([resources]) => {
257+
Promise.all([ clusterInit ])
258+
.then(([resources]) => {
251259
PHYSICAL_STRUCT.updateData(resources);
252-
this.emit('infrastructure-data',PHYSICAL_STRUCT.data());
260+
this.emit('infrastructure-data', PHYSICAL_STRUCT.data());
253261
});
254262
}
255-
256263
}
257264

258265
export default SINGLETON = new DataProvider();

src/main.js

+10-19
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ require('normalize.css');
88
require('animate.css/animate.css');
99
require('./main.less');
1010

11-
12-
1311
function parseQuery(qstr) {
1412
var query = {};
1513
var a = qstr.substr(1).split('&');
@@ -19,35 +17,28 @@ function parseQuery(qstr) {
1917
}
2018
return query;
2119
}
22-
let query = parseQuery(window.location.search);
2320

21+
let query = parseQuery(window.location.search);
22+
let tabPhysical = document.getElementById('tab-physical');
23+
let physical = document.getElementById('vis-physical');
2424

25-
var tabPhysical = document.getElementById('tab-physical');
26-
27-
var physical = document.getElementById('vis-physical');
28-
29-
/*
30-
if(!query.tab || query.tab === 'tab1'){
31-
document.body.className = 'tab1';
32-
addClass(physical,'hidden');
33-
} else {
34-
document.body.className = 'tab2';
35-
removeClass(tabPhysical,'hidden');
36-
}
37-
*/
3825
tabPhysical.addEventListener('click',() => {
3926
removeClass(physical, 'hidden');
4027
removeClass(tabPhysical, 'hidden');
4128

4229
document.body.className = 'tab2';
4330
});
4431

32+
/* Enable polling */
4533
function reload(){
4634
provider.reload();
47-
setTimeout(reload,MS);
35+
setTimeout(reload, MS);
4836
}
49-
console.log(MS);
50-
provider.on('infrastructure-data',physicalVisualization.render);
37+
38+
console.log("Polling refresh: " + MS);
39+
40+
provider.on('infrastructure-data', physicalVisualization.render);
5141
provider.start();
5242
reload();
43+
5344
//TODO: Emit Event that requeries data, removes old data recreates visualizations

src/vis-physical/index.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ var vis = d3.select('#app')
1313
.attr('id','vis-physical');
1414

1515
var wrapper = vis.append('div')
16-
.classed('wrapper',true)
16+
.classed('wrapper', true);
17+
1718
function removeVis() {
1819
cluster = wrapper.selectAll('.node-cluster')
1920
cluster.remove();
2021
}
21-
function render ({root}) {
22+
23+
function render ({root}) {
2224
var cluster, node, container, clusterEnter, nodeEnter;
2325
cluster = wrapper.selectAll('.node-cluster').data(root);
2426

@@ -61,7 +63,8 @@ function render ({root}) {
6163

6264
cluster
6365
.select('.node-cluster-meta')
64-
.html(({name,state='',node_type='',region=''}) => {
66+
.html(({name,state = '', node_type = '', region = ''}) => {
67+
6568
// This is a HORRIBLE hack
6669
// but I don't wanna fetch nodeTypes from the API as from now
6770
var displayType = node_type.split('/')[4] || ''; // horrible
@@ -88,18 +91,9 @@ function render ({root}) {
8891
container.on('mouseenter',null);
8992
container.on('mouseleave',null);
9093

91-
//container.on('mouseenter',function(){
92-
// d3.select(this).html((d) => d.name);
93-
//});
94-
95-
//container.on('mouseleave',function(){
96-
// d3.select(this).html('');
97-
//});
98-
9994
cluster.exit().remove();
10095
container.exit().remove();
10196
node.exit().remove();
102-
10397
}
10498

105-
export default {render}
99+
export default { render }

0 commit comments

Comments
 (0)