atome 0.5.7.3.3 → 0.5.7.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f111d86401c9293ac46fa899d202bf0ab2a1c905d5d17186f0b87ba0560f65d
4
- data.tar.gz: ae3208f9349448b93a93864308445ce9108c450366ce8ee2ac1b7026724b40c2
3
+ metadata.gz: bdac6b85c37bdf4d8e6842a2b423912931a8d33dd693aa03dd90d46a8c91e16f
4
+ data.tar.gz: d52b45f795e5c583a548a29a6d979ffc4fd6671907070c1b28f0234351a83131
5
5
  SHA512:
6
- metadata.gz: 3139df2c2320097e707d095e2aa577104669823e61c77fa9b7a4e43553537068926cea7701bd0cd9c8e21bd41087f9d1e04f101883adcd0ea3b5cc84ba1d665e
7
- data.tar.gz: c151bca3643df87d2388087cf534eb44e22e3ca8bf4281de8a9311bc7a20717164dd8be7c4a65dced3365e23e110af18648d732374706aaa9aab1fabcfc98bee
6
+ metadata.gz: 276797c37915a64902cd3491ec29111aa17364e7aa87b7eeff16f3c7901428a9cd5f94117c459e5e9f11acfd7d39ccccbd5e8aea0baa8f96f57ec3f930710b8f
7
+ data.tar.gz: 88e5562ae2ad330ae11c895e905296c56498f09868c0b881242b17d2c268c9aadd915e35b804610d54a9f3d68c3c6091d21483e3aff52f21186496ba6825b6e5
data/lib/atome/atome.rb CHANGED
@@ -19,7 +19,6 @@ class Atome
19
19
  #
20
20
  # end
21
21
 
22
-
23
22
  def initialize(new_atome = {}, &atomes_proc)
24
23
  # TODO: atome format should always be as followed : {value: 0.44, unit: :px, opt1: 554}
25
24
  # when using optimised version of atome you must type eg : a.set({left: {value: 33, unit: '%', reference: :center}})
@@ -38,8 +37,8 @@ class Atome
38
37
  # @language = :english
39
38
  # @callback = {}
40
39
  @tag = {}
41
- @tick={}
42
- @storage={}
40
+ @tick = {}
41
+ @storage = {}
43
42
  @behavior = {}
44
43
  @selected = false
45
44
  #@metrics = {}
@@ -48,49 +47,44 @@ class Atome
48
47
  @collect = {}
49
48
  @int8 = {}
50
49
  @css = {}
51
- @code={}
52
- @aid= new_atome[:aid] || identity_generator
53
- @controller_proc=[]
50
+ @code = {}
51
+ @aid = new_atome[:aid] || identity_generator
52
+ @controller_proc = []
54
53
  @id = new_atome[:id] || @aid
55
- Universe.atomes.each_value do |atome_f|
56
- # we affect the already existing atome to target
57
- next unless atome_f.id == @id
54
+ # if grab(@id)
55
+ # collapse({})
56
+ # puts "#{@id} already exists"
57
+ # else
58
+ Universe.atomes.each_value do |atome_f|
59
+ # we affect the already existing atome to target
60
+ next unless atome_f.id == @id
58
61
 
59
- new_atome[:affect].each do |affected|
60
- grab(affected).apply(@id)
62
+ new_atome[:affect].each do |affected|
63
+ grab(affected).apply(@id)
64
+ end if new_atome[:affect]
65
+ return false
61
66
  end
62
- return false
63
- end
64
- Universe.add_to_atomes(@aid, self)
65
- Universe.id_to_aid(@id, @aid)
66
- @type = new_atome[:type] || :element
67
- @attached = []
68
- @affect = []
69
- @category = []
70
- # @display = { mode: :default }
71
- # @backup={} # mainly used to restore particle when using grid /table /list display mode
72
- @html = HTML.new(@id, self)
73
- @headless = Headless.new(@id, self)
74
- @initialized={}
75
- @creator= Universe.current_user
76
- # now we store the proc in a an atome's property called :bloc
77
- new_atome[:code] = atomes_proc if atomes_proc
78
- # we reorder the hash
79
- reordered_atome = reorder_particles(new_atome)
80
- # FIXME : try to remove the condition below (it crash in the method : def generator ... in genesis.rb)
81
- collapse(reordered_atome)
82
- # end
83
- # puts "@initialized : #{Atome.instance_variable_get('@initialized')}"
84
- # puts "****> #{Atome.instance_variable_get('@initialized')}"
67
+ Universe.add_to_atomes(@aid, self)
68
+ Universe.id_to_aid(@id, @aid)
69
+ @type = new_atome[:type] || :element
70
+ @attached = []
71
+ @affect = []
72
+ @category = []
73
+ # @display = { mode: :default }
74
+ # @backup={} # mainly used to restore particle when using grid /table /list display mode
75
+ @html = HTML.new(@id, self)
76
+ @headless = Headless.new(@id, self)
77
+ @initialized = {}
78
+ @creator = Universe.current_user
79
+ # now we store the proc in a an atome's property called :bloc
80
+ new_atome[:code] = atomes_proc if atomes_proc
81
+ # we reorder the hash
82
+ reordered_atome = reorder_particles(new_atome)
83
+ # FIXME : try to remove the condition below (it crash in the method : def generator ... in genesis.rb)
85
84
 
86
- # if Atome.instance_variable_get('@initialized')
87
- # puts "-----> #{Atome.instance_variable_get('@initialized')}"
88
- # Atome.instance_variable_get('@initialized').each do |p_found, bloc|
89
- # # puts "==> #{p_found}"
90
- # # instance_exec.call
91
- # # instance_exec(p_found, &bloc) if bloc.is_a?(Proc)
92
- # end
85
+ collapse(reordered_atome)
93
86
  # end
87
+
94
88
  end
95
89
 
96
90
  def js
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ObjectExtension
3
+ require 'time'
4
4
 
5
+ module ObjectExtension
5
6
 
6
7
  def new(params, &bloc)
7
8
  # Genesis = Genesis.Genesis
8
9
  if params.key?(:atome)
9
- # if Universe.atome_list.include?(params[:atome])
10
- # puts "atome #{params[:atome]} already exist you can't create it"
11
- # else
12
- Universe.add_atomes_specificities params[:atome]
13
- Genesis.build_atome(params[:atome], &bloc)
10
+ Universe.add_atomes_specificities params[:atome]
11
+ Genesis.build_atome(params[:atome], &bloc)
14
12
  # end
15
13
  elsif params.key?(:particle)
16
14
  if Universe.particle_list[params[:particle]]
@@ -51,12 +49,12 @@ module ObjectExtension
51
49
  # bloc.call(option)
52
50
  # end
53
51
  elsif params.key?(:molecule)
54
- molecule=params[:molecule]
52
+ molecule = params[:molecule]
55
53
  Genesis.build_molecule(molecule, &bloc)
