From c687353802ea301f6fda4a24a0e0e35659f8d306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 26 Aug 2021 15:58:34 +0200 Subject: [PATCH 01/24] Generate qis PArticle --- .../admin/p_articles_controller.rb | 76 +++++++++++++++++++ app/models/p_article.rb | 3 + app/views/admin/p_articles/_form.html.haml | 12 +++ .../admin/p_articles/_p_article.html.haml | 16 ++++ app/views/admin/p_articles/create.js.erb | 2 + app/views/admin/p_articles/destroy.js.erb | 1 + app/views/admin/p_articles/edit.js.erb | 1 + app/views/admin/p_articles/index.html.haml | 16 ++++ app/views/admin/p_articles/new.js.erb | 1 + app/views/admin/p_articles/show.html.haml | 10 +++ app/views/admin/p_articles/update.js.erb | 2 + config/routes.rb | 11 +++ .../20210826135742_create_p_articles.rb | 9 +++ test/fixtures/p_articles.yml | 7 ++ test/models/p_article_test.rb | 7 ++ 15 files changed, 174 insertions(+) create mode 100644 app/controllers/admin/p_articles_controller.rb create mode 100644 app/models/p_article.rb create mode 100644 app/views/admin/p_articles/_form.html.haml create mode 100644 app/views/admin/p_articles/_p_article.html.haml create mode 100644 app/views/admin/p_articles/create.js.erb create mode 100644 app/views/admin/p_articles/destroy.js.erb create mode 100644 app/views/admin/p_articles/edit.js.erb create mode 100644 app/views/admin/p_articles/index.html.haml create mode 100644 app/views/admin/p_articles/new.js.erb create mode 100644 app/views/admin/p_articles/show.html.haml create mode 100644 app/views/admin/p_articles/update.js.erb create mode 100644 db/migrate/20210826135742_create_p_articles.rb create mode 100644 test/fixtures/p_articles.yml create mode 100644 test/models/p_article_test.rb diff --git a/app/controllers/admin/p_articles_controller.rb b/app/controllers/admin/p_articles_controller.rb new file mode 100644 index 0000000..62a2b86 --- /dev/null +++ b/app/controllers/admin/p_articles_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PArticlesController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @p_articles = PArticle.all + + @p_articles = sort_by_sorting(@p_articles, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_articles = @p_articles.page(page).per(per_page) + + } + end + end + + def show + @p_article = PArticle.find(params[:id]) + + end + + def new + @p_article = PArticle.new + + end + + def edit + @p_article = PArticle.find(params[:id]) + + end + + def create + @p_article = PArticle.new(params.require(:p_article).permit!) + + if @p_article.save + + else + render action: "new" + + end + + end + + + def update + @p_article = PArticle.find(params[:id]) + + + if @p_article.update_attributes(params.require(:p_article).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @p_article = PArticle.find(params[:id]) + @p_article.destroy + + end +end diff --git a/app/models/p_article.rb b/app/models/p_article.rb new file mode 100644 index 0000000..325db1a --- /dev/null +++ b/app/models/p_article.rb @@ -0,0 +1,3 @@ +class PArticle < ApplicationRecord + belongs_to :p_product_ref +end diff --git a/app/views/admin/p_articles/_form.html.haml b/app/views/admin/p_articles/_form.html.haml new file mode 100644 index 0000000..6561210 --- /dev/null +++ b/app/views/admin/p_articles/_form.html.haml @@ -0,0 +1,12 @@ +=semantic_form_for [:admin, @p_article], :remote => true do |f| + + .content + =f.inputs do + = f.input :p_product_ref, :label => f.object.label_for(:p_product_ref) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/p_articles/_p_article.html.haml b/app/views/admin/p_articles/_p_article.html.haml new file mode 100644 index 0000000..171a403 --- /dev/null +++ b/app/views/admin/p_articles/_p_article.html.haml @@ -0,0 +1,16 @@ +%tr#p_article_row{:id => p_article.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_article], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_article_path(p_article), :remote => true + = link_to i(:eye), admin_p_article_path(p_article), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_article} + + + + \ No newline at end of file diff --git a/app/views/admin/p_articles/create.js.erb b/app/views/admin/p_articles/create.js.erb new file mode 100644 index 0000000..4638f5f --- /dev/null +++ b/app/views/admin/p_articles/create.js.erb @@ -0,0 +1,2 @@ +$('#p_articles_rows').prepend("<%= escape_javascript(render(@p_article))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/p_articles/destroy.js.erb b/app/views/admin/p_articles/destroy.js.erb new file mode 100644 index 0000000..267d137 --- /dev/null +++ b/app/views/admin/p_articles/destroy.js.erb @@ -0,0 +1 @@ +$('#p_article_row_<%= @p_article.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/p_articles/edit.js.erb b/app/views/admin/p_articles/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_articles/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_articles/index.html.haml b/app/views/admin/p_articles/index.html.haml new file mode 100644 index 0000000..2b77ca5 --- /dev/null +++ b/app/views/admin/p_articles/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_p_article_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PArticle.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_articles} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_articles} + + + diff --git a/app/views/admin/p_articles/new.js.erb b/app/views/admin/p_articles/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_articles/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_articles/show.html.haml b/app/views/admin/p_articles/show.html.haml new file mode 100644 index 0000000..63cfc6a --- /dev/null +++ b/app/views/admin/p_articles/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @p_article \ No newline at end of file diff --git a/app/views/admin/p_articles/update.js.erb b/app/views/admin/p_articles/update.js.erb new file mode 100644 index 0000000..54d637a --- /dev/null +++ b/app/views/admin/p_articles/update.js.erb @@ -0,0 +1,2 @@ +$('#p_article_row_<%= @p_article.id %>').replaceWith("<%= escape_javascript(render(@p_article))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 226c9c5..482f7d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :p_articles do + member do + + end + collection do + + end + end + end + namespace :admin do resources :buy_lists do member do diff --git a/db/migrate/20210826135742_create_p_articles.rb b/db/migrate/20210826135742_create_p_articles.rb new file mode 100644 index 0000000..67ccbf1 --- /dev/null +++ b/db/migrate/20210826135742_create_p_articles.rb @@ -0,0 +1,9 @@ +class CreatePArticles < ActiveRecord::Migration[6.0] + def change + create_table :p_articles do |t| + t.references :p_product_ref, foreign_key: true + + t.timestamps + end + end +end diff --git a/test/fixtures/p_articles.yml b/test/fixtures/p_articles.yml new file mode 100644 index 0000000..28280d4 --- /dev/null +++ b/test/fixtures/p_articles.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + p_product_ref: one + +two: + p_product_ref: two diff --git a/test/models/p_article_test.rb b/test/models/p_article_test.rb new file mode 100644 index 0000000..8e6e762 --- /dev/null +++ b/test/models/p_article_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PArticleTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 2897a604550348e4dc4478d7a0133b778241bcb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 26 Aug 2021 16:03:24 +0200 Subject: [PATCH 02/24] p_article migration --- db/schema.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 734a9dc..b3956ac 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_07_06_171352) do +ActiveRecord::Schema.define(version: 2021_08_26_135742) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -970,6 +970,13 @@ ActiveRecord::Schema.define(version: 2021_07_06_171352) do t.datetime "updated_at", precision: 6, null: false end + create_table "p_articles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.bigint "p_product_ref_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["p_product_ref_id"], name: "index_p_articles_on_p_product_ref_id" + end + create_table "p_bank_accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.bigint "p_bank_id" t.string "iban" @@ -2336,7 +2343,6 @@ ActiveRecord::Schema.define(version: 2021_07_06_171352) do t.integer "order_hist_id" t.boolean "imported", default: false t.date "validation_date" - t.date "cc_validation_date" t.string "cc_state" t.index ["p_customer_id"], name: "index_price_line_blocks_on_p_customer_id" end @@ -3050,6 +3056,7 @@ ActiveRecord::Schema.define(version: 2021_07_06_171352) do add_foreign_key "order_hist_lines", "p_customers" add_foreign_key "order_hist_lines", "p_payment_types" add_foreign_key "order_hist_lines", "p_product_refs" + add_foreign_key "p_articles", "p_product_refs" add_foreign_key "p_commercial_object_brands", "p_commercial_objectives" add_foreign_key "p_commercial_object_brands", "p_commercials" add_foreign_key "p_commercial_object_brands", "s_brands" From 6222b44a9b0fb55be687864b2c6cb2d036656556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 26 Aug 2021 16:04:27 +0200 Subject: [PATCH 03/24] generate qis p_serial_num_type --- .../admin/p_serial_num_types_controller.rb | 76 +++++++++++++++++++ app/models/p_serial_num_type.rb | 2 + .../admin/p_serial_num_types/_form.html.haml | 12 +++ .../_p_serial_num_type.html.haml | 16 ++++ .../admin/p_serial_num_types/create.js.erb | 2 + .../admin/p_serial_num_types/destroy.js.erb | 1 + .../admin/p_serial_num_types/edit.js.erb | 1 + .../admin/p_serial_num_types/index.html.haml | 16 ++++ app/views/admin/p_serial_num_types/new.js.erb | 1 + .../admin/p_serial_num_types/show.html.haml | 10 +++ .../admin/p_serial_num_types/update.js.erb | 2 + config/routes.rb | 11 +++ ...0210826140333_create_p_serial_num_types.rb | 9 +++ db/schema.rb | 8 +- test/fixtures/p_serial_num_types.yml | 7 ++ test/models/p_serial_num_type_test.rb | 7 ++ 16 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/p_serial_num_types_controller.rb create mode 100644 app/models/p_serial_num_type.rb create mode 100644 app/views/admin/p_serial_num_types/_form.html.haml create mode 100644 app/views/admin/p_serial_num_types/_p_serial_num_type.html.haml create mode 100644 app/views/admin/p_serial_num_types/create.js.erb create mode 100644 app/views/admin/p_serial_num_types/destroy.js.erb create mode 100644 app/views/admin/p_serial_num_types/edit.js.erb create mode 100644 app/views/admin/p_serial_num_types/index.html.haml create mode 100644 app/views/admin/p_serial_num_types/new.js.erb create mode 100644 app/views/admin/p_serial_num_types/show.html.haml create mode 100644 app/views/admin/p_serial_num_types/update.js.erb create mode 100644 db/migrate/20210826140333_create_p_serial_num_types.rb create mode 100644 test/fixtures/p_serial_num_types.yml create mode 100644 test/models/p_serial_num_type_test.rb diff --git a/app/controllers/admin/p_serial_num_types_controller.rb b/app/controllers/admin/p_serial_num_types_controller.rb new file mode 100644 index 0000000..7fa9e38 --- /dev/null +++ b/app/controllers/admin/p_serial_num_types_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PSerialNumTypesController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @p_serial_num_types = PSerialNumType.all + + @p_serial_num_types = sort_by_sorting(@p_serial_num_types, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_serial_num_types = @p_serial_num_types.page(page).per(per_page) + + } + end + end + + def show + @p_serial_num_type = PSerialNumType.find(params[:id]) + + end + + def new + @p_serial_num_type = PSerialNumType.new + + end + + def edit + @p_serial_num_type = PSerialNumType.find(params[:id]) + + end + + def create + @p_serial_num_type = PSerialNumType.new(params.require(:p_serial_num_type).permit!) + + if @p_serial_num_type.save + + else + render action: "new" + + end + + end + + + def update + @p_serial_num_type = PSerialNumType.find(params[:id]) + + + if @p_serial_num_type.update_attributes(params.require(:p_serial_num_type).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @p_serial_num_type = PSerialNumType.find(params[:id]) + @p_serial_num_type.destroy + + end +end diff --git a/app/models/p_serial_num_type.rb b/app/models/p_serial_num_type.rb new file mode 100644 index 0000000..62c20f6 --- /dev/null +++ b/app/models/p_serial_num_type.rb @@ -0,0 +1,2 @@ +class PSerialNumType < ApplicationRecord +end diff --git a/app/views/admin/p_serial_num_types/_form.html.haml b/app/views/admin/p_serial_num_types/_form.html.haml new file mode 100644 index 0000000..70b89fe --- /dev/null +++ b/app/views/admin/p_serial_num_types/_form.html.haml @@ -0,0 +1,12 @@ +=semantic_form_for [:admin, @p_serial_num_type], :remote => true do |f| + + .content + =f.inputs do + = f.input :type, :label => f.object.label_for(:type) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/p_serial_num_types/_p_serial_num_type.html.haml b/app/views/admin/p_serial_num_types/_p_serial_num_type.html.haml new file mode 100644 index 0000000..db6e57b --- /dev/null +++ b/app/views/admin/p_serial_num_types/_p_serial_num_type.html.haml @@ -0,0 +1,16 @@ +%tr#p_serial_num_type_row{:id => p_serial_num_type.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_serial_num_type], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_serial_num_type_path(p_serial_num_type), :remote => true + = link_to i(:eye), admin_p_serial_num_type_path(p_serial_num_type), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_serial_num_type} + + + + \ No newline at end of file diff --git a/app/views/admin/p_serial_num_types/create.js.erb b/app/views/admin/p_serial_num_types/create.js.erb new file mode 100644 index 0000000..1bcfb90 --- /dev/null +++ b/app/views/admin/p_serial_num_types/create.js.erb @@ -0,0 +1,2 @@ +$('#p_serial_num_types_rows').prepend("<%= escape_javascript(render(@p_serial_num_type))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/p_serial_num_types/destroy.js.erb b/app/views/admin/p_serial_num_types/destroy.js.erb new file mode 100644 index 0000000..25bf828 --- /dev/null +++ b/app/views/admin/p_serial_num_types/destroy.js.erb @@ -0,0 +1 @@ +$('#p_serial_num_type_row_<%= @p_serial_num_type.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/p_serial_num_types/edit.js.erb b/app/views/admin/p_serial_num_types/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_serial_num_types/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_serial_num_types/index.html.haml b/app/views/admin/p_serial_num_types/index.html.haml new file mode 100644 index 0000000..6e9745d --- /dev/null +++ b/app/views/admin/p_serial_num_types/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_p_serial_num_type_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PSerialNumType.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_serial_num_types} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_serial_num_types} + + + diff --git a/app/views/admin/p_serial_num_types/new.js.erb b/app/views/admin/p_serial_num_types/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_serial_num_types/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_serial_num_types/show.html.haml b/app/views/admin/p_serial_num_types/show.html.haml new file mode 100644 index 0000000..6ab5cdf --- /dev/null +++ b/app/views/admin/p_serial_num_types/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @p_serial_num_type \ No newline at end of file diff --git a/app/views/admin/p_serial_num_types/update.js.erb b/app/views/admin/p_serial_num_types/update.js.erb new file mode 100644 index 0000000..beac1d8 --- /dev/null +++ b/app/views/admin/p_serial_num_types/update.js.erb @@ -0,0 +1,2 @@ +$('#p_serial_num_type_row_<%= @p_serial_num_type.id %>').replaceWith("<%= escape_javascript(render(@p_serial_num_type))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 482f7d5..f5c5493 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :p_serial_num_types do + member do + + end + collection do + + end + end + end + namespace :admin do resources :p_articles do member do diff --git a/db/migrate/20210826140333_create_p_serial_num_types.rb b/db/migrate/20210826140333_create_p_serial_num_types.rb new file mode 100644 index 0000000..e713124 --- /dev/null +++ b/db/migrate/20210826140333_create_p_serial_num_types.rb @@ -0,0 +1,9 @@ +class CreatePSerialNumTypes < ActiveRecord::Migration[6.0] + def change + create_table :p_serial_num_types do |t| + t.string :type + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b3956ac..0cdad91 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_26_135742) do +ActiveRecord::Schema.define(version: 2021_08_26_140333) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1866,6 +1866,12 @@ ActiveRecord::Schema.define(version: 2021_08_26_135742) do t.index ["p_payment_type_id"], name: "index_p_remises_on_p_payment_type_id" end + create_table "p_serial_num_types", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.string "type" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "p_sheet_line_stocks", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.bigint "p_sheet_line_id" t.bigint "p_brut_product_id" diff --git a/test/fixtures/p_serial_num_types.yml b/test/fixtures/p_serial_num_types.yml new file mode 100644 index 0000000..860f9b8 --- /dev/null +++ b/test/fixtures/p_serial_num_types.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + type: + +two: + type: diff --git a/test/models/p_serial_num_type_test.rb b/test/models/p_serial_num_type_test.rb new file mode 100644 index 0000000..63011d9 --- /dev/null +++ b/test/models/p_serial_num_type_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PSerialNumTypeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 99801d37a7063d116028386e798be4a9c8ae96cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 26 Aug 2021 16:05:22 +0200 Subject: [PATCH 04/24] generate qis p_serial_num_value --- .../admin/p_serial_num_values_controller.rb | 76 +++++++++++++++++++ app/models/p_serial_num_value.rb | 2 + .../admin/p_serial_num_values/_form.html.haml | 12 +++ .../_p_serial_num_value.html.haml | 16 ++++ .../admin/p_serial_num_values/create.js.erb | 2 + .../admin/p_serial_num_values/destroy.js.erb | 1 + .../admin/p_serial_num_values/edit.js.erb | 1 + .../admin/p_serial_num_values/index.html.haml | 16 ++++ .../admin/p_serial_num_values/new.js.erb | 1 + .../admin/p_serial_num_values/show.html.haml | 10 +++ .../admin/p_serial_num_values/update.js.erb | 2 + config/routes.rb | 11 +++ ...210826140445_create_p_serial_num_values.rb | 9 +++ db/schema.rb | 8 +- test/fixtures/p_serial_num_values.yml | 7 ++ test/models/p_serial_num_value_test.rb | 7 ++ 16 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/p_serial_num_values_controller.rb create mode 100644 app/models/p_serial_num_value.rb create mode 100644 app/views/admin/p_serial_num_values/_form.html.haml create mode 100644 app/views/admin/p_serial_num_values/_p_serial_num_value.html.haml create mode 100644 app/views/admin/p_serial_num_values/create.js.erb create mode 100644 app/views/admin/p_serial_num_values/destroy.js.erb create mode 100644 app/views/admin/p_serial_num_values/edit.js.erb create mode 100644 app/views/admin/p_serial_num_values/index.html.haml create mode 100644 app/views/admin/p_serial_num_values/new.js.erb create mode 100644 app/views/admin/p_serial_num_values/show.html.haml create mode 100644 app/views/admin/p_serial_num_values/update.js.erb create mode 100644 db/migrate/20210826140445_create_p_serial_num_values.rb create mode 100644 test/fixtures/p_serial_num_values.yml create mode 100644 test/models/p_serial_num_value_test.rb diff --git a/app/controllers/admin/p_serial_num_values_controller.rb b/app/controllers/admin/p_serial_num_values_controller.rb new file mode 100644 index 0000000..05c3bde --- /dev/null +++ b/app/controllers/admin/p_serial_num_values_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PSerialNumValuesController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @p_serial_num_values = PSerialNumValue.all + + @p_serial_num_values = sort_by_sorting(@p_serial_num_values, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_serial_num_values = @p_serial_num_values.page(page).per(per_page) + + } + end + end + + def show + @p_serial_num_value = PSerialNumValue.find(params[:id]) + + end + + def new + @p_serial_num_value = PSerialNumValue.new + + end + + def edit + @p_serial_num_value = PSerialNumValue.find(params[:id]) + + end + + def create + @p_serial_num_value = PSerialNumValue.new(params.require(:p_serial_num_value).permit!) + + if @p_serial_num_value.save + + else + render action: "new" + + end + + end + + + def update + @p_serial_num_value = PSerialNumValue.find(params[:id]) + + + if @p_serial_num_value.update_attributes(params.require(:p_serial_num_value).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @p_serial_num_value = PSerialNumValue.find(params[:id]) + @p_serial_num_value.destroy + + end +end diff --git a/app/models/p_serial_num_value.rb b/app/models/p_serial_num_value.rb new file mode 100644 index 0000000..735a10d --- /dev/null +++ b/app/models/p_serial_num_value.rb @@ -0,0 +1,2 @@ +class PSerialNumValue < ApplicationRecord +end diff --git a/app/views/admin/p_serial_num_values/_form.html.haml b/app/views/admin/p_serial_num_values/_form.html.haml new file mode 100644 index 0000000..7ad0960 --- /dev/null +++ b/app/views/admin/p_serial_num_values/_form.html.haml @@ -0,0 +1,12 @@ +=semantic_form_for [:admin, @p_serial_num_value], :remote => true do |f| + + .content + =f.inputs do + = f.input :value, :label => f.object.label_for(:value) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/p_serial_num_values/_p_serial_num_value.html.haml b/app/views/admin/p_serial_num_values/_p_serial_num_value.html.haml new file mode 100644 index 0000000..52d6eee --- /dev/null +++ b/app/views/admin/p_serial_num_values/_p_serial_num_value.html.haml @@ -0,0 +1,16 @@ +%tr#p_serial_num_value_row{:id => p_serial_num_value.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_serial_num_value], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_serial_num_value_path(p_serial_num_value), :remote => true + = link_to i(:eye), admin_p_serial_num_value_path(p_serial_num_value), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_serial_num_value} + + + + \ No newline at end of file diff --git a/app/views/admin/p_serial_num_values/create.js.erb b/app/views/admin/p_serial_num_values/create.js.erb new file mode 100644 index 0000000..f53ff23 --- /dev/null +++ b/app/views/admin/p_serial_num_values/create.js.erb @@ -0,0 +1,2 @@ +$('#p_serial_num_values_rows').prepend("<%= escape_javascript(render(@p_serial_num_value))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/p_serial_num_values/destroy.js.erb b/app/views/admin/p_serial_num_values/destroy.js.erb new file mode 100644 index 0000000..1622e2d --- /dev/null +++ b/app/views/admin/p_serial_num_values/destroy.js.erb @@ -0,0 +1 @@ +$('#p_serial_num_value_row_<%= @p_serial_num_value.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/p_serial_num_values/edit.js.erb b/app/views/admin/p_serial_num_values/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_serial_num_values/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_serial_num_values/index.html.haml b/app/views/admin/p_serial_num_values/index.html.haml new file mode 100644 index 0000000..7e600fc --- /dev/null +++ b/app/views/admin/p_serial_num_values/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_p_serial_num_value_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PSerialNumValue.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_serial_num_values} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_serial_num_values} + + + diff --git a/app/views/admin/p_serial_num_values/new.js.erb b/app/views/admin/p_serial_num_values/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_serial_num_values/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_serial_num_values/show.html.haml b/app/views/admin/p_serial_num_values/show.html.haml new file mode 100644 index 0000000..e9b982d --- /dev/null +++ b/app/views/admin/p_serial_num_values/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @p_serial_num_value \ No newline at end of file diff --git a/app/views/admin/p_serial_num_values/update.js.erb b/app/views/admin/p_serial_num_values/update.js.erb new file mode 100644 index 0000000..d272f5f --- /dev/null +++ b/app/views/admin/p_serial_num_values/update.js.erb @@ -0,0 +1,2 @@ +$('#p_serial_num_value_row_<%= @p_serial_num_value.id %>').replaceWith("<%= escape_javascript(render(@p_serial_num_value))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f5c5493..c06dc26 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :p_serial_num_values do + member do + + end + collection do + + end + end + end + namespace :admin do resources :p_serial_num_types do member do diff --git a/db/migrate/20210826140445_create_p_serial_num_values.rb b/db/migrate/20210826140445_create_p_serial_num_values.rb new file mode 100644 index 0000000..79660b3 --- /dev/null +++ b/db/migrate/20210826140445_create_p_serial_num_values.rb @@ -0,0 +1,9 @@ +class CreatePSerialNumValues < ActiveRecord::Migration[6.0] + def change + create_table :p_serial_num_values do |t| + t.string :value + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0cdad91..5bc2582 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_26_140333) do +ActiveRecord::Schema.define(version: 2021_08_26_140445) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1872,6 +1872,12 @@ ActiveRecord::Schema.define(version: 2021_08_26_140333) do t.datetime "updated_at", precision: 6, null: false end + create_table "p_serial_num_values", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.string "value" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "p_sheet_line_stocks", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.bigint "p_sheet_line_id" t.bigint "p_brut_product_id" diff --git a/test/fixtures/p_serial_num_values.yml b/test/fixtures/p_serial_num_values.yml new file mode 100644 index 0000000..ebe29a0 --- /dev/null +++ b/test/fixtures/p_serial_num_values.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + value: MyString + +two: + value: MyString diff --git a/test/models/p_serial_num_value_test.rb b/test/models/p_serial_num_value_test.rb new file mode 100644 index 0000000..812717c --- /dev/null +++ b/test/models/p_serial_num_value_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PSerialNumValueTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 02614f1ec245571e4732501c3846868557895e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 26 Aug 2021 16:07:23 +0200 Subject: [PATCH 05/24] generate qis p_article_serial_num --- .../admin/p_article_serial_nums_controller.rb | 76 +++++++++++++++++++ app/models/p_article_serial_num.rb | 5 ++ .../p_article_serial_nums/_form.html.haml | 14 ++++ .../_p_article_serial_num.html.haml | 16 ++++ .../admin/p_article_serial_nums/create.js.erb | 2 + .../p_article_serial_nums/destroy.js.erb | 1 + .../admin/p_article_serial_nums/edit.js.erb | 1 + .../p_article_serial_nums/index.html.haml | 16 ++++ .../admin/p_article_serial_nums/new.js.erb | 1 + .../p_article_serial_nums/show.html.haml | 10 +++ .../admin/p_article_serial_nums/update.js.erb | 2 + config/routes.rb | 11 +++ ...0826140648_create_p_article_serial_nums.rb | 11 +++ db/schema.rb | 16 +++- test/fixtures/p_article_serial_nums.yml | 11 +++ test/models/p_article_serial_num_test.rb | 7 ++ 16 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/p_article_serial_nums_controller.rb create mode 100644 app/models/p_article_serial_num.rb create mode 100644 app/views/admin/p_article_serial_nums/_form.html.haml create mode 100644 app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml create mode 100644 app/views/admin/p_article_serial_nums/create.js.erb create mode 100644 app/views/admin/p_article_serial_nums/destroy.js.erb create mode 100644 app/views/admin/p_article_serial_nums/edit.js.erb create mode 100644 app/views/admin/p_article_serial_nums/index.html.haml create mode 100644 app/views/admin/p_article_serial_nums/new.js.erb create mode 100644 app/views/admin/p_article_serial_nums/show.html.haml create mode 100644 app/views/admin/p_article_serial_nums/update.js.erb create mode 100644 db/migrate/20210826140648_create_p_article_serial_nums.rb create mode 100644 test/fixtures/p_article_serial_nums.yml create mode 100644 test/models/p_article_serial_num_test.rb diff --git a/app/controllers/admin/p_article_serial_nums_controller.rb b/app/controllers/admin/p_article_serial_nums_controller.rb new file mode 100644 index 0000000..000d7cb --- /dev/null +++ b/app/controllers/admin/p_article_serial_nums_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PArticleSerialNumsController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @p_article_serial_nums = PArticleSerialNum.all + + @p_article_serial_nums = sort_by_sorting(@p_article_serial_nums, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_article_serial_nums = @p_article_serial_nums.page(page).per(per_page) + + } + end + end + + def show + @p_article_serial_num = PArticleSerialNum.find(params[:id]) + + end + + def new + @p_article_serial_num = PArticleSerialNum.new + + end + + def edit + @p_article_serial_num = PArticleSerialNum.find(params[:id]) + + end + + def create + @p_article_serial_num = PArticleSerialNum.new(params.require(:p_article_serial_num).permit!) + + if @p_article_serial_num.save + + else + render action: "new" + + end + + end + + + def update + @p_article_serial_num = PArticleSerialNum.find(params[:id]) + + + if @p_article_serial_num.update_attributes(params.require(:p_article_serial_num).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @p_article_serial_num = PArticleSerialNum.find(params[:id]) + @p_article_serial_num.destroy + + end +end diff --git a/app/models/p_article_serial_num.rb b/app/models/p_article_serial_num.rb new file mode 100644 index 0000000..c4c2da1 --- /dev/null +++ b/app/models/p_article_serial_num.rb @@ -0,0 +1,5 @@ +class PArticleSerialNum < ApplicationRecord + belongs_to :p_article + belongs_to :p_serial_num_type + belongs_to :p_serial_num_value +end diff --git a/app/views/admin/p_article_serial_nums/_form.html.haml b/app/views/admin/p_article_serial_nums/_form.html.haml new file mode 100644 index 0000000..88c40df --- /dev/null +++ b/app/views/admin/p_article_serial_nums/_form.html.haml @@ -0,0 +1,14 @@ +=semantic_form_for [:admin, @p_article_serial_num], :remote => true do |f| + + .content + =f.inputs do + = f.input :p_article, :label => f.object.label_for(:p_article) + = f.input :p_serial_num_type, :label => f.object.label_for(:p_serial_num_type) + = f.input :p_serial_num_value, :label => f.object.label_for(:p_serial_num_value) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml b/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml new file mode 100644 index 0000000..b6e652b --- /dev/null +++ b/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml @@ -0,0 +1,16 @@ +%tr#p_article_serial_num_row{:id => p_article_serial_num.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_article_serial_num], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_article_serial_num_path(p_article_serial_num), :remote => true + = link_to i(:eye), admin_p_article_serial_num_path(p_article_serial_num), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_article_serial_num} + + + + \ No newline at end of file diff --git a/app/views/admin/p_article_serial_nums/create.js.erb b/app/views/admin/p_article_serial_nums/create.js.erb new file mode 100644 index 0000000..0f45d7b --- /dev/null +++ b/app/views/admin/p_article_serial_nums/create.js.erb @@ -0,0 +1,2 @@ +$('#p_article_serial_nums_rows').prepend("<%= escape_javascript(render(@p_article_serial_num))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/p_article_serial_nums/destroy.js.erb b/app/views/admin/p_article_serial_nums/destroy.js.erb new file mode 100644 index 0000000..bfed426 --- /dev/null +++ b/app/views/admin/p_article_serial_nums/destroy.js.erb @@ -0,0 +1 @@ +$('#p_article_serial_num_row_<%= @p_article_serial_num.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/p_article_serial_nums/edit.js.erb b/app/views/admin/p_article_serial_nums/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_article_serial_nums/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_article_serial_nums/index.html.haml b/app/views/admin/p_article_serial_nums/index.html.haml new file mode 100644 index 0000000..2a60940 --- /dev/null +++ b/app/views/admin/p_article_serial_nums/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_p_article_serial_num_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PArticleSerialNum.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_article_serial_nums} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_article_serial_nums} + + + diff --git a/app/views/admin/p_article_serial_nums/new.js.erb b/app/views/admin/p_article_serial_nums/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_article_serial_nums/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_article_serial_nums/show.html.haml b/app/views/admin/p_article_serial_nums/show.html.haml new file mode 100644 index 0000000..b32815c --- /dev/null +++ b/app/views/admin/p_article_serial_nums/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @p_article_serial_num \ No newline at end of file diff --git a/app/views/admin/p_article_serial_nums/update.js.erb b/app/views/admin/p_article_serial_nums/update.js.erb new file mode 100644 index 0000000..2a1b65c --- /dev/null +++ b/app/views/admin/p_article_serial_nums/update.js.erb @@ -0,0 +1,2 @@ +$('#p_article_serial_num_row_<%= @p_article_serial_num.id %>').replaceWith("<%= escape_javascript(render(@p_article_serial_num))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c06dc26..00b564d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :p_article_serial_nums do + member do + + end + collection do + + end + end + end + namespace :admin do resources :p_serial_num_values do member do diff --git a/db/migrate/20210826140648_create_p_article_serial_nums.rb b/db/migrate/20210826140648_create_p_article_serial_nums.rb new file mode 100644 index 0000000..a68ebe3 --- /dev/null +++ b/db/migrate/20210826140648_create_p_article_serial_nums.rb @@ -0,0 +1,11 @@ +class CreatePArticleSerialNums < ActiveRecord::Migration[6.0] + def change + create_table :p_article_serial_nums do |t| + t.references :p_article, foreign_key: true + t.references :p_serial_num_type, foreign_key: true + t.references :p_serial_num_value, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5bc2582..53e2114 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_26_140445) do +ActiveRecord::Schema.define(version: 2021_08_26_140648) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -970,6 +970,17 @@ ActiveRecord::Schema.define(version: 2021_08_26_140445) do t.datetime "updated_at", precision: 6, null: false end + create_table "p_article_serial_nums", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.bigint "p_article_id" + t.bigint "p_serial_num_type_id" + t.bigint "p_serial_num_value_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["p_article_id"], name: "index_p_article_serial_nums_on_p_article_id" + t.index ["p_serial_num_type_id"], name: "index_p_article_serial_nums_on_p_serial_num_type_id" + t.index ["p_serial_num_value_id"], name: "index_p_article_serial_nums_on_p_serial_num_value_id" + end + create_table "p_articles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.bigint "p_product_ref_id" t.datetime "created_at", precision: 6, null: false @@ -3068,6 +3079,9 @@ ActiveRecord::Schema.define(version: 2021_08_26_140445) do add_foreign_key "order_hist_lines", "p_customers" add_foreign_key "order_hist_lines", "p_payment_types" add_foreign_key "order_hist_lines", "p_product_refs" + add_foreign_key "p_article_serial_nums", "p_articles" + add_foreign_key "p_article_serial_nums", "p_serial_num_types" + add_foreign_key "p_article_serial_nums", "p_serial_num_values" add_foreign_key "p_articles", "p_product_refs" add_foreign_key "p_commercial_object_brands", "p_commercial_objectives" add_foreign_key "p_commercial_object_brands", "p_commercials" diff --git a/test/fixtures/p_article_serial_nums.yml b/test/fixtures/p_article_serial_nums.yml new file mode 100644 index 0000000..b464109 --- /dev/null +++ b/test/fixtures/p_article_serial_nums.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + p_article: one + p_serial_num_type: one + p_serial_num_value: one + +two: + p_article: two + p_serial_num_type: two + p_serial_num_value: two diff --git a/test/models/p_article_serial_num_test.rb b/test/models/p_article_serial_num_test.rb new file mode 100644 index 0000000..046c2fb --- /dev/null +++ b/test/models/p_article_serial_num_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PArticleSerialNumTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From fd0801b23d5a982bd7afc7a0fc720ef90cca8f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 26 Aug 2021 17:01:28 +0200 Subject: [PATCH 06/24] rename type (reserved) --- ...45816_rename_column_type_by_name_in_p_serial_num_types.rb | 5 +++++ db/schema.rb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20210826145816_rename_column_type_by_name_in_p_serial_num_types.rb diff --git a/db/migrate/20210826145816_rename_column_type_by_name_in_p_serial_num_types.rb b/db/migrate/20210826145816_rename_column_type_by_name_in_p_serial_num_types.rb new file mode 100644 index 0000000..2fe6872 --- /dev/null +++ b/db/migrate/20210826145816_rename_column_type_by_name_in_p_serial_num_types.rb @@ -0,0 +1,5 @@ +class RenameColumnTypeByNameInPSerialNumTypes < ActiveRecord::Migration[6.0] + def change + rename_column :p_serial_num_types, :type, :name + end +end diff --git a/db/schema.rb b/db/schema.rb index 53e2114..8d9270f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_26_140648) do +ActiveRecord::Schema.define(version: 2021_08_26_145816) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1878,7 +1878,7 @@ ActiveRecord::Schema.define(version: 2021_08_26_140648) do end create_table "p_serial_num_types", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| - t.string "type" + t.string "name" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end From 9db1d17d9a34bf30073c832dd71e7032531f449a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 26 Aug 2021 17:55:49 +0200 Subject: [PATCH 07/24] serial num sorting + form --- .../admin/p_article_serial_nums_controller.rb | 2 +- .../admin/p_articles_controller.rb | 2 +- app/controllers/application_controller.rb | 2 ++ app/models/p_article.rb | 15 +++++++++++ app/models/p_article_serial_num.rb | 14 +++++++++- app/models/p_product.rb | 3 +-- app/models/p_product_ref.rb | 3 +++ app/models/p_serial_num_type.rb | 1 + app/models/p_serial_num_value.rb | 1 + .../p_article_serial_nums/_form.html.haml | 10 ++++--- .../_p_article_serial_num.html.haml | 26 +++++++++++++++++-- app/views/admin/p_articles/_form.html.haml | 4 +-- .../admin/p_articles/_p_article.html.haml | 25 +++++++++++++++++- .../admin/p_serial_num_values/_form.html.haml | 14 +++++----- 14 files changed, 101 insertions(+), 21 deletions(-) diff --git a/app/controllers/admin/p_article_serial_nums_controller.rb b/app/controllers/admin/p_article_serial_nums_controller.rb index 000d7cb..069ade6 100644 --- a/app/controllers/admin/p_article_serial_nums_controller.rb +++ b/app/controllers/admin/p_article_serial_nums_controller.rb @@ -33,7 +33,7 @@ class Admin::PArticleSerialNumsController < ApplicationController def new @p_article_serial_num = PArticleSerialNum.new - + @p_article_serial_num.build_p_serial_num_value end def edit diff --git a/app/controllers/admin/p_articles_controller.rb b/app/controllers/admin/p_articles_controller.rb index 62a2b86..03af6b9 100644 --- a/app/controllers/admin/p_articles_controller.rb +++ b/app/controllers/admin/p_articles_controller.rb @@ -33,7 +33,7 @@ class Admin::PArticlesController < ApplicationController def new @p_article = PArticle.new - + @p_article.build_p_product_ref end def edit diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f693d7e..6c5880a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -65,6 +65,7 @@ class ApplicationController < ActionController::Base if current_admin.has_permission?("products") set_sub_menu :stocks, :p_products, "Produits", admin_p_products_path set_sub_menu :stocks, :p_product_refs, "Références", admin_p_product_refs_path + set_sub_menu :stocks, :p_articles, "Articles", admin_p_articles_path set_sub_menu :stocks, :promos_p_products, "Offres spots", promos_admin_p_products_path end @@ -97,6 +98,7 @@ class ApplicationController < ActionController::Base if current_admin.has_permission?("boutique") set_sub_menu :stocks, :p_product_colors, "Couleurs" + set_sub_menu :stocks, :p_article_serial_nums, "Numero série" set_sub_menu :stocks, :p_product_powers, "Types de chargeurs" set_sub_menu :stocks, :p_product_zones, "Zones produits" diff --git a/app/models/p_article.rb b/app/models/p_article.rb index 325db1a..d2825e3 100644 --- a/app/models/p_article.rb +++ b/app/models/p_article.rb @@ -1,3 +1,18 @@ class PArticle < ApplicationRecord belongs_to :p_product_ref + has_one :p_product, through: :p_product_ref + belongs_to :p_product_color + has_many :p_article_serial_nums, dependent: :destroy + # accepts_nested_attributes_for :p_article_serial_nums + validates_presence_of :p_product_ref + + + acts_as_sorting :fields => { + :id => {:name => "id", :reorder => true}, + :p_product_ref_code => {:name => "Code ref", :reorder => true}, + :p_product_ref => {:name => "Désignation", :reorder => true}, + :color => {:name => "Couleur"}, + :p_article_serial_nums => {:name => "N° identifiants"}, + :actions => {:name => "Actions", :reorder => false}, + } end diff --git a/app/models/p_article_serial_num.rb b/app/models/p_article_serial_num.rb index c4c2da1..aae27cd 100644 --- a/app/models/p_article_serial_num.rb +++ b/app/models/p_article_serial_num.rb @@ -1,5 +1,17 @@ class PArticleSerialNum < ApplicationRecord belongs_to :p_article belongs_to :p_serial_num_type - belongs_to :p_serial_num_value + belongs_to :p_serial_num_value, inverse_of: :p_article_serial_nums + accepts_nested_attributes_for :p_serial_num_value + + acts_as_sorting :fields => { + :id => {:name => "ID"}, + :p_article => {:name => "Article", :reorder => true}, + :p_article_id => {:name => "Article ID", :reorder => true}, + :p_serial_num_type => {:name => "Type", :reorder => true}, + :p_serial_num_value => {:name => "N°", :reorder => true}, + + :actions => {:name => "Actions", :reorder => true} + + } end diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 1d77cd4..12a0795 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -5,8 +5,6 @@ class PProduct < ApplicationRecord has_many :p_product_refs, :dependent => :destroy accepts_nested_attributes_for :p_product_refs, allow_destroy: true - - has_many :p_product_ingredients, :dependent => :destroy accepts_nested_attributes_for :p_product_ingredients, allow_destroy: true @@ -17,6 +15,7 @@ class PProduct < ApplicationRecord has_many :p_product_nutris, :dependent => :destroy accepts_nested_attributes_for :p_product_nutris, allow_destroy: true + has_many :p_articles, through: :p_product_refs has_many :p_product_images diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index ae959f6..12da04b 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -9,6 +9,9 @@ class PProductRef < ApplicationRecord has_many :p_product_ref_price_histories belongs_to :p_product_color + has_many :p_articles + has_many :p_article_serial_nums, through: :p_articles + accepts_nested_attributes_for :p_article_serial_nums, allow_destroy: true #validates :ct_price_ht, :presence => true diff --git a/app/models/p_serial_num_type.rb b/app/models/p_serial_num_type.rb index 62c20f6..83f5ce7 100644 --- a/app/models/p_serial_num_type.rb +++ b/app/models/p_serial_num_type.rb @@ -1,2 +1,3 @@ class PSerialNumType < ApplicationRecord + has_many :p_article_serial_nums end diff --git a/app/models/p_serial_num_value.rb b/app/models/p_serial_num_value.rb index 735a10d..12a74bd 100644 --- a/app/models/p_serial_num_value.rb +++ b/app/models/p_serial_num_value.rb @@ -1,2 +1,3 @@ class PSerialNumValue < ApplicationRecord + has_many :p_article_serial_nums, inverse_of: :p_serial_num_value end diff --git a/app/views/admin/p_article_serial_nums/_form.html.haml b/app/views/admin/p_article_serial_nums/_form.html.haml index 88c40df..caad0f5 100644 --- a/app/views/admin/p_article_serial_nums/_form.html.haml +++ b/app/views/admin/p_article_serial_nums/_form.html.haml @@ -2,13 +2,15 @@ .content =f.inputs do - = f.input :p_article, :label => f.object.label_for(:p_article) - = f.input :p_serial_num_type, :label => f.object.label_for(:p_serial_num_type) - = f.input :p_serial_num_value, :label => f.object.label_for(:p_serial_num_value) + = f.input :p_article, as: :select, collection: PArticle.pluck(:id) ,:label => f.object.label_for(:p_article) + = f.input :p_serial_num_type, :label => f.object.label_for(:p_serial_num_type) + = f.semantic_fields_for :p_serial_num_value do | form | + + =render :partial => "admin/p_serial_num_values/form", :locals => {:f => form} .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml b/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml index b6e652b..59de1cd 100644 --- a/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml +++ b/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml @@ -1,6 +1,28 @@ %tr#p_article_serial_num_row{:id => p_article_serial_num.id} -tr = {} - + + -tr[:p_article_id] = capture do + %td + = p_article_serial_num.p_article.id + + -tr[:p_article] = capture do + %td + = p_article_serial_num.p_article.p_product.name + \- + = p_article_serial_num.p_article.p_product_ref.ct_sub_name + \- + = p_article_serial_num.p_article.p_product_ref.p_product_color.name + + + -tr[:p_serial_num_type] = capture do + %td + = p_article_serial_num.p_serial_num_type.name + + -tr[:p_serial_num_value] = capture do + %td + = p_article_serial_num.p_serial_num_value.value + + -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, p_article_serial_num], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true @@ -13,4 +35,4 @@ - \ No newline at end of file + diff --git a/app/views/admin/p_articles/_form.html.haml b/app/views/admin/p_articles/_form.html.haml index 6561210..8ab680b 100644 --- a/app/views/admin/p_articles/_form.html.haml +++ b/app/views/admin/p_articles/_form.html.haml @@ -2,11 +2,11 @@ .content =f.inputs do - = f.input :p_product_ref, :label => f.object.label_for(:p_product_ref) + = f.input :p_product_ref, as: :select, collection: PProductRef.all, :label => f.object.label_for(:p_product_ref) .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/p_articles/_p_article.html.haml b/app/views/admin/p_articles/_p_article.html.haml index 171a403..13e29ca 100644 --- a/app/views/admin/p_articles/_p_article.html.haml +++ b/app/views/admin/p_articles/_p_article.html.haml @@ -1,6 +1,29 @@ %tr#p_article_row{:id => p_article.id} -tr = {} + -tr[:p_product_ref_code] = capture do + %td + = p_article.p_product_ref.code + + + -tr[:color] = capture do + %td + = p_article.p_product_ref.p_product_color.color + + -tr[:p_product_ref] = capture do + %td + = p_article.p_product_ref.p_product.name + \- + = p_article.p_product_ref.ct_sub_name + \- + = p_article.p_product_ref.p_product_color.name + + -tr[:p_article_serial_nums] = capture do + %td + - p_article.p_article_serial_nums.each do |sn| + = sn.p_serial_num_type.name + " : " + sn.p_serial_num_value.value + + -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, p_article], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true @@ -13,4 +36,4 @@ - \ No newline at end of file + diff --git a/app/views/admin/p_serial_num_values/_form.html.haml b/app/views/admin/p_serial_num_values/_form.html.haml index 7ad0960..1872e5e 100644 --- a/app/views/admin/p_serial_num_values/_form.html.haml +++ b/app/views/admin/p_serial_num_values/_form.html.haml @@ -1,12 +1,12 @@ -=semantic_form_for [:admin, @p_serial_num_value], :remote => true do |f| +/ =semantic_form_for [:admin, @p_serial_num_value], :remote => true do |f| + + +=f.inputs do + = f.input :value, :label => "Numéro" - .content - =f.inputs do - = f.input :value, :label => f.object.label_for(:value) - - .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + / .actions=f.submit "sauvegarder", :class => "btn btn-primary" + From dfdd4439986144767864b92092f36c64fbc83f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 09:46:02 +0200 Subject: [PATCH 08/24] generate p_spec_type --- .../admin/p_spec_types_controller.rb | 76 +++++++++++++++++++ app/models/p_spec_type.rb | 2 + app/views/admin/p_spec_types/_form.html.haml | 12 +++ .../admin/p_spec_types/_p_spec_type.html.haml | 16 ++++ app/views/admin/p_spec_types/create.js.erb | 2 + app/views/admin/p_spec_types/destroy.js.erb | 1 + app/views/admin/p_spec_types/edit.js.erb | 1 + app/views/admin/p_spec_types/index.html.haml | 16 ++++ app/views/admin/p_spec_types/new.js.erb | 1 + app/views/admin/p_spec_types/show.html.haml | 10 +++ app/views/admin/p_spec_types/update.js.erb | 2 + config/routes.rb | 11 +++ .../20210827074532_create_p_spec_types.rb | 9 +++ db/schema.rb | 8 +- test/fixtures/p_spec_types.yml | 7 ++ test/models/p_spec_type_test.rb | 7 ++ 16 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/p_spec_types_controller.rb create mode 100644 app/models/p_spec_type.rb create mode 100644 app/views/admin/p_spec_types/_form.html.haml create mode 100644 app/views/admin/p_spec_types/_p_spec_type.html.haml create mode 100644 app/views/admin/p_spec_types/create.js.erb create mode 100644 app/views/admin/p_spec_types/destroy.js.erb create mode 100644 app/views/admin/p_spec_types/edit.js.erb create mode 100644 app/views/admin/p_spec_types/index.html.haml create mode 100644 app/views/admin/p_spec_types/new.js.erb create mode 100644 app/views/admin/p_spec_types/show.html.haml create mode 100644 app/views/admin/p_spec_types/update.js.erb create mode 100644 db/migrate/20210827074532_create_p_spec_types.rb create mode 100644 test/fixtures/p_spec_types.yml create mode 100644 test/models/p_spec_type_test.rb diff --git a/app/controllers/admin/p_spec_types_controller.rb b/app/controllers/admin/p_spec_types_controller.rb new file mode 100644 index 0000000..5d3ed6b --- /dev/null +++ b/app/controllers/admin/p_spec_types_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PSpecTypesController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @p_spec_types = PSpecType.all + + @p_spec_types = sort_by_sorting(@p_spec_types, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_spec_types = @p_spec_types.page(page).per(per_page) + + } + end + end + + def show + @p_spec_type = PSpecType.find(params[:id]) + + end + + def new + @p_spec_type = PSpecType.new + + end + + def edit + @p_spec_type = PSpecType.find(params[:id]) + + end + + def create + @p_spec_type = PSpecType.new(params.require(:p_spec_type).permit!) + + if @p_spec_type.save + + else + render action: "new" + + end + + end + + + def update + @p_spec_type = PSpecType.find(params[:id]) + + + if @p_spec_type.update_attributes(params.require(:p_spec_type).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @p_spec_type = PSpecType.find(params[:id]) + @p_spec_type.destroy + + end +end diff --git a/app/models/p_spec_type.rb b/app/models/p_spec_type.rb new file mode 100644 index 0000000..30aea9e --- /dev/null +++ b/app/models/p_spec_type.rb @@ -0,0 +1,2 @@ +class PSpecType < ApplicationRecord +end diff --git a/app/views/admin/p_spec_types/_form.html.haml b/app/views/admin/p_spec_types/_form.html.haml new file mode 100644 index 0000000..0a8acc2 --- /dev/null +++ b/app/views/admin/p_spec_types/_form.html.haml @@ -0,0 +1,12 @@ +=semantic_form_for [:admin, @p_spec_type], :remote => true do |f| + + .content + =f.inputs do + = f.input :type, :label => f.object.label_for(:type) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/p_spec_types/_p_spec_type.html.haml b/app/views/admin/p_spec_types/_p_spec_type.html.haml new file mode 100644 index 0000000..fd475e3 --- /dev/null +++ b/app/views/admin/p_spec_types/_p_spec_type.html.haml @@ -0,0 +1,16 @@ +%tr#p_spec_type_row{:id => p_spec_type.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_spec_type], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_spec_type_path(p_spec_type), :remote => true + = link_to i(:eye), admin_p_spec_type_path(p_spec_type), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_spec_type} + + + + \ No newline at end of file diff --git a/app/views/admin/p_spec_types/create.js.erb b/app/views/admin/p_spec_types/create.js.erb new file mode 100644 index 0000000..e9f7774 --- /dev/null +++ b/app/views/admin/p_spec_types/create.js.erb @@ -0,0 +1,2 @@ +$('#p_spec_types_rows').prepend("<%= escape_javascript(render(@p_spec_type))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/p_spec_types/destroy.js.erb b/app/views/admin/p_spec_types/destroy.js.erb new file mode 100644 index 0000000..e97e73c --- /dev/null +++ b/app/views/admin/p_spec_types/destroy.js.erb @@ -0,0 +1 @@ +$('#p_spec_type_row_<%= @p_spec_type.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/p_spec_types/edit.js.erb b/app/views/admin/p_spec_types/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_spec_types/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_spec_types/index.html.haml b/app/views/admin/p_spec_types/index.html.haml new file mode 100644 index 0000000..46d02ec --- /dev/null +++ b/app/views/admin/p_spec_types/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_p_spec_type_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PSpecType.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_spec_types} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_spec_types} + + + diff --git a/app/views/admin/p_spec_types/new.js.erb b/app/views/admin/p_spec_types/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_spec_types/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_spec_types/show.html.haml b/app/views/admin/p_spec_types/show.html.haml new file mode 100644 index 0000000..6005a84 --- /dev/null +++ b/app/views/admin/p_spec_types/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @p_spec_type \ No newline at end of file diff --git a/app/views/admin/p_spec_types/update.js.erb b/app/views/admin/p_spec_types/update.js.erb new file mode 100644 index 0000000..2f952cc --- /dev/null +++ b/app/views/admin/p_spec_types/update.js.erb @@ -0,0 +1,2 @@ +$('#p_spec_type_row_<%= @p_spec_type.id %>').replaceWith("<%= escape_javascript(render(@p_spec_type))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 00b564d..59c5ff0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :p_spec_types do + member do + + end + collection do + + end + end + end + namespace :admin do resources :p_article_serial_nums do member do diff --git a/db/migrate/20210827074532_create_p_spec_types.rb b/db/migrate/20210827074532_create_p_spec_types.rb new file mode 100644 index 0000000..ab9699c --- /dev/null +++ b/db/migrate/20210827074532_create_p_spec_types.rb @@ -0,0 +1,9 @@ +class CreatePSpecTypes < ActiveRecord::Migration[6.0] + def change + create_table :p_spec_types do |t| + t.string :type + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 8d9270f..2ebe559 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_26_145816) do +ActiveRecord::Schema.define(version: 2021_08_27_074532) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1978,6 +1978,12 @@ ActiveRecord::Schema.define(version: 2021_08_26_145816) do t.index ["p_fournisseur_id"], name: "index_p_ship_bills_on_p_fournisseur_id" end + create_table "p_spec_types", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.string "type" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "p_tank_stocks", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.datetime "ok_at" t.boolean "enabled", default: false diff --git a/test/fixtures/p_spec_types.yml b/test/fixtures/p_spec_types.yml new file mode 100644 index 0000000..860f9b8 --- /dev/null +++ b/test/fixtures/p_spec_types.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + type: + +two: + type: diff --git a/test/models/p_spec_type_test.rb b/test/models/p_spec_type_test.rb new file mode 100644 index 0000000..97553a9 --- /dev/null +++ b/test/models/p_spec_type_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PSpecTypeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 374c92b9a4d1d3e62ca214452996fdc15baabcfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 09:46:35 +0200 Subject: [PATCH 09/24] generate p_spec_value --- .../admin/p_spec_values_controller.rb | 76 +++++++++++++++++++ app/models/p_spec_value.rb | 2 + app/views/admin/p_spec_values/_form.html.haml | 13 ++++ .../p_spec_values/_p_spec_value.html.haml | 16 ++++ app/views/admin/p_spec_values/create.js.erb | 2 + app/views/admin/p_spec_values/destroy.js.erb | 1 + app/views/admin/p_spec_values/edit.js.erb | 1 + app/views/admin/p_spec_values/index.html.haml | 16 ++++ app/views/admin/p_spec_values/new.js.erb | 1 + app/views/admin/p_spec_values/show.html.haml | 10 +++ app/views/admin/p_spec_values/update.js.erb | 2 + config/routes.rb | 11 +++ .../20210827074615_create_p_spec_values.rb | 10 +++ db/schema.rb | 9 ++- test/fixtures/p_spec_values.yml | 9 +++ test/models/p_spec_value_test.rb | 7 ++ 16 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/p_spec_values_controller.rb create mode 100644 app/models/p_spec_value.rb create mode 100644 app/views/admin/p_spec_values/_form.html.haml create mode 100644 app/views/admin/p_spec_values/_p_spec_value.html.haml create mode 100644 app/views/admin/p_spec_values/create.js.erb create mode 100644 app/views/admin/p_spec_values/destroy.js.erb create mode 100644 app/views/admin/p_spec_values/edit.js.erb create mode 100644 app/views/admin/p_spec_values/index.html.haml create mode 100644 app/views/admin/p_spec_values/new.js.erb create mode 100644 app/views/admin/p_spec_values/show.html.haml create mode 100644 app/views/admin/p_spec_values/update.js.erb create mode 100644 db/migrate/20210827074615_create_p_spec_values.rb create mode 100644 test/fixtures/p_spec_values.yml create mode 100644 test/models/p_spec_value_test.rb diff --git a/app/controllers/admin/p_spec_values_controller.rb b/app/controllers/admin/p_spec_values_controller.rb new file mode 100644 index 0000000..2dfd736 --- /dev/null +++ b/app/controllers/admin/p_spec_values_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PSpecValuesController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @p_spec_values = PSpecValue.all + + @p_spec_values = sort_by_sorting(@p_spec_values, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_spec_values = @p_spec_values.page(page).per(per_page) + + } + end + end + + def show + @p_spec_value = PSpecValue.find(params[:id]) + + end + + def new + @p_spec_value = PSpecValue.new + + end + + def edit + @p_spec_value = PSpecValue.find(params[:id]) + + end + + def create + @p_spec_value = PSpecValue.new(params.require(:p_spec_value).permit!) + + if @p_spec_value.save + + else + render action: "new" + + end + + end + + + def update + @p_spec_value = PSpecValue.find(params[:id]) + + + if @p_spec_value.update_attributes(params.require(:p_spec_value).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @p_spec_value = PSpecValue.find(params[:id]) + @p_spec_value.destroy + + end +end diff --git a/app/models/p_spec_value.rb b/app/models/p_spec_value.rb new file mode 100644 index 0000000..17c7684 --- /dev/null +++ b/app/models/p_spec_value.rb @@ -0,0 +1,2 @@ +class PSpecValue < ApplicationRecord +end diff --git a/app/views/admin/p_spec_values/_form.html.haml b/app/views/admin/p_spec_values/_form.html.haml new file mode 100644 index 0000000..6d0339f --- /dev/null +++ b/app/views/admin/p_spec_values/_form.html.haml @@ -0,0 +1,13 @@ +=semantic_form_for [:admin, @p_spec_value], :remote => true do |f| + + .content + =f.inputs do + = f.input :value, :label => f.object.label_for(:value) + = f.input :unit, :label => f.object.label_for(:unit) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/p_spec_values/_p_spec_value.html.haml b/app/views/admin/p_spec_values/_p_spec_value.html.haml new file mode 100644 index 0000000..64de749 --- /dev/null +++ b/app/views/admin/p_spec_values/_p_spec_value.html.haml @@ -0,0 +1,16 @@ +%tr#p_spec_value_row{:id => p_spec_value.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_spec_value], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_spec_value_path(p_spec_value), :remote => true + = link_to i(:eye), admin_p_spec_value_path(p_spec_value), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_spec_value} + + + + \ No newline at end of file diff --git a/app/views/admin/p_spec_values/create.js.erb b/app/views/admin/p_spec_values/create.js.erb new file mode 100644 index 0000000..8aef8dd --- /dev/null +++ b/app/views/admin/p_spec_values/create.js.erb @@ -0,0 +1,2 @@ +$('#p_spec_values_rows').prepend("<%= escape_javascript(render(@p_spec_value))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/p_spec_values/destroy.js.erb b/app/views/admin/p_spec_values/destroy.js.erb new file mode 100644 index 0000000..643c933 --- /dev/null +++ b/app/views/admin/p_spec_values/destroy.js.erb @@ -0,0 +1 @@ +$('#p_spec_value_row_<%= @p_spec_value.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/p_spec_values/edit.js.erb b/app/views/admin/p_spec_values/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_spec_values/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_spec_values/index.html.haml b/app/views/admin/p_spec_values/index.html.haml new file mode 100644 index 0000000..8f34bd1 --- /dev/null +++ b/app/views/admin/p_spec_values/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_p_spec_value_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PSpecValue.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_spec_values} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_spec_values} + + + diff --git a/app/views/admin/p_spec_values/new.js.erb b/app/views/admin/p_spec_values/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_spec_values/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_spec_values/show.html.haml b/app/views/admin/p_spec_values/show.html.haml new file mode 100644 index 0000000..6414fbc --- /dev/null +++ b/app/views/admin/p_spec_values/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @p_spec_value \ No newline at end of file diff --git a/app/views/admin/p_spec_values/update.js.erb b/app/views/admin/p_spec_values/update.js.erb new file mode 100644 index 0000000..b7e6986 --- /dev/null +++ b/app/views/admin/p_spec_values/update.js.erb @@ -0,0 +1,2 @@ +$('#p_spec_value_row_<%= @p_spec_value.id %>').replaceWith("<%= escape_javascript(render(@p_spec_value))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 59c5ff0..b1d1e69 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :p_spec_values do + member do + + end + collection do + + end + end + end + namespace :admin do resources :p_spec_types do member do diff --git a/db/migrate/20210827074615_create_p_spec_values.rb b/db/migrate/20210827074615_create_p_spec_values.rb new file mode 100644 index 0000000..442275a --- /dev/null +++ b/db/migrate/20210827074615_create_p_spec_values.rb @@ -0,0 +1,10 @@ +class CreatePSpecValues < ActiveRecord::Migration[6.0] + def change + create_table :p_spec_values do |t| + t.string :value + t.string :unit + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2ebe559..a09865a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_27_074532) do +ActiveRecord::Schema.define(version: 2021_08_27_074615) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1984,6 +1984,13 @@ ActiveRecord::Schema.define(version: 2021_08_27_074532) do t.datetime "updated_at", precision: 6, null: false end + create_table "p_spec_values", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.string "value" + t.string "unit" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "p_tank_stocks", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.datetime "ok_at" t.boolean "enabled", default: false diff --git a/test/fixtures/p_spec_values.yml b/test/fixtures/p_spec_values.yml new file mode 100644 index 0000000..b54b2ea --- /dev/null +++ b/test/fixtures/p_spec_values.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + value: MyString + unit: MyString + +two: + value: MyString + unit: MyString diff --git a/test/models/p_spec_value_test.rb b/test/models/p_spec_value_test.rb new file mode 100644 index 0000000..021bdc7 --- /dev/null +++ b/test/models/p_spec_value_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PSpecValueTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From b1df8ad4c5cd4218ef7141f2897a7c1a6d9c8319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 09:48:30 +0200 Subject: [PATCH 10/24] generate p_product_ref_spec --- .../admin/p_product_ref_specs_controller.rb | 76 +++++++++++++++++++ app/models/p_product_ref_spec.rb | 5 ++ .../admin/p_product_ref_specs/_form.html.haml | 14 ++++ .../_p_product_ref_spec.html.haml | 16 ++++ .../admin/p_product_ref_specs/create.js.erb | 2 + .../admin/p_product_ref_specs/destroy.js.erb | 1 + .../admin/p_product_ref_specs/edit.js.erb | 1 + .../admin/p_product_ref_specs/index.html.haml | 16 ++++ .../admin/p_product_ref_specs/new.js.erb | 1 + .../admin/p_product_ref_specs/show.html.haml | 10 +++ .../admin/p_product_ref_specs/update.js.erb | 2 + config/routes.rb | 11 +++ ...210827074812_create_p_product_ref_specs.rb | 11 +++ db/schema.rb | 16 +++- test/fixtures/p_product_ref_specs.yml | 11 +++ test/models/p_product_ref_spec_test.rb | 7 ++ 16 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/p_product_ref_specs_controller.rb create mode 100644 app/models/p_product_ref_spec.rb create mode 100644 app/views/admin/p_product_ref_specs/_form.html.haml create mode 100644 app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml create mode 100644 app/views/admin/p_product_ref_specs/create.js.erb create mode 100644 app/views/admin/p_product_ref_specs/destroy.js.erb create mode 100644 app/views/admin/p_product_ref_specs/edit.js.erb create mode 100644 app/views/admin/p_product_ref_specs/index.html.haml create mode 100644 app/views/admin/p_product_ref_specs/new.js.erb create mode 100644 app/views/admin/p_product_ref_specs/show.html.haml create mode 100644 app/views/admin/p_product_ref_specs/update.js.erb create mode 100644 db/migrate/20210827074812_create_p_product_ref_specs.rb create mode 100644 test/fixtures/p_product_ref_specs.yml create mode 100644 test/models/p_product_ref_spec_test.rb diff --git a/app/controllers/admin/p_product_ref_specs_controller.rb b/app/controllers/admin/p_product_ref_specs_controller.rb new file mode 100644 index 0000000..7522ebb --- /dev/null +++ b/app/controllers/admin/p_product_ref_specs_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PProductRefSpecsController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @p_product_ref_specs = PProductRefSpec.all + + @p_product_ref_specs = sort_by_sorting(@p_product_ref_specs, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_product_ref_specs = @p_product_ref_specs.page(page).per(per_page) + + } + end + end + + def show + @p_product_ref_spec = PProductRefSpec.find(params[:id]) + + end + + def new + @p_product_ref_spec = PProductRefSpec.new + + end + + def edit + @p_product_ref_spec = PProductRefSpec.find(params[:id]) + + end + + def create + @p_product_ref_spec = PProductRefSpec.new(params.require(:p_product_ref_spec).permit!) + + if @p_product_ref_spec.save + + else + render action: "new" + + end + + end + + + def update + @p_product_ref_spec = PProductRefSpec.find(params[:id]) + + + if @p_product_ref_spec.update_attributes(params.require(:p_product_ref_spec).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @p_product_ref_spec = PProductRefSpec.find(params[:id]) + @p_product_ref_spec.destroy + + end +end diff --git a/app/models/p_product_ref_spec.rb b/app/models/p_product_ref_spec.rb new file mode 100644 index 0000000..3b80fce --- /dev/null +++ b/app/models/p_product_ref_spec.rb @@ -0,0 +1,5 @@ +class PProductRefSpec < ApplicationRecord + belongs_to :p_product_ref + belongs_to :p_spec_type + belongs_to :p_spec_value +end diff --git a/app/views/admin/p_product_ref_specs/_form.html.haml b/app/views/admin/p_product_ref_specs/_form.html.haml new file mode 100644 index 0000000..8fd4851 --- /dev/null +++ b/app/views/admin/p_product_ref_specs/_form.html.haml @@ -0,0 +1,14 @@ +=semantic_form_for [:admin, @p_product_ref_spec], :remote => true do |f| + + .content + =f.inputs do + = f.input :p_product_ref, :label => f.object.label_for(:p_product_ref) + = f.input :p_spec_type, :label => f.object.label_for(:p_spec_type) + = f.input :p_spec_value, :label => f.object.label_for(:p_spec_value) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml b/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml new file mode 100644 index 0000000..e91add0 --- /dev/null +++ b/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml @@ -0,0 +1,16 @@ +%tr#p_product_ref_spec_row{:id => p_product_ref_spec.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_product_ref_spec], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_product_ref_spec_path(p_product_ref_spec), :remote => true + = link_to i(:eye), admin_p_product_ref_spec_path(p_product_ref_spec), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_product_ref_spec} + + + + \ No newline at end of file diff --git a/app/views/admin/p_product_ref_specs/create.js.erb b/app/views/admin/p_product_ref_specs/create.js.erb new file mode 100644 index 0000000..d7a17bc --- /dev/null +++ b/app/views/admin/p_product_ref_specs/create.js.erb @@ -0,0 +1,2 @@ +$('#p_product_ref_specs_rows').prepend("<%= escape_javascript(render(@p_product_ref_spec))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/p_product_ref_specs/destroy.js.erb b/app/views/admin/p_product_ref_specs/destroy.js.erb new file mode 100644 index 0000000..5e87c5d --- /dev/null +++ b/app/views/admin/p_product_ref_specs/destroy.js.erb @@ -0,0 +1 @@ +$('#p_product_ref_spec_row_<%= @p_product_ref_spec.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/p_product_ref_specs/edit.js.erb b/app/views/admin/p_product_ref_specs/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_product_ref_specs/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_product_ref_specs/index.html.haml b/app/views/admin/p_product_ref_specs/index.html.haml new file mode 100644 index 0000000..f486839 --- /dev/null +++ b/app/views/admin/p_product_ref_specs/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_p_product_ref_spec_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PProductRefSpec.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_product_ref_specs} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_product_ref_specs} + + + diff --git a/app/views/admin/p_product_ref_specs/new.js.erb b/app/views/admin/p_product_ref_specs/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_product_ref_specs/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_product_ref_specs/show.html.haml b/app/views/admin/p_product_ref_specs/show.html.haml new file mode 100644 index 0000000..e56e759 --- /dev/null +++ b/app/views/admin/p_product_ref_specs/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @p_product_ref_spec \ No newline at end of file diff --git a/app/views/admin/p_product_ref_specs/update.js.erb b/app/views/admin/p_product_ref_specs/update.js.erb new file mode 100644 index 0000000..ccaba69 --- /dev/null +++ b/app/views/admin/p_product_ref_specs/update.js.erb @@ -0,0 +1,2 @@ +$('#p_product_ref_spec_row_<%= @p_product_ref_spec.id %>').replaceWith("<%= escape_javascript(render(@p_product_ref_spec))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b1d1e69..a585b05 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :p_product_ref_specs do + member do + + end + collection do + + end + end + end + namespace :admin do resources :p_spec_values do member do diff --git a/db/migrate/20210827074812_create_p_product_ref_specs.rb b/db/migrate/20210827074812_create_p_product_ref_specs.rb new file mode 100644 index 0000000..0731732 --- /dev/null +++ b/db/migrate/20210827074812_create_p_product_ref_specs.rb @@ -0,0 +1,11 @@ +class CreatePProductRefSpecs < ActiveRecord::Migration[6.0] + def change + create_table :p_product_ref_specs do |t| + t.references :p_product_ref, foreign_key: true + t.references :p_spec_type, foreign_key: true + t.references :p_spec_value, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a09865a..7edf151 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_27_074615) do +ActiveRecord::Schema.define(version: 2021_08_27_074812) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1745,6 +1745,17 @@ ActiveRecord::Schema.define(version: 2021_08_27_074615) do t.index ["p_product_ref_id"], name: "index_p_product_ref_price_histories_on_p_product_ref_id" end + create_table "p_product_ref_specs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.bigint "p_product_ref_id" + t.bigint "p_spec_type_id" + t.bigint "p_spec_value_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["p_product_ref_id"], name: "index_p_product_ref_specs_on_p_product_ref_id" + t.index ["p_spec_type_id"], name: "index_p_product_ref_specs_on_p_spec_type_id" + t.index ["p_spec_value_id"], name: "index_p_product_ref_specs_on_p_spec_value_id" + end + create_table "p_product_refs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "ref" t.integer "p_product_id" @@ -3126,6 +3137,9 @@ ActiveRecord::Schema.define(version: 2021_08_27_074615) do add_foreign_key "p_product_prices", "p_price_cats" add_foreign_key "p_product_prices", "p_product_refs" add_foreign_key "p_product_ref_price_histories", "p_product_refs" + add_foreign_key "p_product_ref_specs", "p_product_refs" + add_foreign_key "p_product_ref_specs", "p_spec_types" + add_foreign_key "p_product_ref_specs", "p_spec_values" add_foreign_key "p_product_utilisations", "p_products" add_foreign_key "p_product_utilisations", "p_utilisations" add_foreign_key "partition_lines", "partitions" diff --git a/test/fixtures/p_product_ref_specs.yml b/test/fixtures/p_product_ref_specs.yml new file mode 100644 index 0000000..e22eda8 --- /dev/null +++ b/test/fixtures/p_product_ref_specs.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + p_product_ref: one + p_spec_type: one + p_spec_value: one + +two: + p_product_ref: two + p_spec_type: two + p_spec_value: two diff --git a/test/models/p_product_ref_spec_test.rb b/test/models/p_product_ref_spec_test.rb new file mode 100644 index 0000000..59dbd78 --- /dev/null +++ b/test/models/p_product_ref_spec_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PProductRefSpecTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From c1d3c255ee5c2df96c23ee5e1ffbc39d776c4a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 10:29:37 +0200 Subject: [PATCH 11/24] Rename type column --- ...10827082814_rename_column_type_by_name_in_p_spec_types.rb | 5 +++++ db/schema.rb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20210827082814_rename_column_type_by_name_in_p_spec_types.rb diff --git a/db/migrate/20210827082814_rename_column_type_by_name_in_p_spec_types.rb b/db/migrate/20210827082814_rename_column_type_by_name_in_p_spec_types.rb new file mode 100644 index 0000000..4b890e8 --- /dev/null +++ b/db/migrate/20210827082814_rename_column_type_by_name_in_p_spec_types.rb @@ -0,0 +1,5 @@ +class RenameColumnTypeByNameInPSpecTypes < ActiveRecord::Migration[6.0] + def change + rename_column :p_spec_types, :type, :name + end +end diff --git a/db/schema.rb b/db/schema.rb index 7edf151..fc2f026 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_27_074812) do +ActiveRecord::Schema.define(version: 2021_08_27_082814) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1990,7 +1990,7 @@ ActiveRecord::Schema.define(version: 2021_08_27_074812) do end create_table "p_spec_types", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| - t.string "type" + t.string "name" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end From bc96c5bc23abd3ec09597c581c1f63f870fc20e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 10:44:15 +0200 Subject: [PATCH 12/24] form and menu for p_spec --- .../admin/p_product_ref_specs_controller.rb | 4 +++- app/controllers/application_controller.rb | 1 + app/models/p_product_ref.rb | 8 +++++++- app/models/p_product_ref_spec.rb | 13 +++++++++++++ app/models/p_spec_type.rb | 3 +++ app/models/p_spec_value.rb | 3 +++ .../admin/p_product_ref_specs/_form.html.haml | 11 +++++++---- .../_p_product_ref_spec.html.haml | 19 +++++++++++++++++-- app/views/admin/p_spec_types/_form.html.haml | 14 ++------------ app/views/admin/p_spec_values/_form.html.haml | 16 +++------------- 10 files changed, 59 insertions(+), 33 deletions(-) diff --git a/app/controllers/admin/p_product_ref_specs_controller.rb b/app/controllers/admin/p_product_ref_specs_controller.rb index 7522ebb..9935030 100644 --- a/app/controllers/admin/p_product_ref_specs_controller.rb +++ b/app/controllers/admin/p_product_ref_specs_controller.rb @@ -33,7 +33,9 @@ class Admin::PProductRefSpecsController < ApplicationController def new @p_product_ref_spec = PProductRefSpec.new - + @p_product_ref_spec.build_p_spec_type + @p_product_ref_spec.build_p_spec_value + end def edit diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6c5880a..0812d32 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -99,6 +99,7 @@ class ApplicationController < ActionController::Base if current_admin.has_permission?("boutique") set_sub_menu :stocks, :p_product_colors, "Couleurs" set_sub_menu :stocks, :p_article_serial_nums, "Numero série" + set_sub_menu :stocks, :p_product_ref_specs, "Specs" set_sub_menu :stocks, :p_product_powers, "Types de chargeurs" set_sub_menu :stocks, :p_product_zones, "Zones produits" diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 12da04b..07926e6 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -9,10 +9,14 @@ class PProductRef < ApplicationRecord has_many :p_product_ref_price_histories belongs_to :p_product_color + has_many :p_articles has_many :p_article_serial_nums, through: :p_articles accepts_nested_attributes_for :p_article_serial_nums, allow_destroy: true + has_many :p_product_ref_specs + accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true + #validates :ct_price_ht, :presence => true @@ -67,7 +71,9 @@ class PProductRef < ApplicationRecord def ca_name - self.p_product.name if self.p_product + if self.p_product + self.p_product.name + " - " + self.ct_sub_name + end end def ca_code diff --git a/app/models/p_product_ref_spec.rb b/app/models/p_product_ref_spec.rb index 3b80fce..a036951 100644 --- a/app/models/p_product_ref_spec.rb +++ b/app/models/p_product_ref_spec.rb @@ -2,4 +2,17 @@ class PProductRefSpec < ApplicationRecord belongs_to :p_product_ref belongs_to :p_spec_type belongs_to :p_spec_value + + accepts_nested_attributes_for :p_spec_type, :p_spec_value + + acts_as_sorting :fields => { + :id => {:name => "ID"}, + :p_product_ref => {:name => "Référence produit", :reorder => true}, + :p_product_ref_id => {:name => "ID Ref produit", :reorder => true}, + :p_spec_type => {:name => "Type", :reorder => true}, + :p_spec_value => {:name => "Valeur", :reorder => true}, + + :actions => {:name => "Actions", :reorder => true} + + } end diff --git a/app/models/p_spec_type.rb b/app/models/p_spec_type.rb index 30aea9e..a656aa6 100644 --- a/app/models/p_spec_type.rb +++ b/app/models/p_spec_type.rb @@ -1,2 +1,5 @@ class PSpecType < ApplicationRecord + has_many :p_product_ref_specs + + TYPES = ["Ram", "Stockage"] end diff --git a/app/models/p_spec_value.rb b/app/models/p_spec_value.rb index 17c7684..a44875c 100644 --- a/app/models/p_spec_value.rb +++ b/app/models/p_spec_value.rb @@ -1,2 +1,5 @@ class PSpecValue < ApplicationRecord + has_many :p_product_ref_specs + + UNITS = ["Go", "Mo"] end diff --git a/app/views/admin/p_product_ref_specs/_form.html.haml b/app/views/admin/p_product_ref_specs/_form.html.haml index 8fd4851..aed2719 100644 --- a/app/views/admin/p_product_ref_specs/_form.html.haml +++ b/app/views/admin/p_product_ref_specs/_form.html.haml @@ -2,13 +2,16 @@ .content =f.inputs do - = f.input :p_product_ref, :label => f.object.label_for(:p_product_ref) - = f.input :p_spec_type, :label => f.object.label_for(:p_spec_type) - = f.input :p_spec_value, :label => f.object.label_for(:p_spec_value) + = f.input :p_product_ref, as: :select, collection: PProductRef.pluck(:cc_name, :id) ,:label => f.object.label_for(:p_product_ref) + = f.semantic_fields_for :p_spec_type do | form | + =render :partial => "admin/p_spec_types/form", :locals => {:f => form} + = f.semantic_fields_for :p_spec_value do | form | + =render :partial => "admin/p_spec_values/form", :locals => {:f => form} + / = f.input :p_spec_value, :label => f.object.label_for(:p_spec_value) .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml b/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml index e91add0..b696059 100644 --- a/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml +++ b/app/views/admin/p_product_ref_specs/_p_product_ref_spec.html.haml @@ -1,6 +1,21 @@ %tr#p_product_ref_spec_row{:id => p_product_ref_spec.id} -tr = {} - + -tr[:p_product_ref] = capture do + %td + = p_product_ref_spec.p_product_ref.cc_name + + -tr[:p_product_ref_id] = capture do + %td + = p_product_ref_spec.p_product_ref.id + + -tr[:p_spec_type] = capture do + %td + = p_product_ref_spec.p_spec_type.name + -tr[:p_spec_value] = capture do + %td + = p_product_ref_spec.p_spec_value.value + = p_product_ref_spec.p_spec_value.unit + -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, p_product_ref_spec], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true @@ -13,4 +28,4 @@ - \ No newline at end of file + diff --git a/app/views/admin/p_spec_types/_form.html.haml b/app/views/admin/p_spec_types/_form.html.haml index 0a8acc2..ab615d2 100644 --- a/app/views/admin/p_spec_types/_form.html.haml +++ b/app/views/admin/p_spec_types/_form.html.haml @@ -1,12 +1,2 @@ -=semantic_form_for [:admin, @p_spec_type], :remote => true do |f| - - .content - =f.inputs do - = f.input :type, :label => f.object.label_for(:type) - - - - - - .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file +=f.inputs do + = f.input :name, :label => "Type", as: :select, collection: PSpecType::TYPES diff --git a/app/views/admin/p_spec_values/_form.html.haml b/app/views/admin/p_spec_values/_form.html.haml index 6d0339f..d44dd69 100644 --- a/app/views/admin/p_spec_values/_form.html.haml +++ b/app/views/admin/p_spec_values/_form.html.haml @@ -1,13 +1,3 @@ -=semantic_form_for [:admin, @p_spec_value], :remote => true do |f| - - .content - =f.inputs do - = f.input :value, :label => f.object.label_for(:value) - = f.input :unit, :label => f.object.label_for(:unit) - - - - - - .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file +=f.inputs do + = f.input :value, :label => "Valeur" + = f.input :unit, :label => "Unité", as: :select, collection: PSpecValue::UNITS From 11cf27c1cc883bc13799891698b533b6681a40c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 15:52:47 +0200 Subject: [PATCH 13/24] edit menu --- app/controllers/application_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0812d32..8ff974b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -66,13 +66,13 @@ class ApplicationController < ActionController::Base set_sub_menu :stocks, :p_products, "Produits", admin_p_products_path set_sub_menu :stocks, :p_product_refs, "Références", admin_p_product_refs_path set_sub_menu :stocks, :p_articles, "Articles", admin_p_articles_path - set_sub_menu :stocks, :promos_p_products, "Offres spots", promos_admin_p_products_path + # set_sub_menu :stocks, :promos_p_products, "Offres spots", promos_admin_p_products_path end if current_admin.has_permission?("product-cats") set_sub_menu :stocks, :p_product_cats, "Catégories produits", admin_p_product_cats_path - set_sub_menu :stocks, :p_product_sub_cats, "Sous catégories produits", admin_p_product_sub_cats_path + # set_sub_menu :stocks, :p_product_sub_cats, "Sous catégories produits", admin_p_product_sub_cats_path end @@ -99,6 +99,7 @@ class ApplicationController < ActionController::Base if current_admin.has_permission?("boutique") set_sub_menu :stocks, :p_product_colors, "Couleurs" set_sub_menu :stocks, :p_article_serial_nums, "Numero série" + set_sub_menu :stocks, :p_serial_num_types, "Types de Numero série" set_sub_menu :stocks, :p_product_ref_specs, "Specs" set_sub_menu :stocks, :p_product_powers, "Types de chargeurs" set_sub_menu :stocks, :p_product_zones, "Zones produits" From 181089058cb92b209c69d7cfa9ece4ccec680c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 15:53:37 +0200 Subject: [PATCH 14/24] p_spec & p_serial_num form and table --- .../admin/p_articles_controller.rb | 5 ++- .../admin/p_products_controller.rb | 7 +++- app/models/p_article.rb | 5 ++- app/models/p_product.rb | 7 ++++ app/models/p_serial_num_type.rb | 6 +++ .../p_article_serial_nums/_form.html.haml | 26 ++++++------ app/views/admin/p_articles/_form.html.haml | 5 ++- .../admin/p_product_ref_specs/_form.html.haml | 42 ++++++++++++------- .../admin/p_product_refs/_form.html.haml | 25 +++++++---- .../admin/p_serial_num_types/_form.html.haml | 4 +- app/views/admin/p_spec_values/_form.html.haml | 7 +++- 11 files changed, 94 insertions(+), 45 deletions(-) diff --git a/app/controllers/admin/p_articles_controller.rb b/app/controllers/admin/p_articles_controller.rb index 03af6b9..006eeda 100644 --- a/app/controllers/admin/p_articles_controller.rb +++ b/app/controllers/admin/p_articles_controller.rb @@ -33,7 +33,10 @@ class Admin::PArticlesController < ApplicationController def new @p_article = PArticle.new - @p_article.build_p_product_ref + @p_article_serial_nums = @p_article.p_article_serial_nums.build + + @p_serial_num_type = @p_article_serial_nums.build_p_serial_num_type + @p_serial_num_value = @p_article_serial_nums.build_p_serial_num_value end def edit diff --git a/app/controllers/admin/p_products_controller.rb b/app/controllers/admin/p_products_controller.rb index a0ae7f9..9cb4915 100644 --- a/app/controllers/admin/p_products_controller.rb +++ b/app/controllers/admin/p_products_controller.rb @@ -73,8 +73,11 @@ class Admin::PProductsController < ApplicationController @p_product = PProduct.new #(:p_customer_cat_ids => [3]) - @p_product.p_product_refs << PProductRef.new - + # @p_product.p_product_refs << PProductRef.new + @p_product_refs = @p_product.p_product_refs.build + @p_product_ref_specs = @p_product_refs.p_product_ref_specs.build + @p_spec_type = @p_product_ref_specs.build_p_spec_type + @p_spec_value = @p_product_ref_specs.build_p_spec_value end diff --git a/app/models/p_article.rb b/app/models/p_article.rb index d2825e3..3ff569b 100644 --- a/app/models/p_article.rb +++ b/app/models/p_article.rb @@ -3,9 +3,10 @@ class PArticle < ApplicationRecord has_one :p_product, through: :p_product_ref belongs_to :p_product_color has_many :p_article_serial_nums, dependent: :destroy - # accepts_nested_attributes_for :p_article_serial_nums + accepts_nested_attributes_for :p_article_serial_nums validates_presence_of :p_product_ref - + # has_many :p_product_ref_specs, through: :p_product_ref + # accepts_nested_attributes_for :p_product_ref_specs acts_as_sorting :fields => { :id => {:name => "id", :reorder => true}, diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 12a0795..893a83c 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -17,6 +17,13 @@ class PProduct < ApplicationRecord has_many :p_articles, through: :p_product_refs + # has_many :p_product_ref_specs, through: :p_product_refs + # accepts_nested_attributes_for :p_product_ref_specs + # # has_many :p_spec_types, through: :p_product_ref_specs + # has_many :p_spec_values, through: :p_product_ref_specs + # accepts_nested_attributes_for :p_spec_types, allow_destroy: true + # accepts_nested_attributes_for :p_spec_values, allow_destroy: true + has_many :p_product_images diff --git a/app/models/p_serial_num_type.rb b/app/models/p_serial_num_type.rb index 83f5ce7..596d817 100644 --- a/app/models/p_serial_num_type.rb +++ b/app/models/p_serial_num_type.rb @@ -1,3 +1,9 @@ class PSerialNumType < ApplicationRecord has_many :p_article_serial_nums + + acts_as_sorting :fields => { + :id => {:name => "id", :reorder => true}, + :name => {:name => "Type", :reorder => true}, + :actions => {:name => "Actions", :reorder => false}, + } end diff --git a/app/views/admin/p_article_serial_nums/_form.html.haml b/app/views/admin/p_article_serial_nums/_form.html.haml index caad0f5..34d893a 100644 --- a/app/views/admin/p_article_serial_nums/_form.html.haml +++ b/app/views/admin/p_article_serial_nums/_form.html.haml @@ -1,16 +1,18 @@ -=semantic_form_for [:admin, @p_article_serial_num], :remote => true do |f| +- if params[:controller] == "admin/p_article_serial_nums" + =semantic_form_for [:admin, @p_article_serial_num], :remote => true do |f| - .content + .content + =f.inputs do + = f.input :p_article, as: :select, collection: PArticle.pluck(:id) ,:label => f.object.label_for(:p_article_id) + = f.input :p_serial_num_type, :label => f.object.label_for(:p_serial_num_type) + = f.semantic_fields_for :p_serial_num_value do | form | + =render :partial => "admin/p_serial_num_values/form", :locals => {:f => form} + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + +- else + .p_article_serial_nums_form.field =f.inputs do - = f.input :p_article, as: :select, collection: PArticle.pluck(:id) ,:label => f.object.label_for(:p_article) - = f.input :p_serial_num_type, :label => f.object.label_for(:p_serial_num_type) + = f.input :p_serial_num_type, :label => "type", as: :select, collection: PSerialNumType.pluck(:name, :id) = f.semantic_fields_for :p_serial_num_value do | form | - =render :partial => "admin/p_serial_num_values/form", :locals => {:f => form} - - - - - - .actions=f.submit "sauvegarder", :class => "btn btn-primary" - diff --git a/app/views/admin/p_articles/_form.html.haml b/app/views/admin/p_articles/_form.html.haml index 8ab680b..f89186c 100644 --- a/app/views/admin/p_articles/_form.html.haml +++ b/app/views/admin/p_articles/_form.html.haml @@ -2,7 +2,10 @@ .content =f.inputs do - = f.input :p_product_ref, as: :select, collection: PProductRef.all, :label => f.object.label_for(:p_product_ref) + = f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct, :label => f.object.label_for(:p_product_ref) + = f.semantic_fields_for :p_article_serial_nums do |f| + =render :partial => "admin/p_article_serial_nums/form", :locals => {:f => f} + diff --git a/app/views/admin/p_product_ref_specs/_form.html.haml b/app/views/admin/p_product_ref_specs/_form.html.haml index aed2719..7fae978 100644 --- a/app/views/admin/p_product_ref_specs/_form.html.haml +++ b/app/views/admin/p_product_ref_specs/_form.html.haml @@ -1,17 +1,27 @@ -=semantic_form_for [:admin, @p_product_ref_spec], :remote => true do |f| +- if params[:controller] == "admin/p_product_ref_specs" + =semantic_form_for [:admin, @p_product_ref_spec], :remote => true do |f| + .content + =f.inputs do + = f.input :p_product_ref, as: :select, collection: PProductRef.pluck(:cc_name, :id) ,:label => f.object.label_for(:p_product_ref) + = f.semantic_fields_for :p_spec_type do | form | + =render :partial => "admin/p_spec_types/form", :locals => {:f => form} + = f.semantic_fields_for :p_spec_value do | form | + =render :partial => "admin/p_spec_values/form", :locals => {:f => form} - .content - =f.inputs do - = f.input :p_product_ref, as: :select, collection: PProductRef.pluck(:cc_name, :id) ,:label => f.object.label_for(:p_product_ref) - = f.semantic_fields_for :p_spec_type do | form | - =render :partial => "admin/p_spec_types/form", :locals => {:f => form} - = f.semantic_fields_for :p_spec_value do | form | - =render :partial => "admin/p_spec_values/form", :locals => {:f => form} - / = f.input :p_spec_value, :label => f.object.label_for(:p_spec_value) - - - - - - .actions=f.submit "sauvegarder", :class => "btn btn-primary" - + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + +- else + .p_product_ref_spec_form.field + %tr + %td + %h4 spec : + + %td + =form.inputs do + = form.semantic_fields_for :p_spec_type do | f | + =render :partial => "admin/p_spec_types/form", :locals => {:f => f} + = form.semantic_fields_for :p_spec_value do | f | + =render :partial => "admin/p_spec_values/form", :locals => {:f => f} + %tr + %td + = link_to_remove_fields ic(:"trash-o"), form diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index bc9ca3b..55f48bf 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -4,10 +4,8 @@ %table.form-table %tr - %td - =# form.input :enabled, :label => "Actif ?" - %td - =# form.input :assembled, :label => "Assemblé ?", :input_html => {:onchange => 'if ($(this).is(":checked")) {$(this).closest(".field").find(".p_product_assembleds_part").show();}else{$(this).closest(".field").find(".p_product_assembleds_part").hide();}'} + =# form.input :enabled, :label => "Actif ?" + =# form.input :assembled, :label => "Assemblé ?", :input_html => {:onchange => 'if ($(this).is(":checked")) {$(this).closest(".field").find(".p_product_assembleds_part").show();}else{$(this).closest(".field").find(".p_product_assembleds_part").hide();}'} %td = form.input :ref, :label => "Réf int. :" @@ -21,8 +19,21 @@ %td =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true - - =# form.input :s_brand_id, :label => "Marque :", :collection => SBrand.all, :as => :select, :include_blank => true + + -if false + %td + =form.semantic_fields_for :p_spec_type do |f| + =render :partial => "admin/p_spec_types/form", :locals => {:f => f} + =form.semantic_fields_for :p_spec_value do |f| + =render :partial => "admin/p_spec_values/form", :locals => {:f => f} + + + %tr + .p_product_ref_specs_form + = form.semantic_fields_for :p_product_ref_specs do |f| + =render :partial => "admin/p_product_ref_specs/form", :locals => {:form => f} + %p= link_to_add_fields "Ajouter une spec", form, :p_product_ref_specs + %tr @@ -42,4 +53,4 @@ %p= link_to_add_fields "Ajouter une référence fournisseur", form, :fournisseur_product_refs - \ No newline at end of file + diff --git a/app/views/admin/p_serial_num_types/_form.html.haml b/app/views/admin/p_serial_num_types/_form.html.haml index 70b89fe..99f609b 100644 --- a/app/views/admin/p_serial_num_types/_form.html.haml +++ b/app/views/admin/p_serial_num_types/_form.html.haml @@ -2,11 +2,11 @@ .content =f.inputs do - = f.input :type, :label => f.object.label_for(:type) + = f.input :name, :label => f.object.label_for(:name) .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/p_spec_values/_form.html.haml b/app/views/admin/p_spec_values/_form.html.haml index d44dd69..3c4c805 100644 --- a/app/views/admin/p_spec_values/_form.html.haml +++ b/app/views/admin/p_spec_values/_form.html.haml @@ -1,3 +1,6 @@ + =f.inputs do - = f.input :value, :label => "Valeur" - = f.input :unit, :label => "Unité", as: :select, collection: PSpecValue::UNITS + %td + = f.input :value, :label => "Valeur" + %td + = f.input :unit, :label => "Unité", as: :select, collection: PSpecValue::UNITS From 7c0bfc9ae4072eb592d99d0f4cc48d0707bd6707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 18:22:48 +0200 Subject: [PATCH 15/24] search for p_article, p_serial_num, p_article_serial_num --- .../admin/p_article_serial_nums_controller.rb | 14 ++++++++++++- .../admin/p_articles_controller.rb | 21 +++++++++++++++++++ .../admin/p_serial_num_types_controller.rb | 5 +++++ app/models/p_article.rb | 3 ++- app/models/p_article_serial_num.rb | 1 + app/models/p_serial_num_value.rb | 1 + .../p_article_serial_nums/index.html.haml | 13 ++++++++++++ app/views/admin/p_articles/index.html.haml | 16 ++++++++++++++ .../admin/p_serial_num_types/index.html.haml | 8 +++++++ 9 files changed, 80 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/p_article_serial_nums_controller.rb b/app/controllers/admin/p_article_serial_nums_controller.rb index 069ade6..3663027 100644 --- a/app/controllers/admin/p_article_serial_nums_controller.rb +++ b/app/controllers/admin/p_article_serial_nums_controller.rb @@ -11,7 +11,19 @@ class Admin::PArticleSerialNumsController < ApplicationController end def index - @p_article_serial_nums = PArticleSerialNum.all + @p_article_serial_nums = PArticleSerialNum.includes(:p_serial_num_type, :p_product_ref, :p_serial_num_value).all + + if params[:search][:p_serial_num_type_name] + @p_article_serial_nums = @p_article_serial_nums.joins(:p_serial_num_type).where("name LIKE ?", "#{params[:search][:p_serial_num_type_name]}%") + end + + if params[:search][:p_product_ref_cc_name] + @p_article_serial_nums = @p_article_serial_nums.joins(:p_article, :p_product_ref).where("cc_name LIKE ?","#{params[:search][:p_product_ref_cc_name]}%") + end + + if params[:search][:p_serial_num_value_value] + @p_article_serial_nums = @p_article_serial_nums.joins(:p_serial_num_value).where("value LIKE ?","#{params[:search][:p_serial_num_value_value]}%") + end @p_article_serial_nums = sort_by_sorting(@p_article_serial_nums, "id DESC") respond_to do |format| diff --git a/app/controllers/admin/p_articles_controller.rb b/app/controllers/admin/p_articles_controller.rb index 006eeda..24ba78d 100644 --- a/app/controllers/admin/p_articles_controller.rb +++ b/app/controllers/admin/p_articles_controller.rb @@ -13,6 +13,27 @@ class Admin::PArticlesController < ApplicationController def index @p_articles = PArticle.all + if params[:search][:p_product_color].to_s != "" + if params[:search][:p_product_color].to_s == "null" + @p_articles = @p_articles.where(:p_product_color => nil) + else + @p_articles = @p_articles.where(:p_product_color => params[:search][:p_product_color]) + end + end + + if params[:search][:p_product_ref_cc_name] + @p_articles = @p_articles.joins(:p_product_ref).where("cc_name LIKE ?", "#{params[:search][:p_product_ref_cc_name]}%") + end + + if params[:search][:p_product_ref_cc_code] + @p_articles = @p_articles.joins(:p_product_ref).where("cc_code LIKE ?", "#{params[:search][:p_product_ref_cc_code]}%") + end + + if params[:search][:p_serial_num_value] + @p_articles = @p_articles.joins(:p_serial_num_values).where("value LIKE ?", "#{params[:search][:p_serial_num_value]}%") + end + + @p_articles = sort_by_sorting(@p_articles, "id DESC") respond_to do |format| format.html{ diff --git a/app/controllers/admin/p_serial_num_types_controller.rb b/app/controllers/admin/p_serial_num_types_controller.rb index 7fa9e38..34a1208 100644 --- a/app/controllers/admin/p_serial_num_types_controller.rb +++ b/app/controllers/admin/p_serial_num_types_controller.rb @@ -13,6 +13,11 @@ class Admin::PSerialNumTypesController < ApplicationController def index @p_serial_num_types = PSerialNumType.all + if params[:search][:name] + @p_serial_num_types = @p_serial_num_types.where("name LIKE ?","#{params[:search][:name]}%") + end + + @p_serial_num_types = sort_by_sorting(@p_serial_num_types, "id DESC") respond_to do |format| format.html{ diff --git a/app/models/p_article.rb b/app/models/p_article.rb index 3ff569b..3464c36 100644 --- a/app/models/p_article.rb +++ b/app/models/p_article.rb @@ -1,8 +1,9 @@ class PArticle < ApplicationRecord belongs_to :p_product_ref has_one :p_product, through: :p_product_ref - belongs_to :p_product_color + has_one :p_product_color, through: :p_product_ref has_many :p_article_serial_nums, dependent: :destroy + has_many :p_serial_num_values, through: :p_article_serial_nums accepts_nested_attributes_for :p_article_serial_nums validates_presence_of :p_product_ref # has_many :p_product_ref_specs, through: :p_product_ref diff --git a/app/models/p_article_serial_num.rb b/app/models/p_article_serial_num.rb index aae27cd..5941588 100644 --- a/app/models/p_article_serial_num.rb +++ b/app/models/p_article_serial_num.rb @@ -2,6 +2,7 @@ class PArticleSerialNum < ApplicationRecord belongs_to :p_article belongs_to :p_serial_num_type belongs_to :p_serial_num_value, inverse_of: :p_article_serial_nums + has_one :p_product_ref, through: :p_article accepts_nested_attributes_for :p_serial_num_value acts_as_sorting :fields => { diff --git a/app/models/p_serial_num_value.rb b/app/models/p_serial_num_value.rb index 12a74bd..c8a476f 100644 --- a/app/models/p_serial_num_value.rb +++ b/app/models/p_serial_num_value.rb @@ -1,3 +1,4 @@ class PSerialNumValue < ApplicationRecord has_many :p_article_serial_nums, inverse_of: :p_serial_num_value + has_many :p_articles, through: :p_article_serial_nums end diff --git a/app/views/admin/p_article_serial_nums/index.html.haml b/app/views/admin/p_article_serial_nums/index.html.haml index 2a60940..9d294bd 100644 --- a/app/views/admin/p_article_serial_nums/index.html.haml +++ b/app/views/admin/p_article_serial_nums/index.html.haml @@ -7,6 +7,19 @@ .qi_search_row =form_tag "", :method => "get", :onsubmit => "" do + =hidden_field_tag :column, params[:column] + =hidden_field_tag :direction, params[:direction] + + %table + %tr + %td=text_field_tag "search[p_serial_num_type_name]", params[:search][:p_serial_num_type_name],:class => "form-control", :placeholder => "Type" + + %td=text_field_tag "search[p_product_ref_cc_name]", params[:search][:p_product_ref_cc_name],:class => "form-control", :placeholder => "Article" + + %td=text_field_tag "search[p_serial_num_value_value]", params[:search][:p_serial_num_value_value],:class => "form-control", :placeholder => "N° de serie" + + + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_article_serial_nums} diff --git a/app/views/admin/p_articles/index.html.haml b/app/views/admin/p_articles/index.html.haml index 2b77ca5..8bc5e78 100644 --- a/app/views/admin/p_articles/index.html.haml +++ b/app/views/admin/p_articles/index.html.haml @@ -7,6 +7,22 @@ .qi_search_row =form_tag "", :method => "get", :onsubmit => "" do + =hidden_field_tag :column, params[:column] + =hidden_field_tag :direction, params[:direction] + + %table + %tr + %td=text_field_tag "search[p_product_ref_cc_code]", params[:search][:p_product_ref_cc_code],:class => "form-control", :placeholder => "Code" + + %td=text_field_tag "search[p_product_ref_cc_name]", params[:search][:p_product_ref_cc_name],:class => "form-control", :placeholder => "Article" + + %td=text_field_tag "search[p_serial_num_value]", params[:search][:p_serial_num_value],:class => "form-control", :placeholder => "N° de serie" + + %td + Couleur : + =select_tag "search[p_product_color]", options_for_select([["",""],["Aucune","null"]]+PProductColor.pluck(:color, :id), params[:search][:p_product_color]) + + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_articles} diff --git a/app/views/admin/p_serial_num_types/index.html.haml b/app/views/admin/p_serial_num_types/index.html.haml index 6e9745d..522508d 100644 --- a/app/views/admin/p_serial_num_types/index.html.haml +++ b/app/views/admin/p_serial_num_types/index.html.haml @@ -7,6 +7,14 @@ .qi_search_row =form_tag "", :method => "get", :onsubmit => "" do + =hidden_field_tag :column, params[:column] + =hidden_field_tag :direction, params[:direction] + + %table + %tr + + %td=text_field_tag "search[name]", params[:search][:name],:class => "form-control", :placeholder => "Type" + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_serial_num_types} From bea1f58564b91e111ea6886306763aae9523a8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 18:43:38 +0200 Subject: [PATCH 16/24] generate p_grade --- app/controllers/admin/p_grades_controller.rb | 76 ++++++++++++++++++++ app/models/p_grade.rb | 2 + app/views/admin/p_grades/_form.html.haml | 12 ++++ app/views/admin/p_grades/_p_grade.html.haml | 16 +++++ app/views/admin/p_grades/create.js.erb | 2 + app/views/admin/p_grades/destroy.js.erb | 1 + app/views/admin/p_grades/edit.js.erb | 1 + app/views/admin/p_grades/index.html.haml | 16 +++++ app/views/admin/p_grades/new.js.erb | 1 + app/views/admin/p_grades/show.html.haml | 10 +++ app/views/admin/p_grades/update.js.erb | 2 + config/routes.rb | 11 +++ db/migrate/20210827164230_create_p_grades.rb | 9 +++ db/schema.rb | 8 ++- test/fixtures/p_grades.yml | 7 ++ test/models/p_grade_test.rb | 7 ++ 16 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/p_grades_controller.rb create mode 100644 app/models/p_grade.rb create mode 100644 app/views/admin/p_grades/_form.html.haml create mode 100644 app/views/admin/p_grades/_p_grade.html.haml create mode 100644 app/views/admin/p_grades/create.js.erb create mode 100644 app/views/admin/p_grades/destroy.js.erb create mode 100644 app/views/admin/p_grades/edit.js.erb create mode 100644 app/views/admin/p_grades/index.html.haml create mode 100644 app/views/admin/p_grades/new.js.erb create mode 100644 app/views/admin/p_grades/show.html.haml create mode 100644 app/views/admin/p_grades/update.js.erb create mode 100644 db/migrate/20210827164230_create_p_grades.rb create mode 100644 test/fixtures/p_grades.yml create mode 100644 test/models/p_grade_test.rb diff --git a/app/controllers/admin/p_grades_controller.rb b/app/controllers/admin/p_grades_controller.rb new file mode 100644 index 0000000..7a77712 --- /dev/null +++ b/app/controllers/admin/p_grades_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::PGradesController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @p_grades = PGrade.all + + @p_grades = sort_by_sorting(@p_grades, "id DESC") + respond_to do |format| + format.html{ + + params[:search][:per_page] = params[:search][:per_page] || 100 + per_page = params[:search][:per_page] + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @p_grades = @p_grades.page(page).per(per_page) + + } + end + end + + def show + @p_grade = PGrade.find(params[:id]) + + end + + def new + @p_grade = PGrade.new + + end + + def edit + @p_grade = PGrade.find(params[:id]) + + end + + def create + @p_grade = PGrade.new(params.require(:p_grade).permit!) + + if @p_grade.save + + else + render action: "new" + + end + + end + + + def update + @p_grade = PGrade.find(params[:id]) + + + if @p_grade.update_attributes(params.require(:p_grade).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @p_grade = PGrade.find(params[:id]) + @p_grade.destroy + + end +end diff --git a/app/models/p_grade.rb b/app/models/p_grade.rb new file mode 100644 index 0000000..a60cee5 --- /dev/null +++ b/app/models/p_grade.rb @@ -0,0 +1,2 @@ +class PGrade < ApplicationRecord +end diff --git a/app/views/admin/p_grades/_form.html.haml b/app/views/admin/p_grades/_form.html.haml new file mode 100644 index 0000000..00d2fa0 --- /dev/null +++ b/app/views/admin/p_grades/_form.html.haml @@ -0,0 +1,12 @@ +=semantic_form_for [:admin, @p_grade], :remote => true do |f| + + .content + =f.inputs do + = f.input :grade, :label => f.object.label_for(:grade) + + + + + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + \ No newline at end of file diff --git a/app/views/admin/p_grades/_p_grade.html.haml b/app/views/admin/p_grades/_p_grade.html.haml new file mode 100644 index 0000000..9608e54 --- /dev/null +++ b/app/views/admin/p_grades/_p_grade.html.haml @@ -0,0 +1,16 @@ +%tr#p_grade_row{:id => p_grade.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_grade], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_grade_path(p_grade), :remote => true + = link_to i(:eye), admin_p_grade_path(p_grade), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_grade} + + + + \ No newline at end of file diff --git a/app/views/admin/p_grades/create.js.erb b/app/views/admin/p_grades/create.js.erb new file mode 100644 index 0000000..d562c04 --- /dev/null +++ b/app/views/admin/p_grades/create.js.erb @@ -0,0 +1,2 @@ +$('#p_grades_rows').prepend("<%= escape_javascript(render(@p_grade))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/p_grades/destroy.js.erb b/app/views/admin/p_grades/destroy.js.erb new file mode 100644 index 0000000..7e6a917 --- /dev/null +++ b/app/views/admin/p_grades/destroy.js.erb @@ -0,0 +1 @@ +$('#p_grade_row_<%= @p_grade.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/p_grades/edit.js.erb b/app/views/admin/p_grades/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_grades/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_grades/index.html.haml b/app/views/admin/p_grades/index.html.haml new file mode 100644 index 0000000..4dbb173 --- /dev/null +++ b/app/views/admin/p_grades/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_p_grade_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =PGrade.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_grades} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_grades} + + + diff --git a/app/views/admin/p_grades/new.js.erb b/app/views/admin/p_grades/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/p_grades/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/p_grades/show.html.haml b/app/views/admin/p_grades/show.html.haml new file mode 100644 index 0000000..e63e6fc --- /dev/null +++ b/app/views/admin/p_grades/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @p_grade \ No newline at end of file diff --git a/app/views/admin/p_grades/update.js.erb b/app/views/admin/p_grades/update.js.erb new file mode 100644 index 0000000..0371e07 --- /dev/null +++ b/app/views/admin/p_grades/update.js.erb @@ -0,0 +1,2 @@ +$('#p_grade_row_<%= @p_grade.id %>').replaceWith("<%= escape_javascript(render(@p_grade))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a585b05..cdc0dc1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :p_grades do + member do + + end + collection do + + end + end + end + namespace :admin do resources :p_product_ref_specs do member do diff --git a/db/migrate/20210827164230_create_p_grades.rb b/db/migrate/20210827164230_create_p_grades.rb new file mode 100644 index 0000000..3851843 --- /dev/null +++ b/db/migrate/20210827164230_create_p_grades.rb @@ -0,0 +1,9 @@ +class CreatePGrades < ActiveRecord::Migration[6.0] + def change + create_table :p_grades do |t| + t.string :grade + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fc2f026..feae45f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_27_082814) do +ActiveRecord::Schema.define(version: 2021_08_27_164230) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1462,6 +1462,12 @@ ActiveRecord::Schema.define(version: 2021_08_27_082814) do t.datetime "updated_at", precision: 6, null: false end + create_table "p_grades", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| + t.string "grade" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "p_nutris", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" t.boolean "public", default: true diff --git a/test/fixtures/p_grades.yml b/test/fixtures/p_grades.yml new file mode 100644 index 0000000..345f425 --- /dev/null +++ b/test/fixtures/p_grades.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + grade: MyString + +two: + grade: MyString diff --git a/test/models/p_grade_test.rb b/test/models/p_grade_test.rb new file mode 100644 index 0000000..7078651 --- /dev/null +++ b/test/models/p_grade_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PGradeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From b61ff2567f44a76509fcf9488cfaa0a721d03ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 18:51:14 +0200 Subject: [PATCH 17/24] add p_grade references to p_article --- .../20210827164533_add_p_grade_references_to_p_articles.rb | 5 +++++ db/schema.rb | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210827164533_add_p_grade_references_to_p_articles.rb diff --git a/db/migrate/20210827164533_add_p_grade_references_to_p_articles.rb b/db/migrate/20210827164533_add_p_grade_references_to_p_articles.rb new file mode 100644 index 0000000..6185877 --- /dev/null +++ b/db/migrate/20210827164533_add_p_grade_references_to_p_articles.rb @@ -0,0 +1,5 @@ +class AddPGradeReferencesToPArticles < ActiveRecord::Migration[6.0] + def change + add_reference :p_articles, :p_grade, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index feae45f..6f8e516 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_27_164230) do +ActiveRecord::Schema.define(version: 2021_08_27_164533) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -985,6 +985,8 @@ ActiveRecord::Schema.define(version: 2021_08_27_164230) do t.bigint "p_product_ref_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.bigint "p_grade_id" + t.index ["p_grade_id"], name: "index_p_articles_on_p_grade_id" t.index ["p_product_ref_id"], name: "index_p_articles_on_p_product_ref_id" end @@ -3112,6 +3114,7 @@ ActiveRecord::Schema.define(version: 2021_08_27_164230) do add_foreign_key "p_article_serial_nums", "p_articles" add_foreign_key "p_article_serial_nums", "p_serial_num_types" add_foreign_key "p_article_serial_nums", "p_serial_num_values" + add_foreign_key "p_articles", "p_grades" add_foreign_key "p_articles", "p_product_refs" add_foreign_key "p_commercial_object_brands", "p_commercial_objectives" add_foreign_key "p_commercial_object_brands", "p_commercials" From de44f95293c84aa6a2238c9c3f55af3fc881f224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 19:42:35 +0200 Subject: [PATCH 18/24] color search ok --- app/controllers/admin/p_articles_controller.rb | 8 ++++++-- app/views/admin/p_articles/index.html.haml | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/p_articles_controller.rb b/app/controllers/admin/p_articles_controller.rb index 24ba78d..ef8b79a 100644 --- a/app/controllers/admin/p_articles_controller.rb +++ b/app/controllers/admin/p_articles_controller.rb @@ -15,9 +15,9 @@ class Admin::PArticlesController < ApplicationController if params[:search][:p_product_color].to_s != "" if params[:search][:p_product_color].to_s == "null" - @p_articles = @p_articles.where(:p_product_color => nil) + @p_articles = @p_articles.joins(:p_product_ref).where("p_product_color_id = ?", nil) else - @p_articles = @p_articles.where(:p_product_color => params[:search][:p_product_color]) + @p_articles = @p_articles.joins(:p_product_ref).where("p_product_color_id = ?", params[:search][:p_product_color]) end end @@ -25,6 +25,10 @@ class Admin::PArticlesController < ApplicationController @p_articles = @p_articles.joins(:p_product_ref).where("cc_name LIKE ?", "#{params[:search][:p_product_ref_cc_name]}%") end + if params[:search][:p_grade_id] + @p_articles = @p_articles.where("p_grade_id LIKE ?", "#{params[:search][:p_grade_id]}%") + end + if params[:search][:p_product_ref_cc_code] @p_articles = @p_articles.joins(:p_product_ref).where("cc_code LIKE ?", "#{params[:search][:p_product_ref_cc_code]}%") end diff --git a/app/views/admin/p_articles/index.html.haml b/app/views/admin/p_articles/index.html.haml index 8bc5e78..2123172 100644 --- a/app/views/admin/p_articles/index.html.haml +++ b/app/views/admin/p_articles/index.html.haml @@ -18,9 +18,12 @@ %td=text_field_tag "search[p_serial_num_value]", params[:search][:p_serial_num_value],:class => "form-control", :placeholder => "N° de serie" + %td.pl-2 Grade : + %td=select_tag "search[p_grade_id]", options_for_select([["",""],["Aucune","null"]]+PGrade.pluck(:grade, :id), params[:search][:p_grade_id]), class: "custom-select" + + %td.pl-2 Couleur : %td - Couleur : - =select_tag "search[p_product_color]", options_for_select([["",""],["Aucune","null"]]+PProductColor.pluck(:color, :id), params[:search][:p_product_color]) + =select_tag "search[p_product_color]", options_for_select([["",""],["Aucune","null"]]+PProductColor.pluck(:color, :id), params[:search][:p_product_color]),class: "custom-select" =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_articles} From d597960ba9a2450f8ca38390c7d0fbd25a1e5a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 27 Aug 2021 19:43:54 +0200 Subject: [PATCH 19/24] add grade form & menu --- app/controllers/admin/p_serial_num_types_controller.rb | 2 +- app/controllers/application_controller.rb | 3 ++- app/models/p_article.rb | 4 ++++ app/models/p_grade.rb | 8 ++++++++ app/views/admin/p_articles/_form.html.haml | 1 + app/views/admin/p_articles/_p_article.html.haml | 3 +++ app/views/admin/p_serial_num_types/index.html.haml | 4 ++-- 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/p_serial_num_types_controller.rb b/app/controllers/admin/p_serial_num_types_controller.rb index 34a1208..ef1f006 100644 --- a/app/controllers/admin/p_serial_num_types_controller.rb +++ b/app/controllers/admin/p_serial_num_types_controller.rb @@ -14,7 +14,7 @@ class Admin::PSerialNumTypesController < ApplicationController @p_serial_num_types = PSerialNumType.all if params[:search][:name] - @p_serial_num_types = @p_serial_num_types.where("name LIKE ?","#{params[:search][:name]}%") + @p_serial_num_types = @p_serial_num_types.where("id = ?","#{params[:search][:name]}%") end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8ff974b..3ff8eaa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -98,9 +98,10 @@ class ApplicationController < ActionController::Base if current_admin.has_permission?("boutique") set_sub_menu :stocks, :p_product_colors, "Couleurs" - set_sub_menu :stocks, :p_article_serial_nums, "Numero série" + set_sub_menu :stocks, :p_article_serial_nums, "Numeros série" set_sub_menu :stocks, :p_serial_num_types, "Types de Numero série" set_sub_menu :stocks, :p_product_ref_specs, "Specs" + set_sub_menu :stocks, :p_grades, "Grades" set_sub_menu :stocks, :p_product_powers, "Types de chargeurs" set_sub_menu :stocks, :p_product_zones, "Zones produits" diff --git a/app/models/p_article.rb b/app/models/p_article.rb index 3464c36..f1a0294 100644 --- a/app/models/p_article.rb +++ b/app/models/p_article.rb @@ -1,10 +1,13 @@ class PArticle < ApplicationRecord + belongs_to :p_grade belongs_to :p_product_ref has_one :p_product, through: :p_product_ref has_one :p_product_color, through: :p_product_ref + has_many :p_article_serial_nums, dependent: :destroy has_many :p_serial_num_values, through: :p_article_serial_nums accepts_nested_attributes_for :p_article_serial_nums + validates_presence_of :p_product_ref # has_many :p_product_ref_specs, through: :p_product_ref # accepts_nested_attributes_for :p_product_ref_specs @@ -13,6 +16,7 @@ class PArticle < ApplicationRecord :id => {:name => "id", :reorder => true}, :p_product_ref_code => {:name => "Code ref", :reorder => true}, :p_product_ref => {:name => "Désignation", :reorder => true}, + :p_grade => {:name => "Grade", :reorder => true}, :color => {:name => "Couleur"}, :p_article_serial_nums => {:name => "N° identifiants"}, :actions => {:name => "Actions", :reorder => false}, diff --git a/app/models/p_grade.rb b/app/models/p_grade.rb index a60cee5..949f5e1 100644 --- a/app/models/p_grade.rb +++ b/app/models/p_grade.rb @@ -1,2 +1,10 @@ class PGrade < ApplicationRecord + has_many :p_articles + + acts_as_sorting :fields => { + :id => {:name => "id", :reorder => true}, + :grade => {:name => "Grade", :reorder => true}, + :actions => {:name => "Actions", :reorder => false}, + } + end diff --git a/app/views/admin/p_articles/_form.html.haml b/app/views/admin/p_articles/_form.html.haml index f89186c..f336fa7 100644 --- a/app/views/admin/p_articles/_form.html.haml +++ b/app/views/admin/p_articles/_form.html.haml @@ -3,6 +3,7 @@ .content =f.inputs do = f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct, :label => f.object.label_for(:p_product_ref) + = f.input :p_grade, as: :select, collection: PGrade.pluck(:grade, :id), :label => "Grade" = f.semantic_fields_for :p_article_serial_nums do |f| =render :partial => "admin/p_article_serial_nums/form", :locals => {:f => f} diff --git a/app/views/admin/p_articles/_p_article.html.haml b/app/views/admin/p_articles/_p_article.html.haml index 13e29ca..f3631af 100644 --- a/app/views/admin/p_articles/_p_article.html.haml +++ b/app/views/admin/p_articles/_p_article.html.haml @@ -5,6 +5,9 @@ %td = p_article.p_product_ref.code + -tr[:p_grade] = capture do + %td + = p_article.p_grade.grade -tr[:color] = capture do %td diff --git a/app/views/admin/p_serial_num_types/index.html.haml b/app/views/admin/p_serial_num_types/index.html.haml index 522508d..80034b4 100644 --- a/app/views/admin/p_serial_num_types/index.html.haml +++ b/app/views/admin/p_serial_num_types/index.html.haml @@ -12,8 +12,8 @@ %table %tr - - %td=text_field_tag "search[name]", params[:search][:name],:class => "form-control", :placeholder => "Type" + %td Type : + %td=select_tag "search[name]", options_for_select([["",""],["Aucune","null"]]+PSerialNumType.pluck(:name, :id), params[:search][:name]), class: "custom-select" =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_serial_num_types} From 3f22e0c5d53aae9d59200b7c338fac40d145c014 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Mon, 30 Aug 2021 10:17:59 +0200 Subject: [PATCH 20/24] SUite --- .../(__TEMPLATE__)c | Bin 0 -> 5937 bytes .../admin/p_product_ref_specs/_form.html.haml | 28 ++++++++++-------- .../admin/p_product_refs/_form.html.haml | 9 +++--- 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 .sass-cache/d6dc4d64a1af1ff4c7903858d908aeb1a0a8c2c1/(__TEMPLATE__)c diff --git a/.sass-cache/d6dc4d64a1af1ff4c7903858d908aeb1a0a8c2c1/(__TEMPLATE__)c b/.sass-cache/d6dc4d64a1af1ff4c7903858d908aeb1a0a8c2c1/(__TEMPLATE__)c new file mode 100644 index 0000000000000000000000000000000000000000..2aaa2431ed50711a9ea0ae97f1640590acffa43b GIT binary patch literal 5937 zcmbVQZFAek5f(KazCe~JI(joD%Pj3GwqlF4BuDn$OnZ%M&#;qtJdx5b`hYorCkhRS zV*yZ(>hZVaFC;&sf2#cp?ZoPn5r8;*RDNi8H& z>(f%beifhxd?b^@<`FA!cC{BY*^0%f~^EgCz21>EXUjzbqMsve8D3>(gQ zbpC1XEm$0>S9ZvQfskY)Jzo6@F2;Xrq|U%sVQh~isMs_`-pj~~JsDJJ0}$L{^6V@U zF+46Z5%kp-+Eg#;rndn{Bg8I11?y!Pi?E9u>D}Zfc_f=GN_}n{_~=HB-jiBinQl$2 zHt79c`?JTkee&j;_h0|<>g6J*ah%Td84AH?M1XHiw>Us7kkYcHAd4X=XE{H#k? z@}uawyxw!m^nRCa;}xjQ_>(?9Fm_hp4y(D(adns8XHB}zHt8c}Nkx*a#MMcXV#bId z&C>;T!Tqty!Izy~hr8boLOBll_75$vly*}9I zop~Z8ZPphMh%S$To4f$d7}-EV9(WUE@Y-rq7T3VWt=wW#T3x;%ptdd#E_H*q< zAOfcWyV+SqIMG|n`PPkmYZ+VvyphK6!HG`9-#=7A$zvlV_qZE-7vgEF@GUu)7a}zB zwj#~Eg>{m*_lnf3tqpGxKugk0nO2t{AIhIf`h^6>g!nBpzMW@0o&`6)`2XX~DngF) zeI&+xxj}EY9A%lrM881xp-&aXtbRBLMk*v2`i$T&_xO~Xj8%Sq?)kOkH!g$`3d_*xk<6G(odOyHoM`-urI=Ap*J{>RURNM8`iHK zj(%uG()aq=Ehss~ubKIcDf1g(@M;bYS3B9+#pV|&(B_*8a`S&SPFTrLFwIY~u+lHN zKu&{;8EzKky3A0X2`psx~*g6$nE0XlCgO$m*TA zf}K}o>A@|sG;Jhivu`zXX_|ejaHhUVTpeTxbQn%$A9<8=_EcLC#c6AR!wT>u_C(Ps zG)skT#M^P;a^J6mEdFu_I%XuzS~zex-Wv3dz?rCkegTOt$piD)wApx#9TmJ+wUaC` z9>-zyu|}$)=zFFA5^Dg1RDe%42f7pW7xzc!{H**O$UDTQBLbu_C&>UfTd|3XnufPF z<*haF&q^MOxVo2li{53;4Cs`-DbROg9HT6{b5`x{y}(LOR#`9}LNf((mpu+V@YWo3 z8qgC-=#GtlmzV?+fIt0S8@B_%w-8fB05=VQn%Dp!`1*Ts`2k1;W}NNBo!`ZtPslqN z4!Q6BUG%@;%s8EsHz*BFT^eE-eZdXz@gON9hI7}aqI?~W)#U+K z+5#MaW~yV60__4*LGFTo=Pp2jtI9))g_Zu3xd7Q1;Ul4@BOfdMBUfgU=wy9Z-*W~| z|C#Yc1PAA9io>DmL)VJ;HN58SD+9FQ=@6)%&BRC*o32-xp#5(G{1?$U?@_cgTYjg1;hMy$v8sWYBmcg7&iZ)l!2Jd zh-+HK8+l-B$^%~wB1$QZ_4k1WwTJ!nukak4`vnsC#Jh=M`I7Tq3gf}w@&(PM?=X$u;G yCliCuHFzcpfWkD(g$U@T7nK^FA}W~v&}=JhqVg{iDWhP6tf?(oWlitF$^QWEV+vgW literal 0 HcmV?d00001 diff --git a/app/views/admin/p_product_ref_specs/_form.html.haml b/app/views/admin/p_product_ref_specs/_form.html.haml index 7fae978..ecaab27 100644 --- a/app/views/admin/p_product_ref_specs/_form.html.haml +++ b/app/views/admin/p_product_ref_specs/_form.html.haml @@ -12,16 +12,20 @@ - else .p_product_ref_spec_form.field - %tr - %td - %h4 spec : + %table + %tr + %td + %h4 spec : - %td - =form.inputs do - = form.semantic_fields_for :p_spec_type do | f | - =render :partial => "admin/p_spec_types/form", :locals => {:f => f} - = form.semantic_fields_for :p_spec_value do | f | - =render :partial => "admin/p_spec_values/form", :locals => {:f => f} - %tr - %td - = link_to_remove_fields ic(:"trash-o"), form + %td + -form.object.p_spec_type = PSpecType.new if !form.object.p_spec_type + -form.object.p_spec_value = PSpecValue.new if !form.object.p_spec_value + + =form.inputs do + = form.semantic_fields_for :p_spec_type do | f | + =render :partial => "admin/p_spec_types/form", :locals => {:f => f} + = form.semantic_fields_for :p_spec_value do | f | + =render :partial => "admin/p_spec_values/form", :locals => {:f => f} + %tr + %td + = link_to_remove_fields ic(:"trash-o"), form diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index 55f48bf..b058492 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -29,10 +29,11 @@ %tr - .p_product_ref_specs_form - = form.semantic_fields_for :p_product_ref_specs do |f| - =render :partial => "admin/p_product_ref_specs/form", :locals => {:form => f} - %p= link_to_add_fields "Ajouter une spec", form, :p_product_ref_specs + %td{:colspan => 4} + .p_product_ref_specs_form + = form.semantic_fields_for :p_product_ref_specs do |f| + =render :partial => "admin/p_product_ref_specs/form", :locals => {:form => f} + %p= link_to_add_fields "Ajouter une spec", form, :p_product_ref_specs From 9bc8251614830c112f726fd193d3a5db9d546786 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Mon, 30 Aug 2021 10:38:26 +0200 Subject: [PATCH 21/24] Suite --- .../admin/p_product_ref_specs/_form.html.haml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/views/admin/p_product_ref_specs/_form.html.haml b/app/views/admin/p_product_ref_specs/_form.html.haml index ecaab27..5c9ea2d 100644 --- a/app/views/admin/p_product_ref_specs/_form.html.haml +++ b/app/views/admin/p_product_ref_specs/_form.html.haml @@ -18,14 +18,19 @@ %h4 spec : %td - -form.object.p_spec_type = PSpecType.new if !form.object.p_spec_type - -form.object.p_spec_value = PSpecValue.new if !form.object.p_spec_value + -#form.object.p_spec_type = PSpecType.new if !form.object.p_spec_type + -#form.object.p_spec_value = PSpecValue.new if !form.object.p_spec_value - =form.inputs do - = form.semantic_fields_for :p_spec_type do | f | - =render :partial => "admin/p_spec_types/form", :locals => {:f => f} - = form.semantic_fields_for :p_spec_value do | f | - =render :partial => "admin/p_spec_values/form", :locals => {:f => f} + = form.input :p_spec_type_id, :label => "Type", as: :select, collection: PSpecType::TYPES, :include_blank => false + %td + = form.input :p_spec_value_id, :label => "Valeur", as: :select, collection: PSpecValue.all, :include_blank => false + + + =#form.inputs do + =# form.semantic_fields_for :p_spec_type do | f | + =#render :partial => "admin/p_spec_types/form", :locals => {:f => f} + =# form.semantic_fields_for :p_spec_value do | f | + =# render :partial => "admin/p_spec_values/form", :locals => {:f => f} %tr %td = link_to_remove_fields ic(:"trash-o"), form From e4467ff8aef77c9e417c8d621e5b3a7c3a52dfca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 30 Aug 2021 11:34:17 +0200 Subject: [PATCH 22/24] serial number in p_article_serial_num --- .../20210830091804_add_value_to_p_article_serial_nums.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210830091804_add_value_to_p_article_serial_nums.rb diff --git a/db/migrate/20210830091804_add_value_to_p_article_serial_nums.rb b/db/migrate/20210830091804_add_value_to_p_article_serial_nums.rb new file mode 100644 index 0000000..e80c91e --- /dev/null +++ b/db/migrate/20210830091804_add_value_to_p_article_serial_nums.rb @@ -0,0 +1,5 @@ +class AddValueToPArticleSerialNums < ActiveRecord::Migration[6.0] + def change + add_column :p_article_serial_nums, :value, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 6f8e516..e1898e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_27_164533) do +ActiveRecord::Schema.define(version: 2021_08_30_091804) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -976,6 +976,7 @@ ActiveRecord::Schema.define(version: 2021_08_27_164533) do t.bigint "p_serial_num_value_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "value" t.index ["p_article_id"], name: "index_p_article_serial_nums_on_p_article_id" t.index ["p_serial_num_type_id"], name: "index_p_article_serial_nums_on_p_serial_num_type_id" t.index ["p_serial_num_value_id"], name: "index_p_article_serial_nums_on_p_serial_num_value_id" From af77d53b9a69781258491dabf61d55a9d92d2270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 30 Aug 2021 13:11:15 +0200 Subject: [PATCH 23/24] Update form & search with serial_num_value inside p_article_serial_num --- .../admin/p_article_serial_nums_controller.rb | 13 +++++++------ app/controllers/admin/p_articles_controller.rb | 6 +++--- app/models/p_article.rb | 4 ++++ app/models/p_article_serial_num.rb | 5 +++-- app/models/p_spec_value.rb | 5 +++++ .../admin/p_article_serial_nums/_form.html.haml | 17 +++++++++-------- .../_p_article_serial_num.html.haml | 4 ++-- .../admin/p_article_serial_nums/index.html.haml | 5 +++-- app/views/admin/p_articles/_form.html.haml | 7 +++++-- app/views/admin/p_articles/_p_article.html.haml | 3 ++- app/views/admin/p_articles/index.html.haml | 2 +- .../admin/p_product_ref_specs/_form.html.haml | 4 ++-- app/views/admin/p_product_refs/_form.html.haml | 6 ------ 13 files changed, 46 insertions(+), 35 deletions(-) diff --git a/app/controllers/admin/p_article_serial_nums_controller.rb b/app/controllers/admin/p_article_serial_nums_controller.rb index 3663027..d7ecbf7 100644 --- a/app/controllers/admin/p_article_serial_nums_controller.rb +++ b/app/controllers/admin/p_article_serial_nums_controller.rb @@ -11,18 +11,19 @@ class Admin::PArticleSerialNumsController < ApplicationController end def index - @p_article_serial_nums = PArticleSerialNum.includes(:p_serial_num_type, :p_product_ref, :p_serial_num_value).all + @p_article_serial_nums = PArticleSerialNum.all + + if params[:search][:p_serial_num_type_name].present? + @p_article_serial_nums = @p_article_serial_nums.where(p_serial_num_type_id: params[:search][:p_serial_num_type_name]) - if params[:search][:p_serial_num_type_name] - @p_article_serial_nums = @p_article_serial_nums.joins(:p_serial_num_type).where("name LIKE ?", "#{params[:search][:p_serial_num_type_name]}%") end if params[:search][:p_product_ref_cc_name] @p_article_serial_nums = @p_article_serial_nums.joins(:p_article, :p_product_ref).where("cc_name LIKE ?","#{params[:search][:p_product_ref_cc_name]}%") end - if params[:search][:p_serial_num_value_value] - @p_article_serial_nums = @p_article_serial_nums.joins(:p_serial_num_value).where("value LIKE ?","#{params[:search][:p_serial_num_value_value]}%") + if params[:search][:value] + @p_article_serial_nums = @p_article_serial_nums.where("value LIKE ?","#{params[:search][:value]}%") end @p_article_serial_nums = sort_by_sorting(@p_article_serial_nums, "id DESC") @@ -45,7 +46,7 @@ class Admin::PArticleSerialNumsController < ApplicationController def new @p_article_serial_num = PArticleSerialNum.new - @p_article_serial_num.build_p_serial_num_value + # @p_article_serial_num.build_p_serial_num_value end def edit diff --git a/app/controllers/admin/p_articles_controller.rb b/app/controllers/admin/p_articles_controller.rb index ef8b79a..0e40f7a 100644 --- a/app/controllers/admin/p_articles_controller.rb +++ b/app/controllers/admin/p_articles_controller.rb @@ -33,8 +33,8 @@ class Admin::PArticlesController < ApplicationController @p_articles = @p_articles.joins(:p_product_ref).where("cc_code LIKE ?", "#{params[:search][:p_product_ref_cc_code]}%") end - if params[:search][:p_serial_num_value] - @p_articles = @p_articles.joins(:p_serial_num_values).where("value LIKE ?", "#{params[:search][:p_serial_num_value]}%") + if params[:search][:p_article_serial_num] + @p_articles = @p_articles.joins(:p_article_serial_nums).where("value LIKE ?", "#{params[:search][:p_article_serial_num]}%") end @@ -61,7 +61,7 @@ class Admin::PArticlesController < ApplicationController @p_article_serial_nums = @p_article.p_article_serial_nums.build @p_serial_num_type = @p_article_serial_nums.build_p_serial_num_type - @p_serial_num_value = @p_article_serial_nums.build_p_serial_num_value + # @p_serial_num_value = @p_article_serial_nums.build_p_serial_num_value end def edit diff --git a/app/models/p_article.rb b/app/models/p_article.rb index f1a0294..f301d09 100644 --- a/app/models/p_article.rb +++ b/app/models/p_article.rb @@ -21,4 +21,8 @@ class PArticle < ApplicationRecord :p_article_serial_nums => {:name => "N° identifiants"}, :actions => {:name => "Actions", :reorder => false}, } + + def member_label + "#{p_product_ref.cc_name}" + end end diff --git a/app/models/p_article_serial_num.rb b/app/models/p_article_serial_num.rb index 5941588..b17ef22 100644 --- a/app/models/p_article_serial_num.rb +++ b/app/models/p_article_serial_num.rb @@ -3,16 +3,17 @@ class PArticleSerialNum < ApplicationRecord belongs_to :p_serial_num_type belongs_to :p_serial_num_value, inverse_of: :p_article_serial_nums has_one :p_product_ref, through: :p_article - accepts_nested_attributes_for :p_serial_num_value + # accepts_nested_attributes_for :p_serial_num_value acts_as_sorting :fields => { :id => {:name => "ID"}, :p_article => {:name => "Article", :reorder => true}, :p_article_id => {:name => "Article ID", :reorder => true}, :p_serial_num_type => {:name => "Type", :reorder => true}, - :p_serial_num_value => {:name => "N°", :reorder => true}, + :value => {:name => "N°", :reorder => true}, :actions => {:name => "Actions", :reorder => true} } + end diff --git a/app/models/p_spec_value.rb b/app/models/p_spec_value.rb index a44875c..dd0809e 100644 --- a/app/models/p_spec_value.rb +++ b/app/models/p_spec_value.rb @@ -2,4 +2,9 @@ class PSpecValue < ApplicationRecord has_many :p_product_ref_specs UNITS = ["Go", "Mo"] + + def member_label + "#{value} #{unit}" + end + end diff --git a/app/views/admin/p_article_serial_nums/_form.html.haml b/app/views/admin/p_article_serial_nums/_form.html.haml index 34d893a..545dbdf 100644 --- a/app/views/admin/p_article_serial_nums/_form.html.haml +++ b/app/views/admin/p_article_serial_nums/_form.html.haml @@ -3,16 +3,17 @@ .content =f.inputs do - = f.input :p_article, as: :select, collection: PArticle.pluck(:id) ,:label => f.object.label_for(:p_article_id) - = f.input :p_serial_num_type, :label => f.object.label_for(:p_serial_num_type) - = f.semantic_fields_for :p_serial_num_value do | form | - =render :partial => "admin/p_serial_num_values/form", :locals => {:f => form} + = f.input :p_article, as: :select, collection: PArticle.all ,:label => f.object.label_for(:p_article_id), member_label: :member_label + = f.input :p_serial_num_type_id, :label => "type", as: :select, collection: PSerialNumType.pluck(:name, :id) + + = f.input :value + .actions=f.submit "sauvegarder", :class => "btn btn-primary" - else .p_article_serial_nums_form.field - =f.inputs do - = f.input :p_serial_num_type, :label => "type", as: :select, collection: PSerialNumType.pluck(:name, :id) - = f.semantic_fields_for :p_serial_num_value do | form | - =render :partial => "admin/p_serial_num_values/form", :locals => {:f => form} + =form.inputs do + = form.input :p_serial_num_type_id, :label => "type", as: :select, collection: PSerialNumType.pluck(:name, :id) + = form.input :value + diff --git a/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml b/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml index 59de1cd..08acd41 100644 --- a/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml +++ b/app/views/admin/p_article_serial_nums/_p_article_serial_num.html.haml @@ -18,9 +18,9 @@ %td = p_article_serial_num.p_serial_num_type.name - -tr[:p_serial_num_value] = capture do + -tr[:value] = capture do %td - = p_article_serial_num.p_serial_num_value.value + = p_article_serial_num.value -tr[:actions] = capture do diff --git a/app/views/admin/p_article_serial_nums/index.html.haml b/app/views/admin/p_article_serial_nums/index.html.haml index 9d294bd..0c3ea96 100644 --- a/app/views/admin/p_article_serial_nums/index.html.haml +++ b/app/views/admin/p_article_serial_nums/index.html.haml @@ -12,11 +12,12 @@ %table %tr - %td=text_field_tag "search[p_serial_num_type_name]", params[:search][:p_serial_num_type_name],:class => "form-control", :placeholder => "Type" + %td Type : + %td=select_tag "search[p_serial_num_type_name]", options_for_select([["",""],["Aucune","null"]]+PSerialNumType.pluck(:name, :id), params[:search][:p_serial_num_type_name]), class: "custom-select" %td=text_field_tag "search[p_product_ref_cc_name]", params[:search][:p_product_ref_cc_name],:class => "form-control", :placeholder => "Article" - %td=text_field_tag "search[p_serial_num_value_value]", params[:search][:p_serial_num_value_value],:class => "form-control", :placeholder => "N° de serie" + %td=text_field_tag "search[value]", params[:search][:value],:class => "form-control", :placeholder => "N° de serie" diff --git a/app/views/admin/p_articles/_form.html.haml b/app/views/admin/p_articles/_form.html.haml index f336fa7..3bec92b 100644 --- a/app/views/admin/p_articles/_form.html.haml +++ b/app/views/admin/p_articles/_form.html.haml @@ -4,8 +4,11 @@ =f.inputs do = f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct, :label => f.object.label_for(:p_product_ref) = f.input :p_grade, as: :select, collection: PGrade.pluck(:grade, :id), :label => "Grade" - = f.semantic_fields_for :p_article_serial_nums do |f| - =render :partial => "admin/p_article_serial_nums/form", :locals => {:f => f} + %h4 Numero de série : + .p_article_serial_nums_form + = f.semantic_fields_for :p_article_serial_nums do |form| + =render :partial => "admin/p_article_serial_nums/form", :locals => {:form => form} + %p= link_to_add_fields "Ajouter un numéro de série", f, :p_article_serial_nums, {:class => "btn btn-primary"} diff --git a/app/views/admin/p_articles/_p_article.html.haml b/app/views/admin/p_articles/_p_article.html.haml index f3631af..8d4a1ed 100644 --- a/app/views/admin/p_articles/_p_article.html.haml +++ b/app/views/admin/p_articles/_p_article.html.haml @@ -24,7 +24,8 @@ -tr[:p_article_serial_nums] = capture do %td - p_article.p_article_serial_nums.each do |sn| - = sn.p_serial_num_type.name + " : " + sn.p_serial_num_value.value + = sn.p_serial_num_type.name + " : " + sn.value + %br -tr[:actions] = capture do diff --git a/app/views/admin/p_articles/index.html.haml b/app/views/admin/p_articles/index.html.haml index 2123172..0064c5c 100644 --- a/app/views/admin/p_articles/index.html.haml +++ b/app/views/admin/p_articles/index.html.haml @@ -16,7 +16,7 @@ %td=text_field_tag "search[p_product_ref_cc_name]", params[:search][:p_product_ref_cc_name],:class => "form-control", :placeholder => "Article" - %td=text_field_tag "search[p_serial_num_value]", params[:search][:p_serial_num_value],:class => "form-control", :placeholder => "N° de serie" + %td=text_field_tag "search[p_article_serial_num]", params[:search][:p_article_serial_num],:class => "form-control", :placeholder => "N° de serie" %td.pl-2 Grade : %td=select_tag "search[p_grade_id]", options_for_select([["",""],["Aucune","null"]]+PGrade.pluck(:grade, :id), params[:search][:p_grade_id]), class: "custom-select" diff --git a/app/views/admin/p_product_ref_specs/_form.html.haml b/app/views/admin/p_product_ref_specs/_form.html.haml index 5c9ea2d..ffde9d3 100644 --- a/app/views/admin/p_product_ref_specs/_form.html.haml +++ b/app/views/admin/p_product_ref_specs/_form.html.haml @@ -21,9 +21,9 @@ -#form.object.p_spec_type = PSpecType.new if !form.object.p_spec_type -#form.object.p_spec_value = PSpecValue.new if !form.object.p_spec_value - = form.input :p_spec_type_id, :label => "Type", as: :select, collection: PSpecType::TYPES, :include_blank => false + = form.input :p_spec_type_id, :label => "Type", as: :select, collection: PSpecType.all, :include_blank => false %td - = form.input :p_spec_value_id, :label => "Valeur", as: :select, collection: PSpecValue.all, :include_blank => false + = form.input :p_spec_value_id, :label => "Valeur", as: :select, collection: PSpecValue.all, :include_blank => false, :member_label => :member_label =#form.inputs do diff --git a/app/views/admin/p_product_refs/_form.html.haml b/app/views/admin/p_product_refs/_form.html.haml index b058492..b7ff800 100644 --- a/app/views/admin/p_product_refs/_form.html.haml +++ b/app/views/admin/p_product_refs/_form.html.haml @@ -20,12 +20,6 @@ %td =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true - -if false - %td - =form.semantic_fields_for :p_spec_type do |f| - =render :partial => "admin/p_spec_types/form", :locals => {:f => f} - =form.semantic_fields_for :p_spec_value do |f| - =render :partial => "admin/p_spec_values/form", :locals => {:f => f} %tr From 74161b876af517f08bc3755950d06528e01c1091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 30 Aug 2021 14:52:50 +0200 Subject: [PATCH 24/24] Spec value menu --- app/controllers/application_controller.rb | 1 + app/models/p_spec_value.rb | 8 +++++++ app/views/admin/p_spec_values/_form.html.haml | 22 ++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3ff8eaa..9ab496c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -101,6 +101,7 @@ class ApplicationController < ActionController::Base set_sub_menu :stocks, :p_article_serial_nums, "Numeros série" set_sub_menu :stocks, :p_serial_num_types, "Types de Numero série" set_sub_menu :stocks, :p_product_ref_specs, "Specs" + set_sub_menu :stocks, :p_spec_values, "Valeur de specs" set_sub_menu :stocks, :p_grades, "Grades" set_sub_menu :stocks, :p_product_powers, "Types de chargeurs" set_sub_menu :stocks, :p_product_zones, "Zones produits" diff --git a/app/models/p_spec_value.rb b/app/models/p_spec_value.rb index dd0809e..8471de5 100644 --- a/app/models/p_spec_value.rb +++ b/app/models/p_spec_value.rb @@ -7,4 +7,12 @@ class PSpecValue < ApplicationRecord "#{value} #{unit}" end + acts_as_sorting :fields => { + :id => {:name => "ID"}, + :value => {:name => "Valeur", :reorder => true}, + :unit => {:name => "Unité", :reorder => true}, + :actions => {:name => "Actions", :reorder => true} + } + + end diff --git a/app/views/admin/p_spec_values/_form.html.haml b/app/views/admin/p_spec_values/_form.html.haml index 3c4c805..509bf70 100644 --- a/app/views/admin/p_spec_values/_form.html.haml +++ b/app/views/admin/p_spec_values/_form.html.haml @@ -1,6 +1,18 @@ +- if params[:controller] == "admin/p_spec_values" + =semantic_form_for [:admin, @p_spec_value], :remote => true do |f| -=f.inputs do - %td - = f.input :value, :label => "Valeur" - %td - = f.input :unit, :label => "Unité", as: :select, collection: PSpecValue::UNITS + .content + =f.inputs do + %td + = f.input :value, :label => "Valeur" + %td + = f.input :unit, :label => "Unité", as: :select, collection: PSpecValue::UNITS + + .actions=f.submit "sauvegarder", :class => "btn btn-primary" + +- else + =f.inputs do + %td + = f.input :value, :label => "Valeur" + %td + = f.input :unit, :label => "Unité", as: :select, collection: PSpecValue::UNITS