Add admin UI for BankGateway

This commit is contained in:
Patrick Gansterer 2021-03-05 12:44:53 +01:00
parent 87fe9ccdb1
commit 79fdb4dafb
11 changed files with 99 additions and 0 deletions

View file

@ -0,0 +1,41 @@
class Admin::BankGatewaysController < Admin::BaseController
inherit_resources
def new
@bank_gateway = BankGateway.new(params[:bank_gateway])
render layout: false
end
def create
@bank_gateway = BankGateway.new(params[:bank_gateway])
if @bank_gateway.valid? && @bank_gateway.save
redirect_to update_bank_gateways_admin_finances_url, status: :see_other
else
render action: 'new', layout: false
end
end
def edit
@bank_gateway = BankGateway.find(params[:id])
render action: 'new', layout: false
end
def update
@bank_gateway = BankGateway.find(params[:id])
if @bank_gateway.update(params[:bank_gateway])
redirect_to update_bank_gateways_admin_finances_url, status: :see_other
else
render action: 'new', layout: false
end
end
def destroy
@bank_gateway = BankGateway.find(params[:id])
@bank_gateway.destroy
redirect_to update_bank_gateways_admin_finances_url, status: :see_other
rescue StandardError => e
flash.now[:alert] = e.message
render template: 'shared/alert'
end
end

View file

@ -3,6 +3,7 @@ class Admin::FinancesController < Admin::BaseController
def index def index
@bank_accounts = BankAccount.order('name') @bank_accounts = BankAccount.order('name')
@bank_gateways = BankGateway.order('name')
@financial_transaction_classes = FinancialTransactionClass.includes(:financial_transaction_types).order('name ASC') @financial_transaction_classes = FinancialTransactionClass.includes(:financial_transaction_types).order('name ASC')
end end
@ -11,6 +12,11 @@ class Admin::FinancesController < Admin::BaseController
render :layout => false render :layout => false
end end
def update_bank_gateways
@bank_gateways = BankGateway.order('name')
render :layout => false
end
def update_transaction_types def update_transaction_types
@financial_transaction_classes = FinancialTransactionClass.includes(:financial_transaction_types).order('name ASC') @financial_transaction_classes = FinancialTransactionClass.includes(:financial_transaction_types).order('name ASC')
render :layout => false render :layout => false

View file

@ -7,6 +7,7 @@
= f.input :iban = f.input :iban
= f.input :description, as: :text = f.input :description, as: :text
= f.input :balance = f.input :balance
= f.association :bank_gateway
.modal-footer .modal-footer
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'} = link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
= f.submit class: 'btn btn-primary' = f.submit class: 'btn btn-primary'

View file

@ -0,0 +1,12 @@
= simple_form_for [:admin, @bank_gateway], :validate => true, :remote => true do |f|
.modal-header
= close_button :modal
%h3= @bank_gateway.new_record? ? t('.title_new') : t('.title_edit')
.modal-body
= f.input :name
= f.input :url
= f.input :authorization
= f.association :unattended_user
.modal-footer
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
= f.submit class: 'btn btn-primary'

View file

@ -0,0 +1,2 @@
$('#modalContainer').html('#{j(render("form"))}');
$('#modalContainer').modal();

View file

@ -0,0 +1,13 @@
%table.table.table-striped
%thead
%tr
%th= heading_helper BankGateway, :name
%th
%tbody
- @bank_gateways.each do |bank_gateway|
%tr
%td= bank_gateway.name
%td
= link_to t('ui.edit'), edit_admin_bank_gateway_path(bank_gateway), remote: true, class: 'btn btn-mini'
= link_to t('ui.delete'), [:admin, bank_gateway], :method => :delete, :data => {:confirm => t('ui.confirm_delete', name: bank_gateway.name)},
remote: true, class: 'btn btn-mini btn-danger'

View file

@ -3,6 +3,7 @@
- content_for :actionbar do - content_for :actionbar do
= link_to t('.new_financial_transaction_class'), new_admin_financial_transaction_class_path, remote: true, class: 'btn btn-primary' = link_to t('.new_financial_transaction_class'), new_admin_financial_transaction_class_path, remote: true, class: 'btn btn-primary'
= link_to t('.new_bank_account'), new_admin_bank_account_path, remote: true, class: 'btn' = link_to t('.new_bank_account'), new_admin_bank_account_path, remote: true, class: 'btn'
= link_to t('.new_bank_gateway'), new_admin_bank_gateway_path, remote: true, class: 'btn'
- content_for :sidebar do - content_for :sidebar do
%p= t('.first_paragraph').html_safe %p= t('.first_paragraph').html_safe
@ -12,3 +13,6 @@
%h2= t('.bank_accounts') %h2= t('.bank_accounts')
#bank_accounts_table= render 'bank_accounts' #bank_accounts_table= render 'bank_accounts'
%h2= t('.bank_gateways')
#bank_gateways_table= render 'bank_gateways'

View file

@ -0,0 +1,2 @@
$('#bank_gateways_table').html('#{escape_javascript(render("admin/finances/bank_gateways"))}');
$('#modalContainer').modal('hide');

View file

@ -290,6 +290,14 @@ de:
title: Administration title: Administration
type: Typ type: Typ
username: Benutzername username: Benutzername
bank_accounts:
form:
title_edit: Bankkonto bearbeiten
title_new: Bankkonto anlegen
bank_gateways:
form:
title_edit: Bankgateway bearbeiten
title_new: Bankgateway anlegen
configs: configs:
list: list:
key: Schlüssel key: Schlüssel

View file

@ -290,6 +290,14 @@ en:
title: Administration title: Administration
type: type type: type
username: username username: username
bank_accounts:
form:
title_edit: Edit bank account
title_new: Add new bank account
bank_gateways:
form:
title_edit: Edit bank gateway
title_new: Add new bank gateway
configs: configs:
list: list:
key: Key key: Key

View file

@ -224,10 +224,12 @@ Rails.application.routes.draw do
resources :finances, only: [:index] do resources :finances, only: [:index] do
get :update_bank_accounts, on: :collection get :update_bank_accounts, on: :collection
get :update_bank_gateways, on: :collection
get :update_transaction_types, on: :collection get :update_transaction_types, on: :collection
end end
resources :bank_accounts resources :bank_accounts
resources :bank_gateways
resources :financial_transaction_classes resources :financial_transaction_classes
resources :financial_transaction_types resources :financial_transaction_types