From 5e9652f27b262eaf2ea86145940e680fe76edbeb Mon Sep 17 00:00:00 2001 From: Idan Stark Date: Thu, 25 Jan 2018 20:58:26 +0200 Subject: [PATCH 1/4] removed local storage --- js/ClockControlsCtrl.js | 9 ++++----- js/helpers/ng-config.js | 9 ++------- js/ngStorage.min.js | 1 - 3 files changed, 6 insertions(+), 13 deletions(-) delete mode 100644 js/ngStorage.min.js diff --git a/js/ClockControlsCtrl.js b/js/ClockControlsCtrl.js index 8cc9a03..e7e765f 100644 --- a/js/ClockControlsCtrl.js +++ b/js/ClockControlsCtrl.js @@ -1,4 +1,4 @@ -angular.module('Clock',['ngStorage']) +angular.module('Clock',[]) .factory('$opener',[ '$window', function($window) { @@ -10,10 +10,9 @@ angular.module('Clock',['ngStorage']) } ]) .controller('ClockControlsCtrl',[ - '$scope','$timeout','$opener','$localStorage', - function($scope,$timeout,$opener,$localStorage) { - - $scope.config = $localStorage.config; + '$scope','$timeout','$opener','$config', + function($scope,$timeout,$opener,$config) { + $scope.config = $config.get(); // For backwards compatibility $scope.config.tracks = $scope.config.tracks || []; diff --git a/js/helpers/ng-config.js b/js/helpers/ng-config.js index e9691c4..20a5fee 100644 --- a/js/helpers/ng-config.js +++ b/js/helpers/ng-config.js @@ -1,4 +1,4 @@ -angular.module('Clock').service('$config',['$localStorage' ,'$q', '$window' ,function($localStorage, $q, $window) { +angular.module('Clock').service('$config',['$q', '$window' ,function($q, $window) { var _config; function params() { @@ -23,12 +23,7 @@ angular.module('Clock').service('$config',['$localStorage' ,'$q', '$window' ,fun //no url Config } - //config from localStorage, then url, then defaults from config - var $storage = $localStorage.$default({ - config: urlConfig || clockConfig - }); - - _config = $storage.config; + _config = urlConfig || clockConfig; } return _config; }, diff --git a/js/ngStorage.min.js b/js/ngStorage.min.js deleted file mode 100644 index 4be5443..0000000 --- a/js/ngStorage.min.js +++ /dev/null @@ -1 +0,0 @@ -/*! ngstorage 0.3.10 | Copyright (c) 2015 Gias Kay Lee | MIT License */!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["angular"],b):a.hasOwnProperty("angular")?b(a.angular):"object"==typeof exports&&(module.exports=b(require("angular")))}(this,function(a){"use strict";function b(b){return function(){var c="ngStorage-";this.setKeyPrefix=function(a){if("string"!=typeof a)throw new TypeError("[ngStorage] - "+b+"Provider.setKeyPrefix() expects a String.");c=a};var d=a.toJson,e=a.fromJson;this.setSerializer=function(a){if("function"!=typeof a)throw new TypeError("[ngStorage] - "+b+"Provider.setSerializer expects a function.");d=a},this.setDeserializer=function(a){if("function"!=typeof a)throw new TypeError("[ngStorage] - "+b+"Provider.setDeserializer expects a function.");e=a},this.get=function(a){return e(window[b].getItem(c+a))},this.set=function(a,e){return window[b].setItem(c+a,d(e))},this.$get=["$rootScope","$window","$log","$timeout","$document",function(f,g,h,i,j){function k(a){var b;try{b=g[a]}catch(c){b=!1}if(b&&"localStorage"===a){var d="__"+Math.round(1e7*Math.random());try{localStorage.setItem(d,d),localStorage.removeItem(d)}catch(c){b=!1}}return b}var l,m,n=c.length,o=k(b)||(h.warn("This browser does not support Web Storage!"),{setItem:a.noop,getItem:a.noop,removeItem:a.noop}),p={$default:function(b){for(var c in b)a.isDefined(p[c])||(p[c]=a.copy(b[c]));return p.$sync(),p},$reset:function(a){for(var b in p)"$"===b[0]||delete p[b]&&o.removeItem(c+b);return p.$default(a)},$sync:function(){for(var a,b=0,d=o.length;d>b;b++)(a=o.key(b))&&c===a.slice(0,n)&&(p[a.slice(n)]=e(o.getItem(a)))},$apply:function(){var b;if(m=null,!a.equals(p,l)){b=a.copy(l),a.forEach(p,function(e,f){a.isDefined(e)&&"$"!==f[0]&&(o.setItem(c+f,d(e)),delete b[f])});for(var e in b)o.removeItem(c+e);l=a.copy(p)}}};return p.$sync(),l=a.copy(p),f.$watch(function(){m||(m=i(p.$apply,100,!1))}),g.addEventListener&&g.addEventListener("storage",function(b){if(b.key){var d=j[0];d.hasFocus&&d.hasFocus()||c!==b.key.slice(0,n)||(b.newValue?p[b.key.slice(n)]=e(b.newValue):delete p[b.key.slice(n)],l=a.copy(p),f.$apply())}}),g.addEventListener&&g.addEventListener("beforeunload",function(){p.$apply()}),p}]}}return a=a&&a.module?a:window.angular,a.module("ngStorage",[]).provider("$localStorage",b("localStorage")).provider("$sessionStorage",b("sessionStorage"))}); \ No newline at end of file From 5961ffbba33c6b1493bd377d7cb3e9140b832bdd Mon Sep 17 00:00:00 2001 From: Idan Stark Date: Thu, 25 Jan 2018 21:58:32 +0200 Subject: [PATCH 2/4] Added logging and remove option for before in tracks --- config.js | 2 +- js/helpers/ClockModule.js | 2 +- js/helpers/ng-tracks.js | 10 ++++------ localserver.js | 2 ++ package.json | 1 + 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config.js b/config.js index bc84947..3dbe180 100644 --- a/config.js +++ b/config.js @@ -4,7 +4,7 @@ var clockConfig = { seconds: 150, tracks: [{ source: '30SecstoGo.mp3', - start: '30 seconds before stop' + start: '120 seconds after start' },{ source: 'End.mp3', start: 'on stop' diff --git a/js/helpers/ClockModule.js b/js/helpers/ClockModule.js index 859393e..6535441 100644 --- a/js/helpers/ClockModule.js +++ b/js/helpers/ClockModule.js @@ -1 +1 @@ -angular.module('Clock',['ngStorage']); \ No newline at end of file +angular.module('Clock',[]); \ No newline at end of file diff --git a/js/helpers/ng-tracks.js b/js/helpers/ng-tracks.js index 8644ebd..d181d07 100644 --- a/js/helpers/ng-tracks.js +++ b/js/helpers/ng-tracks.js @@ -60,13 +60,11 @@ // With the option for xxx after yyy // Where xxx is the original number-unit trigger, and the yyy is a // reference to another trigger - if(match = str.match(/^(\d+)(s| secs| seconds|%| percents)( (after|before) (.+))?$/)) { + if(match = str.match(/^(\d+)(s| secs| seconds|%| percents)( (after) (.+))?$/)) { let quantity = parseInt(match[1]); let unit = match[2]; - let direction = 1; // Counting forward let startCountingAt = config.seconds; // Start from the beginning if(match[3]) { // Start at a specific time - direction = (match[4] === 'before') ? -1 : 1; startCountingAt = resolveTimeEvent(match[5], config); } let time; @@ -79,16 +77,16 @@ if(isFinite(startCountingAt)) { startCountingAt = parseInt(startCountingAt); - let time = startCountingAt - direction * quantity; + let time = startCountingAt - quantity; return time.toString(); } else { - if(startCountingAt.match(/^(after|before)/)) { + if(startCountingAt.match(/^(after)/)) { console.error(`Illegal trigger: ${str}`); return undefined; } return { event: startCountingAt, - timeAfter: direction * quantity + timeAfter: quantity }; } diff --git a/localserver.js b/localserver.js index 530ca31..9b96f82 100644 --- a/localserver.js +++ b/localserver.js @@ -1,11 +1,13 @@ var connect = require('connect'); var serveStatic = require('serve-static'); var argv = require('minimist')(process.argv.slice(2)); +var morgan = require('morgan'); var fs = require('fs'); var port = 1392; connect() + .use(morgan('DEBUG [:date[iso]]: :method :url - :status in :response-time ms')) .use('/config.js', function(req, res, next) { if(argv.c) { fs.readFile(argv.c, function(err, data) { diff --git a/package.json b/package.json index 6e8494c..a3e7748 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dependencies": { "connect": "^3.4.0", "minimist": "^1.1.0", + "morgan": "^1.9.0", "serve-static": "^1.10.0" }, "devDependencies": {} From 88156c3b74550a3922b8b3d4d8deb3a5f14f6b03 Mon Sep 17 00:00:00 2001 From: Idan Stark Date: Thu, 25 Jan 2018 22:00:30 +0200 Subject: [PATCH 3/4] version-1.2.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a3e7748..e9091c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@first-lego-league/clock", - "version": "1.2.3", + "version": "1.2.4", "description": "Clock\r =====", "main": "config.js", "scripts": { From 5d2acc48e1add269f6616918e88961bf6ec23ce4 Mon Sep 17 00:00:00 2001 From: Idan Stark Date: Thu, 25 Jan 2018 22:49:35 +0200 Subject: [PATCH 4/4] version-1.2.4 --- config.js | 3 + js/helpers/ng-tracks.js | 20 ++-- package-lock.json | 223 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+), 7 deletions(-) create mode 100644 package-lock.json diff --git a/config.js b/config.js index 3dbe180..73a366b 100644 --- a/config.js +++ b/config.js @@ -3,12 +3,15 @@ var clockConfig = { node: 'default', seconds: 150, tracks: [{ + name: '30secs_left_track', source: '30SecstoGo.mp3', start: '120 seconds after start' },{ + name: 'end_track', source: 'End.mp3', start: 'on stop' },{ + name: 'start_track', source: 'Start.mp3', start: 'on start', }] diff --git a/js/helpers/ng-tracks.js b/js/helpers/ng-tracks.js index d181d07..99db0a4 100644 --- a/js/helpers/ng-tracks.js +++ b/js/helpers/ng-tracks.js @@ -47,11 +47,15 @@ function set(listener, time) { let event = Math.floor(time / 1000) - listener.timeAfterEvent; - listeners.push({ - event: event.toString(), - track: listener.track, - action: listener.metaAction - }); + let newListenerName = listener.name + '_set'; + if(!listeners.find(listener => listener.name === newListenerName)) { + listeners.push({ + name: newListenerName, + event: event.toString(), + track: listener.track, + action: listener.metaAction + }); + } } function resolveTimeEvent(str, config) { @@ -146,7 +150,6 @@ }); } }); - console.log(listeners); return listeners; } @@ -160,9 +163,12 @@ config.tracks.forEach(function(trackConfig) { $audio.init(`mp3/${trackConfig.source}`,function(track) { - listeners = listeners.concat(resolveListeners(trackConfig, track, config)); + if(!listeners.find(listener => listener.name === trackConfig.name)) { + listeners = listeners.concat(resolveListeners(trackConfig, track, config)); + } }); }); + console.log(listeners); }, trigger: trigger, pause: function() { diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..98bc2b6 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,223 @@ +{ + "name": "@first-lego-league/clock", + "version": "1.2.3", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "basic-auth": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.0.tgz", + "integrity": "sha1-AV2z81PgLlY3d1X5YnQuiYHnu7o=", + "requires": { + "safe-buffer": "5.1.1" + } + }, + "connect": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/connect/-/connect-3.6.2.tgz", + "integrity": "sha1-aU6NIGgb/kkCgsiriGvpjwn0L+c=", + "requires": { + "debug": "2.6.7", + "finalhandler": "1.0.3", + "parseurl": "1.3.2", + "utils-merge": "1.0.0" + } + }, + "debug": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz", + "integrity": "sha1-krrR9tBbu2u6Isyoi80OyJTChh4=", + "requires": { + "ms": "2.0.0" + } + }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" + }, + "finalhandler": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.3.tgz", + "integrity": "sha1-70fneVDpmXgOhgIqVg4yF+DQzIk=", + "requires": { + "debug": "2.6.7", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "on-finished": "2.3.0", + "parseurl": "1.3.2", + "statuses": "1.3.1", + "unpipe": "1.0.0" + } + }, + "fresh": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz", + "integrity": "sha1-9HTKXmqSRtb9jglTz6m5yAWvp44=" + }, + "http-errors": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", + "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", + "requires": { + "depd": "1.1.1", + "inherits": "2.0.3", + "setprototypeof": "1.0.3", + "statuses": "1.3.1" + }, + "dependencies": { + "depd": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" + } + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "mime": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz", + "integrity": "sha1-EV+eO2s9rylZmDyzjxSaLUDrXVM=" + }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + }, + "morgan": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.0.tgz", + "integrity": "sha1-0B+mxlhZt2/PMbPLU6OCGjEdgFE=", + "requires": { + "basic-auth": "2.0.0", + "debug": "2.6.9", + "depd": "1.1.2", + "on-finished": "2.3.0", + "on-headers": "1.0.1" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + } + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "requires": { + "ee-first": "1.1.1" + } + }, + "on-headers": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.1.tgz", + "integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c=" + }, + "parseurl": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", + "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" + }, + "range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + }, + "send": { + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/send/-/send-0.15.3.tgz", + "integrity": "sha1-UBP5+ZAj31DRvZiSwZ4979HVMwk=", + "requires": { + "debug": "2.6.7", + "depd": "1.1.2", + "destroy": "1.0.4", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", + "fresh": "0.5.0", + "http-errors": "1.6.2", + "mime": "1.3.4", + "ms": "2.0.0", + "on-finished": "2.3.0", + "range-parser": "1.2.0", + "statuses": "1.3.1" + } + }, + "serve-static": { + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.3.tgz", + "integrity": "sha1-n0uhni8wMMVH+K+ZEHg47DjVseI=", + "requires": { + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "parseurl": "1.3.2", + "send": "0.15.3" + } + }, + "setprototypeof": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", + "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" + }, + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + }, + "utils-merge": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz", + "integrity": "sha1-ApT7kiu5N1FTVBxPcJYjHyh8ivg=" + } + } +}