Scott Seago
2008-May-30 16:43 UTC
[Ovirt-devel] [Patch] HW pool quota add/edit/delete/view
-------------- next part -------------- A non-text attachment was scrubbed... Name: hw-pool-quota.patch Type: text/x-patch Size: 21304 bytes Desc: not available URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20080530/aafa13d1/attachment.bin>
Hugh O. Brock
2008-May-30 17:15 UTC
[Ovirt-devel] [Patch] HW pool quota add/edit/delete/view
On Fri, May 30, 2008 at 12:43:28PM -0400, Scott Seago wrote:>> >From f76391b8b1b2e21875fdb3cb8c541e6a70ecb7ee Mon Sep 17 00:00:00 2001 > From: Scott Seago <sseago at redhat.com> > Date: Fri, 30 May 2008 12:39:40 -0400 > Subject: [PATCH] added default quota to HW pool form. it can be edited/deleted too... > > > Signed-off-by: Scott Seago <sseago at redhat.com> > --- > wui/src/app/controllers/hardware_controller.rb | 10 +++ > wui/src/app/controllers/quota_controller.rb | 38 +++++++----- > wui/src/app/helpers/application_helper.rb | 1 - > wui/src/app/views/hardware/quick_summary.rhtml | 56 ++++++++++++++++++ > wui/src/app/views/hardware/show.html.erb | 15 +++++ > wui/src/app/views/host/show.rhtml | 13 +++-- > wui/src/app/views/layouts/redux.rhtml | 5 +- > wui/src/app/views/layouts/selection.rhtml | 28 ++++++++- > wui/src/app/views/quota/_form.rhtml | 2 +- > wui/src/app/views/quota/edit.rhtml | 68 +++++++++++----------- > wui/src/app/views/quota/new.rhtml | 71 +++++++++++------------ > wui/src/app/views/resources/quick_summary.rhtml | 8 +- > wui/src/app/views/resources/show.rhtml | 9 ++- > wui/src/public/images/icon_edit.png | Bin 0 -> 375 bytes > wui/src/public/images/icon_separator.png | Bin 0 -> 216 bytes > wui/src/public/images/icon_x.png | Bin 0 -> 340 bytes > wui/src/public/javascripts/ovirt.js | 12 ++++ > wui/src/public/stylesheets/layout.css | 31 ++++++++++ > 18 files changed, 260 insertions(+), 107 deletions(-) > create mode 100644 wui/src/app/views/hardware/quick_summary.rhtml > create mode 100644 wui/src/public/images/icon_edit.png > create mode 100644 wui/src/public/images/icon_separator.png > create mode 100644 wui/src/public/images/icon_x.png > > diff --git a/wui/src/app/controllers/hardware_controller.rb b/wui/src/app/controllers/hardware_controller.rb > index 0f0c904..0eaf76f 100644 > --- a/wui/src/app/controllers/hardware_controller.rb > +++ b/wui/src/app/controllers/hardware_controller.rb > @@ -225,6 +225,16 @@ class HardwareController < ApplicationController > render :json => graph_object > end > > + def quick_summary > + pre_show > + set_perms(@perm_obj) > + unless @can_view > + flash[:notice] = 'You do not have permission to view this Hardware Pool: redirecting to top level' > + redirect_to :action => 'list' > + end > + render :layout => 'selection' > + end > + > def hosts_json > if params[:id] > pre_json > diff --git a/wui/src/app/controllers/quota_controller.rb b/wui/src/app/controllers/quota_controller.rb > index d865529..cfedf2d 100644 > --- a/wui/src/app/controllers/quota_controller.rb > +++ b/wui/src/app/controllers/quota_controller.rb > @@ -38,39 +38,45 @@ class QuotaController < ApplicationController > end > > def new > + render :layout => 'popup' > end > > def create > - if @quota.save > - flash[:notice] = 'Quota was successfully created.' > - redirect_to_parent > - else > - render :action => 'new' > + begin > + @quota.save! > + render :json => { :object => "quota", :success => true, > + :alert => "Quota was successfully created." } > + rescue > + render :json => { :object => "quota", :success => false, > + :errors => @quota.errors.localize_error_messages.to_a} > end > end > > def edit > + render :layout => 'popup' > end > > def update > - if @quota.update_attributes(params[:quota]) > - flash[:notice] = 'Quota was successfully updated.' > - redirect_to_parent > - else > - render :action => 'edit' > + begin > + @quota.update_attributes!(params[:quota]) > + render :json => { :object => "quota", :success => true, > + :alert => "Quota was successfully updated." } > + rescue > + render :json => { :object => "quota", :success => false, > + :errors => @quota.errors.localize_error_messages.to_a} > end > end > > def destroy > pool = @quota.pool > - unless @quota.destroy > - flash[:notice] = 'destroying quota failed ' > - end > - if pool > - redirect_to :controller => pool.get_controller, :action => 'show', :id => pool.id > + if @quota.destroy > + alert="Quota was successfully deleted." > + success=true > else > - redirect_to :controller => 'dashboard' > + alert="Failed to delete quota." > + success=false > end > + render :json => { :object => "quota", :success => success, :alert => alert } > end > > protected > diff --git a/wui/src/app/helpers/application_helper.rb b/wui/src/app/helpers/application_helper.rb > index 20c344f..75b6195 100644 > --- a/wui/src/app/helpers/application_helper.rb > +++ b/wui/src/app/helpers/application_helper.rb > @@ -106,7 +106,6 @@ module ApplicationHelper > } > end > > - > def timeout_flash(name) > %{ > <script type="text/javascript"> > diff --git a/wui/src/app/views/hardware/quick_summary.rhtml b/wui/src/app/views/hardware/quick_summary.rhtml > new file mode 100644 > index 0000000..efcdb01 > --- /dev/null > +++ b/wui/src/app/views/hardware/quick_summary.rhtml > @@ -0,0 +1,56 @@ > +<%- content_for :title do -%> > + Default quota for <%=h @pool.name %> > +<%- end -%> > +<%- content_for :action_links do -%> > + <%if @can_modify -%> > + <%if @pool.quota -%> > + <%= link_to image_tag("icon_edit.png") + " Edit Default Quota", > + {:controller => 'quota', :action => 'edit', :id => @pool.quota}, > + :rel=>"facebox[.bolder]" %> > + <a href="#" onClick="delete_default_quota()"> > + <%= image_tag "icon_x.png" %> Remove Default Quota > + </a> > + <% else -%> > + <%= link_to image_tag("icon_edit.png") + " Edit Default Quota", > + {:controller => 'quota', :action => 'new', :pool_id => @pool }, > + :rel=>"facebox[.bolder]" %> > + <% end -%> > + <% end -%> > +<% end -%> > +<script type="text/javascript"> > + function delete_default_quota() > + { > + if(confirm("Are you sure?")){ > + $.post('<%= url_for :controller => "quota", :action => "destroy", :id => @pool.quota %>', > + function(data,status){ > + refresh_summary('hwpool_selection', > + '<%= url_for :controller => "hardware", > + :action => "quick_summary" %>', > + <%= @pool.id %>) > + if (data.alert) { > + alert(data.alert); > + } > + }, 'json'); > + } > + } > +</script> > + > + > + <% resources = @pool.full_resources %> > + <div class="selection_key"> > + <br/> > + <% for item in resources[:labels] %> > + <% total_limit = resources[:total][item[1]] > + total_limit = "unlimited" if total_limit.nil? %> > + <%= item[0]%>:<br/> > + <% end %> > + </div> > + <div class="selection_value"> > + default allowed<br/> > + <% for item in resources[:labels] %> > + <% total_limit = resources[:total][item[1]] > + total_limit = "unlimited" if total_limit.nil? %> > + <%= total_limit %> > + <%= item[2]%><br> > + <% end %> > + </div> > diff --git a/wui/src/app/views/hardware/show.html.erb b/wui/src/app/views/hardware/show.html.erb > index 81bb708..b52243b 100644 > --- a/wui/src/app/views/hardware/show.html.erb > +++ b/wui/src/app/views/hardware/show.html.erb > @@ -1,4 +1,5 @@ > <div class="panel_header"></div> > + <div class="data_section"> > > <br/> <b><%= @pool.name %></b><br/><br/> > > @@ -102,4 +103,18 @@ > </tr> > > </table> > + </div> > +</div> > +<div class="selection_detail" id="hwpool_selection"> > + <div>Hardware pool quota details.</div> > </div> > +<%- content_for :scripts do -%> > +<script type="text/javascript"> > + $(document).ready(function(){ > + refresh_summary('hwpool_selection', > + '<%= url_for :controller => "hardware", > + :action => "quick_summary" %>', > + <%= @pool.id %>) > + }); > +</script> > +<%- end -%> > diff --git a/wui/src/app/views/host/show.rhtml b/wui/src/app/views/host/show.rhtml > index dbc9028..c50d511 100644 > --- a/wui/src/app/views/host/show.rhtml > +++ b/wui/src/app/views/host/show.rhtml > @@ -1,5 +1,7 @@ > - <div class="selection_left"> > - <div class="selection_title"><%=h @host.hostname %></div> > +<%- content_for :title do -%> > + <%=h @host.hostname %> > +<%- end -%> > + > <div class="selection_key"> > UUID:<br/> > CPUs:<br/> > @@ -22,7 +24,7 @@ > disabled > <% end -%> > <br/> > - </div> > + > <!-- FIXME: need styling > <h3>Network Interfaces</h3> > <% if !@host.nics.empty? %> > @@ -33,7 +35,8 @@ > <% end %> > --> > </div> > -<div class="selection_right"> > + > +<%- content_for :right do -%> > <div class="detail-pane-chart-header"> > <span> > Load > @@ -62,5 +65,5 @@ > :chartType => 'line', > :yGridLines => 'lightgrey', > :url => (url_for :controller => 'graph', :action => 'graph', :type => 'detail') } %> > -</div> > +<%- end -%> > > diff --git a/wui/src/app/views/layouts/redux.rhtml b/wui/src/app/views/layouts/redux.rhtml > index 63a9a56..a40cb1f 100644 > --- a/wui/src/app/views/layouts/redux.rhtml > +++ b/wui/src/app/views/layouts/redux.rhtml > @@ -43,10 +43,7 @@ > }) > }); > $(document).ready(function(){ > - $('a[rel*=facebox]').facebox() > - }) > - $(document).ready(function(){ > - $('a[rel*=close]').trigger('close.facebox') > + refresh_facebox() > }) > </script> > <%= yield :scripts -%> > diff --git a/wui/src/app/views/layouts/selection.rhtml b/wui/src/app/views/layouts/selection.rhtml > index 736517c..ff9583b 100644 > --- a/wui/src/app/views/layouts/selection.rhtml > +++ b/wui/src/app/views/layouts/selection.rhtml > @@ -1,2 +1,26 @@ > -<%# currently nothing for popups here. %> > -<%= yield %> > +<div class="selection_left"> > + <div class="selection_title"><%= yield :title -%></div> > + > + <% tools = yield :action_links -%> > + <% if tools %> > + <ul class="selection_tools"> > + <li> > + <%= image_tag "icon_separator.png", :style=>"vertical-align: middle;" %> > + </li> > + <%= tools -%> > + </ul> > + <% end %> > + <div class="clear_row"/> > + > + <%= yield %> > + > +</div> > +<% right = yield :right -%> > +<% if right %> > + <div class="selection_right"> > + <%= right -%> > + </div> > +<% end %> > +<script type="text/javascript"> > + refresh_facebox() > +</script> > \ No newline at end of file > diff --git a/wui/src/app/views/quota/_form.rhtml b/wui/src/app/views/quota/_form.rhtml > index 88d9adc..ac55550 100644 > --- a/wui/src/app/views/quota/_form.rhtml > +++ b/wui/src/app/views/quota/_form.rhtml > @@ -1,7 +1,7 @@ > <%= error_messages_for 'quota' %> > > <!--[form:quota]--> > -<%= hidden_field_with_label (@quota.pool[:type] == "HardwarePool" ? "Hardware Pool" : "VM Resource Pool"), 'quota', 'pool_id', @quota.pool.name %> > +<%= hidden_field 'quota', 'pool_id' %> > > <%= text_field_with_label "Total Virtual CPUs", 'quota', 'total_vcpus' %> > > diff --git a/wui/src/app/views/quota/edit.rhtml b/wui/src/app/views/quota/edit.rhtml > index 30db6b7..d2f4be0 100644 > --- a/wui/src/app/views/quota/edit.rhtml > +++ b/wui/src/app/views/quota/edit.rhtml > @@ -1,35 +1,37 @@ > -<div id="dataTableWrapper"> > - > - <div class="dataTable"> > - <div class="inside"> > - > - <div class="data-table-column"> > - <% form_tag :action => 'update', :id => @quota do %> > - <%= render :partial => 'form' %> > - <%= submit_tag 'Edit' %> > - <% end %> > - </div> > - > - </div> <!-- end #data-table.inside --> > - </div> <!-- end #dataTable --> > - > -</div> <!-- end #dataTableWrapper --> > - > -<div class="tools"> > - <h3>Actions</h3> > - > - <%if @can_modify -%> > - <div class="actions remove"> > - <%= link_to 'Remove Quota (unlimited)', { :controller => 'quota', :action => 'destroy', :id => @quota }, { :confirm => 'Are you sure?', :method=> :post, :class => "edit" } %> > - </div> > - <%- end -%> > - > - <div class="actions"> > - <%= link_to "Back to #{@quota.pool.name}", { :controller => @quota.pool.get_controller, :action => 'show', :id => @quota.pool }, { :class => "show" } %> > - </div> > - > -</div> > - > <%- content_for :title do -%> > -<%= _("Editing Quota") %> > + Edit Quota > <%- end -%> > +<%- content_for :description do -%> > + Edit the quota for <%= @quota.pool.name %>. > +<%- end -%> > + > +<form method="POST" action="<%= url_for :action => 'update' %>" id="quota_form" > > +<div class="dialog_form"> > + <%= hidden_field_tag 'id', @quota.id %> > + <%= render :partial => 'form' %> > +</div> > +<%= popup_footer("$('#quota_form').submit()", "Edit Quota") %> > +</form> > + > +<script type="text/javascript"> > +$(function() { > + var quotaoptions = { > + target: '<%= url_for :action => 'update' %>', // target element to update > + dataType: 'json', > + success: function(response, status) { > + ajax_validation(response, status) > + if (response.success) { > + jQuery(document).trigger('close.facebox'); > + refresh_summary('<%= (@quota.pool.get_controller == "hardware") ? > + "hw" : "vm" %>pool_selection', > + '<%= url_for :controller => @quota.pool.get_controller, > + :action => "quick_summary" %>', > + <%= @quota.pool.id %>) > + } > + } > + }; > + > + // bind form using 'ajaxForm' > + $('#quota_form').ajaxForm(quotaoptions); > +}); > +</script> > diff --git a/wui/src/app/views/quota/new.rhtml b/wui/src/app/views/quota/new.rhtml > index 7473884..861d74f 100644 > --- a/wui/src/app/views/quota/new.rhtml > +++ b/wui/src/app/views/quota/new.rhtml > @@ -1,39 +1,36 @@ > - <div id="data"> > - <div class="inside"> > - > - <div id="dataTableWrapper"> > - > - <div class="dataTable"> > - <div class="inside"> > - > - <div class="data-table-column"> > - > - <% form_tag :action => 'create' do %> > - <%= render :partial => 'form' %> > - <%= submit_tag "Create" %> > - <% end %> > - </div> > - > - </div> <!-- end #data-table.inside --> > - </div> <!-- end #dataTable --> > - > - </div> <!-- end #dataTableWrapper --> > - > - </div> <!-- end #data.inside --> > - </div> <!-- end #data --> > - > - </td> > - <td id="right"> > - <div class="heading"> </div> > - <div class="tools"> > - <h3>Actions</h3> > - <div class="actions"> > - <%= link_to "Back to #{@quota.pool.name}", { :controller => @quota.pool.get_controller, :action => 'show', :id => @quota.pool }, { :class => "show" } %> > - </div> > - </div> > - > - </td> > - > <%- content_for :title do -%> > -<%= _("New Quota") %> > + Add New Quota > +<%- end -%> > +<%- content_for :description do -%> > + Add a quota for <%= @quota.pool.name %>. > <%- end -%> > + > +<form method="POST" action="<%= url_for :action => 'create' %>" id="quota_form" > > +<div class="dialog_form"> > + <%= render :partial => 'form' %> > +</div> > +<%= popup_footer("$('#quota_form').submit()", "Create Quota") %> > +</form> > + > +<script type="text/javascript"> > +$(function() { > + var quotaoptions = { > + target: '<%= url_for :action => 'create' %>', // target element to update > + dataType: 'json', > + success: function(response, status) { > + ajax_validation(response, status) > + if (response.success) { > + jQuery(document).trigger('close.facebox'); > + refresh_summary('<%= (@quota.pool.get_controller == "hardware") ? > + "hw" : "vm" %>pool_selection', > + '<%= url_for :controller => @quota.pool.get_controller, > + :action => "quick_summary" %>', > + <%= @quota.pool.id %>) > + } > + } > + }; > + > + // bind form using 'ajaxForm' > + $('#quota_form').ajaxForm(quotaoptions); > +}); > +</script> > diff --git a/wui/src/app/views/resources/quick_summary.rhtml b/wui/src/app/views/resources/quick_summary.rhtml > index 3bdeefa..e71d9c9 100644 > --- a/wui/src/app/views/resources/quick_summary.rhtml > +++ b/wui/src/app/views/resources/quick_summary.rhtml > @@ -1,6 +1,7 @@ > - <div class="selection_left"> > - <div class="selection_title"><%=h @vm_resource_pool.name %> quota</div> > - > +<%- content_for :title do -%> > + <%=h @vm_resource_pool.name %> quota > +<%- end -%> > + > <% resources = @vm_resource_pool.full_resources %> > <div class="selection_key"> > <br/> > @@ -19,4 +20,3 @@ > <%= item[2]%><br> > <% end %> > </div> > -</div> > diff --git a/wui/src/app/views/resources/show.rhtml b/wui/src/app/views/resources/show.rhtml > index ecf8fc6..64bd019 100644 > --- a/wui/src/app/views/resources/show.rhtml > +++ b/wui/src/app/views/resources/show.rhtml > @@ -40,7 +40,7 @@ > </td> > > <div class="selection_detail" id="vmpool_selection"> > - <div>Select a VM pool above.</div> > + <div>VM pool quota details.</div> > </div> > > <%- content_for :title do -%> > @@ -50,9 +50,10 @@ > <%- content_for :scripts do -%> > <script type="text/javascript"> > $(document).ready(function(){ > - $('#vmpool_selection').load('<%= url_for :controller => "resources", > - :action => "quick_summary" %>', > - { id: <%= @vm_resource_pool.id %>}) > + refresh_summary('vmpool_selection', > + '<%= url_for :controller => "resources", > + :action => "quick_summary" %>', > + <%= @vm_resource_pool.id %>) > }); > </script> > > diff --git a/wui/src/public/images/icon_edit.png b/wui/src/public/images/icon_edit.png > new file mode 100644 > index 0000000000000000000000000000000000000000..aaf2459f2e31ee73a7fff3e324d2825e4fca1e65 > GIT binary patch > literal 375 > zcmeAS at N?(olHy`uVBq!ia0vp^0zk~e!3HF=pW8M9DVAa<&kznEsNqQI0P;BtJR*x3 > z7`Q%wFr(8NlNmrk(Gu5)66d1S#FEVXJcW?V+*AfreIrYK0}CgYnWjJmG9U%P`DrEP > ziAAXljw$&`sS0kHMXBZaMcKs)&cVhruDLM-)m`v(aSYLzICYY3-XRA8H~D>xw%a|D > zgO at M)ThkJw;OaGpc})@jHk0%lYl~U}mM&c6;r at B4LxjXn_AsfnCf4sW)3$J@^(_&* > z!7$(O*s-$rduKHMEwsulJMjA92G&`>X9YH at Oiw*|x`^|@?T;Nx-a0pF$ApTSI-IMS > zfBuNX_h8xb5BL3(mrqr-Y)SBB<4M>pzPNy^WRkXxrbJWl0``6`xmI at 8Nm14}{roh2 > z4mme9omN+Te&*@F)W3WOlFA-COe|iuZvU<$#s$}}`fk~Lv|RZQ^UZCi<#~2Lx&rhY > NgQu&X%Q~loCII`8jh_Gj > > literal 0 > HcmV?d00001 > > diff --git a/wui/src/public/images/icon_separator.png b/wui/src/public/images/icon_separator.png > new file mode 100644 > index 0000000000000000000000000000000000000000..225fd6e2ab616d20cfd99837a53cce1049185155 > GIT binary patch > literal 216 > zcmeAS at N?(olHy`uVBq!ia0vp^LO{&J!3HGrh2HJ~QY^(zo*^7SP{WbZ0pxQQctjR6 > zFmQbUVMeDlCNqG7q9v{oCC){ui6xo&c?uz!xv31M`bL)e1{O{(GfjaCWIzgn^V3So > z6N^$A98>a>QWe}Xi&D$;i?WLqoP&*LTytXvsx$O-aSYLznEd1ae|u&g<>r~j>HplP > zDYwj&Si$1PD`lDyAbF%?j;VyCWT48$&AfID41TFbn`OhyB!QY4JYD@<);T3K0RRug > BI;H>s > > literal 0 > HcmV?d00001 > > diff --git a/wui/src/public/images/icon_x.png b/wui/src/public/images/icon_x.png > new file mode 100644 > index 0000000000000000000000000000000000000000..7190b38303f8657e9840311376f88899f1253a68 > GIT binary patch > literal 340 > zcmeAS at N?(olHy`uVBq!ia0vp at K+MU(1|(lrEz1H at EX7WqAsj$Z!;#Vfk}U9uEM{Qf > z`T)X=PHRkN00l)$Tq8=Hi&7IyGV}8kLNaqx8BFz!EcFd6oLpv_0u{)B6a?p|m6RtI > zr7}3C<R_&nxMdclmgg5`7b`di8_&4r#tc-q*3-o?L}F_0L`D8X1_G_|l0w}_b$2MP > zb8J>#p&Ie#-vu49ZdDGUWuDp3HblIcbn0-y((K=p)N0HBzEcf<pstj}B6R-D$(g5` > z-9wYPH*5`Sm1}TPadoMQeOHtCf0yF7V>1L-sJz^C;|OzMMLFjKMaJ`=x8}>(`$uGp > z8XrGn|I%djq%`9%H<xe<7Di7gICs#pJ?+Kcy}Di*YcFef?pmKU&9vQa`zJvOex^_V > azpyTpsQIrKP$&#^ID at CFpUXO@geCykaeLGN > > literal 0 > HcmV?d00001 > > diff --git a/wui/src/public/javascripts/ovirt.js b/wui/src/public/javascripts/ovirt.js > index 675f20d..00befa1 100644 > --- a/wui/src/public/javascripts/ovirt.js > +++ b/wui/src/public/javascripts/ovirt.js > @@ -136,3 +136,15 @@ function afterVm(response, status){ > $("#vms_grid").flexReload() > } > } > + > +//selection detail refresh > +function refresh_summary(element_id, url, obj_id){ > + $('#'+element_id+'').load(url, { id: obj_id}) > +} > + > +// this must be called again after ajax loading of content with facebox links > +function refresh_facebox(){ > + $('a[rel*=facebox]').facebox() > + $('a[rel*=close]').trigger('close.facebox') > +} > + > diff --git a/wui/src/public/stylesheets/layout.css b/wui/src/public/stylesheets/layout.css > index 3bbf1a1..74dd3c0 100644 > --- a/wui/src/public/stylesheets/layout.css > +++ b/wui/src/public/stylesheets/layout.css > @@ -233,8 +233,39 @@ textarea:focus, input:focus { > font-size: 120%; > font-weight:bold; > padding-bottom: 10px; > + float: left; > } > > +.selection_tools { > + background:transparent none repeat scroll 0%; > + color:#000000; > + float:left; > + line-height:1.7; > + list-style-type:none; > + margin:0pt; > + padding:0pt 8px; > + text-align:center; > + text-decoration:none; > +} > +.selection_tools li { > + float:left; > + margin:0pt 1px; > + padding:0pt; > +} > +.selection_tools img { > +} > +.selection_tools a { > + background:transparent none repeat scroll 0%; > + color:#000000; > + float:left; > + line-height:1.7; > + padding:0pt 8px; > + text-align:center; > + text-decoration:none; > +} > +.selection_tools a:hover { > + background:#B0CBDE none repeat scroll 0%; > +} > .selection_key { > text-align:right; > float:left; > -- > 1.5.4.1Starting to get somewhere here... looks good. ACK and committed to the main repo. --H