typus 1.0.0.pre → 1.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/Gemfile +0 -1
  2. data/Gemfile.lock +0 -2
  3. data/app/controllers/admin/account_controller.rb +1 -1
  4. data/app/controllers/{admin_controller.rb → admin/base_controller.rb} +1 -1
  5. data/app/controllers/admin/dashboard_controller.rb +1 -1
  6. data/app/controllers/admin/resource_controller.rb +1 -1
  7. data/app/controllers/admin/resources_controller.rb +1 -1
  8. data/app/controllers/admin/session_controller.rb +1 -1
  9. data/app/helpers/admin/base_helper.rb +60 -0
  10. data/app/views/admin/session/new.html.erb +1 -1
  11. data/app/views/layouts/{admin.html.erb → admin/base.html.erb} +0 -0
  12. data/lib/generators/templates/public/admin/javascripts/jquery.rails.js +17 -11
  13. data/lib/generators/templates/public/admin/stylesheets/screen.css +1 -0
  14. data/lib/generators/typus/migration_generator.rb +1 -1
  15. data/lib/generators/typus/typus_generator.rb +2 -2
  16. data/lib/typus/format.rb +1 -1
  17. data/lib/typus/orm/active_record.rb +7 -9
  18. data/lib/typus/user.rb +3 -3
  19. data/lib/typus/version.rb +1 -1
  20. data/test/fixtures/rails_app/config/routes.rb +1 -4
  21. data/test/fixtures/rails_app/log/test.log +41948 -1879
  22. data/test/fixtures/rails_app/tmp/{export-posts-20100902120447.csv → export-posts-20100913124503.csv} +0 -0
  23. data/test/fixtures/rails_app/tmp/{export-posts-20100902120700.csv → export-posts-20100913124524.csv} +0 -0
  24. data/test/fixtures/rails_app/tmp/export-posts-20100913124638.csv +2 -0
  25. data/test/fixtures/rails_app/tmp/export-posts-20100913124717.csv +2 -0
  26. data/test/fixtures/rails_app/tmp/export-posts-20100913125425.csv +2 -0
  27. data/test/fixtures/rails_app/tmp/export-posts-20100913125626.csv +2 -0
  28. data/test/fixtures/rails_app/tmp/export-posts-20100913125651.csv +2 -0
  29. data/test/fixtures/rails_app/tmp/export-posts-20100913125741.csv +2 -0
  30. data/test/fixtures/rails_app/tmp/export-posts-20100913125827.csv +2 -0
  31. data/test/fixtures/rails_app/tmp/export-posts-20100913125856.csv +2 -0
  32. data/test/fixtures/rails_app/tmp/export-posts-20100913125928.csv +2 -0
  33. data/test/fixtures/rails_app/tmp/export-posts-20100913130119.csv +2 -0
  34. data/test/fixtures/rails_app/tmp/export-posts-20100913130159.csv +2 -0
  35. data/test/fixtures/rails_app/tmp/export-posts-20100913130319.csv +2 -0
  36. data/test/fixtures/rails_app/tmp/export-posts-20100913130339.csv +2 -0
  37. data/test/fixtures/rails_app/tmp/export-posts-20100913131400.csv +2 -0
  38. data/test/fixtures/rails_app/tmp/export-posts-20100913131915.csv +2 -0
  39. data/test/fixtures/rails_app/tmp/export-posts-20100913132022.csv +2 -0
  40. data/test/fixtures/rails_app/tmp/export-posts-20100913132844.csv +2 -0
  41. data/test/lib/typus/active_record_test.rb +49 -18
  42. data/test/lib/typus/configuration_test.rb +7 -7
  43. data/test/unit/typus_user_test.rb +37 -21
  44. metadata +26 -10
  45. data/app/helpers/admin_helper.rb +0 -56
data/Gemfile CHANGED
@@ -14,4 +14,3 @@ gem "acts_as_list"
14
14
  gem "paperclip"
15
15
  gem "shoulda"
16
16
  gem "mocha"
17
- gem "redgreen"
data/Gemfile.lock CHANGED
@@ -70,7 +70,6 @@ GEM
70
70
  rake (>= 0.8.4)
71
71
  thor (~> 0.14.0)
72
72
  rake (0.8.7)
73
- redgreen (1.2.2)
74
73
  shoulda (2.11.3)
75
74
  sqlite3-ruby (1.3.1)
