demo-rails-avo

Demonstration of Ruby on Rails with the Avo administration engine gem

https://github.com/joelparkerhenderson/demo-rails-avo

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.6%) to scientific vocabulary
Last synced: 8 months ago · JSON representation ·

Repository

Demonstration of Ruby on Rails with the Avo administration engine gem

Basic Info
  • Host: GitHub
  • Owner: joelparkerhenderson
  • Language: Ruby
  • Default Branch: main
  • Homepage:
  • Size: 56.6 KB
Statistics
  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created almost 4 years ago · Last pushed about 1 year ago
Metadata Files
Readme Citation

README.md

Demo Rails Avo

Demonstration of:

Setup

Create a demo rails app any way you want such as:

sh rails new demo_rails_avo

Avo fields

Avo provides many kinds of fields that render data:

  • Badge: display an easily recognizable status of a record in the database. Postgres text.

  • Boolean: render an icon on Index view and Show view; render a checkbox on Form views. Postgres boolean.

  • Boolean Group: update a Hash with string keys and boolean values. Postgres jsonb.

  • Code: show a code editor using codemirror. Postgres text.

  • Country: show a select field on Edit view that includes all ISO 3166-1 countries. Postgres char(2).

  • Date: display a date. The Edit view of the picker uses flatpickr. Postgres date.

  • DateTime: display a date and time. The Edit view of the picker uses flatpickr. Postgres datetime.

  • External image: display an image by using its URL. Postgres text.

  • File: display a file as an image, or audio file, or video file. Postgres ?.

  • Files: enable upload of multiple files at once using Active Storage. Postgres ?.

  • Gravatar: display gravatar icon corresponding to an email address. Postgres text.

  • Heading: display a banner between fields, such as a separator for lists or sections. Postgres N/A.

  • Hidden: use a form hidden field. Postgres N/A.

  • ID: show the record\'s id. Postgres primary key, such as an integer or UUID.

  • KeyValue: edit flat key-value pairs stored in JSON format in the database. Postgres jsonb.

  • Markdown: render a SimpleMDE Markdown Editor. Postgres text.

  • Number: render input[type="number"] with options for min, max, step. Postgres numeric.

  • Password: render input[type="password"]. Postgres N/A.

  • Progress bar: render a progress element on index and show views, and input[type=range] on forms. Postgres numeric.

  • Select: render a select field. Postgres integer, or enum, or text.

  • Status: display the status of a column (loading or failed). Postgres text.

  • Tags: show and edit tags. Postgres array of text, or ActsAsTaggableOn gem, etc.

  • Text: render text, with options to render as HTML. Postgres text.

  • Textarea: render a typical HTML form text area. Postgres text.

  • Trix: render using a WYSIWYG Trix Editor, with options for file attachments and ActiveStorage. Postgres text.

Avo

Install via app template:

sh bin/rails app:template LOCATION='https://avohq.io/app-template'

Avo creates some config files, and changes file config/routes.rb:

ruby Rails.application.routes.draw do mount Avo::Engine, at: Avo.configuration.root_path …

Visit http://127.0.0.1:3000/avo and you should see the Avo welcome page.

Avo configuration

Avo configuration is in file config/initializers/avo.rb:

