bumbleworks 0.0.64 → 0.0.65

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ module Bumbleworks
8
8
  @queries << proc { |wi| wi['fields']['params']['task'] }
9
9
  @task_class = task_class
10
10
  @task_filters = []
11
+ @orderers = []
11
12
  @wfids = nil
12
13
  end
13
14
 
@@ -94,6 +95,22 @@ module Bumbleworks
94
95
  for_processes([process])
95
96
  end
96
97
 
98
+ def order_by_field(field, direction = :asc)
99
+ order_by_fields(field => direction)
100
+ end
101
+
102
+ def order_by_param(param, direction = :asc)
103
+ order_by_params(param => direction)
104
+ end
105
+
106
+ def order_by_fields(fields)
107
+ add_orderer(fields)
108
+ end
109
+
110
+ def order_by_params(params)
111
+ add_orderer(params, 'params')
112
+ end
113
+
97
114
  def completable(true_or_false = true)
98
115
  @task_filters << proc { |task| task.completable? == true_or_false }
99
116
  self
@@ -115,7 +132,11 @@ module Bumbleworks
115
132
  def each
116
133
  return to_enum(:each) unless block_given?
117
134
  return if @wfids == []
118
- workitems = Bumbleworks.dashboard.context.storage.get_many('workitems', @wfids).each { |wi|
135
+ workitems = raw_workitems(@wfids)
136
+ @orderers.each do |order_proc|
137
+ workitems.sort! &order_proc
138
+ end
139
+ workitems.each { |wi|
119
140
  if task = filtered_task_from_raw_workitem(wi)
120
141
  yield task
121
142
  end
@@ -132,6 +153,21 @@ module Bumbleworks
132
153
 
133
154
  private
134
155
 
156
+ def add_orderer(fields, field_type = 'fields')
157
+ @orderers << proc { |wi_x, wi_y|
158
+ relevant_direction, result = :asc, 0
159
+ fields.each do |field, direction|
160
+ sets = [wi_x['fields'], wi_y['fields']]
161
+ sets.map! { |s| s['params'] } if field_type.to_s == 'params'
162
+ result = sets[0][field.to_s] <=> sets[1][field.to_s]
163
+ relevant_direction = direction
164
+ break if !result.zero?
165
+ end
166
+ relevant_direction == :desc ? -result : result
167
+ }
168
+ self
169
+ end
170
+
135
171
  def filtered_task_from_raw_workitem(workitem)
136
172
  if @queries.all? { |q| q.call(workitem) }
137
173
  task = from_workitem(::Ruote::Workitem.new(workitem))
@@ -146,6 +182,10 @@ module Bumbleworks
146
182
  def from_workitem(workitem)
147
183
  task = @task_class.new(workitem)
148
184
  end
185
+
186
+ def raw_workitems(wfids)
187
+ Bumbleworks.dashboard.context.storage.get_many('workitems', wfids)
188
+ end
149
189
  end
150
190
  end
151
191
  end
@@ -1,3 +1,3 @@
1
1
  module Bumbleworks
2
- VERSION = "0.0.64"
2
+ VERSION = "0.0.65"
3
3
  end
@@ -218,6 +218,107 @@ describe Bumbleworks::Task do
218
218
  end
219
219
  end
220
220
 
221
+ context 'ordering' do
222
+ before :each do
223
+ Bumbleworks.define_process 'emergency_hamster_bullet' do
224
+ concurrence do
225
+ doctor :task => 'evince_concern', :priority => 3, :importance => 1000
226
+ patient :task => 'panic', :priority => 2, :importance => 5
227
+ nurse :task => 'roll_eyes', :priority => 4, :importance => 1000
228
+ officer :task => 'appear_authoritative', :priority => 1, :importance => 1000
229
+ end
230
+ end
231
+ end
232
+
233
+ context 'by params' do
234
+ before(:each) do
235
+ Bumbleworks.launch!('emergency_hamster_bullet')
236
+ Bumbleworks.dashboard.wait_for(:officer)
237
+ end
238
+
239
+ describe '.order_by_param' do
240
+ it 'orders returned tasks by given param ascending by default' do
241
+ tasks = described_class.order_by_param(:priority)
242
+ tasks.map(&:nickname).should == [
243
+ 'appear_authoritative',
244
+ 'panic',
245
+ 'evince_concern',
246
+ 'roll_eyes'
247
+ ]
248
+ end
249
+
250
+ it 'can order in reverse' do
251
+ tasks = described_class.order_by_param(:priority, :desc)
252
+ tasks.map(&:nickname).should == [
253
+ 'roll_eyes',
254
+ 'evince_concern',
255
+ 'panic',
256
+ 'appear_authoritative'
257
+ ]
258
+ end
259
+ end
260
+
261
+ describe '.order_by_params' do
262
+ it 'orders by multiple parameters' do
263
+ tasks = described_class.order_by_params(:importance => :desc, :priority => :asc)
264
+ tasks.map(&:nickname).should == [
265
+ 'appear_authoritative',
266
+ 'evince_concern',
267
+ 'roll_eyes',
268
+ 'panic'
269
+ ]
270
+ end
271
+ end
272
+ end
273
+
274
+ context 'by fields' do
275
+ before(:each) do
276
+ @wf3 = Bumbleworks.launch!('emergency_hamster_bullet', :group => 2, :strength => 3)
277
+ Bumbleworks.dashboard.wait_for(:officer)
278
+ @wf1 = Bumbleworks.launch!('emergency_hamster_bullet', :group => 2, :strength => 1)
279
+ Bumbleworks.dashboard.wait_for(:officer)
280
+ @wf2 = Bumbleworks.launch!('emergency_hamster_bullet', :group => 1, :strength => 2)
281
+ Bumbleworks.dashboard.wait_for(:officer)
282
+ @wf4 = Bumbleworks.launch!('emergency_hamster_bullet', :group => 1, :strength => 4)
283
+ Bumbleworks.dashboard.wait_for(:officer)
284
+ end
285
+
286
+ describe '.order_by_field' do
287
+ it 'orders returned tasks by given param ascending by default' do
288
+ tasks = described_class.for_role('doctor').order_by_field(:strength)
289
+ tasks.map { |t| [t.nickname, t.wfid] }.should == [
290
+ ['evince_concern', @wf1.wfid],
291
+ ['evince_concern', @wf2.wfid],
292
+ ['evince_concern', @wf3.wfid],
293
+ ['evince_concern', @wf4.wfid]
294
+ ]
295
+ end
296
+
297
+ it 'can order in reverse' do
298
+ tasks = described_class.for_role('doctor').order_by_field(:strength, :desc)
299
+ tasks.map { |t| [t.nickname, t.wfid] }.should == [
300
+ ['evince_concern', @wf4.wfid],
301
+ ['evince_concern', @wf3.wfid],
302
+ ['evince_concern', @wf2.wfid],
303
+ ['evince_concern', @wf1.wfid]
304
+ ]
305
+ end
306
+ end
307
+
308
+ describe '.order_by_fields' do
309
+ it 'orders by multiple parameters' do
310
+ tasks = described_class.for_role('doctor').order_by_fields(:group => :asc, :strength => :desc)
311
+ tasks.map { |t| [t.nickname, t.wfid] }.should == [
312
+ ['evince_concern', @wf4.wfid],
313
+ ['evince_concern', @wf2.wfid],
314
+ ['evince_concern', @wf3.wfid],
315
+ ['evince_concern', @wf1.wfid]
316
+ ]
317
+ end
318
+ end
319
+ end
320
+ end
321
+
221
322
  describe '.for_roles' do
222
323
  before :each do
223
324
  Bumbleworks.define_process 'lowering_penguin_self_esteem' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bumbleworks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.64
4
+ version: 0.0.65
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -263,7 +263,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
263
263
  version: '0'
264
264
  segments:
265
265
  - 0
266
- hash: 2850289231226753878
266
+ hash: 3834352798561343652
267
267
  required_rubygems_version: !ruby/object:Gem::Requirement
268
268
  none: false
269
269
  requirements:
@@ -272,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
272
  version: '0'
273
273
  segments:
274
274
  - 0
275
- hash: 2850289231226753878
275
+ hash: 3834352798561343652
276
276
  requirements: []
277
277
  rubyforge_project:
278
278
  rubygems_version: 1.8.23