card 1.18.1 → 1.18.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,7 +33,7 @@ def revision action
33
33
  # at the time of a given action
34
34
  action = Card::Action.fetch(action) if action.is_a? Integer
35
35
  action && Card::TRACKED_FIELDS.inject({}) do |attr_changes, field|
36
- last_change = action.card_changes.find_by_field_name(field) ||
36
+ last_change = action.change(field) ||
37
37
  last_change_on(field, not_after: action)
38
38
  attr_changes[field.to_sym] = (last_change ? last_change.value : self[field])
39
39
  attr_changes
@@ -43,7 +43,7 @@ end
43
43
  def delete_old_actions
44
44
  Card::TRACKED_FIELDS.each do |field|
45
45
  # assign previous changes on each tracked field to the last action
46
- if (la = last_action) && !la.change_for(field).present? &&
46
+ if (la = last_action) && !la.change(field).present? &&
47
47
  (last_change = last_change_on field)
48
48
  # last_change comes as readonly record
49
49
  last_change = Card::Change.find(last_change.id)
@@ -106,16 +106,17 @@ def last_actor
106
106
  end
107
107
 
108
108
  def last_act
109
- if (action = last_action)
110
- last_act_on_self = acts.last
111
- if last_act_on_self &&
112
- (action.act == last_act_on_self ||
113
- last_act_on_self.acted_at > action.act.acted_at)
114
- last_act_on_self
115
- else
116
- action.act
109
+ @last_act ||=
110
+ if (action = last_action)
111
+ last_act_on_self = acts.last
112
+ if last_act_on_self &&
113
+ (action.act == last_act_on_self ||
114
+ last_act_on_self.acted_at > action.act.acted_at)
115
+ last_act_on_self
116
+ else
117
+ action.act
118
+ end
117
119
  end
118
- end
119
120
  end
120
121
 
121
122
  def acted_at
@@ -1,4 +1,4 @@
1
- REVISIONS_PER_PAGE = Card.config.revisions_per_page
1
+ ACTS_PER_PAGE = Card.config.acts_per_page
2
2
 
3
3
  def history?
4
4
  true
@@ -6,16 +6,13 @@ end
6
6
 
7
7
  # must be called on all actions and before :set_name, :process_subcards and
8
8
  # :validate_delete_children
9
- # event :assign_act,
10
- # after: :identify_action,
11
- # when: proc { |c| c.history? || c.respond_to?(:attachment) } do
12
- # @current_act = (@supercard && @supercard.current_act) ||
13
- # Card::Act.create(ip_address: Env.ip)
14
- # assign_action
15
- # end
16
- #
9
+
10
+ def actionable?
11
+ history? || respond_to?(:attachment)
12
+ end
13
+
17
14
  event :assign_action, :initialize,
18
- when: proc { |c| c.history? || c.respond_to?(:attachment) } do
15
+ when: proc { |c| c.actionable? } do
19
16
  @current_act = director.need_act
