-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
410 lines (274 loc) · 9.48 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
//Modified
//secondApp gets injected into rootApp <body ng-app='rootApp'> scope
//Make Structure Diagram
var rootApp = angular.module('rootApp', ['firstApp','secondApp']);
var firstApp = angular.module('firstApp', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
//UPSI controller
firstApp.controller('hourController', ['$scope', function($scope) {
$scope.today = new Date();
$scope.hour = {value:null};
$scope.answer = 'Higher';
$scope.added = new Date();
//https://stackoverflow.com/questions/1050720/adding-hours-to-javascript-date-object
$scope.shouldBeOpen = false;
$scope.addhours = function (){
var hourV = $scope.hour.value;
Date.prototype.addHours= function(h){
this.setHours(this.getHours()-h);
return this;
};
$scope.addedHours = new Date().addHours(hourV);
console.log('Oh yeah we flying ' + new Date().addHours(hourV));
//Once addHours clicked change shouldBeOpen boolean
//Past date now appears
$scope.shouldBeOpen = true;
};
$(function() {
$('.hourRes,#prangeC').hide();
var a1 = moment(new Date());//now
var a2 = a1.format("dddd, MMMM Do YYYY, h:mm:ss a");
$('input.form-control').val(a2);
$('h5.DateChosen').html('Todays Date: ' + a2);
function upDate() {
var dateStr = $('input.form-control').val();//Input
var a = moment(new Date());//now
var b = moment(dateStr,"dddd, MMMM Do YYYY, h:mm:ss a");//Date chosen
var c = moment(dateStr,"dddd, MMMM Do YYYY, h:mm:ss a");//Date chosen for plus 120
//Check difference
var mins ='Minutes ago: ' + a.diff(b, 'minutes');
var hours ='Hours ago: '+ a.diff(b, 'hours');
var days ='Days ago: '+ a.diff(b, 'days');
var weeks = a.diff(b, 'weeks');
var hrs = a.diff(b, 'hours');
//Used the c variable
var hours120 ='120 Hours ahead: '+ c.add(120,'hours').format("dddd, MMMM Do YYYY, h:mm:ss a");
console.log(a.diff(b, 'minutes')); // 44700
console.log(a.diff(b, 'hours')); // 745
console.log(a.diff(b, 'days')); // 31
console.log(a.diff(b, 'weeks')); // 4
$scope.hour = {value:130};
$('#daysAgo').html(days);//Input
$('#hoursAgo').html(hours);//Input
$('#hoursplus120').html(hours120);
//$('#minutesAgo').html(mins);
var hourLimit = $('#hourz').val(hrs);
if(hrs < 120) {
$('#answer').val('This is under 120 hours');
console.log('This is under 120');
$('#prangeC').hide();
$('h3.hourMsg').show();
} else if(hrs > 120) {
$('#answer').val('This is over 120 hours');
$('#prangeC').show();
$('h3.hourMsg').hide();
console.log('This is over 120');
}
};
$('#datetimepicker1').datetimepicker({
format: 'dddd, MMMM Do YYYY, h:mm:ss a'
});
$("#datetimepicker1").on("dp.change", function (e) {
console.log('WTF' + e.date);
$('#dateInput').data("DateTimePicker").minDate(e.date);
});
$('#dateInput').on('input', upDate());//End change
$('#dateInput').on('click', upDate());
$('span.glyphicon-calendar').on('click', upDate());
$('#datetimepicker1').click(function() {
upDate();
$('.hourRes').show();
});//End clicked
});
}]); //End firstApp hourController
(function () {
'use strict';
var secondApp = angular.module('secondApp', ['ngMaterial']);
secondApp.controller('prangeController', ['$scope', function($scope) {
//This .value is the one being manipulated
// Very important variables
$scope.min1 = 21;
$scope.max1 = 42;
//Period range
$scope.min = 21;
$scope.max = 42;
$scope.expovu = 14;
$scope.iudrange = 5;
//input
$scope.totalcycle = null;// nine
//console.log($scope.answer);
$scope.today = new Date();
$scope.change = new Date();
//Pure JS
$scope.addDays1 = function (){
//Restart $scope.change date to fresh todays date
$scope.change = new Date();
//Need a date for the last day of IUD range,
//Format x to a number // they shouldnt be able to continously add numbers
var xp = document.getElementById("fullc").value;
// Give it the number property and invalid contents
//xp.type = "number";
//xp.value = "qwerty";
// If the string isn't empty, we have a problem
//console.log( element.value ? "Not Supported" : "Supported" );
var changeGet = $scope.change.getDate();
var todayGet = $scope.today.getDate();
//alert(todayGet);
//Use the integer value for validation
var todayInt = Date.parse($scope.today);
var changeInt = Date.parse($scope.change);
//x is full cycle number
var x = parseInt(xp)
console.log('adding:' + x);
console.log('change date is: ' + changeGet);
console.log('todays date is: ' + todayGet);
//Add days if condition is true
var total = todayInt + changeInt;
//Full cycle length
var fullCycleLength = x;
//Check if you still need this condition!!!!
if(todayInt < changeInt) {
//28 - 14 = 14
var firstiudRange = fullCycleLength - $scope.expovu; //14;
//14 + 5 = 19
var secondiudRange = firstiudRange + $scope.iudrange; //Iud length;
var minusOp = '-';
//Date changes here minus for back in time, plus for forward in time
$scope.newdate1 = $scope.change.setDate(changeGet + firstiudRange);
//$scope.newdatemin1 = $scope.change.setDate(changeGet - firstiudRange);
//Restart $scope.change date for newdate2
$scope.change = new Date();
$scope.newdate2 = $scope.change.setDate(changeGet + secondiudRange);
//$scope.newdatemin2 = $scope.change.setDate(changeGet - secondiudRange);
console.log($scope.newdate1 + '--->' +$scope.newdate2);
};
};//End method addDays
//Initiate Date by click
function clickOnUpload() {
$timeout(function() {
angular.element('#myrange').triggerHandler('click');
});
};
function getScope(ctrlName) {
var sel = 'div[ng-controller="' + ctrlName + '"]';
return angular.element(sel).scope();
}
function changeText() {
var $scope = getScope('prangeController');
$scope.my = null;
$scope.$apply();
}
$( "#fullc" ).change(function() {
$( "#cleard" ).click();
//changeText();
});
}]);//End prangeController
secondApp.config(function($mdDateLocaleProvider) {
/**
* @param date {Date}
* @returns {string} string representation of the provided date
*/
$mdDateLocaleProvider.formatDate = function(date) {
if (!date) {return '';
} else {
return moment(date).format('DD-MM-YYYY');
}
//return date ? moment(date).format('L') : '';
};
/**
* @param dateString {string} string that can be converted to a Date
* @returns {Date} JavaScript Date object created from the provided dateString
*/
$mdDateLocaleProvider.parseDate = function(dateString) {
var m = moment(dateString, 'DD-MM-YYYY', true);
return m.isValid() ? m.toDate() : new Date(NaN);
};
})
.controller("AppCtrl", function($log) {
this.DateTrue = false;
var mD = this.myDate,
sD = this.selected,
iD = this.iudLast,
pD = this.Date,
tD = this.todaysDate;
var rightnow = new Date();
this.onDateChanged = function() {
$log.log('Updated Date: ', this.myDate);
Date.prototype.addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
}
var date = this.myDate;
// This variables change the results directly!
var dp = document.getElementById("fullc").value;
//Iud backtrack from next period
var dayForLastIud = 10;
//1st day Ovulation Backtrack from full cycle
var firstO = 15;
//var get = this.myDate.getDate();
//var getDate = this.myDate.getDate();
//y is full cycle number
var y = parseInt(dp);
var x = dayForLastIud;
var z = firstO;
//Full cycle set date
this.selected = date;
//Now True
this.periodDateTrue = true;
//alert(this.myDate.getDate());
this.Date = date.addDays(y);
//Full Cycle minus firstOvulation number (backtrack)
//example 28 - 14 = Day 15
this.firstOv = date.addDays(y - z);
//Full Cycle minus last IUD number (backtrack)
//example 28 - 10 = 18 days from the last
this.iudLast = date.addDays(y - x);
//Start of message boolean
this.IUDright = null;
console.log('WTF !!!!!' + iudLastMinusTimestamp +' or ' + rightnowMinusTimestamp );
if ( rightnow > this.iudLast) {
//$('#answer').html('Todays date is too late for IUD');
console.log('Todays date is too late for IUD '+ rightnow +' is ahead Iud Last: ' + this.iudLast);
this.IUDright = false;
} else {
// $('#answer').html('Todays date is still good for IUD');
console.log('Todays date is still good for IUD '+ rightnow +' is behind Iud Last: ' + this.iudLast);
this.IUDright = null;
}
//Format for Comparison is 2010-MM-DD *****Start
var rightnowMinusTimestamp = moment(rightnow).format('DD-MM-YYYY');
var iudLastMinusTimestamp = moment(this.iudLast).format('DD-MM-YYYY')
function compare(dateTimeA, dateTimeB) {
var momentA = moment(dateTimeA,"DD/MM/YYYY");
var momentB = moment(dateTimeB,"DD/MM/YYYY");
if (momentA > momentB){
return 1;
} else if (momentA < momentB){
return -1;
} else {
return 0;
}
};
//If equals 1 then IUD last is ahead of present time
//If equals -1 then IUD Last is behind present timeout
//If equals 0 then IUD last is the same day/time
var comparison = compare(iudLastMinusTimestamp, rightnowMinusTimestamp );
console.log('Comparison:' + comparison);
var iudlastAheadorNot = compare(iudLastMinusTimestamp, rightnowMinusTimestamp );
//Special condition for if the Last Iud is Todays date
if (comparison == 0){
this.IUDright = true;
}
};//End controller
//Clear date after changing fullcycle
this.clearDate = function (){
this.periodDateTrue = false;
this.myDate = null;
};
});
// jQuery(document).ready(function($) {
//setTimeout(changeText, 30000);
//});
})();
rootApp.controller('rootCon', ['$scope', function($scope) {
}]);