UNPKG

@uicapivara/cp-date

Version:

cp-date

495 lines (493 loc) 20.1 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for src/component/date.component.ts</title> <meta charset="utf-8" /> <link rel="stylesheet" href="../../prettify.css" /> <link rel="stylesheet" href="../../base.css" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <style type='text/css'> .coverage-summary .sorter { background-image: url(../../sort-arrow-sprite.png); } </style> </head> <body> <div class='wrapper'> <div class='pad1'> <h1> <a href="../../index.html">all files</a> / <a href="index.html">src/component/</a> date.component.ts </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">22.73% </span> <span class="quiet">Statements</span> <span class='fraction'>15/66</span> </div> <div class='fl pad1y space-right2'> <span class="strong">0% </span> <span class="quiet">Branches</span> <span class='fraction'>0/81</span> </div> <div class='fl pad1y space-right2'> <span class="strong">7.14% </span> <span class="quiet">Functions</span> <span class='fraction'>1/14</span> </div> <div class='fl pad1y space-right2'> <span class="strong">23.33% </span> <span class="quiet">Lines</span> <span class='fraction'>14/60</span> </div> </div> </div> <div class='status-line low'></div> <pre><table class="coverage"> <tr><td class="line-count quiet">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</td><td class="line-coverage quiet"><span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span></td><td class="text"><pre class="prettyprint lang-js">import $ from 'jquery'; import 'jquery-datetimepicker/build/jquery.datetimepicker.min.css'; import 'jquery-datetimepicker'; &nbsp; export class CapivaraDate { public $constants; public $functions; public $bindings; private element; private oi; private inputElement; &nbsp; <span class="fstat-no" title="function not covered" > constructor($scope, $element)</span> { <span class="cstat-no" title="statement not covered" > this.element = $element;</span> <span class="cstat-no" title="statement not covered" > this.$constants = this.$constants || {};</span> } &nbsp; <span class="fstat-no" title="function not covered" > $onViewInit() {</span> <span class="cstat-no" title="statement not covered" > this.inputElement = this.element.querySelector('input.cp-date');</span> <span class="cstat-no" title="statement not covered" > if (typeof this.$bindings.cpModel === 'string') {</span> <span class="cstat-no" title="statement not covered" > this.$bindings.cpModel = new Date(this.$bindings.cpModel);</span> } <span class="cstat-no" title="statement not covered" > if(this.$bindings.cpModel == 'Invalid Date'){</span> <span class="cstat-no" title="statement not covered" > delete this.$bindings.cpModel;</span> } <span class="cstat-no" title="statement not covered" > this.setModelInInput();</span> <span class="cstat-no" title="statement not covered" > this.createCpDate();</span> } &nbsp; <span class="cstat-no" title="statement not covered" > $onChanges = <span class="fstat-no" title="function not covered" >(changes)</span> =&gt; {</span> <span class="cstat-no" title="statement not covered" > if (changes &amp;&amp; changes[0] &amp;&amp; changes[0].name == 'cpModel') {</span> <span class="cstat-no" title="statement not covered" > this.setModelInInput();</span> } } &nbsp; /** * @method void Method responsible for start and configurate the CpDate */ <span class="fstat-no" title="function not covered" > createCpDate() {</span> <span class="cstat-no" title="statement not covered" > $.datetimepicker.setLocale(this.$constants.language || 'pt-BR')</span> <span class="cstat-no" title="statement not covered" > $(this.inputElement).datetimepicker({</span> timepicker: this.$constants.timepicker == undefined ? true : this.$constants.timepicker, datepicker: this.$constants.datepicker == undefined ? true : this.$constants.datepicker, format: this.$constants.format == undefined ? 'd/m/Y H:i' : this.$constants.format, mask: this.$constants.mask == undefined ? true : this.$constants.mask, inline: this.$constants.openedCalendar == undefined ? false : this.$constants.openedCalendar, allowTimes: this.$constants.allowedTimes || [], defaultTime: this.$constants.defaultTime == undefined ? false : this.$constants.defaultTime, defaultDate: this.$constants.defaultDate == undefined ? false : this.$constants.defaultDate, step: this.$constants.step || 60, weeks: this.$constants.weekNumbers == undefined ? false : this.$constants.weekNumbers, yearStart: this.$constants.yearStart || 1950, yearEnd: this.$constants.yearEnd || 2050, dayOfWeekStart: this.$constants.dayOfWeekStart || 0, disabledDates: this.$constants.disabledDates || [], minDate: this.$constants.minDate == undefined ? false : this.$constants.minDate, maxDate: this.$constants.maxDate == undefined ? false : this.$constants.maxDate, onChangeDateTime: <span class="fstat-no" title="function not covered" >(dp, $input)</span> =&gt; { <span class="cstat-no" title="statement not covered" > if(this.$constants.openCalendar){</span> <span class="cstat-no" title="statement not covered" > this.setModelInInput();</span> } <span class="cstat-no" title="statement not covered" > $(this.inputElement).datetimepicker({mask: this.$constants.mask == undefined ? true : this.$constants.mask})</span> <span class="cstat-no" title="statement not covered" > this.$bindings.cpModel = dp;</span> } }); } &nbsp; /** * @method boolean Method responsible to check if the user selected an allowed time. * @param informedDate Date Object */ <span class="fstat-no" title="function not covered" > isAllowedTimes(informedDate: Date)</span>: boolean { <span class="cstat-no" title="statement not covered" > if(!this.$constants.allowedTimes) <span class="cstat-no" title="statement not covered" >return true;</span></span> <span class="cstat-no" title="statement not covered" > try{</span> <span class="cstat-no" title="statement not covered" > const fullTime = informedDate instanceof Date ? informedDate.getHours() + ':' + ('0' + informedDate.getMinutes()).slice(-2) : new Date(informedDate).getHours() + ':' + ('0' + new Date(informedDate).getMinutes()).slice(-2)</span> <span class="cstat-no" title="statement not covered" > return this.$constants.allowedTimes.filter(<span class="fstat-no" title="function not covered" >(validTime)</span> =&gt; <span class="cstat-no" title="statement not covered" >validTime == fullTime)</span>.length &gt; 0;</span> }catch (e) { <span class="cstat-no" title="statement not covered" >return false </span>} } &nbsp; /** * @method boolean Method responsible to check if the user selected a min allowed date. * @param informedDate Date Object */ <span class="fstat-no" title="function not covered" > isAllowedMinDate(informedDate: Date)</span>: boolean { <span class="cstat-no" title="statement not covered" > if (!this.$constants.minDate) <span class="cstat-no" title="statement not covered" >return true;</span></span> <span class="cstat-no" title="statement not covered" > try {</span> <span class="cstat-no" title="statement not covered" > const min = this.$constants.minDate instanceof Date ? this.$constants.minDate : new Date(this.$constants.minDate);</span> <span class="cstat-no" title="statement not covered" > return informedDate &amp;&amp; (informedDate.getTime() &gt;= min.getTime());</span> } catch (e) { <span class="cstat-no" title="statement not covered" >return false; </span>} } &nbsp; /** * @method boolean Method responsible to check if the user selected a max allowed date. * @param informedDate Date Object */ <span class="fstat-no" title="function not covered" > isAllowedMaxDate(informedDate: Date)</span>: boolean { <span class="cstat-no" title="statement not covered" > if (!this.$constants.maxDate) <span class="cstat-no" title="statement not covered" >return true;</span></span> <span class="cstat-no" title="statement not covered" > try {</span> <span class="cstat-no" title="statement not covered" > const max = this.$constants.maxDate instanceof Date ? this.$constants.maxDate : new Date(this.$constants.maxDate);</span> <span class="cstat-no" title="statement not covered" > max.setHours(23);</span> <span class="cstat-no" title="statement not covered" > max.setMinutes(59);</span> <span class="cstat-no" title="statement not covered" > max.setSeconds(59);</span> <span class="cstat-no" title="statement not covered" > return informedDate &amp;&amp; (informedDate.getTime() &lt;= max.getTime());</span> } catch (e) { <span class="cstat-no" title="statement not covered" >return false; </span>} } &nbsp; /** * @method boolean Method responsible to check if the user selected a max allowed date. * @param informedDate Date Object */ <span class="fstat-no" title="function not covered" > isDisabledDate(informedDate: Date)</span>: boolean { <span class="cstat-no" title="statement not covered" > if (!this.$constants.disabledDates) <span class="cstat-no" title="statement not covered" >return false;</span></span> <span class="cstat-no" title="statement not covered" > return this.$constants.disabledDates.filter(<span class="fstat-no" title="function not covered" >(validDate)</span> =&gt; {</span> <span class="cstat-no" title="statement not covered" > const date = validDate instanceof Date ? validDate : new Date(validDate);</span> <span class="cstat-no" title="statement not covered" > return (date.getDate() == informedDate.getDate() &amp;&amp; date.getMonth() == informedDate.getMonth() &amp;&amp; date.getFullYear() == informedDate.getFullYear());</span> }).length &gt; 0; } &nbsp; /** *@method void This method delete the value inside of the input */ <span class="fstat-no" title="function not covered" > resetInput() {</span> <span class="cstat-no" title="statement not covered" > $(this.inputElement).datetimepicker('reset');</span> } &nbsp; /** * @method void Method responsible of setting the value of the model to the input */ <span class="fstat-no" title="function not covered" > setModelInInput() {</span> <span class="cstat-no" title="statement not covered" > if (this.$bindings.cpModel instanceof Date &amp;&amp;</span> this.isAllowedMinDate(this.$bindings.cpModel) &amp;&amp; this.isAllowedMaxDate(this.$bindings.cpModel) &amp;&amp; !this.isDisabledDate(this.$bindings.cpModel) &amp;&amp; this.isAllowedTimes(this.$bindings.cpModel)) { <span class="cstat-no" title="statement not covered" > $(this.inputElement).datetimepicker({value: this.$bindings.cpModel });</span> } else { <span class="cstat-no" title="statement not covered" > this.resetInput();</span> <span class="cstat-no" title="statement not covered" > $(this.inputElement).datetimepicker({mask: this.$constants.mask == undefined ? true : this.$constants.mask})</span> <span class="cstat-no" title="statement not covered" > this.$bindings.cpModel = null;</span> } } &nbsp; }</pre></td></tr> </table></pre> <div class='push'></div><!-- for sticky footer --> </div><!-- /wrapper --> <div class='footer quiet pad2 space-top1 center small'> Code coverage generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon May 28 2018 10:37:42 GMT-0300 (-03) </div> </div> <script src="../../prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="../../sorter.js"></script> </body> </html>