Skip to content

Commit

Permalink
added sort order feature
Browse files Browse the repository at this point in the history
added to master for appliance based version
  • Loading branch information
kacole2 committed Jun 5, 2014
1 parent bf3e0d1 commit 07f2a53
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/controllers/jumpsizes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create
def update
respond_to do |format|
if @jumpsize.update(jumpsize_params)
format.html { redirect_to @jumpsize, notice: 'Jumpsize was successfully updated.' }
format.html { redirect_to :jumpsizes, notice: 'Jumpsize was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
Expand Down Expand Up @@ -76,6 +76,6 @@ def set_jumpsize

# Never trust parameters from the scary internet, only allow the white list through.
def jumpsize_params
params.require(:jumpsize).permit(:size, :length1, :length2, :itemsperpage)
params.require(:jumpsize).permit(:size, :length1, :length2, :itemsperpage, :sortorder)
end
end
5 changes: 4 additions & 1 deletion app/controllers/jumpsquares_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ class JumpsquaresController < ApplicationController
def index
@tags = Tag.all
@jumpsizes = Jumpsize.all
@jumpsquares = Jumpsquare.search(params[:search]).paginate(:page => params[:page], :per_page => @jumpsizes.first.itemsperpage).order(sort_order('name'))
if @jumpsizes.first.sortorder == ''
@jumpsizes.first.sortorder == 'name'
end
@jumpsquares = Jumpsquare.search(params[:search]).paginate(:page => params[:page], :per_page => @jumpsizes.first.itemsperpage).order(sort_order(@jumpsizes.first.sortorder))
end

# GET /jumpsquares/1
Expand Down
9 changes: 8 additions & 1 deletion app/views/jumpsizes/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@
<div class="col-lg-7">
<%= f.number_field :itemsperpage, :class => "form-control" %>
</div>
</div>
</div>
<br>
<div class="form-group">
<%= f.label :sortorder, "How do you want the JumpSquares to be sorted by default?", :class => "col-lg-4 control-label" %>
<div class="col-lg-7">
<%= f.select :sortorder, [['Name','name'], ['Application Type','apptype'],['IP or DNS','ipordns'],['Jump URL','url']], {}, include_blank: false, :class => "form-control" %>
</div>
</div>
<center>
<div class="form-group">
<%= f.submit "Update JumpSquare Size", class: 'btn btn-primary'%>
Expand Down
14 changes: 14 additions & 0 deletions app/views/jumpsizes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<th>Truncated Characters for Name Length</th>
<th>Truncated Characters for IP/DNS Length</th>
<th>Items Per Page</th>
<th>Default Sort Order</th>

</tr>
</thead>
Expand All @@ -26,6 +27,19 @@
<td><%= jumpsize.length1 %></td>
<td><%= jumpsize.length2 %></td>
<td><%= jumpsize.itemsperpage %></td>

<% if jumpsize.sortorder == 'name' %>
<td>Name</td>
<% elsif jumpsize.sortorder == 'ipordns' %>
<td>IP or DNS</td>
<% elsif jumpsize.sortorder == 'apptype' %>
<td>Application Type</td>
<% elsif jumpsize.sortorder == 'url' %>
<td>Jump URL</td>
<% else %>
<td>Name</td>
<% end %>

<td><%= link_to 'Edit', edit_jumpsize_path(jumpsize), class: "btn btn-warning btn-xs" %></td>

</tr>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140604185504_add_sort_order_to_jump_sizes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSortOrderToJumpSizes < ActiveRecord::Migration
def change
add_column :jumpsizes, :sortorder, :string
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140104154832) do
ActiveRecord::Schema.define(version: 20140604185504) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -40,6 +40,7 @@
t.datetime "updated_at"
t.string "jumpsizecreator"
t.integer "itemsperpage"
t.string "sortorder"
end

create_table "jumpsquares", force: true do |t|
Expand Down Expand Up @@ -67,6 +68,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.string "nmapxml"
t.string "nmapfilecreator"
end

create_table "roles", force: true do |t|
Expand Down

0 comments on commit 07f2a53

Please sign in to comment.