daily 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,28 @@ class DailyReportsController < InheritedResources::Base
22
22
  redirect_to daily_table_daily_report_path(@daily_report.table, @daily_report)
23
23
  end
24
24
 
25
+ def destroy
26
+ destroy! { daily_table_path(@daily_report.table) }
27
+ end
28
+
29
+ def archiveit
30
+ if @daily_report.archive
31
+ flash[:notice] = "Report has been archived."
32
+ else
33
+ flash[:alert] = "Report has not been archived."
34
+ end
35
+ redirect_to daily_table_daily_report_path(@daily_report.table, @daily_report)
36
+ end
37
+
38
+ def unarchiveit
39
+ if @daily_report.unarchive
40
+ flash[:notice] = "Report has been unarchived."
41
+ else
42
+ flash[:alert] = "Report has not been unarchived."
43
+ end
44
+ redirect_to daily_table_daily_report_path(@daily_report.table, @daily_report)
45
+ end
46
+
25
47
  protected
26
48
 
27
49
  # methods to make declarative_authorization allow optional table
@@ -21,4 +21,26 @@ class DailyTablesController < InheritedResources::Base
21
21
  end
22
22
  end
23
23
 
24
+ def archiveit
25
+ if @daily_table.archive
26
+ flash[:notice] = "Table has been archived."
27
+ else
28
+ flash[:alert] = "Table has not been archived."
29
+ end
30
+ redirect_to @daily_table
31
+ end
32
+
33
+ def unarchiveit
34
+ if @daily_table.unarchive
35
+ flash[:notice] = "Table has been unarchived."
36
+ else
37
+ flash[:alert] = "Table has not been unarchived."
38
+ end
39
+ redirect_to @daily_table
40
+ end
41
+
42
+ def destroy
43
+ destroy! { user_root_path }
44
+ end
45
+
24
46
  end
