active_scaffold 3.2.9 → 3.2.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,10 @@
1
- = 3.2.9 (not released)
1
+ = 3.2.10 (not released yet)
2
+ - fix nested scaffolds with update action disabled
3
+ - initial work for tableless support (index with limited options)
4
+ - fix scrolling on closing nested scaffolds
5
+ - fix calculations which were broken in 3.2.9
6
+
7
+ = 3.2.9
2
8
  - remove duplicated conditions with constraints
3
9
  - fix constraints for polymorphic associations
4
10
 
@@ -85,7 +85,7 @@ jQuery(document).ready(function() {
85
85
 
86
86
  if (action_link) {
87
87
  if (action_link.position) {
88
- action_link.close(response);
88
+ action_link.close();
89
89
  } else {
90
90
  response.evalResponse();
91
91
  }
@@ -931,7 +931,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({
931
931
  this.enable();
932
932
  this.adapter.remove();
933
933
  if (this.hide_target) this.target.show();
934
- if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target, ActiveScaffold.config.scroll_on_close == 'checkInViewport');
934
+ if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport');
935
935
  },
936
936
 
937
937
  get_new_adapter_id: function() {
@@ -109,7 +109,7 @@ document.observe("dom:loaded", function() {
109
109
  var action_link = ActiveScaffold.find_action_link(event.findElement());
110
110
  if (action_link) {
111
111
  if (action_link.position) {
112
- action_link.close(event.memo.request.responseText);
112
+ action_link.close();
113
113
  } else {
114
114
  event.memo.request.evalResponse();
115
115
  }
@@ -819,7 +819,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({
819
819
  this.enable();
820
820
  this.adapter.remove();
821
821
  if (this.hide_target) this.target.show();
822
- if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target, ActiveScaffold.config.scroll_on_close == 'checkInViewport');
822
+ if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target.id, ActiveScaffold.config.scroll_on_close == 'checkInViewport');
823
823
  },
824
824
 
825
825
  get_new_adapter_id: function() {
@@ -6,7 +6,7 @@ module ActiveScaffold::Actions
6
6
  after_filter :clear_flashes
7
7
  end
8
8
  base.helper_method :nested?
9
- base.helper_method :beginning_of_chain
9
+ base.helper_method :calculate
10
10
  base.helper_method :new_model
11
11
  end
12
12
  def render_field
@@ -50,9 +50,11 @@ module ActiveScaffold::Actions
50
50
  begin
51
51
  self.successful = @record.destroy
52
52
  marked_records.delete @record.id.to_s if successful?
53
- rescue
53
+ rescue Exception => ex
54
54
  flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label)
55
55
  self.successful = false
56
+ logger.debug ex.message
57
+ logger.debug ex.backtrace.join("\n")
56
58
  end
57
59
  end
58
60
 
@@ -63,7 +63,7 @@ module ActiveScaffold::Config
63
63
  private
64
64
 
65
65
  def columns=(val)
66
- @columns.set_values(*val) if @column
66
+ @columns.set_values(*val) if @columns
67
67
  @columns ||= ActiveScaffold::DataStructures::ActionColumns.new(*val).tap do |columns|
68
68
  columns.action = self
69
69
  columns.set_columns(@core.columns) if @columns.respond_to?(:set_columns)
@@ -16,8 +16,11 @@ module ActiveScaffold
16
16
  constrained_fields ||= []
17
17
  constrained_fields |= active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect(&:to_sym)
18
18
  exclude_actions = []
19
- exclude_actions << :list unless active_scaffold_config.list.hide_nested_column
20
- exclude_actions << :update unless active_scaffold_config.update.hide_nested_column
19
+ [:list, :update].each do |action_name|
20
+ if active_scaffold_config.actions.include? action_name
21
+ exclude_actions << action_name unless active_scaffold_config.send(action_name).hide_nested_column
22
+ end
23
+ end
21
24
 
22
25
  if self.class.uses_active_scaffold?
23
26
  # we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't
@@ -103,8 +103,6 @@ module ActiveScaffold::DataStructures
103
103
  result = false
104
104
  # skip if this matches a constrained column
105
105
  result = true if constraint_columns.include?(column.name.to_sym)
106
- # skip if this matches the field_name of a constrained column
107
- result = true if column.field_name and constraint_columns.include?(column.field_name.to_sym)
108
106
  # skip this field if it's not authorized
109
107
  unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => column.name)
110
108
  self.unauthorized_columns << column.name.to_sym
@@ -358,6 +358,8 @@ module ActiveScaffold::DataStructures
358
358
  self.sort = {:method => "#{self.name}.join(',')"}
359
359
  elsif @active_record_class.connection
360
360
  self.sort = {:sql => self.field}
361
+ else
362
+ self.sort = false
361
363
  end
362
364
  end
363
365
  end
@@ -325,6 +325,14 @@ module ActiveScaffold
325
325
  end
326
326
  pager.page(options[:page])
327
327
  end
328
+
329
+ def calculate(column)
330
+ conditions = all_conditions
331
+ includes = active_scaffold_config.list.count_includes
332
+ includes ||= active_scaffold_includes unless conditions.nil?
333
+ append_to_query(beginning_of_chain, :conditions => conditions, :includes => includes,
334
+ :joins => joins_for_collection).calculate(column.calculate, column.name)
335
+ end
328
336
 
329
337
  def append_to_query(query, options)
330
338
  options.assert_valid_keys :where, :select, :group, :reorder, :limit, :offset, :joins, :includes, :lock, :readonly, :from, :conditions
@@ -264,11 +264,7 @@ module ActiveScaffold
264
264
 
265
265
  def column_calculation(column)
266
266
  unless column.calculate.instance_of? Proc
267
- conditions = controller.send(:all_conditions)
268
- includes = active_scaffold_config.list.count_includes
269
- includes ||= controller.send(:active_scaffold_includes) unless conditions.nil?
270
- calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions,
271
- :joins => controller.send(:joins_for_collection), :include => includes)
267
+ calculate(column)
272
268
  else
273
269
  column.calculate.call(@records)
274
270
  end
@@ -0,0 +1,66 @@
1
+ class ActiveScaffold::Tableless < ActiveRecord::Base
2
+ class Relation < ActiveRecord::Relation
3
+ attr_reader :conditions
4
+ def initialize(klass, table)
5
+ super
6
+ @conditions ||= []
7
+ end
8
+
9
+ def initialize_copy(other)
10
+ @conditions = @conditions.dup
11
+ super
12
+ end
13
+
14
+ def where(opts, *rest)
15
+ unless opts.blank?
16
+ opts = opts.with_indifferent_access if opts.is_a? Hash
17
+ @conditions << (rest.empty? ? opts : [opts, *rest])
18
+ end
19
+ self
20
+ end
21
+
22
+ def merge(r)
23
+ super.tap do |merged|
24
+ merged.conditions.concat r.conditions unless r.nil? || r.is_a?(Array)
25
+ end
26
+ end
27
+
28
+ def to_a
29
+ @klass.find_all(self)
30
+ end
31
+
32
+ def find_one(id)
33
+ @klass.find_one(id, self)
34
+ end
35
+ end
36
+
37
+ def self.columns; @columns ||= []; end
38
+ def self.table_name; @table_name ||= ActiveModel::Naming.plural(self); end
39
+ def self.connection; nil; end
40
+ def self.table_exists?; true; end
41
+ self.abstract_class = true
42
+ class << self
43
+ private
44
+ def relation
45
+ @relation ||= ActiveScaffold::Tableless::Relation.new(self, arel_table)
46
+ super
47
+ end
48
+ end
49
+
50
+ def self.column(name, sql_type = nil, options = {})
51
+ column = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, options[:default], sql_type.to_s, options.has_key?(:null) ? options[:null] : true)
52
+ column.tap { columns << column }
53
+ end
54
+
55
+ def self.find_all(relation)
56
+ raise 'self.find_all must be implemented in a Tableless model'
57
+ end
58
+
59
+ def self.find_one(id, relation)
60
+ raise 'self.find_one must be implemented in a Tableless model'
61
+ end
62
+
63
+ def destroy
64
+ raise 'destroy must be implemented in a Tableless model'
65
+ end
66
+ end
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 2
5
- PATCH = 9
5
+ PATCH = 10
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -1,5 +1,8 @@
1
1
  # TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely.
2
2
  Dir["#{File.dirname __FILE__}/active_scaffold/extensions/*.rb"].each { |file| require file }
3
+ module ActiveScaffold
4
+ autoload :Tableless, 'active_scaffold/tableless'
5
+ end
3
6
 
4
7
  ActionController::Base.send(:include, ActiveScaffold)
5
8
  ActionController::Base.send(:include, RespondsToParent)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 2
9
- - 9
10
- version: 3.2.9
9
+ - 10
10
+ version: 3.2.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Many, see README
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-22 00:00:00 Z
18
+ date: 2012-05-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :development
@@ -303,6 +303,7 @@ files:
303
303
  - lib/active_scaffold/marked_model.rb
304
304
  - lib/active_scaffold/paginator.rb
305
305
  - lib/active_scaffold/responds_to_parent.rb
306
+ - lib/active_scaffold/tableless.rb
306
307
  - lib/active_scaffold/version.rb
307
308
  - lib/active_scaffold_env.rb
308
309
  - lib/generators/active_scaffold/USAGE