blocknotes / tiny_admin

A compact and composable dashboard component for Ruby
MIT License
12 stars 0 forks source link
rails roda ruby ruby-on-rails

Tiny Admin

Gem Version Gem Downloads Linters Specs

A compact and composable dashboard component for Ruby.

Main features:

Please ⭐ if you like it.

screenshot

Install

TinyAdmin.configure do |settings|
  settings.root = {
    title: 'Home',
    page: Admin::PageRoot
  }
end

Plugins and components

Authentication

Plugins available:

Authorization

Plugins available:

Repository

Plugin available:

View pages

Pages available:

View components

Components available:

Configuration

TinyAdmin can be configured using a YAML file and/or programmatically. See extra folder for some usage examples.

The following options are supported:

root (Hash): define the root section of the admin, properties:

πŸ“š Wiki Root page available

Example:

root:
  title: MyAdmin
  redirect: posts
  widgets:
    - LatestAuthorsWidget
    - LatestPostsWidget

helper_class (String): class or module with helper methods, used for attributes' formatters.

πŸ“š Wiki Helper methods page available

page_not_found (String): a view object to render when a missing page is requested.

record_not_found (String): a view object to render when a missing record is requested.

style_links (Array of hashes): list of styles files to include, properties:

scripts (Array of hashes): list of scripts to include, properties:

extra_styles (String): inline CSS styles.

πŸ“š Wiki Styles and scripts page available

authentication (Hash): define the authentication method, properties:

πŸ“š Wiki Authentication page available

Example:

authentication:
  plugin: TinyAdmin::Plugins::SimpleAuth
  password: 'f1891cea80fc05e433c943254c6bdabc159577a02a7395dfebbfbc4f7661d4af56f2d372131a45936de40160007368a56ef216a30cb202c66d3145fd24380906'

authorization_class (String): a plugin class to use;

πŸ“š Wiki Authentication page available

sections (Array of hashes): define the admin sections, properties:

πŸ“š Wiki Pages page available

For content sections:

Example:

slug: test-content
name: Test content
type: content
content: >
  <h1>Test content!</h1>
  <p>Some test content</p>
widgets:
  - LatestAuthorsWidget
  - LatestPostsWidget

For url sections:

Example:

slug: google
name: Google.it
type: url
url: https://www.google.it
options:
  target: '_blank'

For page sections:

Example:

slug: stats
name: Stats
type: page
page: Admin::Stats

For resource sections:

πŸ“š Wiki Repository page available

Example:

slug: posts
name: Posts
type: resource
model: Post

Resource index options

πŸ“š Wiki Resource index page available

The Index hash supports the following options:

Example:

    index:
      sort:
        - id DESC
      pagination: 10
      attributes:
        - id
        - author: call, name
        - position: round, 1
        - field: author_id
          header: The author
          link_to: authors
          call: author, name
      filters:
        - title
        - field: state
          type: select
          values:
            - published
            - draft
            - archived
      links:
        - show
        - author_posts
        - csv_export

Resource show options

πŸ“š Wiki Resource show page available

The Show hash supports the following options:

Example:

    show:
      attributes:
        # Expose the id column
        - id
        # Expose the title column, calling `downcase` support method
        - title: downcase
        # Expose the category column, calling `upcase` support method
        - category: upcase
        # Expose the position column, calling `format` support method with argument %f
        - position: format, %f
        # Expose the position created_at, calling `strftime` support method with argument %Y%m%d %H:%M
        - created_at: strftime, %Y%m%d %H:%M
        # Expose the author_id column, with a custom header label, linked to authors section and calling author.name to get the value
        - field: author_id
          header: The author
          link_to: authors
          call: author, name
      widgets:
        - LatestAuthorsWidget
        - LatestPostsWidget

Sample

# config/initializers/tiny_admin.rb

config = Rails.root.join('config/tiny_admin.yml').to_s
TinyAdmin.configure_from_file(config)

# Change some settings programmatically
TinyAdmin.configure do |settings|
  settings.authentication[:password] = Digest::SHA512.hexdigest('changeme')
end
# config/tiny_admin.yml
---
authentication:
  plugin: TinyAdmin::Plugins::SimpleAuth
  # password: 'f1891cea80fc05e433c943254c6bdabc159577a02a7395dfebbfbc4f7661d4af56f2d372131a45936de40160007368a56ef216a30cb202c66d3145fd24380906'
root:
  title: Test Admin
  widgets:
    - LatestAuthorsWidget
    - LatestPostsWidget
  # page: RootPage
helper_class: AdminHelper
page_not_found: PageNotFound
record_not_found: RecordNotFound
sections:
  - slug: google
    name: Google.it
    type: url
    url: https://www.google.it
    options:
      target: _blank
  - slug: sample
    name: Sample page
    type: page
    page: SamplePage
  - slug: authors
    name: Authors
    type: resource
    model: Author
    collection_actions:
      - sample_col: SampleCollectionAction
    member_actions:
      - sample_mem: SampleMemberAction
  - slug: posts
    name: Posts
    type: resource
    model: Post
    index:
      pagination: 5
      attributes:
        - id
        - title
        - field: author_id
          link_to: authors
        - category: upcase
        - state: downcase
        - published
        - position: round, 1
        - dt: to_date
        - field: created_at
          converter: AdminUtils
          method: datetime_formatter
        - updated_at: strftime, %Y%m%d %H:%M
      filters:
        - title
        - author_id
        - field: category
          type: select
          values:
            - news
            - sport
            - tech
        - published
        - dt
        - created_at
    show:
      attributes:
        - id
        - title
        - description
        - field: author_id
          link_to: authors
        - category
        - published
        - position: format, %f
        - dt
        - created_at
style_links:
  - href: /bootstrap.min.css
    rel: stylesheet
scripts:
  - src: /bootstrap.bundle.min.js
extra_styles: >
  .navbar {
    background-color: var(--bs-cyan);
  }
  .main-content {
    background-color: var(--bs-gray-100);
  }
  .main-content a {
    text-decoration: none;
  }

Do you like it? Star it!

If you use this component just star it. A developer is more motivated to improve a project when there is some interest.

Or consider offering me a coffee, it's a small thing but it is greatly appreciated: about me.

Contributors

License

The gem is available as open source under the terms of the MIT License.