56
54
  Universe.add_to_molecule_list(molecule)
57
55
 
58
- # elsif params.key?(:applicaton)
59
- # alert params
56
+ # elsif params.key?(:applicaton)
57
+ # alert params
60
58
 
61
59
  # molecule=params[:molecule]
62
60
  # Genesis.build_molecule(molecule, &bloc)
@@ -66,7 +64,7 @@ module ObjectExtension
66
64
 
67
65
  tool_content = Atome.instance_exec(&bloc) if bloc.is_a?(Proc)
68
66
 
69
- Universe.tools[params[:tool]]=tool_content
67
+ Universe.tools[params[:tool]] = tool_content
70
68
  # Universe.tools[params[:tool]]=bloc
71
69
 
72
70
  elsif params.key?(:template)
@@ -86,55 +84,13 @@ end
86
84
  # atome extensions
87
85
  class Object
88
86
  include ObjectExtension
89
- # def new(params, &bloc)
90
- # # Genesis = Genesis.Genesis
91
- # if params.key?(:atome)
92
- # if Universe.atome_list.include?(params[:atome])
93
- # puts "atome #{params[:atome]} already exist you can't create it"
94
- # else
95
- # Universe.add_atomes_specificities params[:atome]
96
- # Genesis.build_atome(params[:atome], &bloc)
97
- # end
98
- # elsif params.key?(:particle)
99
- # if Universe.particle_list[params[:particle]]
100
- # puts "particle #{params[:particle]} already exist you can't create it"
101
- # else
102
- # Atome.instance_variable_set("@main_#{params[:particle]}", bloc)
103
- # # render indicate if the particle needs to be rendered
104
- # # store tell the system if it need to store the particle value
105
- # # type help the system what type of type the particle will receive and store
106
- # Genesis.build_particle(params[:particle], { render: params[:render], return: params[:return],
107
- # store: params[:store], type: params[:type],
108
- # category: params[:category] }, &bloc)
109
- # end
110
- #
111
- # elsif params.key?(:sanitizer)
112
- # Genesis.build_sanitizer(params[:sanitizer], &bloc)
113
- # elsif params.key?(:pre)
114
- # Atome.instance_variable_set("@pre_#{params[:pre]}", bloc)
115
- # elsif params.key?(:post)
116
- # Atome.instance_variable_set("@post_#{params[:post]}", bloc)
117
- # elsif params.key?(:after)
118
- # Atome.instance_variable_set("@after_#{params[:after]}", bloc)
119
- # elsif params.key?(:read)
120
- # Atome.instance_variable_set("@read_#{params[:read]}", bloc)
121
- # elsif params[:renderer]
122
- # renderer_found = params[:renderer]
123
- # if params[:specific]
124
- # Universe.set_atomes_specificities(params)
125
- # params[:specific] = "#{params[:specific]}_"
126
- # end
127
- # render_method = "#{renderer_found}_#{params[:specific]}#{params[:method]}"
128
- # Genesis.build_render(render_method, &bloc)
129
- # # elsif params.key?(:callback)
130
- # # particle_targetted = params[:callback]
131
- # # Atome.define_method("#{particle_targetted}_callback", option) do
132
- # # alert option
133
- # # bloc.call(option)
134
- # # end
135
- # end
136
- # end
137
-
87
+ def flash(msg)
88
+ flash_box=box({width: 235, height: 112})
89
+ flash_box.text(msg)
90
+ flash_box.touch(true) do
91
+ flash_box.delete({ recursive: true })
92
+ end
93
+ end
138
94
  def reorder_particles(hash_to_reorder)
139
95
  # we reorder the hash
140
96
  ordered_keys = %i[renderers id alien type attach int8 unit]
@@ -142,7 +98,7 @@ class Object
142
98
  ordered_part = ordered_keys.map { |k| [k, hash_to_reorder[k]] }.to_h
143
99
  other_part = hash_to_reorder.reject { |k, _| ordered_keys.include?(k) }
144
100
  # merge the parts to obtain an re-ordered hash
145
- ordered_part.merge(other_part)
101
+ ordered_part.merge(other_part)
146
102
  # reordered_hash
147
103
  end
148
104
 
@@ -155,16 +111,14 @@ class Object
155
111
  end
156
112
 
157
113
  def hook(a_id)
158
- a_id=a_id.to_sym
114
+ a_id = a_id.to_sym
159
115
  Universe.atomes[a_id]
160
116
  end
161
117
 
162
118
  def grab(id_to_get)
163
- id_to_get=id_to_get.to_sym
119
+ id_to_get = id_to_get.to_sym
164
120
  return if id_to_get == false
165
- aid_to_get= Universe.atomes_ids[id_to_get]
166
- # puts id_to_get.class
167
- # alert Universe.atomes
121
+ aid_to_get = Universe.atomes_ids[id_to_get]
168
122
  aid_to_get = '' if aid_to_get.instance_of? Array
169
123
  # id_to_get = id_to_get.to_sym
170
124
 
@@ -255,7 +209,7 @@ class Object
255
209
 
256
210
  return intervalId;
257
211
  JS
258
- repeat_id+1
212
+ repeat_id + 1
259
213
  end
260
214
 
261
215
  def stop(params)
@@ -266,16 +220,16 @@ class Object
266
220
  JS.eval(<<~JS)