```ruby

For more information regaring these settings check out our docs https://docs.avohq.io

Avo.configure do |config| ## == Routing == config.root_path = '/avo'

# Where should the user be redirected when visting the /avo url # config.home_path = nil

## == Licensing == config.license = 'community' # change this to 'pro' when you add the license key # config.licensekey = ENV['AVOLICENSE_KEY']

## == Set the context == config.set_context do # Return a context object that gets evaluated in Avo::ApplicationController end

## == Authentication == # config.currentusermethod = {} # config.authenticate_with = {}

## == Authorization == # config.authorizationmethods = { # index: 'index?', # show: 'show?', # edit: 'edit?', # new: 'new?', # update: 'update?', # create: 'create?', # destroy: 'destroy?', # } # config.raiseerroronmissing_policy = false

## == Localization == # config.locale = 'en-US'

## == Customization == # config.appname = 'Avocadelicious' # config.timezone = 'UTC' # config.currency = 'USD' # config.perpage = 24 # config.perpagesteps = [12, 24, 48, 72] # config.viaperpage = 8 # config.defaultviewtype = :table # config.hidelayoutwhenprinting = false # config.idlinkstoresource = false # config.fullwidthcontainer = false # config.fullwidthindexview = false # config.cacheresourcesonindexview = true # config.searchdebounce = 300 # config.viewcomponentpath = "app/components" # config.displaylicenserequesttimeouterror = true # config.disabled_features = []

## == Breadcrumbs == # config.displaybreadcrumbs = true # config.setinitialbreadcrumbs do # addbreadcrumb "Home", '/avo' # end

## == Menus == # config.mainmenu = -> { # section "Dashboards", icon: "dashboards" do # alldashboards # end

# section "Resources", icon: "resources" do # all_resources # end

# section "Tools", icon: "tools" do # alltools # end # } # config.profilemenu = -> { # link "Profile", path: "/avo/profile", icon: "user-circle" # } end ```

Optional

Enable home page:

ruby config.home_path = '/avo/resources/items'

Enable id links to resources:

ruby config.id_links_to_resource = true

Enable professional license:

```ruby

License

config.license = 'pro' config.licensekey = ENV['AVOLICENSE_KEY'] ```

Enable localization:

```ruby

== Localization ==

config.locale = 'en-US' ```

Enable breadcrumbs:

```ruby

== Breadcrumbs ==

config.displaybreadcrumbs = true config.setinitialbreadcrumbs do addbreadcrumb "Home", '/avo' end ```

Enable buttons:

```ruby

== Buttons ==

Show web page buttons on the footer of typical web page forms,

e.g. a navigation Back button and an editing Save button.

This confi can help the UI for resources that use long web pages.

config.buttonsonform_footers = true ```

Enable authentication using Devise with typical settings:

```ruby

Authentication with Devise

config.currentusermethod = :currentuser config.currentuserresourcename = :user ```

Scaffold

Generate scaffold:

```sh bin/rails generate scaffold Item \ demobadge:text \ demoboolean:boolean \ democode:text \ democountry:text \ demodate:date \ demodatetime:datetime \ demoexternalimage:text \ demofile:binary \ demofiles:binary \ demogravatar:text \ demomarkdown:text \ demonumber:integer \ demopassword:text \ demoprogressbar:integer \ demoselect:integer \ demostatus:text \ demotext:text \ demotextarea:text \ demotrix:text

TODO:

sh demo_boolean_group:jsonb \ demo_key_value:jsonb \ demo_tags:array\[\] \

Avo resource

Generate:

sh bin/rails generate avo:resource Item

Edit file app/avo/resources/item_resource.rb:

```ruby class ItemResource < Avo::BaseResource

# For web page headline 1 self.title = :name

# For web page headline 2 self.description = "List all the items"

# Enable eager loading for the index view. self.includes = []

# self.searchquery = ->(params:) do # scope.ransack(ideq: params[:q], m: "or").result(distinct: false) # end

# All the fields we want

field :id, as: :id, sortable: true

field :demo_badge, as: :badge, name: 'Badge', help: "help goes here", sortable: true, options: { info: ["info", "i"], success: ["success", "s"], warning: ["warning", "w"], danger: ["danger", "d"], }

field :demoboolean, as: :boolean, name: 'Boolean', help: "help goes here", sortable: true # truevalue: 'yes', # false_value: 'no'

# field :demobooleangroup, # as: :boolean_group, # help: "help goes here"

field :demo_code, as: :code, name: 'Code', help: "help goes here", theme: 'default', language: 'ruby'

field :democountry, as: :country, name: 'Country', help: "help goes here", sortable: true, displayname: false

field :demo_date, as: :date, name: 'Date', help: "help goes here", sortable: true

field :demodatetime, as: :date_time, name: 'Date Time', help: "help goes here", sortable: true

field :demoexternalimage, as: :external_image, name: 'External Image', help: "help goes here", sortable: true

