From 73e075fc64cc6e5c922c4bc7eb0500f54d943c8a Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 19 Feb 2013 19:25:46 +0100 Subject: [PATCH] Fixes for displaying categories --- Gemfile.lock | 4 ++-- app/controllers/suppliers/products_controller.rb | 2 +- app/decorators/product_decorator.rb | 9 ++++++++- app/models/supplier.rb | 2 +- app/views/supplier/edit.html.slim | 2 +- app/views/suppliers/product_categories/_form.html.slim | 4 ++-- app/views/suppliers/product_categories/show.html.slim | 2 +- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 707ccfbe..a0fa01d8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -126,7 +126,7 @@ GEM jquery-rails (2.2.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - json (1.6.8) + json (1.6.7) kaminari (0.14.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -147,7 +147,7 @@ GEM mime-types (1.21) mini_magick (3.5.0) subexec (~> 0.2.1) - multi_json (1.6.1) + multi_json (1.5.0) mustache (0.99.4) nokogiri (1.5.6) orm_adapter (0.0.7) diff --git a/app/controllers/suppliers/products_controller.rb b/app/controllers/suppliers/products_controller.rb index 574f68e5..9ee00c65 100644 --- a/app/controllers/suppliers/products_controller.rb +++ b/app/controllers/suppliers/products_controller.rb @@ -4,7 +4,7 @@ module Suppliers # GET /products # GET /products.json def index - @products = ProductDecorator.decorate(current_supplier.products) + @products = ProductDecorator.decorate_collection(current_supplier.products) respond_to do |format| format.html # index.html.erb diff --git a/app/decorators/product_decorator.rb b/app/decorators/product_decorator.rb index 97484ba9..fc5bb936 100644 --- a/app/decorators/product_decorator.rb +++ b/app/decorators/product_decorator.rb @@ -1,5 +1,6 @@ -class ProductDecorator < Draper::Base +class ProductDecorator < Draper::Decorator decorates :product + delegate_all def category_links(options = {}) if namespace = options[:namespace] @@ -9,6 +10,12 @@ class ProductDecorator < Draper::Base end end + def display + + "#{model.name} (#{h.currency(model.price)})".html_safe + + end + # Accessing Helpers # You can access any helper via a proxy # diff --git a/app/models/supplier.rb b/app/models/supplier.rb index d6c23987..96ce1be7 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -7,7 +7,7 @@ class Supplier property :name property :open, type: :boolean, default: false property :time_zone, default: 'UTC' - property :night_offset, type: Float + property :night_offset, type: Fixnum, default: 0 # Hours #LOCATION property :lat, type: Float, default: 52.08062426379751 diff --git a/app/views/supplier/edit.html.slim b/app/views/supplier/edit.html.slim index 2d73edaa..7d05bd62 100644 --- a/app/views/supplier/edit.html.slim +++ b/app/views/supplier/edit.html.slim @@ -1,4 +1,4 @@ -- content_for :head do +/- content_for :head do = javascript_include_tag 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false' = form_for @supplier, url: supplier_update_settings_path, html: {class: 'form-horizontal'} do |f| diff --git a/app/views/suppliers/product_categories/_form.html.slim b/app/views/suppliers/product_categories/_form.html.slim index 2b0d5a79..bf5059ed 100644 --- a/app/views/suppliers/product_categories/_form.html.slim +++ b/app/views/suppliers/product_categories/_form.html.slim @@ -5,9 +5,9 @@ = hidden_field_tag 'product_category[product_ids][]', '' = label_tag nil, Product.model_name.human_plural, class: 'control-label' .controls - - for product in current_supplier.products + - for product in ProductDecorator.decorate_collection(current_supplier.products) = check_box_tag "product_category[product_ids][]", product.id, @product_category.product_ids.to_a.include?(product.id), id: "product-checker-#{product.id}" - = label_tag "product-checker-#{product.id}", product.name + = label_tag "product-checker-#{product.id}", product.display br .control-group #week_days-group.btn-group data-toggle="buttons-checkbox" diff --git a/app/views/suppliers/product_categories/show.html.slim b/app/views/suppliers/product_categories/show.html.slim index cc7b1201..211f71ee 100644 --- a/app/views/suppliers/product_categories/show.html.slim +++ b/app/views/suppliers/product_categories/show.html.slim @@ -14,5 +14,5 @@ dl.dl-horizontal.show-list ' = link_to t("helpers.links.destroy"), [:suppliers, @product_category], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger' - content_for :row do - - @products = ProductDecorator.decorate(@product_category.products) + - @products = ProductDecorator.decorate_collection(@product_category.products) = render template: 'suppliers/products/index'