Skip to content

Commit

Permalink
export list of datagroups in format of XML. #330
Browse files Browse the repository at this point in the history
  • Loading branch information
manxingxing committed Sep 12, 2013
1 parent 8ec22ee commit caebebc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
12 changes: 8 additions & 4 deletions app/controllers/datagroups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ class DatagroupsController < ApplicationController
end

def index
validate_sort_params(collection: ['id', 'title', 'datacolumns_count'], default: 'title')
@datagroups = Datagroup.select('id, title, description, created_at, datacolumns_count')
.search(params[:search])
.paginate(page: params[:page], per_page: 100, order: "#{params[:sort]} #{params[:direction]}")
validate_sort_params(collection: ['id', 'title', 'datacolumns_count', 'categories_count'], default: 'title')
dgs = Datagroup.select('id, title, description, created_at, datacolumns_count,
(select count(*) from categories where datagroup_id = datagroups.id) as categories_count')
.order("#{params[:sort]} #{params[:direction]}").search(params[:search])
respond_to do |format|
format.html { @datagroups = dgs.paginate(page: params[:page], per_page: 100) }
format.xml { @datagroups = dgs}
end
end

def show
Expand Down
6 changes: 4 additions & 2 deletions app/helpers/datagroups_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def dropdown_list_to_sort_datagroups
"Title" => datagroups_path(params.merge(sort: 'title', direction: 'asc')),
"Recently Added" => datagroups_path(params.merge(sort: 'id', direction: 'desc')),
"Most used" => datagroups_path(params.merge(sort: 'datacolumns_count', direction: 'desc')),
"Least Used" => datagroups_path(params.merge(sort: 'datacolumns_count', direction: 'asc'))
}, selected: datagroups_path(params))
"Least Used" => datagroups_path(params.merge(sort: 'datacolumns_count', direction: 'asc')),
"Most categories" => datagroups_path(params.merge(sort: 'categories_count', direction: 'desc')),
"Least categories" => datagroups_path(params.merge(sort: 'categories_count', direction: 'asc'))
}, selected: datagroups_path(params))
end
end
3 changes: 2 additions & 1 deletion app/views/datagroups/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
.description
= highlight dg.description, params[:search]
.comment
= pluralize(dg.categories_count, 'category')
|
= pluralize(dg.datacolumns_count, 'datacolumn')
in this datagroup
.right
Added at #{dg.created_at}
- if authorized_to_edit_and_delete
Expand Down
12 changes: 12 additions & 0 deletions app/views/datagroups/index.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
xml.instruct!
xml.datagroups {
@datagroups.each do |dg|
xml.datagroup(id: dg.id) {
xml.id dg.id
xml.title dg.title
xml.description dg.description
xml.columns_count dg.datacolumns_count
xml.categories_count dg.categories_count
}
end
}

0 comments on commit caebebc

Please sign in to comment.