Skip to content

Commit

Permalink
Merge pull request #492 from senid231/active-calls-api-patch-1.8
Browse files Browse the repository at this point in the history
Active calls API patch 1.8
  • Loading branch information
dmitry-sinina authored Jun 12, 2019
2 parents bda5b04 + 031a709 commit 5a83465
Show file tree
Hide file tree
Showing 34 changed files with 1,319 additions and 640 deletions.
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ jobs:
- bundle exec rake bundle:audit
- bundle exec rspec

- stage: test
script:
- bundle install --jobs=3 --retry=3 --deployment
- RAILS_ENV=test bundle exec rake db:create db:structure:load db:migrate
- RAILS_ENV=test bundle exec rake db:second_base:create db:second_base:structure:load db:second_base:migrate
- RAILS_ENV=test bundle exec rake db:seed
- bundle exec cucumber

- stage: test
script:
- bundle install --jobs=3 --retry=3 --deployment
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ group :test do
gem 'capybara'
gem 'capybara-screenshot'
gem 'chromedriver-helper'
gem 'cucumber-rails', require: false
gem 'selenium-webdriver'
gem 'shoulda-matchers'
gem 'webmock'
Expand Down
29 changes: 0 additions & 29 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ GEM
arel (9.0.0)
ast (2.4.0)
awesome_print (1.8.0)
backports (3.11.4)
bcrypt (3.1.11)
bootsnap (1.3.2)
msgpack (~> 1.0)
Expand Down Expand Up @@ -230,28 +229,6 @@ GEM
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.4)
cucumber (3.1.2)
builder (>= 2.1.2)
cucumber-core (~> 3.2.0)
cucumber-expressions (~> 6.0.1)
cucumber-wire (~> 0.0.1)
diff-lcs (~> 1.3)
gherkin (~> 5.1.0)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2)
cucumber-core (3.2.1)
backports (>= 3.8.0)
cucumber-tag_expressions (~> 1.1.0)
gherkin (~> 5.0)
cucumber-expressions (6.0.1)
cucumber-rails (1.6.0)
capybara (>= 1.1.2, < 4)
cucumber (>= 3.0.2, < 4)
mime-types (>= 1.17, < 4)
nokogiri (~> 1.8)
railties (>= 4, < 6)
cucumber-tag_expressions (1.1.1)
cucumber-wire (0.0.1)
d3-rails (3.5.2)
railties (>= 3.1)
daemons (1.2.6)
Expand Down Expand Up @@ -298,7 +275,6 @@ GEM
text (>= 1.3.0)
gettext_i18n_rails (1.8.0)
fast_gettext (>= 0.9.0)
gherkin (5.1.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
has_scope (0.7.2)
Expand Down Expand Up @@ -354,16 +330,12 @@ GEM
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
mimemagic (0.3.3)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
msgpack (1.2.6)
multi_json (1.13.1)
multi_test (0.1.2)
mustache (1.0.5)
net-ldap (0.16.1)
net_tcp_client (2.0.1)
Expand Down Expand Up @@ -572,7 +544,6 @@ DEPENDENCIES
chromedriver-helper
coffee-rails (~> 4.0)
compass-rails (~> 3.0.2)
cucumber-rails
d3-rails (= 3.5.2)
daemons
database_cleaner
Expand Down
212 changes: 180 additions & 32 deletions app/admin/realtime_data/active_calls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}
config.batch_actions = true
batch_action :destroy, false
decorate_with ActiveCallDecorator

actions :index, :show

Expand Down Expand Up @@ -116,64 +117,211 @@
end

controller do
def index
index!
rescue StandardError => e
flash.now[:warning] = e.message
raise e
end

def show
show!
rescue YetisNode::Error => e
flash[:warning] = e.message
redirect_to_back
end

def find_resource
node_id, local_tag = params[:id].split('*')
active_calls = [Node.find(node_id).active_call(local_tag)]
active_calls = RealtimeData::ActiveCall.assign_foreign_resources(active_calls)
active_calls.first
def scoped_collection
# is_list = active_admin_config.get_page_presenter(:index, params[:as]).options[:as] == :list_with_content
# # I don't understand what is only.
# only = is_list ? (LIST_ATTRIBUTES + SYSTEM_ATTRIBUTES) : nil
# only = nil # dirty fix for https://bt.yeti-switch.org/issues/253
# # Customer, Vendor, Duration, dst_prefix_routing, Start time, connect time,dst country,
# # Dst network, Destination next rate, Dialpeer next rate
# LIST_ATTRIBUTES = [
# :customer_id,
# :vendor_id,
# :duration,
# :dst_prefix_routing,
# :lrn,
# :start_time,
# :connect_time,
# # :dst_country_id,
# :dst_network_id,
# :destination_next_rate,
# :dialpeer_next_rate
# ].freeze
#
# SYSTEM_ATTRIBUTES = %i[
# node_id
# local_tag
# ].freeze
RealtimeData::ActiveCall.includes(*RealtimeData::ActiveCall.association_types.keys)
end

def find_collection(_options = {})
@search = OpenStruct.new(params[:q])

return [] if params[:q].blank? && GuiConfig.active_calls_require_filter

active_calls = []
begin
is_list = active_admin_config.get_page_presenter(:index, params[:as]).options[:as] == :list_with_content # WTF?? .
is_list = false # dirty fix for https://bt.yeti-switch.org/issues/253
only = is_list ? (RealtimeData::ActiveCall::LIST_ATTRIBUTES + RealtimeData::ActiveCall::SYSTEM_ATTRIBUTES) : nil # I don't understand what is only.
active_calls = RealtimeData::ActiveCall.collection(Yeti::CdrsFilter.new(Node.all, params.to_unsafe_h[:q]).search(only: only, empty_on_error: true))
active_calls = Kaminari.paginate_array(active_calls).page(1).per(active_calls.count)
active_calls = RealtimeData::ActiveCall.assign_foreign_resources(active_calls)
rescue StandardError => e
flash.now[:warning] = e.message
raise e
end
def apply_sorting(chain)
chain
end

def apply_filtering(chain)
query_params = (params.to_unsafe_h[:q] || {}).delete_if { |_, v| v.blank? }
@search = OpenStruct.new(query_params)
chain = chain.none if query_params.blank? && GuiConfig.active_calls_require_filter
chain.where(query_params)
end

def apply_pagination(chain)
@skip_drop_down_pagination = true
active_calls
records = chain.to_a
Kaminari.paginate_array(records).page(1).per(records.size)
end
end

show do
attributes_table do
RealtimeData::ActiveCall.human_attributes.each do |attr|
row attr
row :start_time
row :connect_time
row :duration
row :time_limit
row :dst_prefix_in
row :dst_prefix_routing
row :lrn
row :dst_prefix_out
row :src_prefix_in
row :src_prefix_routing
row :src_prefix_out
row :diversion_in
row :diversion_out
row :dst_country, &:dst_country_link
row :dst_network, &:dst_network_link
row :customer, &:customer_link
row :vendor, &:vendor_link
row :customer_acc, &:customer_acc_link
row :vendor_acc, &:vendor_acc_link
row :customer_auth, &:customer_auth_link
row :destination, &:destination_link
row :dialpeer, &:dialpeer_link
row :orig_gw, &:orig_gw_link
row :term_gw, &:term_gw_link
row :routing_group, &:routing_group_link
row :rateplan, &:rateplan_link
row :destination_initial_rate
row :destination_next_rate
row :destination_initial_interval
row :destination_next_interval
row :destination_fee
row :destination_rate_policy_id
row :dialpeer_initial_rate
row :dialpeer_next_rate
row :dialpeer_initial_interval
row :dialpeer_next_interval
row :dialpeer_fee
row :legA_remote_ip
row :legA_remote_port
row :orig_call_id
row :legA_local_ip
row :legA_local_port
row :local_tag
row :legB_local_ip
row :legB_local_port
row :term_call_id
row :legB_remote_ip
row :legB_remote_port
row :node, &:node_link
row :pop, &:pop_link
end
if resource._rest_attributes
panel 'Extra Attributes' do
attributes_table_for resource do
resource._rest_attributes.each do |key, value|
row(key) { value }
end
end
end
end
end