267
221
  clearInterval(#{repeater_to_stop});
268
222
  JS
269
- elsif params.key?(:wait)
223
+ elsif params.key?(:wait)
270
224
  waiter_to_stop = params[:wait]
271
225
  JS.eval(<<~JS)
272
- clearTimeout(window.timeoutIds['#{waiter_to_stop}'])
226
+ clearTimeout(window.timeoutIds['#{waiter_to_stop}'])
273
227
  JS
274
228
  else
275
- puts "La clé :repeat n'existe pas dans params"
229
+ puts "msg from stop method: the :repeat key doesn't exist"
276
230
  end
277
231
  else
278
- puts "params n'est pas un hash"
232
+ puts "msg from stop method, this params is not a Hash"
279
233
  end
280
234
  end
281
235
 
@@ -462,7 +416,6 @@ class Object
462
416
  event = Native(native_event)
463
417
  event.preventDefault
464
418
  event.stopPropagation
465
- # puts 'File drop out of the special zonne'
466
419
  end
467
420
  end
468
421
  end
@@ -480,12 +433,12 @@ class Object
480
433
  particle_list.delete(:password)
481
434
  particle_list.delete(:selection)
482
435
  infos = {}
483
- particle_list[:css]=:poil
436
+ particle_list[:css] = :poil
484
437
  particle_list.each do |particle_found|
485
438
  infos[particle_found[0]] = send(particle_found[0]) unless send(particle_found[0]).nil?
486
439
  end
487
440
  # we convert CssProxy object to hash below
488
- infos[:css]=eval(infos[:css].to_s)
441
+ infos[:css] = eval(infos[:css].to_s)
489
442
  infos
490
443
  end
491
444
 
@@ -618,8 +571,6 @@ class Object
618
571
  # convert any foreign object (think HTML) to a pseudo atome objet , that embed foreign objet
619
572
  end
620
573
 
621
-
622
-
623
574
  def touch_allow(allow)
624
575
  if allow
625
576
  # Retire l'écouteur d'événements en utilisant la fonction globale
@@ -630,7 +581,6 @@ class Object
630
581
  end
631
582
  end
632
583
 
633
-
634
584
  def allow_copy(allow)
635
585
  if allow
636
586
  # allow selection and text copy
@@ -647,7 +597,7 @@ class Object
647
597
  end
648
598
  end
649
599
 
650
- def above(item, margin=6)
600
+ def above(item, margin = 6)
651
601
  pos = item.to_px(:bottom) + item.height + margin
652
602
  if item.display == :none
653
603
  33
@@ -656,7 +606,7 @@ class Object
656
606
  end
657
607
  end
658
608
 
659
- def below(item, margin=6)
609
+ def below(item, margin = 6)
660
610
  pos = item.to_px(:top) + item.to_px(:height) + margin
661
611
  if item.display == :none
662
612
  0
@@ -666,7 +616,7 @@ class Object
666
616
 
667
617
  end
668
618
 
669
- def after(item, margin=6)
619
+ def after(item, margin = 6)
670
620
  left_f = if item.left.instance_of?(Integer)
671
621
  item.left
672
622
  else
@@ -686,7 +636,7 @@ class Object
686
636
  end
687
637
  end
688
638
 
689
- def before(item, margin=6)
639
+ def before(item, margin = 6)
690
640
  pos = item.to_px(:right) + item.width + margin
691
641
  if item.display == :none
692
642
  0
@@ -695,6 +645,130 @@ class Object
695
645
  end
696
646
  end
697
647
 
648
+ # Helper method to store task configuration in localStorage
649
+ def store_task(name, config)
650
+ JS.global[:localStorage].setItem(name, config.to_json)
651
+ end
652
+
653
+ # Helper method to retrieve task configuration from localStorage
654
+ def retrieve_task(name)
655
+ config = JS.global[:localStorage].getItem(name)
656
+ config.nil? ? nil : JSON.parse(config)
657
+ end
658
+
659
+ # Helper method to retrieve all tasks from localStorage
660
+ def retrieve_all_tasks
661
+ tasks = []
662
+ local_storage = JS.global[:localStorage]
663
+ if Atome::host == "web-opal"
664
+ local_storage.each do |key|
665
+ value = local_storage.getItem(key)
666
+ if value
667
+ value = JSON.parse(value)
668
+ tasks << { name: key, config: value }
669
+ end
670
+ end
671
+ else
672
+ length = local_storage[:length].to_i
673
+ length.times do |i|
674
+ key = local_storage.call(:key, i)
675
+ value = local_storage.call(:getItem, key)
676
+ tasks << { name: key, config: JSON.parse(value.to_s) } if value
677
+ end
678
+ end
679
+ tasks
680
+ end
681
+
682
+ # Helper method to schedule a task
683
+ def schedule_task(name, years, month, day, hours, minutes, seconds, recurrence: nil, &block)
684
+ target_time = Time.new(years, month, day, hours, minutes, seconds)
685
+ now = Time.now
686
+
687
+ if target_time < now
688
+ schedule_recurrence(name, target_time, recurrence, &block)
689
+ else
690
+ seconds_until_target = target_time - now
691
+ wait_task = wait(seconds_until_target) do
692
+ block.call
693
+ schedule_recurrence(name, target_time, recurrence, &block) if recurrence
694
+ end
695
+ store_task(name, { wait: wait_task, target_time: target_time, recurrence: recurrence })
696
+ end
697
+ end
698
+
699
+ def schedule_recurrence(name, target_time, recurrence, &block)
700
+ now = Time.now
701
+ next_time = target_time
702
+
703
+ case recurrence
704
+ when :yearly
705
+ next_time += 365 * 24 * 60 * 60 while next_time <= now
706
+ when :monthly
707
+ next_time = next_time >> 1 while next_time <= now
708
+ when :weekly
709
+ next_time += 7 * 24 * 60 * 60 while next_time <= now
710
+ when :daily
711
+ next_time += 24 * 60 * 60 while next_time <= now
712
+ when :hourly
713
+ next_time += 60 * 60 while next_time <= now
714
+ when :minutely
715
+ next_time += 60 while next_time <= now
716
+ when :secondly
717
+ next_time += 1 while next_time <= now
718
+ when Hash
719
+ if recurrence[:weekly]
720
+ wday = recurrence[:weekly]
721
+ next_time += 7 * 24 * 60 * 60 while next_time <= now
722
+ next_time += 24 * 60 * 60 until next_time.wday == wday
723
+ elsif recurrence[:monthly]
724
+ week_of_month = recurrence[:monthly][:week]
725
+ wday = recurrence[:monthly][:wday]
726
+ while next_time <= now
727
+ next_month = next_time >> 1
728
+ next_time = Time.new(next_month.year, next_month.month, 1, target_time.hour, target_time.min, target_time.sec)
729
+ next_time += 24 * 60 * 60 while next_time.wday != wday
730
+ next_time += (week_of_month - 1) * 7 * 24 * 60 * 60
731
+ end
732
+ end
733
+ else
734
+ puts "Invalid recurrence option"
735
+ return
736
+ end
737
+
738
+ seconds_until_next = next_time - Time.now
739
+ wait_task = wait(seconds_until_next) do
740
+ block.call
741
+ schedule_recurrence(name, next_time, recurrence, &block)
742
+ end
743
+ store_task(name, { wait: wait_task, target_time: next_time, recurrence: recurrence })
744
+ end
745
+
746
+ # Helper method to stop a scheduled task
747
+ def stop_task(name)
748
+ task_config = retrieve_task(name)
749
+ return unless task_config
750
+
751
+ stop({ wait: task_config['wait'] })
752
+ JS.global[:localStorage].removeItem(name)
753
+ end
754
+
755
+ # Method to relaunch all tasks from localStorage
756
+ def relaunch_all_tasks
757
+ tasks = retrieve_all_tasks
758
+
759
+ tasks.each do |task|
760
+ name = task[:name]
761
+ config = task[:config]
762
+ target_time_found = config['target_time']
763
+ target_time = Time.parse(target_time_found)
764
+ recurrence_found = config['recurrence']
765
+ next unless recurrence_found
766
+ recurrence = config['recurrence'].is_a?(Hash) ? config['recurrence'].transform_keys(&:to_sym) : config['recurrence'].to_sym
767
+ schedule_task(name, target_time.year, target_time.month, target_time.day, target_time.hour, target_time.min, target_time.sec, recurrence: recurrence) do
768
+ puts "Relaunched task #{name}(add proc here)"
769
+ end
770
+ end
771
+ end
698
772
 
699
773
  end
700
774
 
@@ -720,7 +794,7 @@ class CssProxy
720
794
  @js[@parent_key][key] = value
721
795
  @current_atome.instance_variable_set('@css', { @parent_key => { key => value } })
722
796
  @css[@parent_key] = { key => value }
723
- puts "==> Clé parente: #{@parent_key}, Clé: #{key}, Valeur: #{value}"
797
+ puts "==> parent key: #{@parent_key}, Clé: #{key}, value: #{value}"
724
798
  else
725
799
  @style[key] = value
726
800
  @js[key] = value
@@ -738,8 +812,6 @@ class CssProxy
738
812
  bloc.call(parsed)
739
813
  end
740
814
 
741
-
742
-
743
815
  end
744
816
 
745
817
 
@@ -81,12 +81,8 @@ class Genesis
81
81
  # end
82
82
 
83
83
  Atome.define_method element do |params = nil, &user_proc|
84
- # if @id
85
- # alert "======> #{self.class}"
86
84
  @history[element] ||= []
87
- # else
88
- # alert "======> #{self.inspect}"
89
- # end
85
+
90
86
  if (params || params == false) && write_auth(element)
91
87
  params = particle_sanitizer(element, params, &user_proc)
92
88
  # the line below execute the main code when creating a new particle
@@ -1,7 +1,16 @@
1
1
  # frozen_string_literal: true
2
+ class Atome
3
+ def animation_callback(proc_sub_category, value=nil)
4
+ # puts "#{p◊roc_sub_category}"
5
+ proc_found = @animate_code[proc_sub_category]
6
+ # puts proc_found
7
+ instance_exec(value,&proc_found) if proc_found.is_a?(Proc)
8
+ end
9
+ end
2
10
 
3
11
  new({ particle: :touch, category: :event, type: :hash, store: false })
4
12
  new({ sanitizer: :touch }) do |params, user_bloc|
13
+ # user_params=params.dup
5
14
  if params
6
15
  # TODO: factorise code below
7
16
  @touch ||= {}
@@ -11,6 +20,7 @@ new({ sanitizer: :touch }) do |params, user_bloc|
11
20
  user_bloc =params.delete(:code) if params[:code]
12
21
  @touch_code[params.keys[0]] = user_bloc
13
22
  option = params[params.keys[0]]
23
+ @touch={ code: user_bloc}
14
24
  params.keys[0]
15
25
  else
16
26
  case params
@@ -47,7 +57,6 @@ new({ sanitizer: :touch }) do |params, user_bloc|
47
57
  @touch = false
48
58
  params
49
59
  end
50
-
51
60
  end
52
61
  new({ particle: :play, category: :event, type: :boolean, store: false })
53
62
  new({ sanitizer: :play }) do |params, user_bloc|
@@ -94,6 +103,7 @@ new({ sanitizer: :on }) do |params, user_bloc|
94
103
  params = if params.instance_of? Hash
95
104
  @on_code[:view_resize] = user_bloc
96
105
  option = params[params.keys[0]]
106
+ @resize={ code: user_bloc}
97
107
  :resize
98
108
  else
99
109
  case params
@@ -123,6 +133,7 @@ new({ sanitizer: :drag }) do |params, user_bloc|
123
133
  user_bloc =params.delete(:code) if params[:code]
124
134
  @drag_code[params.keys[0]] = user_bloc
125
135
  option = params[params.keys[0]]
136
+ @drag={ code: user_bloc}
126
137
  params.keys[0]
127
138
  else
128
139
  case params
@@ -177,6 +188,7 @@ new({ sanitizer: :drop }) do |params, user_bloc|
177
188
  user_bloc =params.delete(:code) if params[:code]
178
189
  @drop_code[params.keys[0]] = user_bloc
179
190
  option = params[params.keys[0]]
191
+ @drop={ code: user_bloc}
180
192
  params.keys[0]
181
193
  else
182
194
  case params
@@ -215,6 +227,8 @@ new({ sanitizer: :over }) do |params, user_bloc|
215
227
  user_bloc =params.delete(:code) if params[:code]
216
228
  @over_code[params.keys[0]] = user_bloc
217
229
  option = params[params.keys[0]]
230
+ @over={ code: user_bloc}
231
+
218
232
  params.keys[0]
219
233
  else
220
234
  case params
@@ -242,9 +256,6 @@ new({ sanitizer: :over }) do |params, user_bloc|
242
256
  params
243
257
 
244
258
  end
245
- # new({ particle: :sort }) do |_value, sort_proc|
246
- # @sort_proc = sort_proc
247
- # end
248
259
  new({ particle: :targets, category: :event, type: :string })
249
260
  new({ particle: :start, category: :event, type: :boolean })
250
261
  new({ pre: :start }) do |_value, user_proc|
@@ -261,9 +272,8 @@ new({ particle: :mass, category: :event, type: :int })
261
272
  new({ particle: :damping, category: :event, type: :int })
262
273
  new({ particle: :stiffness, category: :event, type: :int })
263
274
  new({ particle: :velocity, category: :event, type: :int })
264
- # new({ particle: :repeat, category: :event, type: :boolean })
265
275
  new({ particle: :ease, category: :event, type: :boolean })
266
- new(particle: :keyboard, category: :event, type: :hash, store: false)
276
+ new({ particle: :keyboard, category: :event, type: :hash, store: false })
267
277
  new({ sanitizer: :keyboard }) do |params, user_bloc|
268
278
  @keyboard ||= {}
269
279
  @keyboard_code ||= {}
@@ -277,6 +287,8 @@ new({ sanitizer: :keyboard }) do |params, user_bloc|
277
287
  @keyboard_code[params.keys[0]] = user_bloc
278
288
  option = params[params.keys[0]]
279
289
  params.keys[0]
290
+ @keyboard={ code: user_bloc}
291
+
280
292
  else
281
293
  case params
282
294
  when true
@@ -314,6 +326,8 @@ new({ sanitizer: :resize }) do |params, user_bloc|
314
326
  params = if params.instance_of? Hash
315
327
  @resize_code[:resize] = user_bloc
316
328
  option = params[params.keys[0]]
329
+ @resize={ code: user_bloc}
330
+
317
331
  :resize
318
332
  else
319
333
  case params
@@ -338,16 +352,6 @@ new({ particle: :overflow, category: :event, type: :boolean }) do |params, bloc|
338
352
  params
339
353
 
340
354
  end
341
-
342
- class Atome
343
- def animation_callback(proc_sub_category, value=nil)
344
- # puts "#{p◊roc_sub_category}"
345
- proc_found = @animate_code[proc_sub_category]
346
- # puts proc_found
347
- instance_exec(value,&proc_found) if proc_found.is_a?(Proc)
348
- end
349
- end
350
-
351
355
  new({ particle: :animate, category: :event, type: :hash }) do |params, proc|
352
356
  if params.instance_of? Hash
353
357
  params = { from: 0, to: 300, duration: 1000 }.merge(params)
@@ -364,7 +368,12 @@ new({ particle: :animate, category: :event, type: :hash }) do |params, proc|
364
368
 
365
369
  params
366
370
  end
367
-
368
- new ({ after: :animate }) do |params|
371
+ new({ after: :animate }) do |params|
369
372
  html.animate(params) unless params[:end] || params[:start]
370
373
  end
374
+
375
+
376
+ # new({ particle: :repeat, category: :event, type: :boolean })
377
+ # # new({ particle: :sort }) do |_value, sort_proc|
378
+ # # @sort_proc = sort_proc
379
+ # # end
@@ -2,7 +2,7 @@
2
2
 
3
3
  new({ particle: :renderers, category: :utility, type: :string })
4
4
  new({ particle: :code, category: :utility, type: :string, store: false }) do |params, code|
5
- @code[params]=code
5
+ @code[params] = code
6
6
  end
7
7
  # new({ particle: :run, category: :utility, type: :boolean }) do |params|
8
8
  # code_found = @code
@@ -10,9 +10,9 @@ end
10
10
  # end
11
11
 
12
12
  new({ particle: :run }) do |params, code|
13
- instance_exec(&params) if params.is_a?(Proc)
14
- code_found = @code[params]
15
- instance_exec(params, &code_found) if code_found.is_a?(Proc)
13
+ instance_exec(&params) if params.is_a?(Proc)
14
+ code_found = @code[params]
15
+ instance_exec(params, &code_found) if code_found.is_a?(Proc)
16
16
  end
17
17
 
18
18
  new({ particle: :target }) do |params|
@@ -27,10 +27,9 @@ new({ particle: :target }) do |params|
27
27
  end
28
28
  end
29
29
 
30
-
31
30
  # new({ particle: :broadcast })
32
31
 
33
- def delete_recursive(atome_id, force=false)
32
+ def delete_recursive(atome_id, force = false)
34
33
  return if grab(atome_id).tag && (grab(atome_id).tag[:persistent] || grab(atome_id).tag[:system]) unless force
35
34
 
36
35
  parent_id_found = grab(atome_id).attach
@@ -47,86 +46,95 @@ def delete_recursive(atome_id, force=false)
47
46
  end
48
47
 
49
48
  new({ particle: :delete, category: :utility, type: :boolean, render: false }) do |params|
50
- if params == true
51
49
 
52
- # We use the tag persistent to exclude color of system object and other default colors
53
- unless @tag && (@tag[:persistent] || @tag[:system])
50
+ basic_system_object = %i[view eDen black_matter intuition copy atome
51
+ user_view view_color shape_color
52
+ box_color invisible_color text_color circle_color back_selection
53
+ text_selection nil
54
+ ]
55
+
56
+ unless basic_system_object.include?(id) || id.nil?
57
+
58
+ if params == true
59
+ # We use the tag persistent to exclude color of system object and other default colors
60
+ unless @tag && (@tag[:persistent] || @tag[:system])
61
+ # if we are on a matrix we delete cells found & group found
62
+ cells.delete(true)
63
+ group.delete(true)
64
+ # now we detach the atome from it's parent
65
+ # now we init rendering
66
+ render(:delete, params)
67
+ # the machine delete the current atome from the universe
68
+ id_found = @id.to_sym
69
+ if @attach
70
+ parent_found = grab(@attach)
71
+ parent_found.attached.delete(id_found)
72
+ end
73
+ @affect&.each do |affected_atome|
74
+ affected_found = grab(affected_atome)
75
+ affected_found.apply.delete(id_found)
76
+ affected_found.refresh
77
+ end
78
+
79
+ # Universe.delete(@aid)
80
+ end
81
+ elsif params.instance_of? Hash
54
82
  # if we are on a matrix we delete cells found & group found
55
83
  cells.delete(true)
56
84
  group.delete(true)
57
- # now we detach the atome from it's parent
58
- # now we init rendering
59
- render(:delete, params)
60
- # the machine delete the current atome from the universe
61
- id_found = @id.to_sym
62
- if @attach
63
- parent_found = grab(@attach)
64
- parent_found.attached.delete(id_found)
65
- end
66
- @affect&.each do |affected_atome|
67
- affected_found = grab(affected_atome)
68
- affected_found.apply.delete(id_found)
69
- affected_found.refresh
70
- end
71
- Universe.delete(@aid)
72
- end
73
- # elsif params == :force
74
- # cells.delete(true)
75
- # group.delete(true)
76
- # # now we detach the atome from it's parent
77
- # # now we init rendering
78
- # render(:delete, params)
79
- # # the machine delete the current atome from the universe
80
- # id_found = @id.to_sym
81
- # if @attach
82
- # parent_found = grab(@attach)
83
- # parent_found.attached.delete(id_found)
84
- # end
85
- # @affect&.each do |affected_atome|
86
- # affected_found = grab(affected_atome)
87
- # affected_found.apply.delete(id_found)
88
- # affected_found.refresh
89
- # end
90
- # Universe.delete(@aid)
91
- elsif params.instance_of? Hash
92
- # if we are on a matrix we delete cells found & group found
93
- cells.delete(true)
94
- group.delete(true)
95
- if params[:recursive]
96
- unless grab(@id).tag && (grab(@id).tag[:persistent] || grab(@id).tag[:system])
85
+ if params[:recursive]
86
+ unless grab(@id).tag && (grab(@id).tag[:persistent] || grab(@id).tag[:system])
87
+ attached.each do |atttached_atomes|
88
+ delete_recursive(atttached_atomes)
89
+ end
90
+ # touch(:remove)
91
+ # render(:delete, params)
92
+ # Universe.delete(@aid)
93
+ end
94
+ elsif params[:force]
97
95
  attached.each do |atttached_atomes|
98
- delete_recursive(atttached_atomes)
96
+ # alert "attached : #{attached}"
97
+ delete_recursive(atttached_atomes, true)
98
+ end
99
+ # touch(:remove)
100
+ # render(:delete, params)
101
+ # Universe.delete(@aid)
102
+ else
103
+ # the machine try to find the sub particle id and remove it eg a.delete(monitor: :my_monitor) remove the monitor
104
+ # with id my_monitor
105
+ params.each do |param, value|
106
+ atome[param][value] = nil
99
107
  end
100
- touch(:remove)
101
- render(:delete, params)
102
- Universe.delete(@aid)
103
- end
104
- elsif params[:force]
105
- attached.each do |atttached_atomes|
106
- # alert "attached : #{attached}"
107
- delete_recursive(atttached_atomes, true)
108
108
  end
109
- touch(:remove)
110
- render(:delete, params)
111
- # alert "Universe : #{Universe.atomes[@aid]}"
112
- # alert "length = #{Universe.atomes.length}"
113
- Universe.delete(@aid)
114
- # alert "Universe : #{Universe.atomes.length}"
115
109
 
110
+ elsif Universe.atome_list.include?(params)
111
+ # we check if the params passed is an atome to treat it in a different way
112
+ puts "write code here : #{apply} , #{attached}"
116
113
  else
117
- # the machine try to find the sub particle id and remove it eg a.delete(monitor: :my_monitor) remove the monitor
118
- # with id my_monitor
119
- params.each do |param, value|
120
- atome[param][value] = nil
114
+ send(params, 0) unless params == :id
115
+ end
116
+ touch(:remove)
117
+ drag(false)
118
+ drop(false)
119
+ on(false)
120
+ keyboard(false)
121
+ resize(:remove)
122
+ overflow(:remove)
123
+
124
+ render(:delete, params)
125
+ Universe.delete(@aid)
126
+
127
+ exclusions = %i[@history @renderers @type @tag @html]
128
+
129
+ instance_variables.each do |i_var|
130
+ unless exclusions.include?(i_var)
131
+ instance_variable_set(i_var, nil)
121
132
  end
122
133
  end
123
134
 
124
- elsif Universe.atome_list.include?(params)
125
- # we check if the params passed is an atome to treat it in a different way
126
- puts "write code here : #{apply} , #{attached}"
127
- else
128
- send(params, 0) unless params == :id
135
+ instance_variable_set('@renderers', [])
129
136
  end
137
+
130
138
  end
131
139
 
132
140
  new({ particle: :clear, category: :utility, type: :boolean })
@@ -226,7 +234,7 @@ new({ particle: :duplicate, category: :utility, type: :string, store: false }) d
226
234
  end
227
235
  params[:attached] = attached_atomes
228
236
  infos_found = infos.dup
229
- keys_to_delete = [:history, :callback, :duplicate, :copy, :paste, :touch_code, :html, :attached, :aid]
237
+ keys_to_delete = %i[history callback duplicate copy paste touch_code html attached aid]
230
238
  keys_to_delete.each { |key| infos_found.delete(key) }
231
239
  new_atome_id = "#{@id}_copy_#{copy_number}".to_sym
232
240
  infos_found[:id] = new_atome_id
@@ -117,6 +117,11 @@ class Atome
117
117
 
118
118
  @initialized = {}
119
119
 
120
+
121
+ def recursive(_val)
122
+ #dummy method
123
+ end
124
+
120
125
  def help(particle, &doc)
121
126
  if doc
122
127
  Universe.set_help(particle, &doc)
@@ -149,7 +154,6 @@ class Atome
149
154
  def collapse(new_atome)
150
155
  initialized_procs = []
151
156
  initialized = Atome.initialized
152
-
153
157
  new_atome.each do |element, value|
154
158
  send(element, value)
155
159
  initialized_proc = initialized[element]
data/lib/atome/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  # return atome version
4
4
  class Atome
5
- VERSION = '0.5.7.3.3'
5
+ VERSION = '0.5.7.3.6'
6
6
  end
@@ -428,46 +428,127 @@ new(molecule: :matrix) do |params, &bloc|
428
428
  matrix_back
429
429
  end
430
430
 
431
- new(molecule: :page) do |params, &bloc|
432
- b = box({ color: :red, left: 99, drag: true })
433
- b.remove(:box_color)
434
- b.text(params)
431
+ new(molecule: :application) do |params, &bloc|
432
+ params ||= {}
433
+
434
+ color({ id: :app_color, red: 0.1, green: 0.3, blue: 0.1 })
435
+ # TODO : remove the patch below when possible
436
+ id_f = if params[:id]
437
+ params.delete(:id)
438
+ else
439
+ identity_generator
440
+ end
441
+ main_app = box({ id: id_f, width: :auto, height: :auto, top: 0, bottom: 0, left: 0, right: 0, apply: :app_color,
442
+ category: :application })
443
+ main_app.remove(:box_color)
444
+ main_app.instance_variable_set('@pages', {})
445
+ menu = params.delete(:menu)
446
+ main_app.box(menu.merge({ id: "#{id_f}_menu" })) if menu
447
+ params.each do |part_f, val_f|
448
+ main_app.send(part_f, val_f)
449
+ end
450
+ main_app
435
451
  end
436
452
 
437
- new(molecule: :application) do |params, &bloc|
453
+ new(molecule: :page) do |params, &bloc|
454
+ if params[:id]
455
+ id_f = params.delete(:id)
456
+ page_name=params.delete(:name)
457
+ @pages[id_f.to_sym] = params
458
+ else
459
+ puts "must send an id"
460
+ end
461
+ page_name= page_name || id_f
462
+ menu_f= grab("#{@id}_menu")
463
+ page_title=menu_f.text({ data: page_name })
464
+ page_title.touch(:down) do
465
+ show(id_f)
466
+ end
467
+
468
+ end
438
469
 
439
- main_page = box({ drag: true, width: :auto, height: :auto, top: 0, bottom: 0, left: 0, right: 0 })
470
+ new(molecule: :show) do |page_id, &bloc|
471
+ params = @pages[page_id.to_sym]
472
+ params ||= {}
473
+ footer = params.delete(:footer)
474
+ header = params.delete(:header)
475
+ left_side_bar = params.delete(:left_side_bar)
476
+ right_side_bar = params.delete(:right_side_bar)
477
+ # modules = params.delete(:modules)
478
+ basic_size = 30
479
+ attached.each do |page_id_found|
480
+ page_found = grab(page_id_found)
481
+ # puts "#{page_id_found} : #{page_found}"
482
+ page_found.delete({ recursive: true }) if page_found && page_found.category.include?(:page)
483
+ end
484
+ color({ id: :page_color, red: 0.1, green: 0.1, blue: 0.1 })
485
+ # TODO : remove the patch below when possible
486
+ id_f = if params[:id]
487
+ params.delete(:id)
488
+ else
489
+ "#{id_f}_#{identity_generator}"
490
+ end
491
+ main_page = box({ width: :auto, depth: -1, height: :auto, id: id_f, top: 0, bottom: 0, left: 0, right: 0, apply: :page_color, category: :page })
440
492
  main_page.remove(:box_color)
441
- main_page
442
493
 
443
- # def new(params, &bloc)
444
- # if params[:page]
445
- # site_found = grab(params[:page][:application])
446
- # site_found.clear(true)
447
- # page_id = params[:page][:name]
448
- # site_found.box({ id: page_id })
449
- # elsif params[:application]
450
- #
451
- # footer_header_size = 33
452
- # footer_header_color = color({ red: 0, green: 0, blue: 0, id: :footer_header_color })
453
- #
454
- # if params[:header]
455
- # top = footer_header_size
456
- # header = box({ left: 0, right: 0, width: :auto, top: 0, height: top, id: :header })
457
- # # header.attach(:footer_header_color)
458
- # else
459
- # top = 0
460
- # end
461
- # if params[:footer]
462
- # bottom = footer_header_size
463
- # box({ left: 0, right: 0, width: :auto, top: :auto, bottom: 0, height: bottom, id: :footer })
464
- # else
465
- # bottom = 0
466
- # end
467
- # box({ left: 0, right: 0, width: :auto, top: top, bottom: bottom, height: :auto, id: params[:application] })
468
- # elsif params[:module]
469
- #
470
- # end
471
- # super if defined?(super)
472
- # end
494
+ main_page.set(params)
495
+
496
+ if footer
497
+ new_footer = box({ left: 0, depth: -1, right: 0, width: :auto, top: :auto, bottom: 0, height: basic_size, category: :footer, id: "#{id_f}_footer" })
498
+ new_footer.remove(:box_color)
499
+ new_footer.set(footer)
500
+ end
501
+
502
+ if header
503
+ new_header = box({ left: 0, right: 0, depth: -1, width: :auto, top: 0, height: basic_size, category: :header, id: "#{id_f}_header" })
504
+ new_header.remove(:box_color)
505
+ new_header.set(header)
506
+ end
507
+
508
+ if right_side_bar
509
+ new_right_side_bar = box({ left: :auto, depth: -1, right: 0, width: basic_size, top: 0, bottom: 0, height: :auto, category: :right_side_bar, id: "#{id_f}_right_side_bar" })
510
+ new_right_side_bar.remove(:box_color)
511
+ new_right_side_bar.set(right_side_bar)
512
+ end
513
+
514
+ if left_side_bar
515
+ new_left_side_bar = box({ left: 0, right: :auto, depth: -1, width: basic_size, top: 0, bottom: 0, height: :auto, category: :left_side_bar, id: "#{id_f}_left_side_bar" })
516
+ new_left_side_bar.remove(:box_color)
517
+ new_left_side_bar.set(left_side_bar)
518
+ end
519
+
520
+ attached.each do |item_id_found|
521
+ item_found = grab(item_id_found)
522
+ if item_found&.category&.include?(:footer)
523
+ main_page.height(:auto)
524
+ main_page.bottom(item_found.height)
525
+ end
526
+ if item_found&.category&.include?(:header)
527
+ main_page.height(:auto)
528
+ main_page.top(item_found.height)
529
+ end
530
+
531
+ if item_found&.category&.include?(:right_side_bar)
532
+ main_page.width(:auto)
533
+ main_page.left(item_found.width)
534
+ if footer
535
+ grab("#{id_f}_footer").right(basic_size)
536
+ end
537
+ if header
538
+ grab("#{id_f}_header").right(basic_size)
539
+ end
540
+ end
541
+
542
+ if item_found&.category&.include?(:left_side_bar)
543
+ main_page.width(:auto)
544
+ main_page.right(item_found.width)
545
+ if footer
546
+ grab("#{id_f}_footer").left(basic_size)
547
+ end
548
+ if header
549
+ grab("#{id_f}_header").left(basic_size)
550
+ end
551
+ end
552
+ end
553
+ main_page
473
554
  end
@@ -1303,6 +1303,7 @@ class HTML
1303
1303
  proc_content = @touch_tap.call(event) if event_validation(@touch_tap)
1304
1304
  if proc_content.instance_of? Hash
1305
1305
  proc_content.each do |k, v|
1306
+ # alert "(#{@original_atome.id}, #{k}, #{v}, #{_option})"
1306
1307
  @original_atome.send(k, v)
1307
1308
  end
1308
1309
  end
@@ -1329,8 +1330,6 @@ class HTML
1329
1330
  end
1330
1331
  end
1331
1332
  end
1332
-
1333
- # end
1334
1333
  end
1335
1334
 
1336
1335
  def touch_double(_option)
@@ -6,7 +6,7 @@ class Atome
6
6
 
7
7
  def render(element, params, &user_proc)
8
8
 
9
- render_engines = @renderers
9
+ render_engines = @renderers || []
10
10
  render_engines.each do |render_engine|
11
11
  # in case we found an exception the method call will have the form, example for color top : html_color_top
12
12
  exception_found = "#{Universe.get_atomes_specificities[type][element]}"
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ a = application({
5
+ id: :arp,
6
+ margin: 3,
7
+ # circle: { id: :test, color: :red },
8
+ menu: { width: 220, height: 33, depth: 333, color: :black },
9
+ })
10
+
11
+ page1_code = lambda do |back|
12
+ alert :kooly
13
+ end
14
+
15
+ verif = lambda do
16
+ b = box({ id: :ty, left: 90, top: 90 })
17
+ b.touch(true) do
18
+ alert grab(:mod_1).touch
19
+ end
20
+
21
+ # a=grab('page2').circle({id: :heu, color: :black})
22
+ # a.color(:red)
23
+ # alert 'ok'
24
+ end
25
+
26
+ page1 = {
27
+ id: :page1,
28
+ color: :cyan,
29
+ name: :accueil,
30
+ footer: { color: :green, height: 22 },
31
+ header: { color: :yellow },
32
+ left_side_bar: { color: :yellowgreen },
33
+ right_side_bar: { color: :blue },
34
+ # box: { id: :mod_1, touch: {tap: true, code: page1_code} }
35
+ }
36
+
37
+ color({ id: :titi, red: 1 })
38
+ page2 = { id: :page2,
39
+ color: :white,
40
+ # apply: :titi,
41
+ run: verif,
42
+ # drag: true,
43
+ box: { id: :mod_1, left: 333, top: 123, touch: { down: true, code: page1_code } }
44
+
45
+ }
46
+
47
+ page3 = { id: :page3,
48
+ color: :red,
49
+ # run: verif,
50
+ # box: { id: :mod_1,left: 333, touch: {tap: :down, code: page1_code} }
51
+ }
52
+
53
+ page0 = { id: :page0,
54
+ color: :purple,
55
+
56
+ }
57
+ a.page(page1)
58
+ a.page(page2)
59
+ a.page(page3)
60
+ # wait 1 do
61
+ # a.page(page2)
62
+ # wait 1 do
63
+ # a.page(page1)
64
+ # puts 'second load'
65
+ # wait 5 do
66
+ # a.page(page3)
67
+ # wait 5 do
68
+ # a.page(page2)
69
+ # puts 'third load'
70
+ # end
71
+ # end
72
+ # end
73
+ # end
74
+ # c=grab(:page1).circle({left: 99})
75
+ # c.touch(true) do
76
+ # alert grab(:mod_1).inspect
77
+ # end
78
+
79
+ # wait 1 do
80
+ # a.page(page2)
81
+ # end
82
+ # wait 2 do
83
+ # a.page(page1)
84
+ # end
85
+ #
86
+ # wait 3 do
87
+ # a.page(page2)
88
+ # end
89
+ #
90
+ # # wait 5 do
91
+ # # a.page(page0)
92
+ # # end
93
+ # #
94
+ # # wait 6 do
95
+ # # a.page(page1)
96
+ # # end
97
+
98
+ # wait 4 do
99
+ # cc=box
100
+ # cc.touch(true) do
101
+ # alert grab(:heu).inspect
102
+ # end
103
+ # end
104
+
105
+ # a=lambda do |_val|
106
+ # grab(:testing).color(:red)
107
+ # wait 1 do
108
+ # grab(:testing).delete({recursive: true})
109
+ # end
110
+ # end
111
+ #
112
+ # c=circle
113
+ # c.touch(true) do
114
+ # b=box({id: :testing, left: 99})
115
+ # b.touch({ tap: true , code: a})
116
+ # end
117
+ # wait 1 do
118
+ a.show(:page1)
119
+ # # alert :kool
120
+ # end
@@ -1,132 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'time'
4
- # Helper method to store task configuration in localStorage
5
- def store_task(name, config)
6
- JS.global[:localStorage].setItem(name, config.to_json)
7
- end
8
-
9
- # Helper method to retrieve task configuration from localStorage
10
- def retrieve_task(name)
11
- config = JS.global[:localStorage].getItem(name)
12
- config.nil? ? nil : JSON.parse(config)
13
- end
14
-
15
- # Helper method to retrieve all tasks from localStorage
16
- def retrieve_all_tasks
17
- tasks = []
18
- local_storage = JS.global[:localStorage]
19
- if Atome::host == "web-opal"
20
- local_storage.each do |key|
21
- value = local_storage.getItem(key)
22
- if value
23
- value= JSON.parse(value)
24
- tasks << { name: key, config:value }
25
- end
26
- end
27
- else
28
- length = local_storage[:length].to_i
29
- length.times do |i|
30
- key = local_storage.call(:key, i)
31
- value = local_storage.call(:getItem, key)
32
- tasks << { name: key, config: JSON.parse(value.to_s) } if value
33
- end
34
- end
35
- tasks
36
- end
37
-
38
- # Helper method to schedule a task
39
- def schedule_task(name, years, month, day, hours, minutes, seconds, recurrence: nil, &block)
40
- target_time = Time.new(years, month, day, hours, minutes, seconds)
41
- now = Time.now
42
-
43
- if target_time < now
44
- schedule_recurrence(name, target_time, recurrence, &block)
45
- else
46
- seconds_until_target = target_time - now
47
- wait_task = wait(seconds_until_target) do
48
- block.call
49
- schedule_recurrence(name, target_time, recurrence, &block) if recurrence
50
- end
51
- store_task(name, { wait: wait_task, target_time: target_time, recurrence: recurrence })
52
- end
53
- end
54
-
55
- def schedule_recurrence(name, target_time, recurrence, &block)
56
- now = Time.now
57
- next_time = target_time
58
-
59
- case recurrence
60
- when :yearly
61
- next_time += 365 * 24 * 60 * 60 while next_time <= now
62
- when :monthly
63
- next_time = next_time >> 1 while next_time <= now
64
- when :weekly
65
- next_time += 7 * 24 * 60 * 60 while next_time <= now
66
- when :daily
67
- next_time += 24 * 60 * 60 while next_time <= now
68
- when :hourly
69
- next_time += 60 * 60 while next_time <= now
70
- when :minutely
71
- next_time += 60 while next_time <= now
72
- when :secondly
73
- next_time += 1 while next_time <= now
74
- when Hash
75
- if recurrence[:weekly]
76
- wday = recurrence[:weekly]
77
- next_time += 7 * 24 * 60 * 60 while next_time <= now
78
- next_time += 24 * 60 * 60 until next_time.wday == wday
79
- elsif recurrence[:monthly]
80
- week_of_month = recurrence[:monthly][:week]
81
- wday = recurrence[:monthly][:wday]
82
- while next_time <= now
83
- next_month = next_time >> 1
84
- next_time = Time.new(next_month.year, next_month.month, 1, target_time.hour, target_time.min, target_time.sec)
85
- next_time += 24 * 60 * 60 while next_time.wday != wday
86
- next_time += (week_of_month - 1) * 7 * 24 * 60 * 60
87
- end
88
- end
89
- else
90
- puts "Invalid recurrence option"
91
- return
92
- end
93
-
94
- seconds_until_next = next_time - Time.now
95
- wait_task = wait(seconds_until_next) do
96
- block.call
97
- schedule_recurrence(name, next_time, recurrence, &block)
98
- end
99
- store_task(name, { wait: wait_task, target_time: next_time, recurrence: recurrence })
100
- end
101
-
102
- # Helper method to stop a scheduled task
103
- def stop_task(name)
104
- task_config = retrieve_task(name)
105
- return unless task_config
106
-
107
- stop({ wait: task_config['wait'] })
108
- JS.global[:localStorage].removeItem(name)
109
- end
110
-
111
- # Method to relaunch all tasks from localStorage
112
- def relaunch_all_tasks
113
- tasks = retrieve_all_tasks
114
-
115
- tasks.each do |task|
116
- name = task[:name]
117
- config = task[:config]
118
- target_time_found = config['target_time']
119
- target_time = Time.parse(target_time_found)
120
- recurrence_found = config['recurrence']
121
- next unless recurrence_found
122
- recurrence = config['recurrence'].is_a?(Hash) ? config['recurrence'].transform_keys(&:to_sym) : config['recurrence'].to_sym
123
- puts "found : #{name}, #{target_time.year}, #{target_time.month}, #{target_time.day}, #{target_time.hour}, #{target_time.min}, #{target_time.sec}, recurrence: #{recurrence}"
124
- schedule_task(name, target_time.year, target_time.month, target_time.day, target_time.hour, target_time.min, target_time.sec, recurrence: recurrence) do
125
- puts "Relaunched task #{name}"
126
- end
127
- end
128
- end
129
-
130
3
  ######## check
131
4
 
132
5
  # Relaunch all tasks
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7.3.3
4
+ version: 0.5.7.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Eric Godard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-09 00:00:00.000000000 Z
11
+ date: 2024-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -536,6 +536,7 @@ files:
536
536
  - vendor/assets/application/examples/allow_system_right_click.rb
537
537
  - vendor/assets/application/examples/alternate.rb
538
538
  - vendor/assets/application/examples/animation.rb
539
+ - vendor/assets/application/examples/applications.rb
539
540
  - vendor/assets/application/examples/apply.rb
540
541
  - vendor/assets/application/examples/atome.rb
541
542
  - vendor/assets/application/examples/atome_particle_validation.rb