|
59 | 59 | value: id |
60 | 60 | }; |
61 | 61 | }); |
62 | | - if (countlyGlobal.member.appSortList) { |
63 | | - appList = this.sortBy(appList, countlyGlobal.member.appSortList); |
| 62 | + var sortList = (countlyGlobal.member && countlyGlobal.member.appSortList) || []; |
| 63 | + if (sortList.length) { |
| 64 | + appList = this.sortBy(appList, sortList); |
64 | 65 | } |
65 | 66 | else { |
66 | | - appList.sort(function(a, b) { |
67 | | - return a.label > b.label && 1 || -1; |
68 | | - }); |
| 67 | + appList.sort(this.sortAppOptionsAlphabetically); |
69 | 68 | } |
70 | 69 | var app_id = this.$route.params.app_id || countlyCommon.ACTIVE_APP_ID; |
71 | 70 | return { |
|
340 | 339 | } |
341 | 340 | } |
342 | 341 | }, |
| 342 | + getAppListItemId: function(option) { |
| 343 | + if (!option) { |
| 344 | + return ""; |
| 345 | + } |
| 346 | + |
| 347 | + return (option._id || option.value || option.id || option.app_id || "") + ""; |
| 348 | + }, |
| 349 | + sortAppOptionsAlphabetically: function(optionA, optionB) { |
| 350 | + var labelA = (optionA.label || "").toLowerCase(); |
| 351 | + var labelB = (optionB.label || "").toLowerCase(); |
| 352 | + |
| 353 | + if (labelA < labelB) { |
| 354 | + return -1; |
| 355 | + } |
| 356 | + |
| 357 | + if (labelA > labelB) { |
| 358 | + return 1; |
| 359 | + } |
| 360 | + |
| 361 | + var valueA = (optionA.value || "").toLowerCase(); |
| 362 | + var valueB = (optionB.value || "").toLowerCase(); |
| 363 | + |
| 364 | + if (valueA < valueB) { |
| 365 | + return -1; |
| 366 | + } |
| 367 | + |
| 368 | + if (valueA > valueB) { |
| 369 | + return 1; |
| 370 | + } |
| 371 | + |
| 372 | + return 0; |
| 373 | + }, |
| 374 | + applyAppListOrdering: function() { |
| 375 | + if (!Array.isArray(this.appList)) { |
| 376 | + return; |
| 377 | + } |
| 378 | + |
| 379 | + var sortList = (countlyGlobal.member && countlyGlobal.member.appSortList) || []; |
| 380 | + var currentList = this.appList.slice(); |
| 381 | + var orderedList; |
| 382 | + |
| 383 | + if (sortList.length) { |
| 384 | + orderedList = this.sortBy(currentList, sortList); |
| 385 | + } |
| 386 | + else { |
| 387 | + orderedList = currentList.sort(this.sortAppOptionsAlphabetically); |
| 388 | + } |
| 389 | + |
| 390 | + this.appList = orderedList; |
| 391 | + }, |
343 | 392 | sortBy: function(arrayToSort, sortList) { |
344 | 393 | if (!sortList.length) { |
345 | 394 | return arrayToSort; |
|
349 | 398 | retArr = []; |
350 | 399 | var i; |
351 | 400 | for (i = 0; i < arrayToSort.length; i++) { |
352 | | - var objId = arrayToSort[i]._id + ""; |
353 | | - if (sortList.indexOf(objId) !== -1) { |
354 | | - tmpArr[sortList.indexOf(objId)] = arrayToSort[i]; |
| 401 | + var objId = this.getAppListItemId(arrayToSort[i]); |
| 402 | + var desiredIndex = sortList.indexOf(objId); |
| 403 | + if (desiredIndex !== -1) { |
| 404 | + tmpArr[desiredIndex] = arrayToSort[i]; |
355 | 405 | } |
356 | 406 | } |
357 | 407 |
|
|
392 | 442 | value: data._id + "", |
393 | 443 | label: data.name |
394 | 444 | }); |
| 445 | + self.applyAppListOrdering(); |
395 | 446 | self.$store.dispatch("countlyCommon/addToAllApps", data); |
396 | 447 | self.$store.dispatch("countlyCommon/updateActiveApp", data._id + ""); |
397 | 448 | countlyCommon.setActiveApp(data._id); |
|
459 | 510 | break; |
460 | 511 | } |
461 | 512 | } |
| 513 | + self.applyAppListOrdering(); |
462 | 514 | self.discardForm(); |
463 | 515 | CountlyHelpers.notify({ |
464 | 516 | title: jQuery.i18n.map["configs.changed"], |
|
0 commit comments