wordjelly-auth 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/ai_lab.jpg +0 -0
  3. data/app/assets/images/lab.jpg +0 -0
  4. data/app/assets/images/placeholder.png +0 -0
  5. data/app/assets/javascripts/auth/application.js +1 -2
  6. data/app/assets/javascripts/auth/auth_dependencies.js +25 -4
  7. data/app/assets/javascripts/auth/auth_modals_and_navbar.js +9 -6
  8. data/app/assets/stylesheets/auth/auth_default_css.scss +4 -4
  9. data/app/assets/stylesheets/auth/overrides.scss +12 -1
  10. data/app/controllers/auth/concerns/devise_concern.rb +7 -9
  11. data/app/controllers/auth/concerns/shopping/product_controller_concern.rb +41 -3
  12. data/app/controllers/auth/concerns/token_concern.rb +1 -1
  13. data/app/controllers/auth/concerns/work/instruction_controller_concern.rb +109 -0
  14. data/app/controllers/auth/shopping/shopping_controller.rb +0 -1
  15. data/app/controllers/auth/work/bullets_controller.rb +18 -0
  16. data/app/controllers/auth/work/instructions_controller.rb +16 -0
  17. data/app/controllers/auth/work/work_controller.rb +46 -0
  18. data/app/helpers/auth/work/bullets/bullets_helper.rb +25 -0
  19. data/app/helpers/auth/work/instructions/instructions_helper.rb +25 -0
  20. data/app/models/auth/concerns/chief_model_concern.rb +20 -0
  21. data/app/models/auth/concerns/notification_concern.rb +6 -0
  22. data/app/models/auth/concerns/owner_concern.rb +1 -2
  23. data/app/models/auth/concerns/shopping/product_concern.rb +9 -0
  24. data/app/models/auth/concerns/work/good_concern.rb +37 -0
  25. data/app/models/auth/concerns/work/inform_concern.rb +31 -0
  26. data/app/models/auth/image.rb +3 -0
  27. data/app/models/auth/work/VICTORY SPEECH: +12 -30
  28. data/app/models/auth/work/actor.rb +4 -0
  29. data/app/models/auth/work/bullet.rb +8 -0
  30. data/app/models/auth/work/cycle.rb +1 -1
  31. data/app/models/auth/work/information.rb +20 -0
  32. data/app/models/auth/work/instruction.rb +26 -0
  33. data/app/models/auth/work/link.rb +6 -0
  34. data/app/models/auth/work/minute.rb +151 -5
  35. data/app/models/auth/work/parameter.rb +9 -0
  36. data/app/models/auth/work/variable.rb +4 -0
  37. data/app/views/auth/modals/_oauth_and_submit.html.erb +2 -4
  38. data/app/views/auth/modals/_sign_in_inputs.html.erb +6 -4
  39. data/app/views/auth/modals/_sign_up_inputs.html.erb +1 -0
  40. data/app/views/auth/search/_search_bar.html.erb +8 -11
  41. data/app/views/auth/shopping/cart_items/_form.html.erb +2 -1
  42. data/app/views/auth/shopping/products/index.html.erb +6 -47
  43. data/app/views/auth/shopping/products/index/_show.html.erb +19 -0
  44. data/app/views/auth/shopping/products/show.html.erb +4 -11
  45. data/app/views/auth/shopping/products/show/_action_links.html.erb +2 -0
  46. data/app/views/auth/shopping/products/show/_content.html.erb +22 -0
  47. data/app/views/auth/shopping/products/show/_summary.html.erb +20 -0
  48. data/app/views/auth/work/bullets/_form.html.erb +10 -0
  49. data/app/views/auth/work/bullets/_show.html.erb +12 -0
  50. data/app/views/auth/work/bullets/edit.html.erb +1 -0
  51. data/app/{models/auth/concerns/work/schedule_concern.rb → views/auth/work/bullets/new.html.erb} +0 -0
  52. data/app/views/auth/work/instructions/_form.html.erb +16 -0
  53. data/app/views/auth/work/instructions/_show.html.erb +21 -0
  54. data/app/views/auth/work/instructions/edit.html.erb +1 -0
  55. data/app/views/layouts/auth/application.html.erb +0 -1
  56. data/app/views/layouts/auth/navbar/_navbar.html.erb +31 -31
  57. data/app/views/layouts/auth/navbar/_personalization.html.erb +2 -0
  58. data/config/initializers/devise.rb +0 -1
  59. data/config/initializers/omniauth.rb +5 -4
  60. data/lib/assets/javascripts/main.js +17 -6
  61. data/lib/assets/javascripts/you_need_to_sign_in.js.erb +9 -7
  62. data/lib/auth/engine.rb +19 -1
  63. data/lib/auth/rails/routes.rb +80 -29
  64. data/lib/auth/version.rb +1 -1
  65. data/spec/dummy/app/assets/images/ai_lab.jpg +0 -0
  66. data/spec/dummy/app/assets/images/lab.jpg +0 -0
  67. data/spec/dummy/app/assets/javascripts/application.js +1 -0
  68. data/spec/dummy/app/assets/time_hashes.json +1 -1
  69. data/spec/dummy/app/models/noti.rb +1 -1
  70. data/spec/dummy/app/models/shopping/product.rb +3 -1
  71. data/spec/dummy/app/views/home/index.html.erb +71 -5
  72. data/spec/dummy/app/views/layouts/application.html.erb +2 -0
  73. data/spec/dummy/config/application.rb +6 -0
  74. data/spec/dummy/config/initializers/preinitializer.rb +2 -2
  75. data/spec/dummy/db/products.json +136 -0
  76. data/spec/dummy/db/seeds.rb +80 -2
  77. data/spec/models/auth/work/minute_spec.rb +141 -3
  78. data/spec/requests/shopping/product_request_spec.rb +213 -0
  79. metadata +43 -45
  80. data/app/assets/javascripts/auth/admin_create_users.js +0 -2
  81. data/app/assets/javascripts/auth/assemblies.js +0 -2
  82. data/app/assets/javascripts/auth/clients.js +0 -2
  83. data/app/assets/javascripts/auth/images.js +0 -5
  84. data/app/assets/javascripts/auth/search.js +0 -2
  85. data/app/assets/stylesheets/auth/admin_create_users.css +0 -4
  86. data/app/assets/stylesheets/auth/assemblies.css +0 -4
  87. data/app/assets/stylesheets/auth/images.css +0 -4
  88. data/app/assets/stylesheets/auth/search.css +0 -4
  89. data/app/assets/stylesheets/auth/shopping/discounts.css +0 -4
  90. data/spec/dummy/app/assets/javascripts/activity.js +0 -2
  91. data/spec/dummy/app/assets/javascripts/home.js +0 -2
  92. data/spec/dummy/app/assets/javascripts/pollymer.min.js +0 -170
  93. data/spec/dummy/app/assets/javascripts/tests.js +0 -2
  94. data/spec/dummy/app/assets/javascripts/topics.js +0 -2
  95. data/spec/dummy/app/assets/javascripts/worms.js +0 -2
  96. data/spec/dummy/app/assets/stylesheets/activity.css +0 -4
  97. data/spec/dummy/app/assets/stylesheets/home.css +0 -4
  98. data/spec/dummy/app/assets/stylesheets/scaffolds.scss +0 -73
  99. data/spec/dummy/app/assets/stylesheets/tests.css +0 -4
  100. data/spec/dummy/app/assets/stylesheets/topics.css +0 -4
  101. data/spec/dummy/app/assets/stylesheets/worms.scss +0 -3
  102. data/spec/dummy/log/development.log +0 -21
  103. data/spec/dummy/log/test.log +0 -2821
