Skip to content

Commit

Permalink
admin in aim pange
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Mar 6, 2024
1 parent 05ddd44 commit 36558bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 39 deletions.
26 changes: 6 additions & 20 deletions app/controllers/growth/admin/aims_controller.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
module Growth
class Admin::AimsController < Admin::BaseController
before_action :set_aim, only: [:show, :edit, :update, :destroy]
before_action :set_aim, only: [:show, :edit, :update, :destroy, :actions]
before_action :set_new_aim, only: [:new, :create]

def index
@aims = Aim.includes(:aim_codes).order(id: :desc).page(params[:page])
end

def new
@aim = Aim.new
@aim.aim_codes.build
end

def create
@aim = Aim.new(aim_params)

if @aim.save
redirect_to admin_aims_url, notice: 'Aim was successfully created.'
else
render :new
end
end

def edit
if @aim.aim_codes.count == 0
@aim.aim_codes.build
end
end

def add_item
@aim = Aim.new
@aim.aim_codes.build
end

def remove_item
end

private
def set_aim
@aim = Aim.find(params[:id])
end

def set_new_aim
@aim = Aim.new(aim_params)
end

def aim_params
params.fetch(:aim, {}).permit(
:name,
Expand Down
2 changes: 1 addition & 1 deletion app/views/growth/admin/aims/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<%= f.number_field :rate %>
<%= f.number_field :reward_amount %>
<%= f.select :repeat_type, options_for_select(Growth::Aim.options_i18n(:repeat_type), @aim.repeat_type) %>
<%= f.fields :aim_codes, on: { wrap_all: false, label: false, placeholder: true }, css: { wrap_input: 'two wide field' } do |ef| %>
<%= f.fields :aim_codes, wrap: { input: 'field is-narrow' }, all: { normal: nil }, label: nil, placeholder: true do |ef| %>
<%= render partial: 'item_form', locals: { ef: ef } %>
<% end %>
27 changes: 9 additions & 18 deletions app/views/growth/admin/aims/_item_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
<div class="inline fields" id="aim_aim_codes_<%= ef.index %>" data-title="aim_aim_codes">
<div data-controller="field" class="field is-horizontal" data-field-index-value="<%= ef.index %>">
<% if ef.index == 0 %>
<%= ef.options[:parent_builder].label :aim_codes %>
<% else %>
<label class="six wide field"></label>
<label class="field-label is-normal"></label>
<% end %>
<%= ef.text_field :controller_path, css: { wrapper_input: 'three wide field' } %>
<%= ef.text_field :action_name %>
<%= ef.text_field :code, css: { wrapper_input: 'three wide field' } %>

<div class="field">
<%= link_to add_item_admin_aims_path('item', index: ef.index), data: { title: 'add_item' }, remote: true do %>
<i class="plus circle icon"></i>
<% end %>
<% if ef.object.id %>
<%= ef.check_box :_destroy, { on: { offset: false }, css: { wrapper_checkbox: 'ui checkbox' }, checked: true }, 0, 1 %>
<% else %>
<%= link_to remove_item_admin_aims_path('item', index: ef.index), remote: true do %>
<i class="minus circle icon"></i>
<% end %>
<% end %>
<div class="field-body">
<%= ef.text_field :controller_path %>
<%= ef.text_field :action_name %>
</div>
<div class="field has-addons is-flex">
<i data-action="click->field#add" class="fa-solid fa-plus" style="cursor: pointer"></i>
<i data-action="click->field#remove" class="fa-solid fa-minus" style="cursor: pointer"></i>
</div>
</div>

0 comments on commit 36558bb

Please sign in to comment.