🚧 WIP: More work on the connection profiles
This commit is contained in:
1 parent
06cd4ead8d
commit
a412ff42cb
9 files changed
+181
-74
No files matched your search
@@ -105,10 +105,32 @@ class ConnectionProfileManager(object):
|
||||
return max(dates)
|
||||
|
||||
def get_default(self):
|
||||
pass
|
||||
default = settings().get(["connectionProfiles", "default"])
|
||||
if default is not None and self.exists(default):
|
||||
profile = self.get(default)
|
||||
if profile is not None:
|
||||
return profile
|
||||
else:
|
||||
self._logger.warning("Default profile {} is invalid".format(default))
|
||||
|
||||
def set_default(self, idenitifier):
|
||||
pass
|
||||
return None
|
||||
|
||||
def set_default(self, identifier):
|
||||
all_identifiers = self._load_all_identifiers()
|
||||
if identifier is not None and identifier not in all_identifiers:
|
||||
return
|
||||
|
||||
settings().set(["connectionProfiles", "default"], identifier)
|
||||
settings().save()
|
||||
|
||||
def get_current_or_default(self):
|
||||
if self._current is not None:
|
||||
return self._current
|
||||
else:
|
||||
return self.get_default()
|
||||
|
||||
def get_current(self):
|
||||
return self._current
|
||||
|
||||
def exists(self, identifier):
|
||||
if identifier is None:
|
||||
|
||||
@@ -134,7 +134,6 @@ class Printer(PrinterInterface,
|
||||
self.sd_card_upload_hooks = plugin_manager().get_hooks("octoprint.printer.sdcardupload")
|
||||
|
||||
# comm
|
||||
self._connection = None
|
||||
self._protocol = None
|
||||
self._transport = None
|
||||
self._job = None
|
||||
@@ -302,7 +301,7 @@ class Printer(PrinterInterface,
|
||||
|
||||
if connection is not None:
|
||||
# we have a connection profile
|
||||
self._connection = connection
|
||||
self._connection_profile_manager.select(connection.id)
|
||||
|
||||
##~~ Printer profile
|
||||
profile_id = connection.printer_profile
|
||||
@@ -333,7 +332,7 @@ class Printer(PrinterInterface,
|
||||
printer_profile=profile))
|
||||
|
||||
else:
|
||||
self._connection = None
|
||||
self._connection_profile_manager.deselect()
|
||||
|
||||
##~~ Printer profile
|
||||
|
||||
@@ -831,8 +830,9 @@ class Printer(PrinterInterface,
|
||||
printer_profile=None)
|
||||
|
||||
printer_profile = self._printer_profile_manager.get_current_or_default()
|
||||
connection_profile = self._connection_profile_manager.get_current_or_default()
|
||||
return dict(state=self.get_state_string(),
|
||||
connection=self._connection.id if self._connection is not None else None,
|
||||
connection=connection_profile.id if connection_profile is not None else None,
|
||||
protocol=self._protocol.key,
|
||||
protocol_args=self._protocol.args(),
|
||||
transport=self._transport.key,
|
||||
@@ -1289,6 +1289,7 @@ class Printer(PrinterInterface,
|
||||
self._set_offsets(None)
|
||||
self._add_temperature_data()
|
||||
self._update_job()
|
||||
self._connection_profile_manager.deselect()
|
||||
self._printer_profile_manager.deselect()
|
||||
eventManager().fire(Events.DISCONNECTED)
|
||||
|
||||
|
||||
@@ -131,6 +131,7 @@ def _get_options():
|
||||
default_profile = printerProfileManager.get_default()
|
||||
|
||||
connection_profiles = connectionProfileManager.get_all()
|
||||
default_connection = connectionProfileManager.get_default()
|
||||
|
||||
options = dict(
|
||||
ports=connection_options["ports"],
|
||||
@@ -140,6 +141,7 @@ def _get_options():
|
||||
portPreference=connection_options["portPreference"],
|
||||
baudratePreference=connection_options["baudratePreference"],
|
||||
printerProfilePreference=default_profile["id"] if "id" in default_profile else None,
|
||||
connectionProfilePreference=default_connection.id,
|
||||
protocols=protocols,
|
||||
transports=transports
|
||||
)
|
||||
|
||||
@@ -30,6 +30,8 @@ def _etag(lm=None):
|
||||
value = value.encode('utf-8')
|
||||
hash.update(value)
|
||||
hash_update(str(lm))
|
||||
hash_update(repr(connectionProfileManager.get_default()))
|
||||
hash_update(repr(connectionProfileManager.get_current()))
|
||||
return hash.hexdigest()
|
||||
|
||||
|
||||
@@ -51,7 +53,7 @@ def connectionProfilesGet(identifier):
|
||||
if profile is None:
|
||||
return make_response("Unknown profile: {}".format(identifier), 404)
|
||||
else:
|
||||
return jsonify(dict(profile=profile.as_dict()))
|
||||
return jsonify(dict(profile=_convert_profile(profile)))
|
||||
|
||||
|
||||
@api.route("/connectionprofiles/<string:identifier>", methods=["PUT"])
|
||||
@@ -93,69 +95,75 @@ def connectionProfileSet(identifier):
|
||||
except Exception as e:
|
||||
return make_response("Could not save profile due to an unexpected error: {}".format(e), 500)
|
||||
else:
|
||||
return jsonify(dict(profile=profile.as_dict()))
|
||||
return jsonify(dict(profile=_convert_profile(profile)))
|
||||
|
||||
|
||||
@api.route("/connectionprofiles/<string:identifier>", methods=["DELETE"])
|
||||
@no_firstrun_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def connectionProfilesDelete(identifier):
|
||||
#current_profile = connectionProfileManager.get_current()
|
||||
#if current_profile and current_profile["id"] == identifier:
|
||||
# return make_response("Cannot delete currently selected profile: {}".format(identifier), 409)
|
||||
current_profile = connectionProfileManager.get_current()
|
||||
if current_profile and current_profile["id"] == identifier:
|
||||
return make_response("Cannot delete currently selected profile: {}".format(identifier), 409)
|
||||
|
||||
#default_profile = connectionProfileManager.get_default()
|
||||
#if default_profile and default_profile["id"] == identifier:
|
||||
# return make_response("Cannot delete default profile: {}".format(identifier), 409)
|
||||
default_profile = connectionProfileManager.get_default()
|
||||
if default_profile and default_profile["id"] == identifier:
|
||||
return make_response("Cannot delete default profile: {}".format(identifier), 409)
|
||||
|
||||
connectionProfileManager.remove(identifier)
|
||||
return NO_CONTENT
|
||||
|
||||
#@api.route("/connectionprofiles/<string:identifier>", methods=["PATCH"])
|
||||
#@no_firstrun_access
|
||||
#@Permissions.SETTINGS.require(403)
|
||||
#def printerProfilesUpdate(identifier):
|
||||
# if not "application/json" in request.headers["Content-Type"]:
|
||||
# return make_response("Expected content-type JSON", 400)
|
||||
#
|
||||
# try:
|
||||
# json_data = request.get_json()
|
||||
# except BadRequest:
|
||||
# return make_response("Malformed JSON body in request", 400)
|
||||
#
|
||||
# if json_data is None:
|
||||
# return make_response("Malformed JSON body in request", 400)
|
||||
#
|
||||
# if not "profile" in json_data:
|
||||
# return make_response("No profile included in request", 400)
|
||||
#
|
||||
# profile = printerProfileManager.get(identifier)
|
||||
# if profile is None:
|
||||
# profile = printerProfileManager.get_default()
|
||||
#
|
||||
# new_profile = json_data["profile"]
|
||||
# merged_profile = dict_merge(profile, new_profile)
|
||||
#
|
||||
# make_default = False
|
||||
# if "default" in merged_profile:
|
||||
# make_default = True
|
||||
# del new_profile["default"]
|
||||
#
|
||||
# merged_profile["id"] = identifier
|
||||
#
|
||||
# try:
|
||||
# saved_profile = printerProfileManager.save(merged_profile, allow_overwrite=True, make_default=make_default)
|
||||
# except InvalidProfileError:
|
||||
# return make_response("Profile is invalid", 400)
|
||||
# except CouldNotOverwriteError:
|
||||
# return make_response("Profile already exists and overwriting was not allowed", 400)
|
||||
# except Exception as e:
|
||||
# return make_response("Could not save profile: %s" % str(e), 500)
|
||||
# else:
|
||||
# return jsonify(dict(profile=_convert_profile(saved_profile)))
|
||||
@api.route("/connectionprofiles/<string:identifier>", methods=["PATCH"])
|
||||
@no_firstrun_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def connectionProfilesUpdate(identifier):
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
return make_response("Expected content-type JSON", 400)
|
||||
|
||||
try:
|
||||
json_data = request.get_json()
|
||||
except BadRequest:
|
||||
return make_response("Malformed JSON body in request", 400)
|
||||
|
||||
if json_data is None:
|
||||
return make_response("Malformed JSON body in request", 400)
|
||||
|
||||
if not "profile" in json_data:
|
||||
return make_response("No profile included in request", 400)
|
||||
|
||||
profile = connectionProfileManager.get(identifier)
|
||||
if profile is None:
|
||||
return make_response("Profile {} doesn't exist", 404)
|
||||
|
||||
profile_data = json_data["profile"]
|
||||
make_default = profile_data.pop("default", False)
|
||||
profile_data.pop("id", None)
|
||||
|
||||
merged_profile_data = dict_merge(profile.as_dict(), profile_data)
|
||||
new_profile = connectionProfileManager.to_profile(merged_profile_data)
|
||||
|
||||
try:
|
||||
saved_profile = connectionProfileManager.save(new_profile, allow_overwrite=True, make_default=make_default)
|
||||
except InvalidProfileError:
|
||||
return make_response("Profile is invalid", 400)
|
||||
except SaveError:
|
||||
return make_response("Profile {} could not be saved".format(profile.id), 400)
|
||||
except Exception as e:
|
||||
return make_response("Could not save profile due to an unexpected error: {}".format(e), 500)
|
||||
else:
|
||||
return jsonify(dict(profile=_convert_profile(saved_profile)))
|
||||
|
||||
def _convert_profiles(profiles):
|
||||
result = dict()
|
||||
for identifier, profile in profiles.items():
|
||||
result[identifier] = profile.as_dict()
|
||||
result[identifier] = _convert_profile(profile)
|
||||
return result
|
||||
|
||||
def _convert_profile(profile):
|
||||
current = connectionProfileManager.get_current()
|
||||
default = connectionProfileManager.get_default()
|
||||
|
||||
result = profile.as_dict()
|
||||
result["current"] = profile.id == current.id if current is not None else False
|
||||
result["default"] = profile.id == default.id if default is not None else False
|
||||
return result
|
||||
@@ -293,6 +293,9 @@ default_settings = {
|
||||
"printerProfiles": {
|
||||
"default": None
|
||||
},
|
||||
"connectionProfiles": {
|
||||
"default": None
|
||||
},
|
||||
"printerParameters": {
|
||||
"pauseTriggers": [],
|
||||
"defaultExtrusionLength": 5
|
||||
@@ -311,7 +314,7 @@ default_settings = {
|
||||
"sidebar": ["plugin_printer_safety_check", "connection", "state", "files"],
|
||||
"tab": ["temperature", "control", "gcodeviewer", "terminal", "timelapse"],
|
||||
"settings": [
|
||||
"section_printer", "serial", "printerprofiles", "temperatures", "terminalfilters", "gcodescripts",
|
||||
"section_printer", "serial", "connectionprofiles", "printerprofiles", "temperatures", "terminalfilters", "gcodescripts",
|
||||
"section_features", "features", "webcam", "accesscontrol", "gcodevisualizer", "api", "plugin_appkeys",
|
||||
"section_octoprint", "server", "folders", "appearance", "plugin_logging", "plugin_pluginmanager",
|
||||
"plugin_softwareupdate", "plugin_announcements", "plugin_backup", "plugin_tracking", "plugin_errortracking",
|
||||
|
||||
@@ -1 +1 @@
|
||||
.btn{display:inline-block;*display:inline;*zoom:1;padding:4px 12px;margin-bottom:0;font-size:14px;line-height:20px;text-align:center;vertical-align:middle;cursor:pointer;color:#333;text-shadow:0 1px 1px rgba(255,255,255,.75);background-color:#f5f5f5;background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(to bottom,#fff,#e6e6e6);background-repeat:repeat-x;*background-color:#e6e6e6;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);border:1px solid #ccc;*border:0;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*margin-left:.3em;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05)}.btn.active,.btn.disabled,.btn:active,.btn:focus,.btn:hover,.btn[disabled]{color:#333;background-color:#e6e6e6;*background-color:#d9d9d9}.btn.active,.btn:active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:focus,.btn:hover{color:#333;text-decoration:none;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:#333 dotted thin;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05)}.btn.disabled,.btn[disabled]{cursor:default;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-large{padding:11px 19px;font-size:17.5px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.btn-large [class*=" icon-"],.btn-large [class^=icon-]{margin-top:4px}.btn-small{padding:2px 10px;font-size:11.9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-small [class*=" icon-"],.btn-small [class^=icon-]{margin-top:0}.btn-mini [class*=" icon-"],.btn-mini [class^=icon-]{margin-top:-1px}.btn-mini{padding:0 6px;font-size:10.5px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-block{display:block;width:100%;padding-left:0;padding-right:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.btn-block+.btn-block{margin-top:5px}input[type=submit].btn-block,input[type=reset].btn-block,input[type=button].btn-block{width:100%}.btn-primary{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#006dcc;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);background-repeat:repeat-x;border-color:#04c #04c #002a80;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#04c;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-primary.active,.btn-primary.disabled,.btn-primary:active,.btn-primary:focus,.btn-primary:hover,.btn-primary[disabled]{color:#fff;background-color:#04c;*background-color:#003bb3}.btn-primary.active,.btn-primary:active{background-color:#039 \9}.btn-warning{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;border-color:#f89406 #f89406 #ad6704;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#f89406;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-warning.active,.btn-warning.disabled,.btn-warning:active,.btn-warning:focus,.btn-warning:hover,.btn-warning[disabled]{color:#fff;background-color:#f89406;*background-color:#df8505}.btn-warning.active,.btn-warning:active{background-color:#c67605 \9}.btn-danger{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#da4f49;background-image:-moz-linear-gradient(top,#ee5f5b,#bd362f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#bd362f));background-image:-webkit-linear-gradient(top,#ee5f5b,#bd362f);background-image:-o-linear-gradient(top,#ee5f5b,#bd362f);background-image:linear-gradient(to bottom,#ee5f5b,#bd362f);background-repeaLine truncated
|
||||
.btn{display:inline-block;*display:inline;*zoom:1;padding:4px 12px;margin-bottom:0;font-size:14px;line-height:20px;text-align:center;vertical-align:middle;cursor:pointer;color:#333;text-shadow:0 1px 1px rgba(255,255,255,.75);background-color:#f5f5f5;background-image:-moz-linear-gradient(top,#fff,#e6e6e6);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));background-image:-webkit-linear-gradient(top,#fff,#e6e6e6);background-image:-o-linear-gradient(top,#fff,#e6e6e6);background-image:linear-gradient(to bottom,#fff,#e6e6e6);background-repeat:repeat-x;*background-color:#e6e6e6;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);border:1px solid #ccc;*border:0;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;*margin-left:.3em;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 1px 0 rgba(255,255,255,.2),0 1px 2px rgba(0,0,0,.05)}.btn.active,.btn.disabled,.btn:active,.btn:focus,.btn:hover,.btn[disabled]{color:#333;background-color:#e6e6e6;*background-color:#d9d9d9}.btn.active,.btn:active{background-color:#ccc \9}.btn:first-child{*margin-left:0}.btn:focus,.btn:hover{color:#333;text-decoration:none;background-position:0 -15px;-webkit-transition:background-position .1s linear;-moz-transition:background-position .1s linear;-o-transition:background-position .1s linear;transition:background-position .1s linear}.btn:focus{outline:#333 dotted thin;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 2px 4px rgba(0,0,0,.15),0 1px 2px rgba(0,0,0,.05)}.btn.disabled,.btn[disabled]{cursor:default;background-image:none;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.btn-large{padding:11px 19px;font-size:17.5px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.btn-large [class*=" icon-"],.btn-large [class^=icon-]{margin-top:4px}.btn-small{padding:2px 10px;font-size:11.9px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-small [class*=" icon-"],.btn-small [class^=icon-]{margin-top:0}.btn-mini [class*=" icon-"],.btn-mini [class^=icon-]{margin-top:-1px}.btn-mini{padding:0 6px;font-size:10.5px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.btn-block{display:block;width:100%;padding-left:0;padding-right:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.btn-block+.btn-block{margin-top:5px}input[type=submit].btn-block,input[type=reset].btn-block,input[type=button].btn-block{width:100%}.btn-primary{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#006dcc;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);background-repeat:repeat-x;border-color:#04c #04c #002a80;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#04c;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-primary.active,.btn-primary.disabled,.btn-primary:active,.btn-primary:focus,.btn-primary:hover,.btn-primary[disabled]{color:#fff;background-color:#04c;*background-color:#003bb3}.btn-primary.active,.btn-primary:active{background-color:#039 \9}.btn-warning{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#faa732;background-image:-moz-linear-gradient(top,#fbb450,#f89406);background-image:-webkit-gradient(linear,0 0,0 100%,from(#fbb450),to(#f89406));background-image:-webkit-linear-gradient(top,#fbb450,#f89406);background-image:-o-linear-gradient(top,#fbb450,#f89406);background-image:linear-gradient(to bottom,#fbb450,#f89406);background-repeat:repeat-x;border-color:#f89406 #f89406 #ad6704;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);*background-color:#f89406;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.btn-warning.active,.btn-warning.disabled,.btn-warning:active,.btn-warning:focus,.btn-warning:hover,.btn-warning[disabled]{color:#fff;background-color:#f89406;*background-color:#df8505}.btn-warning.active,.btn-warning:active{background-color:#c67605 \9}.btn-danger{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#da4f49;background-image:-moz-linear-gradient(top,#ee5f5b,#bd362f);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#bd362f));background-image:-webkit-linear-gradient(top,#ee5f5b,#bd362f);background-image:-o-linear-gradient(top,#ee5f5b,#bd362f);background-image:linear-gradient(to bottom,#ee5f5b,#bd362f);background-repeaLine truncated
|
||||
@@ -50,6 +50,48 @@ $(function() {
|
||||
self.availableConnectionProfiles = ko.observableArray();
|
||||
self.selectedConnectionProfile = ko.observable(undefined);
|
||||
|
||||
/*
|
||||
* TODO: Find some way to have sensible behaviour if
|
||||
*
|
||||
* * a connection profile is selected on server side
|
||||
* * no connection profile is selected but a default exists
|
||||
* * there are modifications to the selected connection profile (protocol/transport parameters)
|
||||
*
|
||||
*/
|
||||
|
||||
self.connectionProfiles.profiles.items.subscribe(function() {
|
||||
var allProfiles = self.connectionProfiles.profiles.items();
|
||||
self.availableConnectionProfiles(allProfiles);
|
||||
});
|
||||
|
||||
self.connectionProfiles.currentProfile.subscribe(function() {
|
||||
var connection = self.connectionProfiles.currentProfile();
|
||||
if (connection === undefined) {
|
||||
connection = self.connectionProfiles.defaultProfile();
|
||||
}
|
||||
|
||||
var connections = self.availableConnectionProfiles();
|
||||
|
||||
if (connection) {
|
||||
self.selectedConnectionProfile(_.find(connections, function(c) { return c.id === connection }));
|
||||
} else {
|
||||
var profile = response.current.profile;
|
||||
|
||||
var protocolKey = response.current.protocol;
|
||||
var protocol = _.find(protocols, function(p) { return p.key === protocolKey });
|
||||
|
||||
var transportKey = response.current.transport;
|
||||
var transport = _.find(transports, function(t) { return t.key === transportKey });
|
||||
|
||||
if (!self.selectedPrinter() && profiles && profiles.indexOf(profile) >= 0)
|
||||
self.selectedPrinter(profile);
|
||||
|
||||
self.selectedProtocol(protocol);
|
||||
self.selectedTransport(transport);
|
||||
self.adjustConnectionParameters(true);
|
||||
}
|
||||
});
|
||||
|
||||
self.selectedConnectionProfile.subscribe(function() {
|
||||
var protocolParameters, transportParameters;
|
||||
|
||||
|
||||
@@ -89,26 +89,22 @@ $(function() {
|
||||
[],
|
||||
10
|
||||
);
|
||||
self.defaultProfile = ko.observable();
|
||||
self.currentProfile = ko.observable();
|
||||
|
||||
self.makeDefault = function(data) {
|
||||
/*
|
||||
var profile = {
|
||||
id: data.id,
|
||||
default: true
|
||||
};
|
||||
|
||||
self.updateProfile(profile);
|
||||
*/
|
||||
return OctoPrint.connectionprofiles.update(data.id, {default: true})
|
||||
.done(function() {
|
||||
self.requestData();
|
||||
});
|
||||
};
|
||||
|
||||
self.canMakeDefault = function(data) {
|
||||
//return !data.isdefault();
|
||||
return true;
|
||||
return !data.is_default();
|
||||
};
|
||||
|
||||
self.canRemove = function(data) {
|
||||
//return !data.iscurrent() && !data.isdefault();
|
||||
return true;
|
||||
return !data.is_current() && !data.is_default();
|
||||
};
|
||||
|
||||
self.requestData = function() {
|
||||
@@ -122,10 +118,43 @@ $(function() {
|
||||
|
||||
self.fromResponse = function(data) {
|
||||
var items = [];
|
||||
var defaultProfile = undefined;
|
||||
var currentProfile = undefined;
|
||||
_.each(data.profiles, function(profile) {
|
||||
if (profile.default) {
|
||||
defaultProfile = profile.id;
|
||||
}
|
||||
if (profile.current) {
|
||||
currentProfile = profile.id;
|
||||
}
|
||||
profile.is_default = ko.observable(profile.default);
|
||||
profile.is_current = ko.observable(profile.current);
|
||||
items.push(profile);
|
||||
});
|
||||
self.profiles.updateItems(items);
|
||||
self.defaultProfile(defaultProfile);
|
||||
|
||||
if (currentProfile) {
|
||||
self.currentProfile(currentProfile);
|
||||
} else {
|
||||
// shouldn't normally happen, but just to not have anything else crash...
|
||||
log.warn("Current printer profile could not be detected, using default values");
|
||||
self.currentProfile(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
self.removeProfile = function(data) {
|
||||
var proceed = function() {
|
||||
OctoPrint.connectionprofiles.delete(data.id)
|
||||
.done(function() {
|
||||
self.requestData();
|
||||
});
|
||||
};
|
||||
|
||||
showConfirmationDialog({
|
||||
message: _.sprintf(gettext("You are about to delete the connection profile \"%(profile)s\"."), {profile: data.name}),
|
||||
onproceed: proceed
|
||||
});
|
||||
};
|
||||
|
||||
self.onSettingsShown = self.requestData;
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
</thead>
|
||||
<tbody data-bind="foreach: connectionProfiles.profiles.paginatedItems">
|
||||
<tr data-bind="attr: {title: name}">
|
||||
<td class="settings_connectionProfiles_profiles_name"><span data-bind="text: name"></span></td>
|
||||
<td class="settings_connectionProfiles_profiles_name"><span class="fa fa-star" data-bind="invisible: !is_default()"></span> <span data-bind="text: name"></span></td>
|
||||
<td class="settings_connectionProfiles_profiles_action">
|
||||
<a href="#" class="fa fa-trash-o" title="{{ _('Delete Profile') }}" data-bind="click: function() { if ($root.connectionProfiles.canRemove($data) && !$root.connectionProfiles.requestInProgress()) { $root.connectionProfiles.removeProfile($data); } }, css: {disabled: !$root.connectionProfiles.canRemove($data) || $root.connectionProfiles.requestInProgress()}, enabled: $root.connectionProfiles.canRemove($data) && !$root.connectionProfiles.requestInProgress()"></a>
|
||||
<a href="javascript:void(0)" class="fa fa-star" title="{{ _('Set as default profile') }}" data-bind="click: function() { if ($root.connectionProfiles.canMakeDefault($data) && !$root.connectionProfiles.requestInProgress()) { $root.connectionProfiles.makeDefault($data); } }, css: {disabled: !$root.connectionProfiles.canMakeDefault($data) || $root.connectionProfiles.requestInProgress()}, enabled: $root.connectionProfiles.canMakeDefault($data) && !$root.connectionProfiles.requestInProgress()"></a> | <a href="javascript:void(0)" class="fa fa-trash-o" title="{{ _('Delete Profile') }}" data-bind="click: function() { if ($root.connectionProfiles.canRemove($data) && !$root.connectionProfiles.requestInProgress()) { $root.connectionProfiles.removeProfile($data); } }, css: {disabled: !$root.connectionProfiles.canRemove($data) || $root.connectionProfiles.requestInProgress()}, enabled: $root.connectionProfiles.canRemove($data) && !$root.connectionProfiles.requestInProgress()"></a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Reference in new issue
Block a user