Skip to content

Commit

Permalink
Merge branch 'develop' into feature-commendation
Browse files Browse the repository at this point in the history
Conflicts:
	app/views/articles/show/_commendation.html.slim
  • Loading branch information
Marc Altmann committed Oct 27, 2014
2 parents 5c70a71 + 3f844b5 commit 58b3c08
Show file tree
Hide file tree
Showing 20 changed files with 180 additions and 102 deletions.
6 changes: 5 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ApplicationController < ActionController::Base
after_filter :store_location

protect_from_forgery
skip_before_action :verify_authenticity_token, if: :json_request?

helper :all

Expand All @@ -54,9 +55,12 @@ def after_sign_in_path_for resource_or_scope
end
end

protected

protected

def json_request?
request.format.json?
end

# Pundit checker

Expand Down
18 changes: 7 additions & 11 deletions app/controllers/bank_details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ def check
end
end

def check_iban
@result = KontoAPI::valid?( iban: params[:iban] )
respond_to do |format|
format.json { render json: @result.to_json }
end
end

def check_bic
@result = KontoAPI::valid?( bic: params[:bic] )
respond_to do |format|
format.json { render json: @result.to_json }
# Check IBAN and BIC
[:iban, :bic].each do |value|
define_method("check_#{ value }") do
@result = KontoAPI::valid?( value => params[value] )
respond_to do |format|
format.json { render json: @result.to_json }
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/line_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#
class LineItemsController < ApplicationController
respond_to :html
respond_to :json, only: [:create]
responders :location

skip_before_filter :authenticate_user!, only: [:create, :update, :destroy]
Expand All @@ -40,7 +41,7 @@ def create
flash[:error] = I18n.t('line_item.notices.error_quantity')
end

redirect_to @line_item.article
respond_with @line_item.article
end

def update
Expand Down
21 changes: 8 additions & 13 deletions app/models/mass_upload/fees_and_donations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,17 @@
module MassUpload::FeesAndDonations
extend ActiveSupport::Concern

def self.calculate_total_fees(articles)
total_fee = Money.new(0)
articles.each do |article|
total_fee += article.calculated_fee * article.quantity
# method for calculation of fee or fair percent
[:fees, :fair].each do |type|
define_singleton_method("calculate_total_#{type}") do |articles|
total = Money.new(0)
articles.each do |article|
total += article.send("calculated_#{type.to_s.singularize}") * article.quantity
end
total
end
total_fee
end

def self.calculate_total_fair(articles)
total_fair = Money.new(0)
articles.each do |article|
total_fair += article.calculated_fair * article.quantity
end
total_fair
end

def self.calculate_total_fees_and_donations(articles)
self.calculate_total_fees(articles) + self.calculate_total_fair(articles)
end
Expand Down
39 changes: 4 additions & 35 deletions app/views/articles/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,13 @@ json.articles @articles do |article|
json.html_url article_url(article)
json.title article.title
json.price_cents(article.price.is_a?(Money) ? article.price_cents : article.price)
if article.belongs_to_legal_entity?
json.vat article.vat if article.vat != 0
if show_basic_price_for? article
json.basic_price_cents (article.basic_price.is_a?(Money) ? article.basic_price_cents : article.basic_price)
json.basic_price_amount article.basic_price_amount
end
end
json.tags do
json.condition article.condition
json.fair article.fair
json.ecologic article.ecologic
json.small_and_precious article.small_and_precious
json.borrowable article.borrowable
json.swappable article.swappable
end
json.partial! 'articles/show/legal_entity', article: article
json.partial! 'articles/show/tags', article: article

json.seller do
json.nickname article.seller_nickname
json.legal_entity article.belongs_to_legal_entity?
json.html_url user_url(article.seller)
end
json.donation do
if article.seller_ngo
json.percent 100
json.organization do
json.name article.seller_nickname
json.id article.seller
json.html_url user_url(article.seller)
end
elsif show_friendly_percent_for? article
json.percent article.friendly_percent
json.organization do
json.name article.friendly_percent_organisation_nickname
json.id article.friendly_percent_organisation_id
json.html_url user_url(article.friendly_percent_organisation)
end
else
json.nil!
end
end

