Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #142 from Joaquin6/feature/flow-tracking
Browse files Browse the repository at this point in the history
Track of active flow with green lines
  • Loading branch information
JimTharioAmazon authored Jul 7, 2020
2 parents 17efbf8 + ea8a76c commit 75a5374
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 118 deletions.
143 changes: 69 additions & 74 deletions html/js/app/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,86 +10,85 @@ define(["jquery", "cookie", "app/window", "object_hash", "lodash"], function($,
var cookie_name_current = "MSAM_CURRENT",
cookie_name_prefix = "MSAM_ENDPOINT_",
session_current = "MSAM_CURRENT",
max_age = 7,
max_age = 7;

// return the stored connection objects
get_remembered = _.memoize(function() {
var history = [],
cookies = cookie.get();
for (let name of Object.keys(cookies)) {
if (name.startsWith(cookie_name_prefix)) {
var payload = cookies[name],
content = JSON.parse(window.atob(payload));
history.push(content);
}
// return the stored connection objects
var get_remembered = _.memoize(function() {
var history = [],
cookies = cookie.get();
for (let name of Object.keys(cookies)) {
if (name.startsWith(cookie_name_prefix)) {
var payload = cookies[name],
content = JSON.parse(window.atob(payload));
history.push(content);
}
return history;
}),
}
return history;
});

// return the session copy or the cookie copy, or null
get_current = _.memoize(function() {
var current = null;
var encoded = window.sessionStorage.getItem(session_current);
if (encoded) {
current = JSON.parse(window.atob(encoded));
}
// get the cookie and refresh the expiration
var payload = cookie.get(cookie_name_current);
// return the session copy or the cookie copy, or null
var get_current = _.memoize(function() {
var current = null;
var encoded = window.sessionStorage.getItem(session_current);
if (encoded) {
current = JSON.parse(window.atob(encoded));
}
// get the cookie and refresh the expiration
var payload = cookie.get(cookie_name_current);
if (payload) {
// set the cookie again for expiration
cookie.set(cookie_name_current, payload, {
expires: max_age
});
var name = payload;
payload = cookie.get(name);
// something?
if (payload) {
// set the cookie again for expiration
cookie.set(cookie_name_current, payload, {
cookie.set(name, payload, {
expires: max_age
});
var name = payload;
payload = cookie.get(name);
// something?
if (payload) {
// set the cookie again for expiration
cookie.set(name, payload, {
expires: max_age
});
// set the session storage if not already
if (!current) {
window.sessionStorage.setItem(session_current, payload);
current = JSON.parse(window.atob(payload));
}
// set the session storage if not already
if (!current) {
window.sessionStorage.setItem(session_current, payload);
current = JSON.parse(window.atob(payload));
}
}
return current;
}),

// update the history with another connection
set_current = function(url, api_key, store = true) {
clear_function_cache();
var current = [url, api_key];
window.sessionStorage.setItem(session_current, window.btoa(JSON.stringify(current)));
var cookie_name = cookie_name_prefix + hash.sha1(url);
var encoded = window.btoa(JSON.stringify(current));
if (store) {
// add or update MSAM_ENDPOINT_<ID> cookie
cookie.set(cookie_name, encoded, {
expires: max_age
});
// rewrite MSAM_CURRENT cookie
cookie.set(cookie_name_current, cookie_name, {
expires: max_age
});
} else {
cookie.remove(cookie_name_current);
cookie.remove(cookie_name);
}
},
}
return current;
});

clear_function_cache = function() {
get_current.cache.clear();
get_remembered.cache.clear();
},
// update the history with another connection
var set_current = function(url, api_key, store = true) {
clear_function_cache();
var current = [url, api_key];
window.sessionStorage.setItem(session_current, window.btoa(JSON.stringify(current)));
var cookie_name = cookie_name_prefix + hash.sha1(url);
var encoded = window.btoa(JSON.stringify(current));
if (store) {
// add or update MSAM_ENDPOINT_<ID> cookie
cookie.set(cookie_name, encoded, {
expires: max_age
});
// rewrite MSAM_CURRENT cookie
cookie.set(cookie_name_current, cookie_name, {
expires: max_age
});
} else {
cookie.remove(cookie_name_current);
cookie.remove(cookie_name);
}
};

var clear_function_cache = function() {
get_current.cache.clear();
get_remembered.cache.clear();
};

// is there a connection override on the URL parameters?
current_url = new URL(window.location),
endpoint = current_url.searchParams.get("endpoint"),
key = current_url.searchParams.get("key");
// is there a connection override on the URL parameters?
var current_url = new URL(window.location);
var endpoint = current_url.searchParams.get("endpoint");
var key = current_url.searchParams.get("key");

if (endpoint && key) {
// strip any trailing slashes
Expand All @@ -99,11 +98,7 @@ define(["jquery", "cookie", "app/window", "object_hash", "lodash"], function($,
}
console.log("Connection override with URL parameters");
set_current(endpoint, key, false);
};
}

return {
"get_remembered": get_remembered,
"set_current": set_current,
"get_current": get_current
};
return { get_remembered, set_current, get_current };
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ define(["jquery", "app/model", "app/server", "app/connections"],
"arrows": "to",
"color": {
"color": "black"
}
},
dashes: false,
});
}
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ define(["jquery", "app/model", "app/server", "app/connections"],
"arrows": "to",
"color": {
"color": "black"
}
},
dashes: false,
});
}
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ define(["jquery", "lodash", "app/model", "app/server", "app/connections"],
label: 'HLS',
arrows: "to",
color: { color: "black" },
dashes: false,
};
const hasMoreConnections = _.filter(connections, function(o) {
if (o.from === connection.from && o.to === connection.to) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ define(["jquery", "app/model", "app/server", "app/connections"],
"arrows": "to",
"color": {
"color": "black"
}
},
dashes: false,
});
}
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ define(["jquery", "app/model", "app/server", "app/connections"],
label: data.program,
arrows: 'to',
color: { color: 'black' },
dashes: false,
};
const shouldEndWith = connection.arn.endsWith('0') ? '1' : '0';
const hasMoreConnections = _.filter(connections, function(o) {
Expand Down
39 changes: 11 additions & 28 deletions html/js/app/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,16 @@ define(["jquery", "vis", "app/plugins", "app/server", "app/connections"], functi
return new Promise(function(resolve, reject) {
server.get(url + "/cached/arn/" + arn, api_key).then(function(cached) {
// we should get 0 or 1 results only
if (cached && cached.length == 1) {
var cache_entry = cached[0];
var data = JSON.parse(cache_entry.data);
// node or connection?
var node;
if (data.to && data.from) {
node = edges.get(arn);
} else {
node = nodes.get(arn);
}
if (!node) {
reject("arn " + arn + " not found");
} else {
node.data = data;
resolve(node);
}
} else {
reject("arn " + arn + " not found");
}
if (!cached || !cached.length) return reject(`arn ${arn} not found`);

var cache_entry = cached[0];
var data = JSON.parse(cache_entry.data);
// node or connection?
var node = data.to && data.from ? edges.get(arn) : nodes.get(arn);
if (!node) return reject(`arn ${arn} not found`);

node.data = data;
resolve(node);
}).catch(function(error) {
console.log(error);
reject(error);
Expand Down Expand Up @@ -112,13 +103,5 @@ define(["jquery", "vis", "app/plugins", "app/server", "app/connections"], functi
// clear the model at module definition
reset();

return {
"nodes": nodes,
"edges": edges,
"reset": reset,
"map": map,
"update": update,
"put_records": put_records,
"delete_record": delete_record
}
return { nodes, edges, reset, map, update, put_records, delete_record }
});
Loading

0 comments on commit 75a5374

Please sign in to comment.