76
75
  thor (0.14.0)
@@ -91,6 +90,5 @@ DEPENDENCIES
91
90
  paperclip
92
91
  pg
93
92
  rails (= 3.0.0)
94
- redgreen
95
93
  shoulda
96
94
  sqlite3-ruby
@@ -1,4 +1,4 @@
1
- class Admin::AccountController < AdminController
1
+ class Admin::AccountController < Admin::BaseController
2
2
 
3
3
  layout 'admin/session'
4
4
 
@@ -1,6 +1,6 @@
1
1
  require "typus/authentication"
2
2
 
3
- class AdminController < ActionController::Base
3
+ class Admin::BaseController < ActionController::Base
4
4
 
5
5
  unloadable
6
6
 
@@ -1,4 +1,4 @@
1
- class Admin::DashboardController < AdminController
1
+ class Admin::DashboardController < Admin::BaseController
2
2
 
3
3
  def show
4
4
  raise "Run `rails generate typus` to create configuration files." if Typus.applications.empty?
@@ -1,4 +1,4 @@
1
- class Admin::ResourceController < AdminController
1
+ class Admin::ResourceController < Admin::BaseController
2
2
 
3
3
  before_filter :check_if_user_can_perform_action_on_resource
4
4
 
@@ -1,6 +1,6 @@
1
1
  require "typus/format"
2
2
 
3
- class Admin::ResourcesController < AdminController
3
+ class Admin::ResourcesController < Admin::BaseController
4
4
 
5
5
  include Typus::Format
6
6
 
@@ -1,4 +1,4 @@
1
- class Admin::SessionController < AdminController
1
+ class Admin::SessionController < Admin::BaseController
2
2
 
3
3
  skip_before_filter :reload_config_and_roles
4
4
  skip_before_filter :set_preferences
@@ -0,0 +1,60 @@
1
+ module Admin
2
+
3
+ module BaseHelper
4
+
5
+ def typus_block(resource = @resource.to_resource, partial = params[:action])
6
+ partials_path = "admin/#{resource}"
7
+ resources_partials_path = "admin/resources"
8
+
9
+ partials = ActionController::Base.view_paths.map do |view_path|
10
+ Dir["#{view_path}/#{partials_path}/*"].map { |f| File.basename(f, '.html.erb') }
11
+ end.flatten
12
+ resources_partials = Dir[Rails.root.join("app/views/#{resources_partials_path}/*").to_s].map do |file|
13
+ File.basename(file, ".html.erb")
14
+ end
15
+
16
+ path = if partials.include?("_#{partial}") then partials_path
17
+ elsif resources_partials.include?(partial) then resources_partials_path
18
+ end
19
+
20
+ render "#{path}/#{partial}" if path
21
+ end
22
+
23
+ def title(page_title)
24
+ content_for(:title) { page_title }
25
+ end
26
+
27
+ def header
28
+ render "admin/helpers/header"
29
+ end
30
+
31
+ def apps
32
+ render "admin/helpers/apps"
33
+ end
34
+
35
+ def login_info(user = @current_user)
36
+ return if user.kind_of?(Admin::FakeUser)
37
+
38
+ admin_edit_typus_user_path = { :controller => "/admin/#{Typus.user_class.to_resource}",
39
+ :action => 'edit',
40
+ :id => user.id }
41
+
42
+ message = _("Are you sure you want to sign out and end your session?")
43
+
44
+ user_details = if user.can?('edit', Typus.user_class_name)
45
+ link_to user.name, admin_edit_typus_user_path
46
+ else
47
+ user.name
48
+ end
49
+
50
+ render "admin/helpers/login_info", :message => message, :user_details => user_details
51
+ end
52
+
53
+ def display_flash_message(message = flash)
54
+ return if message.empty?
55
+ render "admin/helpers/flash_message", :flash_type => message.keys.first, :message => message
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -18,7 +18,7 @@
18
18
  </li>
19
19
 
20
20
  <li>
21
- <%= submit_tag _("Sign in"), :class => "button" %> <%= link_to _("Recover password"), forgot_password_admin_account_index_path if Rails.env.development? || Typus.mailer_sender %>
21
+ <%= submit_tag _("Sign in"), :class => "button" %> <%= link_to _("Recover password"), forgot_password_admin_account_index_path if Typus.mailer_sender %>
22
22
  </li>
23
23
 
24
24
  </ul>
