Permalink
Browse files

Merge pull request #14 from bogdanstate/master

Added delete profile functionality.
  • Loading branch information...
chron0 committed Mar 12, 2016
2 parents af3a27b + 6b0492b commit c790a842a0ebd8d740ea184d327050ab8e002bcf
Showing with 47 additions and 5 deletions.
  1. +14 −0 picoreflowd.py
  2. +33 −5 public/assets/js/picoreflow.js
@@ -110,6 +110,13 @@ def handle_storage():
if message == "GET":
log.info("GET command recived")
wsock.send(get_profiles())
elif msgdict.get("cmd") == "DELETE":
log.info("DELETE command received")
profile_obj = msgdict.get('profile')
if delete_profile(profile_obj):
msgdict["resp"] = "OK"
wsock.send(json.dumps(msgdict))
#wsock.send(get_profiles())
elif msgdict.get("cmd") == "PUT":
log.info("PUT command received")
profile_obj = msgdict.get('profile')
@@ -168,6 +175,13 @@ def save_profile(profile, force=False):
log.info("Wrote %s" % filepath)
return True

def delete_profile(profile):
profile_json = json.dumps(profile)
filename = profile['name']+".json"
filepath = os.path.join(profile_path, filename)
os.remove(filepath)
log.info("Deleted %s" % filepath)
return True

def main():
ip = config.listening_ip
@@ -3,9 +3,9 @@ var state_last = "";
var graph = [ 'profile', 'live'];
var points = [];
var profiles = [];
var selected_profile = 0;
var time_mode = 0;
var selected_profile_name = "leadfree";
var selected_profile = 0;
var selected_profile_name = 'leadfree';

var host = "ws://" + window.location.hostname + ":" + window.location.port;
var ws_status = new WebSocket(host+"/status");
@@ -50,9 +50,26 @@ function updateProfile(id)

function deleteProfile()
{
var profile = { "type": "profile", "data": "", "name": selected_profile_name };
var delete_struct = { "cmd": "DELETE", "profile": profile };

var delete_cmd = JSON.stringify(delete_struct);
console.log("Delete profile:" + selected_profile_name);
// FIXME: Add cmd for socket communication to delete stored profile
leaveEditMode();

ws_storage.send(delete_cmd);

selected_profile_name = profiles[0].name;
ws_storage.send('GET');
state="IDLE";
$('#edit').hide();
$('#profile_selector').show();
$('#btn_controls').show();
$('#status').slideDown();
$('#profile_table').slideUp();
$('#e2').select2('val', 0);
graph.profile.points.show = false;
graph.profile.draggable = false;
graph.plot = $.plot("#graph_container", [ graph.profile, graph.live ], getOptions());
}


@@ -193,6 +210,7 @@ function enterEditMode()
$('#edit').show();
$('#profile_selector').hide();
$('#btn_controls').hide();
console.log(profiles);
$('#form_profile_name').attr('value', profiles[selected_profile].name);
graph.profile.points.show = true;
graph.profile.draggable = true;
@@ -558,6 +576,16 @@ $(document).ready(function()
profiles = message;
//delete old options in select
$('#e2').find('option').remove().end();
// check if current selected value is a valid profile name
// if not, update with first available profile name
var valid_profile_names = profiles.map(function(a) {return a.name;});
if (
valid_profile_names.length > 0 &&
$.inArray(selected_profile_name, valid_profile_names) === -1
) {
selected_profile = 0;
selected_profile_name = valid_profile_names[0];
}

// fill select with new options from websocket
for (var i=0; i<profiles.length; i++)
@@ -579,7 +607,7 @@ $(document).ready(function()
$("#e2").select2(
{
placeholder: "Select Profile",
allowClear: false,
allowClear: true,
minimumResultsForSearch: -1
});

0 comments on commit c790a84

Please sign in to comment.