Skip to content

Commit

Permalink
include ransack and add fixed member stat
Browse files Browse the repository at this point in the history
  • Loading branch information
hpyhacking committed Apr 21, 2014
1 parent a24611d commit 0897db8
Show file tree
Hide file tree
Showing 21 changed files with 362 additions and 94 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ gem 'grape-entity', '~> 0.4.2'
gem 'grape-swagger', '~> 0.7.2'
gem 'rack-attack', '~> 3.0.0'
gem 'easy_table'
gem 'ransack', git: 'https://github.com/activerecord-hackery/ransack.git', branch: 'rails-4'

group :development, :test do
gem 'factory_girl_rails'
Expand Down
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
GIT
remote: https://github.com/activerecord-hackery/ransack.git
revision: 8009ae93e3e00325e41edd231b4b917c45a2c6c2
branch: rails-4
specs:
ransack (1.1.0)
actionpack (>= 4.0)
activerecord (>= 4.0)
activesupport (>= 4.0)
i18n
polyamorous (~> 0.6.0)

GIT
remote: https://github.com/peatio/bootstrap-on-rails.git
revision: 1e0ca2e4d3fe129c05cf7a2168bf6824c647496d
Expand Down Expand Up @@ -250,6 +262,8 @@ GEM
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
polyamorous (0.6.4)
activerecord (>= 3.0)
polyglot (0.3.3)
pry (0.9.12.6)
coderay (~> 1.0)
Expand Down Expand Up @@ -492,6 +506,7 @@ DEPENDENCIES
rack-attack (~> 3.0.0)
rails
rails-i18n
ransack!
rbtree
recaptcha
redis-rails
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/admin.less
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ span.detail-section {
border: 1px solid lightgray;
}

.panel-footer {
ul.pagination {
margin: 0px;
}
}
4 changes: 2 additions & 2 deletions app/controllers/admin/statistic/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Admin
module Statistic
class MembersController < BaseController
def show
@members_grid = ::Statistic::MembersGrid.new(params[:statistic_members_grid])
@assets = @members_grid.assets.page(params[:page]).per(20)
@q = Member.order('id desc').includes(:two_factor, :id_document).search(params[:q])
@members = @q.result(distinct: true).page params[:page]
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,12 @@ def muut_api_options
timestamp: ts
}
end

def yesno(val)
if val
content_tag(:span, 'YES', class: 'label label-success')
else
content_tag(:span, 'NO', class: 'label label-danger')
end
end
end
4 changes: 2 additions & 2 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Member < ActiveRecord::Base
has_one :two_factor
has_one :id_document

delegate :activated?, to: :two_factor, prefix: true
delegate :verified?, to: :id_document, prefix: true
delegate :activated?, to: :two_factor, prefix: true, allow_nil: true
delegate :verified?, to: :id_document, prefix: true, allow_nil: true

has_many :authentications, dependent: :destroy

Expand Down
35 changes: 32 additions & 3 deletions app/views/admin/statistic/members/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
= render "admin/statistic/shared/filter", form_target: @members_grid, url: admin_statistic_members_path
.row: .col-md-12
= datagrid_table @members_grid, @assets
.row
.col-md-5
.panel.panel-primary
.panel-heading
span = t('.search')
.panel-body
= search_form_for @q do |f|
= f.label :email_cont
= f.text_field :email_cont
= f.submit
.col-md-19
.panel.panel-primary
.panel-heading
span = t('.table')
.panel-body
= table_for(@members, class: 'table table-condensed table-hover', model: Member) do |t|
- t.column :id, class: 'col-md-1'
- t.column :email, class: 'col-md-2' do |x|
code.text-info = x.email
- t.column :created_at, class: 'col-md-3'
- t.column :activated?, class: 'col-md-1' do |x|
= yesno x.activated?
- t.column :two_factor_activated?, class: 'col-md-1' do |x|
= yesno x.two_factor_activated?
- t.column :id_document_verified?, class: 'col-md-1' do |x|
= yesno x.id_document_verified?
- t.column :action, class: 'col-md-1' do |x|
= link_to t('actions.view'), url_for([:admin, x]), target: '_blank'
.panel-footer
= paginate @members
.pull-right
h5 = @members.size

5 changes: 3 additions & 2 deletions app/views/kaminari/_gap.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
total_pages : total number of pages
per_page : number of items to fetch per page
remote : data-remote
span.page.gap
== raw(t 'views.pagination.truncate')
li.page.gap
a
== raw(t 'views.pagination.truncate')
'
8 changes: 8 additions & 0 deletions config/initializers/easy_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ def column_with_custom(title, label_or_opts = nil, opts = {}, &block)
label_or_opts ||= {}
label_or_opts.merge!({model: @options[:model]})
end

if @options[:scope]
label_or_opts ||= {}
label_or_opts.merge!({scope: @options[:scope]})
end

column_without_custom(title, label_or_opts, opts, &block)
end

