Skip to content

Commit b92f9d8

Browse files
author
Nicholas Thomson
committed
Merge pull request #19 from cloudspace/63335088_ui_redesign
Refactor UI with infinite scrolling and Company/Investor select box
2 parents e499198 + 41752c1 commit b92f9d8

File tree

10 files changed

+174
-79
lines changed

10 files changed

+174
-79
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ dist
33
.tmp
44
*.swp
55
.sass-cache
6+
vendor
67
app/vendor
78
build
89

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ module.exports = function (grunt) {
333333
constants: {
334334
ENV: '<%= ENV.env || "production" %>'
335335
}
336-
},
336+
}
337337
},
338338

339339
s3: {

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ $ grunt serve
2727
{
2828
"id": 1,
2929
"name": "company1",
30+
"permalink": "company-1",
3031
"category_id": 15,
3132
"total_funding": 1000.0,
3233
"latitude": 1.0,
@@ -56,6 +57,7 @@ $ grunt serve
5657
"id": "person-5",
5758
"name": "Test Name",
5859
"investor_type": "person",
60+
"permalink": "test-name",
5961
"invested_company_ids":
6062
[
6163
1,

app/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
</footer>
4242

4343
<!-- build:js({.tmp,app}) scripts/libraries.js -->
44+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
4445
<script src="vendor/underscore/underscore.js"></script>
4546
<script src="vendor/angular/angular.js"></script>
4647
<script src="vendor/angular-ui-router/release/angular-ui-router.js"></script>
@@ -50,6 +51,7 @@
5051
<script src="vendor/d3/d3.js"></script>
5152
<script src="vendor/leaflet-dist/leaflet.js"></script>
5253
<script src="vendor/leaflet.markerclusterer/dist/leaflet.markercluster.js"></script>
54+
<script src="vendor/ngInfiniteScroll/ng-infinite-scroll.js"></script>
5355
<!-- endbuild -->
5456

5557
<!-- build:js({.tmp,app}) scripts/scripts.js -->

app/scripts/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ angular.module('crunchinatorApp.controllers', [
77
'ui.bootstrap',
88
'configuration',
99
'crunchinatorApp.models',
10-
'crunchinatorApp.directives'
10+
'crunchinatorApp.directives',
11+
'infinite-scroll'
1112
]);
1213

1314
angular.module('crunchinatorApp', [

app/scripts/controllers/crunchinator.js

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/styles/main.css

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

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

74+
.remove-selected {
75+
text-align: right;
76+
}

0 commit comments

Comments
 (0)