Skip to content

Instantly share code, notes, and snippets.

Created January 25, 2016 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/80a9bb452b944b338fff to your computer and use it in GitHub Desktop.
Save anonymous/80a9bb452b944b338fff to your computer and use it in GitHub Desktop.
tGkby
<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Side Menus</title>
<link href="http://code.ionicframework.com/1.0.0-beta.11/css/ionic.css" rel="stylesheet">
<script src="http://code.ionicframework.com/1.0.0-beta.11/js/ionic.bundle.js"></script>
</head>
<body ng-controller="MainCtrl">
<ion-nav-view></ion-nav-view>
<script id="app/views/mainView.html" type="text/ng-template">
<ion-side-menus>
<ion-side-menu-content>
<ion-nav-bar class="bar-positive">
<ion-nav-back-button class="button-icon ion-arrow-left-c">
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-navicon" menu-toggle="right"></button>
</ion-nav-buttons>
<ion-nav-view animation="no-animation" name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-header-bar class="bar-assertive">
<h1 class="title">Left Menu</h1>
</ion-header-bar>
<ion-content>
<ul class="list">
<!-- Note each link has the 'menu-close' attribute so the menu auto closes when clicking on one of these links -->
<a href="#/event/check-in" class="item" menu-close>Check-in</a>
<a href="#/event/attendees" class="item" menu-close>Attendees</a>
</ul>
</ion-content>
</ion-side-menu>
<ion-side-menu side="right">
<ion-header-bar class="bar-assertive">
<h1 class="title">Left Menu</h1>
</ion-header-bar>
<ion-content>
<ul class="list">
<!-- Note each link has the 'menu-close' attribute so the menu auto closes when clicking on one of these links -->
<a href="#/event/check-in" class="item" menu-close>Check-in</a>
<a href="#/event/attendees" class="item" menu-close>Attendees</a>
</ul>
</ion-content>
</ion-side-menu>
</ion-side-menus> </script>
<script id="app/views/timers/timersView.html" type="text/ng-template">
<ion-view title="Welcome">
<ion-content padding="true">
<p>Swipe to the right to reveal the left menu.</p>
<p>(On desktop click and drag from left to right)</p>
</ion-content>
</ion-view>
</script>
<script id="templates/check-in.html" type="text/ng-template">
<ion-view title="Event Check-in">
<ion-content>
<form class="list" ng-show="showForm">
<div class="item item-divider">
Attendee Info
</div>
<label class="item item-input">
<input type="text" placeholder="First Name" ng-model="attendee.firstname">
</label>
<label class="item item-input">
<input type="text" placeholder="Last Name" ng-model="attendee.lastname">
</label>
<div class="item item-divider">
Shirt Size
</div>
<ion-radio ng-repeat="shirtSize in shirtSizes"
ng-value="shirtSize.value"
ng-model="attendee.shirtSize">
{{ shirtSize.text }}
</ion-radio>
<div class="item item-divider">
Lunch
</div>
<ion-toggle ng-model="attendee.vegetarian">
Vegetarian
</ion-toggle>
<div class="padding">
<button class="button button-block" ng-click="submit()">Checkin</button>
</div>
</form>
<div ng-hide="showForm">
<pre ng-bind="attendee | json"></pre>
<a href="#/event/attendees">View attendees</a>
</div>
</ion-content>
</ion-view>
</script>
<script id="templates/attendees.html" type="text/ng-template">
<ion-view title="Event Attendees" left-buttons="leftButtons">
<ion-content>
<div class="list">
<ion-toggle ng-repeat="attendee in attendees | orderBy:'firstname' | orderBy:'lastname'"
ng-model="attendee.arrived"
ng-change="arrivedChange(attendee)">
{{ attendee.firstname }}
{{ attendee.lastname }}
</ion-toggle>
<div class="item item-divider">
Activity
</div>
<div class="item" ng-repeat="msg in activity">
{{ msg }}
</div>
</div>
</ion-content>
</ion-view>
</script>
</body>
</html>
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var core;
(function (core) {
"use strict";
core.app = angular.module("app", ["ionic", "ui.router"]);
(function (enumLoadingEvent) {
enumLoadingEvent[enumLoadingEvent["loading"] = 0] = "loading";
enumLoadingEvent[enumLoadingEvent["loaded"] = 1] = "loaded";
})(core.enumLoadingEvent || (core.enumLoadingEvent = {}));
var enumLoadingEvent = core.enumLoadingEvent;
var Controller = (function () {
//constructor(ctlrName: string, $scope: ng.IScope, $location: ng.ILocationService, translationService: service.Translation, notificationService: service.notification) {
function Controller(ctlrName, $scope, $location, $state, notificationService) {
var _this = this;
this.Loading = function () {
//TODO counter
_this.loading = true;
_this.scope.$emit(0 /* loading */.toString());
};
this.Loaded = function () {
//TODO counter
_this.loading = false;
_this.scope.$emit(1 /* loaded */.toString());
};
this.notify = notificationService;
this.ctlrName = ctlrName;
this.location = $location;
this.scope = $scope;
this.state = $state;
//translationService.getCtlrDictionnary(this);
this.loading = false;
//this.translate = translationService;
}
return Controller;
})();
core.Controller = Controller;
var ControllerEntity = (function (_super) {
__extends(ControllerEntity, _super);
function ControllerEntity(ctlrName, $scope, $location, $state, notificationService, $stateParams) {
_super.call(this, ctlrName, $scope, $location, $state, notificationService);
//retrieve route params
this.urlVerb = $stateParams.verb || "";
this.id = $stateParams.id || "";
switch (this.urlVerb) {
case "add":
//this.viewTitle = "Create customer";
this.actionTitle = "Create";
break;
case "edit":
//this.refreshData($routeParams.id);
//this.viewTitle = "Edit customer";
this.actionTitle = "Save";
break;
case "delete":
//this.refreshData($routeParams.id);
//this.viewTitle = "Delete customer";
this.actionTitle = "Delete";
break;
default:
alert("Wrong verb");
break;
}
}
return ControllerEntity;
})(core.Controller);
core.ControllerEntity = ControllerEntity;
var ControllerList = (function (_super) {
__extends(ControllerList, _super);
//constructor(ctlrName: string, $scope: ng.IScope, $location: ng.ILocationService, translationService: service.Translation, notificationService: service.notification) {
function ControllerList(ctlrName, $scope, $location, $state, notificationService) {
_super.call(this, ctlrName, $scope, $location, $state, notificationService);
}
return ControllerList;
})(core.Controller);
core.ControllerList = ControllerList;
(function (navigator_) {
function name() {
var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if (/trident/i.test(M[1])) {
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE ' + (tem[1] || '');
}
if (M[1] === 'Chrome') {
tem = ua.match(/\bOPR\/(\d+)/);
if (tem != null) {
return 'Opera ' + tem[1];
}
}
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
if ((tem = ua.match(/version\/(\d+)/i)) != null) {
M.splice(1, 1, tem[1]);
}
return M[0];
}
navigator_.name = name;
function version() {
var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
console.log(navigator.userAgent);
if (/trident/i.test(M[1])) {
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE ' + (tem[1] || '');
}
if (M[1] === 'Chrome') {
tem = ua.match(/\bOPR\/(\d+)/);
if (tem != null) {
return 'Opera ' + tem[1];
}
}
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
if ((tem = ua.match(/version\/(\d+)/i)) != null) {
M.splice(1, 1, tem[1]);
}
return M[1];
}
navigator_.version = version;
})(core.navigator_ || (core.navigator_ = {}));
var navigator_ = core.navigator_;
(function (cordova_) {
function RunningWithRipple() {
if (window.tinyHippos) {
return true;
} else {
return false;
}
}
cordova_.RunningWithRipple = RunningWithRipple;
})(core.cordova_ || (core.cordova_ = {}));
var cordova_ = core.cordova_;
})(core || (core = {}));
var core;
(function (core) {
(function (misc) {
/* Returns the class name of the argument or undefined if
* it's not a valid JavaScript object.
*/
function getObjectClass(obj) {
if (obj && obj.constructor && obj.constructor.toString) {
var arr = obj.constructor.toString().match(/function\s*(\w+)/);
if (arr && arr.length == 2) {
return arr[1];
}
}
return undefined;
}
misc.getObjectClass = getObjectClass;
function GUID_new() {
var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
return guid;
}
misc.GUID_new = GUID_new;
;
/**
* Zero padding (add 0 char on the left of a number i.e.: ZeroPadding(9,2) => "09"
*
* @num number to pad
* @size size of the returned string
*/
function ZeroPadding(num, size) {
var s = "000000000000" + num;
return s.substr(s.length - size);
}
misc.ZeroPadding = ZeroPadding;
/* Wait the end of several promises
* var fb = new Firebase("https://examples-sql-queries.firebaseio.com/");
* fb.child('user/123').once('value', function(userSnap) {
* fb.child('media/123').once('value', function(mediaSnap) {
* console.log( extend({}, userSnap.val(), mediaSnap.val()) );
* });
* });
*/
function extend(base) {
var parts = Array.prototype.slice.call(arguments, 1);
parts.forEach(function (p) {
if (p && typeof (p) === 'object') {
for (var k in p) {
if (p.hasOwnProperty(k)) {
base[k] = p[k];
}
}
}
});
return base;
}
misc.extend = extend;
})(core.misc || (core.misc = {}));
var misc = core.misc;
})(core || (core = {}));
var core;
(function (core) {
(function (service) {
var notification = (function () {
function notification() {
console.log("notificationService ... loaded");
}
notification.prototype.success = function (text) {
toastr.success(text, "success");
};
notification.prototype.error = function (text) {
toastr.error(text, "error");
};
notification.prototype.info = function (text) {
toastr.info(text, "info");
};
notification.prototype.warning = function (text) {
toastr.warning(text, "info");
};
return notification;
})();
service.notification = notification;
})(core.service || (core.service = {}));
var service = core.service;
})(core || (core = {}));
core.app.factory("notificationService", function () {
return new core.service.notification();
});
//module core.service {
// "use strict";
// export class Translation {
// _res: ng.resource.IResourceService;
// public UserLanguage(): string {
// return navigator.language || navigator.userLanguage;
// }
// public getCtlrDictionnary(ctlr:core.Controller): void{
// var dicoFileName: string = ctlr.ctlrName + "." + this.UserLanguage();
// //TODO CACHING
// this._res(ctlr.location.protocol() + "://" + ctlr.location.host() + ":" + ctlr.location.port() + "/scripts/dictionnaries/" + dicoFileName + ".json").get(
// (dico:any) => {
// ctlr.dico = dico;
// }, (response) => {
// //ctlr.notify.warning("Dictionnary not loaded for the controller:" + dicoFileName + "\n" + response);
// });
// }
// public translate(ctlr: core.Controller, key: string): string {
// //Object.
// //return ctlr.dico + "." + key;
// return "not translated";
// }
// constructor($resource: ng.resource.IResourceService) {
// this._res = $resource;
// console.log("translationService ... loaded");
// }
// }
//}
//core.app.factory("translationService", ($resource:ng.resource.IResourceService) => {
// return new core.service.Translation($resource);
//});
var kct;
(function (kct) {
(function (constant) {
constant.STORAGEKEY_PREFIX = "kct_";
constant.STORAGEKEY_TIMERS = constant.STORAGEKEY_PREFIX + "timers";
constant.TIMER_DURATION = 1000;
constant.TIMER_TICK_EVENT = "_tick";
constant.TIMER_OVER_EVENT = "_over";
constant.TIMER_STARTED_EVENT = "_started";
constant.TIMER_STOPPED_EVENT = "_stopped";
constant.SOUND_OVERTIME_ALERT = "content/alert.m4a";
constant.DATE_STORE_FORMAT = "YYYY-MM-DD";
//Platform depend constants
constant.PLATFORM_ANDROID = "Android";
constant.PLATFORM_IOS = "iOS";
constant.PLATFORM_WINDOWS_PHONE = "Win32NT";
constant.ASSET_ROOT_FOLDER;
function initialize() {
console.log("########### INITIALIZE #########");
console.log("Ripple:" + core.cordova_.RunningWithRipple());
console.log("Device:" + JSON.stringify(device));
console.log("navigator.product:" + navigator.product + "\nnavigator.vendor:" + navigator.vendor + "\nnavigator.appCodeName:" + navigator.appCodeName + "\nnavigator.userAgent:" + navigator.userAgent + "\nnavigator.platform:" + navigator.platform + "\nnavigator.appName:" + navigator.appName + "\nnavigator.appVersion:" + navigator.appVersion + "\nnavigator.appMinorVersion:" + navigator.appMinorVersion + "\nnavigator.language:" + navigator.language);
console.log("core.navigator:" + core.navigator_.name() + ":" + core.navigator_.version());
switch (device.platform) {
case constant.PLATFORM_ANDROID:
if (core.cordova_.RunningWithRipple()) {
//ASSET_ROOT_FOLDER = "assets/www/";
constant.ASSET_ROOT_FOLDER = "";
} else {
constant.ASSET_ROOT_FOLDER = "file:///android_asset/www/";
}
break;
case constant.PLATFORM_IOS:
constant.ASSET_ROOT_FOLDER = "";
break;
case constant.PLATFORM_WINDOWS_PHONE:
constant.ASSET_ROOT_FOLDER = "www/";
break;
default:
//console.log("ASSET_ROOT_FOLDER platform not known");
console.log("device:" + JSON.stringify(device));
navigator.notification.alert("ASSET_ROOT_FOLDER platform not known:" + device.platform, function () {
}, "kct.constant.initialize");
break;
}
console.log("ASSET_ROOT_FOLDER:" + constant.ASSET_ROOT_FOLDER);
console.log("########### INITIALIZE ENDED #########");
}
constant.initialize = initialize;
})(kct.constant || (kct.constant = {}));
var constant = kct.constant;
})(kct || (kct = {}));
core.app.filter('bitwiseAnd', function () {
return function (firstNumber, secondNumber) {
console.log(firstNumber + " & " + secondNumber + " = " + ((parseInt(firstNumber, 10) & parseInt(secondNumber, 10)) != 0));
//return ((parseInt(firstNumber, 10) & parseInt(secondNumber, 10)) === parseInt(secondNumber, 10));
return ((parseInt(firstNumber, 10) & parseInt(secondNumber, 10)) != 0);
// return firstNumber % secondNumber > 0
};
});
var kct;
(function (kct) {
(function (service) {
var TimersConfigService = (function () {
function TimersConfigService($rootScope) {
//this._rootScope = $rootScope;
console.log("timersConfigService ... loaded");
}
//private _rootScope: ng.IRootScopeService;
TimersConfigService.prototype.reinitializeAll = function () {
for (var guid in this._config) {
localStorage.removeItem(kct.constant.STORAGEKEY_PREFIX + guid);
}
localStorage.removeItem(kct.constant.STORAGEKEY_TIMERS);
this.getAllTimersConfig();
};
TimersConfigService.prototype.getAllTimersConfig = function () {
this._config = JSON.parse(localStorage.getItem(kct.constant.STORAGEKEY_TIMERS));
//check first time in the application
if (!this._config) {
//1st time in the application
//TODO navigate to init wizard
var config = {
dayOfLastTimersCalculation: "2013-02-08",
timersConfig: {
"569dc9e5-8874-46bc-9e92-1c8cfbdaf0a3": { guid: "569dc9e5-8874-46bc-9e92-1c8cfbdaf0a3", weekdays: 62, title: "Paul - game", durationMilliSecond: 5400000, durationHumanized: "01:30", picture: "", enable: true },
"a99897da-1460-409b-9778-571a3c4756ae": { guid: "a99897da-1460-409b-9778-571a3c4756ae", weekdays: 192, title: "Paul - TV", durationMilliSecond: 4000, durationHumanized: "01:00", picture: "", enable: true },
"17913ab4-b7b2-4aba-af9f-01e6019844b3": { guid: "17913ab4-b7b2-4aba-af9f-01e6019844b3", weekdays: 254, title: "Louis - game", durationMilliSecond: 10000, durationHumanized: "01:00", picture: "", enable: true },
"ef8d4703-d939-4b75-a814-0157cb8ac0b5": { guid: "ef8d4703-d939-4b75-a814-0157cb8ac0b5", weekdays: 126, title: "Louis - TV", durationMilliSecond: 5000, durationHumanized: "01:00", picture: "", enable: true },
"4d555d07-341c-40aa-aabe-9799577ba2a6": { guid: "4d555d07-341c-40aa-aabe-9799577ba2a6", weekdays: 6, title: "Richard - TV", durationMilliSecond: 3600000, durationHumanized: "01:00", picture: "", enable: false }
}
};
//localStorage.setItem(kct.constant.STORAGEKEY_KIDS, JSON.stringify(timersInit));
this._config = config;
this._storeConfig();
for (var timerConf in config.timersConfig) {
this._storeTimerValue(config.timersConfig[timerConf]);
}
//redo the whole treatment
this.getAllTimersConfig();
console.log("1st initialisation done");
}
//timers should be reinitialize every day
//Shoud we initialize the timers? Is last initialisation date today or before?
var n = moment(Date.now());
var d = moment(this._config.dayOfLastTimersCalculation, kct.constant.DATE_STORE_FORMAT);
var diff = n.diff(d);
var duration = moment.duration(diff);
var days = duration.asDays();
if (days > 1) {
//More than one day that we evaluate the timers
this._initializeTimers();
}
return this._config.timersConfig;
};
TimersConfigService.prototype._initializeTimers = function () {
console.log("_initializeTimers ....!");
var todayDay = moment(Date.now()).weekday() + 1;
for (var t in this._config.timersConfig) {
var config = this._config.timersConfig[t];
//remove the persisted timer
localStorage.removeItem(kct.constant.STORAGEKEY_PREFIX + config.guid);
//Is enable?
if (config.enable) {
//Is it a good day?
console.log("timer today?:" + (Math.pow(2, todayDay) && config.weekdays));
if ((Math.pow(2, todayDay) & config.weekdays) != 0) {
//Timer can run today
this._storeTimerValue(config);
}
}
}
//We update the indicator of the last
this._config.dayOfLastTimersCalculation = moment(Date.now()).format(kct.constant.DATE_STORE_FORMAT);
this._storeConfig();
};
TimersConfigService.prototype.getTimerConfig = function (guid) {
if (!this._config) {
this.getAllTimersConfig();
}
;
return this._config.timersConfig[guid];
};
/*
* replace the timerConfig by the one passed as parameter
* store the timersConfig
*
* DOES NOT UPDATE THE TIMER VALUE
*/
TimersConfigService.prototype.updateTimerConfig = function (timerConf) {
if (!this._config) {
this.getAllTimersConfig();
}
;
this._config.timersConfig[timerConf.guid] = timerConf;
this._storeConfig();
};
/*
* add the timerConfig in the instance array
* store the instance array
* store the timerConfig in timerValue
*/
TimersConfigService.prototype.createTimerConfig = function (timerConf) {
//add the timerConfig in the array and store it
this._config.timersConfig[timerConf.guid] = timerConf;
this._storeConfig();
//prepare and store the timerValue
this._storeTimerValue(timerConf);
};
/*
* delete the item from the timersConfig[]
* and persist it
*
* delete the timerValue persited either
*/
TimersConfigService.prototype.deleteTimerConfig = function (guid) {
//remove the timerConfig in memory and persist
delete this._config.timersConfig[guid];
this._storeConfig();
//remove the timerValue persisted key
localStorage.removeItem(kct.constant.STORAGEKEY_PREFIX + guid);
};
/*
* method to store the instance of the timerConfig array
*/
TimersConfigService.prototype._storeConfig = function () {
localStorage.setItem(kct.constant.STORAGEKEY_TIMERS, JSON.stringify(this._config));
};
/*
* Convert the timerConf in timerValue and store it
* usefull for creating a new timerConfig???
*/
TimersConfigService.prototype._storeTimerValue = function (timerConf) {
var timerValue = {
guid: timerConf.guid,
title: timerConf.title,
durationLeft_MilliSecond: timerConf.durationMilliSecond,
status: 10
};
localStorage.setItem(kct.constant.STORAGEKEY_PREFIX + timerConf.guid, JSON.stringify(timerValue));
};
return TimersConfigService;
})();
service.TimersConfigService = TimersConfigService;
})(kct.service || (kct.service = {}));
var service = kct.service;
})(kct || (kct = {}));
core.app.factory("timersConfigService", function ($rootScope) {
return new kct.service.TimersConfigService($rootScope);
});
var kct;
(function (kct) {
(function (service) {
var TimerService = (function () {
function TimerService($rootScope) {
this._timersToken = [];
this._rootScope = $rootScope;
console.log("TimerService ... loaded");
}
/*
* timer life could be longer than the scope life. Using this function is possible to reactivate events
* when scope & events are recreated
*/
TimerService.prototype.scopeToRaiseEvent = function (scope) {
this._scopeToRaiseEvent = scope;
};
TimerService.prototype.startTimer = function (guid) {
var _this = this;
var timerValue = this.getTimerValue(guid);
if (timerValue.status == 30 /* RUNNING */ || timerValue.status == 50 /* DONE */ || timerValue.status == 40 /* OVER */) {
console.log("Could not start timer status is not good");
} else {
this._timersToken[guid] = setInterval(function () {
var timerValue;
timerValue = _this.getTimerValue(guid);
timerValue.durationLeft_MilliSecond = moment.duration(timerValue.durationLeft_MilliSecond).subtract(1, "seconds").asMilliseconds();
//overtime?
if (timerValue.durationLeft_MilliSecond <= 0) {
//OVER Timer => raise event
timerValue.status = 40 /* OVER */;
//this._rootScope.$emit(guid + kct.constant.TIMER_OVER_EVENT, timerValue);
_this._scopeToRaiseEvent.$emit(guid + kct.constant.TIMER_OVER_EVENT, timerValue);
} else {
//Emit tick event
timerValue.status = 30 /* RUNNING */;
//this._rootScope.$emit(guid + kct.constant.TIMER_TICK_EVENT, timerValue);
_this._scopeToRaiseEvent.$emit(guid + kct.constant.TIMER_TICK_EVENT, timerValue);
}
//Persist the duration left
var timerValueStringified = JSON.stringify(timerValue);
localStorage.setItem(kct.constant.STORAGEKEY_PREFIX + guid, timerValueStringified);
}, kct.constant.TIMER_DURATION);
timerValue.status = 30 /* RUNNING */;
//this._rootScope.$emit(guid + kct.constant.TIMER_STARTED_EVENT, timerValue);
this._scopeToRaiseEvent.$emit(guid + kct.constant.TIMER_STARTED_EVENT, timerValue);
}
};
TimerService.prototype.stopTimer = function (guid) {
//clear the timer
clearInterval(this._timersToken[guid]);
this._timersToken[guid] = null;
//clean the timer status
var timerValue = this.getTimerValue(guid);
if (timerValue.status === 40 /* OVER */) {
timerValue.status = 50 /* DONE */;
} else {
timerValue.status = 20 /* HOLD */;
}
localStorage.setItem(kct.constant.STORAGEKEY_PREFIX + guid, JSON.stringify(timerValue));
//Emit stopped event
//this._rootScope.$emit(guid + kct.constant.TIMER_STOPPED_EVENT, timerValue);
this._scopeToRaiseEvent.$emit(guid + kct.constant.TIMER_STOPPED_EVENT, timerValue);
};
TimerService.prototype.getTimerValue = function (guid) {
return JSON.parse(localStorage.getItem(kct.constant.STORAGEKEY_PREFIX + guid));
};
return TimerService;
})();
service.TimerService = TimerService;
})(kct.service || (kct.service = {}));
var service = kct.service;
})(kct || (kct = {}));
core.app.factory("timerService", function ($rootScope) {
return new kct.service.TimerService($rootScope);
});
var kct;
(function (kct) {
(function (ctlr) {
"use strict";
var MainController = (function (_super) {
__extends(MainController, _super);
function MainController($scope, $http, $location, notificationService, $timeout, $state, timerService, timersConfigService) {
var _this = this;
_super.call(this, "appController", $scope, $location, $state, notificationService);
this.appTitle = "Kids coaching - Timer app";
this._timersConfigService = timersConfigService;
$scope.$on(0 /* loading */.toString(), function () {
_this.loading = true;
console.log("app.loading ...");
});
$scope.$on(1 /* loaded */.toString(), function () {
_this.loading = false;
console.log("app.loaded !!!");
});
console.log("MainController loaded!");
}
MainController.prototype.GoToConfig = function () {
this.state.go(kct.states.app_timersConfig).then(function (reason) {
console.log("state go well done: " + JSON.stringify(reason));
}).catch(function (error) {
console.log("state go WRONG: " + JSON.stringify(error));
});
console.log("Main controller - GoToConfig end:" + kct.states.app_timersConfig);
};
MainController.prototype.ClearAll = function () {
this._timersConfigService.reinitializeAll();
};
return MainController;
})(core.Controller);
ctlr.MainController = MainController;
})(kct.ctlr || (kct.ctlr = {}));
var ctlr = kct.ctlr;
})(kct || (kct = {}));
core.app.controller("mainController", kct.ctlr.MainController);
var kct;
(function (kct) {
(function (ctlr) {
"use strict";
var TimersConfigController = (function (_super) {
__extends(TimersConfigController, _super);
function TimersConfigController($scope, $http, $location, notificationService, timersConfigService, $state) {
_super.call(this, "kidsController", $scope, $location, $state, notificationService);
this.momentWeekDay0 = moment.weekdaysShort(0);
this.momentWeekDay1 = moment.weekdaysShort(1);
this.momentWeekDay2 = moment.weekdaysShort(2);
this.momentWeekDay3 = moment.weekdaysShort(3);
this.momentWeekDay4 = moment.weekdaysShort(4);
this.momentWeekDay5 = moment.weekdaysShort(5);
this.momentWeekDay6 = moment.weekdaysShort(6);
this.viewTitle = "Kid's timer list";
this._timersconfigService = timersConfigService;
this.timers = timersConfigService.getAllTimersConfig();
console.log("timersConfigController loaded!");
}
TimersConfigController.prototype.bitwiseAnd = function (num1, num2) {
//console.log(num1 + "&" + num2 + "=" + ((num1 & num2) != 0));
return (num1 & num2) != 0;
};
TimersConfigController.prototype.Navigate_New = function () {
this.state.go(kct.states.app_timersConfig_single, { id: 0, verb: "add" });
};
TimersConfigController.prototype.Navigate_Edit = function (guid) {
this.state.go(kct.states.app_timersConfig_single, { id: guid, verb: "edit" });
};
TimersConfigController.prototype.Navigate_Delete = function (guid) {
this.state.go(kct.states.app_timersConfig_single, { id: guid, verb: "delete" });
};
return TimersConfigController;
})(core.ControllerList);
ctlr.TimersConfigController = TimersConfigController;
})(kct.ctlr || (kct.ctlr = {}));
var ctlr = kct.ctlr;
})(kct || (kct = {}));
core.app.controller("timersConfigController", kct.ctlr.TimersConfigController);
var kct;
(function (kct) {
(function (ctlr) {
var TimersController = (function (_super) {
__extends(TimersController, _super);
function TimersController($scope, $rootScope, $http, $location, $ionicSideMenuDelegate, notificationService, timerService, timersConfigService, $state) {
var _this = this;
_super.call(this, "timerController", $scope, $location, $state, notificationService);
this._media = {};
this.timers = {};
this.Start = function (guid) {
_this._timerService.startTimer(guid);
};
this.Stop = function (guid) {
_this._timerService.stopTimer(guid);
};
this.WhenIsNext = function (guid) {
console.log("When is next clicked!");
};
this.Acknowledge = function (guid) {
console.log("Acknowledge " + guid + " clicked!");
_this._media[guid].pause();
_this._media[guid].release();
_this._media[guid] = null;
_this.Stop(guid);
};
this._timerService = timerService;
this.viewTitle = "Kid coaching timer";
this._ionicSideMenuDelegate = $ionicSideMenuDelegate;
this.Loading();
//retrieve kids config
var timersConfig = timersConfigService.getAllTimersConfig();
for (var t in timersConfig) {
//retrieve the kid configuration and value
var timerStatus = timerService.getTimerValue(t);
if (!timerStatus) {
//nothing to do
} else {
//timer found, initialize the timer array
var uiTimer = {
guid: timersConfig[t].guid,
title: timerStatus.title,
durationLeft: moment.duration(timerStatus.durationLeft_MilliSecond),
durationLeftString: this._durationStringFormat(moment.duration(timerStatus.durationLeft_MilliSecond)),
status: timerStatus.status,
ready: false,
hold: false,
running: false,
over: false,
done: false
};
this._statusCalcultation(uiTimer);
this.timers[uiTimer.guid] = uiTimer;
//if the timer are already running this is to change the scope instance
timerService.scopeToRaiseEvent(this.scope);
//*** START EVENT ***
this.scope.$on(timerStatus.guid + kct.constant.TIMER_STARTED_EVENT, function (evt, evtTimer) {
console.log("timer:" + evtTimer.title + "_started received ...:" + JSON.stringify(evtTimer));
//Update controller datas
_this.timers[evtTimer.guid].durationLeft = moment.duration(evtTimer.durationLeft_MilliSecond);
_this.timers[evtTimer.guid].durationLeftString = _this._durationStringFormat(_this.timers[evtTimer.guid].durationLeft);
_this.timers[evtTimer.guid].status = evtTimer.status;
_this._statusCalcultation(_this.timers[evtTimer.guid]);
});
//*** TICK EVENT ***
this.scope.$on(timerStatus.guid + kct.constant.TIMER_TICK_EVENT, function (evt, evtTimer) {
console.log("timer:" + evtTimer.title + "_tick received ...:" + JSON.stringify(evtTimer));
//Update controller datas
//Event out of angular (setinterval) so we use $apply to update the view
_this.scope.$apply(function () {
_this.timers[evtTimer.guid].durationLeft = moment.duration(evtTimer.durationLeft_MilliSecond);
_this.timers[evtTimer.guid].durationLeftString = _this._durationStringFormat(_this.timers[evtTimer.guid].durationLeft);
_this.timers[evtTimer.guid].status = evtTimer.status; //no need of started event ;-)
_this._statusCalcultation(_this.timers[evtTimer.guid]);
});
});
//*** OVER EVENT ***
this.scope.$on(timerStatus.guid + kct.constant.TIMER_OVER_EVENT, function (evt, evtTimer) {
console.log("timer:" + evtTimer.title + "_over received ...:" + JSON.stringify(evtTimer));
//Update controller datas
//Event out of angular (setinterval) so we use $apply to update the viewthis.timers[evtTimer.guid].durationLeft = moment.duration(evtTimer.durationLeft_MilliSecond);
_this.scope.$apply(function () {
_this.timers[evtTimer.guid].durationLeftString = _this._durationStringFormat(_this.timers[evtTimer.guid].durationLeft);
_this.timers[evtTimer.guid].status = evtTimer.status;
_this._statusCalcultation(_this.timers[evtTimer.guid]);
//Play the alert (if not already playing)
if (_this._media[evtTimer.guid]) {
} else {
//this._media[evtTimer.guid] = new Audio(kct.constant.SOUND_OVERTIME_ALERT);
//console.log("kct.constant.ASSET_ROOT_FOLDER:" + kct.constant.ASSET_ROOT_FOLDER);
//navigator.notification.alert("file to play:\n" + kct.constant.ASSET_ROOT_FOLDER + kct.constant.SOUND_OVERTIME_ALERT, () => { }, "kct.constant.timersController");
_this._media[evtTimer.guid] = new Media(kct.constant.ASSET_ROOT_FOLDER + kct.constant.SOUND_OVERTIME_ALERT, function () {
}, function mediaError(errObj) {
//Write the error object contents to the console
console.error(JSON.stringify(errObj));
navigator.notification.alert("Error:" + JSON.stringify(errObj), function () {
}, "timersController-MediaError");
//Let the user know what happened
var errStr;
//Had to add this because some of the error conditions I encountered
//did not provide a message value
if (errObj.message.length > 0) {
errStr = errObj.message + " (Code: " + errObj.code + ")";
} else {
errStr = "Error code: " + errObj.code + " (No error message provided by the Media API)";
}
console.error(errStr);
}, function mediaStatus(statusCode) {
console.log("Entering mediaStatus");
var theStatus;
switch (statusCode) {
case Media.MEDIA_NONE:
theStatus = "None";
break;
case Media.MEDIA_STARTING:
theStatus = "Starting";
break;
case Media.MEDIA_RUNNING:
theStatus = "Running";
break;
case Media.MEDIA_PAUSED:
theStatus = "Paused";
break;
case Media.MEDIA_STOPPED:
theStatus = "Stopped";
break;
default:
theStatus = "Unknown";
}
console.log("Status: " + statusCode + " " + theStatus);
$('#statRes').html(theStatus);
console.log("Leaving mediaStatus");
});
console.log("Media object:" + JSON.stringify(_this._media[evtTimer.guid]));
_this._media[evtTimer.guid].play();
}
// TODO est-ce que cela apparait dans la liste?
// TODO: est-ce que cela apparait dans la liste?
//TODO play sound repeatly
//function gun_bang() {
// var audio = document.createElement("audio");
// audio.src = "http://www.seancannon.com/_test/audio/gun_bang.wav";
// audio.addEventListener("ended", function () {
// document.removeChild(this);
// }, false);
// audio.play();
//}
//$('#' + CANVAS_ID).bind(_click, function () {
// gun_bang();
// adj_game_data(GAME_DATA_AMMO_ID, -1);
// check_ammo();
//});
//if (!$rootScope.$$phase) {
// $rootScope.$apply();
//}
});
});
//*** STOPPED EVENT ***
this.scope.$on(timerStatus.guid + kct.constant.TIMER_STOPPED_EVENT, function (evt, evtTimer) {
console.log("timer:" + evtTimer.title + "_stopped received ...:" + JSON.stringify(evtTimer));
_this.timers[evtTimer.guid].status = evtTimer.status;
_this._statusCalcultation(_this.timers[evtTimer.guid]);
});
}
}
this.Loaded();
console.log("TimersController loaded!");
}
//RightToggle() {
// console.log("in RightToggle");
// this._ionicSideMenuDelegate.toggleRight();
//}
TimersController.prototype.Command = function (guid) {
switch (this.timers[guid].status) {
case 10 /* READY */:
this.Start(guid);
break;
case 20 /* HOLD */:
this.Start(guid);
break;
case 30 /* RUNNING */:
this.Stop(guid);
break;
case 40 /* OVER */:
this.Acknowledge(guid);
break;
case 50 /* DONE */:
this.WhenIsNext(guid);
break;
default:
console.log("WRONG TIMER STATUS VALUE");
}
};
TimersController.prototype._durationStringFormat = function (d) {
return core.misc.ZeroPadding(d.hours(), 2) + ":" + core.misc.ZeroPadding(d.minutes(), 2) + ":" + core.misc.ZeroPadding(d.seconds(), 2);
};
TimersController.prototype._statusCalcultation = function (timer) {
switch (timer.status) {
case 10 /* READY */:
timer.ready = true;
timer.hold = false;
timer.running = false;
timer.over = false;
timer.done = false;
break;
case 20 /* HOLD */:
timer.ready = false;
timer.hold = true;
timer.running = false;
timer.over = false;
timer.done = false;
break;
case 30 /* RUNNING */:
timer.ready = false;
timer.hold = false;
timer.running = true;
timer.over = false;
timer.done = false;
break;
case 40 /* OVER */:
timer.ready = false;
timer.hold = false;
timer.running = false;
timer.over = true;
timer.done = false;
break;
case 50 /* DONE */:
timer.ready = false;
timer.hold = false;
timer.running = false;
timer.over = false;
timer.done = true;
break;
default:
timer.ready = false;
timer.hold = false;
timer.running = false;
timer.over = false;
timer.done = true;
}
};
return TimersController;
})(core.Controller);
ctlr.TimersController = TimersController;
})(kct.ctlr || (kct.ctlr = {}));
var ctlr = kct.ctlr;
})(kct || (kct = {}));
core.app.controller("timersController", kct.ctlr.TimersController);
var kct;
(function (kct) {
//export class enumRoute {
// // boilerplate
// constructor(public value: string) {
// }
// toString() {
// return this.value;
// }
// // values
// static app : string = new enumRoute("app");
// static app_timers = new enumRoute("app.timers");
//}
//enum enumRoutes {
// app,
// app.timers,
// Disabled
//}
//// **** FROM *****
//enum Link {
// LEARN = <any>'/Tutorial',
// PLAY = <any>'/Playground',
// GET_IT = <any>'/#Download',
// RUN_IT = <any>'/Samples',
// JOIN_IN = <any>'/#Community'
//}
//alert('Link.LEARN: ' + Link.LEARN);
//alert('Link.PLAY: ' + Link.PLAY);
//alert('Link.GET_IT: ' + Link.GET_IT);
//alert('Link[\'/Samples\']: Link.' + Link['/Samples']);
//alert('Link[\'/#Community\'] Link.' + Link['/#Community']);
//export enum routes {
// app = <any>'/app',
// app_timers = <any>'/app.timers',
// app_timersConfig = <any>'/#app.timersConfig',
//}
var states = (function () {
function states() {
}
states.app = "app";
states.app_timers = "app.timers";
states.app_timersConfig = "app.timersConfig";
states.app_timersConfig_single = "app.timersConfig_single";
return states;
})();
kct.states = states;
core.app.config(function ($stateProvider, $urlRouterProvider) {
console.log("Routing initialization - start");
$stateProvider.state(states.app, {
url: "/app",
abstract: true,
//controller: "mainController as mainCtlr",
templateUrl: "app/views/mainView.html"
}).state(states.app_timers, {
url: "/timers",
views: {
"menuContent": {
templateUrl: "app/views/timers/timersView.html"
}
}
}).state(states.app_timersConfig, {
name: states.app_timersConfig,
url: '/timersconfig',
views: {
'menuContent': {
templateUrl: 'app/views/timers/config/timersConfigView.html',
controller: "timersConfigController as timersConfigCtlr"
}
}
}).state(states.app_timersConfig_single, {
url: "/timersconfig/{id}/{verb}",
views: {
'menuContent': {
templateUrl: "app/views/timers/config/timerConfigView.html",
controller: "timerConfigController as timerConfigCtlr"
}
}
});
$urlRouterProvider.otherwise('/app/timers');
console.log("Routing initialization - end");
});
})(kct || (kct = {}));
//ng - app = "app" ng - controller = "appController as appCtlr"
//document.addEventListener("deviceready", function () {
// // retrieve the DOM element that had the ng-app attribute
// var domElement = document.getElementById("app");
// console.log("device ready:" + domElement.id);
// angular.bootstrap(domElement, ["app"]);
//}, false);
var t3;
(function (t3) {
"use strict";
core.app.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
// // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// // for form inputs)
// if (window.cordova && window.cordova.plugins.Keyboard) {
// cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// }
// if (window.StatusBar) {
// // org.apache.cordova.statusbar required
// //RL StatusBar.styleDefault(); modification to allow compilation
// window.StatusBar.styleDefault();
// }
console.log("ionicPlaform.ready's event");
});
});
core.app.config(function () {
//angular.module("app").run(()=>{
kct.constant.initialize();
});
(function (Application) {
function initialize() {
document.addEventListener('deviceready', onDeviceReady, false);
}
Application.initialize = initialize;
function onDeviceReady() {
console.log("onDeviceReady's event-start");
// Handle the Cordova pause and resume events
document.addEventListener('pause', onPause, false);
document.addEventListener('resume', onResume, false);
// initialize the platform depend variables
//kct.constant.initialize();
// init ng-app
//var domElement = document.getElementById("app");
//console.log("device ready:" + domElement.id);
//angular.bootstrap(domElement, ["app"]);
//console.log("onDeviceReady's event-end");
}
function onPause() {
// TODO: This application has been suspended. Save application state here.
console.log("onPause event");
}
function onResume() {
// TODO: This application has been reactivated. Restore application state here.
console.log("onResumer event");
}
})(t3.Application || (t3.Application = {}));
var Application = t3.Application;
})(t3 || (t3 = {}));
/// <reference path="scripts/typings/moment/moment.d.ts" />
/// <reference path="missingreference.d.ts" />
/// <reference path="appcore/core.ts" />
/// <reference path="appcore/misc.ts" />
/// <reference path="appcore/notificationservice.ts" />
/// <reference path="appcore/translationservice.ts" />
/// <reference path="app/config.ts" />
/// <reference path="app/filters.ts" />
/// <reference path="app/service/timersConfigService.ts" />
/// <reference path="app/service/timerservice.ts" />
/// <reference path="app/views/maincontroller.ts" />
/// <reference path="app/views/timers/config/timersconfigcontroller.ts" />
/// <reference path="app/views/timers/timerscontroller.ts" />
/// <reference path="app/routing.ts" />
/// <reference path="app/app.ts" />
var kct;
(function (kct) {
(function (ctlr) {
"use strict";
var TimerConfigController = (function (_super) {
__extends(TimerConfigController, _super);
function TimerConfigController($scope, $http, $location, notificationService, timersConfigService, $stateParams, $state) {
var _this = this;
_super.call(this, "TimerConfigController", $scope, $location, $state, notificationService, $stateParams);
this.momentWeekDay0 = moment.weekdaysShort(0);
this.momentWeekDay1 = moment.weekdaysShort(1);
this.momentWeekDay2 = moment.weekdaysShort(2);
this.momentWeekDay3 = moment.weekdaysShort(3);
this.momentWeekDay4 = moment.weekdaysShort(4);
this.momentWeekDay5 = moment.weekdaysShort(5);
this.momentWeekDay6 = moment.weekdaysShort(6);
this.onCancel = function () {
_this.location.path("/timers");
};
this.onSubmit = function () {
switch (_this.urlVerb) {
case "add":
_this._timersConfigService.createTimerConfig(_this.timer);
break;
case "edit":
_this._timersConfigService.updateTimerConfig(_this.timer);
break;
case "delete":
_this._timersConfigService.deleteTimerConfig(_this.timer.guid);
break;
}
_this.onCancel();
};
this.weekDaysChanged = function (day) {
day += 1;
var pow = Math.pow(2, day);
var weekDayBef = _this.timer.weekdays;
_this.timer.weekdays = pow ^ _this.timer.weekdays;
console.log(weekDayBef + " ^ " + pow + "=" + _this.timer.weekdays);
};
this.hoursChanged = function (value) {
_this.durationHours = value;
_this._convertToTimerDuration();
};
this.minutesChanged = function (value) {
_this.durationMinutes = value;
_this._convertToTimerDuration();
};
this._formatDuration = function () {
//var hours = this.durationHours > 0 ? core.misc.ZeroPadding(this.durationHours, 2) + " hours" : "";
//var minutes = this.durationMinutes > 0 ? core.misc.ZeroPadding(this.durationMinutes, 2) + " minutes" : "";
//var and = (hours != "" && minutes != "") ? " and " : "";
//this.timer.durationHumanized = hours + and + minutes;
_this.timer.durationHumanized = core.misc.ZeroPadding(_this.durationHours, 2) + ":" + core.misc.ZeroPadding(_this.durationMinutes, 2);
};
this.viewTitle = "Timer configuration";
this._timersConfigService = timersConfigService;
if (this.id == "0") {
//No id => add
//Initialise a timer object
this.timer = {
guid: core.misc.GUID_new(),
title: "",
durationMilliSecond: 5400000,
durationHumanized: "",
picture: "",
weekdays: 192,
enable: true
};
} else {
//Id => edit/delete/detail
//retrieve the timerConf
this.timer = this._timersConfigService.getTimerConfig(this.id);
}
//Convert duration in hours and minutes
var dur = moment.duration(this.timer.durationMilliSecond);
this.durationHours = dur.hours();
this.durationMinutes = dur.minutes();
this._formatDuration();
console.log("timerConfigController loaded!" + JSON.stringify(this.timer));
}
TimerConfigController.prototype._convertToTimerDuration = function () {
this.timer.durationMilliSecond = this.durationHours * 3600000 + this.durationMinutes * 60000;
this._formatDuration();
};
return TimerConfigController;
})(core.ControllerEntity);
ctlr.TimerConfigController = TimerConfigController;
})(kct.ctlr || (kct.ctlr = {}));
var ctlr = kct.ctlr;
})(kct || (kct = {}));
core.app.controller("timerConfigController", kct.ctlr.TimerConfigController);
var kct;
(function (kct) {
(function (model) {
(function (enumTimerStatus) {
enumTimerStatus[enumTimerStatus["READY"] = 10] = "READY";
enumTimerStatus[enumTimerStatus["HOLD"] = 20] = "HOLD";
enumTimerStatus[enumTimerStatus["RUNNING"] = 30] = "RUNNING";
enumTimerStatus[enumTimerStatus["OVER"] = 40] = "OVER";
enumTimerStatus[enumTimerStatus["DONE"] = 50] = "DONE";
})(model.enumTimerStatus || (model.enumTimerStatus = {}));
var enumTimerStatus = model.enumTimerStatus;
function enumTimerStatus_String(val) {
switch (val) {
case 10 /* READY */:
return "READY";
break;
case 20 /* HOLD */:
return "HOLD";
break;
case 30 /* RUNNING */:
return "RUNNING";
break;
case 40 /* OVER */:
return "OVER";
break;
case 50 /* DONE */:
return "DONE";
break;
default:
return "WRONG TIMER STATUS VALUE";
}
}
model.enumTimerStatus_String = enumTimerStatus_String;
})(kct.model || (kct.model = {}));
var model = kct.model;
})(kct || (kct = {}));
// Platform specific overrides will be placed in the merges folder versions of this file
//# sourceMappingURL=app.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment