Skip to content

Commit 577718d

Browse files
committed
refactor: add avo and resources
1 parent fc2e34d commit 577718d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1727
-108
lines changed

Gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ end
5252

5353
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
5454
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
55+
56+
# authentication
57+
gem 'devise'
58+
59+
gem 'faker'
60+
61+
gem 'avo', source: 'https://rubygems.pkg.github.com/avo-hq'

Gemfile.lock

+40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
GEM
22
remote: https://rubygems.org/
3+
remote: https://rubygems.pkg.github.com/avo-hq/
34
specs:
45
actioncable (6.0.3.3)
56
actionpack (= 6.0.3.3)
@@ -58,6 +59,13 @@ GEM
5859
zeitwerk (~> 2.2, >= 2.2.2)
5960
addressable (2.7.0)
6061
public_suffix (>= 2.0.2, < 5.0)
62+
avo (0.1.15)
63+
inline_svg
64+
kaminari
65+
rails (~> 6.0.2, >= 6.0.2.1)
66+
webpacker
67+
zeitwerk
68+
bcrypt (3.1.16)
6169
bindex (0.8.1)
6270
bootsnap (1.4.8)
6371
msgpack (~> 1.0)
@@ -74,14 +82,37 @@ GEM
7482
childprocess (3.0.0)
7583
concurrent-ruby (1.1.7)
7684
crass (1.0.6)
85+
devise (4.7.3)
86+
bcrypt (~> 3.0)
87+
orm_adapter (~> 0.1)
88+
railties (>= 4.1.0)
89+
responders
90+
warden (~> 1.2.3)
7791
erubi (1.9.0)
92+
faker (2.13.0)
93+
i18n (>= 1.6, < 2)
7894
ffi (1.13.1)
7995
globalid (0.4.2)
8096
activesupport (>= 4.2.0)
8197
i18n (1.8.5)
8298
concurrent-ruby (~> 1.0)
99+
inline_svg (1.7.1)
100+
activesupport (>= 3.0)
101+
nokogiri (>= 1.6)
83102
jbuilder (2.10.1)
84103
activesupport (>= 5.0.0)
104+
kaminari (1.2.1)
105+
activesupport (>= 4.1.0)
106+
kaminari-actionview (= 1.2.1)
107+
kaminari-activerecord (= 1.2.1)
108+
kaminari-core (= 1.2.1)
109+
kaminari-actionview (1.2.1)
110+
actionview
111+
kaminari-core (= 1.2.1)
112+
kaminari-activerecord (1.2.1)
113+
activerecord
114+
kaminari-core (= 1.2.1)
115+
kaminari-core (1.2.1)
85116
listen (3.2.1)
86117
rb-fsevent (~> 0.10, >= 0.10.3)
87118
rb-inotify (~> 0.9, >= 0.9.10)
@@ -101,6 +132,7 @@ GEM
101132
nio4r (2.5.4)
102133
nokogiri (1.10.10)
103134
mini_portile2 (~> 2.4.0)
135+
orm_adapter (0.5.0)
104136
pg (1.2.3)
105137
public_suffix (4.0.6)
106138
puma (4.3.6)
@@ -141,6 +173,9 @@ GEM
141173
rb-inotify (0.10.1)
142174
ffi (~> 1.0)
143175
regexp_parser (1.8.0)
176+
responders (3.0.1)
177+
actionpack (>= 5.0)
178+
railties (>= 5.0)
144179
rubyzip (2.3.0)
145180
sass-rails (6.0.0)
146181
sassc-rails (~> 2.1, >= 2.1.1)
@@ -174,6 +209,8 @@ GEM
174209
turbolinks-source (5.2.0)
175210
tzinfo (1.2.7)
176211
thread_safe (~> 0.1)
212+
warden (1.2.9)
213+
rack (>= 2.0.9)
177214
web-console (4.0.4)
178215
actionview (>= 6.0.0)
179216
activemodel (>= 6.0.0)
@@ -198,9 +235,12 @@ PLATFORMS
198235
ruby
199236

