Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Aug 15, 2023
0 parents commit bcc2faa
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.key]
insert_final_newline = false
14 changes: 14 additions & 0 deletions .github/workflows/reset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Reset cache

on:
push:
branches:
- main

jobs:
run-updater:
runs-on: ubuntu-latest
steps:
- name: Reset cache
run: |
curl -X GET "https://v3.avohq.io/templates/reset?secret=${{secrets.GH_API_SECRET}}&repo=$GITHUB_REPOSITORY"
Empty file added .gitignore
Empty file.
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Avo 3 to Bullet Train template

## Happening

1. Add to the `Gemfile`. Possibly to show a choice for `avo`, `pro` or `advanced`. `gem "avo", ">= 3.0.1.beta4", source: "https://packager.dev/avo-hq"`
1. Run `bundle install`
1. Add the route `mount Avo::Engine, at: Avo.configuration.root_path`
1. Copy the `template` files


59 changes: 59 additions & 0 deletions template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Insert templates here

if ARGV.include? "--community-edition"
edition = "community"
elsif ARGV.include? "--pro-edition"
edition = "pro"
elsif ARGV.include? "--advanced-edition"
edition = "advanced"
end

unless edition
# === Fetch the Avo edition ===
question = <<~QUESTION
What version of Avo would you like to install?
1. Avo Community (default)
2. Avo Pro
3. Avo Advanced
QUESTION

answer = ask(question, default: "1", limited_to: ["1", "2", "3"])

edition = case answer
when "1"
"community"
when "2"
"pro"
when "3"
"advanced"
end
end

# === Add gem to Gemfile ===
case edition
when "community"
gem "avo", ">= 3.0.1.beta4", source: "https://packager.dev/avo-hq"
when "pro"
gem "avo-pro", source: "https://packager.dev/avo-hq"
when "advanced"
gem "avo-advanced", source: "https://packager.dev/avo-hq"
end

# === Run bundle install ===
Bundler.with_unbundled_env { run "bundle install" }

# === Add route ===
route_contents = <<-ROUTES
# Avo admin panel
if defined?(Avo::Engine)
authenticated :user, lambda { |u| u.admin? } do
mount Avo::Engine, at: Avo.configuration.root_path
end
end
ROUTES
route route_contents

# === Copy template files ===
files.each do |path, contents|
file path, contents
end
9 changes: 9 additions & 0 deletions template/app/avo/cards/active_subscriptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Avo::Cards::ActiveSubscriptions < Avo::Dashboards::MetricCard
self.id = "active_subscriptions"
self.label = "Active subscriptions"
self.description = "Total number of active subscriptions"

def query
result ::Pay::Subscription.active.count
end
end
44 changes: 44 additions & 0 deletions template/app/avo/cards/total_revenue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Avo::Cards::TotalRevenue < Avo::Dashboards::MetricCard
self.id = "total_revenue"
self.label = "Total revenue"
self.prefix = "$"

def query
case arguments[:period]
when :last_12_months
result last_12_months
when :last_month
result last_month
when :this_month
result this_month
else
result total_revenue
end
end

def total_revenue
revenue_in_cents = ::Pay::Charge.sum(:amount)
refunds_in_cents = ::Pay::Charge.sum(:amount_refunded)
(revenue_in_cents - refunds_in_cents) / 100.0
end

def last_12_months
revenue_for_range 12.months.ago..Time.current
end

def last_month
month = Time.current.prev_month
revenue_for_range month.beginning_of_month..month.end_of_month
end

def this_month
month = Time.current
revenue_for_range month.beginning_of_month..month.end_of_month
end

def revenue_for_range(range)
revenue_in_cents = ::Pay::Charge.where(created_at: range).sum(:amount)
refunds_in_cents = ::Pay::Charge.where(created_at: range).sum(:amount_refunded)
(revenue_in_cents - refunds_in_cents) / 100.0
end
end
9 changes: 9 additions & 0 deletions template/app/avo/cards/users_count.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Avo::Cards::UsersCount < Avo::Dashboards::MetricCard
self.id = "users_count"
self.label = "Users count"
self.description = "Total number of users registered"

