@kigi/components 1.8.5 → 1.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kigi/components",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "description": "@kigi/components",
5
5
  "main": "src/components/index.ts",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  <div class="mbg-input-wrapper mbg-input-name-wrapper"
2
2
  ng-if="$ctrl.props">
3
3
  <input type="text"
4
- ng-if="$ctrl.state == 'TO' || $ctrl.state == 'MT'"
4
+ ng-if="$ctrl.state == 'TO' || $ctrl.state == 'MT' || $ctrl.state == 'AL'"
5
5
  mbg-mask-ie
6
6
  ng-model="$ctrl.ngModel"
7
7
  name="{{$ctrl.name}}"
@@ -17,7 +17,7 @@
17
17
  placeholder="{{ $ctrl.props.placeholder }}" />
18
18
 
19
19
  <input type="text"
20
- ng-if="!$ctrl.state || ($ctrl.state != 'TO' && $ctrl.state != 'MT')"
20
+ ng-if="!$ctrl.state || ($ctrl.state != 'TO' && $ctrl.state != 'MT' && $ctrl.state != 'AL')"
21
21
  ng-model="$ctrl.ngModel"
22
22
  name="{{$ctrl.name}}"
23
23
  ng-init="$ctrl.onInit()"
@@ -4,98 +4,100 @@ import * as angular from 'angular'
4
4
  import { UtilUID } from '../../helpers/util-uid'
5
5
  const progressBar = require('progressbar.js')
