Skip to content

Commit 5f1c26b

Browse files
committed
add company/investor selection with autocomplete
1 parent eec1266 commit 5f1c26b

File tree

4 files changed

+67
-13
lines changed

4 files changed

+67
-13
lines changed

app/scripts/controllers/crunchinator.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,35 @@ angular.module('crunchinatorApp.controllers')
1616
})
1717

1818
.controller('CrunchinatorCtrl', function CrunchinatorCtrl($scope, $http, ENV, CompanyModel, CategoryModel, InvestorModel) {
19-
$scope.select2Options = {
20-
minimumInputLength: 2
21-
};
2219
$scope.environment = ENV;
2320

2421
$scope.filteredCompaniesList = [];
2522
$scope.filteredCategoriesList = [];
2623
$scope.filteredInvestorsList = [];
2724
$scope.lookingForList = [];
2825

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+
2948
$scope.geoJsonData = _.memoize(function(filteredCompanies) {
3049
var geojson = {
3150
'type': 'FeatureCollection',
@@ -50,7 +69,7 @@ angular.module('crunchinatorApp.controllers')
5069
return _.pluck(filteredCompanies, 'id').join('');
5170
});
5271

53-
$scope.totalRaisedGraphData = _.memoize(function(filteredCompanies) {
72+
/*$scope.totalRaisedGraphData = _.memoize(function(filteredCompanies) {
5473
if (!filteredCompanies || !filteredCompanies.length) { return; }
5574
var total_raised_data = [];
5675
for(var i = 1; i <= 10; i++){
@@ -67,7 +86,7 @@ angular.module('crunchinatorApp.controllers')
6786
return total_raised_data;
6887
}, function(filteredCompanies) {
6988
return _.pluck(filteredCompanies, 'id').join('');
70-
});
89+
});*/
7190

7291
$scope.resetSelection = function() {
7392
$scope.selectedCompanies = [];
@@ -115,7 +134,7 @@ angular.module('crunchinatorApp.controllers')
115134
$scope.filteredCompanies = function() {
116135
if(crossCompanies) {
117136
companiesDimension.filterAll(); //clear filter
118-
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); });
137+
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); });
119138

120139
$scope.filteredCompaniesList = companiesByName.bottom(Infinity);
121140
}
@@ -159,16 +178,11 @@ angular.module('crunchinatorApp.controllers')
159178
var current_count = $scope.lookingForList.length;
160179
if($scope.lookingFor === 'companies') {
161180
next_items = $scope.filteredCompaniesList.slice(current_count, current_count+50);
162-
console.log($scope.filteredCompaniesList.length);
163181
}
164182
else if($scope.lookingFor === 'investors') {
165183
next_items = $scope.filteredInvestorsList.slice(current_count, current_count+50);
166-
console.log($scope.filteredInvestorsList.length);
167184
}
168185
$scope.lookingForList = $scope.lookingForList.concat(next_items);
169-
170-
console.log(next_items);
171-
172186
};
173187

174188
$scope.companies = CompanyModel;

app/styles/main.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ body {
6767
clear: both;
6868
}
6969

70-
70+
#investors .dataset, #companies .dataset {
71+
height: 251px;
72+
}

app/views/main.tpl.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,48 @@ <h3 class='pull-left'>
6161

6262
<div ng-show='lookingFor == "companies"' class='col-sm-4 spacing-med'>
6363
<h3 class="pull-left">Investors</h3>
64+
<div id="investors" class="textlist clear-both">
65+
<div class="form-group">
66+
<div class="controls">
67+
<div class="input-group">
68+
<span class="input-group-addon"><i class="glyphicon glyphicon-leaf"></i></span>
69+
<input class="form-control" type="text" ng-model="selected_investor" typeahead-on-select="select_investor()" typeahead="investor as investor.name for investor in all_investors | filter:{name: $viewValue} | limitTo: 3" />
70+
</div>
71+
</div>
72+
</div>
73+
<div class="dataset">
74+
<table class="table">
75+
<tbody>
76+
<tr ng-repeat="investor in selectedInvestors">
77+
<td>{{investor.name}}</td>
78+
</tr>
79+
</tbody>
80+
</table>
81+
</div>
82+
</div>
6483
</div>
6584

6685
<div ng-show='lookingFor == "investors"' class='col-sm-4 spacing-med'>
6786
<h3 class="pull-left">Companies</h3>
87+
<div id="companies" class="textlist clear-both">
88+
<div class="form-group">
89+
<div class="controls">
90+
<div class="input-group">
91+
<span class="input-group-addon"><i class="glyphicon glyphicon-bullhorn"></i></span>
92+
<input class="form-control" type="text" ng-model="selected_company" typeahead-on-select="select_company()" typeahead="company as company.name for company in all_companies | filter:{name: $viewValue} | limitTo: 3" />
93+
</div>
94+
</div>
95+
</div>
96+
<div class="dataset">
97+
<table class="table">
98+
<tbody>
99+
<tr ng-repeat="company in selectedCompanies">
100+
<td>{{company.name}}</td>
101+
</tr>
102+
</tbody>
103+
</table>
104+
</div>
105+
</div>
68106
</div>
69107
</div>
70108
<div class='row spacing-med'>

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"es5-shim": "~2.1.0",
88
"bootstrap": "~3.0.3",
99
"d3": "~3.3.13",
10-
"angular-bootstrap": "~0.3.0",
10+
"angular-bootstrap": "~0.9.0",
1111
"angular-ui-router": "~0.0.1",
1212
"angular-ui-utils": "~0.0.3",
1313
"underscore": "~1.5.2",

0 commit comments

Comments
 (0)