five-two-nw-olivander 0.1.1 → 0.1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/adminlte.css +1 -0
- data/app/components/olivander/components/menu_item_component.html.haml +19 -0
- data/app/components/olivander/components/menu_item_component.rb +10 -0
- data/app/controllers/olivander/resources/crud_chain.rb +119 -0
- data/app/controllers/olivander/resources/crud_controller.rb +55 -0
- data/app/controllers/olivander/resources/default_crud_chain.rb +48 -0
- data/app/controllers/olivander/test_controller.rb +35 -0
- data/app/datatables/olivander/datatable.rb +18 -0
- data/app/helpers/olivander/application_helper.rb +10 -1
- data/app/views/application/edit.html.haml +11 -0
- data/app/views/application/index.html.haml +24 -0
- data/app/views/application/new.html.haml +11 -0
- data/app/views/application/show.html.haml +14 -0
- data/app/views/layouts/olivander/adminlte/_content.html.haml +5 -1
- data/app/views/layouts/olivander/adminlte/_footer.html.haml +5 -3
- data/app/views/layouts/olivander/adminlte/_head.html.haml +1 -1
- data/app/views/layouts/olivander/adminlte/_navbar.html.haml +3 -4
- data/app/views/layouts/olivander/adminlte/_sidebar.html.haml +4 -2
- data/app/views/layouts/olivander/adminlte/main.html.haml +2 -1
- data/lib/five-two-nw-olivander.rb +1 -0
- data/lib/olivander/application_context.rb +53 -0
- data/lib/olivander/menus/menu_item.rb +106 -0
- data/lib/olivander/menus.rb +1 -0
- data/lib/olivander/version.rb +1 -1
- data/lib/olivander.rb +4 -2
- metadata +45 -3
- /data/config/initializers/{effective_datatables.rb → effective_datatables.rb.old} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc230db07c2624d5ca4398239976b374c1fcdec0a4d741a27387f7ecfd3705dd
|
4
|
+
data.tar.gz: 45767c0b8bfca58e6ce48672e6c8bc310baec3bc15c2bedf8f34d95e330085a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b96d61fa31cb64a25fd0ceb3097979d4874763f88891fc503318a7b3f30fde73f306e9973525205f3876b9ea07739f7f4c45b4fa24c814289bcf2564984d0077
|
7
|
+
data.tar.gz: 74ca5454b8081887b6c16ede1e4fa941248bc8854d41998dab7007011b07fe548efc6b970b1f5ccc6999b58d15a4a90fdb4e328e1b20992e0404c1397186a9fd
|
@@ -18,6 +18,7 @@
|
|
18
18
|
*= require 'adminlte/plugins/daterangepicker/daterangepicker'
|
19
19
|
*= require 'adminlte/plugins/summernote/summernote-bs4.min'
|
20
20
|
*= require 'adminlte/plugins/fontawesome-free/css/all.min'
|
21
|
+
*= require effective_datatables
|
21
22
|
*= require_tree .
|
22
23
|
*= require_self
|
23
24
|
*/
|
@@ -0,0 +1,19 @@
|
|
1
|
+
- if menu_item.visible
|
2
|
+
- if menu_item.href
|
3
|
+
%li.nav-item
|
4
|
+
%a.nav-link{href: menu_item.href}
|
5
|
+
- if menu_item.icon_class
|
6
|
+
%i.nav-icon{class: menu_item.icon_class}
|
7
|
+
%p
|
8
|
+
= menu_item.text
|
9
|
+
- if menu_item.submenu_items.size.positive?
|
10
|
+
%i.fas.fa-angle-left.right
|
11
|
+
- menu_item.badges.each do |badge|
|
12
|
+
%span.badge.right{ class: "badge-#{badge.badge_class}" }
|
13
|
+
= badge.text
|
14
|
+
- if menu_item.submenu_items.size.positive?
|
15
|
+
%ul.nav.nav-treeview
|
16
|
+
- menu_item.submenu_items.each do |item|
|
17
|
+
= render Olivander::Components::MenuItemComponent.new(item)
|
18
|
+
- else
|
19
|
+
%li.nav-header= menu_item.text.upcase
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module Olivander
|
2
|
+
module Resources
|
3
|
+
class CrudChain
|
4
|
+
attr_accessor :controller
|
5
|
+
|
6
|
+
def initialize(controller)
|
7
|
+
@controller = controller
|
8
|
+
end
|
9
|
+
|
10
|
+
def links
|
11
|
+
@links ||= {
|
12
|
+
authorize_action: nil,
|
13
|
+
before_load: nil, load_resource: nil, after_load: nil,
|
14
|
+
authorize_resource: nil,
|
15
|
+
before_assign: nil, assign: nil, after_assign: nil,
|
16
|
+
update_if: nil,
|
17
|
+
before_update: nil, update: nil, after_update: nil,
|
18
|
+
update_success: nil, update_failure: nil,
|
19
|
+
render_success: nil, render_failure: nil
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def on(chain_link, &block)
|
24
|
+
raise "Invalid Link: #{chain_link}" unless links.keys.include?(chain_link)
|
25
|
+
|
26
|
+
links[chain_link] = block
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def skip_load
|
31
|
+
clear_keys(%i[before_load load_resource after_load])
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def skip_assign
|
36
|
+
clear_keys(%i[before_assign assign after_assign])
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def skip_update
|
41
|
+
update_if { false }
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
def skip_render
|
46
|
+
clear_keys(%i[render_success render_failure])
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def execute
|
51
|
+
execute_link_keys(%i[authorize_action before_load load_resource after_load authorize_resource before_assign assign after_assign])
|
52
|
+
success = perform_update
|
53
|
+
# we may not do any update - in which case we assume success
|
54
|
+
success = true if success.nil?
|
55
|
+
execute_link_key(success ? :render_success : :render_failure)
|
56
|
+
success
|
57
|
+
end
|
58
|
+
|
59
|
+
# def self.test
|
60
|
+
# CrudChain.new('string')
|
61
|
+
# .before_load { puts "we did a before load from within this action: #{self}" }
|
62
|
+
# .before_update { puts "we are doing a before_update on a controller named: #{self.class.name}" }
|
63
|
+
# .execute
|
64
|
+
# end
|
65
|
+
|
66
|
+
def clear_keys(keys)
|
67
|
+
keys.each { |k| clear_key(k) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def clear_keys_except(keys)
|
71
|
+
(links.keys - keys).each { |k| clear_key(k) }
|
72
|
+
end
|
73
|
+
|
74
|
+
def clear_key(key)
|
75
|
+
links[key] = nil
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def perform_update
|
81
|
+
perform_update = execute_link_key(:update_if)
|
82
|
+
perform_update = true if perform_update.nil?
|
83
|
+
return false unless perform_update
|
84
|
+
|
85
|
+
execute_link_key(:before_update)
|
86
|
+
success = execute_link_key(:update)
|
87
|
+
execute_link_key(:after_update)
|
88
|
+
execute_link_key(success ? :update_success : :update_failure)
|
89
|
+
success
|
90
|
+
end
|
91
|
+
|
92
|
+
def execute_link_keys(keys)
|
93
|
+
keys.each do |k|
|
94
|
+
execute_link_key(k)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def execute_link_key(key)
|
99
|
+
block = links[key]
|
100
|
+
return if block.nil?
|
101
|
+
|
102
|
+
@controller.instance_exec(&block)
|
103
|
+
end
|
104
|
+
|
105
|
+
def respond_to_missing?(method_name, _include_private = false)
|
106
|
+
links.keys.include?(method_name.to_sym)
|
107
|
+
end
|
108
|
+
|
109
|
+
# syntax sugar to allow direct assignment of a chain link
|
110
|
+
def method_missing(m, *args, &block)
|
111
|
+
if respond_to_missing?(m)
|
112
|
+
send(:on, m, &block)
|
113
|
+
else
|
114
|
+
super
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Olivander
|
2
|
+
module Resources
|
3
|
+
module CrudController
|
4
|
+
def index
|
5
|
+
execute_crud_chain(crud_action: :index)
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
execute_crud_chain(crud_action: :new)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
execute_crud_chain(crud_action: :create)
|
14
|
+
end
|
15
|
+
|
16
|
+
def show
|
17
|
+
execute_crud_chain(crud_action: :show)
|
18
|
+
end
|
19
|
+
|
20
|
+
def edit
|
21
|
+
execute_crud_chain(crud_action: :edit)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
execute_crud_chain(crud_action: :update)
|
26
|
+
end
|
27
|
+
|
28
|
+
def destroy
|
29
|
+
execute_crud_chain(crud_action: :destroy)
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute_crud_chain(crud_action: action_name, only: [], skip: [], &block)
|
33
|
+
chain = default_crud_chain(crud_action)
|
34
|
+
chain.clear_keys_except(only) if only.size.positive?
|
35
|
+
chain.clear_keys(skip) if skip.size.positive?
|
36
|
+
yield(chain) if block_given?
|
37
|
+
chain.execute
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_crud_chain(crud_action = '')
|
41
|
+
chain = Olivander::Resources::CrudChain.new(self)
|
42
|
+
chain.links.keys.each do |k|
|
43
|
+
method_name = "crud_chain_#{crud_action}_#{k}"
|
44
|
+
method_name = "crud_chain_#{k}" unless respond_to?(method_name)
|
45
|
+
next unless respond_to?(method_name)
|
46
|
+
|
47
|
+
chain.on(k) do
|
48
|
+
send(method_name)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
chain
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Olivander
|
2
|
+
module Resources
|
3
|
+
module DefaultCrudChain
|
4
|
+
def crud_chain_index_authorize_action
|
5
|
+
puts 'default crud chain: index_authorize_action'
|
6
|
+
end
|
7
|
+
|
8
|
+
def crud_chain_index_load_resource
|
9
|
+
puts 'default crud chain: index_load_resource'
|
10
|
+
end
|
11
|
+
|
12
|
+
def crud_chain_load_resource
|
13
|
+
puts 'default crud chain: load_resource'
|
14
|
+
end
|
15
|
+
|
16
|
+
def crud_chain_authorize_resource
|
17
|
+
raise 'Unauthorized' unless true
|
18
|
+
puts 'default crud chain: authorize_resource'
|
19
|
+
end
|
20
|
+
|
21
|
+
def crud_chain_assign
|
22
|
+
puts 'default crud chain: assign'
|
23
|
+
end
|
24
|
+
|
25
|
+
def crud_chain_update_if
|
26
|
+
puts 'default crud chain: update_if'
|
27
|
+
return true if %w[create update destroy].include?(action_name)
|
28
|
+
return false if %w[index new show edit].include?(action_name)
|
29
|
+
return false if request.method == 'GET'
|
30
|
+
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def crud_chain_update
|
35
|
+
puts 'default crud chain: update'
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def crud_chain_render_success
|
40
|
+
puts 'default crud chain: render_success'
|
41
|
+
end
|
42
|
+
|
43
|
+
def crud_chain_render_failure
|
44
|
+
puts 'default crud chain: render_failure'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Olivander
|
2
|
+
class TestController < ApplicationController
|
3
|
+
include Olivander::Resources::CrudController
|
4
|
+
include Olivander::Resources::DefaultCrudChain
|
5
|
+
|
6
|
+
def index
|
7
|
+
execute_crud_chain(crud_action: :index) do |c|
|
8
|
+
c.authorize_resource { puts 'block: authorize_resource'; true }
|
9
|
+
.update { puts 'block: update'; true }
|
10
|
+
.before_assign { puts 'block: before assign' }
|
11
|
+
.after_assign { puts 'block: after assign' }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# def crud_chain_update
|
16
|
+
# puts 'controller: update'
|
17
|
+
# end
|
18
|
+
|
19
|
+
# def crud_chain_index_update
|
20
|
+
# puts 'controller: index_update'
|
21
|
+
# end
|
22
|
+
|
23
|
+
# def crud_chain_before_load
|
24
|
+
# puts 'controller: before_load'
|
25
|
+
# end
|
26
|
+
|
27
|
+
# def crud_chain_after_update
|
28
|
+
# puts 'controller: after_update'
|
29
|
+
# end
|
30
|
+
|
31
|
+
# def crud_chain_index_after_update
|
32
|
+
# puts 'controller: index_after_update'
|
33
|
+
# end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Olivander
|
2
|
+
class Datatable < Effective::Datatable
|
3
|
+
def link_col(field, path, path_args)
|
4
|
+
dsl_tool.col(field) do |r|
|
5
|
+
args = [].tap do |arr|
|
6
|
+
if path_args.is_a? Array
|
7
|
+
path_args.each do |arg|
|
8
|
+
arr << r.send(arg)
|
9
|
+
end
|
10
|
+
else
|
11
|
+
arr << r.send(path_args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
link_to r.send(field), send(path, args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,7 +1,16 @@
|
|
1
1
|
module Olivander
|
2
2
|
module ApplicationHelper
|
3
3
|
def page_title
|
4
|
-
|
4
|
+
return @page_title if @page_title
|
5
|
+
|
6
|
+
cf = content_for(:title)
|
7
|
+
return cf unless cf.blank?
|
8
|
+
|
9
|
+
controller_key = controller.class.name.underscore
|
10
|
+
key = "page_titles.#{controller_key}.#{action_name}"
|
11
|
+
return I18n.t(key) if I18n.exists?(key)
|
12
|
+
|
13
|
+
"#{controller_name}: #{action_name}".titleize
|
5
14
|
end
|
6
15
|
|
7
16
|
def user_image_path(user)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
- resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
2
|
+
- @resource = instance_variable_get('@' + resource.name) if resource.name
|
3
|
+
|
4
|
+
- if @resource
|
5
|
+
.row
|
6
|
+
.col-8
|
7
|
+
%h1= @page_title
|
8
|
+
.col-4.text-right
|
9
|
+
= render_resource_buttons(@resource, edit: false)
|
10
|
+
|
11
|
+
= render_resource_form(@resource)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
- resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
2
|
+
|
3
|
+
.row
|
4
|
+
.col-12
|
5
|
+
.card
|
6
|
+
.card-header
|
7
|
+
%h1= @page_title
|
8
|
+
.card-body
|
9
|
+
- if @datatable
|
10
|
+
= render_datatable(@datatable)
|
11
|
+
|
12
|
+
- elsif instance_variable_get('@' + resource.plural_name).respond_to?(:to_partial_path)
|
13
|
+
= render instance_variable_get('@' + resource.plural_name)
|
14
|
+
|
15
|
+
- elsif instance_variable_get('@' + resource.name).respond_to?(:to_partial_path)
|
16
|
+
= render instance_variable_get('@' + resource.name)
|
17
|
+
|
18
|
+
- elsif Rails.env.development?
|
19
|
+
%p effective_resources index view is not sure what to render.
|
20
|
+
%p Define an @datatable, @#{resource.try(:plural_name) || 'a plural'}, or @#{resource.try(:name) || 'a singular'}.
|
21
|
+
%p or include Effective::CrudController in your controller
|
22
|
+
.card-footer
|
23
|
+
= render_resource_buttons(resource.klass, (action ||= :index) => false)
|
24
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
- resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
2
|
+
- @resource = instance_variable_get('@' + resource.name) if resource.name
|
3
|
+
|
4
|
+
- if @resource
|
5
|
+
.row
|
6
|
+
.col-8
|
7
|
+
%h1= @page_title
|
8
|
+
.col-4.text-right
|
9
|
+
= render_resource_buttons(@resource)
|
10
|
+
|
11
|
+
= render_resource_form(@resource)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
- resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
2
|
+
- @resource = instance_variable_get('@' + resource.name) if resource.name
|
3
|
+
|
4
|
+
- if @resource
|
5
|
+
.row
|
6
|
+
.col-8
|
7
|
+
%h1= @page_title
|
8
|
+
.col-4.text-right
|
9
|
+
= render_resource_buttons(@resource, show: false)
|
10
|
+
|
11
|
+
= render_resource_partial(@resource)
|
12
|
+
|
13
|
+
.form-actions
|
14
|
+
= link_to 'Continue', (resource.action_path(:index) || root_path), class: 'btn btn-primary'
|
@@ -2,8 +2,10 @@
|
|
2
2
|
%strong
|
3
3
|
Copyright © #{Date.current.year}
|
4
4
|
= succeed "." do
|
5
|
-
|
5
|
+
= link_to @context.company.name, @context.company.url
|
6
6
|
All rights reserved.
|
7
7
|
.float-right.d-none.d-sm-inline-block
|
8
|
-
|
9
|
-
|
8
|
+
.text-small
|
9
|
+
Powered by
|
10
|
+
= link_to '5&2 Northwest', 'https://www.5and2northwest.com'
|
11
|
+
%b Olivander v#{Olivander::VERSION}
|
@@ -5,10 +5,9 @@
|
|
5
5
|
%li.nav-item
|
6
6
|
%a.nav-link{"data-widget" => "pushmenu", :href => "#", :role => "button"}
|
7
7
|
%i.fas.fa-bars
|
8
|
-
|
9
|
-
%
|
10
|
-
|
11
|
-
%a.nav-link{:href => "/system"} System
|
8
|
+
- @context.visible_modules.each do |menu_item|
|
9
|
+
%li.nav-item.d-none.d-sm-inline-block
|
10
|
+
= link_to menu_item.text, menu_item.href, class: 'nav-link'
|
12
11
|
/ Right navbar links
|
13
12
|
%ul.navbar-nav.ml-auto
|
14
13
|
/ Navbar Search
|
@@ -2,8 +2,8 @@
|
|
2
2
|
%aside.main-sidebar.sidebar-dark-primary.elevation-4{ data: { controller: 'left-nav' }}
|
3
3
|
/ Brand Logo
|
4
4
|
%a.brand-link.bg-info{:href => "/"}
|
5
|
-
%img.brand-image.img-circle.elevation-3{:alt => @context.
|
6
|
-
%span.brand-text.font-weight-light= @context.
|
5
|
+
%img.brand-image.img-circle.elevation-3{:alt => @context.logo.alt, :src => @context.logo.url, :style => "opacity: .8"}/
|
6
|
+
%span.brand-text.font-weight-light= @context.name
|
7
7
|
/ Sidebar
|
8
8
|
.sidebar
|
9
9
|
/ Sidebar user panel (optional)
|
@@ -22,3 +22,5 @@
|
|
22
22
|
/ Sidebar Menu
|
23
23
|
%nav.mt-2
|
24
24
|
%ul.nav.nav-pills.nav-sidebar.nav-compact.flex-column{"data-accordion" => "false", "data-widget" => "treeview", :role => "menu"}
|
25
|
+
- @context.menu_items.each do |menu_item|
|
26
|
+
= render Olivander::Components::MenuItemComponent.new(menu_item)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
!!!
|
2
2
|
%html
|
3
|
-
- @context
|
3
|
+
- @context ||= Olivander::ApplicationContext.default
|
4
4
|
= render partial: 'layouts/olivander/adminlte/head'
|
5
5
|
- sidebar_collapse = cookies['lte.pushmenu.collapsed'] == 'true' ? 'sidebar-collapse' : ''
|
6
6
|
%body.hold-transition.sidebar-mini.layout-fixed{ class: sidebar_collapse }
|
@@ -15,3 +15,4 @@
|
|
15
15
|
= render partial: 'layouts/olivander/adminlte/flashes'
|
16
16
|
= render partial: 'layouts/olivander/adminlte/footer'
|
17
17
|
= render partial: 'layouts/olivander/adminlte/control_sidebar'
|
18
|
+
= content_for :javascript
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Olivander
|
2
|
+
class ApplicationContext
|
3
|
+
attr_accessor :name, :logo, :company, :menu_items
|
4
|
+
|
5
|
+
def self.default
|
6
|
+
ctx = ApplicationContext.new
|
7
|
+
ctx.company.name = 'Company Name'
|
8
|
+
ctx
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(name: 'Application Name', logo: Logo.new, company: Company.new, menu_items: [])
|
12
|
+
self.name = name
|
13
|
+
self.logo = logo
|
14
|
+
self.company = company
|
15
|
+
self.menu_items = menu_items
|
16
|
+
end
|
17
|
+
|
18
|
+
def visible_modules
|
19
|
+
[].tap do |arr|
|
20
|
+
menu_items.each do |menu_item|
|
21
|
+
arr << visible_modules_for(menu_item)
|
22
|
+
end
|
23
|
+
end.flatten
|
24
|
+
end
|
25
|
+
|
26
|
+
def visible_modules_for(menu_item)
|
27
|
+
[].tap do |arr|
|
28
|
+
arr << menu_item if menu_item.module? && menu_item.visible
|
29
|
+
menu_item.submenu_items.each do |sub|
|
30
|
+
arr << visible_modules_for(sub)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Logo
|
36
|
+
attr_accessor :url, :alt
|
37
|
+
|
38
|
+
def initialize(url: nil, alt: 'Logo')
|
39
|
+
self.url = url
|
40
|
+
self.alt = alt
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Company
|
45
|
+
attr_accessor :name, :url
|
46
|
+
|
47
|
+
def initialize(name: nil, url: nil)
|
48
|
+
self.url = url
|
49
|
+
self.name = name
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Olivander
|
2
|
+
module Menus
|
3
|
+
class MenuItem
|
4
|
+
attr_reader :href
|
5
|
+
|
6
|
+
def initialize(key, href = nil, icon = nil, is_module: false)
|
7
|
+
@key = key
|
8
|
+
@href = href
|
9
|
+
@icon = icon
|
10
|
+
@submenu_items_blocks = []
|
11
|
+
@badges_blocks = []
|
12
|
+
@module = is_module
|
13
|
+
end
|
14
|
+
|
15
|
+
def module?
|
16
|
+
@module
|
17
|
+
end
|
18
|
+
|
19
|
+
def text
|
20
|
+
resolved_key(@key, "menus.#{@key}.text")
|
21
|
+
end
|
22
|
+
|
23
|
+
def icon_class
|
24
|
+
@icon || resolved_key(@key, "menus.#{@key}.icon", 'menus.default_icon')
|
25
|
+
end
|
26
|
+
|
27
|
+
def visible
|
28
|
+
@visible ||= evaluate_conditions_block
|
29
|
+
end
|
30
|
+
|
31
|
+
def with_condition(&block)
|
32
|
+
@conditions_block = block
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def with_submenu_items(&block)
|
37
|
+
@submenu_items_blocks << block
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def submenu_items
|
42
|
+
@submenu_items ||= [].tap do |arr|
|
43
|
+
if visible
|
44
|
+
@submenu_items_blocks.each do |block|
|
45
|
+
Rails.logger.debug "invoking submenu item block on #{@key}"
|
46
|
+
block.call.each { |item| arr << item if item.visible }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def with_badges(&block)
|
53
|
+
@badges_blocks << block
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def badges
|
58
|
+
@badges ||= [].tap do |arr|
|
59
|
+
if visible
|
60
|
+
@badges_blocks.each do |block|
|
61
|
+
Rails.logger.debug "invoking badge block on #{@key}"
|
62
|
+
block.call.each { |badge| arr << badge }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def evaluate_conditions_block
|
71
|
+
if @conditions_block
|
72
|
+
Rails.logger.debug "invoking condition on #{@key}"
|
73
|
+
@conditions_block.call
|
74
|
+
else
|
75
|
+
true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def resolved_key(raw, key = nil, fallback = nil)
|
80
|
+
return nil unless raw
|
81
|
+
|
82
|
+
if key && I18n.exists?(key)
|
83
|
+
I18n.t(key)
|
84
|
+
elsif fallback && I18n.exists?(fallback)
|
85
|
+
I18n.t(fallback)
|
86
|
+
else
|
87
|
+
raw.titleize
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class Badge
|
93
|
+
attr_accessor :text, :badge_class
|
94
|
+
|
95
|
+
def initialize(text = nil, badge_class = nil)
|
96
|
+
@text = text
|
97
|
+
@badge_class = badge_class
|
98
|
+
end
|
99
|
+
|
100
|
+
def with_proc
|
101
|
+
yield(self)
|
102
|
+
self
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'olivander/menus/menu_item'
|
data/lib/olivander/version.rb
CHANGED
data/lib/olivander.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: five-two-nw-olivander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1
|
4
|
+
version: 0.1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Dennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03
|
11
|
+
date: 2023-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chartkick
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.2.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simple_form
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: view_component
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Description of Olivander.
|
84
112
|
email:
|
85
113
|
- devops@5and2northwest.com
|
@@ -141,12 +169,23 @@ files:
|
|
141
169
|
- app/assets/stylesheets/adminlte.css
|
142
170
|
- app/assets/stylesheets/fa-fix.scss
|
143
171
|
- app/assets/stylesheets/olivander/application.css
|
172
|
+
- app/components/olivander/components/menu_item_component.html.haml
|
173
|
+
- app/components/olivander/components/menu_item_component.rb
|
144
174
|
- app/controllers/olivander/application_controller.rb
|
175
|
+
- app/controllers/olivander/resources/crud_chain.rb
|
176
|
+
- app/controllers/olivander/resources/crud_controller.rb
|
177
|
+
- app/controllers/olivander/resources/default_crud_chain.rb
|
178
|
+
- app/controllers/olivander/test_controller.rb
|
179
|
+
- app/datatables/olivander/datatable.rb
|
145
180
|
- app/datatables/test_datatable.rb
|
146
181
|
- app/helpers/olivander/application_helper.rb
|
147
182
|
- app/jobs/olivander/application_job.rb
|
148
183
|
- app/mailers/olivander/application_mailer.rb
|
149
184
|
- app/models/olivander/application_record.rb
|
185
|
+
- app/views/application/edit.html.haml
|
186
|
+
- app/views/application/index.html.haml
|
187
|
+
- app/views/application/new.html.haml
|
188
|
+
- app/views/application/show.html.haml
|
150
189
|
- app/views/layouts/olivander/adminlte/_content.html.haml
|
151
190
|
- app/views/layouts/olivander/adminlte/_content_kanban.html.haml
|
152
191
|
- app/views/layouts/olivander/adminlte/_control_sidebar.html.haml
|
@@ -159,11 +198,14 @@ files:
|
|
159
198
|
- app/views/layouts/olivander/adminlte/login.html.haml
|
160
199
|
- app/views/layouts/olivander/adminlte/main.html.haml
|
161
200
|
- app/views/layouts/olivander/application.html.haml
|
162
|
-
- config/initializers/effective_datatables.rb
|
201
|
+
- config/initializers/effective_datatables.rb.old
|
163
202
|
- config/routes.rb
|
164
203
|
- lib/five-two-nw-olivander.rb
|
165
204
|
- lib/olivander.rb
|
205
|
+
- lib/olivander/application_context.rb
|
166
206
|
- lib/olivander/engine.rb
|
207
|
+
- lib/olivander/menus.rb
|
208
|
+
- lib/olivander/menus/menu_item.rb
|
167
209
|
- lib/olivander/version.rb
|
168
210
|
- lib/tasks/olivander_tasks.rake
|
169
211
|
homepage: https://rubygems.org/gems/olivander
|
File without changes
|