add fiat balances dashboard

This commit is contained in:
João Geonizeli
2021-08-11 23:30:51 -03:00
parent 5cda80446f
commit 0b247d390b
6 changed files with 85 additions and 2 deletions

View File

@@ -0,0 +1,8 @@
# frozen_string_literal: true
module Admin
class FiatBalancesController < Admin::ApplicationController
def valid_action?(name, resource = resource_class)
["destroy"].exclude?(name.to_s) && super
end
end
end

View File

@@ -0,0 +1,53 @@
# frozen_string_literal: true
require "administrate/base_dashboard"
class FiatBalanceDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
id: Field::Number,
user: Field::BelongsTo,
amount_formatted: Field::String,
created_at: Field::DateTime,
updated_at: Field::DateTime,
}.freeze
# COLLECTION_ATTRIBUTES
# an array of attributes that will be displayed on the model's index page.
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = [:id, :user, :amount_formatted].freeze
# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = [:user, :id, :amount_formatted, :created_at, :updated_at].freeze
# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [:user, :amount_formatted].freeze
# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search
# field of the dashboard.
#
# For example to add an option to search for open resources by typing "open:"
# in the search field:
#
# COLLECTION_FILTERS = {
# open: ->(resources) { resources.where(open: true) }
# }.freeze
COLLECTION_FILTERS = {}.freeze
# Overwrite this method to customize how fiat balances are displayed
# across all pages of the admin dashboard.
#
# def display_resource(fiat_balance)
# "FiatBalance ##{fiat_balance.id}"
# end
end

View File

@@ -24,5 +24,7 @@ class FiatBalance < ApplicationRecord
monetize :amount_cents monetize :amount_cents
validates :amount, presence: true def amount_formatted
amount.format
end
end end

View File

@@ -4,17 +4,34 @@ pt-BR:
user_document: user_document:
one: Documentos de Usuário one: Documentos de Usuário
other: Documentos de Usuários other: Documentos de Usuários
admin_user: admin_user:
one: Administrador one: Administrador
other: Administradores other: Administradores
currency: currency:
one: Moeda one: Moeda
other: Moedas other: Moedas
balance: balance:
one: Saldo one: Saldo
other: Saldos other: Saldos
fiat_balance:
one: Saldo Fiat
other: Saldos Fiat
attributes: attributes:
user: user:
first_name: Primeiro nome first_name: Primeiro nome
last_name: Último nome last_name: Último nome
full_name: Nome completo full_name: Nome completo
balance:
amount: Quantia
fiat_balance:
amount_formatted: Quantia
currency:
name: Nome

View File

@@ -6,6 +6,7 @@ Rails.application.routes.draw do
namespace :admin do namespace :admin do
resources :users resources :users
resources :balances resources :balances
resources :fiat_balances
resources :currencies resources :currencies
resources :admin_users resources :admin_users

View File

@@ -22,5 +22,7 @@
require "rails_helper" require "rails_helper"
RSpec.describe(FiatBalance, type: :model) do RSpec.describe(FiatBalance, type: :model) do
pending "add some examples to (or delete) #{__FILE__}" describe "associations" do
it { is_expected.to(belong_to(:user)) }
end
end end