#TODO # field :demofile, # as: :file, # name: 'File', # help: "help goes here", # isimage: true, # linktoresource: true

#TODO # field :demo_files, # as: :files, # name: 'Files', # help: "help goes here", # sortable: true

field :demogravatar, as: :gravatar, name: 'Gravatar', help: "help goes here", sortable: true, hideon: [:index]

#TODO # field :demokeyvalue, # as: :key_value, # name: 'Key-Value', # help: "help goes here", # sortable: true

field :demomarkdown, as: :markdown, name: 'Markdown', help: "help goes here", sortable: true, hideon: [:index]

field :demo_number, as: :number, name: 'Number', help: "help goes here", sortable: true

field :demopassword, as: :password, name: 'Password', help: "help goes here", sortable: true, hideon: [:index]

field :demoprogressbar, as: :progress_bar, name: 'Progress Bar', help: "help goes here", sortable: true, max: 100, step: 1

#TODO # field :demo_select, # as: :select, # name: 'Select', # help: "help goes here", # sortable: true

field :demostatus, as: :status, name: 'Status', help: "help goes here", sortable: true # loadingwhen: ["loading", "loading2", "loading3"], # failed_when: ["failed", "failed2", "failed3"]

# field :demo_tags, # as: :tags, # help: "help goes here", # sortable: true

field :demotext, as: :text, name: 'Text', help: "help goes here", placeholder: "placeholder goes here", sortable: true, hideon: [:index]

field :demotextarea, as: :textarea, name: 'Text Area', help: "help goes here", sortable: true, hideon: [:index]

field :demotrix, as: :trix, name: 'Trix', help: "help goes here", sortable: true, hideon: [:index]

end ```

Create seeds

Create demo data seeds and demo data fabricators.

Create these any way you wish. We favor using the typical Rails file db/seeds.rb. We favor methods with a naming convention that starts with "fab_" meaning fabricate.

Example file db/seeds.rb:

```ruby def self.fabbadge fabbadge_sampler.sample end

def self.fabbadgesampler [ "info", "success", "warning", "danger", ] end

def self.fab_boolean [true, false].sample end

def self.fab_code "puts \"Hello World\"" end

def self.fabcountry fabcountry_sampler.sample end

def self.fabcountrysampler [ "US", "UK", "CH", "IE", "IN", "IT", ] end

def self.fabexternalimage "https://picsum.photos/#{40 + rand(40)}/#{40 + rand(40)}" end

def self.fabgravatar fabgravatar_sampler.sample end

def self.fabgravatarsampler [ "alpha@example.com", "bravo@example.com", "charlie@example.com", "delta@example.com", "echo@example.com", "foxtrot@example.com", ] end

def self.fab_markdown "markdown" end

def self.fab_number rand(100) end

def self.fab_password "password" end

def self.fabprogressbar rand(100) end

def self.fabstatus fabstatus_sampler.sample end

def self.fabstatussampler [ "done", "complete", "waiting", "running", "failed", ] end

def self.fab_text "text" end

def self.fab_textarea "textarea" end

def self.fab_trix "trix" end

def self.fab_date Date.today + rand(1000) end

def self.fabdatetime DateTime.now + rand(1000) end

def self.fabitem Item.new( demobadge: fabbadge, demoboolean: fabboolean, democode: fabcode, democountry: fabcountry, demodate: fabdate, demodatetime: fabdatetime, demoexternalimage: fabexternalimage, demogravatar: fabgravatar, demomarkdown: fabmarkdown, demonumber: fabnumber, demopassword: fabpassword, demoprogressbar: fabprogressbar, demostatus: fabstatus, demotext: fabtext, demotextarea: fabtextarea, demotrix: fab_trix, ) end

100.times do item = fab_item puts item item.save! end ```

Tags

Avo provides various ways to manage tags. We prefer using the gem acts-as-taggable-on

Add to Gemfile:

```ruby

Use tags with associations

