@@ -16,8 +16,9 @@ angular.module('crunchinatorApp.controllers')
1616} )
1717
1818. controller ( 'CrunchinatorCtrl' , [
19- '$scope' , 'Company' , 'Category' , 'Investor' , 'ComponentData' ,
20- function CrunchinatorCtrl ( $scope , Company , Category , Investor , ComponentData ) {
19+ '$scope' , '$q' , 'Company' , 'Category' , 'Investor' , 'ComponentData' ,
20+ function CrunchinatorCtrl ( $scope , $q , Company , Category , Investor , ComponentData ) {
21+ $scope . loading = true ;
2122 //Create the initial empty filter data for every filter
2223 var filterData = {
2324 categoryIds : [ ] ,
@@ -54,6 +55,7 @@ angular.module('crunchinatorApp.controllers')
5455 Investor . linkModels ( companiesById , categoriesById ) ;
5556 Investor . setupDimensions ( ) ;
5657 Investor . runFilters ( filterData ) ;
58+ $scope . loading = false ;
5759 } ) ;
5860 }
5961 } ) ;
@@ -66,6 +68,24 @@ angular.module('crunchinatorApp.controllers')
6668 //When a filter receives input we set up filterData and run each model's filters
6769 //This should automatically update all the graph displays
6870 $scope . $on ( 'filterAction' , function ( ) {
71+ var deferred = $q . defer ( ) ;
72+
73+
74+ function applyFilters ( ) {
75+ _ . delay ( function ( ) {
76+ $scope . $apply ( function ( ) {
77+ Company . runFilters ( filterData ) ;
78+ Category . runFilters ( filterData ) ;
79+ Investor . runFilters ( filterData ) ;
80+
81+ deferred . resolve ( 'Finished filters' ) ;
82+ } ) ;
83+ } , 300 ) ;
84+
85+ return deferred . promise ;
86+ }
87+
88+ $scope . loading = true ;
6989 filterData . categoryIds = _ . pluck ( $scope . selectedCategories , 'id' ) ;
7090 filterData . companyIds = _ . pluck ( $scope . selectedCompanies , 'id' ) ;
7191 filterData . investorIds = _ . pluck ( $scope . selectedInvestors , 'id' ) ;
@@ -78,9 +98,9 @@ angular.module('crunchinatorApp.controllers')
7898 filterData . acquiredDate = $scope . selectedAquiredDate || [ ] ;
7999 filterData . foundedDate = $scope . selectedFoundedDate || [ ] ;
80100
81- Company . runFilters ( filterData ) ;
82- Category . runFilters ( filterData ) ;
83- Investor . runFilters ( filterData ) ;
101+ applyFilters ( ) . then ( function ( ) {
102+ $scope . loading = false ;
103+ } ) ;
84104 } ) ;
85105 }
86106] ) ;
0 commit comments