20
17
  @current_action = Card::Action.create(
21
18
  card_act_id: @current_act.id,
@@ -28,7 +25,7 @@ event :assign_action, :initialize,
28
25
  end
29
26
 
30
27
  def finalize_action?
31
- (history? || respond_to?(:attachment)) && current_action
28
+ actionable? && current_action
32
29
  end
33
30
 
34
31
  # stores changes in the changes table and assigns them to the current action
@@ -39,6 +36,7 @@ event :finalize_action, :finalize,
39
36
  changed_attributes.member? f
40
37
  end
41
38
  if @changed_fields.present?
39
+ # FIXME: should be one bulk insert
42
40
  @changed_fields.each do |f|
43
41
  Card::Change.create field: f,
44
42
  value: self[f],
@@ -95,23 +93,6 @@ def rollback_request?
95
93
  Env.params['action_ids'].class == Array
96
94
  end
97
95
 
98
- # alternative approach to handle act and action that doesn't change the
99
- # database in the beginning stopped working with Rails 4
100
- # def build_act_and_action
101
- # @current_act = if @supercard
102
- # @supercard.current_act || @supercard.acts.build(ip_address: Env.ip)
103
- # else
104
- # acts.build(ip_address: Env.ip)
105
- # end
106
- # @current_action = actions(true).build(action_type: @action, draft:
107
- # (Env.params['draft'] == 'true') )
108
- # @current_action.act = @current_act
109
- #
110
- # if (@supercard and @supercard !=self)
111
- # @current_action.super_action = @supercard.current_action
112
- # end
113
- # end
114
-
115
96
  # all acts with actions on self and on cards that are descendants of self and
116
97
  # included in self
117
98
  def intrusive_family_acts args={}
@@ -121,7 +102,7 @@ def intrusive_family_acts args={}
121
102
  end
122
103
 
123
104
  # all acts with actions on self and on cards included in self
124
- def intrusive_acts args={ with_drafts: true }
105
+ def intrusive_acts args={ with_drafts: true }
125
106
  @intrusive_acts ||= begin
126
107
  Act.find_all_with_actions_on((included_card_ids << id), args)
127
108
  end
@@ -138,14 +119,14 @@ def current_rev_nr
138
119
  end
139
120
 
140
121
  def included_card_ids
141
- Card::Reference.select(:referee_id).where(
142
- ref_type: 'I', referer_id: id
143
- ).pluck('referee_id').compact.uniq
122
+ @included_card_ids ||=
123
+ Card::Reference.select(:referee_id).where(
124
+ ref_type: 'I', referer_id: id
125
+ ).pluck('referee_id').compact.uniq
144
126
  end
145
127
 
146
128
  def descendant_card_ids parent_ids=[id]
147
129
  more_ids = Card.where('left_id IN (?)', parent_ids).pluck('id')
148
-
149
130
  more_ids += descendant_card_ids more_ids unless more_ids.empty?
150
131
  more_ids
151
132
  end
@@ -157,27 +138,25 @@ end
157
138
  format :html do
158
139
  view :history do |args|
159
140
  frame args.merge(body_class: 'history-slot list-group', content: true) do
160
- [
161
- history_legend,
162
- _render_revisions
163
- ]
141
+ [history_legend, _render_act_list]
164
142
  end
165
143
  end
144
+
166
145
  def default_history_args args
167
146
  args[:optional_toolbar] ||= :show
168
147
  end
169
148
 
170
- view :revisions do |args|
149
+ view :act_list do |args|
171
150
  page = params['page'] || 1
172
- count = card.intrusive_acts.size + 1 - (page.to_i - 1) * REVISIONS_PER_PAGE
173
- card.intrusive_acts.page(page).per(REVISIONS_PER_PAGE).map do |act|
151
+ count = card.intrusive_acts.size + 1 - (page.to_i - 1) * ACTS_PER_PAGE
152
+ card.intrusive_acts.page(page).per(ACTS_PER_PAGE).map do |act|
174
153
  count -= 1
175
- render_act_summary args.merge(act: act, rev_nr: count)
154
+ render_act args.merge(act: act, act_seq: count)
176
155
  end.join
177
156
  end
178
157
 
179
158
  def history_legend
180
- intr = card.intrusive_acts.page(params['page']).per(REVISIONS_PER_PAGE)
159
+ intr = card.intrusive_acts.page(params['page']).per(ACTS_PER_PAGE)
181
160
  render_haml intr: intr do
182
161
  <<-HAML
183
162
  .history-header
@@ -195,70 +174,97 @@ format :html do
195
174
  end
196
175
  end
197
176
 
198
- view :act_summary do |args|
199
- render_act :summary, args
177
+ def default_act_args args
178
+ act = (args[:act] ||= Act.find(params['act_id']))
179
+ args[:act_seq] ||= params['act_seq']
180
+ args[:hide_diff] ||= hide_diff?
181
+ args[:slot_class] ||= "revision-#{act.id} history-slot list-group-item"
182
+ args[:action_view] ||= action_view
183
+ args[:actions] ||= action_list args
184
+ end
185
+
186
+ def action_list args
187
+ act = args[:act]
188
+ actions =
189
+ if act_context(args) == :absolute
190
+ act.actions
191
+ else
192
+ act.relevant_actions_for(card)
193
+ end
194
+ actions.select { |a| a.card && a.card.ok?(:read) }
195
+ # FIXME: should not need to test for presence of card here.
200
196
  end
201
197
 
202
- view :act_expanded do |args|
203
- render_act :expanded, args
198
+ def act_context args
199
+ args[:act_context] =
200
+ (args[:act_context] || params['act_context'] || :relative).to_sym
204
201
  end
205
202
 
206
- def render_act act_view, args
207
- act = (params['act_id'] && Card::Act.find(params['act_id'])) || args[:act]
208
- rev_nr = params['rev_nr'] || args[:rev_nr]
209
- current_rev_nr = params['current_rev_nr'] || args[:current_rev_nr] ||
210
- card.current_rev_nr
211
- hide_diff = (params['hide_diff'] == ' true') || args[:hide_diff]
212
- args[:slot_class] = "revision-#{act.id} history-slot list-group-item"
213
- draft = (last_action = act.actions.last) && last_action.draft
203
+ def hide_diff?
204
+ params['hide_diff'].to_s.strip == 'true'
205
+ end
214
206
 
207
+ def action_view
208
+ (params['action_view'] || 'summary').to_sym
209
+ end
210
+
211
+ view :act do |args|
215
212
  wrap(args) do
216
- render_haml card: card, act: act, act_view: act_view, draft: draft,
217
- current_rev_nr: current_rev_nr, rev_nr: rev_nr,
218
- hide_diff: hide_diff do
213
+ render_haml args.merge(card: card, args: args) do
219
214
  <<-HAML
220
215
  .act{style: "clear:both;"}
216
+ - show_header = act_context == :absolute ? :show : :hide
217
+ = optional_render :act_header, args, show_header
221
218
  .head
222
- .nr
223
- = "##{rev_nr}"
224
- .title
225
- .actor
226
- = link_to act.actor.name, card_url(act.actor.cardname.url_key)
227
- .time.timeago
228
- = time_ago_in_words(act.acted_at)
229
- ago
230
- - if draft
231
- |
232
- %em.info
233
- Autosave
234
- - if current_rev_nr == rev_nr
235
- %em.label.label-info
236
- Current
237
- - elsif act_view == :expanded
238
- = rollback_link act.relevant_actions_for(card)
239
- = show_or_hide_changes_link hide_diff, act_id: act.id, act_view: act_view, rev_nr: rev_nr, current_rev_nr: current_rev_nr
219
+ = render :act_metadata, args
240
220
  .toggle
241
- = fold_or_unfold_link act_id: act.id, act_view: act_view, rev_nr: rev_nr, current_rev_nr: current_rev_nr
242
-
243
- .action-container{style: ("clear: left;" if act_view == :expanded)}
244
- - act.relevant_actions_for(card).each do |action|
245
- = send("_render_action_#{act_view}", action: action )
221
+ = fold_or_unfold_link args
222
+ .action-container
223
+ - actions.each do |action|
224
+ = render ('action_' + action_view.to_s), args.merge(action: action)
246
225
  HAML
247
226
  end
248
227
  end
249
228
  end
250
229
 
230
+ view :act_header do |_args|
231
+ %(<h5 "class=act-header">#{card_link card}</h5>)
232
+ end
233
+
234
+ view :act_metadata do |args|
235
+ render_haml args.merge(card: card, args: args) do
236
+ <<-HAML
237
+ - unless act_context == :absolute
238
+ .nr
239
+ = '#' + act_seq.to_s
240
+ .title
241
+ .actor
242
+ = link_to act.actor.name, card_url(act.actor.cardname.url_key)
243
+ .time.timeago
244
+ = time_ago_in_words(act.acted_at)
245
+ ago
246
+ - if act.id == card.last_act.id
247
+ %em.label.label-info Current
248
+ - if action_view == :expanded
249
+ - unless act.id == card.last_act.id
250
+ = rollback_link act.relevant_actions_for(card)
251
+ = show_or_hide_changes_link args
252
+ HAML
253
+ end
254
+ end
255
+
251
256
  view :action_summary do |args|
252
- render_action :summary, args
257
+ view_action :summary, args
253
258
  end
254
259
 
255
260
  view :action_expanded do |args|
256
- render_action :expanded, args
261
+ view_action :expanded, args
257
262
  end
258
263
 
259
- def render_action action_view, args
264
+ def view_action action_view, args
260
265
  action = args[:action] || card.last_action
261
- hide_diff = Env.params['hide_diff'] == 'true' || args[:hide_diff]
266
+ hide_diff = args[:hide_diff] || hide_diff?
267
+
262
268
  render_haml action: action,
263
269
  action_view: action_view,
264
270
  name_diff: name_diff(action, hide_diff),
@@ -318,9 +324,9 @@ HAML
318
324
  end
319
325
 
320
326
  def name_changes action, hide_diff=false
321
- old_name = (name = action.old_values[:name]) && showname(name).to_s
327
+ old_name = (name = action.previous_value :name) && showname(name).to_s
322
328
  if action.new_name?
323
- new_name = showname(action.new_values[:name]).to_s
329
+ new_name = showname(action.value(:name)).to_s
324
330
  if hide_diff
325
331
  new_name
326
332
  else
@@ -332,45 +338,56 @@ HAML
332
338
  end
333
339
 
334
340
  def type_changes action, hide_diff=false
335
- change = hide_diff ? action.new_values[:cardtype] : action.cardtype_diff
341
+ change = hide_diff ? action.value(:cardtype) : action.cardtype_diff
336
342
  "(#{change})"
337
343
  end
338
344
 
339
345
  view :content_changes do |args|
340
346
  if args[:hide_diff]
341
- args[:action].new_values[:content]
347
+ args[:action].value :db_content
342
348
  else
343
349
  args[:action].content_diff(args[:diff_type])
344
350
  end
345
351
  end
346
352
 
353
+ def fold_or_unfold_link args
354
+ path_opts = {
355
+ act_id: args[:act].id,
356
+ act_seq: args[:act_seq],
357
+ hide_diff: args[:hide_diff],
358
+ act_context: args[:act_context],
359
+ action_view: (args[:action_view] == :expanded ? :summary : :expanded)
360
+ }
361
+ arrow_dir = args[:action_view] == :expanded ? 'arrow-down' : 'arrow-right'
362
+ view_link '', :act, path_opts: path_opts,
363
+ class: "slotter revision-#{args[:act_id]} #{arrow_dir}"
364
+ end
365
+
347
366
  def rollback_link actions
348
367
  not_current =
349
368
  actions.select { |action| action.card.last_action_id != action.id }
350
369
  return unless card.ok?(:update) && not_current.present?
351
370
  link_path = path action: :update, view: :open, action_ids: not_current
352
- '| ' + link_to(
371
+ link = link_to(
353
372
  'Save as current', link_path,
354
373
  class: 'slotter', 'data-slot-selector' => '.card-slot.history-view',
355
374
  remote: true, method: :post, rel: 'nofollow'
356
375
  )
376
+ %(<div class="act-link">#{link}</div>)
357
377
  end
358
378
 
359
- def fold_or_unfold_link args
360
- toggled_view = args[:act_view] == :expanded ? :act_summary : :act_expanded
361
- arrow_dir = args[:act_view] == :expanded ? 'arrow-down' : 'arrow-right'
362
- link_to '', args.merge(view: toggled_view),
363
- class: "slotter revision-#{args[:act_id]} #{arrow_dir}",
364
- remote: true
365
- end
366
-
367
- def show_or_hide_changes_link hide_diff, args
368
- text = (hide_diff ? 'Show' : 'Hide') + ' changes'
369
- '| ' + view_link(
370
- text, :act_expanded,
371
- path_opts: args.merge(hide_diff: !hide_diff),
372
- class: 'slotter', remote: true
373
- )
379
+ def show_or_hide_changes_link args
380
+ toggle = args[:hide_diff] ? 'Show' : 'Hide'
381
+ path_opts = {
382
+ act_id: args[:act].id,
383
+ act_seq: args[:act_seq],
384
+ hide_diff: !args[:hide_diff],
385
+ action_view: :expanded,
386
+ act_context: args[:act_context]
387
+ }
388
+ link = view_link("#{toggle} changes", :act,
389
+ path_opts: path_opts, class: 'slotter', remote: true)
390
+ %(<div class="act-link">#{link}</div>)
374
391
  end
375
392
  end
376
393
 
@@ -144,7 +144,7 @@ format do
144
144
  view :subedit_notice, denial: :blank do |args|
145
145
  action = get_action(args)
146
146
  name_before_action =
147
- (action.new_values[:name] && action.old_values[:name]) || card.name
147
+ (action.value(:name) && action.previous_value(:name)) || card.name
148
148
 
149
149
  wrap_subedit_item %(#{name_before_action} #{action.action_type}d
150
150
  #{render_list_of_changes(args)})
@@ -180,7 +180,7 @@ format do
180
180
  end
181
181
 
182
182
  def edit_info_for field, action
183
- return nil unless action.new_values[field]
183
+ return nil unless action.value field
184
184
 
185
185
  item_title =
186
186
  case action.action_type
@@ -192,9 +192,9 @@ format do
192
192
 
193
193
  item_value =
194
194
  if action.action_type == :delete
195
- action.old_values[field]
195
+ action.previous_value field
196
196
  else
197
- action.new_values[field]
197
+ action.value field
198
198
  end
199
199
 
200
200
  wrap_list_item "#{item_title}#{item_value}"
@@ -1,42 +1,27 @@
1
+ ACTS_PER_PAGE = 50
1
2
 
2
3
  view :title do |args|
3
4
  super args.merge(title: 'Recent Changes')
4
5
  end
5
6
 
6
7
  format :html do
7
- view :card_list do |args|
8
- search_vars[:item] ||= :change
9
-
10
- cards_by_day = Hash.new { |h, day| h[day] = [] }
11
- search_results.each do |card|
12
- begin
13
- stamp = card.updated_at
14
- day = Date.new(stamp.year, stamp.month, stamp.day)
15
- rescue => e
16
- day = Date.today
17
- card.content = '(error getting date)'
18
- end
19
- cards_by_day[day] << card if card.followable?
8
+ view :core do |args|
9
+ content_tag(:div, class: 'history-slot list-group') do
10
+ [history_legend, render_recent_acts(args)].join
20
11
  end
12
+ end
21
13
 
22
- paging = _optional_render :paging, args
23
- %(
24
- #{paging}
25
- #{cards_by_day.keys.sort.reverse.map do |day|
26
- %(
27
- <h2>#{format_date(day, include_time = false)}</h2>
28
- <div class="search-result-list">
29
- #{cards_by_day[day].map do |card|
30
- %(
31
- <div class="search-result-item item-#{search_vars[:item]}">
32
- #{nest(card, view: search_vars[:item])}
33
- </div>
34
- )
35
- end * ' '}
36
- </div>
37
- )
38
- end * "\n"}
39
- #{paging}
40
- )
14
+ view :recent_acts do |args|
15
+ page = params['page'] || 1
16
+ acts = Act.all_viewable.order(id: :desc).page(page).per(ACTS_PER_PAGE)
17
+ acts.map do |act|
18
+ if (act_card = act.card)
19
+ format = act_card.format :html
20
+ format.render_act args.merge(act: act, act_context: :absolute)
21
+ else
22
+ Rails.logger.info "bad data, act: #{act}"
23
+ ''
24
+ end
25
+ end.join
41
26
  end
42
27
  end