Commit 6a540188 by Mykhailo Makohin

one more try

parent 3d1f34b7
......@@ -35,6 +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"
group :development, :test do
gem 'byebug', platform: :mri
......
......@@ -24,6 +24,11 @@ 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)
......@@ -36,6 +41,7 @@ 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)
......@@ -318,7 +324,9 @@ PLATFORMS
ruby
DEPENDENCIES
active_admin-sortable_tree (~> 2.0.0)
activeadmin
activeadmin_reorderable
acts_as_list
awesome_print
bootstrap-sass
......
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")
......@@ -60,6 +65,7 @@ ActiveAdmin.register Project do
project_documents_attributes: [:id, :project_id, :document_uk, :document_en,
:document_name_uk, :document_name_en, :_destroy])
end
end
form html: { multipart: true } do |f|
......@@ -260,11 +266,17 @@ ActiveAdmin.register Project do
p.updated_at
end
end
end
sidebar "Projects", only: :show do
attributes_table_for project.project_partials do
reorderable_table_for project.project_partials 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
//= require active_admin/base
//= require ckeditor/init
//= require activeadmin_reorderable
#= require activeadmin_reorderable
\ No newline at end of file
......@@ -10,6 +10,7 @@
// 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,6 +16,7 @@ class Ability
# User related abilities
can :manage, User
can :manage, Project
can :manage, ProjectPartial
end
end
end
......@@ -14,8 +14,7 @@ class Project < ApplicationRecord
enum types: [:program, :project]
enum status: [:in_progress, :implemented]
has_many :project_partials, dependent: :destroy
has_many :project_partials, -> { order(position: :asc) }, dependent: :destroy
has_many :project_galeries, inverse_of: :project, dependent: :destroy
has_many :project_qoutes, inverse_of: :project, dependent: :destroy
has_many :project_photos, inverse_of: :project, dependent: :destroy
......
class ProjectPartial < ApplicationRecord
# acts_as_list top_of_list: 0
belongs_to :project
acts_as_list scope: :project
end
......@@ -16,17 +16,17 @@
.project_content
.container
%div#project_partials
%div.project_partials
- @project.project_partials.each do |project_partial|
= render "#{project_partial.title}"
:javascript
document.addEventListener("turbolinks:load", function(){
document.addEventListener("turbolinks:load", function(){(
$(function() {
console.log("dfsfds");
$("#project_partials").sortable({
$(".project_partials").sortable({
update: function(e ,ui){
$.ajax({
url: $(this).data("url"),
......@@ -41,5 +41,5 @@ document.addEventListener("turbolinks:load", function(){
});
}
});
});
)};
})
)})
......@@ -6,6 +6,7 @@ require 'carrierwave'
require 'carrierwave/processing/mini_magick'
require 'awesome_print'
require 'acts_as_list'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
......
......@@ -3,7 +3,7 @@ Rails.application.routes.draw do
mount Ckeditor::Engine => '/ckeditor'
root 'home#index'
ActiveAdmin.routes(self)
patch '/projects/warm', to: 'admin/projects#sort'
# 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