@@ -0,0 +1,25 @@
1
+ module Auth::Work::Bullets::BulletsHelper
2
+ ## get /new
3
+ =begin
4
+ def new_bullet_path
5
+ main_app.send(Auth::OmniAuth::Path.new_path(Auth.configuration.bullet_class))
6
+ end
7
+
8
+ ## (PUT/PATCH/GET) - individual bullet
9
+ def bullet_path(bullet)
10
+
11
+ main_app.send(Auth::OmniAuth::Path.show_or_update_or_delete_path(Auth.configuration.bullet_class),bullet)
12
+ end
13
+
14
+
15
+ ##/bullets (GET - all bullets /CREATE - individual bullet)
16
+ def bullets_path
17
+ main_app.send(Auth::OmniAuth::Path.create_or_index_path(Auth.configuration.bullet_class))
18
+ end
19
+
20
+ ##/shopping/bullets/:id/edit
21
+ def edit_bullet_path(bullet)
22
+ main_app.send(Auth::OmniAuth::Path.edit_path(Auth.configuration.bullet_class),bullet)
23
+ end
24
+ =end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Auth::Work::Instructions::InstructionsHelper
2
+ ## get /new
3
+ =begin
4
+ def new_instruction_path
5
+ main_app.send(Auth::OmniAuth::Path.new_path(Auth.configuration.instruction_class))
6
+ end
7
+
8
+ ## (PUT/PATCH/GET) - individual instruction
9
+ def instruction_path(instruction)
10
+ ## so it basically needs the whole product instruction combined path.
11
+ main_app.send(Auth::OmniAuth::Path.show_or_update_or_delete_path(Auth.configuration.instruction_class),instruction)
12
+ end
13
+
14
+
15
+ ##/instructions (GET - all instructions /CREATE - individual instruction)
16
+ def instructions_path
17
+ main_app.send("shopping_product_instructions_path")
18
+ end
19
+
20
+ ##/shopping/instructions/:id/edit
21
+ def edit_instruction_path(instruction)
22
+ main_app.send(Auth::OmniAuth::Path.edit_path(Auth.configuration.instruction_class),instruction)
23
+ end
24
+ =end
25
+ end
@@ -17,10 +17,23 @@ module Auth::Concerns::ChiefModelConcern
17
17
  ## currently used in the after_save callback where we dont want the refund being set to accepted, and thereafter to update all other refunds as failed to cascade.