json.partial! 'articles/show/donation', article: article
end
51 changes: 51 additions & 0 deletions app/views/articles/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
json.(@article,:id,:slug,:title,:price_cents,:quantity_available)
json.partial! 'articles/show/legal_entity', article: @article
json.partial! 'articles/show/tags', article: @article
json.partial! 'articles/show/donation', article: @article
json.categories resource.categories.each do |leaf|
json.name leaf.name
json.ancestors leaf.ancestors.map(&:name)
end
if @article.title_image
json.title_image do
json.thumb_url asset_url(@article.title_image.image.url :thumb)
json.original_url asset_url(@article.title_image.image.url :original)
end
end
if show_fair_percent_for? @article
json.fair_percent_html t('article.show.donate_html')
end

json.thumbnails @article.thumbnails do |thumbnail|
json.thumb_url asset_url(thumbnail.image.url :thumb)
json.original_url asset_url(thumbnail.image.url :original)
end
json.seller do
json.type @article.seller.type.underscore
if @article.seller.is_a?(LegalEntity) && @article.seller.ngo
json.type_name t('users.legal_status.show.ngo')
elsif @article.seller.is_a? LegalEntity
json.type_name t('users.legal_status.show.legal_entity')
else
json.type_name t('users.legal_status.show.private_user')
end
json.ngo @article.seller.ngo
json.name @article.seller.name
json.vacationing @article.seller.vacationing?
json.image_url @article.user.image_url(:profile)
json.html_url user_url(@article.seller)
json.ratings do
json.url user_ratings_url(@article.seller)
json.count @article.seller.ratings.count
json.positive_percent @article.seller.percentage_of_positive_ratings
json.neutral_percent @article.seller.percentage_of_neutral_ratings
json.negative_percent @article.seller.percentage_of_negative_ratings
end
json.terms @article.seller.terms
json.cancellation @article.seller.cancellation
end
json.content @article.content
json.payment_html render(partial: '/articles/show/payment', formats: [:html])
json.transport_html render(partial: '/articles/show/transport', formats: [:html])
json.commendation_html render(partial: '/articles/show/commendation', formats: [:html], locals: {commendation_link: url_for(controller: 'contents', action: 'show', id: 'faq', anchor: 'f1', only_path: false)})
json.html_url article_url(@article)
20 changes: 2 additions & 18 deletions app/views/articles/show/_article_contents.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,9 @@
= resource.condition_extra_text

= accordion_item "payment" do
= render "/articles/show/payment"

h4
= t('formtastic.labels.article.payment_methods')+':'
ul
= payment_format_for "bank_transfer"
= payment_format_for "cash"
= payment_format_for "paypal"
= payment_format_for "cash_on_delivery"
= payment_format_for "invoice"

= simple_format(resource.payment_details).html_safe
h4
= t('formtastic.labels.article.transport_method') + ':'
ul
= transport_format_for "pickup"
= transport_format_for "type1"
= transport_format_for "type2"

= simple_format(resource.transport_details).html_safe
= render "/articles/show/transport"

- if resource.has_commendation?
= accordion_item "commendation" do
Expand Down
8 changes: 4 additions & 4 deletions app/views/articles/show/_commendation.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
/ You should have received a copy of the GNU Affero General Public License
/ along with Fairmondo. If not, see <http://www.gnu.org/licenses/>.
/
- commendation_link = nil unless local_assigns.has_key? :commendation_link

/ Be careful, between case and when should not be a empty line
.commendation
/ Fair
- if resource.fair
h3= render 'articles/show/commendation_label', label: :fair, size: :big
h3= render 'articles/show/commendation_label', label: :fair, size: :big, link: commendation_link
- case resource.fair_kind
- when 'social_producer'
- if resource.social_producer_questionnaire
Expand All @@ -51,7 +51,7 @@

/ Ecologic
- if resource.ecologic
h3= render 'articles/show/commendation_label', label: :ecologic, size: :big
h3= render 'articles/show/commendation_label', label: :ecologic, size: :big, link: commendation_link
h4= t('enumerize.article.ecologic_kind.' + resource.ecologic_kind)
- if resource.ecologic_kind == 'ecologic_seal'
p= t('enumerize.article.ecologic_seal.' + resource.ecologic_seal)
Expand All @@ -60,7 +60,7 @@

