harvest-reaper 0.1.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dd69ab60881cb42314075bb91da4da62034c59ea86d556383229b6435fdc1e3d
4
+ data.tar.gz: 0f210bbdce3822f66b2d1c0179ec09542e08c797b7511dce9846a7dccc79f726
5
+ SHA512:
6
+ metadata.gz: f8b4a3a1524e1e5d9bed51527220e9365649c3044a6cbdd5bbab3327bdf16241c301a1d0e67bc303b1d3250bcb94008df95b46532e522ac066ea6c81d308a224
7
+ data.tar.gz: d47832dc57b12436f8528f84b4e10a385084af2a361204255d967b631ffecc6d3c48e557d3bfdf008b793d27a9931742997b596c8dd562c262e1174f87db8a74
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.0
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in reaper.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ harvest-reaper (0.1.1)
5
+ ruby-progressbar (~> 1.10.1)
6
+ terminal-table (~> 1.8.0)
7
+ thor (~> 0.20.3)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.3)
13
+ rake (10.5.0)
14
+ rspec (3.8.0)
15
+ rspec-core (~> 3.8.0)
16
+ rspec-expectations (~> 3.8.0)
17
+ rspec-mocks (~> 3.8.0)
18
+ rspec-core (3.8.2)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-expectations (3.8.4)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-mocks (3.8.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-support (3.8.2)
27
+ ruby-progressbar (1.10.1)
28
+ terminal-table (1.8.0)
29
+ unicode-display_width (~> 1.1, >= 1.1.1)
30
+ thor (0.20.3)
31
+ unicode-display_width (1.6.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 2.0)
38
+ harvest-reaper!
39
+ rake (~> 10.0)
40
+ rspec (~> 3.0)
41
+
42
+ BUNDLED WITH
43
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 derekkk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Reaper
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/reaper`. 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 'reaper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install reaper
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. Then, run `rake spec` to run the tests. 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]/reaper.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,316 @@
1
+ <!DOCTYPE>
2
+ <html>
3
+ <header>
4
+ <style>
5
+ body {
6
+ font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
7
+ font-size: 14px;
8
+ line-height: 1.4;
9
+ color: #333;
10
+ }
11
+
12
+ ul#tasks {
13
+ background-color: #efefef;
14
+ }
15
+
16
+ div {
17
+ display: block;
18
+ }
19
+
20
+ p {
21
+ display: block;
22
+ margin-block-start: 1em;
23
+ margin-block-end: 1em;
24
+ margin-inline-start: 0px;
25
+ margin-inline-end: 0px;
26
+ }
27
+
28
+ p#error-msg {
29
+ color: #ff0000;
30
+ }
31
+
32
+ hr {
33
+ display: block;
34
+ height: 1px;
35
+ border: 0;
36
+ border-top: 1px solid #ccc;
37
+ margin: 1em 0;
38
+ padding: 0;
39
+ }
40
+ </style>
41
+ <script>
42
+ var globalSettings = "{{RPR_GLOBAL_SETTINGS}}";
43
+
44
+ var projects = "{{RPR_PROJECTS}}";
45
+
46
+ var addedTasks = "{{RPR_ADDED_TASKS}}";
47
+
48
+ function updateTaskPickerByProject(p) {
49
+ var taskPicker = document.getElementById('task_picker');
50
+ while (taskPicker.options.length > 0) {
51
+ taskPicker.remove(0);
52
+ }
53
+
54
+ var tasks = p.tasks;
55
+
56
+ for (var i = 0; i < tasks.length; i++) {
57
+ var t = tasks[i];
58
+ var opt = document.createElement('option');
59
+ opt.value = i;
60
+ opt.innerHTML = t.name
61
+ taskPicker.appendChild(opt);
62
+ }
63
+ }
64
+
65
+ function init() {
66
+ // projects = [{
67
+ // pid: 1,
68
+ // code: 'COD-A',
69
+ // name: "Kapsool Website Frontend Development",
70
+ // client: "Kapsool",
71
+ // tasks: [{
72
+ // tid: 11,
73
+ // name: "Frontend Development"
74
+ // }]
75
+ // },
76
+ // {
77
+ // pid: 2,
78
+ // code: 'BPS-A',
79
+ // name: "BASF Website Development",
80
+ // client: "BASF",
81
+ // tasks: [{
82
+ // tid: 12,
83
+ // name: "Frontend Development"
84
+ // },
85
+ // {
86
+ // tid: 13,
87
+ // name: "Technical Direction"
88
+ // }]
89
+ // }];
90
+
91
+ // addedTasks = [{
92
+ // pid: 2,
93
+ // tid: 13,
94
+ // pct: 0.2
95
+ // },
96
+ // {
97
+ // pid: 1,
98
+ // tid: 11,
99
+ // pct: 0.8
100
+ // }];
101
+
102
+ if (projects === "{{" + "RPR_PROJECTS" + "}}") {
103
+ document.body.innerHTML = "<h1>Reaper Configuration</h1><p>Don't Be Naughty.</p><p>This page is supposed to be launched by Reaper only.</p>"
104
+ return;
105
+ }
106
+
107
+ document.getElementById('negative-daily-offset').value = globalSettings.noffset;
108
+ document.getElementById('positive-daily-offset').value = globalSettings.poffset;
109
+
110
+ var lastClient = null;
111
+
112
+ var projPicker = document.getElementById('proj_picker');
113
+
114
+ for (var i = 0; i < projects.length; i++) {
115
+ var p = projects[i];
116
+
117
+ var client = p.client;
118
+
119
+ if (!lastClient || lastClient !== client) {
120
+ var optgroup = document.createElement('optgroup');
121
+ optgroup.label = client;
122
+ projPicker.appendChild(optgroup);
123
+ lastClient = client;
124
+ }
125
+
126
+ var opt = document.createElement('option');
127
+ opt.value = i;
128
+ opt.innerHTML = "[" + p.code + "] " + p.name;
129
+ projPicker.appendChild(opt);
130
+ }
131
+
132
+ if (projects.length > 0) {
133
+ updateTaskPickerByProject(projects[0]);
134
+ }
135
+
136
+ for (var i = 0; i < addedTasks.length; i++) {
137
+ var t = addedTasks[i];
138
+
139
+ var proj = projects.find(function(p) {
140
+ return p.pid == t.pid
141
+ });
142
+
143
+ var task = proj.tasks.find(function(t) {
144
+ return t.tid == t.tid
145
+ });
146
+
147
+ addTask(i, t.pid, proj.name, t.tid, task.name, t.pct);
148
+ }
149
+ }
150
+
151
+ function onProjectPickerChanged() {
152
+ var projPicker = document.getElementById('proj_picker');
153
+ var p = projects[projPicker.selectedIndex];
154
+ updateTaskPickerByProject(p);
155
+ }
156
+
157
+ function addSelectedTask() {
158
+ clearError();
159
+
160
+ var projPicker = document.getElementById('proj_picker');
161
+ var taskPicker = document.getElementById('task_picker');
162
+
163
+ var pindex = projPicker.selectedIndex;
164
+ var tindex = taskPicker.selectedIndex;
165
+
166
+ var p = projects[pindex];
167
+ var t = p.tasks[tindex];
168
+
169
+ for (var i = 0; i < addedTasks.length; i++) {
170
+ var task = addedTasks[i];
171
+ if (task.pid === p.pid && task.tid == t.tid) {
172
+ showError("Task already added!");
173
+ return;
174
+ }
175
+ }
176
+
177
+ addTask(addedTasks.length, p.pid, p.name, t.tid, t.name, 0);
178
+
179
+ addedTasks.push({
180
+ pid: p.pid,
181
+ tid: t.tid
182
+ });
183
+ }
184
+
185
+ function addTask(index, pid, project, tid, task, percentage) {
186
+ var percentageId = "percentage-" + index;
187
+ var p = Math.round(percentage * 100);
188
+
189
+ var ul = document.getElementById('tasks');
190
+ var li = document.createElement('li');
191
+ li.innerHTML = "<h3>" + project + "</h3>" +
192
+ "<p>" + task + "</p>" +
193
+ "<div>" +
194
+ "<label for=\"" + percentageId + "\">Percentage (1-100, integer only): </label>" +
195
+ "<input id=\"" + percentageId + "\" type=\"text\" value=\"" + p + "\">" +
196
+ "</div>" +
197
+ "<button onclick=\"removeTask(this)\">Remove</button>";
198
+ ul.appendChild(li);
199
+ }
200
+
201
+ function removeTask(e) {
202
+ clearError();
203
+
204
+ var li = e.parentElement;
205
+
206
+ var index = 0;
207
+ var ele = li;
208
+ while((ele = ele.previousElementSibling) != null) ++index;
209
+
210
+ li.remove();
211
+
212
+ addedTasks.splice(index, 1);
213
+ }
214
+
215
+ function update() {
216
+ clearError();
217
+
218
+ if (addedTasks.length == 0) {
219
+ showError("You didn't add any tasks!");
220
+ return;
221
+ }
222
+
223
+ var noffset = parseInt(document.getElementById('negative-daily-offset').value);
224
+ var poffset = parseInt(document.getElementById('positive-daily-offset').value);
225
+
226
+ if (isNaN(noffset) || noffset < 0 || noffset > 4) {
227
+ showError("Daily working hours negative offset is invalid!");
228
+ return;
229
+ }
230
+
231
+ if (isNaN(poffset) || poffset < 0 || poffset > 4) {
232
+ showError("Daily working hours positive offset is invalid!");
233
+ return;
234
+ }
235
+
236
+ var percentageList = [];
237
+ var taskLis = document.getElementById('tasks').getElementsByTagName('li');
238
+ for (var i = 0; i < taskLis.length; i++) {
239
+ var li = taskLis[i];
240
+ var percentage = parseInt(document.getElementById('percentage-' + i).value);
241
+ if (isNaN(percentage) || percentage <= 0 || percentage > 100) {
242
+ showError("Percentage at row " + (i + 1) + " is invalid!");
243
+ return;
244
+ }
245
+ percentageList.push(percentage);
246
+ }
247
+
248
+ sum = percentageList.reduce((acc, cur) => acc + cur, 0);
249
+
250
+ if (sum != 100) {
251
+ showError("The sum of all percentage values must be 100!");
252
+ return;
253
+ }
254
+
255
+ document.body.innerHTML = "<h1>Reaper Configuration</h1><p>Update successfully. You may now close this webpage safely and go back to your terminal.</p>"
256
+
257
+ var params = [];
258
+ for (var i = 0; i < addedTasks.length; i++) {
259
+ var t = addedTasks[i];
260
+ var pct = percentageList[i];
261
+ params.push("p" + i + "=" + t.pid + "&t" + i + "=" + t.tid + "&pct" + i + "=" + pct);
262
+ }
263
+
264
+ var url = "http://localhost:31390/submitTimeEntries?no=" + noffset + "&po=" + poffset +"&" + params.join('&');
265
+ sendRequest(url);
266
+ }
267
+
268
+ function sendRequest(url) {
269
+ var xmlHttp = new XMLHttpRequest();
270
+ xmlHttp.open("GET", url, false); // false for synchronous request
271
+ xmlHttp.send(null);
272
+ return xmlHttp.responseText;
273
+ }
274
+
275
+ function showError(msg) {
276
+ document.getElementById('error-msg').innerText = msg;
277
+ }
278
+
279
+ function clearError() {
280
+ showError('');
281
+ }
282
+ </script>
283
+ </header>
284
+ <body onload="init()">
285
+ <h1>Reaper Configuration</h1>
286
+ <h2>Global Settings</h2>
287
+ <div>
288
+ <label for="negative-daily-offset">Daily working hours negative offset (0-4, integer only): </label>
289
+ <input id="negative-daily-offset" type="text" value="0">
290
+ </div>
291
+ <div>
292
+ <label for="positive-daily-offset">Daily working hours positive offset (0-4, integer only): </label>
293
+ <input id="positive-daily-offset" type="text" value="0">
294
+ <div>
295
+ <h2>Projects & Tasks Settings</h2>
296
+ <div>
297
+ <div>
298
+ <select id="proj_picker" onchange="onProjectPickerChanged()"></select>
299
+ <select id="task_picker"></select>
300
+ <button onclick="addSelectedTask()">Add</button>
301
+ </div>
302
+ <ul id="tasks"></ul>
303
+ </div>
304
+ <div>
305
+ <p id="error-msg"></p>
306
+ </div>
307
+ <button onclick="update()">OK</button>
308
+ <hr>
309
+ <div>
310
+ <p>Reaper: A Harvest time entries filling helper</p>
311
+ <p><i>Keep your PM away (TM)</i></p>
312
+ <p>"Keep your PM away" is a trademark of heartace (or not</p>
313
+ <p>&copy;2019 heartace</p>
314
+ </div>
315
+ </body>
316
+ </html>