18
18
  attr_accessor :skip_callbacks
19
19
 
20
+ ## these are for adding embedded documents.
21
+ attr_accessor :embedded_document_path
22
+
23
+ ## any embedded document to be changed is to be added here.
24
+ attr_accessor :embedded_document
25
+
26
+ ## array of image ids, that are associated with the current document.
27
+ attr_accessor :images
20
28
 
21
29
  field :public, type:String, default: "no"
22
30
 
23
31
 
32
+ after_initialize do |document|
33
+ document.load_images
34
+ end
35
+
36
+
24
37
  def field_names_to_skip_while_making_form
25
38
  ["_id","_type.,","resource_id","resource_class","created_at","updated_at","public"]
26
39
  end
@@ -30,6 +43,13 @@ module Auth::Concerns::ChiefModelConcern
30
43
  end
31
44
 
32
45
 
46
+ ##find an image/ images with this parent id.
47
+ ##and add them to an images array.
48
+ def load_images
49
+ self.images = Auth::Image.where(:parent_id => self.id.to_s) || []
50
+ end
51
+
52
+
33
53
  ## returns a list of attributes of tis model other than those mentioned in #FIELD_NAMES_TO_SKIP_WHILE_MAKING_FORM in this concern.
34
54
  ## this is only used in the web api.
35
55
  ## @return[Array] array_of_strings : field name.
@@ -148,6 +148,9 @@ module Auth::Concerns::NotificationConcern
148
148
  recipients[:resources].map{|r|
149
149
  send_email_background(r) if send_by_email?(r)
150
150
  send_sms_background(r) if send_by_sms?(r)
151
+ ## so here i still need to implement aws for the notifications.
152
+ ## that part is still pending.
153
+ ## so i can override send_sms_background to use a handle_asynchronously with the specified delay.
151
154
  #r.send_mobile_notification(self) if send_by_mobile?(r)
152
155
  #r.send_desktop_notification(self) if send_by_desktop?(r)
153
156
  }
@@ -161,6 +164,9 @@ module Auth::Concerns::NotificationConcern
161
164
  def send_sms_background(resource)
162
165
  send_sms(resource)
163
166
  end
167
+ ## i can override this, to do async.
168
+ ## that's the only thing,
169
+ ## and it will be another notification object, totally.
164
170
 
165
171
  ## creates a notification response object using the yield block from calling this method.
166
172
  ## block passed if any must return a string as the yield.
