@@ -15,216 +15,43 @@ angular.module('crunchinatorApp.controllers')
1515 } ) ;
1616} )
1717
18- . controller ( 'CrunchinatorCtrl' , function CrunchinatorCtrl ( $scope , $http , ENV , CompanyModel , CategoryModel , InvestorModel ) {
19- $scope . environment = ENV ;
20-
21- $scope . filteredCompaniesList = [ ] ;
22- $scope . filteredCategoriesList = [ ] ;
23- $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- }
18+ . controller ( 'CrunchinatorCtrl' , function CrunchinatorCtrl ( $scope , $http , ENV , Company , Category , Investor , ComponentData ) {
19+ var filterData = {
20+ categoryIds : [ ] ,
21+ investorIds : [ ] ,
22+ companyIds : [ ]
3523 } ;
3624
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 ( ) ;
25+ $scope . companies = Company ;
26+ $scope . investors = Investor ;
27+ $scope . categories = Category ;
4228
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- } ;
61-
62- $scope . geoJsonData = _ . memoize ( function ( filteredCompanies ) {
63- var geojson = {
64- 'type' : 'FeatureCollection' ,
65- 'features' : [ ]
66- } ;
67- if ( ! filteredCompanies || ! filteredCompanies . length ) { return geojson ; }
68-
69- _ . each ( filteredCompanies , function ( company ) {
70- if ( company . latitude && company . longitude ) {
71- geojson . features . push ( {
72- 'type' : 'Feature' ,
73- 'geometry' : { 'type' : 'Point' , 'coordinates' : [ company . longitude , company . latitude ] } ,
74- 'properties' : 0
75- } ) ;
76- }
77-
78- } ) ;
79-
80- return geojson ;
81-
82- } , function ( filteredCompanies ) {
83- return _ . pluck ( filteredCompanies , 'id' ) . join ( '' ) ;
29+ Company . fetch ( ) . then ( function ( ) {
30+ Company . setupDimensions ( ) ;
31+ Company . runFilters ( filterData ) ;
8432 } ) ;
8533
86- /*$scope.totalRaisedGraphData = _.memoize(function(filteredCompanies) {
87- if (!filteredCompanies || !filteredCompanies.length) { return; }
88- var total_raised_data = [];
89- for(var i = 1; i <= 10; i++){
90- total_raised_data.push({
91- label: '$'+i+' - $'+((i === 1 ? 0 : i)+1) + 'M',
92- count: 0
93- });
94- }
95-
96- _.each(filteredCompanies, function(company) {
97- var label_index = Math.floor((company.total_funding + 1) / 1000000);
98- total_raised_data[label_index].count++;
99- });
100- return total_raised_data;
101- }, function(filteredCompanies) {
102- return _.pluck(filteredCompanies, 'id').join('');
103- });*/
104-
105- $scope . resetSelection = function ( ) {
106- $scope . selectedCompanies = [ ] ;
107- $scope . selectedCategories = [ ] ;
108- $scope . selectedInvestors = [ ] ;
109-
110- $scope . filteredCompanies ( ) ;
111- $scope . filteredCategories ( ) ;
112- $scope . filteredInvestors ( ) ;
113- } ;
114-
115- var cat_ids = [ ] ;
116- var company_ids = [ ] ;
117- var inv_ids = [ ] ;
118- $scope . toggleSelected = function ( selectedItems , item ) {
119- $scope . selectedItem = item ;
120- var ind = selectedItems . indexOf ( item ) ;
121- if ( ind > - 1 ) {
122- //Remove item if its already selected
123- selectedItems . splice ( ind , 1 ) ;
124- } else {
125- //Add item if its not already selected
126- selectedItems . push ( item ) ;
127- }
128-
129- cat_ids = _ . pluck ( $scope . selectedCategories , 'id' ) ;
130- company_ids = _ . pluck ( $scope . selectedCompanies , 'id' ) ;
131- inv_ids = _ . pluck ( $scope . selectedInvestors , 'id' ) ;
132-
133- $scope . filteredCompanies ( ) ;
134- $scope . filteredCategories ( ) ;
135- $scope . filteredInvestors ( ) ;
136- $scope . clearLookingFor ( ) ;
137-
138- $scope . updateLookingFor ( ) ;
139-
140- $scope . selectedCompanies = _ . intersection ( $scope . selectedCompanies , $scope . filteredCompaniesList ) ;
141- $scope . selectedCategories = _ . intersection ( $scope . selectedCategories , $scope . filteredCategoriesList ) ;
142- $scope . selectedInvestors = _ . intersection ( $scope . selectedInvestors , $scope . filteredInvestorsList ) ;
143- } ;
144-
145- var crossCompanies ;
146- var companiesDimension ;
147- var companiesByName ;
148- $scope . filteredCompanies = function ( ) {
149- if ( crossCompanies ) {
150- companiesDimension . filterAll ( ) ; //clear filter
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 ) ; } ) ;
152-
153- $scope . filteredCompaniesList = companiesByName . bottom ( Infinity ) ;
154- }
155- } ;
156-
157- var crossInvestors ;
158- var investorsDimension ;
159- var investorsByName ;
160- $scope . filteredInvestors = function ( ) {
161- if ( crossInvestors ) {
162- investorsDimension . filterAll ( ) ;
163- 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 ) ; } ) ;
164-
165- $scope . filteredInvestorsList = investorsByName . bottom ( Infinity ) ;
166- }
167- } ;
168-
169- var crossCategories ;
170- var categoriesDimension ;
171- var categoriesByName ;
172- $scope . filteredCategories = function ( ) {
173- if ( crossCategories ) {
174- categoriesDimension . filterAll ( ) ;
175- 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 ) ; } ) ;
176-
177- $scope . filteredCategoriesList = categoriesByName . bottom ( Infinity ) ;
178- }
179- } ;
180-
181- $scope . clearLookingFor = function ( ) {
182- $scope . lookingForList = [ ] ;
183- $scope . updateLookingFor ( ) ;
184- } ;
34+ Category . fetch ( ) . then ( function ( ) {
35+ Category . setupDimensions ( ) ;
36+ Category . runFilters ( filterData ) ;
37+ } ) ;
18538
186- $scope . $watch ( 'lookingFor' , function ( ) {
187- $scope . clearLookingFor ( ) ;
39+ Investor . fetch ( ) . then ( function ( ) {
40+ Investor . setupDimensions ( ) ;
41+ Investor . runFilters ( filterData ) ;
18842 } ) ;
18943
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 ) ;
199- }
200- $scope . lookingForList = $scope . lookingForList . concat ( next_items ) ;
201- } ;
44+ $scope . geoJsonData = ComponentData . companyGeoJson ;
45+ $scope . totalFunding = ComponentData . totalFunding ;
20246
203- $scope . companies = CompanyModel ;
204- $scope . categories = CategoryModel ;
205- $scope . investors = InvestorModel ;
47+ //Moves into a directive that handles how we do categories
48+ $scope . $on ( 'filterAction' , function ( ) {
49+ filterData . categoryIds = _ . pluck ( $scope . selectedCategories , 'id' ) ;
50+ filterData . companyIds = _ . pluck ( $scope . selectedCompanies , 'id' ) ;
51+ filterData . investorIds = _ . pluck ( $scope . selectedInvestors , 'id' ) ;
20652
207- CompanyModel . fetch ( ) . then ( function ( ) {
208- $scope . all_companies = CompanyModel . all ( ) ;
209- crossCompanies = crossfilter ( $scope . all_companies ) ;
210- companiesDimension = crossCompanies . dimension ( function ( company ) { return company ; } ) ;
211- companiesByName = crossCompanies . dimension ( function ( company ) { return company . name ; } ) ;
212- $scope . filteredCompanies ( ) ;
213- } ) ;
214- InvestorModel . fetch ( ) . then ( function ( ) {
215- $scope . all_investors = InvestorModel . all ( ) ;
216- crossInvestors = crossfilter ( $scope . all_investors ) ;
217- investorsDimension = crossInvestors . dimension ( function ( investor ) { return investor ; } ) ;
218- investorsByName = crossInvestors . dimension ( function ( investor ) { return investor . name ; } ) ;
219- $scope . filteredInvestors ( ) ;
220- } ) ;
221- CategoryModel . fetch ( ) . then ( function ( ) {
222- crossCategories = crossfilter ( CategoryModel . all ( ) ) ;
223- categoriesDimension = crossCategories . dimension ( function ( category ) { return category ; } ) ;
224- categoriesByName = crossCategories . dimension ( function ( category ) { return category . name ; } ) ;
225- $scope . filteredCategories ( ) ;
53+ Company . runFilters ( filterData ) ;
54+ Category . runFilters ( filterData ) ;
55+ Investor . runFilters ( filterData ) ;
22656 } ) ;
227-
228- $scope . resetSelection ( ) ;
229-
23057} ) ;
0 commit comments