Fixed articles views.

This commit is contained in:
benni 2012-10-19 01:12:47 +02:00
parent fd361090b4
commit f30e57dd49
18 changed files with 159 additions and 153 deletions

View file

@ -33,6 +33,7 @@ gem 'delayed_job_active_record'
gem 'twitter-bootstrap-rails' gem 'twitter-bootstrap-rails'
gem 'simple-navigation' gem 'simple-navigation'
gem 'simple-navigation-bootstrap' gem 'simple-navigation-bootstrap'
gem 'meta_search'
group :production do group :production do
gem 'exception_notification', :require => 'exception_notifier' gem 'exception_notification', :require => 'exception_notifier'

View file

@ -36,7 +36,7 @@ GEM
i18n (~> 0.6) i18n (~> 0.6)
multi_json (~> 1.0) multi_json (~> 1.0)
arel (3.0.2) arel (3.0.2)
builder (3.0.3) builder (3.0.4)
client_side_validations (3.1.4) client_side_validations (3.1.4)
coffee-rails (3.2.2) coffee-rails (3.2.2)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
@ -90,6 +90,11 @@ GEM
i18n (>= 0.4.0) i18n (>= 0.4.0)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
meta_search (1.1.3)
actionpack (~> 3.1)
activerecord (~> 3.1)
activesupport (~> 3.1)
polyamorous (~> 0.5.0)
mime-types (1.19) mime-types (1.19)
multi_json (1.3.6) multi_json (1.3.6)
mysql2 (0.3.11) mysql2 (0.3.11)
@ -97,6 +102,8 @@ GEM
Ascii85 (~> 1.0.0) Ascii85 (~> 1.0.0)
hashery (~> 2.0) hashery (~> 2.0)
ruby-rc4 ruby-rc4
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3) polyglot (0.3.3)
prawn (0.12.0) prawn (0.12.0)
pdf-reader (>= 0.9.0) pdf-reader (>= 0.9.0)
@ -183,6 +190,7 @@ DEPENDENCIES
jquery-rails jquery-rails
kaminari kaminari
localize_input! localize_input!
meta_search
mysql2 mysql2
prawn prawn
rails (= 3.2.8) rails (= 3.2.8)

View file