Expand All @@ -16,6 +22,8 @@ module Base
def translate_with_custom(key)
if @opts[:model]
@opts[:model].human_attribute_name(@title)
elsif @opts[:scope]
I18n.t("easy_table.#{@opts[:scope]}.#{@title}")
else
translate_without_custom(key)
end
Expand Down
10 changes: 10 additions & 0 deletions config/initializers/kaminari_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Kaminari.configure do |config|
config.default_per_page = 10
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
end
13 changes: 13 additions & 0 deletions config/initializers/ransack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Ransack
module Helpers
module FormHelper
def search_form_for_with_default_url_opt(record, options = {}, &proc)
options[:url] = ''
options[:wrapper] = 'search'
search_form_for_without_default_url_opt(record, options, &proc)
end

alias_method_chain :search_form_for, :default_url_opt
end
end
end
21 changes: 18 additions & 3 deletions config/initializers/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,32 @@
b.optional :readonly

## Inputs
b.use :label
#
b.use :label, wrap_with: { tag: :div, class: 'col-sm-4 text-right'}
b.use :input, wrap_with: { tag: :div, class: 'col-sm-7'}
b.use :error, wrap_with: { tag: :span, class: 'error text-danger col-sm-7 col-sm-offset-4' }
b.use :hint, wrap_with: { tag: :span, class: 'hint col-sm-7 col-sm-offset-4' }
end

config.wrappers :search, class: 'form-group',
hint_class: :field_with_hint, error_class: :field_with_errors do |b|
b.use :placeholder
b.optional :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly

## Inputs
b.use :label
b.use :input, wrap_with: { tag: :div }
b.use :hint, wrap_with: { tag: :span, class: 'hint' }
end

# The default wrapper to be used by the FormBuilder.
config.default_wrapper = :default

# You can define the class to use on all labels. Default is nil.
config.label_class = 'col-sm-4 control-label'
config.label_class = 'control-label'

# Define the way to render check boxes / radio buttons with labels.
# Defaults to :nested for bootstrap config.
Expand Down Expand Up @@ -101,7 +116,7 @@
# config.label_text = lambda { |label, required| "#{required} #{label}" }

# You can define the class to use on all forms. Default is simple_form.
config.form_class = 'simple_form form-horizontal'
config.form_class = 'simple_form'

# You can define which elements should obtain additional classes
# config.generate_additional_classes_for = [:wrapper, :label, :input]
Expand Down
52 changes: 52 additions & 0 deletions config/initializers/simple_form_bootstrap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper tag: 'div', class: 'controls' do |ba|
ba.use :input
ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end

config.wrappers :prepend, tag: 'div', class: "control-group", error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper tag: 'div', class: 'controls' do |input|
input.wrapper tag: 'div', class: 'input-prepend' do |prepend|
prepend.use :input
end
input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end

config.wrappers :append, tag: 'div', class: "control-group", error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper tag: 'div', class: 'controls' do |input|
input.wrapper tag: 'div', class: 'input-append' do |append|
append.use :input
end
input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end
end

module SimpleForm
module ActionViewExtensions
module FormHelper
def simple_form_for_with_default_class(record, options = {}, &block)
options[:html] ||= {}
options[:html][:class] ||= 'form-horizontal'
simple_form_for_without_default_class(record, options, &block)
end
alias_method_chain :simple_form_for, :default_class
end
end
end
2 changes: 2 additions & 0 deletions config/locales/breadcrumbs/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ zh-CN:
admin/deposits/satoshis: 比特币充值
admin/withdraws/banks: 银行转账提现
admin/withdraws/satoshis: 比特币提现
admin/statistic: 数据统计
admin/statistic/members: 用户统计
21 changes: 4 additions & 17 deletions config/locales/easy_table/zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
zh-CN:
easy_table:
satoshi:
amount: 充值数量
txid: 交易哈希
created_at: 交易时间
memo: 确认数
member_name: 用户
state_and_actions: 状态/操作
currency_obj_key_text: 币种
bank:
sn: 充值编号
amount: 充值金额
created_at: 提交时间
fund_source: 充值帐号
memo: 备注
member_name: 用户
state_and_actions: 状态/操作
currency_obj_key_text: 币种
statistic:
member:
id: 编号
email: asdf
6 changes: 6 additions & 0 deletions config/locales/models/zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
zh-CN:
attributes:
action: 操作
activerecord:
models:
trade: 交易
Expand Down Expand Up @@ -84,12 +86,16 @@ zh-CN:
state_done: 完成
state_wait: 等待
member:
id: 编号
name: 真实姓名
email: 邮件地址
created_at: 注册时间
sn: 个人识别码
tag_list: 标签
activated: 激活成功
activated?: 邮件激活
id_document_verified?: 实名认证
two_factor_activated?: 二次验证
errors:
models:
order_bid:
Expand Down
Loading

0 comments on commit 0897db8

Please sign in to comment.