@@ -54,8 +54,7 @@ module Auth::Concerns::OwnerConcern
54
54
  #puts "conditions are:"
55
55
  #puts conditions.to_s
56
56
  all = self.where(conditions)
57
- #puts "the resultant size:"
58
- #puts all.size.to_s
57
+
59
58
  return all.first if all.size > 0
60
59
  return nil
61
60
  end
@@ -97,15 +97,23 @@ module Auth::Concerns::Shopping::ProductConcern
97
97
  #field :time_information, type: Hash, default: {}
98
98
  field :miscellaneous_attributes, type: Hash, default: {}
99
99
 
100
+ field :description, type: String, default: "Available"
101
+
102
+ field :badge_text, type: String, default: "Delivery in 30 mins"
103
+
104
+ field :badge_class, type: String, default: "new badge"
100
105
 
101
106
  ## all products are public to be searched.
102
107
  before_save do |document|
103
108
  self.public = "yes"
104
109
  end
105
110
 
111
+ ## first have to ensure that the summary is returned along with the json.
112
+
106
113
  end
107
114
 
108
115
 
116
+
109
117
  def as_indexed_json(options={})
110
118
  {
111
119
  name: name,
@@ -115,6 +123,7 @@ module Auth::Concerns::Shopping::ProductConcern
115
123
  }
116
124
  end
117
125
 
126
+
118
127
  module ClassMethods
119
128
 
120
129
  ## so we have completed the rolling n minutes.
@@ -0,0 +1,37 @@
1
+ ## intended to be mixed into the product_class
2
+ ## contains methods assuming that an item is going to be processed by using the modules provided by the work concern.
3
+ module Auth::Concerns::Work::GoodConcern
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ embeds_many :parameters, :class_name => "Auth::Work::Parameter"
9
+ embeds_many :instructions, :class_name => "Auth::Work::Instruction"
10
+ embeds_many :actors, :class_name => "Auth::Work::Actor"
11
+ embeds_many :variables, :class_name => "Auth::Work::Variable"
12
+
13
+ after_initialize do |document|
14
+ document.summary = document.build_summary
15
+ end
16
+
17
+ attr_accessor :summary
18
+
19
+ end
20
+
21
+ def build_summary
22
+ self.summary = []
23
+ self.instructions.each do |inst|
24
+ self.summary << {
25
+ :summary_icon_class => inst.summary_icon_class,
26
+ :summary_text => inst.summary_text,
27
+ :summary_icon_color => inst.summary_icon_color
28
+ } if inst.include_in_summary == true
29
+ end
30
+ end
31
+
32
+ def as_json(options)
33
+ ## includes the images associated with the object as well.
34
+ super({:methods => [:embedded_document_path, :embedded_document, :summary, :images]}.merge(options))
35
+ end
36
+
37
+ end
@@ -0,0 +1,31 @@
1
+ module Auth::Concerns::Work::InformConcern
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ ## what does this do really ?
7
+ field :who_and_when_to_inform, type: Hash
8
+ field :inform_on_actions, type: Array, default: []
9
+
10
+ after_update do |document|
11
+ document.inform if document.inform_on_actions.include? "after_update"
12
+ end
13
+
14
+ before_destroy do |document|
15
+ document.inform if document.inform_on_actions.include? "before_destroy"
16
+ end
17
+
18
+ def inform
19
+ self.who_and_when_to_inform.keys.each do |person_id|
20
+ information = Auth::Work::Information.new
21
+ information.resource_id = person_id
22
+ information.send_at = self.who_and_when_to_inform[person_id]
23
+ ## other options can be added.
24
+ ## like payload and format.
25
+ information.inform
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -1,5 +1,8 @@
1
1
  class Auth::Image
2
2
 
3
+ ## cloudinary link to show android app that signs request
4
+ ## https://github.com/cloudinary/cloudinary_android/tree/master/sample-signed
5
+
3
6
  include Mongoid::Document
4
7
  include Auth::Concerns::OwnerConcern
5
8
 