gem 'acts-as-taggable-on', '~> 9.0' ```

sh bundle rake acts_as_taggable_on_engine:install:migrations bin/rails db:migrate

Edit file app/models/item.rb and add:

ruby acts_as_taggable_on :tags

Edit file app/avo/resources/item_resource.rb and add:

ruby field :tags, as: :tags

Restart the app.

Verify that you can edit an item, create some tags, save the record, then see your tags.

Use ActiveStorage for files

Add to Gemfile:

```ruby

Use Active Storage variant for files

gem "image_processing", "~> 1.2" ```

sh bundle bin/rails active_storage:install bin/rails db:mgirate

Add to file app/models/item.rb:

ruby has_many_attached :demo_files

Add to file app/avo/resources/item_resource.rb:

ruby field :demo_files, as: :files, name: 'Files', help: "help goes here", sortable: true

Optionally create some demo files:

sh echo "alpha" > tmp/alpha.txt echo "bravo" > tmp/bravo.txt

Restart the app.

Verify that you can edit an item, upload some files, save the record, then see your file entries.

Use Ransack for searching

Add to Gemfile:

```ruby

Use Ransack for searching

gem 'ransack' ```

sh bundle

Edit file app/avo/resources/item_resource.rb to add a Ransack search query as a class lambda, and an optional search query help string:

```ruby class ItemResource < Avo::BaseResource … # Avo search for Ransack search query self.searchquery = ->(params:) do scope.ransack( ideq: params[:q], m: "or" ).result(distinct: false) end

self.searchqueryhelp = "- search by id" … end ```

Restart the app.

Verify that Avo shows a top navigation search box, and that you can type in the box, and that the box shows a dropdown area that lists some matching items.

Add search result label and description

The search currently lists each item with same resource title which is "Item". We want to also show a label and description.

Edit file app/avo/resources/item_resource.rb to add option as_label and option as_description like this:

ruby class ItemResource < Avo::BaseResource … field :id, … as_label: true … field :demo_text, … as_description: true …

Add search result custom label and custom description

If you want more customization for the label or description, then you can define your own fields with custom blocks such as:

```ruby class ItemResource < Avo::BaseResource … # Avo label for Ransack search result list field :mycustomlabel, as: :text, aslabel: true, hideon: :all \ do |model| "Item #{model.id}" rescue "Item" end

# Avo description for Ransack search result list field :mycustomdescription, as: :text, asdescription: true, hideon: :all \ do |model| ActionView::Base.fullsanitizer.sanitize(model.demotext).truncate 130 rescue "" end … ```

Add search result list avatar

Edit file app/avo/resources/item_resource.rb:

ruby class ItemResource < Avo::BaseResource … field :demo_external_image, … as_avatar: :circle …

Add search form fields

Edit file app/avo/resources/item_resource.rb to add a Ransack search query as a class lambda:

ruby class ItemResource < Avo::BaseResource … # Ransack search query self.search_query = ->(params:) do scope.ransack( id_eq: params[:q], demo_text_cont: params[:q], demo_textarea_cont: params[:q], demo_trix_cont: params[:q], m: "or" ).result(distinct: false) end … end

Owner

  • Name: Joel Parker Henderson
  • Login: joelparkerhenderson
  • Kind: user
  • Location: California

Software developer. Technology consultant. Creator of GitAlias.com, NumCommand.com, SixArm.com, and many open source projects.

Citation (CITATION.cff)

cff-version: 1.2.0
title: Demo Rails Avo
message: >-
  If you use this work and you want to cite it,
  then you can use the metadata from this file.
type: software
authors:
  - given-names: Joel Parker
    family-names: Henderson
    email: joel@joelparkerhenderson.com
    affiliation: joelparkerhenderson.com
    orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
  - type: url
    value: 'https://github.com/joelparkerhenderson/demo-rails-avo/'
    description: Demo Rails Avo
repository-code: 'https://github.com/joelparkerhenderson/demo-rails-avo/'
abstract: >-
  Demo Rails Avo
license: See license file

GitHub Events

Total
  • Watch event: 1
  • Push event: 1
Last Year
  • Watch event: 1
  • Push event: 1

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 6
  • Total Committers: 1
  • Avg Commits per committer: 6.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Joel Parker Henderson j****l@j****m 6
