diff options
author | Peter Kozak <spag@golwen.net> | 2013-06-22 10:25:31 +0200 |
---|---|---|
committer | Peter Kozak <spag@golwen.net> | 2013-06-22 10:25:31 +0200 |
commit | 130e77d4c9df2cca2425b63a443ea8745133d083 (patch) | |
tree | 4637509156e35ac172937d02e9639b6cde8b29a6 /app | |
parent | 08ecc91d89a2b6a83daee4a1ffda5520e38e53c6 (diff) |
cdrs added
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/cdrs_controller.rb | 43 | ||||
-rw-r--r-- | app/models/cdr.rb | 17 | ||||
-rw-r--r-- | app/models/freeswitch_cdr.rb | 4 | ||||
-rw-r--r-- | app/views/cdrs/_index_core.html.haml | 33 | ||||
-rw-r--r-- | app/views/cdrs/index.html.haml | 4 |
5 files changed, 97 insertions, 4 deletions
diff --git a/app/controllers/cdrs_controller.rb b/app/controllers/cdrs_controller.rb new file mode 100644 index 0000000..3815f52 --- /dev/null +++ b/app/controllers/cdrs_controller.rb @@ -0,0 +1,43 @@ +class CdrsController < ApplicationController + load_and_authorize_resource :tenant + + before_filter :set_and_authorize_parent + before_filter :spread_breadcrumbs + + helper_method :sort_column, :sort_descending + + def index + @cdrs = Cdr.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( + :page => params[:page], + :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') + ) + end + + def show + end + + def destroy + @cdr.destroy + m = method( :"#{@parent.class.name.underscore}_cdrs_url" ) + redirect_to m.(@parent), :notice => t('cdrs.controller.successfuly_destroyed') + end + + private + def set_and_authorize_parent + @parent = @user || @tenant + authorize! :read, @parent + end + + def spread_breadcrumbs + add_breadcrumb t("cdrs.index.page_title"), tenant_cdrs_path(@tenant) + end + + def sort_descending + params[:desc].to_s == 'true' + end + + def sort_column + Cdr.column_names.include?(params[:sort]) ? params[:sort] : 'start_stamp' + end + +end diff --git a/app/models/cdr.rb b/app/models/cdr.rb new file mode 100644 index 0000000..ff9198f --- /dev/null +++ b/app/models/cdr.rb @@ -0,0 +1,17 @@ +class Cdr < ActiveRecord::Base + self.table_name = 'cdrs' + self.primary_key = 'uuid' + + belongs_to :account + belongs_to :bleg_account + belongs_to :forwarding_account + + + def self.seconds_to_minutes_seconds(call_seconds) + if call_seconds.to_i > 0 + minutes = (call_seconds / 1.minutes).to_i + seconds = call_seconds - minutes.minutes.seconds + return '%i:%02i' % [minutes, seconds] + end + end +end diff --git a/app/models/freeswitch_cdr.rb b/app/models/freeswitch_cdr.rb deleted file mode 100644 index fd0eb75..0000000 --- a/app/models/freeswitch_cdr.rb +++ /dev/null @@ -1,4 +0,0 @@ -class FreeswitchCdr < ActiveRecord::Base - self.table_name = 'cdrs' - self.primary_key = 'uuid' -end diff --git a/app/views/cdrs/_index_core.html.haml b/app/views/cdrs/_index_core.html.haml new file mode 100644 index 0000000..39e9e7f --- /dev/null +++ b/app/views/cdrs/_index_core.html.haml @@ -0,0 +1,33 @@ + +- if defined?(cdrs.total_pages) + = will_paginate cdrs, :renderer => BootstrapPagination::Rails, :previous_label => raw('<i class = "icon-chevron-left"></i>'), :next_label => raw('<i class = "icon-chevron-right"></i>') + +%table.table.table-striped + %thead + %tr + %th= sortable :start_stamp, t('cdrs.index.start_stamp') + %th= sortable :caller_id_number, t('cdrs.index.caller_id_number') + %th= sortable :caller_id_name, t('cdrs.index.caller_id_name') + %th= sortable :dialed_number, t('cdrs.index.dialed_number') + %th= sortable :destination_number, t('cdrs.index.destination_number') + %th= sortable :callee_id_number, t('cdrs.index.callee_id_number') + %th= sortable :callee_id_name, t('cdrs.index.callee_id_name') + %th= sortable :billsec, t('cdrs.index.billsec') + %th= sortable :hangup_cause, t('cdrs.index.hangup_cause') + %th= sortable :dialstatus, t('cdrs.index.dialstatus') + + %tbody + - for cdr in cdrs + %tr{:class => (cdr.dialstatus == 'SUCCESS' ? '' : 'warning')} + %td= l cdr.start_stamp, :format => :short + %td= cdr.caller_id_number + %td= cdr.caller_id_name + %td= cdr.dialed_number + %td= cdr.destination_number + %td= cdr.callee_id_number + %td= cdr.callee_id_name + %td= Cdr.seconds_to_minutes_seconds(cdr.billsec) + %td= cdr.hangup_cause + %td= cdr.dialstatus + + /=render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => @tenant, :child => cdr} diff --git a/app/views/cdrs/index.html.haml b/app/views/cdrs/index.html.haml new file mode 100644 index 0000000..b260b38 --- /dev/null +++ b/app/views/cdrs/index.html.haml @@ -0,0 +1,4 @@ +- content_for :title, t("cdrs.index.page_title") + +- if @cdrs.count > 0 + = render "index_core", :cdrs => @cdrs |