-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into improve-devise-routing
Conflicts: core/spec/helpers/comable/application_helper_spec.rb
- Loading branch information
Showing
46 changed files
with
944 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
backend/app/assets/javascripts/comable/admin/navigations.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class @Navigation | ||
constructor: -> | ||
$(document).ready(@ready) | ||
@add_event() | ||
|
||
ready: => | ||
@navigation_items = $('#navigation-items') | ||
@add_fields = $('.add_fields') | ||
|
||
# linkable_idの検索 | ||
search_linkable_ids: -> | ||
$linkable_type = $('#linkable_type') | ||
$position = $('#position') | ||
$linkable_type.val($(this).val()) | ||
$position.val($('.linkable_type').index(this)) | ||
$linkable_type.closest('form').submit() | ||
|
||
# アイテムの追加 | ||
adding_navigation_item_field: -> | ||
regexp = new RegExp($(this).data('index'), 'g') | ||
field_tags = $(this).data('fields').replace(regexp, $('.navigation-item').length) # 置換予定文字を添字に置換する | ||
$field = $(field_tags) | ||
$field.addClass('js-new-record') | ||
$('#navigation-items').append($field) # タグを追加 | ||
|
||
# アイテムの削除 | ||
remove_navigation_item_field: -> | ||
$navigation_item = $(this).closest('.navigation-item') | ||
if $navigation_item.hasClass('js-new-record') | ||
$navigation_item.remove() | ||
else | ||
$navigation_item.find('.destroy').val(true) | ||
$navigation_item.addClass('hidden') | ||
|
||
# イベント設定 | ||
add_event: -> | ||
@navigation_items.on('change', '.linkable_type', @search_linkable_ids) | ||
@navigation_items.on('click', '.remove_fields', @remove_navigation_item_field) | ||
@add_fields.click(@adding_navigation_item_field) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
backend/app/assets/stylesheets/comable/admin/_navigations.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#comable-navigation { | ||
.add_fields { | ||
margin-right: 30px; | ||
} | ||
|
||
.remove_fields { | ||
margin-top: 25px; | ||
} | ||
|
||
.linkable_id select { | ||
margin-top: 25px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
backend/app/controllers/comable/admin/navigations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require_dependency 'comable/admin/application_controller' | ||
|
||
module Comable | ||
module Admin | ||
class NavigationsController < Comable::Admin::ApplicationController | ||
load_and_authorize_resource class: Comable::Navigation.name, except: :index | ||
|
||
def index | ||
@q = Comable::Navigation.ransack(params[:q]) | ||
@navigations = @q.result.accessible_by(current_ability) | ||
end | ||
|
||
def show | ||
edit | ||
render :edit | ||
end | ||
|
||
def new | ||
@navigation.navigation_items.build | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def create | ||
@navigation = Comable::Navigation.new(navigation_params) | ||
if @navigation.save | ||
redirect_to comable.admin_navigation_path(@navigation), notice: Comable.t('successful') | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
@navigation.attributes = navigation_params | ||
if @navigation.save | ||
redirect_to comable.admin_navigation_path(@navigation), notice: Comable.t('successful') | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@navigation.destroy | ||
redirect_to comable.admin_navigations_path, notice: Comable.t('successful') | ||
end | ||
|
||
def search_linkable_ids | ||
@linkable_id_options = linkable_id_options | ||
render layout: false | ||
end | ||
|
||
private | ||
|
||
def linkable_type | ||
return if params[:linkable_type].blank? | ||
params[:linkable_type] if Comable.const_defined?(params[:linkable_type].demodulize) | ||
end | ||
|
||
def linkable_id_options | ||
linkable_type ? linkable_type.constantize.linkable_id_options : [[]] | ||
end | ||
|
||
def navigation_params | ||
params.require(:navigation).permit( | ||
:name, | ||
navigation_items_attributes: navigation_items_attributes_keys | ||
) | ||
end | ||
|
||
def navigation_items_attributes_keys | ||
[ | ||
:id, | ||
:position, | ||
:linkable_id, | ||
:linkable_type, | ||
:name, | ||
:url, | ||
:_destroy | ||
] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Comable | ||
module Admin | ||
module NavigationsHelper | ||
def linkable_type_options | ||
Comable::NavigationItem.linkable_params_lists.map { |attr| attr.slice(:name, :type).values } | ||
end | ||
|
||
def linkable_id_options(navigation_item) | ||
navigation_item.linkable_class.try(:linkable_id_options) || [[]] | ||
end | ||
|
||
# アイテム追加ボタン設置 | ||
def add_fields_button_tag(name, f, association) | ||
new_object = f.object.send(association).klass.new | ||
index = new_object.object_id # 後で置換するために必要な文字を入れる | ||
fields = f.fields_for(association, new_object, child_index: index) do |builder| | ||
render(association.to_s.singularize + '_fields', f: builder) | ||
end | ||
button_tag(name, type: :button, class: 'add_fields btn btn-default pull-right', data: { index: index, fields: fields.delete("\n") }) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
= error_messages_for @navigation | ||
|
||
- url = @navigation.new_record? ? comable.admin_navigations_path : comable.admin_navigation_path(@navigation) | ||
|
||
= form_for @navigation, url: url do |f| | ||
.hidden | ||
= f.submit | ||
|
||
fieldset | ||
.col-md-3 | ||
legend | ||
= Comable.t('admin.nav.navigations.general') | ||
|
||
.col-md-9 | ||
.form-group | ||
= f.label :name | ||
= f.text_field :name | ||
|
||
hr | ||
|
||
fieldset | ||
.col-md-3 | ||
legend | ||
= Comable.t('admin.nav.navigations.navigation_items') | ||
|
||
.col-md-9 | ||
#navigation-items | ||
= f.fields_for :navigation_items do |navigation_items_form| | ||
= render 'navigation_item_fields', f: navigation_items_form | ||
|
||
hr | ||
|
||
.row | ||
= add_fields_button_tag Comable.t('admin.nav.navigation_items.add_link'), f, :navigation_items | ||
|
||
.hidden | ||
= form_tag(comable.search_linkable_ids_admin_navigations_path, remote: true) do | ||
= text_field_tag :linkable_type | ||
= text_field_tag :position | ||
= submit_tag |
24 changes: 24 additions & 0 deletions
24
backend/app/views/comable/admin/navigations/_navigation_item_fields.slim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
- linkable_class = f.object.linkable_class | ||
- link_selectable = linkable_class.try(:linkable_exists?) | ||
|
||
fieldset.navigation-item class="#{'hidden' if f.object._destroy}" | ||
.row | ||
.col-sm-3 | ||
= f.label :name | ||
= f.text_field :name | ||
|
||
.col-sm-3 | ||
= f.label :linkable_type | ||
= f.select :linkable_type, linkable_type_options, {}, class: :linkable_type | ||
|
||
.col-sm-3.url class="#{'hidden' if link_selectable}" | ||
= f.label :url | ||
= f.text_field :url | ||
|
||
.col-sm-3.linkable_id class="#{'hidden' unless link_selectable}" | ||
= f.select :linkable_id, linkable_id_options(f.object) | ||
|
||
.col-sm-3 | ||
= f.hidden_field :_destroy, class: :destroy | ||
button.btn.btn-default.pull-right.remove_fields type="button" | ||
= Comable.t('actions.destroy') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.comable-page | ||
.comable-main-fixed-top | ||
.comable-page-heading | ||
ul.pull-right.list-inline | ||
li | ||
= link_to_save | ||
|
||
h1.page-header | ||
ol.breadcrumb | ||
li> | ||
= link_to Comable.t('admin.nav.navigation'), comable.admin_navigations_path | ||
li.active | ||
= @navigation.name | ||
|
||
.comable-page-body | ||
= render 'form' | ||
hr | ||
.panel.panel-danger | ||
.panel-heading type="button" data-toggle="collapse" data-target="#comable-danger" | ||
strong | ||
span.fa.fa-angle-down> | ||
= Comable.t('admin.actions.destroy') | ||
#comable-danger.collapse | ||
.panel-body | ||
p | ||
= Comable.t('admin.confirmation_to_remove_navigation') | ||
= link_to Comable.t('admin.actions.destroy'), comable.admin_navigation_path(@navigation), method: :delete, class: 'btn btn-danger' |
Oops, something went wrong.