From 8c9698630954e7d8ab8b0c391ef8048ee0c297ea Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Thu, 23 May 2019 20:59:03 +0200 Subject: [PATCH] suite --- Gemfile | 2 ++ Gemfile.lock | 3 +++ app/controllers/public/products_controller.rb | 8 ++++++++ app/models/abonnement.rb | 2 +- app/models/reseaux.rb | 1 + app/views/admin/reseauxes/_form.html.haml | 1 + app/views/layouts/admin.html.haml | 2 +- app/views/public/abonnements/new.html.haml | 9 +++++++-- app/views/public/needs/index.html.haml | 3 ++- app/views/public/products/index.html.haml | 2 +- app/views/public/products/show.html.haml | 2 +- app/views/public/shared/_sub_menu.html.haml | 5 +++-- db/migrate/20190523185031_add_menu_item_to_reseauxes.rb | 5 +++++ db/schema.rb | 4 +++- 14 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20190523185031_add_menu_item_to_reseauxes.rb diff --git a/Gemfile b/Gemfile index 7294750..b267e9a 100755 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,8 @@ gem 'bcrypt', '~> 3.1.7' gem 'unicorn' +gem 'rails_autolink' + gem 'haml-rails' gem "therubyracer", group: :production diff --git a/Gemfile.lock b/Gemfile.lock index 9e5e5c7..bf455f9 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -164,6 +164,8 @@ GEM rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) + rails_autolink (1.1.6) + rails (> 3.1) railties (4.2.6) actionpack (= 4.2.6) activesupport (= 4.2.6) @@ -272,6 +274,7 @@ DEPENDENCIES paranoia (~> 2.0) posix-spawn rails (= 4.2.6) + rails_autolink rmagick rubyzip (>= 1.0.0) rvm-capistrano (= 1.4.1) diff --git a/app/controllers/public/products_controller.rb b/app/controllers/public/products_controller.rb index 153668b..e633d03 100755 --- a/app/controllers/public/products_controller.rb +++ b/app/controllers/public/products_controller.rb @@ -6,7 +6,14 @@ class Public::ProductsController < ApplicationController layout "public" def show + @product = Product.not_archived.find(params[:id]) + + if @product.orderable + params[:type] = "2" + else + params[:type] = "1" + end @product_lang = @product.lang(I18n.locale) @product_category = @product.product_category @image_bandeau = @product.product_category.image_file.file.url if @product.product_category and @product.product_category.image_file @@ -19,6 +26,7 @@ class Public::ProductsController < ApplicationController def index + params[:type] = params[:type] || "1" @products = true @reseaux = current_customer.reseauxes.find(params[:reseaux_id]) @reseaux_layout = true diff --git a/app/models/abonnement.rb b/app/models/abonnement.rb index ad7ee54..4abc530 100644 --- a/app/models/abonnement.rb +++ b/app/models/abonnement.rb @@ -1,5 +1,5 @@ class Abonnement < ActiveRecord::Base - + belongs_to :reseaux has_many :payments, :as => :element def after_paid diff --git a/app/models/reseaux.rb b/app/models/reseaux.rb index dbd1d9a..9a72fc3 100644 --- a/app/models/reseaux.rb +++ b/app/models/reseaux.rb @@ -12,6 +12,7 @@ class Reseaux < ActiveRecord::Base has_many :offer_reseauxes, :dependent => :destroy has_many :offers, :through => :offer_reseauxes + belongs_to :menu_item has_many :thing_conversations, :as => :thing, :dependent => :destroy diff --git a/app/views/admin/reseauxes/_form.html.haml b/app/views/admin/reseauxes/_form.html.haml index fd4237f..bda0ae6 100755 --- a/app/views/admin/reseauxes/_form.html.haml +++ b/app/views/admin/reseauxes/_form.html.haml @@ -20,6 +20,7 @@ =f.input :abo_needed, :label => "Abonnement nécessaire ?" =f.input :abo_price, :label => "Prix de l'abonnement ?" + =f.input :menu_item_id, :label => "Page statique de présentation de l'abonnement :", :collection => MenuItem.all, :include_blank => true, :as => :select =f.input :needs_enabled, :label => "Besoins spécifiques activées ?" diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index c12b3a7..1731db6 100755 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -71,7 +71,7 @@ %li= link_to "Fournisseurs", admin_fournisseurs_path %li= link_to "Type de documents", admin_product_order_document_types_path %li=# link_to "Codes de reduction", admin_vourcher_codes_path - + %li=link_to "Pages statiques", admin_menu_items_path(:menu_id => 1) %ul.nav.navbar-nav.navbar-right %li.dropdown diff --git a/app/views/public/abonnements/new.html.haml b/app/views/public/abonnements/new.html.haml index 1ddd044..9dbbf1b 100644 --- a/app/views/public/abonnements/new.html.haml +++ b/app/views/public/abonnements/new.html.haml @@ -1,5 +1,10 @@ - --@menu_item = MenuItem.where(:slug => "negos-a-propos").first +-if @reseaux + -if @reseaux.menu_item + -@menu_item = @reseaux.menu_item + -else + -@menu_item = MenuItem.where(:slug => "negos-a-propos").first +-else + -@menu_item = MenuItem.where(:slug => "negos-a-propos").first -if @menu_item .page.center{:style => "padding-bottom:40px;"} diff --git a/app/views/public/needs/index.html.haml b/app/views/public/needs/index.html.haml index 09c32db..12a7e25 100755 --- a/app/views/public/needs/index.html.haml +++ b/app/views/public/needs/index.html.haml @@ -1,6 +1,7 @@ .center.row.need-container - + .intro=raw @reseaux.description + .row.col-md-9.gutter =render collection: @needs, partial: 'need_item', as: :need diff --git a/app/views/public/products/index.html.haml b/app/views/public/products/index.html.haml index caafaee..a1cb412 100644 --- a/app/views/public/products/index.html.haml +++ b/app/views/public/products/index.html.haml @@ -8,6 +8,6 @@ %h1 Produits exclusifs réservés à ce réseau .boutique_body.products - =render Product.where(:archived => false, :reseaux_id => @reseaux.id).all + =render Product.where(:archived => false, :reseaux_id => @reseaux.id, :orderable => (params[:type] == "1" ? false : true )).all \ No newline at end of file diff --git a/app/views/public/products/show.html.haml b/app/views/public/products/show.html.haml index 0131bce..53ec4cd 100755 --- a/app/views/public/products/show.html.haml +++ b/app/views/public/products/show.html.haml @@ -16,7 +16,7 @@ .col_description .product_description %h1= @product_lang.title - =simple_format @product_lang.description + =auto_link(simple_format(@product_lang.description), :html => { :target => '_blank' }) -nbr_products = ProductOrderProduct.joins(:product_order).where(:product_orders => {:completed_finish => true},:product_id => @product.id).sum("product_order_products.qty") diff --git a/app/views/public/shared/_sub_menu.html.haml b/app/views/public/shared/_sub_menu.html.haml index c1643a0..b4702d8 100644 --- a/app/views/public/shared/_sub_menu.html.haml +++ b/app/views/public/shared/_sub_menu.html.haml @@ -6,11 +6,12 @@ -if @reseaux and @reseaux.needs_enabled =link_to "Besoins exclusifs", public_needs_path(:type => 1), :class => ("active" if @needs and params[:type].to_i == 1) -if @reseaux and @reseaux.centrale_enabled - =link_to "Portail local", public_needs_path(:type => 2), :class => ("active" if @needs and params[:type].to_i == 2) + =link_to "Portail local", public_reseaux_products_path(:reseaux_id => session[:reseaux_id].to_i, :type => 2), :class => ("active" if (@products or @product) and params[:type] == "2") + -if session[:reseaux_id].to_i > 0 -if @reseaux and @reseaux.offres_enabled - =link_to "Offres exclusives", public_reseaux_products_path(:reseaux_id => session[:reseaux_id].to_i), :class => ("active" if @products or @product) + =link_to "Offres exclusives", public_reseaux_products_path(:reseaux_id => session[:reseaux_id].to_i), :class => ("active" if ((@products or @product) and params[:type] == "1")) .clear diff --git a/db/migrate/20190523185031_add_menu_item_to_reseauxes.rb b/db/migrate/20190523185031_add_menu_item_to_reseauxes.rb new file mode 100644 index 0000000..6820aef --- /dev/null +++ b/db/migrate/20190523185031_add_menu_item_to_reseauxes.rb @@ -0,0 +1,5 @@ +class AddMenuItemToReseauxes < ActiveRecord::Migration + def change + add_column :reseauxes, :menu_item_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 53568de..406df5e 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20181017211545) do +ActiveRecord::Schema.define(version: 20190523185031) do create_table "abonnements", force: :cascade do |t| t.integer "abonnement_type_id", limit: 4 @@ -1015,6 +1015,7 @@ ActiveRecord::Schema.define(version: 20181017211545) do t.decimal "step_group", precision: 10, scale: 2 t.decimal "step_stop", precision: 10, scale: 2 t.boolean "constraint_qty" + t.boolean "orderable", default: true end add_index "products", ["product_category_id"], name: "index_products_on_product_category_id", using: :btree @@ -1049,6 +1050,7 @@ ActiveRecord::Schema.define(version: 20181017211545) do t.boolean "needs_enabled", default: false t.boolean "centrale_enabled", default: false t.integer "default_part", limit: 4, default: 1 + t.integer "menu_item_id", limit: 4 end create_table "sessions", force: :cascade do |t|