glimmer-cw-cdatetime-nebula 1.4.0.2.0 → 1.5.0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,281 @@
1
+ require 'glimmer/swt/widget_proxy'
2
+ #
3
+ module Glimmer
4
+ module SWT
5
+ class CDateTimeProxy < WidgetProxy
6
+ class << self
7
+ def create(keyword, parent, args, block)
8
+ # TODO support :tab_fields style
9
+ # TODO support :border style
10
+ # TODO support :compact style
11
+ # TODO support :spinner style
12
+ # TODO support :date_medium and :date_long styles
13
+ # TODO support :time_medium style
14
+ # TODO support :CLOCK_24_HOUR style in addition to :CLOCK_12_HOUR
15
+ # TODO support :BUTTON_ALWAYS, :BUTTON_AUTO, :BUTTON_MANUAL, :BUTTON_NEVER, :BUTTON_LEFT, and :BUTTON_RIGHT styles
16
+ # TODO support "Today" functionality
17
+ # TODO support pattern functionality
18
+ if [keyword].include_any?('c_date', 'c_date_drop_down', 'c_date_spinner', 'c_date_compact')
19
+ args += [:date_short]
20
+ end
21
+ if [keyword].include_any?('c_time', 'c_time_drop_down', 'c_time_spinner', 'c_time_compact')
22
+ args += [:time_short]
23
+ end
24
+ if keyword.end_with?('_drop_down')
25
+ args += [:drop_down]
26
+ elsif keyword.end_with?('_spinner')
27
+ args += [:spinner]
28
+ elsif keyword.end_with?('_compact')
29
+ args += [:compact]
30
+ else
31
+ args += [:simple]
32
+ end
33
+
34
+ new(parent, args, block)
35
+ end
36
+ end
37
+
38
+ def initialize(parent, args, block)
39
+ super(parent, args, block)
40
+ post_add_content if block.nil?
41
+ end
42
+
43
+ def post_add_content
44
+ if time?
45
+ clocklet
46
+ if drop_down?
47
+ time_button_dom_element.on('click') do |event|
48
+ `clocklet.open(document.getElementById(#{input_id}))`
49
+ end
50
+ end
51
+ else
52
+ options = {
53
+ changeMonth: true,
54
+ changeYear: true,
55
+ }
56
+ if drop_down?
57
+ options = {
58
+ showOn: 'both',
59
+ buttonImage: 'assets/glimmer/images/calendar.gif',
60
+ buttonImageOnly: true,
61
+ buttonText: 'Select date',
62
+ }
63
+ end
64
+ input_dom_element.datepicker(options)
65
+ end
66
+ selection_value = self.selection
67
+ @added_content = true
68
+ self.selection = selection_value
69
+ end
70
+
71
+ def clocklet
72
+ unless defined?(@@clocklet_default_options_set)
73
+ `clocklet.defaultOptions.appendTo = 'parent'`
74
+ `clocklet.defaultOptions.format = 'hh:mm A'`
75
+ @@clocklet_default_options_set = true
76
+ end
77
+ if simple?
78
+ @clocklet ||= Native(`clocklet.inline(document.getElementById(#{clock_id}), {input: document.getElementById(#{input_id})})`)
79
+ end
80
+ end
81
+
82
+ def date?
83
+ args.to_a.include_any?(:date_short, :date_medium, :date_long)
84
+ end
85
+
86
+ def time?
87
+ args.to_a.include_any?(:time_short, :time_medium)
88
+ end
89
+
90
+ def date_time?
91
+ !date? && !time?
92
+ end
93
+
94
+ def drop_down?
95
+ args.to_a.include?(:drop_down)
96
+ end
97
+
98
+ def simple?
99
+ args.to_a.include?(:simple)
100
+ end
101
+
102
+ def compact?
103
+ args.to_a.include?(:compact)
104
+ end
105
+
106
+ def spinner?
107
+ args.to_a.include?(:spinner)
108
+ end
109
+
110
+ def selection
111
+ if @added_content
112
+ default_date = DateTime.new if @selection.nil?
113
+ default_year = @selection&.year || default_date.year
114
+ default_month = @selection&.month || default_date.month
115
+ default_day = @selection&.day || default_date.day
116
+ default_hour = @selection&.hour || default_date.hour
117
+ default_min = @selection&.min || default_date.min
118
+ default_sec = @selection&.sec || default_date.sec
119
+ if time?
120
+ time_string = input_dom_element.val
121
+ _, current_hour, current_min, am_pm = time_string.match(/(\d{1,2})\:(\d{1,2})[ ]?([APap]?\.?[Mm]?\.?)/).to_a
122
+ current_hour ||= default_hour
123
+ current_min ||= default_min
124
+ current_hour = current_hour.to_i
125
+ am_pm = am_pm.to_s.gsub('.', '').upcase
126
+ current_hour += 12 if am_pm == 'PM'
127
+ current_min = current_min.to_i
128
+ @selection = DateTime.new(default_year, default_month, default_day, current_hour, current_min, default_sec)
129
+ else
130
+ @selection = DateTime.new(input_dom_element.datepicker('getDate')&.year.to_i, input_dom_element.datepicker('getDate')&.month.to_i, input_dom_element.datepicker('getDate')&.day.to_i, default_hour, default_min, default_sec)
131
+ end
132
+ @selection = @selection&.to_datetime
133
+ else
134
+ @initial_selection
135
+ end
136
+ end
137
+
138
+ def selection=(value)
139
+ if @added_content
140
+ @selection = value&.to_datetime || DateTime.new
141
+ if time?
142
+ formatted_time = @selection.strftime('%I:%M %p')
143
+ if drop_down? || spinner? || compact?
144
+ input_dom_element.val(formatted_time)
145
+ else
146
+ clocklet.value(formatted_time)
147
+ end
148
+ else
149
+ input_dom_element.datepicker('setDate', @selection.to_time)
150
+ end
151
+ else
152
+ @initial_selection = value
153
+ end
154
+ end
155
+
156
+ def observation_request_to_event_mapping
157
+ {
158
+ 'on_widget_selected' => [
159
+ { # time
160
+ event: 'input',
161
+ },
162
+ { # date
163
+ event: 'change',
164
+ },
165
+ ],
166
+ }
167
+ end
168
+
169
+ def listener_path
170
+ input_path
171
+ end
172
+
173
+ def time_button_id
174
+ "#{id}-time-button"
175
+ end
176
+
177
+ def time_button_class
178
+ "#{name}-time-button"
179
+ end
180
+
181
+ def time_button_path
182
+ "#{path} ##{time_button_id}"
183
+ end
184
+
185
+ def time_button_dom_element
186
+ Document.find(time_button_path)
187
+ end
188
+
189
+ def element
190
+ 'span'
191
+ end
192
+
193
+ def input_id
194
+ "#{id}-input"
195
+ end
196
+
197
+ def input_class
198
+ "#{name}-input"
199
+ end
200
+
201
+ def input_path
202
+ "#{path} ##{input_id}"
203
+ end
204
+
205
+ def input_dom_element
206
+ Document.find(input_path)
207
+ end
208
+
209
+ def clock_id
210
+ "#{id}-clock"
211
+ end
212
+
213
+ def clock_class
214
+ "#{name}-clock"
215
+ end
216
+
217
+ def clock_path
218
+ "#{path} .clocklet"
219
+ end
220
+
221
+ def clock_dom_element
222
+ Document.find(clock_path)
223
+ end
224
+
225
+ def dom
226
+ input_element = date? && simple? ? 'div' : 'input'
227
+ input_class_value = "#{input_class} hide" if time? && simple?
228
+ input_attributes = {type: 'text', id: input_id, class: input_class_value}
229
+ input_attributes['data-clocklet'] = 'format: hh:mm A; appendTo: parent;' if time?
230
+ the_class = name
231
+ the_class += ' simple' if simple?
232
+ the_class += ' drop-down' if drop_down?
233
+ the_class += ' compact' if compact?
234
+ the_class += ' spinner' if spinner?
235
+ @dom ||= html {
236
+ span(id: id, class: the_class) {
237
+ style {
238
+ css {
239
+ s('.c-date-time.compact .clocklet, .c-date-time.spinner .clocklet') {
240
+ pv 'display', 'none'
241
+ }
242
+ }
243
+ }
244
+ send(input_element, input_attributes)
245
+ div(id: clock_id, class: clock_class) if time? && simple?
246
+ button(id: time_button_id, class: time_button_class, style: "border: none; background: url(assets/glimmer/images/ui-icons_222222_256x240.png) -80px, -96px; width: 16px; height: 16px;") if time? && drop_down?
247
+ }
248
+ }.to_s
249
+ end
250
+
251
+ def widget_property_listener_installers
252
+ super.merge(
253
+ CDateTimeProxy => {
254
+ :selection => lambda do |observer|
255
+ on_widget_selected { |selection_event|
256
+ observer.call(selection)
257
+ }
258
+ end
259
+ },
260
+
261
+ )
262
+ end
263
+ end
264
+
265
+ # Aliases: `date`, `date_drop_down`, `time`, and `calendar`
266
+ # TODO
267
+ CDateProxy = CDateTimeProxy
268
+ CDateDropDownProxy = CDateTimeProxy
269
+ CDateSpinnerProxy = CDateTimeProxy
270
+ CDateCompactProxy = CDateTimeProxy
271
+ CTimeProxy = CDateTimeProxy
272
+ CTimeDropDownProxy = CDateTimeProxy
273
+ CTimeSpinnerProxy = CDateTimeProxy
274
+ CTimeCompactProxy = CDateTimeProxy
275
+ CDateTimeDropDownProxy = CDateTimeProxy
276
+ CDateTimeSpinnerProxy = CDateTimeProxy
277
+ CDateTimeCompactProxy = CDateTimeProxy
278
+
279
+ end
280
+
281
+ end
@@ -0,0 +1 @@
1
+ # TODO
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2020 - Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -19,16 +19,25 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require_relative '../../lib/glimmer-cw-cdatetime-nebula'
22
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
23
+
24
+ require 'glimmer-cw-cdatetime-nebula'
23
25
 
