| 13542 |
anikendra |
1 |
angular.module('starter.controllers', [])
|
|
|
2 |
|
| 13557 |
anikendra |
3 |
.controller('DashCtrl', function($scope, $stateParams, Categories, CategoryProducts, localStorageService, apihost,$location) {
|
|
|
4 |
$scope.me = $location.search().user_id;
|
|
|
5 |
if($scope.me) {
|
| 13563 |
anikendra |
6 |
localStorageService.set('me',$scope.me);
|
| 13557 |
anikendra |
7 |
}else{
|
| 13563 |
anikendra |
8 |
$scope.me = localStorageService.get('me');
|
| 13557 |
anikendra |
9 |
}
|
| 13551 |
anikendra |
10 |
$scope.apihost = apihost;
|
|
|
11 |
$scope.curpage = 1;
|
|
|
12 |
$scope.maxpages = 10;
|
|
|
13 |
$scope.products = [];
|
| 13542 |
anikendra |
14 |
$scope.categories = Categories.all({'me':$scope.me});
|
| 13551 |
anikendra |
15 |
$scope.getCategoryName = function(id,cats){
|
|
|
16 |
for(var i in cats){
|
|
|
17 |
if(cats[i].Category.id == id){
|
|
|
18 |
return cats[i].Category.name;
|
|
|
19 |
}
|
|
|
20 |
}
|
|
|
21 |
}
|
|
|
22 |
/*
|
|
|
23 |
$scope.loadmore = function () {
|
|
|
24 |
console.log('Fetch category products page '+$scope.curpage);
|
|
|
25 |
CategoryProducts.all({'me':$scope.me, page: $scope.curpage++},
|
|
|
26 |
function( result ) {
|
|
|
27 |
// console.log(result);
|
|
|
28 |
// $scope.category = result.categories;
|
|
|
29 |
$scope.maxpages = result.maxresults;
|
|
|
30 |
$scope.$broadcast('scroll.infiniteScrollComplete');
|
|
|
31 |
for(var i in result.products){
|
|
|
32 |
$scope.products[i] = result.products;
|
|
|
33 |
// var catproducts = result.products[i];
|
|
|
34 |
// console.log(catproducts.products);
|
|
|
35 |
// $scope.products[i] = catproducts.products;
|
|
|
36 |
}
|
|
|
37 |
// $scope.chunkedData = $scope.chunk($scope.products, 2);
|
|
|
38 |
},
|
|
|
39 |
function( error ) {
|
|
|
40 |
console.log( "Something went wrong!" );
|
|
|
41 |
}
|
|
|
42 |
);
|
|
|
43 |
},
|
|
|
44 |
*/
|
|
|
45 |
$scope.moreDataCanBeLoaded = function() {
|
|
|
46 |
if($scope.curpage <= $scope.maxpages)
|
|
|
47 |
return true;
|
|
|
48 |
return false;
|
|
|
49 |
},
|
|
|
50 |
$scope.$on('$stateChangeSuccess', function() {
|
|
|
51 |
// $scope.loadmore();
|
|
|
52 |
});
|
|
|
53 |
// var catproducts = CategoryProducts.all({'me':$scope.me, page: $scope.curpage++});
|
|
|
54 |
// $scope.products = catproducts.products;
|
|
|
55 |
CategoryProducts.all({'me':$scope.me, page: $scope.curpage++},
|
|
|
56 |
function( result ) {
|
|
|
57 |
console.log(result);
|
|
|
58 |
$scope.products = result.products;
|
|
|
59 |
$scope.maxpages = result.maxresults;
|
|
|
60 |
$scope.$broadcast('scroll.infiniteScrollComplete');
|
|
|
61 |
/*for(var i in result.products){
|
|
|
62 |
console.log(result.products[i].products);
|
|
|
63 |
$scope.products[i] = result.products[i];
|
|
|
64 |
console.log($scope.products);
|
|
|
65 |
}*/
|
|
|
66 |
},
|
|
|
67 |
function( error ) {
|
|
|
68 |
console.log( "Something went wrong!" );
|
|
|
69 |
}
|
|
|
70 |
);
|
| 13542 |
anikendra |
71 |
$scope.hasProducts = function(categoryId,products) {
|
|
|
72 |
for(index in products) {
|
|
|
73 |
// console.log(products[index].Product.category_id);
|
|
|
74 |
// console.log(objects[index].Product.category_id)
|
|
|
75 |
if(products[index].Product.category_id == categoryId) // filter by name only
|
|
|
76 |
return true;
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
})
|
|
|
80 |
|
| 13563 |
anikendra |
81 |
.controller('ChatsCtrl', function($scope, $rootScope, Products, localStorageService, apihost, $location, Myactions) {
|
| 13557 |
anikendra |
82 |
$scope.me = $location.search().user_id;
|
|
|
83 |
if($scope.me) {
|
|
|
84 |
localStorageService.set('me',$scope.me);
|
|
|
85 |
}else{
|
|
|
86 |
$scope.me = localStorageService.get('me');
|
|
|
87 |
}
|
| 13551 |
anikendra |
88 |
$scope.apihost = apihost;
|
|
|
89 |
$scope.curpage = 1;
|
|
|
90 |
$scope.maxpages = 10;
|
|
|
91 |
$scope.products = [];
|
| 13563 |
anikendra |
92 |
$rootScope.liked = [];
|
|
|
93 |
$rootScope.disliked = [];
|
|
|
94 |
|
|
|
95 |
Myactions.all({user_id:$scope.me},
|
|
|
96 |
function( result ) {
|
|
|
97 |
var userActions = result;
|
|
|
98 |
if(userActions){
|
|
|
99 |
for(var i in userActions){
|
|
|
100 |
for(var j in userActions[i]) {
|
|
|
101 |
if(userActions[i][j].UserAction){
|
|
|
102 |
if(userActions[i][j].UserAction.action == 'like'){
|
|
|
103 |
$rootScope.liked[userActions[i][j].UserAction.store_product_id] = 1;
|
|
|
104 |
}else{
|
|
|
105 |
$rootScope.disliked[userActions[i][j].UserAction.store_product_id] = 1;
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
},
|
|
|
112 |
function( error ) {
|
|
|
113 |
console.log( "Something went wrong!" );
|
|
|
114 |
}
|
|
|
115 |
),
|
|
|
116 |
|
| 13551 |
anikendra |
117 |
$scope.loadmore = function () {
|
|
|
118 |
console.log('Fetch deal products page '+$scope.curpage);
|
|
|
119 |
Products.all({'me':$scope.me, page: $scope.curpage++},
|
|
|
120 |
function( result ) {
|
|
|
121 |
$scope.category = result.category;
|
|
|
122 |
$scope.maxpages = result.maxresults;
|
|
|
123 |
$scope.$broadcast('scroll.infiniteScrollComplete');
|
|
|
124 |
for(var i in result.products){
|
|
|
125 |
$scope.products.push(result.products[i]);
|
|
|
126 |
}
|
|
|
127 |
$scope.chunkedData = $scope.chunk($scope.products, 2);
|
|
|
128 |
},
|
|
|
129 |
function( error ) {
|
|
|
130 |
console.log( "Something went wrong!" );
|
|
|
131 |
}
|
|
|
132 |
);
|
|
|
133 |
},
|
|
|
134 |
$scope.moreDataCanBeLoaded = function() {
|
|
|
135 |
if($scope.curpage <= $scope.maxpages)
|
|
|
136 |
return true;
|
|
|
137 |
return false;
|
|
|
138 |
},
|
|
|
139 |
$scope.$on('$stateChangeSuccess', function() {
|
|
|
140 |
$scope.loadmore();
|
|
|
141 |
});
|
| 13542 |
anikendra |
142 |
})
|
|
|
143 |
|
| 13551 |
anikendra |
144 |
.controller('CategoryCtrl', function($scope, $stateParams, Chats) {
|
| 13542 |
anikendra |
145 |
$scope.chat = Chats.get($stateParams.chatId);
|
|
|
146 |
})
|
|
|
147 |
|
|
|
148 |
.controller('FriendsCtrl', function($scope, Friends) {
|
|
|
149 |
$scope.friends = Friends.all();
|
|
|
150 |
})
|
|
|
151 |
|
|
|
152 |
.controller('FriendDetailCtrl', function($scope, $stateParams, Friends) {
|
|
|
153 |
$scope.friend = Friends.get($stateParams.friendId);
|
|
|
154 |
})
|
|
|
155 |
|
|
|
156 |
.controller('AccountCtrl', function($scope) {
|
|
|
157 |
$scope.settings = {
|
|
|
158 |
enableFriends: true
|
|
|
159 |
};
|
|
|
160 |
})
|
|
|
161 |
.controller('LoginCtrl', function($scope,$location,localStorageService) {
|
|
|
162 |
$scope.me = $location.search().user_id;
|
|
|
163 |
if($scope.me){
|
|
|
164 |
console.log($scope.me);
|
|
|
165 |
localStorageService.set('me',$scope.me);
|
|
|
166 |
$location.path("/tab/chats");
|
|
|
167 |
}
|
|
|
168 |
});
|