|
| 1 | +# Tiny Admin |
| 2 | + |
| 3 | +A compact and composible dashboard component for Ruby. |
| 4 | + |
| 5 | +The main features are: |
| 6 | +- a Rack app that can be mounted in any Rack-enabled framework; |
| 7 | +- some features are handled as plugins, so they can be replaced with little effort; |
| 8 | +- routing is provided by Roda (which is small and performant); |
| 9 | +- views are Phlex components. |
| 10 | + |
| 11 | +See (extra)[extra] folder for usage examples. |
| 12 | + |
| 13 | +Please ⭐ if you like it. |
| 14 | + |
| 15 | +## Install |
| 16 | + |
| 17 | +- Add to your Gemfile: `gem 'tiny_admin'` |
| 18 | +- For a Rails project: add an initializer and the YAML config - see (configuration)[#configuration] below. |
| 19 | + |
| 20 | +## Plugins and components |
| 21 | + |
| 22 | +Every plugin or component can be replaced. |
| 23 | + |
| 24 | +### Authentication |
| 25 | + |
| 26 | +There are 2 plugins included: |
| 27 | +- _SimpleAuth_: provides a simple session authentication based on Warden (`warden` gem must be included in the host project); |
| 28 | +- _NoAuth_: no authentication. |
| 29 | + |
| 30 | +### Repository |
| 31 | + |
| 32 | +There is 1 plugin included: |
| 33 | +- _ActiveRecordRepository_: isolates the query layer to expose the resources in the admin interface. |
| 34 | + |
| 35 | +### View pages |
| 36 | + |
| 37 | +There are 5 view pages included: |
| 38 | +- _Root_: define how to present the content in the main page of the interface; |
| 39 | +- _PageNotFound_: define how to present pages not found; |
| 40 | +- _RecordNotFound_: define how to present record not found page; |
| 41 | +- _SimpleAuthLogin_: define how to present the login form for SimpleAuth plugin; |
| 42 | +- _Index_: define how to present a collection of items; |
| 43 | +- _Show_: define how to present the details of an item. |
| 44 | + |
| 45 | +### View components |
| 46 | + |
| 47 | +There are 5 view components included: |
| 48 | +- _FiltersForm_: define how to present the filters form in the resource collection pages; |
| 49 | +- _Flash_: define how to present the flash messages; |
| 50 | +- _Head_: define how to present the Head tag; |
| 51 | +- _Navbar_: define how to present the navbar (the default one uses the Bootstrap structure); |
| 52 | +- _Pagination_: define how to present the pagination of a collection. |
| 53 | + |
| 54 | +## Configuration |
| 55 | + |
| 56 | +TinyAdmin can be configured programmatically or using a YAML config. |
| 57 | + |
| 58 | +Example: |
| 59 | + |
| 60 | +```rb |
| 61 | +# config/initializers/tiny_admin.rb |
| 62 | + |
| 63 | +# hash generated using: Digest::SHA512.hexdigest("changeme") |
| 64 | +ENV['ADMIN_PASSWORD_HASH'] = 'f1891cea80fc05e433c943254c6bdabc159577a02a7395dfebbfbc4f7661d4af56f2d372131a45936de40160007368a56ef216a30cb202c66d3145fd24380906' |
| 65 | +config = Rails.root.join('config/tiny_admin.yml').to_s |
| 66 | +TinyAdmin.configure_from_file(config) |
| 67 | +``` |
| 68 | + |
| 69 | +```yml |
| 70 | +--- |
| 71 | +authentication: |
| 72 | + plugin: TinyAdmin::Plugins::SimpleAuth |
| 73 | +page_not_found: Admin::PageNotFound |
| 74 | +record_not_found: Admin::RecordNotFound |
| 75 | +root: |
| 76 | + title: 'Tiny Admin' |
| 77 | + page: Admin::PageRoot |
| 78 | + # redirect: posts |
| 79 | +sections: |
| 80 | + - slug: google |
| 81 | + name: Google.it |
| 82 | + type: url |
| 83 | + url: https://www.google.it |
| 84 | + options: |
| 85 | + target: '_blank' |
| 86 | + - slug: stats |
| 87 | + name: Stats |
| 88 | + type: page |
| 89 | + page: Admin::Stats |
| 90 | + - slug: authors |
| 91 | + name: Authors |
| 92 | + type: resource |
| 93 | + model: Author |
| 94 | + repository: Admin::AuthorsRepo |
| 95 | + collection_actions: |
| 96 | + - latests: Admin::LatestAuthorsAction |
| 97 | + member_actions: |
| 98 | + - csv_export: Admin::CsvExportAuthorAction |
| 99 | + # only: |
| 100 | + # - index |
| 101 | + # options: |
| 102 | + # - hidden |
| 103 | + - slug: posts |
| 104 | + name: Posts |
| 105 | + type: resource |
| 106 | + model: Post |
| 107 | + index: |
| 108 | + sort: |
| 109 | + - author_id DESC |
| 110 | + pagination: 15 |
| 111 | + attributes: |
| 112 | + - id |
| 113 | + - title |
| 114 | + - field: author_id |
| 115 | + link_to: authors |
| 116 | + - state |
| 117 | + - published |
| 118 | + - dt |
| 119 | + - field: created_at |
| 120 | + converter: Admin::Utils |
| 121 | + method: datetime_formatter |
| 122 | + filters: |
| 123 | + - title |
| 124 | + - field: state |
| 125 | + type: select |
| 126 | + values: |
| 127 | + - available |
| 128 | + - unavailable |
| 129 | + - arriving |
| 130 | + - published |
| 131 | + show: |
| 132 | + attributes: |
| 133 | + - id |
| 134 | + - title |
| 135 | + - description |
| 136 | + - field: author_id |
| 137 | + link_to: authors |
| 138 | + - category |
| 139 | + - published |
| 140 | + - state |
| 141 | + - created_at |
| 142 | +style_links: |
| 143 | + - href: /bootstrap.min.css |
| 144 | + rel: stylesheet |
| 145 | +scripts: |
| 146 | + - src: /bootstrap.bundle.min.js |
| 147 | +extra_styles: > |
| 148 | + .navbar { |
| 149 | + background-color: var(--bs-cyan); |
| 150 | + } |
| 151 | + .main-content { |
| 152 | + background-color: var(--bs-gray-100); |
| 153 | + } |
| 154 | + .main-content a { |
| 155 | + text-decoration: none; |
| 156 | + } |
| 157 | +``` |
| 158 | +
|
| 159 | +## Do you like it? Star it! |
| 160 | +
|
| 161 | +If you use this component just star it. A developer is more motivated to improve a project when there is some interest. |
| 162 | +
|
| 163 | +Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me). |
| 164 | +
|
| 165 | +## Contributors |
| 166 | +
|
| 167 | +- [Mattia Roccoberton](https://blocknot.es/): author |
| 168 | +
|
| 169 | +## License |
| 170 | +
|
| 171 | +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
0 commit comments