@@ -0,0 +1,56 @@
1
+ module Ruport
2
+ class Formatter::Png < Formatter
3
+ renders :png, :for => [Ruport::Controller::Table]
4
+
5
+ CHART_TYPES = %w{line line_xy scatter bar venn pie pie_3d sparkline meter}
6
+
7
+ save_as_binary_file
8
+
9
+ def google_hash
10
+ out = options.to_hash.symbolize_keys
11
+ columns = out.delete(:columns) || data.column_names
12
+
13
+ if out[:legend] == false or skip_legend?
14
+ out.delete(:legend)
15
+ else
16
+ out[:legend] ||= columns
17
+ end
18
+
19
+ unless out[:data]
20
+ out[:data] = []
21
+ columns.each_with_index do |col, i|
22
+ out[:data][i] ||= []
23
+ end
24
+ data.each_with_index do |row, i|
25
+ columns.each_with_index do |col, i|
26
+ out[:data][i] << row[col]
27
+ end
28
+ end
29
+ end
30
+
31
+ out
32
+ end
33
+
34
+ def skip_legend?
35
+ google_type == "sparkline"
36
+ end
37
+
38
+ def google_type
39
+ options.chart_type.try(:to_s).try(:downcase) || CHART_TYPES.first
40
+ end
41
+
42
+ def google_url
43
+ url = Gchart.send(google_type, google_hash)
44
+ unwise = %w({ } | \ ^ [ ] `)
45
+ unwise.each { |c| url.gsub!(c, "%#{c[0].to_s(16).upcase}") }
46
+ url.gsub!(/\s/, "%20")
47
+ url
48
+ end
49
+
50
+ def finalize_table
51
+ require 'open-uri'
52
+ output << open(google_url).read
53
+ end
54
+
55
+ end
56
+ end
@@ -10,6 +10,7 @@ class GenerateReportJob < Struct.new(:report_id, :requeue)
10
10
 
11
11
  def perform
12
12
  return if report.nil?
13
+ return if report.archived?
13
14
  report.generate!
14
15
  report.queue_next! if requeue
15
16
  end
@@ -16,7 +16,10 @@ class DailyReport < ActiveRecord::Base
16
16
  before_validation :filename_extension_update
17
17
 
18
18
  after_save :ensure_job
19
- after_save :queue_now!, :if => :filename_changed?
19
+ after_save :queue_now!, :if => :queue_job_now?
20
+
21
+ after_save :delete_file!, :if => :archived?
22
+ after_destroy :delete_file!
20
23
 
21
24
  def self.formatters
22
25
  Ruport::Controller::Table.formats.keys
@@ -43,6 +46,11 @@ class DailyReport < ActiveRecord::Base
43
46
  File.file?(localfile)
44
47
  end
45
48
 
49
+ def delete_file!
50
+ File.delete(localfile) if File.file?(localfile)
51
+ true
52
+ end
53
+
46
54
  def generate!
47
55
  Dir.mkdir(localdir) unless File.directory?(localdir)
48
56
  touch(:generate_started_at)
@@ -80,7 +88,27 @@ class DailyReport < ActiveRecord::Base
80
88
  jobs.by_priority.first
81
89
  end
82
90
 
91
+ def archive
92
+ self.archived = true
93
+ save ? self : nil
94
+ end
95
+
96
+ def archive!
97
+ self.archived = true
98
+ save!
99
+ end
100
+
101
+ def unarchive
102
+ self.archived = false
103
+ save ? self : nil
104
+ end
105
+
83
106
  protected
107
+
108
+ def queue_job_now?
109
+ return false if archived?
110
+ filename_changed? or archived_changed?
111
+ end
84
112
 
85
113
  def guid_append
86
114
  return "" if formatter.blank?
@@ -91,10 +119,8 @@ class DailyReport < ActiveRecord::Base
91
119
  Time.now + 1.hour
92
120
  end
93
121
 
94
- protected
95
-
96
122
  def ensure_job
97
- queue_next! if jobs.reload.size == 0
123
+ queue_next! if not archived? and jobs.reload.size == 0
98
124
  true
99
125
  end
100
126
 
@@ -2,7 +2,7 @@ class DailyTable < ActiveRecord::Base
2
2
  include SharedBehaviors
3
3
 
4
4
  belongs_to :user, :class_name => "DailyUser"
5
- has_many :reports, :class_name => "DailyReport", :foreign_key => "table_id"
5
+ has_many :reports, :class_name => "DailyReport", :foreign_key => "table_id", :dependent => :destroy
6
6
 
7
7
  # just easier with declarative auth to also have this one
8
8
  has_many :daily_reports, :foreign_key => "table_id"
@@ -54,7 +54,29 @@ class DailyTable < ActiveRecord::Base
54
54
  return "#{metric} (unknown)"
55
55
  end
56
56
  end
57
+
58
+ def archive
59
+ transaction do
60
+ self.archived = true
61
+ reports.each do |report|
62
+ report.archive!
63
+ end
64
+ save!
65
+ end
66
+ return self
67
+ rescue ActiveRecord::RecordInvalid
68
+ return nil
69
+ end
70
+
71
+ def unarchive
72
+ self.archived = false
73
+ save ? self : nil
74
+ end
57
75
 
76
+ def has_reports?
77
+ reports.size > 0
78
+ end
79
+
58
80
  protected
59
81
 
60
82
  def metric_valid
@@ -8,11 +8,15 @@
8
8
  <% end %>
9
9
 
10
10
  <h6>User: <%= "#{@daily_report.user.email}" %></h6>
11
+ <h6>State: <%= @daily_report.archived? ? "Archived" : "Active" %></h6>
11
12
  <h6>Running time: <%= report_time_run(@daily_report) %></h6>
12
13
  <h6>Last updated: <%= report_time_ago(@daily_report) %></h6>
13
14
  <h6>Next updated: <%= report_time_next(@daily_report) %></h6>
14
- <%= button_to "Queue Update Now", generate_daily_table_daily_report_path(@daily_report.table, @daily_report) if permitted_to? :generate, @daily_report %>
15
15
 
16
+ <%= button_to "Archive", archiveit_daily_table_daily_report_path(@daily_report.table, @daily_report) if permitted_to? :archiveit, @daily_report %>
17
+ <%= button_to "Unarchive", unarchiveit_daily_table_daily_report_path(@daily_report.table, @daily_report) if permitted_to? :unarchiveit, @daily_report %>
18
+ <%= button_to "Delete", daily_table_daily_report_path(@daily_report.table, @daily_report), :method => :delete if permitted_to? :destroy, @daily_report %>
19
+ <%= button_to "Queue Update Now", generate_daily_table_daily_report_path(@daily_report.table, @daily_report) if permitted_to? :generate, @daily_report %>
16
20
  <%= content_tag(:p, link_to("Edit", edit_daily_table_daily_report_path(@daily_report.table, @daily_report))) if permitted_to? :edit, @daily_report %>
17
21
 
18
22
  <%= formatter_display(@daily_report) %>
@@ -0,0 +1,21 @@
1
+ <% title "Archive: " + @daily_table.name %>
2
+
3
+ <%= content_tag(:p, link_to("Back to table", daily_table_path(@daily_table))) if permitted_to? :show, @daily_table %>
4
+ <p><strong>Archiving</strong> this table will archive all of the associated reports.</p>
5
+ <p>These reports will also have their respective files deleted and unavailable until unarchived.</p>
6
+
7
+ <% if permitted_to? :destroy, @daily_table %>
8
+ <p><strong>Deleting</strong> this daily will delete all of the associated reports and files.</p>
9
+ <% end %>
10
+
11
+ <% if @daily_table.reports.size == 0 %>
12
+ <h3>No reports based on this table.</h3>
13
+ <% else %>
14
+ <h3>Reports based on this table</h3>
15
+ <%= render "daily_reports/list", :list => @daily_table.reports %>
16
+ <% end %>
17
+
18
+ <hr/>
19
+
20
+ <%= button_to "Archive", archiveit_daily_table_path(@daily_table) if permitted_to? :archiveit, @daily_table %>
21
+ <%= button_to "Delete", daily_table_path(@daily_table), :method => :delete if permitted_to? :destroy, @daily_table %>
@@ -7,8 +7,13 @@
7
7
  <hr/>
8
8
 
9
9
  <h6>User: <%= "#{@daily_table.user.email}" %></h6>
10
+ <h6>State: <%= @daily_table.archived? ? "Archived" : "Active" %></h6>
10
11
  <h6>Type: <%= "#{@daily_table.metric_name}" %></h6>
11
12
  <h6>Running time: <%= table_time_run(@daily_table) %></h6>
13
+
14
+ <%= button_to "Delete", daily_table_path(@daily_table), :method => :delete if permitted_to? :destroy, @daily_table %>
15
+ <%= button_to "Unarchive", unarchiveit_daily_table_path(@daily_table) if permitted_to? :unarchiveit, @daily_table %>
16
+ <%= content_tag(:p, link_to("Archive", archive_daily_table_path(@daily_table))) if permitted_to? :archive, @daily_table %>
12
17
  <%= content_tag(:p, link_to("Edit", edit_daily_table_path(@daily_table))) if permitted_to? :edit, @daily_table %>
13
18
 
14
19
  <% if @test_html %>
@@ -11,8 +11,24 @@ authorization do
11
11
  if_attribute :user => is { user }
12
12
  end
13
13
 
14
- has_permission_on :daily_tables, :to => [:report] do
14
+ has_permission_on :daily_tables, :to => [:archive, :archiveit], :join_by => :and do
15
+ if_permitted_to :update
16
+ if_attribute :archived? => is_not { true }
17
+ end
18
+
19
+ has_permission_on :daily_tables, :to => [:unarchiveit], :join_by => :and do
20
+ if_permitted_to :update
21
+ if_attribute :archived? => is { true }
22
+ end
23
+
24
+ has_permission_on :daily_tables, :to => [:destroy], :join_by => :and do
25
+ if_permitted_to :update
26
+ if_attribute :has_reports? => is { false }
27
+ end
28
+
29
+ has_permission_on :daily_tables, :to => [:report], :join_by => :and do
15
30
  if_permitted_to :show
31
+ if_attribute :archived? => is_not { true }
16
32
  end
17
33
 
18
34
  has_permission_on :daily_reports, :to => [:create] do
@@ -23,8 +39,27 @@ authorization do
23
39
  if_attribute :user => is { user }
24
40
  end
25
41
 
26
- has_permission_on :daily_reports, :to => [:show, :generate] do
42
+ has_permission_on :daily_reports, :to => [:archive, :archiveit], :join_by => :and do
43
+ if_permitted_to :update
44
+ if_attribute :archived? => is_not { true }
45
+ end
46
+
47
+ has_permission_on :daily_reports, :to => [:unarchiveit], :join_by => :and do
48
+ if_permitted_to :update
49
+ if_attribute :archived? => is { true }
50
+ end
51
+
52
+ has_permission_on :daily_reports, :to => [:destroy], :join_by => :and do
53
+ if_permitted_to :update
54
+ end
55
+
56
+ has_permission_on :daily_reports, :to => [:show] do
57
+ if_permitted_to :update
58
+ end
59
+
60
+ has_permission_on :daily_reports, :to => [:generate], :join_by => :and do
27
61
  if_permitted_to :update
62
+ if_attribute :archived? => is_not { true }
28
63
  end
29
64
 
30
65
  has_permission_on :daily_users, :to => [:update, :account] do
@@ -24,8 +24,12 @@ en:
24
24
  notice: "Report was successfully created."
25
25
  update:
26
26
  notice: "Report was successfully updated."
27
+ destroy:
28
+ notice: "Report has been deleted."
27
29
  daily_tables:
28
30
  create:
29
31
  notice: "Table was successfully created."
30
32
  update:
31
- notice: "Table was successfully updated."
33
+ notice: "Table was successfully updated."
34
+ destroy:
35
+ notice: "Table has been deleted."
@@ -11,9 +11,16 @@ Rails.application.routes.draw do
11
11
  match 'home' => 'main#home', :as => :user_root
12
12
 
13
13
  resources :daily_tables, :path => "tables" do
14
+ member do
15
+ get :archive
16
+ post :archiveit
17
+ post :unarchiveit
18
+ end
14
19
  resources :daily_reports, :path => "reports" do
15
20
  member do
16
21
  post :generate
22
+ post :archiveit
23
+ post :unarchiveit
17
24
  end
18
25
  end
19
26
  end
Binary file
@@ -0,0 +1,11 @@
1
+ class AddArchivedToTables < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :daily_tables, :archived, :boolean, :default => false
4
+ add_column :daily_reports, :archived, :boolean, :defualt => false
5
+ end
6
+
7
+ def self.down
8
+ remove_column :daily_reports, :archived
9
+ remove_column :daily_tables, :archived
10
+ end
11
+ end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended to check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(:version => 20120111081745) do
13
+ ActiveRecord::Schema.define(:version => 20120117020222) do
14
14
 
15
15
  create_table "daily_reports", :force => true do |t|
16
16
  t.string "name"
@@ -25,6 +25,7 @@ ActiveRecord::Schema.define(:version => 20120111081745) do
25
25
  t.string "transform"
26
26
  t.text "transform_data"
27
27
  t.text "formatter_data"
28
+ t.boolean "archived"
28
29
  end
29
30
 
30
31
  create_table "daily_tables", :force => true do |t|
@@ -39,6 +40,7 @@ ActiveRecord::Schema.define(:version => 20120111081745) do
39
40
  t.text "column_names"
40
41
  t.string "transform"
41
42
  t.text "transform_data"
43
+ t.boolean "archived", :default => false
42
44
  end
43
45
 
44
46
  create_table "daily_users", :force => true do |t|
Binary file
@@ -1,3 +1,3 @@
1
1
  module Daily
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daily
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Leonard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-13 00:00:00 -08:00
18
+ date: 2012-01-18 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -364,6 +364,7 @@ files:
364
364
  - app/controllers/main_controller.rb
365
365
  - app/formatters/html_formatter.rb
366
366
  - app/formatters/json_formatter.rb
367
+ - app/formatters/png_formatter.rb
367
368
  - app/helpers/application_helper.rb
368
369
  - app/jobs/generate_report_job.rb
369
370
  - app/metrics/metric.rb
@@ -382,6 +383,7 @@ files:
382
383
  - app/views/daily_reports/show.erb
383
384
  - app/views/daily_tables/_form.erb
384
385
  - app/views/daily_tables/_list.erb
386
+ - app/views/daily_tables/archive.erb
385
387
  - app/views/daily_tables/edit.erb
386
388
  - app/views/daily_tables/index.erb
387
389
  - app/views/daily_tables/new.erb
@@ -436,6 +438,7 @@ files:
436
438
  - db/migrate/20120110075743_add_queue_to_delayed_jobs.rb
437
439
  - db/migrate/20120111054115_create_table_metrics.rb
438
440
  - db/migrate/20120111081745_namespace_models.rb
441
+ - db/migrate/20120117020222_add_archived_to_tables.rb
439
442
  - db/schema.rb
440
443
  - db/seeds.rb
441
444
  - db/test.sqlite3