Committer Domains (Top 20 + Academic)

Dependencies

Gemfile rubygems
  • capybara >= 0 development
  • selenium-webdriver >= 0 development
  • web-console >= 0 development
  • webdrivers >= 0 development
  • acts-as-taggable-on ~> 9.0
  • avo >= 0
  • bootsnap >= 0
  • image_processing ~> 1.2
  • importmap-rails >= 0
  • jbuilder >= 0
  • puma ~> 5.0
  • rails ~> 7.0.3, >= 7.0.3.1
  • ransack >= 0
  • redis ~> 4.0
  • sprockets-rails >= 0
  • sqlite3 ~> 1.4
  • stimulus-rails >= 0
  • turbo-rails >= 0
Gemfile.lock rubygems
  • actioncable 7.0.3.1
  • actionmailbox 7.0.3.1
  • actionmailer 7.0.3.1
  • actionpack 7.0.3.1
  • actiontext 7.0.3.1
  • actionview 7.0.3.1
  • active_link_to 1.0.5
  • activejob 7.0.3.1
  • activemodel 7.0.3.1
  • activerecord 7.0.3.1
  • activestorage 7.0.3.1
  • activesupport 7.0.3.1
  • acts-as-taggable-on 9.0.1
  • addressable 2.8.0
  • avo 2.11.0
  • bindex 0.8.1
  • bootsnap 1.12.0
  • breadcrumbs_on_rails 4.1.0
  • builder 3.2.4
  • capybara 3.37.1
  • chartkick 4.2.0
  • childprocess 4.1.0
  • concurrent-ruby 1.1.10
  • countries 5.1.1
  • crass 1.0.6
  • debug 1.6.1
  • digest 3.1.0
  • docile 1.4.0
  • dry-initializer 3.1.1
  • erubi 1.10.0
  • ffi 1.15.5
  • globalid 1.0.0
  • hotwire-rails 0.1.3
  • httparty 0.20.0
  • i18n 1.12.0
  • image_processing 1.12.2
  • importmap-rails 1.1.5
  • io-console 0.5.11
  • irb 1.4.1
  • jbuilder 2.11.5
  • loofah 2.18.0
  • mail 2.7.1
  • marcel 1.0.2
  • matrix 0.4.2
  • meta-tags 2.17.0
  • method_source 1.0.0
  • mime-types 3.4.1
  • mime-types-data 3.2022.0105
  • mini_magick 4.11.0
  • mini_mime 1.1.2
  • minitest 5.16.2
  • msgpack 1.5.3
  • multi_xml 0.6.0
  • net-imap 0.2.3
  • net-pop 0.1.1
  • net-protocol 0.1.3
  • net-smtp 0.3.1
  • nio4r 2.5.8
  • nokogiri 1.13.7
  • pagy 5.10.1
  • public_suffix 4.0.7
  • puma 5.6.4
  • pundit 2.2.0
  • racc 1.6.0
  • rack 2.2.4
  • rack-test 2.0.2
  • rails 7.0.3.1
  • rails-dom-testing 2.0.3
  • rails-html-sanitizer 1.4.3
  • railties 7.0.3.1
  • rake 13.0.6
  • ransack 3.2.1
  • redis 4.7.1
  • regexp_parser 2.5.0
  • reline 0.3.1
  • rexml 3.2.5
  • ruby-vips 2.1.4
  • rubyzip 2.3.2
  • selenium-webdriver 4.3.0
  • sixarm_ruby_unaccent 1.2.0
  • sprockets 4.1.1
  • sprockets-rails 3.4.2
  • sqlite3 1.4.4
  • stimulus-rails 1.1.0
  • strscan 3.0.3
  • thor 1.2.1
  • timeout 0.3.0
  • turbo-rails 1.1.1
  • tzinfo 2.0.5
  • view_component 2.61.0
  • web-console 4.2.0
  • webdrivers 5.0.0
  • websocket 1.2.9
  • websocket-driver 0.7.5
  • websocket-extensions 0.1.5
  • xpath 3.2.0
  • zeitwerk 2.6.0