From a9a5e222513c46236d77b2aed0bb3301c6cee330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 18:19:47 +0200 Subject: [PATCH] g qis sorecop_cats --- .../admin/sorecop_cats_controller.rb | 76 +++++++++++++++++++ app/models/sorecop_cat.rb | 2 + app/views/admin/sorecop_cats/_form.html.haml | 12 +++ .../admin/sorecop_cats/_sorecop_cat.html.haml | 16 ++++ app/views/admin/sorecop_cats/create.js.erb | 2 + app/views/admin/sorecop_cats/destroy.js.erb | 1 + app/views/admin/sorecop_cats/edit.js.erb | 1 + app/views/admin/sorecop_cats/index.html.haml | 16 ++++ app/views/admin/sorecop_cats/new.js.erb | 1 + app/views/admin/sorecop_cats/show.html.haml | 10 +++ app/views/admin/sorecop_cats/update.js.erb | 2 + config/routes.rb | 11 +++ .../20210923161914_create_sorecop_cats.rb | 9 +++ test/fixtures/sorecop_cats.yml | 7 ++ test/models/sorecop_cat_test.rb | 7 ++ 15 files changed, 173 insertions(+) create mode 100644 app/controllers/admin/sorecop_cats_controller.rb create mode 100644 app/models/sorecop_cat.rb create mode 100644 app/views/admin/sorecop_cats/_form.html.haml create mode 100644 app/views/admin/sorecop_cats/_sorecop_cat.html.haml create mode 100644 app/views/admin/sorecop_cats/create.js.erb create mode 100644 app/views/admin/sorecop_cats/destroy.js.erb create mode 100644 app/views/admin/sorecop_cats/edit.js.erb create mode 100644 app/views/admin/sorecop_cats/index.html.haml create mode 100644 app/views/admin/sorecop_cats/new.js.erb create mode 100644 app/views/admin/sorecop_cats/show.html.haml create mode 100644 app/views/admin/sorecop_cats/update.js.erb create mode 100644 db/migrate/20210923161914_create_sorecop_cats.rb create mode 100644 test/fixtures/sorecop_cats.yml create mode 100644 test/models/sorecop_cat_test.rb diff --git a/app/controllers/admin/sorecop_cats_controller.rb b/app/controllers/admin/sorecop_cats_controller.rb new file mode 100644 index 0000000..9a0803e --- /dev/null +++ b/app/controllers/admin/sorecop_cats_controller.rb @@ -0,0 +1,76 @@ +# -*- encoding : utf-8 -*- + +class Admin::SorecopCatsController < ApplicationController + layout "admin" + before_action :auth_admin + + before_action :admin_space + + def admin_space + @admin_space = "default" + end + + def index + @sorecop_cats = SorecopCat.all + + @sorecop_cats = sort_by_sorting(@sorecop_cats, "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 + @sorecop_cats = @sorecop_cats.page(page).per(per_page) + + } + end + end + + def show + @sorecop_cat = SorecopCat.find(params[:id]) + + end + + def new + @sorecop_cat = SorecopCat.new + + end + + def edit + @sorecop_cat = SorecopCat.find(params[:id]) + + end + + def create + @sorecop_cat = SorecopCat.new(params.require(:sorecop_cat).permit!) + + if @sorecop_cat.save + + else + render action: "new" + + end + + end + + + def update + @sorecop_cat = SorecopCat.find(params[:id]) + + + if @sorecop_cat.update_attributes(params.require(:sorecop_cat).permit!) + + else + render action: "edit" + + end + + end + + + def destroy + @sorecop_cat = SorecopCat.find(params[:id]) + @sorecop_cat.destroy + + end +end diff --git a/app/models/sorecop_cat.rb b/app/models/sorecop_cat.rb new file mode 100644 index 0000000..be69dba --- /dev/null +++ b/app/models/sorecop_cat.rb @@ -0,0 +1,2 @@ +class SorecopCat < ApplicationRecord +end diff --git a/app/views/admin/sorecop_cats/_form.html.haml b/app/views/admin/sorecop_cats/_form.html.haml new file mode 100644 index 0000000..92adc9a --- /dev/null +++ b/app/views/admin/sorecop_cats/_form.html.haml @@ -0,0 +1,12 @@ +=semantic_form_for [:admin, @sorecop_cat], :remote => true do |f| + + .content + =f.inputs do + = 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/sorecop_cats/_sorecop_cat.html.haml b/app/views/admin/sorecop_cats/_sorecop_cat.html.haml new file mode 100644 index 0000000..f7c3aa2 --- /dev/null +++ b/app/views/admin/sorecop_cats/_sorecop_cat.html.haml @@ -0,0 +1,16 @@ +%tr#sorecop_cat_row{:id => sorecop_cat.id} + -tr = {} + + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, sorecop_cat], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true + = link_to i(:pencil), edit_admin_sorecop_cat_path(sorecop_cat), :remote => true + = link_to i(:eye), admin_sorecop_cat_path(sorecop_cat), :remote => true + + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => sorecop_cat} + + + + \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/create.js.erb b/app/views/admin/sorecop_cats/create.js.erb new file mode 100644 index 0000000..5b32752 --- /dev/null +++ b/app/views/admin/sorecop_cats/create.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_cats_rows').prepend("<%= escape_javascript(render(@sorecop_cat))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/destroy.js.erb b/app/views/admin/sorecop_cats/destroy.js.erb new file mode 100644 index 0000000..53582e6 --- /dev/null +++ b/app/views/admin/sorecop_cats/destroy.js.erb @@ -0,0 +1 @@ +$('#sorecop_cat_row_<%= @sorecop_cat.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/edit.js.erb b/app/views/admin/sorecop_cats/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_cats/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/sorecop_cats/index.html.haml b/app/views/admin/sorecop_cats/index.html.haml new file mode 100644 index 0000000..635f57b --- /dev/null +++ b/app/views/admin/sorecop_cats/index.html.haml @@ -0,0 +1,16 @@ +.qi_header + .right= link_to ic(:plus)+' Ajouter', new_admin_sorecop_cat_path(), :class => "btn btn-primary btn-ap-add", :remote => true + %h1 + =SorecopCat.human rescue "" + + + +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @sorecop_cats} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @sorecop_cats} + + + diff --git a/app/views/admin/sorecop_cats/new.js.erb b/app/views/admin/sorecop_cats/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/sorecop_cats/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/sorecop_cats/show.html.haml b/app/views/admin/sorecop_cats/show.html.haml new file mode 100644 index 0000000..764b0b5 --- /dev/null +++ b/app/views/admin/sorecop_cats/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @sorecop_cat \ No newline at end of file diff --git a/app/views/admin/sorecop_cats/update.js.erb b/app/views/admin/sorecop_cats/update.js.erb new file mode 100644 index 0000000..3fe7cb0 --- /dev/null +++ b/app/views/admin/sorecop_cats/update.js.erb @@ -0,0 +1,2 @@ +$('#sorecop_cat_row_<%= @sorecop_cat.id %>').replaceWith("<%= escape_javascript(render(@sorecop_cat))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a5835ca..bb3e0c3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,16 @@ Rails.application.routes.draw do + namespace :admin do + resources :sorecop_cats do + member do + + end + collection do + + end + end + end + namespace :admin do resources :price_line_resp_selects do member do diff --git a/db/migrate/20210923161914_create_sorecop_cats.rb b/db/migrate/20210923161914_create_sorecop_cats.rb new file mode 100644 index 0000000..4679ff6 --- /dev/null +++ b/db/migrate/20210923161914_create_sorecop_cats.rb @@ -0,0 +1,9 @@ +class CreateSorecopCats < ActiveRecord::Migration[6.0] + def change + create_table :sorecop_cats do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/test/fixtures/sorecop_cats.yml b/test/fixtures/sorecop_cats.yml new file mode 100644 index 0000000..7d41224 --- /dev/null +++ b/test/fixtures/sorecop_cats.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/sorecop_cat_test.rb b/test/models/sorecop_cat_test.rb new file mode 100644 index 0000000..2daceaa --- /dev/null +++ b/test/models/sorecop_cat_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SorecopCatTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end