k_admin 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +42 -0
- data/Rakefile +32 -0
- data/app/assets/config/k_admin_manifest.js +0 -0
- data/app/controllers/admin/base_controller.rb +12 -0
- data/app/controllers/admin/resources_controller.rb +67 -0
- data/app/decorators/resource_decorator.rb +15 -0
- data/app/helpers/admin/forms_helper.rb +5 -0
- data/app/views/admin/base/_resource.html.erb +9 -0
- data/app/views/admin/base/edit.html.erb +10 -0
- data/app/views/admin/base/index.html.erb +16 -0
- data/app/views/admin/base/new.html.erb +1 -0
- data/app/views/admin/base/show.html.erb +7 -0
- data/app/views/layouts/admin.html.erb +24 -0
- data/app/views/shared/admin/_header.html.erb +5 -0
- data/config/initializers/assets.rb +4 -0
- data/config/initializers/initializer.rb +1 -0
- data/config/locales/admin.en.yml +9 -0
- data/config/routes.rb +8 -0
- data/lib/generators/admin_resource_generator.rb +16 -0
- data/lib/generators/templates/admin_resource/controller.rb +12 -0
- data/lib/generators/templates/admin_resource/decorator.rb +2 -0
- data/lib/generators/templates/admin_resource/views/_form.html.erb +15 -0
- data/lib/k_admin.rb +5 -0
- data/lib/k_admin/engine.rb +4 -0
- data/lib/k_admin/version.rb +3 -0
- data/lib/tasks/k_admin_tasks.rake +4 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 548f45742b3750b2c763fba22d706d97791775f8766bdcbef01ecff5eb4e7846
|
4
|
+
data.tar.gz: d53eaf010835d0871d76abbdd21f7ed0f6efc67aac88f14a61e670115420d026
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1b809d333898acd3da1574910c6d975bc1bcfaa553c50393a83f04fa807ed2bb6da234bb53585b756454307132c5b7f7dfb72310e610a5711bc33e954ab6850
|
7
|
+
data.tar.gz: 40a4bf816a4c9dd82343ccddcd0063ee4b3ade073babf036d6def3e62a29bddbbdf9f4d8cecbf0ad8013f77093740785e2a00a8a23e7a4ac3c456904a71e281b
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Ricardo Marques
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# KAdmin
|
2
|
+
Simple admin interface for data administration.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'k_admin'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
```bash
|
13
|
+
$ bundle
|
14
|
+
```
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
```bash
|
18
|
+
$ gem install k_admin
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
To add a resource to the admin dashboard just run the following command
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
rails g admin_resource model_name
|
26
|
+
```
|
27
|
+
|
28
|
+
That'll create the following files, which you then can adapt to your model
|
29
|
+
|
30
|
+
```bash
|
31
|
+
/app/controllers/admin/model_name_controller.rb # model controller
|
32
|
+
/app/decorators/model_name_decorator.rb # model decorator
|
33
|
+
/app/views/admin/_form.html.erb # model form
|
34
|
+
```
|
35
|
+
|
36
|
+
All the remaining views/controllers logic will be defaulted to this engine files. To override them just create them on your local repo and you're good to go.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kollegorna/k-admin.
|
40
|
+
|
41
|
+
## License
|
42
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'KAdmin'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("spec/test_app/Rakefile", __dir__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class Admin::ResourcesController < Admin::BaseController
|
2
|
+
# generic controller for model admin manipulation
|
3
|
+
before_action :load_resource, only: [:show, :edit, :update, :destroy]
|
4
|
+
|
5
|
+
def new
|
6
|
+
@resource = resource_class.new.decorate
|
7
|
+
authorize @resource
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
@resource = resource_class.new(resource_params)
|
12
|
+
authorize @resource
|
13
|
+
|
14
|
+
if @resource.save
|
15
|
+
redirect_to admin_resource_path
|
16
|
+
else
|
17
|
+
@resource = @resource.decorate
|
18
|
+
render :new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def index
|
23
|
+
@resources = paginate resource_class.all
|
24
|
+
@resource_class = resource_class
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
if @resource.update(resource_params)
|
35
|
+
redirect_to action: :show
|
36
|
+
else
|
37
|
+
render 'edit'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy
|
42
|
+
if @resource.destroy
|
43
|
+
redirect_to admin_resource_path, notice: t("deleted")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def load_resource
|
50
|
+
@resource = resource_class.find(params[:id]).decorate
|
51
|
+
authorize @resource
|
52
|
+
end
|
53
|
+
|
54
|
+
def resource_class
|
55
|
+
# has to be defined by the subclass
|
56
|
+
fail 'not defined'
|
57
|
+
end
|
58
|
+
|
59
|
+
def resource_params
|
60
|
+
# has to be defined by the subclass
|
61
|
+
fail 'not defined'
|
62
|
+
end
|
63
|
+
|
64
|
+
def admin_resource_path
|
65
|
+
send("admin_#{resource_class.to_s.downcase.pluralize}_path")
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ResourceDecorator < ApplicationDecorator
|
2
|
+
delegate_all
|
3
|
+
|
4
|
+
def admin_path
|
5
|
+
model.persisted? ? helpers.send("admin_#{model_name.singular}_path", model) : helpers.send("admin_#{model_name.plural}_path")
|
6
|
+
end
|
7
|
+
|
8
|
+
def edit_admin_path
|
9
|
+
helpers.send("edit_admin_#{model_name.singular}_path", model)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.new_admin_path
|
13
|
+
helpers.send("new_admin_#{model_name.singular}_path")
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= render 'form' %>
|
2
|
+
|
3
|
+
<% if policy(@resource).destroy? %>
|
4
|
+
<footer class="footer">
|
5
|
+
<%= button_to t("destroy"),
|
6
|
+
{ action: 'destroy', id: @resource.id }, method: :delete,
|
7
|
+
data: { confirm: t("are_you_sure"), disable_with: t("deleting") },
|
8
|
+
class: 'button warning' %>
|
9
|
+
</footer>
|
10
|
+
<% end %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<table class="stack">
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th><%= t(".name") %></th>
|
5
|
+
<th> </th>
|
6
|
+
</tr>
|
7
|
+
</thead>
|
8
|
+
|
9
|
+
<% @resources.each do |resource| %>
|
10
|
+
<%= render 'resource', resource: resource %>
|
11
|
+
<% end %>
|
12
|
+
</table>
|
13
|
+
|
14
|
+
<%= paginate @resources %>
|
15
|
+
|
16
|
+
<%= link_to t(".add"), @resource_class.decorator_class.new_admin_path, class: "button" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render "form", resource: @resource %>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Admin Dashboard</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
|
7
|
+
<!-- Using CDN, no customization of foundation so not requiring gem -->
|
8
|
+
<%= stylesheet_link_tag 'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.4.3/css/foundation-float.css' %>
|
9
|
+
<%= javascript_include_tag 'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.4.3/js/foundation.min.js' %>
|
10
|
+
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
12
|
+
</head>
|
13
|
+
|
14
|
+
<body>
|
15
|
+
<%= render 'shared/admin/header' %>
|
16
|
+
|
17
|
+
<% # rendering partial header if existing %>
|
18
|
+
<%= render "admin/#{controller_name}/header" rescue nil %>
|
19
|
+
|
20
|
+
<%= yield %>
|
21
|
+
|
22
|
+
<%= render 'shared/footer' %>
|
23
|
+
</body>
|
24
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
# Add initialization content here
|
data/config/routes.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
namespace :admin do
|
3
|
+
# dynamically fetching routes from views folder
|
4
|
+
Dir.glob('app/views/admin/*').select { |f| File.directory? f }.map { |directory| directory.split('/').last.to_sym }.each do |resources|
|
5
|
+
resources resources
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class AdminResourceGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
include Rails::Generators::ResourceHelpers
|
4
|
+
|
5
|
+
def create_controller_file
|
6
|
+
template "admin_resource/controller.rb", File.join("app/controllers/admin/", "#{controller_file_name}_controller.rb")
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_decorator_file
|
10
|
+
template "admin_resource/decorator.rb", File.join("app/decorators/", "#{singular_name}_decorator.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_view_file
|
14
|
+
copy_file "admin_resource/views/_form.html.erb", "app/views/admin/#{plural_name}/_form.html.erb"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= simple_form_for @resource, url: @resource.admin_path do |f| %>
|
2
|
+
<!-- add input fields here (Example below) -->
|
3
|
+
<!-- div class="row">
|
4
|
+
<div class="small-12 columns">
|
5
|
+
<%= f.label :name %>
|
6
|
+
<%= f.input :name %>
|
7
|
+
</div>
|
8
|
+
</div -->
|
9
|
+
|
10
|
+
<div class="row">
|
11
|
+
<div class="small-12 columns">
|
12
|
+
<%= f.submit t("save"), class: "button" %>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
data/lib/k_admin.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: k_admin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricardo Marques
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: draper
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Simple admin interface for data administration.
|
56
|
+
email:
|
57
|
+
- ricardo.ds.marques@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- app/assets/config/k_admin_manifest.js
|
66
|
+
- app/controllers/admin/base_controller.rb
|
67
|
+
- app/controllers/admin/resources_controller.rb
|
68
|
+
- app/decorators/resource_decorator.rb
|
69
|
+
- app/helpers/admin/forms_helper.rb
|
70
|
+
- app/views/admin/base/_resource.html.erb
|
71
|
+
- app/views/admin/base/edit.html.erb
|
72
|
+
- app/views/admin/base/index.html.erb
|
73
|
+
- app/views/admin/base/new.html.erb
|
74
|
+
- app/views/admin/base/show.html.erb
|
75
|
+
- app/views/layouts/admin.html.erb
|
76
|
+
- app/views/shared/admin/_header.html.erb
|
77
|
+
- config/initializers/assets.rb
|
78
|
+
- config/initializers/initializer.rb
|
79
|
+
- config/locales/admin.en.yml
|
80
|
+
- config/routes.rb
|
81
|
+
- lib/generators/admin_resource_generator.rb
|
82
|
+
- lib/generators/templates/admin_resource/controller.rb
|
83
|
+
- lib/generators/templates/admin_resource/decorator.rb
|
84
|
+
- lib/generators/templates/admin_resource/views/_form.html.erb
|
85
|
+
- lib/k_admin.rb
|
86
|
+
- lib/k_admin/engine.rb
|
87
|
+
- lib/k_admin/version.rb
|
88
|
+
- lib/tasks/k_admin_tasks.rake
|
89
|
+
homepage: https://github.com/kollegorna/k-admin
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.7.6
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Simple admin interface for data administration.
|
113
|
+
test_files: []
|