@ -49,6 +49,14 @@ footer {
} }
table { table {
th.sortdown a:after {
content: ' \25BC';
}
th.sortup a:after {
content: ' \25B2';
}
tr.article-category { tr.article-category {
background-color: #efefef; background-color: #efefef;
td:first-child { td:first-child {

View file

@ -21,10 +21,9 @@ class ArticlesController < ApplicationController
end end
@articles = @supplier.articles.includes(:article_category).order(sort) @articles = @supplier.articles.includes(:article_category).order(sort)
@articles = @articles.where('name LIKE ?', "%#{params[:query]}%") unless params[:query].nil? @articles = @articles.where('articles.name LIKE ?', "%#{params[:query]}%") unless params[:query].nil?
@total = @articles.size @articles = @articles.page(params[:page]).per(@per_page)
@articles = @articles.paginate(:page => params[:page], :per_page => @per_page)
respond_to do |format| respond_to do |format|
format.html format.html
@ -200,7 +199,7 @@ class ArticlesController < ApplicationController
params[:search][:name_contains_all] = params[:search][:name_contains_all].split(' ') if params[:search] params[:search][:name_contains_all] = params[:search][:name_contains_all].split(' ') if params[:search]
# Build search with meta search plugin # Build search with meta search plugin
@search = @supplier.shared_supplier.shared_articles.search(params[:search]) @search = @supplier.shared_supplier.shared_articles.search(params[:search])
@articles = @search.paginate :page => params[:page], :per_page => 10 @articles = @search.page(params[:page]).per(10)
render :layout => false render :layout => false
end end

View file

@ -47,13 +47,13 @@ module ApplicationHelper
end end
def sort_td_class_helper(param) def sort_td_class_helper(param)
result = 'class="sortup"' if params[:sort] == param result = 'sortup' if params[:sort] == param.to_s
result = 'class="sortdown"' if params[:sort] == param + "_reverse" result = 'sortdown' if params[:sort] == param.to_s + "_reverse"
result result
end end
def sort_link_helper(text, key, options = {}) def sort_link_helper(text, key, options = {})
per_page = options[:per_page] || 10 per_page = options[:per_page] || @per_page
remote = options[:remote].nil? ? true : options[:remote] remote = options[:remote].nil? ? true : options[:remote]
key += "_reverse" if params[:sort] == key key += "_reverse" if params[:sort] == key
url = url_for(:sort => key, :page => nil, :per_page => per_page) url = url_for(:sort => key, :page => nil, :per_page => per_page)

View file

@ -11,4 +11,9 @@ module ArticlesHelper
classes += " just_updated" if article.recently_updated && article.availability classes += " just_updated" if article.recently_updated && article.availability
classes classes
end end
# Flatten search params, used in import from external database
def search_params
Hash[params[:search].map { |k,v| [k, (v.is_a?(Array) ? v.join(" ") : v)] }]
end
end end

View file

@ -3,7 +3,7 @@ class SharedArticle < ActiveRecord::Base
# connect to database from sharedLists-Application # connect to database from sharedLists-Application
SharedArticle.establish_connection(FoodsoftConfig[:shared_lists]) SharedArticle.establish_connection(FoodsoftConfig[:shared_lists])
# set correct table_name in external DB # set correct table_name in external DB
set_table_name :articles self.table_name = 'articles'
belongs_to :shared_supplier, :foreign_key => :supplier_id belongs_to :shared_supplier, :foreign_key => :supplier_id

View file

@ -3,8 +3,7 @@ class SharedSupplier < ActiveRecord::Base
# connect to database from sharedLists-Application # connect to database from sharedLists-Application
SharedSupplier.establish_connection(FoodsoftConfig[:shared_lists]) SharedSupplier.establish_connection(FoodsoftConfig[:shared_lists])
# set correct table_name in external DB # set correct table_name in external DB
set_table_name :suppliers self.table_name = 'suppliers'
has_one :supplier has_one :supplier
has_many :shared_articles, :foreign_key => :supplier_id has_many :shared_articles, :foreign_key => :supplier_id

View file

@ -1,28 +1,19 @@
%p - if @supplier.articles.count > 20
Gefundene Artikel: = items_per_page
%b= @total = pagination_links_remote @articles
%p %table#articles_table.table.table-striped
%table{:style => "width:100%"}
%tr
%td
= pagination_links_remote @articles, :params => {:sort => params[:sort]}
%td{:style => "text-align:right"}
- if @total > 30
= items_per_page :per_page_options => [30, 100, 500]
%table#articles_table.list.articles
%thead %thead
%tr %tr
%th %th
%th[sort_td_class_helper("name")] %th{class: sort_td_class_helper(:name)}
= sort_link_helper "Name", "name" = sort_link_helper "Name", "name"
%th %th
%th[sort_td_class_helper("category")] %th{class: sort_td_class_helper(:category)}
= sort_link_helper "Kategorie", "category" = sort_link_helper "Kategorie", "category"
%th[sort_td_class_helper("unit")] %th{class: sort_td_class_helper(:unit)}
= sort_link_helper "Einheit", "unit" = sort_link_helper "Einheit", "unit"
%th[sort_td_class_helper("note")] %th{class: sort_td_class_helper(:note)}
= sort_link_helper "Notiz", "note" = sort_link_helper "Notiz", "note"
%th{:style => "width: 4em;"} Gebgr. %th{:style => "width: 4em;"} Gebgr.
%th{:style => "width: 5em;"} Preis %th{:style => "width: 5em;"} Preis
@ -32,7 +23,7 @@
%tbody#listbody %tbody#listbody
- if @total > 0 - unless @articles.empty?
- for article in @articles - for article in @articles
= render(article) = render(article)
%tfoot %tfoot
@ -46,5 +37,4 @@
%option{:value => "setAvailable"} Artikel sind verfügbar %option{:value => "setAvailable"} Artikel sind verfügbar
= hidden_field_tag 'supplier_id', @supplier.id = hidden_field_tag 'supplier_id', @supplier.id
%p= pagination_links_remote @articles, :params => {:sort => params[:sort]} = pagination_links_remote @articles
= hidden_field_tag :per_page, params[:per_page]

View file

@ -1,4 +1,10 @@
= simple_form_for [@supplier, @article], :validate => true, :remote => true do |f| = simple_form_for [@supplier, @article], :validate => true, :remote => true do |f|
= f.hidden_field :shared_updated_on
= f.hidden_field :supplier_id
.modal-header
= button_tag "x", class: 'close', data: {dismiss: 'modal'}
%h3 Neuen Artikel einfügen
.modal-body
= f.input :availability = f.input :availability
= f.input :name = f.input :name
= f.input :origin = f.input :origin
@ -12,7 +18,7 @@
= f.input :order_number = f.input :order_number
= f.input :tax = f.input :tax
= f.input :deposit = f.input :deposit
= f.submit .modal-footer
= button_tag "Schließen", class: 'btn', data: {dismiss: 'modal'}
= f.submit class: 'btn btn-primary'
= f.hidden_field :shared_updated_on
= f.hidden_field :supplier_id

View file

@ -1,5 +1,8 @@
%p= pagination_links_remote @articles, :per_page => 10, :params => {:search => params[:search]} - if @articles.empty?
%table.list %p Keine Artikel gefunden
- else
= pagination_links_remote @articles, :params => {:search => search_params}
%table.table.table-striped
%thead %thead
%tr %tr
%th Name %th Name
@ -12,7 +15,7 @@
%th %th
%tbody %tbody
- for article in @articles - for article in @articles
%tr{:class => cycle('even','odd', :name => 'import_search_results')} %tr
%td= highlight article.name, params[:search][:name_contains_all] %td= highlight article.name, params[:search][:name_contains_all]
%td= article.origin %td= article.origin
%td= article.manufacturer %td= article.manufacturer
@ -20,6 +23,11 @@
%td= number_to_currency(article.price) %td= number_to_currency(article.price)
%td= article.unit %td= article.unit
%td= article.unit_quantity %td= article.unit_quantity
%td= link_to 'importieren', import_supplier_articles_path(@supplier, :shared_article_id => article.id), %td
:remote => true - logger.debug "[debug] #{article.attributes.inspect}"
- if @supplier.articles.where(order_number: article.number).exists?
%i.icon-ok
schon importiert
- else
= link_to 'importieren', import_supplier_articles_path(@supplier, :shared_article_id => article.id),
:remote => true, class: 'btn btn-small btn-success'

View file

@ -1,2 +1,2 @@
$('#modalContainer').modal('hide');
$('#listbody').prepend('#{escape_javascript(render(@article))}'); $('#listbody').prepend('#{escape_javascript(render(@article))}');
$.fancybox.close();

View file

@ -1,66 +1,48 @@
- title "Artikel von #{@supplier.name}" - title "Artikel von #{@supplier.name} (#{@supplier.articles.count})"
.well.well-small
.btn-toolbar
= form_tag supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search pull-right',
'data-submit-onchange' => true do
= text_field_tag :query, params[:query], class: 'input-medium search-query',
placeholder: 'Name ...'
.btn-group
= link_to "Neuer Artikel", new_supplier_article_path(@supplier), remote: true, class: 'btn btn-primary'
= link_to "Alle bearbeiten", edit_all_supplier_articles_path(@supplier), class: 'btn'
= link_to "Artikel hochladen", upload_supplier_articles_path(@supplier), class: 'btn'
- if current_user.role_orders?
= link_to "Bestellung anlegen", new_order_path(supplier_id: @supplier), class: 'btn'
// import menu
- unless @supplier.shared_supplier.nil? - unless @supplier.shared_supplier.nil?
.menu{:style => 'width: 16em'} .btn-group
%ul = link_to '#', data: {toggle: 'dropdown'}, class: 'btn btn-success dropdown-toggle' do
%li Externe Datenbank
Zugriff auf externe Datenbank %span.caret
%ul %ul.dropdown-menu
%li= link_to "Suchen/Importieren", "#import", 'data-toggle-this' => '#import' %li= link_to "Suchen/Importieren", "#import", 'data-toggle-this' => '#import'
%li= link_to "Synchronisieren", sync_supplier_articles_path(@supplier), :method => :post %li= link_to "Synchronisieren", sync_supplier_articles_path(@supplier), method: :post
.btn-group
#change_supplier{:style => "padding:0 0 0.5em 0.7em;"} = link_to '#', data: {toggle: 'dropdown'}, class: 'btn dropdown-toggle' do
%span{:style => "float:left"} Lieferant wechseln ..
Lieferantin wechseln: %span.caret
= select_tag :switch_supplier, %ul.dropdown-menu
options_for_select(Supplier.order(:name).map {|s| [s.name, supplier_articles_url(s)] }, supplier_articles_url(@supplier)), - Supplier.where('id != ?', @supplier.id).order('name ASC').each do |supplier|
:style => "font-size: 0.9em;margin-left:1em;", %li= link_to supplier.name, supplier_articles_path(supplier), tabindex: -1
'data-redirect-to' => true
- unless @supplier.shared_supplier.nil? - unless @supplier.shared_supplier.nil?
#import.single_column{:style => "display:none; clear:both"} #import.well.well-small(style="display:none;")
.box_title = form_tag shared_supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search',
%h2 Artikel importieren 'data-submit-onchange' => true do
.column_content %h3 Artikel importieren
#search{:style => "padding-bottom:3em"} = text_field_tag "search[name_contains_all]", "", class: 'input-medium search-query', placeholder: 'Name ...'
= form_tag shared_supplier_articles_path(@supplier), :method => :get, :remote => true do %label.checkbox
= text_field_tag "search[name_contains_all]", "", :size => 10
= submit_tag "Suchen"
- if @supplier.shared_supplier.lists
Suche in folgenden Listen:
- @supplier.shared_supplier.lists.each do |token, name|
= check_box_tag "search[list_equals_any][]", token, true
= name
|
Nur aus der Region:
= check_box_tag "search[origin_equals]", "REG", false = check_box_tag "search[origin_equals]", "REG", false
#search_results Nur aus der Region
#search_results.clearfix
= link_to "Schließen", "#import", 'data-toggle-this' => '#import' = link_to "Schließen", "#import", 'data-toggle-this' => '#import'
.single_column{:style => 'width:100%; clear:both'} = form_tag update_selected_supplier_articles_path(@supplier), id: "articlesInListForm",
.box_title
.column_content
#links
%b= link_to "Neuer Artikel", new_supplier_article_path(@supplier), :remote => true
|
= link_to "Alle bearbeiten", edit_all_supplier_articles_path(@supplier)
|
= link_to "Artikel hochladen", upload_supplier_articles_path(@supplier)
- if current_user.role_orders?
|
= link_to "Bestellung anlegen", new_order_path(:supplier_id => @supplier)
#article_filter
#article_search_form{:style=>"display:inline;"}
= form_tag supplier_articles_path(@supplier), :method => :get, :remote => true, 'data-submit-onchange' => true do
%label{:for => 'article_name'} Suche im Artikelnamen:
= text_field_tag :query, params[:query], :size => 10
= submit_tag "Suchen"
= form_tag update_selected_supplier_articles_path(@supplier), :id => "articlesInListForm",
'data-submit-onchange' => true do 'data-submit-onchange' => true do
#table= render 'articles' #table= render 'articles'
#edit_article{:style => "display:none"}

View file

@ -1 +1,2 @@
$.fancybox('#{escape_javascript(render("form"))}'); $('#modalContainer').html('#{escape_javascript(render("form"))}');
$('#modalContainer').modal();

View file

@ -1,4 +1,3 @@
#modalForm.modal(tabindex="-1" role="dialog")
= simple_form_for @invite, remote: true do |form| = simple_form_for @invite, remote: true do |form|
.modal-header .modal-header
= button_tag "x", class: 'close', data: {dismiss: 'modal'} = button_tag "x", class: 'close', data: {dismiss: 'modal'}

View file

@ -33,4 +33,4 @@
%footer %footer
%p %p
Foodsoft, open source software to manage a non-profit food coop. Foodsoft, open source software to manage a non-profit food coop.
#modalContainer #modalContainer.modal(tabindex="-1" role="dialog" style="display:none")

View file

@ -2,10 +2,10 @@
%table.table.table-striped %table.table.table-striped
%thead %thead
%tr %tr
%th[sort_td_class_helper("supplier")] %th{class: sort_td_class_helper(:supplier)}
= sort_link_helper "Lieferantin", "supplier" = sort_link_helper "Lieferantin", "supplier"
%th Start %th Start
%th[sort_td_class_helper("ends")] %th{class: sort_td_class_helper(:ends)}
= sort_link_helper "Ende", "ends" = sort_link_helper "Ende", "ends"
%th Status %th Status
%th{:colspan => "2"} %th{:colspan => "2"}