@@ -23,18 +23,19 @@ jQuery(function ($) {
23
23
  */
24
24
  callRemote: function () {
25
25
  var el = this,
26
- data = el.is('form') ? el.serializeArray() : [],
27
26
  method = el.attr('method') || el.attr('data-method') || 'GET',
28
- url = el.attr('action') || el.attr('href');
27
+ url = el.attr('action') || el.attr('href'),
28
+ dataType = el.attr('data-type') || 'script';
29
29
 
30
30
  if (url === undefined) {
31
31
  throw "No URL specified for remote call (action or href must be present).";
32
32
  } else {
33
33
  if (el.triggerAndReturn('ajax:before')) {
34
+ var data = el.is('form') ? el.serializeArray() : [];
34
35
  $.ajax({
35
36
  url: url,
36
37
  data: data,
37
- dataType: 'script',
38
+ dataType: dataType,
38
39
  type: method.toUpperCase(),
39
40
  beforeSend: function (xhr) {
40
41
  el.trigger('ajax:loading', xhr);
@@ -104,23 +105,28 @@ jQuery(function ($) {
104
105
  /**
105
106
  * disable-with handlers
106
107
  */
107
- var disable_with_input_selector = 'input[data-disable-with]';
108
- var disable_with_form_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
108
+ var disable_with_input_selector = 'input[data-disable-with]';
109
+ var disable_with_form_remote_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
110
+ var disable_with_form_not_remote_selector = 'form:not([data-remote]):has(' + disable_with_input_selector + ')';
109
111
 
110
- $(disable_with_form_selector).live('ajax:before', function () {
112
+ var disable_with_input_function = function () {
111
113
  $(this).find(disable_with_input_selector).each(function () {
112
114
  var input = $(this);
113
115
  input.data('enable-with', input.val())
114
- .attr('value', input.attr('data-disable-with'))
115
- .attr('disabled', 'disabled');
116
+ .attr('value', input.attr('data-disable-with'))
117
+ .attr('disabled', 'disabled');
116
118
  });
117
- });
119
+ };
120
+
121
+ $(disable_with_form_remote_selector).live('ajax:before', disable_with_input_function);
122
+ $(disable_with_form_not_remote_selector).live('submit', disable_with_input_function);
118
123
 
119
- $(disable_with_form_selector).live('ajax:after', function () {
124
+ $(disable_with_form_remote_selector).live('ajax:complete', function () {
120
125
  $(this).find(disable_with_input_selector).each(function () {
121
126
  var input = $(this);
122
127
  input.removeAttr('disabled')
123
128
  .val(input.data('enable-with'));
124
129
  });
125
130
  });
126
- });
131
+
132
+ });
@@ -169,6 +169,7 @@ a:hover { color: #333; text-decoration: underline; }
169
169
  height: 50px;
170
170
  position: absolute;
171
171
  width: 100%;
172
+ z-index: -100;
172
173
  }
173
174
 
174
175
  #footer { font-size: 0.9em; padding: 20px; }
@@ -31,7 +31,7 @@ Examples:
31
31
  DESC
32
32
 
33
33
  def self.next_migration_number(path)
34
- Time.now.utc.to_s(:number)
34
+ Time.zone.now.utc.to_s(:number)
35
35
  end
36
36
 
37
37
  def generate_migration
@@ -24,7 +24,7 @@ Description:
24
24
  DESC
25
25
 
26
26
  def self.next_migration_number(path)
27
- Time.now.utc.to_s(:number)
27
+ Time.zone.now.utc.to_s(:number)
28
28
  end
29
29
 
30
30
  def copy_config_readme
@@ -87,7 +87,7 @@ Description:
87
87
  end
88
88
 
89
89
  def timestamp
90
- Time.now.utc.to_s(:number)
90
+ Time.zone.now.utc.to_s(:number)
91
91
  end
92
92
 
93
93
  private
data/lib/typus/format.rb CHANGED
@@ -39,7 +39,7 @@ module Typus
39
39
  csv = CSV
40
40
  end
41
41
 
42
- filename = Rails.root.join("tmp", "export-#{@resource.to_resource}-#{Time.now.utc.to_s(:number)}.csv")
42
+ filename = Rails.root.join("tmp", "export-#{@resource.to_resource}-#{Time.zone.now.to_s(:number)}.csv")
43
43
 
44
44
  options = { :conditions => @conditions, :batch_size => 1000 }
45
45
 
@@ -122,12 +122,11 @@ module Typus
122
122
  end
123
123
 
124
124
  def typus_search_fields
125
- data = Typus::Configuration.config[name]["search"]
126
- return [] if data.nil?
125
+ data = typus_defaults_for(:search)
127
126
 
128
127
  search = {}
129
128
 
130
- data.extract_settings.each do |field|
129
+ data.each do |field|
131
130
  if field.starts_with?("=")
132
131
  field.slice!(0)
133
132
  search[field] = "="
@@ -140,7 +139,6 @@ module Typus
140
139
  end
141
140
 
142
141
  return search
143
-
144
142
  end
145
143
 
146
144
  #--
@@ -301,10 +299,10 @@ module Typus
301
299
  conditions = merge_conditions(conditions, condition)
302
300
  when :datetime
303
301
  interval = case value
304
- when 'today' then Time.new.midnight..Time.new.midnight.tomorrow
305
- when 'last_few_days' then 3.days.ago.midnight..Time.new.midnight.tomorrow
306
- when 'last_7_days' then 6.days.ago.midnight..Time.new.midnight.tomorrow
307
- when 'last_30_days' then Time.new.midnight.prev_month..Time.new.midnight.tomorrow
302
+ when 'today' then Time.zone.now.beginning_of_day..Time.zone.now.beginning_of_day.tomorrow
303
+ when 'last_few_days' then 3.days.ago.beginning_of_day..Time.zone.now.beginning_of_day.tomorrow
304
+ when 'last_7_days' then 6.days.ago.beginning_of_day..Time.zone.now.beginning_of_day.tomorrow
305
+ when 'last_30_days' then Time.zone.now.beginning_of_day.prev_month..Time.zone.now.beginning_of_day.tomorrow
308
306
  end
309
307
  condition = ["#{key} BETWEEN ? AND ?", interval.first.to_s(:db), interval.last.to_s(:db)]
310
308
  conditions = merge_conditions(conditions, condition)
@@ -329,7 +327,7 @@ module Typus
329
327
  interval = case value
330
328
  when 'today' then nil
331
329
  when 'last_few_days' then 3.days.ago.to_date..Date.tomorrow
332
- when 'last_7_days' then 6.days.ago.midnight..Date.tomorrow
330
+ when 'last_7_days' then 6.days.ago.beginning_of_day..Date.tomorrow
333
331
  when 'last_30_days' then (Date.today << 1)..Date.tomorrow
334
332
  end
335
333
  if interval
data/lib/typus/user.rb CHANGED
@@ -20,7 +20,7 @@ module Typus
20
20
  validates_uniqueness_of :email
21
21
 
22
22
  validates_confirmation_of :password, :if => :password_required?
23
- validates_length_of :password, :within => 8..40, :if => :password_required?
23
+ validates_length_of :password, :within => 6..40, :if => :password_required?
24
24
  validates_presence_of :password, :if => :password_required?
25
25
 
26
26
  validates_presence_of :role
@@ -152,7 +152,7 @@ module Typus
152
152
  end
153
153
 
154
154
  def initialize_salt
155
- self.salt = generate_hash("--#{Time.now.utc.to_s(:number)}--#{email}--") if new_record?
155
+ self.salt = generate_hash("--#{Time.zone.now.to_s(:number)}--#{email}--") if new_record?
156
156
  end
157
157
 
158
158
  def initialize_token
@@ -160,7 +160,7 @@ module Typus
160
160
  end
161
161
 
162
162
  def generate_token
163
- self.token = encrypt("--#{Time.now.utc.to_s(:number)}--#{password}--").first(12)
163
+ self.token = encrypt("--#{Time.zone.now.to_s(:number)}--#{password}--").first(12)
164
164
  end
165
165
 
166
166
  def password_required?
data/lib/typus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Typus
2
- VERSION = "1.0.0.pre"
2
+ VERSION = "1.0.0.pre2"
3
3
  end
@@ -1,8 +1,5 @@
1
- RailsApp::Application.routes.draw do |map|
1
+ RailsApp::Application.routes.draw do
2
2
 
3
- map.connect "admin/delayed/tasks/:action/:id(.:format)", :controller => "admin/delayed/tasks"
4
-
5
- # Typus::Routes.draw(map)
6
3
  root :to => "welcome#index"
7
4
 
8
5
  end