class SidekiqMonitor.AbstractJobsTable constructor: -> @api_params = {} @initialize() initialize_with_options: (options) => @options = options @table = $(@options.table_selector) @columns = @options.columns @status_filter = null $.getJSON SidekiqMonitor.settings.api_url('jobs/clean') @table.dataTable bProcessing: true bServerSide: true sAjaxSource: @table.data('source') iDisplayLength: 10 aaSorting: [[@columns.enqueued_at, 'desc']] sPaginationType: 'bootstrap' aoColumns: @options.column_options oLanguage: sInfo: '_TOTAL_ jobs' sInfoFiltered: ' (filtered from _MAX_)' sLengthMenu: 'Per page: _MENU_' sSearch: '' fnRowCallback: (nRow, aData, iDisplayIndex) => $('.timeago', nRow).timeago() fnInitComplete: () => filter_container = @table.siblings('.dataTables_filter') filter_container.find('input').attr('placeholder', 'Search...') filter_container.prepend '
' @status_filter = filter_container.find('.status-filter') fnServerData: (sSource, aoData, fnCallback) => $.each @api_params, (key, value) => aoData.push name: key value: @api_params[key] $.getJSON sSource, aoData, (json) -> fnCallback(json) @table.parents('.dataTables_wrapper').addClass('jobs-table-wrapper') @initialize_ui() initialize_ui: => @table.on 'click', '.status-value', (e) => tr = $(e.target).parents('tr:first')[0] job = @table.fnGetData(tr) @show_job(job) false @table.on 'click', '.retry-job', (e) => jid = $(e.target).attr('data-job-jid') $.getJSON SidekiqMonitor.settings.api_url('jobs/retry?jid='+jid), => @reload_table() false $('body').on 'click', '.status-filter .btn', (e) => e.stopPropagation() btn = $(e.target) btn.siblings('.btn').removeClass('active') btn.toggleClass('active') value = @status_filter.find('.active:first').attr('data-value') value = '' if !value? @table.fnFilter(value, @columns.status - 1) @start_polling() show_job: (job) => return false if !job? jid = job[@columns.jid] class_name = job[@columns.class_name] started_at = job[@columns.started_at] duration = job[@columns.duration] status = job[@columns.status] result = job[@columns.result] args = job[@columns.args] # TODO: Make this cleaner; is there a way to grab the original value returned by the server? status = $("
#{status}
").find('.status-value').text() result_html = '' if status == 'failed' result_html = """

Error

#{result.message}
Backtrace
        #{result.backtrace.join("\n")}
        
""" else if result? rows_html = "#{key}#{value}" for key, value in result result_html = """ #{rows_html}
""" modal_html = """ """ $('.job-modal').modal('hide') $('body').append(modal_html) $('.job-modal:last').modal() on_poll: => @reload_table() reload_table: => @table.dataTable().fnStandingRedraw() start_polling: => setInterval => @on_poll() , 3000 format_time_ago: (time) => if time? """#{time}""" else ""