Skip to content

Commit 7fbb747

Browse files
JeremyDecJoffrey LEVEUGLE
authored andcommitted
fix(telephony.phone): fix order of function keys (#1350)
1 parent 3694896 commit 7fbb747

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const ALPHA_NUMERIC_REGEXP = new RegExp(/[a-z]+|[\d.-_]+/ig);
2+
3+
export const COMPLEX_NUMERIC_REGEXP = new RegExp(/\d+/g);
4+
5+
export default {
6+
ALPHA_NUMERIC_REGEXP,
7+
COMPLEX_NUMERIC_REGEXP,
8+
};

packages/manager/apps/telecom/src/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.controller.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import cloneDeep from 'lodash/cloneDeep';
12
import filter from 'lodash/filter';
23
import find from 'lodash/find';
34
import get from 'lodash/get';
45
import map from 'lodash/map';
56
import set from 'lodash/set';
67

8+
import {
9+
ALPHA_NUMERIC_REGEXP,
10+
COMPLEX_NUMERIC_REGEXP,
11+
} from './telecom-telephony-line-phone-programmableKeys.constants';
12+
713
export default class TelecomTelephonyLinePhoneProgammableKeysCtrl {
814
/* @ngInject */
915
constructor($stateParams, $translate, $uibModal, TelephonyMediator, tucTelephonyBulk, TucToast) {
@@ -91,13 +97,31 @@ export default class TelecomTelephonyLinePhoneProgammableKeysCtrl {
9197
return this.line.getPhone().then(() => {
9298
if (this.line.hasPhone) {
9399
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);
95102
});
96103
}
97104
return null;
98105
});
99106
}
100107

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+
101125
/* ===========================
102126
= BULK =
103127
============================ */

packages/manager/apps/telecom/src/app/telecom/telephony/line/phone/programmableKeys/telecom-telephony-line-phone-programmableKeys.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</tuc-telephony-bulk-action>
3737

3838
<oui-datagrid data-rows="ProgrammableKeysCtrl.functionKeys.raw">
39-
<oui-column data-title="'telephony_line_phone_programmableKeys_keys_title' | translate" data-property="label" data-sortable="asc">
39+
<oui-column data-title="'telephony_line_phone_programmableKeys_keys_title' | translate" data-property="label">
4040
<span data-ng-bind="$row.label || '-'"></span>
4141
</oui-column>
4242
<oui-column data-title="'telephony_line_phone_programmableKeys_function_title' | translate">

0 commit comments

Comments
 (0)