Hi all,
This adds a filter/pretty (or grid/pretty) toggle to Pools#show. I built on Pools#index and ended up building a helper method and moving the existing code into application.js, if this isn't too much of a taboo. We'll be using it in a lot more places. I set class="active" on whichever is currently selected so that when we have elements for the icons, we can style them with CSS to indicate which is selected.
There are a lot more places where this will be needed that haven't been implemented just yet; this should make it easier to implement those.
I want to call one weird thing out because it doesn't feel right, but I can't find a less-bad solution: I duplicated the filter_view? method between ApplicationController and ApplicationHelper. Same exact code. The reason I got here is that I need to reference filter_view? in a helper and/or a partial, neither of which is able to call controller methods. I initially just moved it to ApplicationHelper instead, but it turns out that controllers need to access it too, and controllers can't call helper methods. So for now I duplicated it, hoping that someone will point out a much more elegant solution.
-- Matt
Implements https://www.aeolusproject.org/redmine/issues/1575 Standard method of toggling between pretty and filter views. Also extends to Pools#show. --- src/app/helpers/application_helper.rb | 11 +++++++++++ src/app/views/layouts/_pretty_filter_toggle.haml | 2 ++ src/app/views/pools/index.haml | 22 +--------------------- src/app/views/pools/show.haml | 4 +++- src/features/pool.feature | 20 ++++++++++++++++---- src/public/javascripts/application.js | 20 ++++++++++++++++++++ 6 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 src/app/views/layouts/_pretty_filter_toggle.haml
diff --git a/src/app/helpers/application_helper.rb b/src/app/helpers/application_helper.rb index a73f293..9afcb84 100644 --- a/src/app/helpers/application_helper.rb +++ b/src/app/helpers/application_helper.rb @@ -221,4 +221,15 @@ module ApplicationHelper "#{obj.owner.first_name} #{obj.owner.last_name}" end end + + def pretty_filter_toggle(pretty_link, filter_link) + render :partial => 'layouts/pretty_filter_toggle', :locals => { + :pretty_link => pretty_link, + :filter_link => filter_link + } + end + + def filter_view? + params.include?(:view) and params[:view] == 'filter' + end end diff --git a/src/app/views/layouts/_pretty_filter_toggle.haml b/src/app/views/layouts/_pretty_filter_toggle.haml new file mode 100644 index 0000000..c985915 --- /dev/null +++ b/src/app/views/layouts/_pretty_filter_toggle.haml @@ -0,0 +1,2 @@ += link_to "Pretty View", pretty_link, :id => 'pretty_view', :class => (filter_view? ? '' : 'active') += link_to "Filter View", filter_link, :id => 'filter_view', :class => (filter_view? ? 'active' : '') \ No newline at end of file diff --git a/src/app/views/pools/index.haml b/src/app/views/pools/index.haml index 35fcd43..d04782e 100644 --- a/src/app/views/pools/index.haml +++ b/src/app/views/pools/index.haml @@ -1,29 +1,9 @@ = render :partial => 'header_index' = render :partial => 'scoreboard_index' -= link_to "Pretty View", pools_path(:view => 'pretty'), :id =>'pretty_view' -= link_to "Filtred View", pools_path(:view => 'filter'), :id => 'filtred_view' += pretty_filter_toggle(pools_path(:view => 'pretty'), pools_path(:view => 'filter')) %div#view - if params[:view] == 'filter' = render :partial => 'layouts/tabpanel' - else = render :partial => 'pretty_list'
-:javascript - $(document).ready(function (){ - $("#pretty_view").click(function(){ - $.get($(this).attr("href"), $(this).serialize(), - function(result) { - $("#view").html(result); - }, "script"); - return false; - }); - $("#filtred_view").click(function(){ - $.get($(this).attr("href"), $(this).serialize(), - function(result) { - $("#view").html(result); - $('#details-selected').hide(); - $('#details-view').tabs('destroy').tabs(); - }, "script"); - return false; - }); - }); diff --git a/src/app/views/pools/show.haml b/src/app/views/pools/show.haml index 355d33d..9986a23 100644 --- a/src/app/views/pools/show.haml +++ b/src/app/views/pools/show.haml @@ -1,8 +1,10 @@ = render :partial => 'header_show' = render :partial => 'scoreboard_show' += pretty_filter_toggle(pool_path(@pool, :view => 'pretty'), pool_path(@pool, :view => 'filter'))
-# TODO - Alerts aren't implemented just yet -#= render :partial => 'alerts'
-# TODO: %w(Deployments History Properties Permissions) links/tabs, plus filter links/icons, go here -= render :partial => @view, :locals => {:deployments => @pool.deployments} \ No newline at end of file +%div#view + = render :partial => @view, :locals => {:deployments => @pool.deployments} diff --git a/src/features/pool.feature b/src/features/pool.feature index 6c88c69..b507050 100644 --- a/src/features/pool.feature +++ b/src/features/pool.feature @@ -154,21 +154,33 @@ Feature: Manage Pools When I delete "mockpool" pool Then I should get back JSON object with success and errors
- Scenario: Switch pretty view to filtred + Scenario: Switch pretty view to filtred view on pools index Given I am on the pools page And I see "Overview" And I should see "expand all" - When I follow "Filtred View" + When I follow "Filter View" Then I should see "Pools" within "#details-view" And I should see "Instances" within "#details-view" And I should see "Deployments" within "#details-view" And I should not see "expand all" When I follow "Pretty View"
- Scenario: Switch from filtred view to pretty + Scenario: Switch from filtred view to pretty view on pools index Given I am on the pools page - And I follow "Filtred View" + And I follow "Filter View" And I should see "Pools" within "#view" When I follow "Pretty View" Then I should not see "Pools" within "#view" And I should see "expand all" + + Scenario: Pools#show pretty view + Given a pool "mockpool" exists with deployment "mockdeployment" + When I am viewing the pool "mockpool" + And I follow "Pretty View" + Then I should see "0 Instances" within "#view" + + Scenario: Pools#show filter view + Given a pool "mockpool" exists with deployment "mockdeployment" + When I am viewing the pool "mockpool" + And I follow "Filter View" + Then I should not see "0 Instances" within "#view" \ No newline at end of file diff --git a/src/public/javascripts/application.js b/src/public/javascripts/application.js index af29bd6..4e513c3 100644 --- a/src/public/javascripts/application.js +++ b/src/public/javascripts/application.js @@ -167,3 +167,23 @@ $(document).ready(function () { Conductor.enhanceListView(); Conductor.enhanceDetailsTabs(); }); + +/* Standard method for switching filter/pretty views */ +$(document).ready(function (){ +$("#pretty_view_toggle").click(function(){ + $.get($(this).attr("href"), $(this).serialize(), + function(result) { + $("#view").html(result); + }, "script"); + return false; + }); +$("#filter_view").click(function(){ + $.get($(this).attr("href"), $(this).serialize(), + function(result) { + $("#view").html(result); + $('#details-selected').hide(); + $('#details-view').tabs('destroy').tabs(); + }, "script"); + return false; +}); +});
Hey Matt,
ACK. There's a few notes inline.
As for your worry about having the same method accessible both from the controllers and views, there are 2 idiomatic ways to tackle that, depending on whether you want the code to reside in the controller or the helper module.
1) Keep the method in the controller and add this line to the controller's class definition:
helper_method :filter_view?
That will provide a helper out of the method.
2) If you want to have the code in a helper file, you can include that helper module in your controller class:
include ApplicationHelper
I tried it and both ways work.
Thomas
On Wed, May 25, 2011 at 12:42:21PM +0200, Tomas Sedovic wrote:
ACK. There's a few notes inline.
Updated and pushed. Thanks!
- Keep the method in the controller and add this line to the
controller's class definition:
helper_method :filter_view?
This is *precisely* what I was wanting to do. Thanks for the tip!
I think it would make more sense to move this code to a standalone function that would be called from $(document).ready. It would make it cleaner in my opinion.
Agreed. Updated.
I've made the changes you describe and pushed per your ACK. Thanks.
-- Matt
aeolus-devel@lists.fedorahosted.org