@@ -21,6 +21,43 @@ angular.module('crunchinatorApp.controllers')
2121 $scope . filteredCompaniesList = [ ] ;
2222 $scope . filteredCategoriesList = [ ] ;
2323 $scope . filteredInvestorsList = [ ] ;
24+ $scope . lookingForList = [ ] ;
25+
26+ $scope . select_investor = function ( ) {
27+ if ( $scope . selectedInvestors . indexOf ( $scope . selected_investor ) === - 1 ) {
28+ $scope . selectedInvestors . push ( $scope . selected_investor ) ;
29+ inv_ids = _ . pluck ( $scope . selectedInvestors , 'id' ) ;
30+ $scope . filteredCompanies ( ) ;
31+
32+ $scope . selected_investor = '' ;
33+ $scope . clearLookingFor ( ) ;
34+ }
35+ } ;
36+
37+ $scope . select_company = function ( ) {
38+ if ( $scope . selectedCompanies . indexOf ( $scope . selected_company ) === - 1 ) {
39+ $scope . selectedCompanies . push ( $scope . selected_company ) ;
40+ company_ids = _ . pluck ( $scope . selectedCompanies , 'id' ) ;
41+ $scope . filteredInvestors ( ) ;
42+
43+ $scope . selected_company = '' ;
44+ $scope . clearLookingFor ( ) ;
45+ }
46+ } ;
47+
48+ $scope . removeInvestor = function ( investor ) {
49+ $scope . selectedInvestors . splice ( $scope . selectedInvestors . indexOf ( investor ) , 1 ) ;
50+ inv_ids = _ . pluck ( $scope . selectedInvestors , 'id' ) ;
51+ $scope . filteredCompanies ( ) ;
52+ $scope . clearLookingFor ( ) ;
53+ } ;
54+
55+ $scope . removeCompany = function ( company ) {
56+ $scope . selectedCompanies . splice ( $scope . selectedCompanies . indexOf ( company ) , 1 ) ;
57+ company_ids = _ . pluck ( $scope . selectedCompanies , 'id' ) ;
58+ $scope . filteredInvestors ( ) ;
59+ $scope . clearLookingFor ( ) ;
60+ } ;
2461
2562 $scope . geoJsonData = _ . memoize ( function ( filteredCompanies ) {
2663 var geojson = {
@@ -46,7 +83,7 @@ angular.module('crunchinatorApp.controllers')
4683 return _ . pluck ( filteredCompanies , 'id' ) . join ( '' ) ;
4784 } ) ;
4885
49- $scope . totalRaisedGraphData = _ . memoize ( function ( filteredCompanies ) {
86+ /* $scope.totalRaisedGraphData = _.memoize(function(filteredCompanies) {
5087 if (!filteredCompanies || !filteredCompanies.length) { return; }
5188 var total_raised_data = [];
5289 for(var i = 1; i <= 10; i++){
@@ -63,7 +100,7 @@ angular.module('crunchinatorApp.controllers')
63100 return total_raised_data;
64101 }, function(filteredCompanies) {
65102 return _.pluck(filteredCompanies, 'id').join('');
66- } ) ;
103+ });*/
67104
68105 $scope . resetSelection = function ( ) {
69106 $scope . selectedCompanies = [ ] ;
@@ -96,6 +133,9 @@ angular.module('crunchinatorApp.controllers')
96133 $scope . filteredCompanies ( ) ;
97134 $scope . filteredCategories ( ) ;
98135 $scope . filteredInvestors ( ) ;
136+ $scope . clearLookingFor ( ) ;
137+
138+ $scope . updateLookingFor ( ) ;
99139
100140 $scope . selectedCompanies = _ . intersection ( $scope . selectedCompanies , $scope . filteredCompaniesList ) ;
101141 $scope . selectedCategories = _ . intersection ( $scope . selectedCategories , $scope . filteredCategoriesList ) ;
@@ -104,60 +144,84 @@ angular.module('crunchinatorApp.controllers')
104144
105145 var crossCompanies ;
106146 var companiesDimension ;
107- var companiesById ;
147+ var companiesByName ;
108148 $scope . filteredCompanies = function ( ) {
109149 if ( crossCompanies ) {
110150 companiesDimension . filterAll ( ) ; //clear filter
111- companiesDimension . filter ( function ( c ) { return ( cat_ids . length === 0 || cat_ids . indexOf ( c . category_id ) > - 1 ) && ( inv_ids . length === 0 || _ . intersection ( c . investor_ids , inv_ids ) . length > 0 ) ; } ) ;
151+ companiesDimension . filter ( function ( c ) { return ( cat_ids . length === 0 || cat_ids . indexOf ( c . category_id ) > - 1 ) && ( inv_ids . length === 0 || _ . intersection ( c . investor_ids [ 0 ] , inv_ids ) . length > 0 ) ; } ) ;
112152
113- $scope . filteredCompaniesList = companiesById . bottom ( 100 ) ;
153+ $scope . filteredCompaniesList = companiesByName . bottom ( Infinity ) ;
114154 }
115155 } ;
116156
117157 var crossInvestors ;
118158 var investorsDimension ;
119- var investorsById ;
159+ var investorsByName ;
120160 $scope . filteredInvestors = function ( ) {
121161 if ( crossInvestors ) {
122162 investorsDimension . filterAll ( ) ;
123163 investorsDimension . filter ( function ( i ) { return ( cat_ids . length === 0 || _ . intersection ( i . invested_category_ids , cat_ids ) . length > 0 ) && ( company_ids . length === 0 || _ . intersection ( i . invested_company_ids , company_ids ) . length > 0 ) ; } ) ;
124164
125- $scope . filteredInvestorsList = investorsById . bottom ( 100 ) ;
165+ $scope . filteredInvestorsList = investorsByName . bottom ( Infinity ) ;
126166 }
127167 } ;
128168
129169 var crossCategories ;
130170 var categoriesDimension ;
131- var categoriesById ;
171+ var categoriesByName ;
132172 $scope . filteredCategories = function ( ) {
133173 if ( crossCategories ) {
134174 categoriesDimension . filterAll ( ) ;
135175 categoriesDimension . filter ( function ( c ) { return ( company_ids . length === 0 || _ . intersection ( company_ids , c . company_ids ) . length > 0 ) && ( inv_ids . length === 0 || _ . intersection ( inv_ids , c . investor_ids ) . length > 0 ) ; } ) ;
136176
137- $scope . filteredCategoriesList = categoriesById . bottom ( 100 ) ;
177+ $scope . filteredCategoriesList = categoriesByName . bottom ( Infinity ) ;
178+ }
179+ } ;
180+
181+ $scope . clearLookingFor = function ( ) {
182+ $scope . lookingForList = [ ] ;
183+ $scope . updateLookingFor ( ) ;
184+ } ;
185+
186+ $scope . $watch ( 'lookingFor' , function ( ) {
187+ $scope . clearLookingFor ( ) ;
188+ } ) ;
189+
190+ $scope . updateLookingFor = function ( ) {
191+ var next_items = [ ] ;
192+ var current_count = $scope . lookingForList . length ;
193+ var page_size = 100 ;
194+ if ( $scope . lookingFor === 'companies' ) {
195+ next_items = $scope . filteredCompaniesList . slice ( current_count , current_count + page_size ) ;
196+ }
197+ else if ( $scope . lookingFor === 'investors' ) {
198+ next_items = $scope . filteredInvestorsList . slice ( current_count , current_count + page_size ) ;
138199 }
200+ $scope . lookingForList = $scope . lookingForList . concat ( next_items ) ;
139201 } ;
140202
141203 $scope . companies = CompanyModel ;
142204 $scope . categories = CategoryModel ;
143205 $scope . investors = InvestorModel ;
144206
145207 CompanyModel . fetch ( ) . then ( function ( ) {
146- crossCompanies = crossfilter ( CompanyModel . all ( ) ) ;
208+ $scope . all_companies = CompanyModel . all ( ) ;
209+ crossCompanies = crossfilter ( $scope . all_companies ) ;
147210 companiesDimension = crossCompanies . dimension ( function ( company ) { return company ; } ) ;
148- companiesById = crossCompanies . dimension ( function ( company ) { return company . id ; } ) ;
211+ companiesByName = crossCompanies . dimension ( function ( company ) { return company . name ; } ) ;
149212 $scope . filteredCompanies ( ) ;
150213 } ) ;
151214 InvestorModel . fetch ( ) . then ( function ( ) {
152- crossInvestors = crossfilter ( InvestorModel . all ( ) ) ;
215+ $scope . all_investors = InvestorModel . all ( ) ;
216+ crossInvestors = crossfilter ( $scope . all_investors ) ;
153217 investorsDimension = crossInvestors . dimension ( function ( investor ) { return investor ; } ) ;
154- investorsById = crossInvestors . dimension ( function ( investor ) { return investor . id ; } ) ;
218+ investorsByName = crossInvestors . dimension ( function ( investor ) { return investor . name ; } ) ;
155219 $scope . filteredInvestors ( ) ;
156220 } ) ;
157221 CategoryModel . fetch ( ) . then ( function ( ) {
158222 crossCategories = crossfilter ( CategoryModel . all ( ) ) ;
159223 categoriesDimension = crossCategories . dimension ( function ( category ) { return category ; } ) ;
160- categoriesById = crossCategories . dimension ( function ( category ) { return category . id ; } ) ;
224+ categoriesByName = crossCategories . dimension ( function ( category ) { return category . name ; } ) ;
161225 $scope . filteredCategories ( ) ;
162226 } ) ;
163227
0 commit comments