24
26
  class CDateTimeGallery
27
+ class Person
28
+ attr_accessor :date_of_birth
29
+ end
30
+
25
31
  include Glimmer
26
32
 
27
33
  def open
28
- shell {
34
+ person = Person.new
35
+ person.date_of_birth = DateTime.new(2013, 7, 12, 18, 37, 23)
36
+
37
+ shell {
29
38
  grid_layout(4, false) {
30
39
  vertical_spacing 20
31
- }
40
+ }
32
41
  text 'Nebula CDateTime Glimmer Custom Widget Gallery'
33
42
 
34
43
  label {
@@ -41,8 +50,8 @@ class CDateTimeGallery
41
50
 
42
51
  tab_folder {
43
52
  tab_item {
44
- grid_layout 2, false
45
- text 'Plain'
53
+ grid_layout 2, false
54
+ text 'Simple'
46
55
 
47
56
  label {
48
57
  text 'c_date_time'
@@ -60,7 +69,9 @@ class CDateTimeGallery
60
69
  text 'c_time'
61
70
  font name: 'Consolas', height: 14
62
71
  }
63
- c_time
72
+ c_time {
73
+ selection bind(person, :date_of_birth)
74
+ }
64
75
  }
65
76
 
66
77
  tab_item {
@@ -89,11 +100,12 @@ class CDateTimeGallery
89
100
  }
90
101
  c_time_drop_down {
91
102
  layout_data(:fill, :center, true, true)
103
+ selection bind(person, :date_of_birth)
92
104
  }
93
105
  }
94
106
 
95
107
  tab_item {
96
- grid_layout 2, false
108
+ grid_layout 2, false
97
109
  text 'Spinner'
98
110
 
99
111
  label {
@@ -118,11 +130,12 @@ class CDateTimeGallery
118
130
  }
119
131
  c_time_spinner {
120
132
  layout_data(:fill, :center, true, true)
133
+ selection bind(person, :date_of_birth)
121
134
  }
122
135
  }
123
136
 
124
137
  tab_item {
125
- grid_layout 2, false
138
+ grid_layout 2, false
126
139
  text 'Compact'
127
140
 
128
141
  label {
@@ -147,11 +160,12 @@ class CDateTimeGallery
147
160
  }
148
161
  c_time_compact {
149
162
  layout_data(:fill, :center, true, true)
163
+ selection bind(person, :date_of_birth)
150
164
  }
151
- }
165
+ }
152
166
  }