200237
DEPENDENCIES
238+
avo!
201239
bootsnap (>= 1.4.2)
202240
byebug
203241
capybara (>= 2.15)
242+
devise
243+
faker
204244
jbuilder (~> 2.7)
205245
listen (~> 3.2)
206246
pg (>= 0.18, < 2.0)

app/avo/actions/mark_inactive.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Avo
2+
module Actions
3+
class MarkInactive < Action
4+
def name
5+
'Mark inactive'
6+
end
7+
8+
def handle(request, models, fields)
9+
models.each do |model|
10+
model.update active: false
11+
12+
model.notify fields['message'] if fields['notify_user']
13+
end
14+
15+
succeed 'Perfect!'
16+
reload_resources
17+
end
18+
19+
fields do
20+
boolean :notify_user
21+
textarea :message, default: 'Your account has been marked as inactive.'
22+
end
23+
end
24+
end
25+
end

app/avo/actions/toggle_published.rb

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Avo
2+
module Actions
3+
class TogglePublished < Action
4+
def name
5+
'Toggle post published'
6+
end
7+
8+
def message
9+
'Are you sure, sure?'
10+
end
11+
12+
def handle(request, models, fields)
13+
models.each do |model|
14+
if model.published_at.present?
15+
model.update published_at: nil
16+
else
17+
model.update published_at: DateTime.now
18+
end
19+
end
20+
21+
succeed 'Perfect!'
22+
redirect '/resources/posts'
23+
end
24+
25+
def confirm_text
26+
'Toggle'
27+
end
28+
29+
def cancel_text
30+
"Don't toggle yet"
31+
end
32+
end
33+
end
34+
end

app/avo/filters/featured_filter.rb

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Avo
2+
module Filters
3+
class FeaturedFilter < BooleanFilter
4+
def name
5+
'Featured status'
6+
end
7+
8+
def apply(request, query, values)
9+
return query if values[:is_featured] && values[:is_unfeatured]
10+
11+
if values[:is_featured]
12+
query = query.where(is_featured: true)
13+
elsif values[:is_unfeatured]
14+
query = query.where(is_featured: false)
15+
end
16+
17+
query
18+
end
19+
20+
def options
21+
{
22+
'is_featured': 'Featured',
23+
'is_unfeatured': 'Unfeatured',
24+
}
25+
end
26+
end
27+
end
28+
end

app/avo/filters/published_filter.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Avo
2+
module Filters
3+
class PublishedFilter < SelectFilter
4+
def name
5+
'Published status'
6+
end
7+
8+
def apply(request, query, value)
9+
case value
10+
when 'published'
11+
query.where.not(published_at: nil)
12+
when 'unpublished'
13+
query.where(published_at: nil)
14+
else
15+
query
16+
end
17+
end
18+
19+
def options
20+
{
21+
'published': 'Published',
22+
'unpublished': 'Unpublished',
23+
}
24+
end
25+
end
26+
end
27+
end

app/avo/resources/post.rb

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module Avo
2+
module Resources
3+
class Post < Resource
4+
def initialize
5+
@title = :name
6+
@search = [:name, :id]
7+
@includes = :user
8+
@default_view_type = :grid
9+
end
10+
11+
fields do
12+
id
13+
text :name, required: true
14+
trix :body, placeholder: 'Enter text', always_show: false
15+
file :cover_photo, is_image: true
16+
boolean :is_featured
17+
boolean :is_published do |model|
18+
model.published_at.present?
19+
end
20+
code :custom_css, theme: 'dracula', language: 'css', help: "This enables you to edit the user's custom styles."
21+
22+
belongs_to :user, searchable: false, placeholder: '—'
23+
end
24+
25+
# These fields are a reference on the already configured fields above
26+
grid do
27+
preview :cover_photo
28+
title :name
29+
body :body
30+
end
31+
32+
use_filter Avo::Filters::FeaturedFilter
33+
use_filter Avo::Filters::PublishedFilter
34+
35+
use_action Avo::Actions::TogglePublished
36+
end
37+
end
38+
end

