Commit 3ec74dcb by Mykhailo Makohin

make sort list of project_partials

parent 6a540188
......@@ -35,8 +35,8 @@ gem 'ckeditor', '~> 4.3'
gem 'mini_magick'
gem 'video_info', '~> 2.7'
gem 'acts_as_list'
gem 'activeadmin_reorderable'
gem 'active_admin-sortable_tree', "~> 2.0.0"
gem 'rails_sortable'
group :development, :test do
gem 'byebug', platform: :mri
......
......@@ -24,11 +24,6 @@ GEM
erubis (~> 2.7.0)
rails-dom-testing (~> 2.0)
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)
arbre (~> 1.2, >= 1.2.1)
formtastic (~> 3.1)
......@@ -41,7 +36,6 @@ GEM
sass (~> 3.4)
sprockets (>= 3.0, < 4.1)
sprockets-es6 (~> 0.9, >= 0.9.2)
activeadmin_reorderable (0.1.2)
activejob (5.0.7.2)
activesupport (= 5.0.7.2)
globalid (>= 0.3.6)
......@@ -233,6 +227,7 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.2.0)
loofah (~> 2.2, >= 2.2.2)
rails_sortable (1.3.1)
railties (5.0.7.2)
actionpack (= 5.0.7.2)
activesupport (= 5.0.7.2)
......@@ -324,9 +319,7 @@ PLATFORMS
ruby
DEPENDENCIES
active_admin-sortable_tree (~> 2.0.0)
activeadmin
activeadmin_reorderable
acts_as_list
awesome_print
bootstrap-sass
......@@ -353,6 +346,7 @@ DEPENDENCIES
omniauth-linkedin-oauth2
puma (~> 3.0)
rails (~> 5.0.7, >= 5.0.7.2)
rails_sortable
remotipart
sass-rails (~> 5.0)
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
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" }
filter :photo, label: I18n.t("active_admin.attributes.project.photo")
......@@ -23,6 +18,7 @@ ActiveAdmin.register Project do
filter :updated_at, label: I18n.t("active_admin.attributes.project.updated_at")
controller do
skip_before_action :verify_authenticity_token
def create
@project = Project.new(project_params)
......@@ -34,18 +30,24 @@ ActiveAdmin.register Project do
end
end
def show
@project = find_resource
end
def find_resource
scoped_collection.friendly.find(params[:id])
end
def sort
params[:project_partials].each_with_index do |id, index|
ProjectPartialsService.where(id: id).update_all(position: index + 1)
params[:project_partial].each_with_index do |id, index|
ProjectPartial.find(id).update_column(:position, index + 1)
end
head :ok
end
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,
:title_uk, :title_en, :heading_uk, :heading_en, :slug, :short_description_uk,
:short_description_en, :description_uk,:description_en, :site,
......@@ -266,17 +268,11 @@ ActiveAdmin.register Project do
p.updated_at
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 :position
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
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 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 @@
// Active Admin's got SASS!
@import "active_admin/mixins";
@import "active_admin/base";
@import "activeadmin_reorderable";
// Overriding any non-variable SASS must be done after the fact.
// For example, to change the default status-tag color:
......
......@@ -16,7 +16,6 @@ class Ability
# User related abilities
can :manage, User
can :manage, Project
can :manage, ProjectPartial
end
end
end
......@@ -5,13 +5,13 @@ class ProjectPartialsService
end
def params_project_partial
[{title: 'description', position: 0},
{title: 'galery', position: 1},
{title: 'quote', position: 2},
{title: 'video', position: 3},
{title: 'photos', position: 4},
{title: 'links', position: 5},
{title: 'documents', position: 6}]
[{title: 'project_description', position: 0},
{title: 'project_galeries', position: 1},
{title: 'project_quotes', position: 2},
{title: 'project_videos', position: 3},
{title: 'project_photos', position: 4},
{title: 'project_links', position: 5},
{title: 'project_documents', position: 6}]
end
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 @@
.project_content
.container
%div.project_partials
- @project.project_partials.each do |project_partial|
= 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!');
}
});
}
});
})
)})
- @project.project_partials.order(:position).each_with_index do |id, val|
- if @project.val
= render "#{project_partial.title}"
......@@ -26,6 +26,10 @@ ActiveAdmin.setup do |config|
config.authentication_method = :authenticate_user!
config.register_javascript 'activeadmin_sortable.js'
# Set the link url for the title. For example, to take
# users to your main site. Defaults to no link.
#
......
......@@ -2,8 +2,8 @@ Rails.application.routes.draw do
scope "(:locale)", locale: /en|uk/ do
mount Ckeditor::Engine => '/ckeditor'
root 'home#index'
put "/admin/projects/:id", to: 'admin/projects#sort'
ActiveAdmin.routes(self)
# patch '/projects/warm', to: 'admin/projects#sort'
resources :users
resources :projects, only: [:show]
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