@@ -1,31 +1,13 @@
1
- Feels good. Some folks who deserve a mention:
1
+ Some people who deserve a mention:
2
+
3
+ -Dr.Manas Dutta(for the motivation, and setting a fine example),
4
+ -Dr.Harvinder Singh & Dr. Priyam Pargaonkar(for being so understanding in my first year),
5
+ -Dr.Shailendra Tiwari(for the tutorial on Hindi romantic poetry and its indications and contraindications),
6
+ -Dr.Vanshika Shahi(for teaching me pathology),
7
+ -Dr.Rishabh Joshi(for redefining my notion of 'capacity'),
8
+ -Dr.Chaitrangi Rohekar Paranjpe(for being as blunt as is humanly possible),
9
+ -Dr.Iqbal Ahmed Farooqi(for the tips on MCQ's),
10
+ -Dr.Monalisa Makashir Laturkar(for telling me I'd top this exam),
11
+ -Dr.Kumud Jeswani Raut(for the sugar cubes, and Lahejat tea),
12
+ -Dr.Aditya Raut(for existing) and my parents(for everything).
2
13
 
3
- Dr.Manas Dutta : I think AIIMS made a good choice when they chose you for the CVTS job. Studying together with you, showed me there are parts of the mind, levels of endurance, that we don't know we are capable of.
4
-
5
- Dr.Priyam Pargaonkar, Dr.Harvinder Singh : You guys put up with all my eccentricities during first year. I don't think I could have found more understanding seniors. Words do not begin to express how much of a difference you people inadvertantly and unknowingly made to my life, especially since you didn't know my story from the preceeding 5 years.
6
-
7
- Dr.Shailendra Tiwari : For showing me that all-nighters are possible.
8
-
9
- Dr.Rishabh Joshi : The guy who can answer any medical question under the sun, and I still don't know when you study. If I ever start drinking or smoking, the first one is going to be with you. Look after your liver and lungs till then!
10
-
11
- Dr.Chaitrangi Rohekar Paranjpe : For your no holds-barred, downright brutal assessment of my life, especially the day you said "Get off your lazy a**, and do something with your life."(Although I was already working on a lot of things at the time). Its rare to find someone who is willing to be so frank. You're like a conscience in human form, and you simply don't give a damn what the hooman thinks. #Awe
12
-
13
- Dr.Iqbal Ahmed Farooqui : Your knowledge of competitive exams, and the tips and tricks you shared, were invaluable. And thanks for keeping me company on those 3 am burger binges.
14
-
15
- Dr.Monalisa Laturkar : For telling me nearly 6 months ago, that she knew I was going to top this exam. #Psychic
16
-
17
- Dr.Twinnie Bhalla : For the singing.
18
-
19
- Dr.Riya Mishra : For the encouragement.
20
-
21
- My mom, who told me she felt the vibes were right for me to give this exam. My dad, for the unconditional love.
22
-
23
- A special mention to Dr.Karandikar, my original pathology teacher since 2008. I still remember the slide you showed us on a rainy afternoon in June 2008, Linitus Plastica. The dedication you show to your work, is impossible to match.
24
-
25
- Dr.Kumud Jeswani, for the golden turtle and sugar cubes, these were all i ate on some days.
26
-
27
- And of course, all the stray dogs around Bharti Vidyapeeth, who will no longer have someone to feed them at 4 am in the morning. You guys were always there.
28
-
29
- Furbo the cat: true love is true love, even if you find it in a heartless cat. I don't know why I let you go. I hope there's someone to look after you, the nights can get chilly.
30
-
31
- Finally, Dr.Aditya Raut.
@@ -0,0 +1,4 @@
1
+ class Auth::Work::Actor
2
+ include Mongoid::Document
3
+ embedded_in :product, :class_name => Auth.configuration.product_class
4
+ end
@@ -0,0 +1,8 @@
1
+ class Auth::Work::Bullet
2
+ include Mongoid::Document
3
+ include Auth::Concerns::ChiefModelConcern
4
+ embedded_in :instruction, :class_name => "Auth::Work::Instruction"
5
+ field :title, type: String
6
+ field :description, type: String
7
+ field :text, type: String
8
+ end
@@ -63,7 +63,7 @@ class Auth::Work::Cycle
63
63
  field :cycle_code, type: String
64
64
 
65
65
  ## the ids of the related cycles.
66
- field :cycle_chain, type: Array
66
+ field :cycle_chain, type: Array, default: []
67
67
 
68
68
  before_save do |document|
69
69
  document.cycle_code = BSON::ObjectId.new.to_s unless document.cycle_code
@@ -0,0 +1,20 @@
1
+ class Auth::Work::Information
2
+ include Mongoid::Document
3
+ field :resource_id, type: String
4
+ field :send_at, type: Time
5
+ field :payload_for_sms, type: String
6
+ field :payload_for_email, type: String
7
+ field :payload_for_mobile_notification, type: String
8
+
9
+ ## how to format the email / sms / mobile app notification
10
+
11
+ field :email_format_option, type: String
12
+ field :sms_format_option, type: String
13
+ field :notification_format_option, type: String
14
+
15
+ def inform
16
+ end
17
+
18
+
19
+
20
+ end
@@ -0,0 +1,26 @@
1
+ class Auth::Work::Instruction
2
+ include Mongoid::Document
3
+ include Auth::Concerns::ChiefModelConcern
4
+
5
+ attr_accessor :product_id
6
+
7
+ INSTRUCTION_TYPES = ["Before The Test","After The Test","During The Test","Who This Test is For","Who Should Not Take This Test"]
8
+
9
+ embedded_in :product, :class_name => Auth.configuration.product_class
10
+
11
+ field :summary_icon_class, type: String
12
+
13
+ field :summary_text, type: String
14
+
15
+ field :summary_icon_color, type: String
16
+
17
+ field :include_in_summary, type: Boolean, default: false
18
+
19
+ field :title, type: String
20
+
21
+ field :description, type: String
22
+
23
+ embeds_many :links, :class_name => "Auth::Work::Link"
24
+ embeds_many :bullets, :class_name => "Auth::Work::Bullet"
25
+
26
+ end
@@ -0,0 +1,6 @@
1
+ class Auth::Work::Link
2
+ include Auth::Concerns::ChiefModelConcern
3
+ embedded_in :instruction, :class_name => "Auth::Work::Instruction"
4
+ field :url, type: String
5
+ field :url_text, type: String
6
+ end
@@ -1,9 +1,12 @@
1
1
  class Auth::Work::Minute
2
+
2
3
  include Mongoid::Document
4
+
3
5
  embeds_many :cycles, :class_name => "Auth::Work::Cycle", :as => :minute_cycles
6
+
4
7
  field :time, type: Time
5
- field :geom, type: Array
6
8
 
9
+ field :geom, type: Array
7
10
 
8
11
 
9
12
  ## returns all minutes which have affected cycles , only containing the affected cycles.
@@ -71,6 +74,11 @@ class Auth::Work::Minute
71
74
  "includeArrayIndex" => "cycle_index"
72
75
  }
73
76
  },