6
6
  class MbgProgressCircleController {
7
- private unWatchPercentage: any
8
- private unWatchShow: any
9
- private progressCircle: any
10
- private onFinish: Function
11
- private uidComponent
12
- private show = false
13
- private closeOnFinish
14
- private duration: number
15
- private percentage
16
7
 
17
- constructor(public $scope, public $element, public $attrs, public $timeout) {
18
- this.percentage = this.percentage || 100
19
- if (this.closeOnFinish == undefined) {
20
- this.closeOnFinish = true
8
+ private unWatchPercentage: any
9
+ private unWatchShow: any
10
+ private progressCircle: any
11
+ private onFinish: Function
12
+ private uidComponent
13
+ private show = false
14
+ private duration: number
15
+ private percentage
16
+
17
+ constructor(public $scope, public $element, public $attrs, public $timeout) {
18
+ this.percentage = this.percentage || 100
21
19
  }
22
- }
23
20
 
24
- createProgress() {
25
- this.duration = this.duration || 1400
26
- this.uidComponent = UtilUID.generete()
27
- this.unWatchShow = this.$scope.$watch('$ctrl.show', (value) => {
28
- this.$timeout(() => {
29
- value !== undefined && value ? this.addInBody() : this.removeInBody()
30
- })
31
- })
32
- this.$timeout(() => {
33
- this.progressCircle = new progressBar.Circle('#progress', {
34
- color: '#666',
35
- strokeWidth: 4,
36
- trailWidth: 1,
37
- easing: 'easeInOut',
38
- duration: this.duration,
39
- text: {
40
- autoStyleContainer: true,
41
- },
42
- from: { color: '#666', width: 1 },
43
- to: { color: '#000', width: 4 },
44
- step: (state, circle) => {
45
- const value = Math.round(circle.value() * 100)
46
- if (value === 0) {
47
- circle.setText('')
48
- } else {
49
- if (this.duration && value === 100 && this.closeOnFinish) {
50
- this.$timeout(() => (this.show = false), 2000)
51
- }
52
- circle.setText(value + '%')
53
- }
54
- },
55
- })
56
- this.progressCircle.text.style.fontFamily = '"Raleway", Helvetica, sans-serif'
57
- this.progressCircle.text.style.fontSize = '2rem'
58
- this.progressCircle.animate(0.0)
21
+ createProgress() {
22
+ this.duration = this.duration || 1400
23
+ this.uidComponent = UtilUID.generete()
24
+ this.unWatchShow = this.$scope.$watch('$ctrl.show', (value) => {
25
+ this.$timeout(() => {
26
+ value !== undefined && value ? this.addInBody() : this.removeInBody()
27
+ })
28
+ })
29
+ this.$timeout(() => {
30
+ this.progressCircle = new progressBar.Circle('#progress', {
31
+ color: '#666',
32
+ strokeWidth: 4,
33
+ trailWidth: 1,
34
+ easing: 'easeInOut',
35
+ duration: this.duration,
36
+ text: {
37
+ autoStyleContainer: true,
38
+ },
39
+ from: { color: '#666', width: 1 },
40
+ to: { color: '#000', width: 4 },
41
+ step: (state, circle) => {
42
+ const value = Math.round(circle.value() * 100)
43
+ if (value === 0) {
44
+ circle.setText('')
45
+ } else {
46
+ if (this.duration && value === 100) {
47
+ this.$timeout(() => this.show = false, 2000)
48
+ }
49
+ circle.setText(value + '%')
50
+ }
51
+ }
52
+ })
53
+ this.progressCircle.text.style.fontFamily = '"Raleway", Helvetica, sans-serif'
54
+ this.progressCircle.text.style.fontSize = '2rem'
55
+ this.progressCircle.animate(0.0)
59
56
 
60
- this.unWatchPercentage = this.$scope.$watch('$ctrl.percentage', (value) => {
61
- if (this.progressCircle && value !== undefined) {
62
- this.progressCircle.animate(value / 100)
63
- }
64
- })
65
- })
66
- }
57
+ this.unWatchPercentage = this.$scope.$watch('$ctrl.percentage', (value) => {
58
+ if (this.progressCircle && value !== undefined) {
59
+ this.progressCircle.animate(value / 100)
60
+ }
61
+ })
62
+ })
63
+ }
67
64
 
68
- addInBody() {
69
- const body = angular.element(document).find('body')
70
- const list = this.$element.find('div.mbg-progress-circle-wrapper')
71
- list.attr('uid', this.uidComponent)
72
- body.append(list)
73
- }
65
+ addInBody() {
66
+ const body = angular.element(document).find('body')
67
+ const list = this.$element.find('div.mbg-progress-circle-wrapper')
68
+ list.attr('uid', this.uidComponent)
69
+ body.append(list)
70
+ }
74
71
 
75
- removeInBody() {
76
- const list = angular.element(`[uid="${this.uidComponent}"]`)
77
- this.$element.find('.mbg-progress-circle-wrapper').append(list)
78
- }
72
+ removeInBody() {
73
+ const list = angular.element(`[uid="${this.uidComponent}"]`)
74
+ this.$element.find('.mbg-progress-circle-wrapper').append(list)
75
+ }
79
76
 
80
- $onDestroy() {
81
- if (this.unWatchPercentage) {
82
- this.unWatchPercentage()
77
+ $onDestroy() {
78
+ if (this.unWatchPercentage) {
79
+ this.unWatchPercentage()
80
+ }
83
81
  }
84
- }
82
+
85
83
  }
86
84
 
87
- MbgProgressCircleController.$inject = ['$scope', '$element', '$attrs', '$timeout']
85
+ MbgProgressCircleController.$inject = [
86
+ '$scope',
87
+ '$element',
88
+ '$attrs',
89
+ '$timeout'
90
+ ]
88
91
 
89
92
  const mbgProgressCircle = {
90
- bindings: {
91
- percentage: '=?',
92
- titleProgress: '@?',
93
- show: '=?',
94
- duration: '=?',
95
- closeOnFinish: '=?',
96
- },
97
- template,
98
- controller: MbgProgressCircleController,
93
+ bindings: {
94
+ percentage: '=?',
95
+ titleProgress: '@?',
96
+ show: '=?',
97
+ duration: '=?'
98
+ },
99
+ template,
100
+ controller: MbgProgressCircleController,
99
101
  }
100
102
 
101
103
  export { mbgProgressCircle }
@@ -8,6 +8,7 @@ export class NgMaskIe {
8
8
  private $timeout
9
9
  private $parse
10
10
  private uid: string = UtilUID.generete()
11
+ private ordZero = '0'.charCodeAt(0)
11
12
 
12
13
  constructor() {
13
14
  this.restrict = 'A'
@@ -25,12 +26,12 @@ export class NgMaskIe {
25
26
  scope.$parent && scope.$parent.$parent && scope.$parent.$parent.$ctrl
26
27
  ? scope.$parent.$parent.$ctrl.state
27
28
  : null
28
- const valid = this.validade(data, state)
29
+ const valid = this.validate(data, state)
29
30
  const form = elm.closest('form')
30
31
  const formName = form.attr('name')
31
32
  const formScope = form.scope()
32
33
  if (formName && formScope) {
33
- this.setIeValidade(elm, valid)
34
+ this.setIeValidate(elm, valid)
34
35
  if (!valid) {
35
36
  elm.addClass('mbg-error')
36
37
  } else {
@@ -65,43 +66,74 @@ export class NgMaskIe {
65
66
  ngModelController.$formatters.push(formatterView)
66
67
 
67
68
  scope.$on('$destroy', () => {
68
- this.setIeValidade(elm, true)
69
+ this.setIeValidate(elm, true)
69
70
  })
70
71
  }
71
72
 
72
- validade(ngModel, state) {
73
+ validate(ngModel, state) {
73
74
  switch (state) {
74
75
  case 'TO':
75
- if (ngModel && (ngModel.length === 11 || ngModel.length === 9)) {
76
- const digit = ngModel[ngModel.length - 1]
77
- let total = 0
78
- let indexCalc = 0
79
- for (let index = 9; index >= 2; index--) {
80
- total += ngModel[indexCalc] * index
81
- if (ngModel.length === 11 && indexCalc === 1) {
82
- indexCalc = indexCalc + 3
83
- } else {
84
- indexCalc++
85
- }
86
- }
87
- const result = total - Math.floor(total / 11) * 11
88
- if (result < 2) {
89
- return Number(digit) === 0
90
- } else {
91
- return Number(digit) === 11 - result
92
- }
76
+ return this.validateTO(ngModel)
77
+ case 'MT':
78
+ return this.validateMT(ngModel)
79
+ case 'AL':
80
+ return this.validateAL(ngModel)
81
+ }
82
+ }
83
+
84
+ charToInt(ch) {
85
+ return ch.charCodeAt(0) - this.ordZero
86
+ }
87
+
88
+ intToChar(int) {
89
+ return String.fromCharCode(int + this.ordZero)
90
+ }
91
+
92
+ validateAL(ie) {
93
+ let dig = -1
94
+ if (ie.length != 9) return false
95
+ var b = 9,
96
+ soma = 0
97
+ for (var i = 0; i <= 7; i++) {
98
+ soma += this.charToInt(ie.charAt(i)) * b
99
+ --b
100
+ }
101
+ soma *= 10
102
+ dig = soma - Math.floor(soma / 11) * 11
103
+ if (dig == 10) {
104
+ dig = 0
105
+ }
106
+ return this.intToChar(dig) == ie.charAt(8)
107
+ }
108
+
109
+ validateTO(ngModel) {
110
+ if (ngModel && (ngModel.length === 11 || ngModel.length === 9)) {
111
+ const digit = ngModel[ngModel.length - 1]
112
+ let total = 0
113
+ let indexCalc = 0
114
+ for (let index = 9; index >= 2; index--) {
115
+ total += ngModel[indexCalc] * index
116
+ if (ngModel.length === 11 && indexCalc === 1) {
117
+ indexCalc = indexCalc + 3
93
118
  } else {
94
- return false
119
+ indexCalc++
95
120
  }
96
- case 'MT':
97
- return this.validadeMT(ngModel)
121
+ }
122
+ const result = total - Math.floor(total / 11) * 11
123
+ if (result < 2) {
124
+ return Number(digit) === 0
125
+ } else {
126
+ return Number(digit) === 11 - result
127
+ }
128
+ } else {
129
+ return false
98
130
  }
99
131
  }
100
132
 
101
- validadeMT(model, plusZero = '') {
133
+ validateMT(model, plusZero = '') {
102
134
  const lengthZero = plusZero.length
103
135
  model = `${plusZero}${model}`
104
- if (model.length != 11 && lengthZero < 2) return this.validadeMT(model, `0`)
136
+ if (model.length != 11 && lengthZero < 2) return this.validateMT(model, `0`)
105
137
  var nro = new Array(11)
106
138
  for (var i = 0; i <= 10; i++) nro[i] = parseInt(model[i])
107
139
  let b = 3
@@ -121,7 +153,7 @@ export class NgMaskIe {
121
153
  return dig == nro[10]
122
154
  }
123
155
 
124
- setIeValidade(elm, valid) {
156
+ setIeValidate(elm, valid) {
125
157
  const form = elm.closest('form')
126
158
  const formName = form.attr('name')
127
159
  const formScope = form.scope()