1
1
app . controller ( 'homeCtr' , function ( $scope , $mdSidenav , readJsonData , $state , $mdDialog , $rootScope ) {
2
2
3
+ //$filter('currency')(amount, symbol, fractionSize)
4
+ $state . go ( 'home.dashboard' ) ;
3
5
6
+ $scope . homePage = function ( ) {
7
+ $state . go ( 'home.dashboard' ) ;
8
+ }
9
+ //$state.go('home');
4
10
$scope . toggleLeft = buildToggler ( 'left' ) ;
5
11
function buildToggler ( id ) {
6
12
return function ( ) {
@@ -18,9 +24,10 @@ app.controller('homeCtr', function($scope, $mdSidenav, readJsonData, $state, $md
18
24
}
19
25
}
20
26
}
21
-
22
27
$scope . logout = function ( ) {
23
28
$state . go ( 'login' ) ;
29
+
30
+
24
31
}
25
32
26
33
$scope . fileData = function ( ) {
@@ -65,9 +72,9 @@ function adding(array,id){
65
72
array . push ( id ) ;
66
73
}
67
74
}
68
- $state . go ( 'home.dashboard' ) ;
69
75
70
- console . log ( $scope . quantity ) ;
76
+
77
+ //console.log($scope.quantity);
71
78
72
79
$scope . showFavorite = function ( ) {
73
80
$state . go ( 'home.favourite' ) ;
@@ -78,47 +85,64 @@ $scope.showFavorite = function(){
78
85
79
86
$scope . numbers = [ 1 , 2 , 3 , 4 , 5 ] ;
80
87
//console.log($scope.quantity);
81
- $scope . quantity = 0 ;
88
+
89
+
90
+
91
+ $scope . addingQuantity = function ( s , f ) {
92
+ $scope . quantity = 0 ;
82
93
$scope . presentPrice = 0 ;
83
94
$scope . p = [ ] ;
84
- $scope . addingQuantity = function ( s , f ) {
85
- $scope . presentPrice = 0 ;
86
95
//console.log($rootScope.favouriteElements);
96
+ var a = $scope . p ;
87
97
var index ;
88
98
// if ($scope.p.length != 0) {
89
99
// for (var i = 0; i < $scope.p.length; i++)
90
100
var count = 0 ;
91
101
for ( var i = 1 ; i <= 5 ; i ++ ) {
92
- index = $scope . p . indexOf ( { id :f . id , quantity :i } ) ;
102
+ index = findingIndex ( { id :f . id , quantity :i } ) ;
93
103
console . log ( index ) ;
94
- console . log ( { id :f . id , quantity :i } ) ;
104
+ // console.log({id:f.id,quantity:i});
95
105
if ( index > - 1 ) {
96
- $scope . p . splice ( index , 1 ) ;
97
- $scope . p . push ( { id :f . id , quantity :s } )
106
+ a . splice ( index , 1 ) ;
107
+ a . push ( { id :f . id , quantity :s } )
98
108
count ++ ;
99
109
}
100
110
101
- console . log ( i ) ;
111
+ // console.log(i);
102
112
}
103
113
if ( count == 0 ) {
104
- $scope . p . push ( { id :f . id , quantity :s } ) ;
114
+ a . push ( { id :f . id , quantity :s } ) ;
105
115
}
106
-
116
+ $scope . p = a ;
107
117
//}
108
118
//}
109
- console . log ( $scope . p ) ;
119
+ // console.log($scope.p[0].quantity );
110
120
var cartFile = $rootScope . favouriteElements ;
111
121
//console.log(cartFile);
112
- for ( var i = 0 ; i < cartFile . length ; i ++ ) {
113
- $scope . quantity = ( s * cartFile [ i ] . price ) ;
122
+ $scope . quantity = 0 ;
123
+ for ( var i = 0 ; i < $scope . p . length ; i ++ ) {
124
+ for ( var j = 0 ; j < cartFile . length ; j ++ ) {
125
+ //console.log($scope.p[i].id,'id',cartFile[j].id);
126
+ if ( $scope . p [ i ] . id == cartFile [ j ] . id ) {
127
+ $scope . quantity = $scope . quantity + ( ( $scope . p [ i ] . quantity ) * ( cartFile [ j ] . price ) ) ;
128
+ }
129
+ }
114
130
}
115
-
116
- $scope . presentPrice = $scope . presentPrice + $scope . quantity ;
117
- // console.log(f.price);
118
- // console.log($scope.quantity);
131
+ $scope . presentPrice = $scope . quantity ;
132
+ //console.log(f.price);
133
+ //console.log($scope.quantity);
119
134
//console.log($scope.presentPrice);
120
-
135
+ function findingIndex ( o ) {
136
+ for ( var i = 0 ; i < $scope . p . length ; i ++ ) {
137
+ if ( $scope . p [ i ] . id == o . id && $scope . p [ i ] . quantity == o . quantity ) {
138
+ return i ;
139
+ }
140
+ }
141
+ return - 1 ;
142
+ }
121
143
}
144
+
145
+
122
146
$scope . ad = function ( num ) {
123
147
//console.log(num);
124
148
}
@@ -140,4 +164,4 @@ $scope.ad = function(num){
140
164
141
165
} ) ;
142
166
143
- $state . go ( 'home.favourite' ) ;
167
+ // $state.go('home.favourite');
0 commit comments