timemapjs-rails 0.0.4

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66fe97ef12231d5e31ca7fda8c24748b489e26b4
4
+ data.tar.gz: c941f95076f6a7ad75440f3098531d135a15e017
5
+ SHA512:
6
+ metadata.gz: 71379a7899be819e4c3b7f5b6e2b42397c5e1f95d9fac07689f0f22ebcf8c8d6702d2a724509be2ec455a8d8a095f6ec825b5f7dedc3adc085a0cc9a98cb3dc0
7
+ data.tar.gz: 18250d5d119a5c1db90c732b26de7063f7c90b7e98f2241e321bddf33638855b7e44fecd70b0a7a79026d551c05a3736f410f93d338dfffc3575eed6b92b8443
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in timemapjs-rails.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ # Timemapjs::Rails
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/timemapjs/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'timemapjs-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install timemapjs-rails
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/timemapjs-rails.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "timemapjs/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require "timemapjs/rails"
@@ -0,0 +1,7 @@
1
+ require "timemapjs/rails/engine"
2
+ require "timemapjs/rails/version"
3
+
4
+ module Timemapjs
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Timemapjs
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Timemapjs
2
+ module Rails
3
+ VERSION = "0.0.4"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/timemapjs/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "timemapjs-rails"
6
+ spec.version = Timemapjs::Rails::VERSION
7
+ spec.authors = ["Artem Levenkov"]
8
+
9
+ spec.summary = "time map"
10
+ spec.homepage = "https://github.com/bitia-ru/timemap.git"
11
+ spec.license = 'MIT'
12
+
13
+ spec.add_dependency "jquery-rails", '>= 2.0'
14
+
15
+ spec.files = ["lib/timemapjs-rails.rb","lib/timemapjs/rails.rb","lib/timemapjs/rails/engine.rb",
16
+ "lib/timemapjs/rails/version.rb","vendor/assets/javascripts/timemapjs.js","vendor/assets/stylesheets/timemapjs.css",
17
+ "Gemfile","Rakefile","README.md","timemapjs-rails.gemspec"]
18
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
+ spec.require_paths = 'lib'
20
+
21
+ end
@@ -0,0 +1,399 @@
1
+ function log(msg)
2
+ {
3
+ $('#logger').append('<p>' + msg + '</p>');
4
+ }
5
+
6
+ function clearSelection()
7
+ {
8
+ if (window.getSelection) {
9
+ if (window.getSelection().empty) { // Chrome
10
+ window.getSelection().empty();
11
+ } else if (window.getSelection().removeAllRanges) { // Firefox
12
+ window.getSelection().removeAllRanges();
13
+ }
14
+ } else if (document.selection) { // IE?
15
+ document.selection.empty();
16
+ }
17
+ }
18
+
19
+ function TimeMapView_onMouseDown(event) {
20
+ self = event.data.self;
21
+
22
+ }
23
+
24
+ function TimeMapView(e, m)
25
+ {
26
+ this.e = e;
27
+ this.m = m;
28
+
29
+ this.cellSize = 24;
30
+ this.headersWidth = 34;
31
+ this.cells = [];
32
+
33
+ this.quant = 5;
34
+ this.row_width = hm(1,0);
35
+ this.start = hm(8,0);
36
+ this.end = hm(24,0);
37
+ this.sel = [];
38
+
39
+ this.prefix = `${e.attr('id')}_`;
40
+
41
+ this.e.mousedown({s: this}, function(event) { event.data.s.onMouseDown(); });
42
+ this.e.mouseup({s: this}, function(event) { event.data.s.onMouseUp(); });
43
+
44
+ log('started');
45
+ }
46
+
47
+ TimeMapView.prototype.elemUnderCursor = function()
48
+ {
49
+ return $('#' + this.e.attr('curItem'));
50
+ }
51
+
52
+ TimeMapView.prototype.taskByElem = function(e)
53
+ {
54
+ id = e.attr('tid');
55
+ start = e.attr('tstart');
56
+ duration = e.attr('tduration');
57
+
58
+ return id === undefined ? TimeTaskNull(start, duration) : this.m.task(id, start);
59
+ }
60
+
61
+ TimeMapView.prototype.selTasks = function()
62
+ {
63
+ res = [];
64
+
65
+ for (var i = 0; i < this.sel.length; i++)
66
+ res.push(this.taskByElem(this.sel[i]));
67
+
68
+ if (res.length < 2)
69
+ return res;
70
+
71
+ if (res[0].start > res[res.length-1].start)
72
+ res.reverse();
73
+
74
+ return res;
75
+ }
76
+
77
+ TimeMapView.prototype.abolishSelection = function()
78
+ {
79
+ for (var i = 0; i < this.sel.length; i++) {
80
+ this.sel[i].removeAttr('sel');
81
+ }
82
+
83
+ this.sel = [];
84
+ }
85
+
86
+ TimeMapView.prototype.onMouseDown = function()
87
+ {
88
+ this.abolishSelection();
89
+ this.sel = [ this.elemUnderCursor() ];
90
+ }
91
+
92
+ TimeMapView.prototype.onMouseUp = function() {
93
+ if (this.sel.length != 1) {
94
+ console.log('onMouseUp: this.sel is bad');
95
+ return;
96
+ }
97
+
98
+ var eStart = $(this.sel[0]);
99
+ var eEnd = this.elemUnderCursor();
100
+ var b = false;
101
+ this.sel = [];
102
+
103
+ if (eStart.attr('id') == eEnd.attr('id')) {
104
+ this.sel = [ eStart ];
105
+ eStart.attr('sel', 1);
106
+ eStart.droppable();
107
+ eStart.bind('drop', {s: this},
108
+ function(ev, elem) {
109
+ ev.data.s.mkTaskFromSelection(elem.draggable.attr('id'), elem.draggable.text());
110
+ });
111
+ return;
112
+ }
113
+
114
+ for (var i = 0; i < this.cells.length; i++) {
115
+ var bend = false;
116
+
117
+ if ( $(this.cells[i]).attr('tstart') == eStart.attr('tstart') ||
118
+ $(this.cells[i]).attr('tstart') == eEnd.attr('tstart') ) {
119
+ if (!b) b = true;
120
+ else bend = true;
121
+ }
122
+
123
+ if (b) {
124
+ this.sel.push($(this.cells[i]));
125
+ $(this.cells[i]).attr('sel', 1);
126
+ $(this.cells[i]).droppable();
127
+ $(this.cells[i]).bind('drop', {s: this},
128
+ function(ev, elem) {
129
+ ev.data.s.mkTaskFromSelection(elem.draggable.attr('tid'), elem.draggable.text());
130
+ });
131
+ }
132
+
133
+ if (bend)
134
+ break;
135
+ }
136
+
137
+ clearSelection();
138
+ }
139
+
140
+ function html_span(text, id, cl) {
141
+ var res = '<span';
142
+
143
+ if (id != null) res += ` id=${id}`;
144
+ if (cl != null) res += ` class=${cl}`;
145
+
146
+ return res + `>${text}</span>`;
147
+ }
148
+
149
+ TimeMapView.prototype.invalidate = function()
150
+ {
151
+ var tsel = this.selTasks();
152
+
153
+ this.e.html('');
154
+
155
+ var map = this.m.to_map(this.quant, this.row_width, this.start, this.end);
156
+
157
+ this.e.append(html_span('&nbsp;', null, 'TimeMapHeader'));
158
+
159
+ for (var i = 0; i < this.row_width/this.quant; i++)
160
+ this.e.append(html_span(this.row_width <= hm(1,0) ? i*this.quant : hm_s(i*this.quant), null, 'TimeMapCol'));
161
+
162
+ for (var j = 0; j < map.length; j++) {
163
+
164
+ this.e.append(html_span(hm_h(this.start + j*this.row_width), null, 'TimeMapHeader'));
165
+
166
+ for (var i = 0, row = map[j]; i < row.length; i++) {
167
+ var t = row[i];
168
+ var id = `${this.prefix}tmc_${j}_${i}`;
169
+
170
+ this.e.append(html_span(t.title == null ? '&nbsp;' : t.title, id, 'TimeMapCell'));
171
+
172
+ var nsquares = t.duration/this.quant;
173
+ $(`#${id}`).width(nsquares * this.cellSize + (nsquares-1)*2);
174
+
175
+ $(`#${id}`).mouseenter(function() {
176
+ $(this).parent().attr('curItem', $(this).attr('id'));
177
+ }).mouseleave(function() {
178
+ $(this).parent().attr('curItem', '');
179
+ });
180
+
181
+ if (t.id != null) {
182
+ $(`#${id}`).attr('tid', t.id);
183
+
184
+ $(`#${id}`).dblclick({s: this, id: t.id, start: t.start},
185
+ function(e) { e.data.s.delTaskByIdnStart(e.data.id, e.data.start); });
186
+ }
187
+
188
+ $(`#${id}`).attr('tstart', t.start);
189
+ $(`#${id}`).attr('tduration', t.duration);
190
+ }
191
+ }
192
+
193
+ this.e.width((this.row_width/this.quant) * (this.cellSize+2) + this.headersWidth+2);
194
+ this.e.height((map.length + 1) * (this.cellSize));
195
+
196
+ $('.TimeMapCell').height(this.cellSize);
197
+ $('.TimeMapHeader').height(this.cellSize);
198
+ $('.TimeMapHeader').width(this.headersWidth);
199
+ $('.TimeMapCol').width(this.cellSize);
200
+ $('.TimeMapCell').css('line-height', this.cellSize + 'px');
201
+ $('.TimeMapHeader').css('line-height', this.cellSize + 'px');
202
+ $('.TimeMapCol').css('line-height', this.cellSize + 'px');
203
+
204
+ this.cells = $('.TimeMapCell').toArray();
205
+ }
206
+
207
+ TimeMapView.prototype.mkTaskFromSelection = function(id, text)
208
+ {
209
+ if (this.sel.length < 1)
210
+ return;
211
+
212
+ var sel = this.selTasks();
213
+
214
+ this.m.tlist.push(new TimeTask(id, text, sel[0].start, sel[sel.length-1].end() - sel[0].start));
215
+
216
+ this.abolishSelection();
217
+ this.invalidate();
218
+ }
219
+
220
+ TimeMapView.prototype.delTaskByIdnStart = function(id, start)
221
+ {
222
+ this.m.del(id, start);
223
+ this.abolishSelection();
224
+ this.invalidate();
225
+ }
226
+
227
+ TimeMapView.prototype.delSelectedTask = function()
228
+ {
229
+ if (this.sel.length != 1)
230
+ return;
231
+
232
+ var task = this.selTasks()[0].id;
233
+
234
+ if (task == null)
235
+ return;
236
+
237
+ var start = this.selTasks()[0].start;
238
+
239
+ this.m.del(id, start);
240
+
241
+ this.abolishSelection();
242
+ this.invalidate();
243
+ }
244
+
245
+ var tm;
246
+ var tv;
247
+
248
+ $(function () {
249
+ tm = new TimeMap([]);
250
+ tv = new TimeMapView($('.timemap'), tm);
251
+
252
+ tv.invalidate();
253
+ });
254
+
255
+ function hm(hours, mins)
256
+ {
257
+ return hours*60 + mins;
258
+ }
259
+
260
+ function hm_s(rmins)
261
+ {
262
+ var hours = Math.floor(rmins/60);
263
+ var mins = rmins%60;
264
+
265
+ return hours + ':' + mins;
266
+ }
267
+
268
+ function hm_h(rmins)
269
+ {
270
+ var hours = Math.floor(rmins/60);
271
+
272
+ return hours;
273
+ }
274
+
275
+ function hm_m(rmins)
276
+ {
277
+ var mins = rmins%60;
278
+
279
+ return mins;
280
+ }
281
+
282
+ function tround(mins, r)
283
+ {
284
+ return mins - mins%r;
285
+ }
286
+
287
+
288
+ function TimeTask(id, title, start, duration)
289
+ {
290
+ this.id = id;
291
+ this.title = title;
292
+ this.start = parseInt(start);
293
+ this.duration = parseInt(duration);
294
+ }
295
+
296
+ function TimeTaskDup(tm)
297
+ {
298
+ return new TimeTask(tm.id, tm.title, tm.start, tm.duration);
299
+ }
300
+
301
+ function TimeTaskNull(start, duration)
302
+ {
303
+ return new TimeTask(null, null, start, duration);
304
+ }
305
+
306
+ TimeTask.prototype.end = function()
307
+ {
308
+ return this.start+this.duration;
309
+ }
310
+
311
+
312
+ function TimeMap(tlist)
313
+ {
314
+ this.tlist = tlist;
315
+ }
316
+
317
+ TimeMap.prototype.index = function(id, start)
318
+ {
319
+ for (var i = 0; i < this.tlist.length; i++)
320
+ if (this.tlist[i].id == id && this.tlist[i].start == start)
321
+ return i;
322
+
323
+ return null;
324
+ }
325
+
326
+ TimeMap.prototype.task = function(id, start)
327
+ {
328
+ var ind = this.index(id, start);
329
+
330
+ return ind == null ? null : this.tlist[ind];
331
+ }
332
+
333
+ TimeMap.prototype.del = function(id, start)
334
+ {
335
+ var ind = this.index(id, start);
336
+
337
+ if (ind == null)
338
+ return;
339
+
340
+ this.tlist.splice(ind, 1);
341
+ }
342
+
343
+ TimeMap.prototype.to_map = function(quant, row_width, start, end)
344
+ {
345
+ periods = [];
346
+
347
+ this.tlist.at = function(t, r)
348
+ {
349
+ for (var i = 0; i < this.length; i++) {
350
+ if (tround(this[i].start, r) == tround(t, r)) {
351
+ return TimeTaskDup(this[i]);
352
+ }
353
+ }
354
+
355
+ return false;
356
+ }
357
+
358
+ for (var t = start; t < end; ) {
359
+ var at = this.tlist.at(t, quant);
360
+ if (at) {
361
+ periods.push(at);
362
+ t += at.duration;
363
+ } else {
364
+ periods.push(new TimeTaskNull(t, quant));
365
+ t += quant;
366
+ }
367
+ }
368
+
369
+ var i = 0;
370
+
371
+ for (var wnd = { start: start, end: start + row_width}; wnd.end < end; wnd.start+=row_width, wnd.end+=row_width) {
372
+ for (; periods[i].start < wnd.end; i++) {
373
+ if (periods[i].end() > wnd.end) {
374
+ var rest_duration = periods[i].end() - wnd.end;
375
+ periods[i].duration -= rest_duration;
376
+ ctm = TimeTaskDup(periods[i]);
377
+ ctm.start = wnd.end
378
+ ctm.duration = rest_duration
379
+ periods.splice(i+1, 0, ctm);
380
+ }
381
+ }
382
+ }
383
+
384
+ i = 0;
385
+ map = [];
386
+
387
+ for (var wnd = { start: start, end: start + row_width}; wnd.end < end; wnd.start+=row_width, wnd.end+=row_width) {
388
+ var row = [];
389
+
390
+ for (; periods[i].start < wnd.end; i++)
391
+ row.push(periods[i]);
392
+
393
+ map.push(row);
394
+ }
395
+
396
+ return map;
397
+ }
398
+
399
+
@@ -0,0 +1,55 @@
1
+ .timemap {
2
+ float: left;
3
+ display: inline-block;
4
+ }
5
+
6
+ .TimeMapCell {
7
+ background: #F5F5F5;
8
+ display: inline-block;
9
+ margin: 1px;
10
+ padding: 0px;
11
+ text-align: center;
12
+
13
+ -webkit-user-select: none; /* Chrome all / Safari all */
14
+ -moz-user-select: none; /* Firefox all */
15
+ -ms-user-select: none; /* IE 10+ */
16
+ user-select: none;
17
+ }
18
+
19
+ .TimeMapHeader {
20
+ color: rgb(170, 80, 100);
21
+ display: inline-block;
22
+ margin: 1px;
23
+ padding: 0px;
24
+ text-align: center;
25
+ font-weight: bold;
26
+
27
+ -webkit-user-select: none; /* Chrome all / Safari all */
28
+ -moz-user-select: none; /* Firefox all */
29
+ -ms-user-select: none; /* IE 10+ */
30
+ user-select: none;
31
+ }
32
+
33
+ .TimeMapCol {
34
+ color: rgb(170, 80, 100);
35
+ display: inline-block;
36
+ margin: 1px;
37
+ padding: 0px;
38
+ text-align: center;
39
+ font-weight: bold;
40
+
41
+ -webkit-user-select: none; /* Chrome all / Safari all */
42
+ -moz-user-select: none; /* Firefox all */
43
+ -ms-user-select: none; /* IE 10+ */
44
+ user-select: none;
45
+ }
46
+
47
+ .TimeMapCell:hover {
48
+ background: #F5F5F5;
49
+ cursor: pointer;
50
+ }
51
+
52
+ .TimeMapCell[sel] {
53
+ background: rgb(255, 230, 210);
54
+ }
55
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timemapjs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Artem Levenkov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jquery-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description:
28
+ email:
29
+ executables:
30
+ - console
31
+ - setup
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - Gemfile
36
+ - README.md
37
+ - Rakefile
38
+ - bin/console
39
+ - bin/setup
40
+ - lib/timemapjs-rails.rb
41
+ - lib/timemapjs/rails.rb
42
+ - lib/timemapjs/rails/engine.rb
43
+ - lib/timemapjs/rails/version.rb
44
+ - timemapjs-rails.gemspec
45
+ - vendor/assets/javascripts/timemapjs.js
46
+ - vendor/assets/stylesheets/timemapjs.css
47
+ homepage: https://github.com/bitia-ru/timemap.git
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.5.2
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: time map
71
+ test_files: []