Coder Social home page Coder Social logo

pinholepress / rails_admin_nestable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dalpo/rails_admin_nestable

0.0 2.0 0.0 325 KB

RailsAdmin drag & drop custom action to sorting list and tree (with the Ancestry gem) :gem:

Home Page: http://andreadalponte.com/rails_admin_nestable/

License: MIT License

Ruby 16.22% JavaScript 72.51% CSS 10.40% HTML 0.87%

rails_admin_nestable's Introduction

Rails Admin Nestable

RailsAdmin Drag and drop tree view for Ancestry and mongoid-ancestry gem

Sample demo available at: https://github.com/dalpo/rails_admin_nestable_demo

Gem Version Code Climate

Installation

To enable rails_admin_nestable, add the following to your Gemfile:

gem 'rails_admin_nestable', '~> 0.3.2'

Add in your config/initializers/rails_admin.rb initializer the configuration:

RailsAdmin.config do |config|
  config.actions do
    # root actions
    dashboard                     # mandatory
    # collection actions
    index                         # mandatory
    new
    export
    history_index
    bulk_delete
    # member actions
    show
    edit
    delete
    history_show
    show_in_app

    # Add the nestable action for configured models
    nestable
  end
end

Configuration

You could choose between two different configurations for your model:

1. Nestable tree:

To use this configuration, you need to organize your tree model with Ancestry or Mongoid Ancestry. Otherwise your model have to respond to the parent, arrange and children methods.

The nestable_tree methods supports the following options:

  • position_field: (symbol) default => nil
  • max_depth: (integer) default => nil
  • enable_callback: (boolean) default => false
  • scope: (symbol | proc) default => nil
  • live_update: (boolean | :only) default => true (:only is for live updating only)

In your config/initializers/rails_admin.rb initializer:

RailsAdmin.config do |config|
  config.actions do
    ...
  end

  config.model MyModel do
    nestable_tree({
      position_field: :position,
      max_depth: 3
    })
  end
end

2. Nestable list:

To use this configuration, you need a position field

The nestable_list methods supports the following options:

  • position_field: (symbol) default :position
  • enable_callback: (boolean) default => false
  • scope: (symbol | proc) default => nil
  • live_update: (boolean | :only) default => true (:only is for live updating only)

In your config/initializers/rails_admin.rb initializer:

RailsAdmin.config do |config|
  config.actions do
    ...
  end

  config.model MyModel do
    nestable_list true
  end
end

Authorization with CanCan

Sample ability:

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new

    if user.admin?
      can :access, :rails_admin
      can :dashboard

      if user.role? :superadmin
        can :manage, :all
      end

      if user.role? :editor
        can :edit, :all
        can :nestable, :all
      end
    end
  end
end

Screenshot

Nestable view

Contributing

Submitting a Pull Request:

  1. Fork the repository.
  2. Create a topic branch.
  3. Implement your feature or bug fix.
  4. Add, commit, and push your changes.
  5. Submit a pull request.

Thanks

License

This project rocks and uses MIT-LICENSE.

Copyright 2015 Andrea Dal Ponte

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rails_admin_nestable's People

Contributors

dalpo avatar sudosu avatar dieunb avatar benhutton avatar gokure avatar tagliala avatar jesson avatar vened avatar thiagoa avatar javifr avatar neilang avatar nicovak avatar subrova avatar ideadapt avatar

Watchers

James Cloos avatar Dan McCabe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.