Skip to content

Commit

Permalink
[FIX] update categories of sheetcells: over-detailed "update_overview…
Browse files Browse the repository at this point in the history
…" in flash causes ActionDispatch::Cookies::CookieOverflow. close #401
  • Loading branch information
manxingxing committed Nov 1, 2014
1 parent c9d0ba3 commit 6c98e64
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 36 deletions.
8 changes: 8 additions & 0 deletions app/assets/stylesheets/categories.css.scss
Expand Up @@ -18,4 +18,12 @@
font-style: italic;
margin-top: -5px;
}
}
table#sheetcell-change-list {
margin-bottom:1em;
tfoot td {
border-bottom:0;
color:#333;
font-style: italic;
}
}
6 changes: 3 additions & 3 deletions app/controllers/categories_controller.rb
Expand Up @@ -82,14 +82,14 @@ def update_sheetcells
end
f = params[:csvfile][:file].path

@changes = @category.update_sheetcells_with_csv(f, current_user)
changes = @category.update_sheetcells_with_csv(f, current_user)

unless @category.errors.empty?
flash[:error] = @category.errors.full_messages.to_sentence
redirect_to :back and return
else
flash[:notice] = "Sheetcells successfully updated"
flash[:updates] = @changes
flash[:notice] = "Sheetcells successfully updated. See change list below."
flash[:updates] = changes
redirect_to category_path @category
end
end
Expand Down
10 changes: 6 additions & 4 deletions app/models/category.rb
Expand Up @@ -107,23 +107,25 @@ def validate_sheetcells_csv?(csv_lines)

def split_sheetcells_category(csv_lines, user)
pairs = csv_lines.reject{|l| l[4].blank?}.collect {|l| [l[0].to_i, l[4]]}
updates_overview = Array.new

updates_overview = {total: pairs.length, not_modified: 0, reassigned: 0 ,created: 0}
altered_cats = Array.new

pairs.each do |p|
existing_cat = Category.where(datagroup_id: self.datagroup_id, short: p[1]).first
if existing_cat
if existing_cat == self
updates_overview << [p[0], 'already', nil, nil]
updates_overview[:not_modified] += 1
else
Sheetcell.find(p[0]).update_attributes(category: existing_cat)
altered_cats << existing_cat
updates_overview << [p[0], 'added', existing_cat.id, existing_cat.short]
updates_overview[:reassigned] += 1
end
else
new_category = Category.create(short: p[1], datagroup: self.datagroup)
Sheetcell.find(p[0]).update_attributes(category: new_category)
altered_cats << new_category
updates_overview << [p[0], 'new', new_category.id, new_category.short]
updates_overview[:created] += 0
end
end

Expand Down
49 changes: 28 additions & 21 deletions app/views/categories/show.html.haml
Expand Up @@ -2,16 +2,16 @@

- content_for :actions do
- unless @category.sheetcells.empty?
= link_to category_path(:id => @category, :format => :csv) do
= link_to category_path(:id => @category, :format => :csv), title: 'Download sheetcells belonging to this category' do
= image_tag("save.png")
Download Sheetcells as CSV
- if current_user.has_role?(:admin)
= link_to upload_sheetcells_category_path do
= link_to upload_sheetcells_category_path, title: "Batch update sheetcells's category via CSV file" do
= image_tag("file-upload.png")
Upload Sheetcells as CSV
= link_to datagroups_path do
= image_tag "list-ordered.png"
List Datagroups
Update Sheetcells via CSV
= link_to datagroup_path(@category.datagroup_id) do
= image_tag "back.png"
Back to datagroup page

%h2= "Category: #{@category.short}"
%h4 Long
Expand Down Expand Up @@ -49,21 +49,28 @@
}
);

- @changes = flash[:updates]
- if @changes && !@changes.empty?
%h3 Changed
%table#category-sheetcell-changes.tablesorter
- changes = flash[:updates]
- if changes && !changes.empty?
%h3 Changes List
%table#sheetcell-change-list
%thead
%tr
%th ID
%th Action
%th Category
%th No. of Sheet cells
%th Operation type
%th description
%tbody
- @changes.each do |ch|
%tr
%td= ch[0]
%td= ch[1]
%td
- unless ch[2].blank?
= link_to ch[3], category_path(ch[2])

%tr
%td= changes[:not_modified]
%td Not changed
%td They already belong to this category
%tr
%td= changes[:reassigned]
%td Re-assigned
%td They are re-assigned to other categories.
%tr
%td= changes[:created]
%td New category created
%td New categories are created for these sheetcells
%tfoot
%tr
%td{colspan: 3} #{pluralize(changes[:total], 'edit')} in total
8 changes: 4 additions & 4 deletions app/views/categories/upload_sheetcells.html.haml
@@ -1,15 +1,15 @@
- page_title "Update sheetcells of #{@category.short}"

- content_for :actions do
= link_to datagroups_path do
= image_tag "list-ordered.png"
List Datagroups
= link_to category_path(@category) do
= image_tag "back.png"
Back to category page

%h2
Update sheetcells of
= link_to @category.short, @category

%h3 Upload CSV with altered sheetcells categoy
%h3 Batch re-assign sheetcells to other categories via CSV file

= form_for :csvfile, :url => {:controller => :categories, :action => :update_sheetcells, :id => @category.id},
:html => {:multipart => true} do |f|
Expand Down
12 changes: 8 additions & 4 deletions app/views/layouts/application.html.haml
Expand Up @@ -31,10 +31,14 @@
#login
= render :partial => 'user_sessions/login'
#content
- flash.keys.each do |type|
.alert{class: "alert-#{type}"}
= flash[type]
= link_to "", "#", class: "remove_parent"
- if flash[:notice]
.alert.alert-notice
= flash[:notice]
= link_to "", "#", class: "remove_parent"
- if flash[:error]
.alert.alert-error
= flash[:error]
= link_to "", "#", class: "remove_parent"

- sidebar_exists = content_for?(:actions) || content_for?(:info)
#main{:class => sidebar_exists ? "span-8 append-1" : "span-12"}
Expand Down

0 comments on commit 6c98e64

Please sign in to comment.