app/avo/resources/project.rb

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Avo
2+
module Resources
3+
class Project < Resource
4+
def initialize
5+
@title = :name
6+
@search = [:name, :id]
7+
@includes = :users
8+
end
9+
10+
fields do
11+
id link_to_resource: true
12+
text :name, required: true
13+
14+
status :status, failed_when: [:closed, :rejected, :failed], loading_when: [:loading, :running, :waiting], nullable: true
15+
select :stage, hide_on: [:show, :index], options: { discovery: 'Discovery', ideea: 'Ideea', done: 'Done', 'on hold': 'On hold', cancelled: 'Cancelled' }, placeholder: 'Choose the stage.'
16+
badge :stage, options: { info: [:discovery, :ideea], success: :done, warning: 'on hold', danger: :cancelled }
17+
currency :budget, currency: 'EUR', locale: 'de-DE'
18+
# country :country
19+
number :users_required
20+
datetime :started_at, time_24hr: true
21+
files :files
22+
key_value :meta, key_label: 'Meta key', value_label: 'Meta value', action_text: 'New item', delete_text: 'Remove item', disable_editing_keys: false, disable_adding_rows: false, disable_deleting_rows: false
23+
24+
has_and_belongs_to_many :users
25+
end
26+
end
27+
end
28+
end

app/avo/resources/team.rb

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Avo
2+
module Resources
3+
class Team < Resource
4+
def initialize
5+
@title = :name
6+
@search = [:id, :name]
7+
end
8+
9+
fields do
10+
id
11+
text :name
12+
textarea :description, rows: 5, readonly: false, hide_on: :index, format_using: -> (value) { value.to_s.truncate 30 }, default: 'This team is wonderful!', nullable: true, null_values: ['0', '', 'null', 'nil']
13+
14+
number :members_count do |model|
15+
model.members.count
16+
end
17+
18+
has_one :admin
19+
has_many :members
20+
end
21+
end
22+
end
23+
end

app/avo/resources/team_membership.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Avo
2+
module Resources
3+
class TeamMembership < Resource
4+
def initialize
5+
@title = :id
6+
@search = :id
7+
end
8+
9+
fields do
10+
id
11+
select :level, options: { beginner: 'Beginner', intermediate: 'Intermediate', advanced: 'Advanced' }, display_value: true, default: -> (model, resource, view, field) { Time.now.hour < 12 ? 'advanced' : 'beginner' }
12+
belongs_to :user
13+
belongs_to :team
14+
end
15+
end
16+
end
17+
end

app/avo/resources/user.rb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module Avo
2+
module Resources
3+
class User < Resource
4+
def initialize
5+
@title = :name
6+
@search = [:id, :first_name, :last_name]
7+
@includes = :posts
8+
@has_devise_password = true
9+
end
10+
11+
fields do
12+
id
13+
gravatar :email, link_to_resource: true
14+
heading 'User information'
15+
text :first_name, required: true, placeholder: 'John'
16+
text :last_name, required: true, placeholder: 'Doe'
17+
text :email, name: 'User Email', required: true
18+
boolean :active, name: 'Is active', show_on: :show
19+
file :cv, name: 'CV'
20+
boolean :is_admin?, name: 'Is admin', only_on: :index
21+
boolean_group :roles, options: { admin: 'Administrator', manager: 'Manager', editor: 'Editor' }
22+
date :birthday, first_day_of_week: 1, picker_format: 'F J Y', format: 'MMMM Do YYYY', placeholder: 'Feb 24th 1955', required: true
23+
text :is_writer, format_using: -> (value) { value.truncate 3 }, hide_on: :edit do |model, resource, view, field|
24+
model.posts.to_a.count > 0 ? 'yes' : 'no'
25+
end
26+
27+
password :password, name: 'User Password', required: false, except_on: :forms, help: 'You may verify the password strength <a href="http://www.passwordmeter.com/">here</a>.'
28+
password :password_confirmation, name: 'Password confirmation', required: false
29+
30+
heading '<div class="text-gray-300 uppercase font-bold">DEV</div>', as_html: true
31+
32+
hidden :team_id, default: 0 # For testing purposes
33+
34+
has_and_belongs_to_many :projects
35+
has_many :posts
36+
end
37+
38+
use_action Avo::Actions::MarkInactive
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)