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] 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