77
+ {
78
+ "$addFields" => {
79
+ "cycles.cycle_index" => "$cycle_index"
80
+ }
81
+ },
74
82
  {
75
83
  "$match" => {
76
84
  "$and" => [
@@ -130,11 +138,149 @@ class Auth::Work::Minute
130
138
  }
131
139
  }
132
140
  ])
133
- response
141
+
142
+ array_of_minute_objects = []
143
+ response.each do |res|
144
+ #puts JSON.pretty_generate(res)
145
+ array_of_minute_objects << Auth::Work::Minute.new(res)
146
+ end
147
+ array_of_minute_objects
148
+ end
149
+
150
+ def self.update_all_affected_cycles(minutes,cycle_workers_assigned,cycle_entities_assigned)
151
+ update_cycle_chains(minutes)
152
+ update_cycles(minutes,cycle_workers_assigned,cycle_entities_assigned)
153
+ end
154
+
155
+ ## @param[Array] minutes :
156
+ def self.update_cycles(minutes,cycle_workers_assigned,cycle_entities_assigned)
157
+
158
+ minutes = minutes.map {|minute|
159
+
160
+ pull_hash = {}
161
+
162
+ minute.cycles.each do |cycle|
163
+ pull_hash["cycles.#{cycle.cycle_index}.workers_available"] = {
164
+ "$in" => cycle_workers_assigned
165
+ }
166
+ end
167
+
168
+ minute = Auth::Work::Minute
169
+ .where({
170
+ "_id" => BSON::ObjectId(minute.id.to_s)
171
+ })
172
+ .find_one_and_update(
173
+ {
174
+ "$pull" => pull_hash
175
+ },
176
+ {
177
+ :return_document => :after
178
+ }
179
+ )
180
+
181
+ minute
182
+ }
183
+
184
+ minutes
185
+
186
+ end
187
+
188
+ ## first knock of the cycle chains.
189
+ ## then the actual cycles.
190
+ def self.update_cycle_chains(minutes)
191
+ cycles_to_pull = []
192
+ minutes.each do |minute|
193
+ minute.cycles.each do |cycle|
194
+ cycles_to_pull << cycle.cycle_chain
195
+ end
196
+ end
197
+
198
+ cycles_to_pull.flatten.map{|c| c = BSON::ObjectId(c)}.each_slice(100) do |ids_to_pull|
199
+ pull_hash = {}
200
+ pull_hash["cycles"] = {
201
+ "_id" => {
202
+ "$in" => ids_to_pull
203
+ }
204
+ }
205
+ response = Auth::Work::Minute.collection.update_many({},{"$pull" => pull_hash})
206
+ end
207
+
208
+ cycles_to_pull.flatten
134
209
  end
