|
| 1 | +import cloneDeep from 'lodash/cloneDeep'; |
1 | 2 | import filter from 'lodash/filter'; |
2 | 3 | import find from 'lodash/find'; |
3 | 4 | import get from 'lodash/get'; |
4 | 5 | import map from 'lodash/map'; |
5 | 6 | import set from 'lodash/set'; |
6 | 7 |
|
| 8 | +import { |
| 9 | + ALPHA_NUMERIC_REGEXP, |
| 10 | + COMPLEX_NUMERIC_REGEXP, |
| 11 | +} from './telecom-telephony-line-phone-programmableKeys.constants'; |
| 12 | + |
7 | 13 | export default class TelecomTelephonyLinePhoneProgammableKeysCtrl { |
8 | 14 | /* @ngInject */ |
9 | 15 | constructor($stateParams, $translate, $uibModal, TelephonyMediator, tucTelephonyBulk, TucToast) { |
@@ -91,13 +97,31 @@ export default class TelecomTelephonyLinePhoneProgammableKeysCtrl { |
91 | 97 | return this.line.getPhone().then(() => { |
92 | 98 | if (this.line.hasPhone) { |
93 | 99 | return this.line.phone.initDeffered().then(() => { |
94 | | - this.functionKeys.raw = angular.copy(this.line.phone.functionKeys); |
| 100 | + this.functionKeys.raw = cloneDeep(this.line.phone.functionKeys); |
| 101 | + this.functionKeys.raw.sort(this.constructor.sortFunctionKeys); |
95 | 102 | }); |
96 | 103 | } |
97 | 104 | return null; |
98 | 105 | }); |
99 | 106 | } |
100 | 107 |
|
| 108 | + static sortFunctionKeys(functionKeyA, functionKeyB) { |
| 109 | + const [alphaA, numericA] = functionKeyA.label.match(ALPHA_NUMERIC_REGEXP); |
| 110 | + const [alphaB, numericB] = functionKeyB.label.match(ALPHA_NUMERIC_REGEXP); |
| 111 | + if (alphaA === alphaB) { |
| 112 | + const [numericA1, numericA2] = numericA.match(COMPLEX_NUMERIC_REGEXP); |
| 113 | + const [numericB1, numericB2] = numericB.match(COMPLEX_NUMERIC_REGEXP); |
| 114 | + |
| 115 | + if (numericA1 === numericB1) { |
| 116 | + return parseInt(numericA2, 10) > parseInt(numericB2, 10) ? 1 : -1; |
| 117 | + } |
| 118 | + |
| 119 | + return parseInt(numericA, 10) > parseInt(numericB, 10) ? 1 : -1; |
| 120 | + } |
| 121 | + |
| 122 | + return alphaA > alphaB ? 1 : -1; |
| 123 | + } |
| 124 | + |
101 | 125 | /* =========================== |
102 | 126 | = BULK = |
103 | 127 | ============================ */ |
|
0 commit comments