-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add madmin initial implementation #295
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Madmin | ||
class ApplicationController < Madmin::BaseController | ||
before_action :ensure_admin | ||
|
||
def ensure_admin | ||
redirect_to "/" if current_user.nil? || !current_user.admin | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Madmin | ||
class EstimatesController < Madmin::ResourceController | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Madmin | ||
class ProjectsController < Madmin::ResourceController | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Madmin | ||
class StoriesController < Madmin::ResourceController | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Madmin | ||
class UsersController < Madmin::ResourceController | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class EstimateResource < Madmin::Resource | ||
# Attributes | ||
attribute :id, form: false | ||
attribute :best_case_points | ||
attribute :worst_case_points | ||
|
||
# Associations | ||
attribute :story | ||
attribute :user | ||
|
||
# Uncomment this to customize the display name of records in the admin area. | ||
# def self.display_name(record) | ||
# record.name | ||
# end | ||
|
||
# Uncomment this to customize the default sort column and direction. | ||
# def self.default_sort_column | ||
# "created_at" | ||
# end | ||
# | ||
# def self.default_sort_direction | ||
# "desc" | ||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class ProjectResource < Madmin::Resource | ||
# Attributes | ||
attribute :id, form: false | ||
attribute :title | ||
attribute :status | ||
|
||
# Associations | ||
attribute :stories | ||
attribute :estimates | ||
attribute :users | ||
attribute :parent | ||
attribute :projects | ||
|
||
def self.display_name(record) | ||
record.title.truncate(20) | ||
end | ||
|
||
# Uncomment this to customize the default sort column and direction. | ||
# def self.default_sort_column | ||
# "created_at" | ||
# end | ||
# | ||
# def self.default_sort_direction | ||
# "desc" | ||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class StoryResource < Madmin::Resource | ||
# Attributes | ||
attribute :id, form: false | ||
attribute :title | ||
attribute :description | ||
attribute :real_score | ||
attribute :extra_info | ||
|
||
# Associations | ||
attribute :project | ||
attribute :estimates | ||
attribute :users | ||
|
||
def self.display_name(record) | ||
record.title.truncate(30) | ||
end | ||
|
||
# Uncomment this to customize the default sort column and direction. | ||
# def self.default_sort_column | ||
# "created_at" | ||
# end | ||
# | ||
# def self.default_sort_direction | ||
# "desc" | ||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class UserResource < Madmin::Resource | ||
# Attributes | ||
attribute :id, form: false | ||
attribute :email | ||
attribute :name | ||
attribute :admin | ||
|
||
# Associations | ||
attribute :estimates | ||
|
||
def self.display_name(record) | ||
record.name.truncate(12) | ||
end | ||
|
||
# Uncomment this to customize the default sort column and direction. | ||
# def self.default_sort_column | ||
# "created_at" | ||
# end | ||
# | ||
# def self.default_sort_direction | ||
# "desc" | ||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="<%= I18n.locale %>"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="ROBOTS" content="NOODP"> | ||
<meta name="viewport" content="initial-scale=1"> | ||
<title> | ||
Madmin: <%= Rails.application.class %> | ||
</title> | ||
|
||
<%= csrf_meta_tags %> | ||
|
||
<%= render "javascript" %> | ||
</head> | ||
<body class="min-h-screen"> | ||
<div class="md:flex w-full min-h-screen"> | ||
<div id="sidebar" class="md:w-64 p-4 flex-shrink-0 border-r"> | ||
<%= render "navigation" -%> | ||
</div> | ||
<main class="flex-grow p-4 overflow-x-scroll" role="main"> | ||
<%#= render "flashes" -%> | ||
<%= yield %> | ||
</main> | ||
</div> | ||
</body> | ||
</html> |
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,23 @@ | ||
<%= form_with model: [:madmin, record], url: (record.persisted? ? resource.show_path(record) : resource.index_path), local: true do |form| %> | ||
<% if form.object.errors.any? %> | ||
<div class="mb-4 rounded-md text-sm text-red-700 bg-red-100 p-4"> | ||
<div class="mb-2 font-medium leading-5 text-red-800">There was <%= pluralize form.object.errors.full_messages.count, "error" %> with your submission</div> | ||
|
||
<% form.object.errors.full_messages.each do |message| %> | ||
<div class="ml-4"><%= message %></div> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
|
||
<% resource.attributes.values.each do |attribute| %> | ||
<% next if attribute.field.nil? %> | ||
<% next unless attribute.field.visible?(action_name) %> | ||
<% next unless attribute.field.visible?(:form) %> | ||
|
||
<div class="mb-4 md:flex"> | ||
<%= render partial: attribute.field.to_partial_path("form"), locals: { field: attribute.field, record: record, form: form, resource: resource } %> | ||
</div> | ||
<% end %> | ||
|
||
<%= form.submit class: "bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow" %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp"></script> | ||
<%= stylesheet_link_tag "https://unpkg.com/flatpickr/dist/flatpickr.min.css", "data-turbo-track": "reload" %> | ||
<%= stylesheet_link_tag "https://unpkg.com/trix/dist/trix.css", "data-turbo-track": "reload" %> | ||
<%= stylesheet_link_tag "https://unpkg.com/tom-select/dist/css/tom-select.min.css", "data-turbo-track": "reload" %> | ||
|
||
<script type="importmap" data-turbo-track="reload"> | ||
{ | ||
"imports": { | ||
"@hotwired/stimulus": "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js", | ||
"@hotwired/turbo": "https://unpkg.com/@hotwired/turbo", | ||
"@hotwired/turbo-rails": "https://unpkg.com/@hotwired/turbo-rails", | ||
"@rails/actiontext": "https://unpkg.com/@rails/actiontext@<%= npm_rails_version %>/app/assets/javascripts/actiontext.js", | ||
"@rails/activestorage": "https://unpkg.com/@rails/activestorage@<%= npm_rails_version %>/app/assets/javascripts/activestorage.esm.js", | ||
"flatpickr": "https://unpkg.com/flatpickr/dist/esm/index.js", | ||
"stimulus-flatpickr": "https://unpkg.com/stimulus-flatpickr@3.0.0-0/dist/index.m.js", | ||
"tailwindcss-stimulus-components": "https://unpkg.com/tailwindcss-stimulus-components/dist/tailwindcss-stimulus-components.modern.js", | ||
"tom-select": "https://unpkg.com/tom-select/dist/esm/tom-select.complete.js", | ||
"trix": "https://unpkg.com/trix" | ||
} | ||
} | ||
</script> | ||
<script async src="https://unpkg.com/es-module-shims/dist/es-module-shims.js"></script> | ||
|
||
<script type="module"> | ||
import * as Turbo from "@hotwired/turbo-rails" | ||
|
||
import * as ActiveStorage from "@rails/activestorage" | ||
ActiveStorage.start() | ||
import "trix" | ||
import "@rails/actiontext" | ||
|
||
import { Application, Controller } from '@hotwired/stimulus' | ||
const application = Application.start() | ||
|
||
import { Dropdown } from "tailwindcss-stimulus-components" | ||
application.register("dropdown", Dropdown) | ||
|
||
import StimulusFlatpickr from "stimulus-flatpickr" | ||
application.register("flatpickr", StimulusFlatpickr) | ||
|
||
import TomSelect from "tom-select" | ||
|
||
(() => { | ||
application.register('select', class extends Controller { | ||
static values = { | ||
options: Object, | ||
url: String | ||
} | ||
|
||
connect() { | ||
this.select = new TomSelect(this.element, { | ||
plugins: ['remove_button'], | ||
valueField: 'id', | ||
labelField: 'name', | ||
searchField: 'name', | ||
load: (search, callback) => { | ||
let url = search ? `${this.urlValue}?q=${search}` : this.urlValue; | ||
fetch(url) | ||
.then(response => response.json()) | ||
.then(json => { | ||
callback(json); | ||
}).catch(() => { | ||
callback(); | ||
}); | ||
} | ||
}) | ||
} | ||
|
||
disconnect() { | ||
this.select.destroy() | ||
} | ||
}) | ||
|
||
application.register('nested-form', class extends Controller { | ||
static get targets() { | ||
return [ "links", "template" ] | ||
} | ||
|
||
connect() { | ||
this.wrapperClass = this.data.get("wrapperClass") || "nested-fields" | ||
} | ||
|
||
add_association(event) { | ||
event.preventDefault() | ||
|
||
var content = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, new Date().getTime()) | ||
this.linksTarget.insertAdjacentHTML('beforebegin', content) | ||
} | ||
|
||
remove_association(event) { | ||
event.preventDefault() | ||
|
||
let wrapper = event.target.closest("." + this.wrapperClass) | ||
|
||
// New records are simply removed from the page | ||
if (wrapper.dataset.newRecord == "true") { | ||
wrapper.remove() | ||
|
||
// Existing records are hidden and flagged for deletion | ||
} else { | ||
wrapper.querySelector("input[name*='_destroy']").value = 1 | ||
wrapper.style.display = 'none' | ||
} | ||
} | ||
}) | ||
})() | ||
</script> |
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,32 @@ | ||
<div class="flex flex-col h-full text-sm" data-controller="dropdown"> | ||
<div class="flex md:block justify-between items-center"> | ||
<div class="flex md:block items-center"> | ||
<h1 class="mr-2 md:p-2 text-xl font-semibold">Madmin</h1> | ||
<% if main_app.respond_to?(:root_url) %> | ||
<%= link_to main_app.root_url, class: "block p-2 rounded hover:bg-gray-200", data: { turbo: false } do %> | ||
← Back <span class="hidden md:inline">to App</span> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
|
||
<div class="-mr-2 flex items-center md:hidden"> | ||
<button data-action="click->dropdown#toggle touch->dropdown#toggle click@window->dropdown#hide touch@window#dropdown->hide" type="button" class="bg-white rounded-md p-2 inline-flex items-center justify-center text-gray-400 hover:bg-gray-200 focus:outline-none focus:ring-2 focus-ring-inset focus:ring-white" id="main-menu" aria-haspopup="true"> | ||
<span class="sr-only">Open main menu</span> | ||
<!-- Heroicon name: outline/menu --> | ||
<svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true"> | ||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path> | ||
</svg> | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<div class="hidden md:flex flex-col flex-grow justify-between" data-dropdown-target="menu"> | ||
<% Madmin.resources.each do |resource| %> | ||
<%= nav_link_to resource.friendly_name.pluralize, resource.index_path, class: "block p-2 rounded hover:bg-gray-100", starts_with: resource.index_path, active_class: "font-bold text-black" %> | ||
<% end %> | ||
|
||
<div class="mt-auto"> | ||
<%= link_to "View Madmin on GitHub", "https://github.com/excid3/madmin", target: :_blank, class: "block p-2 rounded text-gray-500 hover:bg-gray-100" %> | ||
</div> | ||
</div> | ||
</div> |
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,7 @@ | ||
<h1 class="text-xl mb-4"> | ||
<%= link_to resource.friendly_name.pluralize, resource.index_path, class: "text-indigo-500" %> | ||
/ | ||
<strong>Edit <%= link_to resource.display_name(@record), resource.show_path(@record), class: "text-indigo-500" %></strong> | ||
</h1> | ||
|
||
<%= render partial: "form", locals: { record: @record, resource: resource } %> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is leaving out
position
intentional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I don't think it makes a difference for the purpose of this admin panel.