Commit 3ec74dcb by Mykhailo Makohin

make sort list of project_partials

parent 6a540188
...@@ -35,8 +35,8 @@ gem 'ckeditor', '~> 4.3' ...@@ -35,8 +35,8 @@ gem 'ckeditor', '~> 4.3'
gem 'mini_magick' gem 'mini_magick'
gem 'video_info', '~> 2.7' gem 'video_info', '~> 2.7'
gem 'acts_as_list' gem 'acts_as_list'
gem 'activeadmin_reorderable' gem 'rails_sortable'
gem 'active_admin-sortable_tree', "~> 2.0.0"
group :development, :test do group :development, :test do
gem 'byebug', platform: :mri gem 'byebug', platform: :mri
......
...@@ -24,11 +24,6 @@ GEM ...@@ -24,11 +24,6 @@ GEM
erubis (~> 2.7.0) erubis (~> 2.7.0)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_admin-sortable_tree (2.0.0)
activeadmin (>= 1.1)
coffee-rails
jquery-rails
sass (~> 3.1)
activeadmin (2.0.0) activeadmin (2.0.0)
arbre (~> 1.2, >= 1.2.1) arbre (~> 1.2, >= 1.2.1)
formtastic (~> 3.1) formtastic (~> 3.1)
...@@ -41,7 +36,6 @@ GEM ...@@ -41,7 +36,6 @@ GEM
sass (~> 3.4) sass (~> 3.4)
sprockets (>= 3.0, < 4.1) sprockets (>= 3.0, < 4.1)
sprockets-es6 (~> 0.9, >= 0.9.2) sprockets-es6 (~> 0.9, >= 0.9.2)
activeadmin_reorderable (0.1.2)
activejob (5.0.7.2) activejob (5.0.7.2)
activesupport (= 5.0.7.2) activesupport (= 5.0.7.2)
globalid (>= 0.3.6) globalid (>= 0.3.6)
...@@ -233,6 +227,7 @@ GEM ...@@ -233,6 +227,7 @@ GEM
nokogiri (>= 1.6) nokogiri (>= 1.6)
rails-html-sanitizer (1.2.0) rails-html-sanitizer (1.2.0)
loofah (~> 2.2, >= 2.2.2) loofah (~> 2.2, >= 2.2.2)
rails_sortable (1.3.1)
railties (5.0.7.2) railties (5.0.7.2)
actionpack (= 5.0.7.2) actionpack (= 5.0.7.2)
activesupport (= 5.0.7.2) activesupport (= 5.0.7.2)
...@@ -324,9 +319,7 @@ PLATFORMS ...@@ -324,9 +319,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
active_admin-sortable_tree (~> 2.0.0)
activeadmin activeadmin
activeadmin_reorderable
acts_as_list acts_as_list
awesome_print awesome_print
bootstrap-sass bootstrap-sass
...@@ -353,6 +346,7 @@ DEPENDENCIES ...@@ -353,6 +346,7 @@ DEPENDENCIES
omniauth-linkedin-oauth2 omniauth-linkedin-oauth2
puma (~> 3.0) puma (~> 3.0)
rails (~> 5.0.7, >= 5.0.7.2) rails (~> 5.0.7, >= 5.0.7.2)
rails_sortable
remotipart remotipart
sass-rails (~> 5.0) sass-rails (~> 5.0)
simple_form simple_form
......
ActiveAdmin.register ProjectPartial do
menu label: 'Project Partials'
reorderable
controller do
def find_resource
scoped_collection.friendly.find(params[:id])
end
end
end
ActiveAdmin.register Project do ActiveAdmin.register Project do
config.sort_order = 'position_asc' # assuming Widget.insert_at modifies the `position` attribute
config.paginate = false
reorderable
menu label: proc{ I18n.t "active_admin.models.project.other" } menu label: proc{ I18n.t "active_admin.models.project.other" }
filter :photo, label: I18n.t("active_admin.attributes.project.photo") filter :photo, label: I18n.t("active_admin.attributes.project.photo")
...@@ -23,6 +18,7 @@ ActiveAdmin.register Project do ...@@ -23,6 +18,7 @@ ActiveAdmin.register Project do
filter :updated_at, label: I18n.t("active_admin.attributes.project.updated_at") filter :updated_at, label: I18n.t("active_admin.attributes.project.updated_at")
controller do controller do
skip_before_action :verify_authenticity_token
def create def create
@project = Project.new(project_params) @project = Project.new(project_params)
...@@ -34,18 +30,24 @@ ActiveAdmin.register Project do ...@@ -34,18 +30,24 @@ ActiveAdmin.register Project do
end end
end end
def show
@project = find_resource
end
def find_resource def find_resource
scoped_collection.friendly.find(params[:id]) scoped_collection.friendly.find(params[:id])
end end
def sort def sort
params[:project_partials].each_with_index do |id, index| params[:project_partial].each_with_index do |id, index|
ProjectPartialsService.where(id: id).update_all(position: index + 1) ProjectPartial.find(id).update_column(:position, index + 1)
end end
head :ok
end end
def project_params def project_params
params.require(:project).permit(:photo, :photo_preview, :photo_before, :remove_photo_before, params.require(:project).permit(:position, :photo, :photo_preview, :photo_before, :remove_photo_before,
:photo_after, :remove_photo_after, :types, :status, :individual_type_uk, :individual_type_en, :photo_after, :remove_photo_after, :types, :status, :individual_type_uk, :individual_type_en,
:title_uk, :title_en, :heading_uk, :heading_en, :slug, :short_description_uk, :title_uk, :title_en, :heading_uk, :heading_en, :slug, :short_description_uk,
:short_description_en, :description_uk,:description_en, :site, :short_description_en, :description_uk,:description_en, :site,
...@@ -266,17 +268,11 @@ ActiveAdmin.register Project do ...@@ -266,17 +268,11 @@ ActiveAdmin.register Project do
p.updated_at p.updated_at
end end
end end
reorderable_table_for project.project_partials do end
sidebar "Project Partials", only: :show do
table_for project.project_partials.order(:position) do
column :title column :title
column :position
end end
end end
# sidebar "Project Partials", class: "project_partials", as: :sortable, only: :show do
# reorderable_table_for project.project_partials do
# column :title
# column :position
# end
# end
end end
class Admin.ReorderableTable
constructor: (selector) ->
$(selector).find("ul").sortable
items: "li"
handle: ".js-reorder-handle" # from `reorderable_column` above
update: @_sendPositions
_calculatePositions: (sortable) ->
# Sortable uses ids by default for serialisation
for itemId, index in $(sortable).sortable("toArray")
# ActiveAdmin sets the id to the form "underscored_classname_id"
id: itemId.split("_").pop()
order: index + 1
_sendPositions: (event) =>
positions = items: @_calculatePositions(event.target)
# `url` assumes that we're on the index page, with no extra params
$.ajax
url: $(this).data("url")
method: "PATCH"
dataType: "json"
contentType: "application/json"
data: JSON.stringify(positions)
# Initialise on page load
$ ->
new Admin.ReorderableTable(".project_partials")
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
try{
try{
s_Q("r36a9c");
var s_GTa=s_S("r36a9c");
var s_HTa=function(a){return null!=a&&0<a.getBoundingClientRect().width&&0<a.getBoundingClientRect().height?(a=window.getComputedStyle(a,null),"none"!==a.display&&"hidden"!==a.visibility&&"auto"===a.clip):!1},s_ITa=function(a){s_h.call(this,a.Pa)};s_k(s_ITa,s_h);s_ITa.Ka=s_h.Ka;
s_ITa.prototype.$ub=function(){var a=this.Ia("BKxS1e").el();s_f(a);a=s_Wi(this.XE().documentElement).find('[role="heading"], h1, h2, h3').filter(s_HTa).Ng();if(!s_yf(a.el())){if(null==s_Ti(a,"aria-label")&&null==s_Ti(a,"aria-describedby")){var b=s_Ri(a);if(s_HTa(b.el())&&"A"==b.el().tagName){b.focus();return}b=a.children().filter(s_HTa);if(1==b.size()&&"A"==b.Ng().el().tagName){b.Ng().focus();return}}a.el().tabIndex="-1";a.el().onblur=function(c){c.target.removeAttribute("tabIndex")}}a.focus()};
s_Y(s_ITa.prototype,"i3viod",function(){return this.$ub});s_Z(s_GTa,s_ITa);
s_g().$();
}catch(e){_DumpException(e)}
// Google Inc.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
//= require active_admin/base //= require active_admin/base
//= require ckeditor/init //= require ckeditor/init
//= require activeadmin_reorderable //= require activeadmin_sortable
#= require activeadmin_reorderable
\ No newline at end of file
$(function() {
$("#project-partials_sidebar_section").sortable({
items: 'tr',
update: function(e ,ui){
$.ajax({
url: $(this).data("url"),
type: "PUT",
data: $(this).sortable("serialize"),
success: function(){
console.log('success!');
},
error: function(){
console.log('error!');
}
});
}
});
});
\ No newline at end of file
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
// Active Admin's got SASS! // Active Admin's got SASS!
@import "active_admin/mixins"; @import "active_admin/mixins";
@import "active_admin/base"; @import "active_admin/base";
@import "activeadmin_reorderable";
// Overriding any non-variable SASS must be done after the fact. // Overriding any non-variable SASS must be done after the fact.
// For example, to change the default status-tag color: // For example, to change the default status-tag color:
......
...@@ -16,7 +16,6 @@ class Ability ...@@ -16,7 +16,6 @@ class Ability
# User related abilities # User related abilities
can :manage, User can :manage, User
can :manage, Project can :manage, Project
can :manage, ProjectPartial
end end
end end
end end
...@@ -5,13 +5,13 @@ class ProjectPartialsService ...@@ -5,13 +5,13 @@ class ProjectPartialsService
end end
def params_project_partial def params_project_partial
[{title: 'description', position: 0}, [{title: 'project_description', position: 0},
{title: 'galery', position: 1}, {title: 'project_galeries', position: 1},
{title: 'quote', position: 2}, {title: 'project_quotes', position: 2},
{title: 'video', position: 3}, {title: 'project_videos', position: 3},
{title: 'photos', position: 4}, {title: 'project_photos', position: 4},
{title: 'links', position: 5}, {title: 'project_links', position: 5},
{title: 'documents', position: 6}] {title: 'project_documents', position: 6}]
end end
def set_project_partials def set_project_partials
......
= raw @project.short_description
\ No newline at end of file
description
\ No newline at end of file
documents
\ No newline at end of file
galery
\ No newline at end of file
links
\ No newline at end of file
photos
\ No newline at end of file
qoutes
\ No newline at end of file
video
\ No newline at end of file
= raw @project.description
\ No newline at end of file
...@@ -17,29 +17,6 @@ ...@@ -17,29 +17,6 @@
.project_content .project_content
.container .container
%div.project_partials %div.project_partials
- @project.project_partials.each do |project_partial| - @project.project_partials.order(:position).each_with_index do |id, val|
- if @project.val
= render "#{project_partial.title}" = render "#{project_partial.title}"
:javascript
document.addEventListener("turbolinks:load", function(){(
$(function() {
console.log("dfsfds");
$(".project_partials").sortable({
update: function(e ,ui){
$.ajax({
url: $(this).data("url"),
type: "PATCH",
data: $(this).sortable("serialize"),
success: function(){
console.log('success!');
},
error: function(){
console.log('error!');
}
});
}
});
})
)})
...@@ -26,6 +26,10 @@ ActiveAdmin.setup do |config| ...@@ -26,6 +26,10 @@ ActiveAdmin.setup do |config|
config.authentication_method = :authenticate_user! config.authentication_method = :authenticate_user!
config.register_javascript 'activeadmin_sortable.js'
# Set the link url for the title. For example, to take # Set the link url for the title. For example, to take
# users to your main site. Defaults to no link. # users to your main site. Defaults to no link.
# #
......
...@@ -2,8 +2,8 @@ Rails.application.routes.draw do ...@@ -2,8 +2,8 @@ Rails.application.routes.draw do
scope "(:locale)", locale: /en|uk/ do scope "(:locale)", locale: /en|uk/ do
mount Ckeditor::Engine => '/ckeditor' mount Ckeditor::Engine => '/ckeditor'
root 'home#index' root 'home#index'
put "/admin/projects/:id", to: 'admin/projects#sort'
ActiveAdmin.routes(self) ActiveAdmin.routes(self)
# patch '/projects/warm', to: 'admin/projects#sort'
resources :users resources :users
resources :projects, only: [:show] resources :projects, only: [:show]
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment