|
3 | 3 | (function (angular, buildfire) { |
4 | 4 | angular |
5 | 5 | .module('couponPluginContent') |
6 | | - .controller('ContentHomeCtrl', ['$scope', '$timeout', 'TAG_NAMES', 'SORT', 'SORT_FILTER', 'STATUS_CODE', 'DataStore', 'LAYOUTS', 'Buildfire', 'Modals', 'RankOfLastFilter', 'RankOfLastItem', '$csv', 'Utils', '$rootScope', 'PluginEvents', 'StateSeeder', '$filter', |
7 | | - function ($scope, $timeout, TAG_NAMES, SORT, SORT_FILTER, STATUS_CODE, DataStore, LAYOUTS, Buildfire, Modals, RankOfLastFilter, RankOfLastItem, $csv, Utils, $rootScope, PluginEvents, StateSeeder, $filter) { |
| 6 | + .controller('ContentHomeCtrl', ['$scope', '$timeout', 'TAG_NAMES', 'SORT', 'SORT_FILTER', 'STATUS_CODE', 'DataStore', 'LAYOUTS', 'Buildfire', 'Modals', 'RankOfLastFilter', 'RankOfLastItem', '$csv', 'Utils', '$rootScope', 'PluginEvents', 'StateSeeder', 'defaultInfo', |
| 7 | + function ($scope, $timeout, TAG_NAMES, SORT, SORT_FILTER, STATUS_CODE, DataStore, LAYOUTS, Buildfire, Modals, RankOfLastFilter, RankOfLastItem, $csv, Utils, $rootScope, PluginEvents, StateSeeder, defaultInfo ) { |
8 | 8 | var ContentHome = this; |
9 | 9 | let stateSeeder; |
10 | 10 | $rootScope.$watch('showEmptyState', function(newValue, oldValue) { |
|
15 | 15 | ContentHome.searchValue = ""; |
16 | 16 | ContentHome.filter = null; |
17 | 17 | ContentHome.isBusy = true; |
18 | | - var _data = { |
19 | | - "content": { |
20 | | - "carouselImages": [], |
21 | | - "description": '', |
22 | | - "rankOfLastFilter": '', |
23 | | - "rankOfLastItem": '', |
24 | | - "sortItemBy": SORT.MANUALLY, |
25 | | - "sortFilterBy": SORT_FILTER.MANUALLY |
26 | | - }, |
27 | | - "design": { |
28 | | - "itemListLayout": LAYOUTS.itemListLayout[0].name |
29 | | - }, |
30 | | - "settings": { |
31 | | - "defaultView": "list", |
32 | | - "distanceIn": "mi", |
33 | | - "mapView": "show", |
34 | | - "filterPage": "show" |
35 | | - } |
36 | | - }; |
37 | | - |
38 | | - |
| 18 | + var _data = defaultInfo; |
| 19 | + |
39 | 20 | // Show the top plugin info part when on home view |
40 | 21 | Buildfire.appearance.setHeaderVisibility(true); |
41 | 22 |
|
|
116 | 97 | ContentHome.searchOptionsForItems = { |
117 | 98 | filter: { "$json.title": { "$regex": '/*' } }, |
118 | 99 | skip: SORT._skip, |
119 | | - limit: SORT._limit + 1 // the plus one is to check if there are any more |
| 100 | + limit: SORT._limit + 1, // the plus one is to check if there are any more |
| 101 | + sort: { "rank": 1 } |
120 | 102 | }; |
121 | 103 | /* |
122 | 104 | * create an artificial delay so api isnt called on every character entered |
|
204 | 186 | var isRankChanged = false; |
205 | 187 | if (next) { |
206 | 188 | if (prev) { |
207 | | - draggedItem.data.rank = ((prev.data.rank || 0) + (next.data.rank || 0)) / 2; |
| 189 | + draggedItem.data.rank = Number((prev.data.rank || 0) + (next.data.rank || 0)) / 2; |
208 | 190 | isRankChanged = true; |
209 | 191 | } else { |
210 | | - draggedItem.data.rank = (next.data.rank || 0) / 2; |
| 192 | + draggedItem.data.rank = Number(next.data.rank || 0) / 2; |
211 | 193 | isRankChanged = true; |
212 | 194 | } |
213 | 195 | } else { |
214 | 196 | if (prev) { |
215 | | - draggedItem.data.rank = (((prev.data.rank || 0) * 2) + 10) / 2; |
216 | | - maxRank = draggedItem.data.rank; |
| 197 | + draggedItem.data.rank = Number(((prev.data.rank || 0) * 2) + 10) / 2; |
| 198 | + maxRank = Number(draggedItem.data.rank); |
217 | 199 | isRankChanged = true; |
218 | 200 | } |
219 | 201 | } |
|
1361 | 1343 | var success = function (result) { |
1362 | 1344 | console.info('Init success result:', result); |
1363 | 1345 | ContentHome.data = result.data; |
1364 | | - if (!ContentHome.data.content) { |
| 1346 | + if (!Object.keys(ContentHome.data).length) { |
1365 | 1347 | ContentHome.data = angular.copy(_data); |
1366 | 1348 | } else { |
1367 | 1349 | if (!ContentHome.data.content) |
1368 | 1350 | ContentHome.data.content = {}; |
1369 | 1351 | if (!ContentHome.data.settings) |
1370 | | - ContentHome.data.settings = {}; |
| 1352 | + ContentHome.data.settings = defaultInfo.settings; |
1371 | 1353 | if (!ContentHome.data.content.carouselImages) |
1372 | 1354 | editor.loadItems([]); |
1373 | 1355 | else |
1374 | 1356 | editor.loadItems(ContentHome.data.content.carouselImages); |
1375 | 1357 | if (!ContentHome.data.content.sortFilterBy) |
1376 | 1358 | ContentHome.data.content.sortFilterBy = ContentHome.sortFilterOptions[0]; |
1377 | 1359 | if (!ContentHome.data.content.sortItemBy) |
1378 | | - ContentHome.data.content.sortItemBy = ContentHome.sortItemOptions[0]; |
| 1360 | + ContentHome.data.content.sortItemBy = ContentHome.sortItemOptions[4]; |
1379 | 1361 | ContentHome.filters = []; |
1380 | 1362 | ContentHome.searchOptions.skip = 0; |
1381 | 1363 | ContentHome.busyFilter = false; |
|
0 commit comments