/ Small and precious
- if resource.small_and_precious
h3= render 'articles/show/commendation_label', label: :small_and_precious, size: :big
h3= render 'articles/show/commendation_label', label: :small_and_precious, size: :big, link: commendation_link
h4= t('formtastic.labels.article.small_and_precious_eu_small_enterprise')
p= resource.small_and_precious_eu_small_enterprise ? t('article.show.agree') : t('article.show.non_agree')
h4= t('formtastic.labels.article.small_and_precious_reason')
Expand Down
19 changes: 19 additions & 0 deletions app/views/articles/show/_donation.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
json.donation do
if article.seller_ngo
json.percent 100
json.organization do
json.name article.seller_nickname
json.id article.seller
json.html_url user_url(article.seller)
end
elsif show_friendly_percent_for? article
json.percent article.friendly_percent
json.organization do
json.name article.friendly_percent_organisation_nickname
json.id article.friendly_percent_organisation_id
json.html_url user_url(article.friendly_percent_organisation)
end
else
json.nil!
end
end
7 changes: 7 additions & 0 deletions app/views/articles/show/_legal_entity.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if article.belongs_to_legal_entity?
json.vat article.vat if article.vat != 0
if show_basic_price_for? article
json.basic_price_cents (article.basic_price.is_a?(Money) ? article.basic_price_cents : article.basic_price)
json.basic_price_amount article.basic_price_amount
end
end
10 changes: 10 additions & 0 deletions app/views/articles/show/_payment.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
h4
= t('formtastic.labels.article.payment_methods')+':'
ul
= payment_format_for "bank_transfer"
= payment_format_for "cash"
= payment_format_for "paypal"
= payment_format_for "cash_on_delivery"
= payment_format_for "invoice"

= simple_format(resource.payment_details).html_safe
8 changes: 8 additions & 0 deletions app/views/articles/show/_tags.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
json.tags do
json.condition article.condition
json.fair article.fair
json.ecologic article.ecologic
json.small_and_precious article.small_and_precious
json.borrowable article.borrowable
json.swappable article.swappable
end
8 changes: 8 additions & 0 deletions app/views/articles/show/_transport.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
h4
= t('formtastic.labels.article.transport_method') + ':'
ul
= transport_format_for "pickup"
= transport_format_for "type1"
= transport_format_for "type2"

= simple_format(resource.transport_details).html_safe
4 changes: 3 additions & 1 deletion app/views/layouts/partials/_header_nav.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
= link_to t('header.community.title'), 'https://info.fairmondo.de/forum/', target: '_blank', class: 'JS-active-toggle--trigger JS-active-toggle--target'
ul.l-header-nav-dropdown.JS-active-toggle--target
li= link_to t('header.community.coop'), '/genossenschaft/'
li= link_to t('header.community.active'), 'http://mithelfen.fairmondo.de', target: '_blank'
li= link_to t('header.community.active'), 'http://mitmachen.fairmondo.de', target: '_blank'
li= link_to t('header.community.forum'), 'https://info.fairmondo.de/forum/', target: '_blank'
li= link_to t('header.community.facebook'), 'https://www.facebook.com/fairmondo', target: '_blank'
li= link_to t('header.community.developer'), 'https://github.com/fairmondo/fairmondo', target: '_blank'
li= link_to t('header.community.events'), 'http://mitmachen.fairmondo.de/veranstaltungen', target: '_blank'
li= link_to t('header.community.partner'), 'http://mitmachen.fairmondo.de/materialecke/partnerprogramm/', target: '_blank'
li= link_to t('header.community.godfather'), '/warum/'

- if user_signed_in?
li= link_to t('header.profile'), user_path(current_user), data: navigation_push
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
= image_tag(business_transaction.article.title_image_url_thumb)
.Payment-article-title
= business_transaction_listing[:quantity].to_s + 'x'
= business_transaction.article_title
=< business_transaction.article_title
.Payment-value.Payment-value--prices

.Payment-value-info.Payment-value-info--left
= business_transaction_listing[:quantity].to_s + 'x'
= money(business_transaction.article_price) + ' ='
=< money(business_transaction.article_price) + ' ='
= money( business_transaction_listing[:retail_price] )

.Payment-value-info.Payment-value-info--right
= t('cart.texts.net')
= money business_transaction_listing[:net_price]
=< money business_transaction_listing[:net_price]
- if business_transaction.article_basic_price_amount
br
= money business_transaction.article_basic_price
Expand Down
7 changes: 7 additions & 0 deletions app/views/line_items/create.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if @line_item.errors.any?
json.error I18n.t('line_item.notices.error_quantity')
else
json.cart_id @cart.id
json.cart_url cart_url(@cart)
json.line_item @line_item
end
2 changes: 2 additions & 0 deletions config/locales/header.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ de:
facebook: 'Wir auf Facebook'
developer: 'Aktiv als Entwickler*in'
events: 'Veranstaltungen'
partner: 'Partnerprogramm'
godfather: 'Namenspat*innen'
profile: "Profil"
sell: "Verkaufen"
cart:
Expand Down
Loading

0 comments on commit 58b3c08

Please sign in to comment.