def query
result ::User.all.count
end
end
30 changes: 30 additions & 0 deletions template/app/avo/dashboards/overview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Avo::Dashboards::Overview < Avo::Dashboards::BaseDashboard
self.id = "overview"
self.name = "Overview"
self.grid_cols = 4

def cards
divider label: "Revenue"
card Avo::Cards::TotalRevenue,
arguments: {
period: :this_month
},
label: "This month"
card Avo::Cards::TotalRevenue,
arguments: {
period: :last_month
},
label: "Last month"
card Avo::Cards::TotalRevenue,
arguments: {
period: :last_12_months
},
label: "Last 12 months"
card Avo::Cards::TotalRevenue

divider

card Avo::Cards::UsersCount
card Avo::Cards::ActiveSubscriptions
end
end
21 changes: 21 additions & 0 deletions template/app/avo/resources/invitation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class InvitationResource < Avo::BaseResource
self.title = :email
self.includes = []
# self.search = {
# query: -> { query.ransack(id_eq: params[:q], email_cont: params[:q], m: "or").result(distinct: false) },
# item: -> {
# {
# title: record.title
# }
# }
# }

def fields
field :id, as: :id
field :email, as: :text
field :uuid, as: :text
field :team, as: :belongs_to
field :from_membership, as: :belongs_to
field :membership, as: :has_one
end
end
23 changes: 23 additions & 0 deletions template/app/avo/resources/membership.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class MembershipResource < Avo::BaseResource
self.title = :name
self.includes = []
# self.search = {
# query: -> { query.ransack(id_eq: params[:q], name_cont: params[:q], user_email_cont: params[:q], role_cont: params[:q], m: "or").result(distinct: false) },
# item: -> {
# {
# title: record.name
# }
# }
# }

field :id, as: :id
field :name, as: :text, hide_on: :forms
field :user_profile_photo_id, as: :text
field :user_email, as: :text
field :added_by_id, as: :number
field :role_ids, as: :tags
field :user, as: :belongs_to
field :team, as: :belongs_to
field :invitation, as: :belongs_to
field :added_by, as: :belongs_to
end
24 changes: 24 additions & 0 deletions template/app/avo/resources/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Avo::Resources::Team < Avo::BaseResource
self.title = :name
self.includes = []
self.search = {
query: -> { query.ransack(id_eq: params[:q], name_cont: params[:q], slug_cont: params[:q], m: "or").result(distinct: false) },
item: -> {
{
title: record.name
}
}
}

def fields
field :id, as: :id
field :name, as: :text
field :slug, as: :text
field :being_destroyed, as: :boolean, hide_on: :forms
field :time_zone, as: :text
field :locale, as: :text
field :users, as: :has_many, through: :memberships
field :memberships, as: :has_many
field :invitations, as: :has_many
end
end
24 changes: 24 additions & 0 deletions template/app/avo/resources/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class UserResource < Avo::BaseResource
self.title = :full_name
self.includes = [:teams, :memberships]
self.search = {
query: -> { query.ransack(id_eq: params[:q], first_name_cont: params[:q], last_name_cont: params[:q], email_cont: params[:q], m: "or").result(distinct: false) },
item: -> {
{
title: record.name,
}
}
}

def fields
field :id, as: :id
field :email, as: :text
field :first_name, as: :text
field :last_name, as: :text
field :time_zone, as: :text
field :current_team, as: :belongs_to

field :teams, as: :has_many, through: :teams
field :memberships, as: :has_many
end
end
4 changes: 4 additions & 0 deletions template/app/controllers/avo/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/3.0/controllers.html
class Avo::InvitationsController < Avo::ResourcesController
end
4 changes: 4 additions & 0 deletions template/app/controllers/avo/memberships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/3.0/controllers.html
class Avo::MembershipsController < Avo::ResourcesController
end
4 changes: 4 additions & 0 deletions template/app/controllers/avo/teams_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/3.0/controllers.html
class Avo::TeamsController < Avo::ResourcesController
end
4 changes: 4 additions & 0 deletions template/app/controllers/avo/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/3.0/controllers.html
class Avo::UsersController < Avo::ResourcesController
end
Loading

0 comments on commit bcc2faa

Please sign in to comment.