From 5039442d7f9b32d6f4626b9f8f851038983d517c Mon Sep 17 00:00:00 2001 From: "Alex M. Sielicki" Date: Thu, 18 Aug 2016 23:15:17 +0000 Subject: [PATCH 1/6] Adding ability to edit bookmark names. Renaming Create New to Save As. Addresses #645 --- packages/slycat/web/server/engine.py | 1 + packages/slycat/web/server/handlers.py | 17 +++++++++ web-server/css/slycat.css | 8 +++- web-server/js/slycat-dialog.js | 2 +- web-server/js/slycat-navbar.js | 26 +++++++++++++ web-server/js/slycat-web-client.js | 37 ++++++++++++++++++- .../slycat-model-wizards.py | 2 +- web-server/templates/slycat-navbar.html | 10 ++--- 8 files changed, 93 insertions(+), 10 deletions(-) diff --git a/packages/slycat/web/server/engine.py b/packages/slycat/web/server/engine.py index d5bd3ee4a..276c64de1 100644 --- a/packages/slycat/web/server/engine.py +++ b/packages/slycat/web/server/engine.py @@ -130,6 +130,7 @@ def abspath(path): dispatcher.connect("put-model-inputs", "/models/:mid/inputs", slycat.web.server.handlers.put_model_inputs, conditions={"method" : ["PUT"]}) dispatcher.connect("put-model", "/models/:mid", slycat.web.server.handlers.put_model, conditions={"method" : ["PUT"]}) dispatcher.connect("put-model-parameter", "/models/:mid/parameters/:aid", slycat.web.server.handlers.put_model_parameter, conditions={"method" : ["PUT"]}) + dispatcher.connect("put-reference", "/references/:rid", slycat.web.server.handlers.put_reference, conditions={"method" : ["PUT"]}) dispatcher.connect("put-project", "/projects/:pid", slycat.web.server.handlers.put_project, conditions={"method" : ["PUT"]}) dispatcher.connect("post-checksid", "/remotes/checksid", slycat.web.server.handlers.post_checksid, conditions={ "method": ["POST"] }) dispatcher.connect("post-remote-launch", "/remotes/launch", slycat.web.server.handlers.post_remote_launch, conditions={ "method": ["POST"] }) diff --git a/packages/slycat/web/server/handlers.py b/packages/slycat/web/server/handlers.py index 01d208b2a..079388276 100644 --- a/packages/slycat/web/server/handlers.py +++ b/packages/slycat/web/server/handlers.py @@ -403,6 +403,23 @@ def post_project_references(pid): cherrypy.response.status = "201 Reference created." return {"id" : rid} +@cherrypy.tools.json_in(on = True) +@cherrypy.tools.json_out(on = True) +def put_reference(rid): + couchdb = slycat.web.server.database.couchdb.connect() + reference = couchdb.get("reference", rid) + project = couchdb.get("project", reference["project"]) + slycat.web.server.authentication.require_project_writer(project) + + if cherrypy.request.json.get("name", None): + reference["name"] = cherrypy.request.json.get("name", None) + if cherrypy.request.json.get("bid", None): + reference["bid"] = cherrypy.request.json.get("bid", None) + + couchdb.save(reference) + + cherrypy.response.status = "201 Reference updated." + def get_page(ptype): database = slycat.web.server.database.couchdb.connect() diff --git a/web-server/css/slycat.css b/web-server/css/slycat.css index 7fc57529c..bd8d89e73 100644 --- a/web-server/css/slycat.css +++ b/web-server/css/slycat.css @@ -85,16 +85,20 @@ body font-weight: bold !important; } .nav-bookmarks .bookmark-new .fa { - + margin-right: 3px; } .nav-bookmarks .bookmark-link { position: relative; - padding-right: 65px !important; + padding-right: 95px !important; } .nav-bookmarks .bookmark-delete { position: absolute; right: 20px; } +.nav-bookmarks .bookmark-edit { + position: absolute; + right: 43px; +} .bootstrap-styles .modal .jumbotron { diff --git a/web-server/js/slycat-dialog.js b/web-server/js/slycat-dialog.js index 2e5503589..7cae102b7 100644 --- a/web-server/js/slycat-dialog.js +++ b/web-server/js/slycat-dialog.js @@ -16,7 +16,7 @@ define("slycat-dialog", ["slycat-server-root", "slycat-web-client", "knockout", component.message = ko.observable(params.message || ""); component.input = ko.observable(params.input || false); component.placeholder = ko.observable(params.placeholder || ""); - component.value = ko.observable(params.value || ""); + component.value = ko.isObservable(params.value) ? params.value : ko.observable(params.value || ""); component.alert = ko.observable(params.alert || ""); component.buttons = params.buttons || [{className: "btn-default", label:"OK"}]; component.container = $($.parseHTML(template)).appendTo($("body")); diff --git a/web-server/js/slycat-navbar.js b/web-server/js/slycat-navbar.js index 1fc6eb96b..086211819 100644 --- a/web-server/js/slycat-navbar.js +++ b/web-server/js/slycat-navbar.js @@ -386,6 +386,32 @@ define("slycat-navbar", ["slycat-server-root", "slycat-web-client", "slycat-chan }; }); + component.edit_saved_bookmark = function(reference) + { + var name = ko.observable(reference.name()) + dialog.prompt( + { + title: "Edit Bookmark", + value: name, + buttons: [{className: "btn-default", label:"Cancel"}, {className: "btn-danger",label:"OK"}], + callback: function(button) + { + if(button.label != "OK") + return; + client.put_reference( + { + rid: reference._id(), + name: name(), + success: function() + { + component.update_references(); + }, + error: dialog.ajax_error("Couldn't edit bookmark."), + }); + }, + }); + } + component.delete_saved_bookmark = function(reference) { dialog.dialog( diff --git a/web-server/js/slycat-web-client.js b/web-server/js/slycat-web-client.js index 7ae666fbf..72d80eb21 100644 --- a/web-server/js/slycat-web-client.js +++ b/web-server/js/slycat-web-client.js @@ -65,7 +65,7 @@ define("slycat-web-client", ["slycat-server-root", "jquery", "URI"], function(se /** * delete a reference in Slycat * @param params: object{ - * pid: project id of project that is to be deleted from Slycat + * rid: reference id of reference that is to be deleted from Slycat * success(): function called upon success * error(request, status, reason_phrase): function called upon error * } @@ -732,6 +732,41 @@ define("slycat-web-client", ["slycat-server-root", "jquery", "URI"], function(se }); }; + /** + * put a reference in Slycat + * @param params: object{ + * rid: reference id of reference that is to be updated + * success(): function called upon success + * error(request, status, reason_phrase): function called upon error + * } + */ + module.put_reference = function(params) + { + var data = {}; + if("name" in params) + data["name"] = params["name"]; + if("bid" in params) + data["bid"] = params["bid"]; + + $.ajax( + { + contentType: "application/json", + data: JSON.stringify(data), + type: "PUT", + url: server_root + "references/" + params.rid, + success: function() + { + if(params.success) + params.success(); + }, + error: function(request, status, reason_phrase) + { + if(params.error) + params.error(request, status, reason_phrase); + } + }); + }; + module.post_remotes = function(params) { $.ajax( diff --git a/web-server/plugins/slycat-model-wizards/slycat-model-wizards.py b/web-server/plugins/slycat-model-wizards/slycat-model-wizards.py index 074e471f2..2b86406a4 100644 --- a/web-server/plugins/slycat-model-wizards/slycat-model-wizards.py +++ b/web-server/plugins/slycat-model-wizards/slycat-model-wizards.py @@ -12,7 +12,7 @@ def register_slycat_plugin(context): context.register_wizard_resource("slycat-create-template", "ui.js", os.path.join(os.path.dirname(__file__), "create-template-ui.js")) context.register_wizard_resource("slycat-create-template", "ui.html", os.path.join(os.path.dirname(__file__), "create-template-ui.html")) - context.register_wizard("slycat-create-saved-bookmark", "Create New", require={"action":"create", "context":"model"}) + context.register_wizard("slycat-create-saved-bookmark", "Save As", require={"action":"create", "context":"model"}) context.register_wizard_resource("slycat-create-saved-bookmark", "ui.js", os.path.join(os.path.dirname(__file__), "create-saved-bookmark-ui.js")) context.register_wizard_resource("slycat-create-saved-bookmark", "ui.html", os.path.join(os.path.dirname(__file__), "create-saved-bookmark-ui.html")) diff --git a/web-server/templates/slycat-navbar.html b/web-server/templates/slycat-navbar.html index c482d7597..f7cdcdfa2 100644 --- a/web-server/templates/slycat-navbar.html +++ b/web-server/templates/slycat-navbar.html @@ -123,10 +123,7 @@
  • - - +
  • @@ -135,7 +132,10 @@
  • - +