-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
170 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
<div class="block md:inline-block md:w-32 flex-shrink-0 text-gray-700"> | ||
<%= render "madmin/shared/label", form: form, field: field %> | ||
</div> | ||
<%= form.text_field field.attribute_name, class: "flex-grow form-input" %> | ||
<%= form.text_field field.attribute_name, class: "form-input" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module Madmin | ||
class Menu | ||
def initialize | ||
@children = {} | ||
end | ||
|
||
def reset | ||
@children = {} | ||
end | ||
|
||
def before_render(&block) | ||
if block_given? | ||
@before_render = block | ||
else | ||
@before_render | ||
end | ||
end | ||
|
||
def render(&block) | ||
instance_eval(&@before_render) if @before_render | ||
|
||
# Ensure all the resources have been added to the menu | ||
Madmin.resources.each do |resource| | ||
next if resource.menu_options == false | ||
add resource.menu_options | ||
end | ||
|
||
items.each(&block) | ||
end | ||
|
||
module Node | ||
def add(options) | ||
options = options.dup | ||
|
||
if (parent = options.delete(:parent)) | ||
@children[parent] ||= Item.new(label: parent) | ||
@children[parent].add options | ||
else | ||
item = Item.new(**options) | ||
@children[item.label] = item | ||
end | ||
end | ||
|
||
def items | ||
@children.values.sort do |a, b| | ||
result = a.position <=> b.position | ||
result = a.label <=> b.label if result == 0 # sort alphabetically for the same position | ||
result | ||
end | ||
end | ||
end | ||
|
||
include Node | ||
|
||
class Item | ||
include Node | ||
|
||
attr_reader :label, :url, :position, :parent, :children | ||
|
||
def initialize(label:, url: nil, position: 99, parent: nil, **options) | ||
@label = label | ||
@url = url | ||
@position = position | ||
@parent = parent | ||
@if = options.delete(:if) | ||
@children = {} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters