|
| 1 | +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +Object.defineProperty(exports, "__esModule", { |
| 5 | + value: true |
| 6 | +}); |
| 7 | + |
| 8 | +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
| 9 | + |
| 10 | +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 11 | + |
| 12 | +// A bubble represents the colorized area with a start date, end date and a |
| 13 | +// label. Tags will be added as HTML classes for custom colors. |
| 14 | +var Bubble = function () { |
| 15 | + function Bubble(start, end, label, tags) { |
| 16 | + _classCallCheck(this, Bubble); |
| 17 | + |
| 18 | + this.label = label; |
| 19 | + this.tags = tags || []; |
| 20 | + |
| 21 | + this.date = { |
| 22 | + start: Date.parse(start), |
| 23 | + end: Date.parse(end) |
| 24 | + }; |
| 25 | + } |
| 26 | + |
| 27 | + // End returns the Bubble's end date object |
| 28 | + |
| 29 | + |
| 30 | + _createClass(Bubble, [{ |
| 31 | + key: "End", |
| 32 | + value: function End() { |
| 33 | + return this.date.end; |
| 34 | + } |
| 35 | + |
| 36 | + // Label returns the Bubble's label text |
| 37 | + |
| 38 | + }, { |
| 39 | + key: "Label", |
| 40 | + value: function Label() { |
| 41 | + return this.label; |
| 42 | + } |
| 43 | + |
| 44 | + // Start returns the Bubble's start date object |
| 45 | + |
| 46 | + }, { |
| 47 | + key: "Start", |
| 48 | + value: function Start() { |
| 49 | + return this.date.start; |
| 50 | + } |
| 51 | + }]); |
| 52 | + |
| 53 | + return Bubble; |
| 54 | +}(); |
| 55 | + |
| 56 | +exports.default = Bubble; |
| 57 | + |
| 58 | +},{}],2:[function(require,module,exports){ |
| 59 | +"use strict"; |
| 60 | + |
| 61 | +Object.defineProperty(exports, "__esModule", { |
| 62 | + value: true |
| 63 | +}); |
| 64 | + |
| 65 | +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
| 66 | + |
| 67 | +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 68 | + |
| 69 | +// List is a basic wrapper for Array access |
| 70 | +var List = function () { |
| 71 | + |
| 72 | + // When initializing a new List item you can pass a custom function to sort |
| 73 | + // the items stored in the List |
| 74 | + function List(sort) { |
| 75 | + _classCallCheck(this, List); |
| 76 | + |
| 77 | + this.storage = []; |
| 78 | + this.position = 0; |
| 79 | + this.sorter = sort; |
| 80 | + } |
| 81 | + |
| 82 | + _createClass(List, [{ |
| 83 | + key: "sort", |
| 84 | + value: function sort() { |
| 85 | + if (!this.sorter) { |
| 86 | + return; |
| 87 | + } |
| 88 | + |
| 89 | + this.storage.sort(this.sorter); |
| 90 | + } |
| 91 | + |
| 92 | + // Add can receive one or multiple parameters which are added to the List |
| 93 | + |
| 94 | + }, { |
| 95 | + key: "Add", |
| 96 | + value: function Add() { |
| 97 | + for (var _len = arguments.length, items = Array(_len), _key = 0; _key < _len; _key++) { |
| 98 | + items[_key] = arguments[_key]; |
| 99 | + } |
| 100 | + |
| 101 | + for (var i = 0, m = items.length; i < m; i++) { |
| 102 | + this.storage.push(items[i]); |
| 103 | + } |
| 104 | + |
| 105 | + this.sort(); |
| 106 | + } |
| 107 | + |
| 108 | + // Clear removes all data from storage |
| 109 | + |
| 110 | + }, { |
| 111 | + key: "Clear", |
| 112 | + value: function Clear() { |
| 113 | + this.storage = []; |
| 114 | + this.position = 0; |
| 115 | + } |
| 116 | + |
| 117 | + // First returns the first item of the List |
| 118 | + |
| 119 | + }, { |
| 120 | + key: "First", |
| 121 | + value: function First() { |
| 122 | + return this.storage[0]; |
| 123 | + } |
| 124 | + |
| 125 | + // Get returns all items in the List |
| 126 | + |
| 127 | + }, { |
| 128 | + key: "Get", |
| 129 | + value: function Get() { |
| 130 | + return this.storage; |
| 131 | + } |
| 132 | + |
| 133 | + // Last returns the last item of the List |
| 134 | + |
| 135 | + }, { |
| 136 | + key: "Last", |
| 137 | + value: function Last() { |
| 138 | + return this.storage[this.Size() - 1]; |
| 139 | + } |
| 140 | + |
| 141 | + // Next increase the position pointer and return the current element |
| 142 | + |
| 143 | + }, { |
| 144 | + key: "Next", |
| 145 | + value: function Next() { |
| 146 | + if (this.position === this.Size()) { |
| 147 | + return null; |
| 148 | + } |
| 149 | + |
| 150 | + this.position = this.position + 1; |
| 151 | + |
| 152 | + return this.storage[this.position - 1]; |
| 153 | + } |
| 154 | + |
| 155 | + // Size returns the length of the List |
| 156 | + |
| 157 | + }, { |
| 158 | + key: "Size", |
| 159 | + value: function Size() { |
| 160 | + return this.storage.length; |
| 161 | + } |
| 162 | + |
| 163 | + // Walk is an alias for forEach |
| 164 | + |
| 165 | + }, { |
| 166 | + key: "Walk", |
| 167 | + value: function Walk(func) { |
| 168 | + return this.storage.forEach(func); |
| 169 | + } |
| 170 | + }]); |
| 171 | + |
| 172 | + return List; |
| 173 | +}(); |
| 174 | + |
| 175 | +exports.default = List; |
| 176 | + |
| 177 | +},{}],3:[function(require,module,exports){ |
| 178 | +'use strict'; |
| 179 | + |
| 180 | +Object.defineProperty(exports, "__esModule", { |
| 181 | + value: true |
| 182 | +}); |
| 183 | + |
| 184 | +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
| 185 | + |
| 186 | +var _parser = require('./parser'); |
| 187 | + |
| 188 | +var _parser2 = _interopRequireDefault(_parser); |
| 189 | + |
| 190 | +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 191 | + |
| 192 | +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 193 | + |
| 194 | +var Timesheet = function () { |
| 195 | + function Timesheet(html) { |
| 196 | + _classCallCheck(this, Timesheet); |
| 197 | + |
| 198 | + var p = new _parser2.default(); |
| 199 | + |
| 200 | + this.list = p.parse(html); |
| 201 | + } |
| 202 | + |
| 203 | + // End returns the last end date of all bubbles |
| 204 | + |
| 205 | + |
| 206 | + _createClass(Timesheet, [{ |
| 207 | + key: 'End', |
| 208 | + value: function End() { |
| 209 | + var end = null; |
| 210 | + |
| 211 | + this.list.Walk(function (item) { |
| 212 | + if (end === null || item.End() > end) { |
| 213 | + end = item.End(); |
| 214 | + } |
| 215 | + }); |
| 216 | + |
| 217 | + return end; |
| 218 | + } |
| 219 | + |
| 220 | + // Start returns the earliest start date of all bubbles |
| 221 | + |
| 222 | + }, { |
| 223 | + key: 'Start', |
| 224 | + value: function Start() { |
| 225 | + var start = null; |
| 226 | + |
| 227 | + this.list.Walk(function (item) { |
| 228 | + if (start === null || item.Start() < start) { |
| 229 | + start = item.Start(); |
| 230 | + } |
| 231 | + }); |
| 232 | + |
| 233 | + return start; |
| 234 | + } |
| 235 | + }]); |
| 236 | + |
| 237 | + return Timesheet; |
| 238 | +}(); |
| 239 | + |
| 240 | +exports.default = Timesheet; |
| 241 | + |
| 242 | +},{"./parser":4}],4:[function(require,module,exports){ |
| 243 | +'use strict'; |
| 244 | + |
| 245 | +Object.defineProperty(exports, "__esModule", { |
| 246 | + value: true |
| 247 | +}); |
| 248 | + |
| 249 | +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
| 250 | + |
| 251 | +var _bubble = require('./bubble'); |
| 252 | + |
| 253 | +var _bubble2 = _interopRequireDefault(_bubble); |
| 254 | + |
| 255 | +var _list = require('./list'); |
| 256 | + |
| 257 | +var _list2 = _interopRequireDefault(_list); |
| 258 | + |
| 259 | +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| 260 | + |
| 261 | +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 262 | + |
| 263 | +// CLASS_MAIN identifies the main timesheet container |
| 264 | +var CLASS_MAIN = 'timesheet'; |
| 265 | +// CLASS_ITEM stores the HTML class name which indicates an item for timesheet |
| 266 | +var CLASS_ITEM = 'timesheet-item'; |
| 267 | +// CLASS_ITEM_DATE_START identifies the start date of an item |
| 268 | +var CLASS_ITEM_DATE_START = 'timesheet-item--date-start'; |
| 269 | +// CLASS_ITEM_DATE_END identifies the end date of an item |
| 270 | +var CLASS_ITEM_DATE_END = 'timesheet-item--date-end'; |
| 271 | +// CLASS_ITEM_LABEL identifies the label of an item |
| 272 | +var CLASS_ITEM_LABEL = 'timesheet-item--label'; |
| 273 | + |
| 274 | +// Parser is used to parse the HTML DOM into timesheet data |
| 275 | + |
| 276 | +var Parser = function () { |
| 277 | + function Parser() { |
| 278 | + _classCallCheck(this, Parser); |
| 279 | + |
| 280 | + this.list = new _list2.default(function (a, b) { |
| 281 | + return a.Start() < b.Start() ? -1 : 1; |
| 282 | + }); |
| 283 | + } |
| 284 | + |
| 285 | + _createClass(Parser, [{ |
| 286 | + key: 'parse', |
| 287 | + value: function parse(html) { |
| 288 | + var dateStart = void 0, |
| 289 | + dateEnd = void 0, |
| 290 | + label = void 0, |
| 291 | + item = void 0; |
| 292 | + |
| 293 | + // Clear list |
| 294 | + this.list.Clear(); |
| 295 | + |
| 296 | + // Return an empty List if the passed element does not have the needed |
| 297 | + // timesheet class. |
| 298 | + if (!html.classList.contains(CLASS_MAIN)) { |
| 299 | + return this.list; |
| 300 | + } |
| 301 | + |
| 302 | + // Get all items with timesheet-item class from the list |
| 303 | + var items = html.querySelectorAll('.' + CLASS_ITEM); |
| 304 | + for (var i = 0, m = items.length; i < m; i++) { |
| 305 | + item = items[i]; |
| 306 | + |
| 307 | + // Get needed elements from timsheet item |
| 308 | + dateStart = item.querySelector('.' + CLASS_ITEM_DATE_START); |
| 309 | + dateEnd = item.querySelector('.' + CLASS_ITEM_DATE_END); |
| 310 | + label = item.querySelector('.' + CLASS_ITEM_LABEL); |
| 311 | + |
| 312 | + // Skip the item if not all needed elements are found |
| 313 | + if (dateStart === null || dateEnd === null || label === null) { |
| 314 | + continue; |
| 315 | + } |
| 316 | + |
| 317 | + // Add the parsed Bubble to the List |
| 318 | + this.list.Add(new _bubble2.default(dateStart ? dateStart.innerHTML : null, dateEnd ? dateEnd.innerHTML : null, label ? label.innerHTML : null)); |
| 319 | + } |
| 320 | + |
| 321 | + return this.list; |
| 322 | + } |
| 323 | + }]); |
| 324 | + |
| 325 | + return Parser; |
| 326 | +}(); |
| 327 | + |
| 328 | +exports.default = Parser; |
| 329 | + |
| 330 | +},{"./bubble":1,"./list":2}]},{},[3]); |
0 commit comments