153
- }.open
154
- end
167
+ }.open
168
+ end
155
169
  end
156
170
 
157
171
  CDateTimeGallery.new.open
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-cw-cdatetime-nebula
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.2.0
4
+ version: 1.5.0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-17 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.6.8
18
+ version: 4.17.10.0
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
- version: 2.0.0
21
+ version: 5.0.0.0
22
22
  name: glimmer-dsl-swt
23
- type: :runtime
24
23
  prerelease: false
24
+ type: :runtime
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.6.8
29
+ version: 4.17.10.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 2.0.0
32
+ version: 5.0.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
@@ -37,8 +37,8 @@ dependencies:
37
37
  - !ruby/object:Gem::Version
38
38
  version: 3.5.0
39
39
  name: rspec
40
- type: :development
41
40
  prerelease: false
41
+ type: :development
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
@@ -51,8 +51,8 @@ dependencies:
51
51
  - !ruby/object:Gem::Version
52
52
  version: 2.3.9
53
53
  name: jeweler
54
- type: :development
55
54
  prerelease: false
55
+ type: :development
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - '='
@@ -65,30 +65,15 @@ dependencies:
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  name: simplecov
68
- type: :development
69
68
  prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '0'
75
- - !ruby/object:Gem::Dependency
76
- requirement: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: '0'
81
- name: glimmer-cs-gladiator
82
69
  type: :development
