Skip to content

Commit

Permalink
System Packages - filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
knowncitizen committed Aug 12, 2011
1 parent baf77b0 commit 4f90d0b
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/app/stylesheets/katello.scss
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,17 @@ legend {
background-position: 0 -16px;
}
}
#filter_form {
float: right;
position: relative;
}
.filter {
@extend .search;
}
.filter_button {
@extend .search_button;
left: -30px;
}

/*footer*/
footer {
Expand Down
9 changes: 6 additions & 3 deletions src/app/views/systems/_packages.html.haml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
= include_javascripts :system_packages

= content_for :title do
#{_("System")}

= content_for :navigation do
= render_navigation(:expand_all => true, :level => 3)

= content_for :content do
%form#filter_form.clear
%input{ :name => "f", :type => "search", :placeholder => "Filter...", :id=>"filter"}
%button.filter_button #{_("Filter")}
%br.clear
%table.packages
%thead
%th #{_("Name")}
Expand All @@ -17,6 +23,3 @@
%td{:class=>"arch"}
#{p.arch}




2 changes: 1 addition & 1 deletion src/app/views/systems/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
= environment_selector(:locker_clickable=>false, :url_proc => lambda {|a| environments_systems_path(:env_id =>a[:environment].id )})

.grid_16.tall#main
= two_panel(@systems, @panel_options)
= two_panel(@systems, @panel_options)
3 changes: 3 additions & 0 deletions src/config/assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ javascripts:
- public/javascripts/systems.js
system_subscriptions:
- public/javascripts/system_subscriptions.js
system_packages:
- public/javascripts/system_packages.js
- public/javascripts/jquery.uitablefilter.js
organization:
- public/javascripts/organization.js
environment_edit:
Expand Down
91 changes: 91 additions & 0 deletions src/public/javascripts/jquery.uitablefilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2008 Greg Weber greg at gregweber.info
* Dual licensed under the MIT and GPLv2 licenses just as jQuery is:
* http://jquery.org/license
*
* documentation at http://gregweber.info/projects/uitablefilter
*
* allows table rows to be filtered (made invisible)
* <code>
* t = $('table')
* $.uiTableFilter( t, phrase )
* </code>
* arguments:
* jQuery object containing table rows
* phrase to search for
* optional arguments:
* column to limit search too (the column title in the table header)
* ifHidden - callback to execute if one or more elements was hidden
*/
(function($) {
$.uiTableFilter = function(jq, phrase, column, ifHidden){
var new_hidden = false;
if( this.last_phrase === phrase ) return false;

var phrase_length = phrase.length;
var words = phrase.toLowerCase().split(" ");

// these function pointers may change
var matches = function(elem) { elem.show() }
var noMatch = function(elem) { elem.hide(); new_hidden = true }
var getText = function(elem) { return elem.text() }

if( column ) {
var index = null;
jq.find("thead > tr:last > th").each( function(i){
if( $.trim($(this).text()) == column ){
index = i; return false;
}
});
if( index == null ) throw("given column: " + column + " not found")

getText = function(elem){ return $(elem.find(
("td:eq(" + index + ")") )).text()
}
}

// if added one letter to last time,
// just check newest word and only need to hide
if( (words.size > 1) && (phrase.substr(0, phrase_length - 1) ===
this.last_phrase) ) {

if( phrase[-1] === " " )
{ this.last_phrase = phrase; return false; }

var words = words[-1]; // just search for the newest word

// only hide visible rows
matches = function(elem) {;}
var elems = jq.find("tbody:first > tr:visible")
}
else {
new_hidden = true;
var elems = jq.find("tbody:first > tr")
}

elems.each(function(){
var elem = $(this);
$.uiTableFilter.has_words( getText(elem), words, false ) ?
matches(elem) : noMatch(elem);
});

last_phrase = phrase;
if( ifHidden && new_hidden ) ifHidden();
return jq;
};

// caching for speedup
$.uiTableFilter.last_phrase = ""

// not jQuery dependent
// "" [""] -> Boolean
// "" [""] Boolean -> Boolean
$.uiTableFilter.has_words = function( str, words, caseSensitive )
{
var text = caseSensitive ? str : str.toLowerCase();
for (var i=0; i < words.length; i++) {
if (text.indexOf(words[i]) === -1) return false;
}
return true;
}
}) (jQuery);
34 changes: 34 additions & 0 deletions src/public/javascripts/system_packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
Copyright 2011 Red Hat, Inc.
This software is licensed to you under the GNU General Public
License as published by the Free Software Foundation; either version
2 of the License (GPLv2) or (at your option) any later version.
There is NO WARRANTY for this software, express or implied,
including the implied warranties of MERCHANTABILITY,
NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
have received a copy of GPLv2 along with this software; if not, see
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*/
/**
* Created by .
* User: jrist
* Date: 7/13/11
* Time: 2:27 PM
*
* This file is for use with the packages subnav within systems page.
*/

$(document).ready(function() {
var theTable = $('table.packages');
var filter = $('#filter');

filter.keyup(function() {
$.uiTableFilter(theTable, this.value);
});

$('#filter_form').submit(function () {
filter.keyup();
return false;
}).focus(); //Give focus to input field
});
4 changes: 3 additions & 1 deletion src/public/javascripts/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ $(document).ready(function() {
}});
});
// check if we are viewing systems by environment
if (window.env_select !== undefined)
if (window.env_select !== undefined) {
env_select.click_callback = systems_page.env_change;
}

});

var systems_page = (function() {
Expand Down

0 comments on commit 4f90d0b

Please sign in to comment.