easy_admin 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +50 -6
- data/app/controllers/admin/outbound_requests_controller.rb +12 -0
- data/app/models/outbound_request.rb +48 -0
- data/app/views/admin/outbound_requests/_pagination.html.erb +6 -0
- data/app/views/admin/outbound_requests/index.html.erb +51 -0
- data/app/views/admin/outbound_requests/show.html.erb +58 -0
- data/config/routes.rb +1 -0
- data/lib/easy_admin/engine.rb +14 -0
- data/lib/easy_admin/version.rb +1 -1
- data/lib/easy_admin.rb +1 -1
- data/lib/generators/easy_admin/active_record_generator.rb +10 -0
- data/lib/generators/easy_admin/templates/create_outbound_requests.rb +18 -0
- data/test/dummy/app/controllers/admin/base_controller.rb +4 -0
- data/test/dummy/app/views/admin/welcome/index.html.erb +4 -1
- data/test/dummy/config/application.rb +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20121220022003_create_outbound_requests.rb +15 -0
- data/test/dummy/db/schema.rb +13 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +6412 -461
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/{C59/8C0/sprockets%2F2e45846506bfb54899651c20ff106384 → D0F/E70/sprockets%2Fbf4f18084af3243b43a5908cdae69166} +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/{CFE/770/sprockets%2Fb10582c06d2124dc13bacf089ba28588 → D4A/BB0/sprockets%2F34084ccfce0481c4263c0c2105acabb1} +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/{CA3/430/sprockets%2F8435b3b79289bd6b024f52c640320d1a → D96/B60/sprockets%2Ff0ba0257c64a22a49d8fa0fbc2a97f66} +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/{DDD/730/sprockets%2F6f588f81892fdea1a6ffad7405dacb47 → E54/480/sprockets%2Fe1da3d29f8a7fbee0d64b62c0ad7afa4} +0 -0
- data/test/dummy/tmp/restart.txt +0 -0
- metadata +36 -45
- data/lib/tasks/easy_admin_tasks.rake +0 -4
- data/test/dummy/log/test.log +0 -205
- data/test/dummy/tmp/cache/assets/C33/4C0/sprockets%2Fc4839b48061e4985b0961597ec802366 +0 -0
- data/test/dummy/tmp/cache/assets/C57/5F0/sprockets%2F3688375383e6e700ba1b68f06235734f +0 -0
- data/test/dummy/tmp/cache/assets/C61/730/sprockets%2F9397e1a672ad1e5353a77488305d5488 +0 -0
- data/test/dummy/tmp/cache/assets/D33/A80/sprockets%2Fc4a0e88dc4684c0073811473ed0bfb3b +0 -0
- data/test/dummy/tmp/cache/assets/D6E/AA0/sprockets%2Feff88475222e5aad1a7324ef9d6135aa +0 -0
- data/test/dummy/tmp/cache/assets/D82/170/sprockets%2Fd81e75b9c7729487caaa875e6eeb60f1 +0 -0
- data/test/dummy/tmp/cache/assets/E2D/CF0/sprockets%2Fccdfa721fbfe009dfa5da7801e8c64d7 +0 -0
- data/test/dummy/tmp/cache/assets/E4F/F40/sprockets%2F0ed4c0b964c38da5a08ebcaf2da3fd7a +0 -0
- data/test/dummy/tmp/pids/server.pid +0 -1
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# EasyAdmin
|
2
2
|
|
3
3
|
A Rails engine containing common admin maintenance screens.
|
4
|
-
Currently contains Delayed::Job maintenance screens
|
4
|
+
Currently contains Delayed::Job and Outbound Request maintenance screens
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -19,18 +19,20 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
|
22
|
+
The gem contains a dummy rails apps (under test/dummy) which you can use to test or extend the functionality (contains no styles!).
|
23
23
|
|
24
|
-
|
24
|
+
To use it in your Rails app, all you need is a Admin::BaseController (which the EasyAdmin controllers will extend). Define any authentication, layout and before_filter logic in there.
|
25
|
+
|
26
|
+
### Delayed::Jobs
|
25
27
|
To manage Delayed::Jobs, you need to define a method in your Admin::BaseController called authorize_jobs which will control access to the JobsController.
|
26
28
|
|
27
29
|
class Admin::BaseController < ApplicationController
|
28
|
-
layout 'admin'
|
30
|
+
layout 'admin'
|
29
31
|
|
30
32
|
private
|
31
|
-
|
33
|
+
|
32
34
|
def authorize_jobs
|
33
|
-
@current_user.admin?
|
35
|
+
redirect_to root_path unless @current_user.admin?
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
@@ -41,6 +43,48 @@ You will get the following routes:
|
|
41
43
|
admin_job GET /admin/jobs/:id(.:format) admin/jobs#show
|
42
44
|
DELETE /admin/jobs/:id(.:format) admin/jobs#destroy
|
43
45
|
|
46
|
+
### Outbound Requests
|
47
|
+
#### Setup
|
48
|
+
To manage OutboundRequests you need to define a method in your Admin::BaseController called authorize_outbound_requests which will controll access to the OutboundRequestsController.
|
49
|
+
|
50
|
+
class Admin::BaseController < ApplicationController
|
51
|
+
layout 'admin'
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def authorize_outbound_requests
|
56
|
+
redirect_to root_path unless @current_user.admin?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
You need to run this for generating the outbound_request create table migration:
|
61
|
+
|
62
|
+
$ rails g easy_admin:active_record
|
63
|
+
|
64
|
+
You also need to define the outbound services as a hash constant. Put this in an EasyAdmin module in application.rb.
|
65
|
+
|
66
|
+
module ::EasyAdmin
|
67
|
+
OUTBOUND_SERVICES = {webhook: 'Webhook', sailthru: 'Sailthru'}
|
68
|
+
end
|
69
|
+
|
70
|
+
You will get the following routes:
|
71
|
+
|
72
|
+
admin_outbound_requests GET /admin/outbound_requests(.:format) admin/outbound_requests#index
|
73
|
+
admin_outbound_request GET /admin/outbound_requests/:id(.:format) admin/outbound_requests#show
|
74
|
+
|
75
|
+
You will also get a rake task to delete old outbound requests. `age` is counted in days. Default age = 2:
|
76
|
+
|
77
|
+
rake requests:clean[age]
|
78
|
+
|
79
|
+
#### Methods
|
80
|
+
If you want to get the request elapse time, you can call `elapsed_time`:
|
81
|
+
|
82
|
+
outbound_request = OutboundRequest.create(service: :twitter, identifier: 'abletech', action: :dm)
|
83
|
+
# do request here
|
84
|
+
outbound_request.update_attribute(:response_code, response.code)
|
85
|
+
|
86
|
+
outbound_request.elapsed_time
|
87
|
+
|
44
88
|
## Contributing
|
45
89
|
|
46
90
|
1. Fork it
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Admin::OutboundRequestsController < Admin::BaseController
|
2
|
+
before_filter :authorize_outbound_requests
|
3
|
+
|
4
|
+
def index
|
5
|
+
@outbound_requests = OutboundRequest.search(params)
|
6
|
+
@services = EasyAdmin::OUTBOUND_SERVICES.invert
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
@outbound_request = OutboundRequest.find(params[:id])
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: outbound_requests
|
4
|
+
#
|
5
|
+
# id :integer not null, primary key
|
6
|
+
# service :string(255)
|
7
|
+
# action :string(255)
|
8
|
+
# identifier :string(255)
|
9
|
+
# params :text
|
10
|
+
# response_code :string(255)
|
11
|
+
# response_body :text
|
12
|
+
# error :text
|
13
|
+
# created_at :datetime not null
|
14
|
+
# updated_at :datetime not null
|
15
|
+
#
|
16
|
+
|
17
|
+
class OutboundRequest < ActiveRecord::Base
|
18
|
+
serialize :params
|
19
|
+
serialize :response_body
|
20
|
+
|
21
|
+
attr_accessible :service, :action, :identifier, :params, :response_code, :response_body, :error
|
22
|
+
|
23
|
+
self.per_page = 50
|
24
|
+
|
25
|
+
scope :partial_search, lambda { |column, query|
|
26
|
+
where("lower(#{column}) LIKE lower(?)", "%#{query}%")
|
27
|
+
}
|
28
|
+
|
29
|
+
def self.search(params)
|
30
|
+
identifier = params[:identifier]
|
31
|
+
service = params[:service]
|
32
|
+
action = params[:request_action]
|
33
|
+
|
34
|
+
requests = self.order('created_at desc')
|
35
|
+
requests = requests.partial_search(:identifier, identifier) if identifier.present?
|
36
|
+
requests = requests.where(service: service) if service.present?
|
37
|
+
requests = requests.where(action: action) if action.present?
|
38
|
+
requests = requests.page(params[:page])
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.delete_requests_older_than(age)
|
42
|
+
self.where('created_at < ?', (Time.now - age)).delete_all
|
43
|
+
end
|
44
|
+
|
45
|
+
def elapsed_time
|
46
|
+
updated_at - created_at
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<h2>Outbound Requests</h2>
|
2
|
+
|
3
|
+
<%= form_tag admin_outbound_requests_path, :method => :get do %>
|
4
|
+
<dl class="field">
|
5
|
+
<dt><%= label_tag :service %></dt>
|
6
|
+
<dd><%= select_tag :service, options_for_select(@services, params[:service]), include_blank: true %></dd>
|
7
|
+
</dl>
|
8
|
+
<dl class="field">
|
9
|
+
<dt><%= label_tag :identifier %></dt>
|
10
|
+
<dd>
|
11
|
+
<%= text_field_tag :identifier, params[:identifier] %>
|
12
|
+
<span class="help">Performs a partial search</span></dd>
|
13
|
+
</dl>
|
14
|
+
<dl class="field">
|
15
|
+
<dt><%= label_tag :request_action, 'Action' %></dt>
|
16
|
+
<dd><%= text_field_tag :request_action, params[:request_action] %></dd>
|
17
|
+
</dl>
|
18
|
+
<div class="buttons">
|
19
|
+
<%= submit_tag "Filter", :class => 'form-submit' %>
|
20
|
+
</div>
|
21
|
+
<% end %>
|
22
|
+
<br/>
|
23
|
+
<%= render 'pagination', rows: @outbound_requests, model: "#{params[:service] || 'Outbound'} request" unless @outbound_requests.empty? %>
|
24
|
+
<br>
|
25
|
+
<div class="standard">
|
26
|
+
<table class="sortable">
|
27
|
+
<% if @outbound_requests.empty? %>
|
28
|
+
<tr>
|
29
|
+
<td colspan='5'>No requests found</td>
|
30
|
+
</tr>
|
31
|
+
<% else %>
|
32
|
+
<tr>
|
33
|
+
<th class="sorted">Service</th>
|
34
|
+
<th class="sorted">Action</th>
|
35
|
+
<th class="sorted">Identifier</th>
|
36
|
+
<th class="sorted">Response Code</th>
|
37
|
+
<th class="sorted">Created At</th>
|
38
|
+
</tr>
|
39
|
+
<% @outbound_requests.each do |request| %>
|
40
|
+
<tr>
|
41
|
+
<td><%= EasyAdmin::OUTBOUND_SERVICES[request.service.to_sym] %>
|
42
|
+
<td><%= link_to request.action, admin_outbound_request_path(request) %></td>
|
43
|
+
<td><%= request.identifier %></td>
|
44
|
+
<td><%= request.response_code %></td>
|
45
|
+
<td><%= request.created_at.to_s %></td>
|
46
|
+
</tr>
|
47
|
+
<% end %>
|
48
|
+
<% end %>
|
49
|
+
</table>
|
50
|
+
</div>
|
51
|
+
<%= render 'pagination', rows: @outbound_requests, model: "#{params[:service] || 'Outbound'} request" unless @outbound_requests.empty? %>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<div class="clear options">
|
2
|
+
<%= link_to "« Back".html_safe, admin_outbound_requests_path %>
|
3
|
+
</div>
|
4
|
+
|
5
|
+
<h2><%= EasyAdmin::OUTBOUND_SERVICES[@outbound_request.service.to_sym] %> Request <%= @outbound_request.id %></h2>
|
6
|
+
|
7
|
+
<table class="details">
|
8
|
+
<tr>
|
9
|
+
<th>Action</th>
|
10
|
+
<td><%= @outbound_request.action %></td>
|
11
|
+
</tr>
|
12
|
+
<tr>
|
13
|
+
<th>Identifier</th>
|
14
|
+
<td><%= @outbound_request.identifier %></td>
|
15
|
+
</tr>
|
16
|
+
<tr>
|
17
|
+
<th>Created At</th>
|
18
|
+
<td><%= @outbound_request.created_at.to_s(:display) %></td>
|
19
|
+
</tr>
|
20
|
+
<tr>
|
21
|
+
<th>Updated At</th>
|
22
|
+
<td><%= @outbound_request.updated_at.to_s(:display) %></td>
|
23
|
+
</tr>
|
24
|
+
</table>
|
25
|
+
|
26
|
+
<h3>Request</h3>
|
27
|
+
<table class="details">
|
28
|
+
<tr>
|
29
|
+
<th>Request Params</th>
|
30
|
+
<td><%= @outbound_request.params.to_s.gsub(",", "<br>").html_safe %></td>
|
31
|
+
</tr>
|
32
|
+
<tr>
|
33
|
+
<th>Elapsed Time</th>
|
34
|
+
<td><%= @outbound_request.elapsed_time.round(2) %> seconds</td>
|
35
|
+
</tr>
|
36
|
+
</table>
|
37
|
+
|
38
|
+
<h3>Response</h3>
|
39
|
+
<table class="details">
|
40
|
+
<tr>
|
41
|
+
<th>Response Code</th>
|
42
|
+
<td><%= @outbound_request.response_code %></td>
|
43
|
+
</tr>
|
44
|
+
<tr>
|
45
|
+
<th>Response Body</th>
|
46
|
+
<td><%= @outbound_request.response_body %></td>
|
47
|
+
</tr>
|
48
|
+
<% unless @outbound_request.error.blank? %>
|
49
|
+
<tr>
|
50
|
+
<th>Error</th>
|
51
|
+
<td><%= @outbound_request.error %></td>
|
52
|
+
</tr>
|
53
|
+
<% end %>
|
54
|
+
</table>
|
55
|
+
|
56
|
+
<div class="clear options">
|
57
|
+
<%= link_to "« Back".html_safe, admin_outbound_requests_path %>
|
58
|
+
</div>
|
data/config/routes.rb
CHANGED
data/lib/easy_admin/engine.rb
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
module EasyAdmin
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
+
require 'will_paginate'
|
4
|
+
end
|
5
|
+
|
6
|
+
class Railtie < ::Rails::Railtie
|
7
|
+
rake_tasks do
|
8
|
+
namespace :requests do
|
9
|
+
desc "Delete old outbound requests, DEFAULT=2 (days)."
|
10
|
+
task :clean, [:age] => :environment do |task, params|
|
11
|
+
params.with_defaults(age: 2)
|
12
|
+
outbound_request_count = OutboundRequest.delete_requests_older_than(params[:age].to_i.days)
|
13
|
+
puts "Deleted #{outbound_request_count} old Outbound Requests"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
3
17
|
end
|
4
18
|
end
|
data/lib/easy_admin/version.rb
CHANGED
data/lib/easy_admin.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'easy_admin/engine'
|
1
|
+
require 'easy_admin/engine'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module EasyAdmin
|
2
|
+
class ActiveRecordGenerator < Rails::Generators::Base
|
3
|
+
desc "Generates the migration for outbound_requests table"
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def outbound_request_migration
|
7
|
+
copy_file "create_outbound_requests.rb", "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_outbound_requests.rb"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateOutboundRequests < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :outbound_requests do |t|
|
4
|
+
t.string :service
|
5
|
+
t.string :action
|
6
|
+
t.string :identifier
|
7
|
+
t.text :params
|
8
|
+
t.string :response_code
|
9
|
+
t.text :response_body
|
10
|
+
t.text :error
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :outbound_requests, :service
|
15
|
+
add_index :outbound_requests, [:service, :action]
|
16
|
+
add_index :outbound_requests, [:service, :identifier]
|
17
|
+
end
|
18
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
<h1>Welcome to the dummy app</h1>
|
2
2
|
<h2>Use this to test changes to the EasyAdmin gem</h1>
|
3
3
|
|
4
|
-
|
4
|
+
<ul>
|
5
|
+
<li><%= link_to 'Delayed Jobs', admin_jobs_path %></li>
|
6
|
+
<li><%= link_to 'Outbound Requests', admin_outbound_requests_path %></li>
|
7
|
+
</ul>
|
@@ -55,5 +55,9 @@ module Dummy
|
|
55
55
|
# Version of your assets, change this if you want to expire all your assets
|
56
56
|
config.assets.version = '1.0'
|
57
57
|
end
|
58
|
+
|
59
|
+
module ::EasyAdmin
|
60
|
+
OUTBOUND_SERVICES = {tracking: 'Tracking API', sailthru: 'Sailthru API', twitter: 'Twitter API', webhook: 'Webhook', sms: 'SMS Global API'}
|
61
|
+
end
|
58
62
|
end
|
59
63
|
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateOutboundRequests < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :outbound_requests do |t|
|
4
|
+
t.string :service
|
5
|
+
t.string :action
|
6
|
+
t.string :identifier
|
7
|
+
t.text :params
|
8
|
+
t.string :response_code
|
9
|
+
t.text :response_body
|
10
|
+
t.text :error
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20121220022003) do
|
15
15
|
|
16
16
|
create_table "delayed_jobs", :force => true do |t|
|
17
17
|
t.integer "priority", :default => 0
|
@@ -29,4 +29,16 @@ ActiveRecord::Schema.define(:version => 20121114025434) do
|
|
29
29
|
|
30
30
|
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
|
31
31
|
|
32
|
+
create_table "outbound_requests", :force => true do |t|
|
33
|
+
t.string "service"
|
34
|
+
t.string "action"
|
35
|
+
t.string "identifier"
|
36
|
+
t.text "params"
|
37
|
+
t.string "response_code"
|
38
|
+
t.text "response_body"
|
39
|
+
t.text "error"
|
40
|
+
t.datetime "created_at", :null => false
|
41
|
+
t.datetime "updated_at", :null => false
|
42
|
+
end
|
43
|
+
|
32
44
|
end
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|