135
210
 
136
- ## this means that the cycle has to be keeping track of the workers available and entities_available.
137
- ## but what about capacity ?
138
- ##
211
+ ## this will block the transporter and rewire his availability for all subsequent and prior minutes.
212
+ ## this i have to do today.
213
+ def update_transporter
214
+
215
+ end
216
+
217
+ ## okay first do what can be predictable done.
218
+ ## that means the partials in the views.
219
+ ## go for it.
220
+
221
+ ## match where [cycle is a and cycle is primary] OR [cycle is b and cycle is primary, cycle is c and cycle is primary] present.
222
+ ## then unwind the cycles
223
+ ## so now we know that all these cycles even if they don't be primary, still belong to a minute with a primary
224
+ ## now match only the useful cycles
225
+ ## group by minutes
226
+ ## add a field that combines the size of the avialable cycles + the distance from now
227
+ ## sort by that.
228
+ ## @param[Array] cycle_requirements_array : {cycle_id , worker_requirements :{"type" : number}, entity_requirements: {"type" : number}}
229
+ ## @param[Hash] transport_information : {distance : , coordinates :}
230
+ ## lets get the edit out of the way first.
231
+ def find_applicable_minute(cycle_requirements_array)
232
+ ## go to elasticsearch for this ?
233
+ ## ?
234
+ aggregations = [
235
+ {
236
+ "cycles" => {
237
+ "$elemMatch" => {
238
+ "$or" =>
239
+ [
240
+
241
+ ]
242
+ }
243
+ }
244
+ },
245
+ {
246
+ "$unwind" => "$cycles"
247
+ },
248
+ {
249
+ ## keep all cycles, dont enforce the belongs_to_minute at this level.
250
+ ## just cycle_type and workers and entities
251
+ ## since we want to include the 30 min rolling slots as well.
252
+ ## we are only keeping the cycles which have the required type.
253
+ ## and we can match again,
254
+ "$match" => {
255
+ "cycles.cycle_type" => {
256
+ "$in" => "all_the_cycles"
257
+ }
258
+ }
259
+ }
260
+ ]
261
+
262
+
263
+
264
+ cycle_requirements_array.each do |req|
265
+ aggregations[0]["cycles"]["$elemMatch"]["$or"] << {
266
+ "cycle_type" => req["cycle_type"],
267
+ "workers_available.#{req['workers_count'] - 1}" => {
268
+ "$exists" => true
269
+ },
270
+ "entities_available.#{req['entities_count'] - 1}" => {
271
+ "$exists" => true
272
+ },
273
+ "belongs_to_minute" => true
274
+ }
275
+ end
276
+
277
+ ## we are going to get minutes that have at the minimum one of the cycles as belonging to the given minute.
278
+
279
+ ## now we are going to unwind the cycles,
280
+ ## keep only those which satisfy these conditions.
281
+
282
+ ## we take a look at other cycles which will be affected only if that cycle, is not already booked, otherwise it doesnt make any difference at all.
283
+
284
+ end
139
285
 
140
286
  end