# collection_action :items_list do
# @active_calls = find_collection
# render "active_calls_collection", layout: false
# end

index do
render 'active_calls_table', context: self
selectable_column
actions do |resource|
item 'Terminate',
url_for(action: :drop, id: resource.id),
method: :post,
class: 'member_link delete_link',
data: { confirm: I18n.t('active_admin.delete_confirmation') }
end
column :start_time
column :connect_time
column :duration
column :time_limit
column :dst_prefix_in
column :dst_prefix_routing
column :lrn
column :dst_prefix_out
column :src_prefix_in
column :src_prefix_routing
column :src_prefix_out
column :diversion_in
column :diversion_out
column :dst_country, :dst_country_link
column :dst_network, :dst_network_link
column :customer, :customer_link
column :vendor, :vendor_link
column :customer_acc, :customer_acc_link
column :vendor_acc, :vendor_acc_link
column :customer_auth, :customer_auth_link
column :destination, :destination_link
column :dialpeer, :dialpeer_link
column :orig_gw, :orig_gw_link
column :term_gw, :term_gw_link
column :routing_group, :routing_group_link
column :rateplan, :rateplan_link
column :destination_initial_rate
column :destination_next_rate
column :destination_initial_interval
column :destination_next_interval
column :destination_fee
column :destination_rate_policy_id
column :dialpeer_initial_rate
column :dialpeer_next_rate
column :dialpeer_initial_interval
column :dialpeer_next_interval
column :dialpeer_fee
column :legA_remote_ip
column :legA_remote_port
column :orig_call_id
column :legA_local_ip
column :legA_local_port
column :local_tag
column :legB_local_ip
column :legB_local_port
column :term_call_id
column :legB_remote_ip
column :legB_remote_port
column :node, :node_link
column :pop, :pop_link
end

index as: :list_with_content, default: true, download_links: false, partial: 'shared/active_calls_top_chart',
blank_slate_content: lambda {
GuiConfig::FILTER_MISSED_TEXT if GuiConfig.active_calls_require_filter
} do

render 'active_calls_list', context: self
selectable_column
actions do |resource|
item 'Terminate',
url_for(action: :drop, id: resource.id),
method: :post,
class: 'member_link delete_link',
data: { confirm: I18n.t('active_admin.delete_confirmation') }
end

column :customer, :customer_link
column :vendor, :vendor_link
column :duration
column :dst_number, :dst_prefix_routing
column :dst_network, :dst_network_link
column :origination_rate, :destination_next_rate
column :termination_rate, :dialpeer_next_rate
end
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/active_calls_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::ActiveCallsController < Api::Rest::Admin::BaseController
end
14 changes: 14 additions & 0 deletions app/decorators/active_call_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class ActiveCallDecorator < ApplicationDecorator
def self.object_class_namespace
'RealtimeData'
end

RealtimeData::ActiveCall.association_types.each do |name, foreign_key:, **_|
define_method("#{name}_link") do
record = model.public_send(name)
record ? h.auto_link(record) : model.public_send(foreign_key)
end
end
end
18 changes: 18 additions & 0 deletions app/decorators/application_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

class ApplicationDecorator < Draper::Decorator
include Rails.application.routes.url_helpers
delegate_all

def self.object_class_name
return nil if name.nil? || name.demodulize !~ /.+Decorator$/

class_name = name.chomp('Decorator')
namespace = object_class_namespace
namespace.blank? ? class_name : "#{namespace}::#{class_name}"
end

def self.object_class_namespace
nil
end
end
Loading

0 comments on commit 5a83465

Please sign in to comment.