Class: Auth::Workflow::Step

Inherits:
Object
  • Object
show all
Includes:
Concerns::WorkflowConcern
Defined in:
app/models/auth/workflow/step.rb

Constant Summary collapse

FIELDS_LOCKED_AFTER_ORDER_ADDED =
["applicable"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assembly_doc_versionObject

Returns the value of attribute assembly_doc_version.



44
45
46
# File 'app/models/auth/workflow/step.rb', line 44

def assembly_doc_version
  @assembly_doc_version
end

#assembly_idObject

Returns the value of attribute assembly_id.



43
44
45
# File 'app/models/auth/workflow/step.rb', line 43

def assembly_id
  @assembly_id
end

#query_informationObject

Returns the value of attribute query_information.



54
55
56
# File 'app/models/auth/workflow/step.rb', line 54

def query_information
  @query_information
end

#sop_doc_versionObject

Returns the value of attribute sop_doc_version.



49
50
51
# File 'app/models/auth/workflow/step.rb', line 49

def sop_doc_version
  @sop_doc_version
end

#sop_idObject

Returns the value of attribute sop_id.



50
51
52
# File 'app/models/auth/workflow/step.rb', line 50

def sop_id
  @sop_id
end

#sop_indexObject

Returns the value of attribute sop_index.



48
49
50
# File 'app/models/auth/workflow/step.rb', line 48

def sop_index
  @sop_index
end

#stage_doc_versionObject

Returns the value of attribute stage_doc_version.



46
47
48
# File 'app/models/auth/workflow/step.rb', line 46

def stage_doc_version
  @stage_doc_version
end

#stage_idObject

Returns the value of attribute stage_id.



47
48
49
# File 'app/models/auth/workflow/step.rb', line 47

def stage_id
  @stage_id
end

#stage_indexObject

Returns the value of attribute stage_index.



45
46
47
# File 'app/models/auth/workflow/step.rb', line 45

def stage_index
  @stage_index
end

#step_indexObject

Returns the value of attribute step_index.



51
52
53
# File 'app/models/auth/workflow/step.rb', line 51

def step_index
  @step_index
end

Class Method Details

.find_self(id, signed_in_resource, options = {}) ⇒ Object



61
62
63
64
65
66
67
68
# File 'app/models/auth/workflow/step.rb', line 61

def self.find_self(id,signed_in_resource,options={})
	
	return nil unless collection =  Auth.configuration.assembly_class.constantize.where("stages.sops.steps._id" => BSON::ObjectId(id)
	)

	collection.first
	  
end

.permitted_paramsObject



56
57
58
# File 'app/models/auth/workflow/step.rb', line 56

def self.permitted_params
	[{:step => [:name, :applicable, :description,:assembly_id,:assembly_doc_version,:stage_id, :stage_doc_version, :stage_index, :sop_id, :sop_doc_version, :sop_index, :doc_version, :step_index]},:id]
end

Instance Method Details

#append_time_and_location_information_based_on_previous_stepObject



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'app/models/auth/workflow/step.rb', line 214

def append_time_and_location_information_based_on_previous_step
	## suppose we have the previous step saying some things
	## and now we have 3 cart items here.
	## so they have to be matched to whichever group they belong to.
	## so for that we will have to go over the hash.
	## and then assign them there.
	## based on time since previous query, we have to change the start time ranges.
	## based on the query results.
	## the query will provide a start and an end time.
	## so we will have to hold the minutes from the earlier query for all the cart items.
	## from the previous step.
	## when you come to a step, clear the previous step.
end

#create_with_conditions(params, permitted_params, model) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/models/auth/workflow/step.rb', line 70

def create_with_conditions(params,permitted_params,model)
	## in this case the model is a stage model.
	
	return false unless model.valid?

	assembly_updated = Auth.configuration.assembly_class.constantize.where({
		"$and" => [
			{
				"stages.#{model.stage_index}._id" => BSON::ObjectId(model.stage_id)
			},
			{
				"stages.#{model.stage_index}.doc_version" => model.stage_doc_version
			},
			{
				"_id" => BSON::ObjectId(model.assembly_id)
			},
			{
				"doc_version" => model.assembly_doc_version
			},
			{
				"stages.#{model.stage_index}.sops.#{model.sop_index}._id" => BSON::ObjectId(model.sop_id)
			},
			{
				"stages.#{model.stage_index}.sops.#{model.sop_index}.doc_version" => model.sop_doc_version
			},
		]
	})
	.find_one_and_update(
		{
			"$push" => 
			{
				"stages.#{stage_index}.sops.#{sop_index}.steps" => model.attributes
			}
		},
		{
			:return_document => :after
		}
	)

	

	return false unless assembly_updated
	return model

end

#do_queryObject



228
229
230
# File 'app/models/auth/workflow/step.rb', line 228

def do_query

end

#duration_calculation_functionObject

we need to provide a duration calculation function here.



35
# File 'app/models/auth/workflow/step.rb', line 35

field :duration_calculation_function, type: String, default: ""

#duration_or_duration_calculation_function_existsObject

if this step is made applicable, it must have either a duration or a duration calculation function.



340
341
342
343
344
345
346
# File 'app/models/auth/workflow/step.rb', line 340

def duration_or_duration_calculation_function_exists

	if self.applicable_changed? && self.applicable == true
		self.errors.add(:duration,"please specify a duration or a duration calculation function") if (self.duration.blank? && self.duration_calculation_function.blank?)
	end

end

#merge_cart_item_specifications(cart_items) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'app/models/auth/workflow/step.rb', line 117

def merge_cart_item_specifications(cart_items)

	current_time = Time.now

	_time = {}
	_only_location_cart_items = {}
	
	## here the problem is that we have to add a start time, that is consistent for all the specifications at the minimum
	## while entering the step.

	cart_items.each do |cart_item|
		puts "doing cart item: #{cart_item.id.to_s}"
		if specification = cart_item.get_specification(self.stage_index.to_s + ":" + self.sop_index.to_s + ":" + self.step_index.to_s)

			if start_time_range = specification.start_time_range(current_time)
				puts "has start time range."
				_time[Base64.encode64(start_time_range.to_s)] = {:sort_key => start_time_range[:start_time_range_beginning], :start_time_range => start_time_range, :any_location => {}} unless _time[Base64.encode64(start_time_range.to_s)]

				if loc = specification.location
				
					
					
					_time[Base64.encode64(start_time_range.to_s)][Base64.encode64(loc.to_s)] = {:location => loc, :cart_item_ids => []} unless _time[Base64.encode64(start_time_range.to_s)][Base64.encode64(loc.to_s)]
					
					_time[Base64.encode64(start_time_range.to_s)][Base64.encode64(loc.to_s)][:cart_item_ids] << cart_item.id.to_s
					
				else
					
					if _time[Base64.encode64(start_time_range.to_s)][:any_location][:cart_item_ids]
						
						puts "any location cart item ids already exist."

						_time[Base64.encode64(start_time_range.to_s)][:any_location][:cart_item_ids] << cart_item.id.to_s

					else

						puts "they dont exist."
						
						_time[Base64.encode64(start_time_range.to_s)][:any_location][:cart_item_ids] = [cart_item.id.to_s]
					
					end

				end
										
			else
				if loc = specification.location
					
					_only_location_cart_items[Base64.encode64(loc.to_s)] = {:cart_item_ids => [], :location => loc.to_s} unless _only_location_cart_items[Base64.encode64(loc.to_s)]

					_only_location_cart_items[Base64.encode64(loc.to_s)][:cart_item_ids] << cart_item.id.to_s

				else
				
					## no time information and no location information , will not be performed at all.
				
				end

			end


			
		end

	end

	puts JSON.pretty_generate(_time)

	_time = _time.sort_by{|k,v| v[:sort_key]}.to_h
	## so what to do if there is no sort key.

	_only_location_cart_items.keys.each do |loc|
		found_existing = false
		_time.keys.each do |k|
			unless _time[k][loc].nil?

				#puts "this is _time[k][loc]"
				#puts _time[k][loc]

				#puts "this is only locations cart items"
				#puts _only_location_cart_items[loc][:cart_item_ids]

				_time[k][loc][:cart_item_ids]+= _only_location_cart_items[loc][:cart_item_ids]
				found_existing = true
				break
			end
			unless found_existing
				_time[_time.keys.first][loc] = {:cart_item_ids => _only_location_cart_items[loc][:cart_item_ids]}
			end
		end
	end

	_time

	

end

#modify_tlocation_conditions_for_each_product(order, stage_index, sop_index, step_index) ⇒ Object

@param order : the latest added order which is being scheduled. @param stage_index : the index of the stage @param sop_index : the index of the sop @param step_index : the index of the step.

what to do incase this step’s location information has a reference? and same for requirement ? can a requirement reference a previous step? in that case what sense does it make to add time and location information to it? we don’t enforce location. this should only be done if time and locatino are to be enforced, for a particular step. but at this stage, let the merging happen.



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'app/models/auth/workflow/step.rb', line 287

def modify_tlocation_conditions_for_each_product(order,stage_index,sop_index,step_index)
	
	self.location_information.deep_symbolize_keys!
	self.time_information.deep_symbolize_keys!
	#puts "stage index :#{stage_index}"
	#puts "sop index : #{sop_index}"
	#puts "step index: #{step_index}"

	if first_cart_item = Auth.configuration.cart_item_class.constantize.find(order.cart_item_ids.first)

		
		location_information = first_cart_item.location_information["stages:#{stage_index}:sops:#{sop_index}:steps:#{step_index}"]

		time_information = first_cart_item.time_information["stages:#{stage_index}:sops:#{sop_index}:steps:#{step_index}"]


		## merge the information inside it, 
		if !location_information.blank?
			self.location_information = self.location_information.merge(location_information)
		end
		
		if !time_information.blank?
			self.time_information = self.time_information.merge(time_information) 
		end
		
		## the variables if any are added only to the step.
		## the requirements that are noted inside the step , can have only a category.
		## requirements can always have only a category, there is no such thing as a direct requirement id


=begin
		self.requirements.each_with_index{|requirement,key|
			if requirement.applicable
				
				requirement_location_information = first_cart_item.location_information["stages:#{stage_index}:sops:#{sop_index}:steps:#{step_index}:requirements:#{key}"]
					
				requirement.location_information = requirement.location_information.deep_symbolize_keys.merge(requirement_location_information) if !requirement_location_information.blank?

				requirement_time_information = first_cart_item.time_information["stages:#{stage_index}:sops:#{sop_index}:steps:#{step_index}:requirements:#{key}"]
				
				requirement.time_information = requirement.time_information.deep_symbolize_keys.merge(requirement_time_information) if !requirement_time_information.blank?


			end
		}
=end
	end

end

#start_minute_listObject

and array of the type :

[1,1],,[1,3]

: the first element of every sub array is the day_id, and the last element is the minute.



24
# File 'app/models/auth/workflow/step.rb', line 24

field :start_minute_list, type: Array, default: []