83
- prerelease: false
84
70
  version_requirements: !ruby/object:Gem::Requirement
85
71
  requirements:
86
72
  - - ">="
87
73
  - !ruby/object:Gem::Version
88
74
  version: '0'
89
75
  description: Nebula CDateTime Widget - Glimmer Custom Widget - A Date and Time selection
90
- widget that can be used in a plain (graphical), dropdown, spinner, or compact text
91
- style.
76
+ widget that can be used in a simple, dropdown, spinner, or compact style.
92
77
  email: andy.am@gmail.com
93
78
  executables: []
94
79
  extensions: []
@@ -96,17 +81,25 @@ extra_rdoc_files:
96
81
  - LICENSE.txt
97
82
  - README.md
98
83
  files:
84
+ - CHANGELOG.md
99
85
  - LICENSE.txt
100
86
  - README.md
101
87
  - VERSION
88
+ - app/assets/stylesheets/glimmer_cw_cdatetime_nebula/clocklet.min.css
89
+ - app/assets/stylesheets/glimmer_cw_cdatetime_nebula/glimmer_cw_cdatetime_nebula.css
102
90
  - lib/glimmer-cw-cdatetime-nebula.rb
103
91
  - lib/glimmer-cw-cdatetime-nebula/ext/glimmer/dsl/swt/cdt_expression.rb
104
92
  - lib/glimmer-cw-cdatetime-nebula/ext/glimmer/swt/c_date_time_proxy.rb
105
93
  - lib/glimmer-cw-cdatetime-nebula/ext/glimmer/swt/cdt_proxy.rb
94
+ - lib/glimmer-cw-cdatetime-nebula/vendor/clocklet.min.js
95
+ - lib/glimmer_cw_cdatetime_nebula/engine.rb
106
96
  - lib/views/nebula/c_date_time.rb
97
+ - opal/glimmer-cw-cdatetime-nebula/ext/glimmer/cdt.rb
98
+ - opal/glimmer-cw-cdatetime-nebula/ext/glimmer/swt/c_date_time_proxy.rb
99
+ - opal/views/nebula/c_date_time.rb
107
100
  - samples/nebula/c_date_time_gallery.rb
108
- - vendor/nebula/org.eclipse.nebula.cwt_1.1.0.jar
109
- - vendor/nebula/org.eclipse.nebula.widgets.cdatetime_1.4.0.jar
101
+ - vendor/nebula/org.eclipse.nebula.cwt_1.1.0.202007241204.jar
102
+ - vendor/nebula/org.eclipse.nebula.widgets.cdatetime_1.5.0.202007241204.jar
110
103
  homepage: http://github.com/AndyObtiva/glimmer-cw-cdatetime-nebula
111
104
  licenses:
112
105
  - MIT
@@ -115,6 +108,7 @@ post_install_message:
115
108
  rdoc_options: []
116
109
  require_paths:
117
110
  - lib
111
+ - opal
118
112
  required_ruby_version: !ruby/object:Gem::Requirement
119
113
  requirements:
120
114
  - - ">="
@@ -126,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
120
  - !ruby/object:Gem::Version
127
121
  version: '0'
128
122
  requirements: []
129
- rubygems_version: 3.0.6
123
+ rubygems_version: 3.1.4
130
124
  signing_key:
131
125
  specification_version: 4
132
126
  summary: Nebula CDateTime Widget - Glimmer Custom Widget