Author: eallen
Date: 2008-07-25 15:26:39 -0400 (Fri, 25 Jul 2008)
New Revision: 2221
Modified:
mgmt/trunk/cumin/python/cumin/exchange.py
mgmt/trunk/cumin/python/cumin/exchange.strings
Log:
Added Add Exchange
Modified: mgmt/trunk/cumin/python/cumin/exchange.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/exchange.py 2008-07-25 19:23:16 UTC (rev 2220)
+++ mgmt/trunk/cumin/python/cumin/exchange.py 2008-07-25 19:26:39 UTC (rev 2221)
@@ -68,6 +68,11 @@
def get_args(self, session):
reg = self.frame.get_object(session)
return (reg.getDefaultVhost(),)
+
+ def render_add_exchange_url(self, session, vhost):
+ branch = session.branch()
+ self.frame.show_exchange_add(branch)
+ return branch.marshal()
def render_title(self, session, vhost):
return "Exchanges %s" % fmt_count(vhost.exchanges.count())
@@ -165,6 +170,10 @@
view = ExchangeView(app, "view")
self.add_mode(view)
self.set_view_mode(view)
+
+ remove = ExchangeRemove(app, "remove")
+ self.add_mode(remove)
+ self.set_remove_mode(remove)
def render_title(self, session, exchange):
if exchange.name:
@@ -172,6 +181,32 @@
else:
return "Default Exchange"
+class ExchangeRemove(CuminConfirmForm):
+ def get_args(self, session):
+ return self.frame.get_args(session)
+
+ def process_cancel(self, session, reg):
+ branch = session.branch()
+ self.frame.show_view(branch)
+ self.page.set_redirect_url(session, branch.marshal())
+
+ def process_submit(self, session, reg):
+ action = self.app.model.broker_registration.remove
+ action.invoke(reg)
+
+ branch = session.branch()
+ self.page.show_main(branch).show_view(branch)
+ self.page.set_redirect_url(session, branch.marshal())
+
+ def render_title(self, session, exchange):
+ return "Remove Exchange '%s'" % exchange.name
+
+ def render_submit_content(self, session, exchange):
+ return "Yes, Remove Exchange '%s'" % exchange.name
+
+ def render_cancel_content(self, session, reg):
+ return "No, Cancel"
+
class ExchangeStatus(CuminStatus):
def render_messages_received(self, session, exchange):
return self.app.model.exchange.msgReceives.rate_html(exchange)
@@ -239,13 +274,13 @@
if binding.queue:
return binding.queue.name
-class ExchangeForm(CuminForm):
+class ExchangeForm(CuminFieldForm):
def __init__(self, app, name):
super(ExchangeForm, self).__init__(app, name)
- self.exchange_name = TextInput(app, "exchange_name", self)
- self.add_child(self.exchange_name)
-
+ self.exchange_name = ExchangeNameField(app, "exchange_name", self)
+ self.add_field(self.exchange_name)
+
self.type = Parameter(app, "type")
self.type.default = "direct"
self.add_parameter(self.type)
@@ -264,46 +299,50 @@
self.fanout.set_parameter(self.type)
self.fanout.set_value("fanout")
self.add_child(self.fanout)
+
+ self.xml = RadioInput(app, "xml", self)
+ self.xml.set_parameter(self.type)
+ self.xml.set_value("xml")
+ self.add_child(self.xml)
+
+ def render_direct_id(self, session, *args):
+ return self.direct.path
+
+ def render_topic_id(self, session, *args):
+ return self.topic.path
+
+ def render_fanout_id(self, session, *args):
+ return self.fanout.path
- def validate(self, session):
- error = None
+ def render_xml_id(self, session, *args):
+ return self.xml.path
- name = self.exchange_name.get(session)
-
- if name == "":
- error = EmptyInputError(exchange_name)
- self.exchange_name.add_error(session, error)
- elif " " in name:
- error = FormError("""
- The exchange name is invalid; allowed characters are
- letters, digits, ".", and "_"
- """)
- self.exchange_name.add_error(session, error)
-
- return error is None
-
class ExchangeAdd(ExchangeForm):
def get_args(self, session):
return self.frame.frame.get_args(session)
- def process_cancel(self, session, vhost):
+ def process_cancel(self, session):
branch = session.branch()
- self.page.show_broker(branch, vhost.get_broker()).show_view(branch)
+ self.frame.show_view(branch)
self.page.set_redirect_url(session, branch.marshal())
- def process_submit(self, session, vhost):
- if self.validate(session):
+ def process_submit(self, session):
+ errors = self.validate(session)
+
+ if errors:
+ pass
+ else:
+ reg = self.frame.get_object(session)
exchange = Exchange()
exchange.name = self.exchange_name.get(session)
exchange.type = self.type.get(session)
+
+ action = self.app.model.exchange.add
+ action.invoke(reg, exchange)
- vhost.addExchange(exchange)
-
- branch = session.branch()
- self.page.show_exchange(branch, exchange).show_view(branch)
- self.page.set_redirect_url(session, branch.marshal())
-
- def render_title(self, session, vhost):
+ self.process_cancel(session)
+
+ def render_title(self, session):
return "Add Exchange"
class ExchangeEdit(ExchangeForm):
Modified: mgmt/trunk/cumin/python/cumin/exchange.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/exchange.strings 2008-07-25 19:23:16 UTC (rev 2220)
+++ mgmt/trunk/cumin/python/cumin/exchange.strings 2008-07-25 19:26:39 UTC (rev 2221)
@@ -46,8 +46,12 @@
}
[ExchangeSet.html]
+
+<ul class="actions">
+ <li><a class="nav" href="{add_exchange_url}">Add New
Exchange</a></li>
+ </ul>
+
<div class="rfloat">{phase}</div>
-
{unit}
<table class="mobjects">
@@ -72,27 +76,30 @@
<h1>{title}</h1>
</div>
<div class="body">
- <span class="legend">Name</span>
- <fieldset>
<div class="field">{exchange_name}</div>
- </fieldset>
+ <div style="clear:right;">
<span class="legend">Type</span>
<fieldset>
<div class="field">
{direct}
- <em>Direct:</em> Route messages to queues by queue name
+ <label for="{direct_id}"><em>Direct:</em> Route
messages to queues by queue name</label>
</div>
<div class="field">
{topic}
- <em>Topic:</em> Route messages to queues by topic keyword match
+ <label for="{topic_id}"><em>Topic:</em> Route
messages to queues by topic keyword match</label>
</div>
<div class="field">
{fanout}
- <em>Fan Out:</em> Lorem ipsum gloria dei ipso facto ad nauseum
+ <label for="{fanout_id}"><em>Fan Out:</em> Route
message to all queues attached to this exchange</label>
</div>
+ <div class="field">
+ {xml}
+ <label for="{xml_id}"><em>XML:</em> Route message to
queues based on XML content of the message</label>
+ </div>
</fieldset>
-
+ </div>
+
{hidden_inputs}
</div>
<div class="foot">
@@ -101,7 +108,7 @@
{cancel}
</div>
</form>
-<script defer="defer">
+<script type="text/javascript" defer="defer">
(function() {
// elements[0] is a fieldset, at least in firefox
var elem = wooly.doc().elembyid("{id}").node.elements[1];
@@ -152,7 +159,7 @@
</tr>
</table>
</div>
-<script>
+<script type="text/javascript">
cumin.objectListeners["{id}"] = updateExchangeStatus
</script>