activeadmin_jobs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +7 -0
  6. data/Gemfile +18 -0
  7. data/Gemfile.lock +280 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.md +272 -0
  10. data/Rakefile +21 -0
  11. data/activeadmin_jobs.gemspec +35 -0
  12. data/app/admin/jobs.rb +30 -0
  13. data/app/assets/images/activeadmin_jobs/.keep +0 -0
  14. data/app/assets/javascripts/activeadmin_jobs/application.js +13 -0
  15. data/app/assets/javascripts/activeadmin_jobs/base.js +3 -0
  16. data/app/assets/javascripts/activeadmin_jobs/growl_setup.js.erb +115 -0
  17. data/app/assets/stylesheets/activeadmin_jobs/application.css +15 -0
  18. data/app/assets/stylesheets/activeadmin_jobs/base.scss +19 -0
  19. data/app/controllers/activeadmin_jobs/application_controller.rb +4 -0
  20. data/app/helpers/activeadmin_jobs/application_helper.rb +4 -0
  21. data/app/views/layouts/activeadmin_jobs/application.html.erb +14 -0
  22. data/bin/rails +12 -0
  23. data/config/locales/activeadmin_jobs.en.yml +24 -0
  24. data/config/locales/activeadmin_jobs.es.yml +24 -0
  25. data/config/routes.rb +2 -0
  26. data/docs/images/error-notification.png +0 -0
  27. data/docs/images/error-view.png +0 -0
  28. data/docs/images/import-form.png +0 -0
  29. data/docs/images/jobs-example.gif +0 -0
  30. data/docs/images/jobs-list.png +0 -0
  31. data/docs/images/success-notification.png +0 -0
  32. data/docs/images/success-view.png +0 -0
  33. data/lib/activeadmin_jobs.rb +8 -0
  34. data/lib/activeadmin_jobs/activeadmin_config.rb +31 -0
  35. data/lib/activeadmin_jobs/engine.rb +16 -0
  36. data/lib/activeadmin_jobs/i18n_dictionary.rb +7 -0
  37. data/lib/activeadmin_jobs/job_extensions.rb +11 -0
  38. data/lib/activeadmin_jobs/job_result_renderer.rb +27 -0
  39. data/lib/activeadmin_jobs/version.rb +3 -0
  40. data/lib/generators/activeadmin_jobs/install/USAGE +5 -0
  41. data/lib/generators/activeadmin_jobs/install/install_generator.rb +18 -0
  42. data/lib/tasks/activeadmin_jobs_tasks.rake +4 -0
  43. metadata +331 -0
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ActiveadminJobs'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,35 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "activeadmin_jobs/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "activeadmin_jobs"
9
+ s.version = ActiveadminJobs::VERSION
10
+ s.authors = ["Platanus", "Emilio Blanco", "Leandro Segovia"]
11
+ s.email = ["rubygems@platan.us", "emilioeduardob@gmail.com", "ldlsegovia@gmail.com"]
12
+ s.homepage = "https://github.com/platanus/activeadmin_jobs"
13
+ s.summary = "Gem that allows you to play nice with Active Job in Active Admin providing feedback"
14
+ s.description = "It's a Rails engine that allows you to play nice with Active Job in Active Admin providing user feedback"
15
+ s.license = "MIT"
16
+
17
+ s.files = `git ls-files`.split($/).reject { |fn| fn.start_with? "spec" }
18
+
19
+ s.add_dependency "rails", "~> 4.2", ">= 4.2.0"
20
+ s.add_dependency "job_notifier", "~> 1.1", ">= 1.1.1"
21
+ s.add_dependency "devise", "~> 3.5", ">= 3.5.0"
22
+ s.add_dependency "activeadmin", "~> 1.0.0.pre2"
23
+ s.add_dependency "activeadmin_addons", "~> 0.9", ">= 0.9.2"
24
+ s.add_dependency "rails-assets-growl", "~> 1.3", ">= 1.3.1"
25
+
26
+ s.add_development_dependency "pry-rails"
27
+ s.add_development_dependency "sqlite3"
28
+ s.add_development_dependency "rspec-rails", "~> 3.4.0"
29
+ s.add_development_dependency "capybara"
30
+ s.add_development_dependency "selenium-webdriver"
31
+ s.add_development_dependency "database_cleaner"
32
+ s.add_development_dependency "daemons"
33
+ s.add_development_dependency "delayed_job_active_record"
34
+ s.add_development_dependency "quiet_assets"
35
+ end
data/app/admin/jobs.rb ADDED
@@ -0,0 +1,30 @@
1
+ ActiveAdmin.register JobNotifier::Job, as: "Job" do
2
+ actions :index, :show
3
+
4
+ filter :status
5
+ filter :notified
6
+ filter :created_at
7
+
8
+ index do
9
+ id_column
10
+ tag_column :status
11
+ column :description
12
+ bool_column :notified
13
+ column :created_at
14
+ actions
15
+ end
16
+
17
+ show do
18
+ attributes_table do
19
+ row :id
20
+ tag_row :status
21
+ row :description
22
+ bool_row :notified
23
+ row :created_at
24
+ end
25
+
26
+ panel JobNotifier::Job.human_attribute_name(:result) do
27
+ ActiveadminJobs::JobResultRenderer.new(self).render
28
+ end unless resource.result.blank?
29
+ end
30
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,3 @@
1
+ //= require growl
2
+ //= require job_notifier/notifier
3
+ //= require ./growl_setup
@@ -0,0 +1,115 @@
1
+ JobNotifier.translations = <%= I18nDictionary.translations.to_json %>;
2
+ JobNotifier.jobsUrl = "<%= AdminHelpers.jobs_url %>";
3
+ console.info('translations', JobNotifier.translations);
4
+
5
+ JobNotifier.onNotify = function(result) {
6
+ DEFAULT_MESSAGES = {
7
+ finished: {
8
+ title: 'Completed Job',
9
+ one: '1 job was successfully completed!',
10
+ other: 'jobs were successfully completed!'
11
+ },
12
+ failed: {
13
+ title: 'Failed Job',
14
+ one: '1 job was completed, but it contains errors...',
15
+ other: 'jobs were completed, but they contains errors...'
16
+ }
17
+ };
18
+
19
+ function findTranslation(jobClass, status, key) {
20
+ try {
21
+ return JobNotifier.translations[jobClass][status][key];
22
+ } catch(err) {
23
+ console.info('Translation not found. Using default...', jobClass, status, key);
24
+ }
25
+
26
+ return DEFAULT_MESSAGES[status][key];
27
+ }
28
+
29
+ function camelToDash(str) {
30
+ return str.replace(/\W+/g, '_').replace(/([a-z\d])([A-Z])/g, '$1_$2').toLowerCase();
31
+ }
32
+
33
+ function prepareMessage(job, count) {
34
+ var jobClass = camelToDash(job.job_class);
35
+ var jobsUrl = JobNotifier.jobsUrl;
36
+ var msg = '';
37
+
38
+ if(count == 1) {
39
+ jobsUrl += '/' + job.id;
40
+ msg = findTranslation(jobClass, job.status, 'one');
41
+ } else {
42
+ msg = count + ' ' + findTranslation(jobClass, job.status, 'other');
43
+ }
44
+
45
+ var link = '<a href="' + jobsUrl + '">' + msg + '</a>';
46
+
47
+ return {
48
+ title: findTranslation(jobClass, job.status, 'title'),
49
+ message: link,
50
+ duration: 6000
51
+ };
52
+ }
53
+
54
+ function showPopUp(job, count) {
55
+ var msg = prepareMessage(job, count);
56
+
57
+ switch(job.status) {
58
+ case 'finished':
59
+ $.growl.notice(msg);
60
+ break;
61
+ case 'failed':
62
+ $.growl.error(msg);
63
+ break;
64
+ default:
65
+ console.error('Invalid job status given', job.status);
66
+ }
67
+ }
68
+
69
+ function groupJobsByClass(jobs) {
70
+ var groupedJobs = {};
71
+
72
+ for(i = 0; i < jobs.length; i++) {
73
+ var job = jobs[i];
74
+
75
+ if(job.status == 'pending') {
76
+ continue;
77
+ }
78
+
79
+ var jobClass = camelToDash(job.job_class);
80
+
81
+ if(!groupedJobs[jobClass]) {
82
+ groupedJobs[jobClass] = {};
83
+ }
84
+
85
+ if(!groupedJobs[jobClass][job.status]) {
86
+ groupedJobs[jobClass][job.status] = [];
87
+ }
88
+
89
+ groupedJobs[jobClass][job.status].push(job);
90
+ }
91
+
92
+ return groupedJobs;
93
+ }
94
+
95
+ function showMsg(jobs) {
96
+ if(jobs.length === 0) {
97
+ return;
98
+ }
99
+
100
+ var groupedJobs = groupJobsByClass(jobs);
101
+
102
+ for(var jobClass in groupedJobs) {
103
+ if(groupedJobs.hasOwnProperty(jobClass)) {
104
+ for(var status in groupedJobs[jobClass]) {
105
+ if(groupedJobs[jobClass].hasOwnProperty(status)) {
106
+ jobs = groupedJobs[jobClass][status];
107
+ showPopUp(jobs[0], jobs.length);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ }
113
+
114
+ showMsg(result);
115
+ };
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,19 @@
1
+ @import "growl";
2
+
3
+ $pending-color: #e67e22;
4
+ $failed-color: #c0392b;
5
+ $finished-color: #27ae60;
6
+
7
+ .status_tag {
8
+ &.pending { background: $pending-color; }
9
+ &.failed { background: $failed-color; }
10
+ &.finished { background: $finished-color; }
11
+ }
12
+
13
+ .growl {
14
+ a {
15
+ &:link, &:visited, &:hover, &:active {
16
+ color: #FFFFFF;
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,4 @@
1
+ module ActiveadminJobs
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveadminJobs
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>ActiveadminJobs</title>
5
+ <%= stylesheet_link_tag "activeadmin_jobs/application", media: "all" %>
6
+ <%= javascript_include_tag "activeadmin_jobs/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/bin/rails ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/activeadmin_jobs/engine', __FILE__)
6
+
7
+ # Set up gems listed in the Gemfile.
8
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10
+
11
+ require 'rails/all'
12
+ require 'rails/engine/commands'
@@ -0,0 +1,24 @@
1
+ en:
2
+ enumerize:
3
+ job_notifier/job:
4
+ status:
5
+ failed: Failed
6
+ finished: Finished
7
+ pending: Pending
8
+ activerecord:
9
+ models:
10
+ job:
11
+ one: Job
12
+ other: Jobs
13
+ attributes:
14
+ job_notifier/job:
15
+ id: ID
16
+ identifier: Identifier
17
+ job_id: Job ID
18
+ job_class: Job Type
19
+ status: Status
20
+ result: Result
21
+ description: Description
22
+ notified: Notified?
23
+ created_at: Created At
24
+ updated_at: Updated At
@@ -0,0 +1,24 @@
1
+ es:
2
+ enumerize:
3
+ job_notifier/job:
4
+ status:
5
+ failed: Con Errores
6
+ finished: Completo
7
+ pending: Pendiente
8
+ activerecord:
9
+ models:
10
+ job:
11
+ one: Proceso
12
+ other: Procesos
13
+ attributes:
14
+ job_notifier/job:
15
+ id: ID
16
+ identifier: Identificador
17
+ job_id: ID Proceso
18
+ job_class: Tipo
19
+ status: Estado
20
+ result: Resultado
21
+ description: Descripción
22
+ notified: Notificado?
23
+ created_at: Fecha de Creación
24
+ updated_at: Fecha de Actualización
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ ActiveadminJobs::Engine.routes.draw do
2
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,8 @@
1
+ require "job_notifier"
2
+ require "devise"
3
+ require "activeadmin"
4
+ require "activeadmin_addons"
5
+ require "activeadmin_jobs/engine"
6
+
7
+ module ActiveadminJobs
8
+ end
@@ -0,0 +1,31 @@
1
+ module AdminHelpers
2
+ def self.jobs_url
3
+ url = ["/"]
4
+
5
+ if ActiveAdmin.application.default_namespace.present?
6
+ url << "#{ActiveAdmin.application.default_namespace}/"
7
+ end
8
+
9
+ url << "jobs"
10
+ url.join("")
11
+ end
12
+ end
13
+
14
+ ActiveAdmin.setup do |config|
15
+ config.load_paths += [File.join(ActiveadminJobs::Engine.root, "app", "admin")]
16
+ end
17
+
18
+ class ActiveAdmin::Views::Pages::Base
19
+ alias_method :original_add_classes_to_body, :add_classes_to_body
20
+
21
+ def add_classes_to_body
22
+ original_add_classes_to_body
23
+ current_user_method = ActiveAdmin.application.current_user_method
24
+
25
+ if current_user_method
26
+ admins_job_identifier = send(current_user_method).job_identifier
27
+ @body.set_attribute "data-identifier", admins_job_identifier
28
+ @body.set_attribute "data-root-url", "/"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ module ActiveadminJobs
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ActiveadminJobs
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, fixture: false
7
+ end
8
+
9
+ initializer "initialize" do
10
+ require_relative "./i18n_dictionary"
11
+ require_relative "./job_result_renderer"
12
+ require_relative "./activeadmin_config"
13
+ require_relative "./job_extensions"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module I18nDictionary
2
+ def self.translations
3
+ I18n.backend.load_translations
4
+ translations = I18n.backend.send(:translations)
5
+ translations[I18n.locale][:activeadmin_jobs]
6
+ end
7
+ end