Author: eallen
Date: 2010-04-30 12:47:11 -0400 (Fri, 30 Apr 2010)
New Revision: 3944
Modified:
mgmt/newdata/cumin/python/cumin/messaging/binding.py
mgmt/newdata/cumin/python/cumin/messaging/binding.strings
mgmt/newdata/cumin/python/cumin/messaging/exchange.py
mgmt/newdata/cumin/python/cumin/messaging/queue.py
mgmt/newdata/cumin/python/cumin/messaging/queue.strings
mgmt/newdata/cumin/python/cumin/widgets.py
mgmt/newdata/cumin/python/cumin/widgets.strings
Log:
Simplified the add binding form.
Added 'Add Binding' task to queue and exchange
Moved common classes to Widgets
Modified: mgmt/newdata/cumin/python/cumin/messaging/binding.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/binding.py 2010-04-29 19:08:54 UTC (rev
3943)
+++ mgmt/newdata/cumin/python/cumin/messaging/binding.py 2010-04-30 16:47:11 UTC (rev
3944)
@@ -360,183 +360,197 @@
return self.get(session) == "c"
class ExchangeKeysField(FormField):
- def __init__(self, app, name, vhost, title="Initial bindings:"):
+ def __init__(self, app, name, exchange):
super(ExchangeKeysField, self).__init__(app, name)
- assert vhost
+ self.title = "Initial bindings"
+ self.exchange = exchange
- self.vhost = vhost
+ name = StringParameter(app, "name")
+ self.names = ListParameter(app, "names", name)
+ self.add_parameter(self.names)
- self.dict_param = DictParameter(app, "exchange")
- self.add_parameter(self.dict_param)
+ value = StringParameter(app, "value")
+ self.values = ListParameter(app, "values", value)
+ self.add_parameter(self.values)
- self.direct_input = DirectExchangeInput(app, "direct")
- self.add_child(self.direct_input)
+ self.count = IntegerParameter(app, "count")
+ self.count.default = 3
+ self.add_parameter(self.count)
- self.topic_input = TopicExchangeInput(app, "topic")
- self.add_child(self.topic_input)
+ self.inputs_container_tmpl = WidgetTemplate(self,
"input_container_html")
+ self.inputs_tmpl = WidgetTemplate(self, "inputs_html")
- self.fanout_input = FanoutExchangeInput(app, "fanout")
- self.add_child(self.fanout_input)
+ def init(self):
+ """ we added parameters directly to the FormField instead
+ of adding FormInputs. XXX should this logic be moved up to FormField?
"""
+ super(ExchangeKeysField, self).init()
+ for param in self.parameters:
+ self.form.form_params.add(param)
- self.xml_input = XMLExchangeInput(app, "xml")
- self.add_child(self.xml_input)
+ def render_title(self, session):
+ return self.title
- self.headers_input = HeadersExchangeInput(app, "headers")
- self.add_child(self.headers_input)
+ def render_input_fields(self, session, *args):
+ count = self.count.get(session)
+ writer = Writer()
+ for i in range(count):
+ self.inputs_tmpl.render(writer, session, i)
+ return writer.to_string()
- self.title = title
+ def render_inputs(self, session, *args):
+ writer = Writer()
+ self.inputs_container_tmpl.render(writer, session, *args)
+ return writer.to_string()
- self.binding_errors = self.Errors(self, "binding_errors")
- self.add_attribute(self.binding_errors)
+ def render_n_name(self, session, i):
+ return self.names.path
- self.state = ExchangeState(app, "phase")
- self.add_child(self.state)
+ def render_v_name(self, session, i):
+ return self.values.path
- class Errors(Attribute):
- def get_default(self, session):
- return dict()
+ def render_n_value(self, session, i):
+ names = self.names.get(session)
+ return len(names) > i and names[i] or ""
- def render_title(self, session):
- return self.title
+ def render_v_value(self, session, i):
+ values = self.values.get(session)
+ return len(values) > i and values[i] or ""
- def render_exchanges(self, session):
- vhost = self.vhost.get(session)
- cls = self.app.rosemary.org_apache_qpid_broker.Exchange
+ def get_exchange(self, session):
+ exchange_string = self.exchange.get(session)
+ if exchange_string:
+ obj = self.form.object.get(session)
+ cls = self.app.rosemary.org_apache_qpid_broker.Exchange
+ vhostid = obj._class._name == "Vhost" and obj._id or
obj._vhostRef_id
+ exchanges = cls.get_selection(session.cursor, name=exchange_string,
_vhostRef_id=vhostid)
+ if len(exchanges):
+ return exchanges[0]
+ return None
- exchanges = cls.get_selection(session.cursor, _vhostRef_id=vhost._id)
+ def get(self, session):
+ ret_dict = dict()
+ exchange = self.get_exchange(session)
+ if exchange:
+ if exchange.type == "headers" or exchange.type == "xml":
+ names = self.names.get(session)
+ values = self.values.get(session)
- # render each exchange we support
- writer = Writer()
+ for name, value in zip(names, values):
+ if name:
+ ret_dict[name] = value
+ return ret_dict
- for exchange in exchanges:
- if not ExchangeInfo.is_builtin(exchange):
- continue
+ def validate(self, session):
+ exchange = self.get_exchange(session)
+ names = self.names.get(session)
+ values = self.values.get(session)
- if exchange._qmf_delete_time:
- continue
+ if exchange:
+ if exchange.type == "headers":
+ if not "x-match" in names:
+ error = FormError("x-match argument is required for this
exchange")
+ self.form.errors.add(session, error)
- # if self.state.is_active(session) and not is_active(exchange):
- # continue
+ for i in range(len(names)):
+ if names[i]:
+ if names[i] == "x-match":
+ if not values[i] == "all" and not values[i] ==
"any":
+ error = FormError("Argument name x-match must have a
value of <i>all</i> or <i>any</i>")
+ self.form.errors.add(session, error)
+ else:
+ if not values[i]:
+ error = FormError("Missing argument value for name:
%s" % names[i])
+ self.form.errors.add(session, error)
- if exchange.name == "qpid.management":
- continue
+ for i in range(len(values)):
+ if values[i]:
+ if not names[i]:
+ error = FormError("Missing argument name for value:
%s" % values[i])
+ self.form.errors.add(session, error)
- # XXX
- # if ExchangeInfo.is_builtin(exchange) or \
- # (not exchange._qmf_delete_time and \
- # not (self.state.is_active(session) and not is_active(exchange))):
+ elif exchange.type == "xml":
+ if not "xquery" in names:
+ error = FormError("xquery argument is required for this
exchange")
+ self.form.errors.add(session, error)
- # instance_key gives us a unique path for each exchange
- # we will be rendering
+class BindingAddForm(ObjectTaskForm):
+ def __init__(self, app, name, task):
+ super(BindingAddForm, self).__init__(app, name, task)
- instance_key = self.dict_param.get_instance_key(str(exchange._id))
+ self.queue = Parameter(app, "queue")
+ self.add_parameter(self.queue)
+ self.q_field = QueueBindingField(app, "q_field", self.queue)
+ self.add_field(self.q_field)
- if exchange.type == "direct" and exchange.name:
- self.direct_input.set_instance_data(exchange, instance_key)
- writer.write(self.direct_input.render(session, exchange))
- elif exchange.type == "topic":
- self.topic_input.set_instance_data(exchange, instance_key)
- writer.write(self.topic_input.render(session, exchange))
- elif exchange.type == "fanout":
- self.fanout_input.set_instance_data(exchange, instance_key)
- writer.write(self.fanout_input.render(session, exchange))
- elif exchange.type == "xml":
- self.xml_input.set_instance_data(exchange, instance_key)
- writer.write(self.xml_input.render(session, exchange))
- elif exchange.type == "headers":
- self.headers_input.set_instance_data(exchange, instance_key)
- writer.write(self.headers_input.render(session, exchange))
+ self.exchange = Parameter(app, "exchange")
+ self.add_parameter(self.exchange)
+ self.x_field = ExchangeBindingField(app, "x_field", self.exchange)
+ self.add_field(self.x_field)
- return writer.to_string()
+ self.key = self.KeyField(app, "key")
+ self.add_field(self.key)
- def get_binding_errors(self, session, queue_name):
- form_binding_info = self.process_binding_info(session, queue_name)
- binding_info = self.dict_param.get(session)
- berrs = self.binding_errors.get(session)
+ self.bindings = self.ExchangeBindings(app, "bindings", self.exchange)
+ self.add_field(self.bindings)
- for exchange in form_binding_info:
- type = form_binding_info[exchange]["type"]
- if (type == "topic") or (type == "direct"):
- try:
- val = form_binding_info[exchange]["key"]
- if not val:
- raise KeyError
- except KeyError:
- name = form_binding_info[exchange]["name"]
- errs = berrs.setdefault(name, list())
- errs.append("A binding key is required")
- elif type == "headers":
- try:
- val = form_binding_info[exchange]["key"]
- if not val:
- raise KeyError
- except KeyError:
- name = form_binding_info[exchange]["name"]
- errs = berrs.setdefault(name, dict())
- errs["key"] = ["A binding key is required"]
- for key_num in ("1", "2", "3"):
- mkey = "mkey."+key_num
- mkeynv = mkey+".nv"
- if mkeynv in binding_info[exchange] and
binding_info[exchange][mkeynv]:
- try:
- val = binding_info[exchange][mkey]
- if not val:
- raise KeyError
- except KeyError:
- name = binding_info[exchange]["name"]
- if not name in berrs:
- berrs.setdefault(name, dict())
- berrs[name][mkey] = ["Missing key"]
- elif type == "xml":
- try:
- val = form_binding_info[exchange]["key"]
- if not val:
- raise KeyError
- except KeyError:
- name = form_binding_info[exchange]["name"]
- errs = berrs.setdefault(name, dict())
- errs["key"] = ["A binding key is required"]
- try:
- val = binding_info[exchange]["xquery"]
- if not val:
- raise KeyError
- except KeyError:
- name = binding_info[exchange]["name"]
- if not name in berrs:
- berrs.setdefault(name, dict())
- berrs[name]["xquery"] = ["Missing xquery"]
+ def init(self):
+ super(BindingAddForm, self).init()
+ self.form_params.add(self.queue)
+ self.form_params.add(self.exchange)
- return (len(berrs), form_binding_info)
+ def render_title(self, session):
+ return self.task.get_description(session)
- def process_binding_info(self, session, queue_name):
- """ Processes the raw binding_info from the DictParameter into
- a "form_binding_info" dictionary that contains four keys:
- name, key, arguments, and type
- """
- binding_info = self.dict_param.get(session)
- form_binding_info = dict()
- for this_exchange in binding_info:
- # if the exchange checkbox is checked
- if "name" in binding_info[this_exchange]:
- type = binding_info[this_exchange]["type"]
- #if type == "direct":
- # binding_info[this_exchange]["key"] = queue_name
+ def render_key_id(self, session):
+ return self.key.path
- form_binding_info[this_exchange] = dict()
- form_binding_info[this_exchange]["name"] =
binding_info[this_exchange]["name"]
- if "key" in binding_info[this_exchange] and
binding_info[this_exchange]["key"]:
- form_binding_info[this_exchange]["key"] =
binding_info[this_exchange]["key"]
- form_binding_info[this_exchange]["type"] = type
+ def validate(self, session):
+ super(BindingAddForm, self).validate(session)
- arguments = dict()
- if type == "headers":
- self.headers_input.process_input(binding_info[this_exchange],
arguments)
- elif type == "xml":
- self.xml_input.process_input(binding_info[this_exchange], arguments)
- #direct, topic and fanout exchanges don't have aditional arguments
- form_binding_info[this_exchange]["arguments"] = arguments
+ queue = self.queue.get(session)
+ exchange = self.bindings.get_exchange(session)
+ key = self.key.get(session)
- return form_binding_info
+ if not queue:
+ error = FormError("A valid queue name is required")
+ self.errors.add(session, error)
+ if not exchange:
+ error = FormError("A valid exchange name is required")
+ self.errors.add(session, error)
+ else:
+ if not exchange.type == "fanout":
+ if not key:
+ error = MissingValueError(self.key)
+ self.errors.add(session, error)
-from exchange import ExchangeInfo
+ def process_submit(self, session):
+ self.validate(session)
+ if not self.errors.get(session):
+ queue = self.queue.get(session)
+ exchange = self.exchange.get(session)
+ key = self.key.get(session)
+ arguments = self.bindings.get(session)
+ obj = self.object.get(session)
+
+ self.task.invoke(session, obj, queue, exchange, key, arguments)
+ self.task.exit_with_redirect(session)
+
+ class KeyField(StringField):
+ def render_row_id(self, session):
+ return "id='%s'" % self.path
+
+ def render_title(self, session):
+ return "Binding Key"
+
+ class ExchangeBindings(ExchangeKeysField):
+ def render_id(self, session, *args):
+ s = fmt_bytes(1)
+ cls = "ExchangeHiddenRow"
+ exchange = self.exchange.get(session)
+ if exchange and exchange.type == 'headers':
+ cls = ""
+ return cls and "%s\" class=\"%s" % (self.path, cls) or
self.path
+
+ def render_title(self, session):
+ return "Arguments"
Modified: mgmt/newdata/cumin/python/cumin/messaging/binding.strings
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/binding.strings 2010-04-29 19:08:54 UTC (rev
3943)
+++ mgmt/newdata/cumin/python/cumin/messaging/binding.strings 2010-04-30 16:47:11 UTC (rev
3944)
@@ -16,172 +16,25 @@
left outer join binding_stats as c on c.id = b.stats_curr_id
{sql_where}
-[ExchangeInput.name_html]
-<td>
- <input type="checkbox" id="{id}.{exchange_id}"
name="{name_path}"
- value="{exchange_name}" size="15" tabindex="100"
{exchange_checked}
- {onclick} />
- <input type="hidden" name="{exchange_type_path}"
value="{exchange_type}" />
-</td>
-<td><label class="exchange_name"
for="{id}.{exchange_id}">{exchange_fmt_name}</label></td>
-<td class="exchange_type">{exchange_type}</td>
-
-[ExchangeInput.key_html]
-<td>
- <input type="text" name="{key_path}"
id="{exchange_name}"
- value="{key_value}" size="32" maxlength="256"
tabindex="100" />
- {key_error}
-</td>
-
-[DirectExchangeInput.html]
-<tr>
- {exchange_name_input}
- {exchange_key_input}
-</tr>
-
-[TopicExchangeInput.html]
-<tr>
- {exchange_name_input}
- {exchange_key_input}
-</tr>
-
-[FanoutExchangeInput.html]
-<tr>
- {exchange_name_input}
- <td> </td>
-</tr>
-
-[XMLExchangeInput.html]
-<tr>
- {exchange_name_input}
- {exchange_key_input}
-</tr>
-<tr id="{xml_extra}" class="{headers_class}">
- <td colspan="4"><table>
- <tr>
- <td>XQuery:</td>
- <td colspan="3"><textarea name="{xquery_path}"
id="{exchange_name}" tabindex="100" rows="4"
cols="40">{xquery_value}</textarea>{xquery_error}</td>
- </tr>
- </table></td>
-</tr>
-
-[HeadersExchangeInput.html]
-<tr>
- {exchange_name_input}
- {exchange_key_input}
-</tr>
-<tr id="{headers_extra}" class="{headers_class}">
- <td colspan="4"><table>
- <tr>
- <td> </td>
- <td>x-match Type:</td>
- <td colspan="2">
- <input type="radio" id="headers.x-match.all"
name="{x_match_path}" value="all" {all_checked}/>
- <label for="headers.x-match.all">All</label>
- <input type="radio" id="headers.x-match.any"
name="{x_match_path}" value="any" {any_checked}/>
- <label for="headers.x-match.any">Any</label>
- </td>
- </tr>
- <tr>
- <td> </td>
- <td>Match Keys:</td>
- <td colspan="2">
- <table class="xmlExchange">
- <thead>
- <tr>
- <th>Key</th><th>type, value</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><input type="text" name="{mkey_path}.1"
value="{mkey1_value}" tabindex="100" />{mkey1_error}</td>
- <td><input type="text" name="{mkey_path}.1.nv"
value="{mnv1_value}" tabindex="100" /></td>
- </tr>
- <tr>
- <td><input type="text" name="{mkey_path}.2"
value="{mkey2_value}" tabindex="100" />{mkey2_error}</td>
- <td><input type="text" name="{mkey_path}.2.nv"
value="{mnv2_value}" tabindex="100" /></td>
- </tr>
- <tr>
- <td><input type="text" name="{mkey_path}.3"
value="{mkey3_value}" tabindex="100" />{mkey3_error}</td>
- <td><input type="text" name="{mkey_path}.3.nv"
value="{mnv3_value}" tabindex="100" /></td>
- </tr>
- </tbody>
- </table>
- </td>
- </tr>
-</table></td></tr>
-
[ExchangeKeysField.css]
-table.FormFieldSet div.inputs {
- position: relative;
- left: -4em;
-}
-
-td.exchange_type {
- font-style: italic;
-}
-
-table.mobjects tr#headers_extra {
- border-top: 0px;
-}
-
-table.mobjects tr.initial_header_state {
- display:none;
-}
-
-table.xmlExchange {
- border-collapse: collapse;
- border: 1px dotted #ccc;
- margin: 0;
-}
-
-table.xmlExchange tr {
- border-top: 0px solid #fff;
-}
-
-table.mobjects label.exchange_name {
+table th.NameHeader {
+ color: red;
+ font-size: 0.8em;
font-weight: bold;
+ text-align: left;
}
-table.mobjects td.exchange_type, table.mobjects th.exchange_type {
- font-style: italic;
-}
+[ExchangeKeysField.input_container_html]
+<table>
+ <tr>
+ <th class="NameHeader">Name</th>
+ <th class="NameHeader">Value</th>
+ </tr>
+ {input_fields}
+</table>
-[ExchangeKeysField.javascript]
-function toggle_row(chk, row_id) {
- var display = "none";
- var headers_extra = document.getElementById(row_id);
-
- if (chk.checked) {
- display = "table-row";
- }
-
- headers_extra.style.display = display;
-}
-
-[ExchangeKeysField.html]
+[ExchangeKeysField.inputs_html]
<tr>
- <th>
- <div class="title">{title}</div>
- <div class="help">{help}</div>
- </th>
- <td>
- <div class="rfloat">{phase}</div>
- <div class="rclear"> </div>
-
- <div class="inputs">
- <table class="mobjects" id="exchange_types">
- <thead>
- <tr>
- <th colspan="2"><label
class="exchange_name">Exchange Name</label></th>
- <th class="exchange_type">Exchange Type</th>
- <th>Binding Key</th>
- </tr>
- </thead>
- <tbody>
- {exchanges}
- </tbody>
- </table>
- </div>
- </td>
+ <td><input class="NameInput" type="text"
size="15" name="{n_name}" value="{n_value}"
tabindex="100"/> = </td>
+ <td><input class="ValueInput" type="text"
size="15" name="{v_name}" value="{v_value}"
tabindex="100"/></td>
</tr>
Modified: mgmt/newdata/cumin/python/cumin/messaging/exchange.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/exchange.py 2010-04-29 19:08:54 UTC (rev
3943)
+++ mgmt/newdata/cumin/python/cumin/messaging/exchange.py 2010-04-30 16:47:11 UTC (rev
3944)
@@ -33,6 +33,7 @@
self.view.add_tab(self.bindings)
self.remove = ExchangeRemove(app, self)
+ self.add_binding = ExchangeBindingAdd(app, self)
def get_title(self, session):
title = super(ExchangeFrame, self).get_title(session)
@@ -56,6 +57,18 @@
invoc.end()
+class ExchangeBindingAdd(BindingAddTask):
+ def __init__(self, app, frame):
+ super(ExchangeBindingAdd, self).__init__(app, frame)
+
+ self.form = ExchangeBindingAddForm(app, self.name, self)
+
+class ExchangeBindingAddForm(BindingAddForm):
+ def __init__(self, app, name, task):
+ super(ExchangeBindingAddForm, self).__init__(app, name, task)
+
+ self.x_field.input.disabled = True
+
class ExchangeSelector(ObjectSelector):
def __init__(self, app, name, vhost):
cls = app.rosemary.org_apache_qpid_broker.Exchange
Modified: mgmt/newdata/cumin/python/cumin/messaging/queue.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/queue.py 2010-04-29 19:08:54 UTC (rev 3943)
+++ mgmt/newdata/cumin/python/cumin/messaging/queue.py 2010-04-30 16:47:11 UTC (rev 3944)
@@ -15,7 +15,7 @@
from cumin.widgets import *
from binding import *
-from exchange import *
+
from subscription import *
strings = StringCatalog(__file__)
@@ -45,6 +45,7 @@
self.remove = QueueRemove(app, self)
self.purge = QueuePurge(app, self)
self.move_messages = MoveQueueMessages(app, self)
+ self.add_binding = QueueBindingAdd(app, self)
class QueueRemove(ObjectTask):
def get_title(self, session):
@@ -119,6 +120,15 @@
def get_title(self, session):
return "Add queue"
+ def do_invoke(self, invoc, queue, name, durable, args):
+ session = self.app.model.get_session_by_object(queue)
+ session.queue_declare(queue=name,
+ durable=durable,
+ arguments=args)
+ session.sync()
+
+ invoc.end()
+
class QueueAddForm(ObjectTaskForm):
def __init__(self, app, name, task):
super(QueueAddForm, self).__init__(app, name, task)
@@ -126,12 +136,6 @@
self.namef = NameField(app, "name")
self.add_field(self.namef)
- self.more = self.AdvancedOptions(app, "more")
- self.add_field(self.more)
-
- self.bindings = ExchangeKeysField(app, "bindings", self.object)
- self.add_field(self.bindings)
-
self.durable = self.QueueDurabilityField(app, "durable")
self.add_extra_field(self.durable)
@@ -320,63 +324,30 @@
self.validate(session)
errors = self.errors.get(session)
-
- binding_errors, binding_info = self.bindings.get_binding_errors \
- (session, name)
-
if not errors:
- errors = binding_errors
+ args = dict()
- if not errors:
- invoc = self.task.start(session, vhost)
+ if durable:
+ args["qpid.file_count"] = self.file_count.get(session)
+ args["qpid.file_size"] = self.file_size.get(session)
- try:
- args = dict()
+ if policy != "none":
+ args["qpid.policy_type"] = policy
+ args["qpid.max_size"] = self.q_size.get(session)
+ args["qpid.max_count"] = self.q_count.get(session)
- if durable:
- args["qpid.file_count"] = self.file_count.get(session)
- args["qpid.file_size"] = self.file_size.get(session)
+ args["qpid.persist_last_node"] = \
+ self.cluster_durable.get(session) == "yes"
- if policy != "none":
- args["qpid.policy_type"] = policy
- args["qpid.max_size"] = self.q_size.get(session)
- args["qpid.max_count"] = self.q_count.get(session)
+ args["qpid.last_value_queue"] = \
+ self.lvq.get(session) == "enable"
- args["qpid.persist_last_node"] = \
- self.cluster_durable.get(session) == "yes"
+ args["qpid.optimistic_consume"] = \
+ self.optimistic.get(session) == "yes"
- args["qpid.last_value_queue"] = \
- self.lvq.get(session) == "enable"
+ self.task.invoke(session, vhost, name, durable, args)
+ self.task.exit_with_redirect(session)
- args["qpid.optimistic_consume"] = \
- self.optimistic.get(session) == "yes"
-
- qsession = self.app.model.get_session_by_object(vhost)
-
- qsession.queue_declare(queue=name,
- durable=durable,
- arguments=args)
-
- for exchange in binding_info:
- if "key" in binding_info[exchange]:
- binding_key = binding_info[exchange]["key"]
- else:
- binding_key = None
-
- ename = binding_info[exchange]["name"]
- eargs = binding_info[exchange]["arguments"]
-
- qsession.exchange_bind(queue=name,
- exchange=ename,
- binding_key=binding_key,
- arguments=eargs)
-
- invoc.end()
- except Exception, e:
- self.task.exception(invoc, e)
-
- self.process_return(session)
-
class QueuePurge(ObjectTask):
def __init__(self, app, frame):
super(QueuePurge, self).__init__(app, frame)
@@ -416,71 +387,18 @@
self.task.invoke(session, queue, count)
self.task.exit_with_redirect(session)
-class BindSummaryPropertiesField(FormField):
- def __init__(self, app, name, queue):
- super(BindSummaryPropertiesField, self).__init__(app, name)
+class QueueBindingAdd(BindingAddTask):
+ def __init__(self, app, frame):
+ super(QueueBindingAdd, self).__init__(app, frame)
- self.sum_props = self.SummaryProperties(app, "properties", queue)
- self.add_child(self.sum_props)
+ self.form = QueueBindingAddForm(app, self.name, self)
- self.prop_tmpl = WidgetTemplate(self, "properties_html")
-
- class SummaryProperties(CuminProperties):
- def do_get_items(self, session):
- queue = self.object.get(session)
-
- return [("Name", queue.name),
- ("Durable", queue.durable),
- ("Exclusive", queue.exclusive),
- ("Auto-Delete", queue.autoDelete)]
-
- def render_inputs(self, session):
- writer = Writer()
- self.prop_tmpl.render(writer, session)
- return writer.to_string()
-
- def render_prop_items(self, session):
- return self.sum_props.render_items(session)
-
-class BindingAddForm(ObjectTaskForm):
+class QueueBindingAddForm(BindingAddForm):
def __init__(self, app, name, task):
- super(BindingAddForm, self).__init__(app, name, task)
+ super(QueueBindingAddForm, self).__init__(app, name, task)
- self.vhost = self.VhostAttribute(app, "vhost")
- self.add_attribute(self.vhost)
+ self.q_field.input.disabled = True
- self.props = BindSummaryPropertiesField(app, "props", self.object)
- self.add_field(self.props)
-
- self.bindings = self.ExchangeBindings(app, "bindings", self.vhost)
- self.add_field(self.bindings)
-
- class ExchangeBindings(ExchangeKeysField):
- def render_title(self, session):
- return "Exchange Bindings"
-
- class VhostAttribute(Attribute):
- def get(self, session):
- return self.widget.object.get(session).vhost
-
- def process_submit(self, session):
- queue = self.object.get(session)
-
- errors, form_binding_info = self.bindings.get_binding_errors \
- (session, queue.name)
-
- if not len(form_binding_info):
- # no exchanges were selected is not an error that
- # ExchangeKeysField looks for
- error = FormError("At least one exchange must be selected")
- self.errors.add(session, error)
-
- if not self.errors.get(session):
- print "XXX queue binding add", queue, form_binding_info
-
- #self.task.invoke(session, queue, args)
- self.task.exit_with_redirect(session)
-
class QueueOverview(RadioModeSet):
def __init__(self, app, name, queue):
super(QueueOverview, self).__init__(app, name)
@@ -634,10 +552,10 @@
return "Transactional messages enqueued and dequeued"
class QueueSelectField(FormField):
- def __init__(self, app, name, form):
+ def __init__(self, app, name, form, param):
super(QueueSelectField, self).__init__(app, name)
- self.param = self.QueueSearchInputSet(app, "queue_set")
+ self.param = self.QueueSearchInputSet(app, "queue_set", param)
self.add_child(self.param)
def get(self, session):
@@ -673,6 +591,9 @@
def render_item_content(self, session, queue):
return queue.name or "<em>Default</em>"
+ def render_item_value(self, session, queue):
+ return queue._id
+
class MoveMessagesBase(ObjectTask):
def get_title(self, session):
return "Move messages"
@@ -706,7 +627,8 @@
self.src_queue = src_queue
self.add_field(src_queue)
- self.dest_queue = self.QueueDestField(app, "dest", self)
+ queue = QueueParameter(app, "dqueue")
+ self.dest_queue = self.QueueDestField(app, "dest", self, queue)
self.dest_queue.required = True
self.add_field(self.dest_queue)
@@ -743,7 +665,8 @@
class MoveMessagesForm(MoveMessagesFormBase):
def __init__(self, app, name, task):
- src_queue = self.QueueSrctField(app, "src", self)
+ queue = QueueParameter(app, "queue")
+ src_queue = self.QueueSrctField(app, "src", self, queue)
src_queue.required = True
super(MoveMessagesForm, self).__init__(app, name, task, src_queue)
Modified: mgmt/newdata/cumin/python/cumin/messaging/queue.strings
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/queue.strings 2010-04-29 19:08:54 UTC (rev
3943)
+++ mgmt/newdata/cumin/python/cumin/messaging/queue.strings 2010-04-30 16:47:11 UTC (rev
3944)
@@ -81,12 +81,3 @@
</tr>
</tbody>
</table>
-
-[BindSummaryPropertiesField.properties_html]
-<div class="properties" style="width:80%">
- <table class="PropertySet">
- <tbody>
- {prop_items}
- </tbody>
- </table>
-</div>
Modified: mgmt/newdata/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/widgets.py 2010-04-29 19:08:54 UTC (rev 3943)
+++ mgmt/newdata/cumin/python/cumin/widgets.py 2010-04-30 16:47:11 UTC (rev 3944)
@@ -1441,12 +1441,103 @@
writer.write("</data>")
class IncrementalSearchInput(StringInput, ItemSet):
+ def __init__(self, app, name, field_param):
+ super(IncrementalSearchInput, self).__init__(app, name)
+
+ self.disabled_tmpl = WidgetTemplate(self, "disabled_html")
+ self.field = field_param
+
def do_get_items(self, session):
return ()
- def render_item_class(self, session, item):
- return "list_item"
+ def render_name(self, session):
+ return self.field.path
+ def do_render(self, session, *args):
+ if self.disabled:
+ writer = Writer()
+
+ self.disabled_tmpl.render(writer, session, *args)
+
+ return writer.to_string()
+ else:
+ return super(IncrementalSearchInput, self).do_render(session, *args)
+
+class BaseBindingInput(IncrementalSearchInput):
+ def __init__(self, app, name, field_param):
+ super(BaseBindingInput, self).__init__(app, name, field_param)
+
+ def render_item_content(self, session, field):
+ return field.name or "Default"
+
+ def render_value(self, session):
+ if self.disabled:
+ field = self.form.object.get(session)
+ return fmt_shorten(field.name, pre=36, post=4)
+ else:
+ input_value = self.param.get(session)
+ return input_value and input_value or ""
+
+ def base_get_items(self, session, objects):
+ obj_list = []
+ if not self.disabled:
+ obj_list_full = sorted_by(list(objects))
+
+ delta = timedelta(minutes=10)
+ for _obj in obj_list_full:
+ if (_obj._qmf_update_time > (datetime.now() - delta)):
+ obj_list.append(_obj)
+
+ return obj_list
+
+class BindingAddTask(ObjectTask):
+ def get_title(self, session):
+ return "Add Binding"
+
+ def do_invoke(self, invoc, obj, queue, exchange, key, args):
+ session = self.app.model.get_session_by_object(obj)
+ session.exchange_bind(queue=queue, exchange=exchange,
+ binding_key=key, arguments=args)
+ session.sync()
+
+ invoc.end()
+
+class QueueBindingField(ScalarField):
+ def __init__(self, app, name, queue):
+ super(QueueBindingField, self).__init__(app, name, None)
+
+ self.input = QueueInput(app, "input", queue)
+ self.add_child(self.input)
+
+ def render_title(self, session):
+ return "Queue"
+
+class ExchangeBindingField(ScalarField):
+ def __init__(self, app, name, exchange):
+ super(ExchangeBindingField, self).__init__(app, name, None)
+
+ self.input = ExchangeInput(app, "input", exchange)
+ self.add_child(self.input)
+
+ def render_title(self, session):
+ return "Exchange"
+
+class QueueInput(BaseBindingInput):
+ def do_get_items(self, session):
+ cls = self.app.rosemary.org_apache_qpid_broker.Queue
+ queue = self.form.object.get(session)
+ vhostid = queue._vhostRef_id
+ queues = cls.get_selection(session.cursor, _vhostRef_id=vhostid)
+ return self.base_get_items(session, queues)
+
+class ExchangeInput(BaseBindingInput):
+ def do_get_items(self, session):
+ cls = self.app.rosemary.org_apache_qpid_broker.Exchange
+ obj = self.form.object.get(session)
+ vhostid = obj._class._name == "Vhost" and obj._id or obj._vhostRef_id
+ exchanges = cls.get_selection(session.cursor, _vhostRef_id=vhostid)
+ return self.base_get_items(session, exchanges)
+
class TopTable(DataTable):
def __init__(self, app, name, adapter):
super(TopTable, self).__init__(app, name, adapter)
Modified: mgmt/newdata/cumin/python/cumin/widgets.strings
===================================================================
--- mgmt/newdata/cumin/python/cumin/widgets.strings 2010-04-29 19:08:54 UTC (rev 3943)
+++ mgmt/newdata/cumin/python/cumin/widgets.strings 2010-04-30 16:47:11 UTC (rev 3944)
@@ -804,20 +804,55 @@
background-color: #fff;
}
+[IncrementalSearchInput.javascript]
+addJavascript('resource?name=incrementalSearch.js', 'head');
+
[IncrementalSearchInput.css]
-div.IncrementalSearchInput ul {
+div.IncrementalSearchInput select {
display: none;
}
+div.IncrementalSearchInput input.disabled {
+ background:white;
+ color:black;
+ border: 0px solid white;
+ cursor:default;
+}
[IncrementalSearchInput.html]
<div class="IncrementalSearchInput">
-<input id="{id}" type="text" name="{name}"
value="{value}" tabindex="{tab_index}" {disabled_attr}
size="{size}" autocomplete="off"/>
-<ul id="{id}.list">{items}</ul>
+ <input id="{id}" type="text" name="{name}"
value="{value}" tabindex="{tab_index}" size="{size}"
autocomplete="off"/>
+ <select id="{id}.list">{items}</select>
</div>
<script type="text/javascript">
//<![CDATA[
-window.addEvent("domready", function () {
- new IncrementalSearch($("{id}"), Inc_CIBeginning, "autocomplete",
"{id}.list", 8); });
+window.addEvent("domready",
+ function () {
+ new IncrementalSearch($("{id}"), Inc_CIBeginning,
"autocomplete", "{id}.list", 8);
+ }
+);
//]]>
</script>
+[IncrementalSearchInput.item_html]
+<option value="{item_value}">{item_content}</option>
+
+[IncrementalSearchInput.disabled_html]
+<div class="IncrementalSearchInput">
+<input class="disabled" id="{name}" name="{name}"
value="{value}" tabindex="{tab_index}" size="{size}" />
+</div>
+<script type="text/javascript">
+//<![CDATA[
+// Using input attribute disabled="disabled' has the unfortunate side effect of
not sending the input value
+// when the form is submitted. So we just leave it enabled and filter out keyboard input
with javascript.
+window.addEvent("domready",
+ function () {
+ $("{name}").addEvent("keypress",
+ function (e) {
+ if (!(e.key in {tab:1, left:1, right:1}))
+ if (! (e.key == 'c' && e.control) )
+ new Event(e).stop();
+ } )
+ }
+);
+//]]>
+</script>