@@ -16,11 +16,15 @@ angular.module('openshiftConsole')
16
16
AuthService ,
17
17
DataService ,
18
18
KeywordService ,
19
+ Navigate ,
19
20
Logger ,
20
21
ProjectsService ) {
22
+ var MAX_PROJETS_TO_WATCH = 250 ;
23
+
21
24
var projects , sortedProjects ;
22
25
var watches = [ ] ;
23
26
var filterKeywords = [ ] ;
27
+ var watchingProjects = false ;
24
28
25
29
$scope . alerts = $scope . alerts || { } ;
26
30
$scope . loading = true ;
@@ -30,6 +34,9 @@ angular.module('openshiftConsole')
30
34
text : ''
31
35
} ;
32
36
37
+ // Only show the first `MAX_PROJETS_TO_WATCH` on the page. Users can always filter.
38
+ $scope . limitListTo = MAX_PROJETS_TO_WATCH ;
39
+
33
40
var filterFields = [
34
41
'metadata.name' ,
35
42
'metadata.annotations["openshift.io/display-name"]' ,
@@ -62,19 +69,19 @@ angular.module('openshiftConsole')
62
69
// Sort by display name. Use `metadata.name` as a secondary sort when
63
70
// projects have the same display name.
64
71
sortedProjects = _ . orderBy ( projects ,
65
- [ displayNameLower , 'metadata.name' ] ,
66
- [ primarySortOrder ] ) ;
72
+ [ displayNameLower , 'metadata.name' ] ,
73
+ [ primarySortOrder ] ) ;
67
74
break ;
68
75
case 'metadata.annotations["openshift.io/requester"]' :
69
76
// Sort by requester, then display name. Secondary sort is always ascending.
70
77
sortedProjects = _ . orderBy ( projects ,
71
- [ sortID , displayNameLower ] ,
72
- [ primarySortOrder , 'asc' ] ) ;
78
+ [ sortID , displayNameLower ] ,
79
+ [ primarySortOrder , 'asc' ] ) ;
73
80
break ;
74
81
default :
75
82
sortedProjects = _ . orderBy ( projects ,
76
- [ sortID ] ,
77
- [ primarySortOrder ] ) ;
83
+ [ sortID ] ,
84
+ [ primarySortOrder ] ) ;
78
85
}
79
86
80
87
// Remember the previous sort ID.
@@ -109,6 +116,21 @@ angular.module('openshiftConsole')
109
116
onSortChange : update
110
117
} ;
111
118
119
+ var updateProjects = function ( projectData ) {
120
+ projects = _ . toArray ( projectData . by ( "metadata.name" ) ) ;
121
+ $scope . loading = false ;
122
+ $scope . showGetStarted = _ . isEmpty ( projects ) && ! $scope . isProjectListIncomplete ;
123
+ update ( ) ;
124
+ } ;
125
+
126
+ // On create / edit / delete, manually update the project list if not
127
+ // watching. This uses cached project data, so is not expensive.
128
+ var onChanges = function ( ) {
129
+ if ( ! watchingProjects ) {
130
+ ProjectsService . list ( ) . then ( updateProjects ) ;
131
+ }
132
+ } ;
133
+
112
134
$scope . newProjectPanelShown = false ;
113
135
114
136
$scope . createProject = function ( ) {
@@ -121,6 +143,7 @@ angular.module('openshiftConsole')
121
143
122
144
$scope . onNewProject = function ( ) {
123
145
$scope . newProjectPanelShown = false ;
146
+ onChanges ( ) ;
124
147
} ;
125
148
126
149
$scope . editProjectPanelShown = false ;
@@ -136,24 +159,38 @@ angular.module('openshiftConsole')
136
159
137
160
$scope . onEditProject = function ( ) {
138
161
$scope . editProjectPanelShown = false ;
162
+ onChanges ( ) ;
163
+ } ;
164
+
165
+ $scope . onDeleteProject = onChanges ;
166
+
167
+ $scope . goToProject = function ( projectName ) {
168
+ Navigate . toProjectOverview ( projectName ) ;
139
169
} ;
140
170
141
171
$scope . $watch ( 'search.text' , _ . debounce ( function ( searchText ) {
142
172
$scope . keywords = filterKeywords = KeywordService . generateKeywords ( searchText ) ;
143
- $scope . $apply ( filterProjects ) ;
144
- } , 50 , { maxWait : 250 } ) ) ;
173
+ $scope . $applyAsync ( filterProjects ) ;
174
+ } , 350 ) ) ;
145
175
146
176
AuthService . withUser ( ) . then ( function ( ) {
147
- watches . push ( DataService . watch ( "projects" , $scope , function ( projectData ) {
148
- projects = _ . toArray ( projectData . by ( "metadata.name" ) ) ;
177
+ ProjectsService . list ( ) . then ( function ( projectData ) {
178
+ $scope . isProjectListIncomplete = ProjectsService . isProjectListIncomplete ( ) ;
179
+ updateProjects ( projectData ) ;
180
+ if ( ! $scope . isProjectListIncomplete && _ . size ( projects ) <= MAX_PROJETS_TO_WATCH ) {
181
+ watches . push ( ProjectsService . watch ( $scope , updateProjects ) ) ;
182
+ watchingProjects = true ;
183
+ }
184
+ } , function ( ) {
185
+ $scope . isProjectListIncomplete = true ;
149
186
$scope . loading = false ;
150
- $scope . showGetStarted = _ . isEmpty ( projects ) ;
187
+ projects = [ ] ;
151
188
update ( ) ;
152
- } ) ) ;
189
+ } ) ;
153
190
} ) ;
154
191
155
- // Test if the user can submit project requests. Handle error notifications
156
- // ourselves because 403 responses are expected.
192
+ // Test if the user can submit project requests. Handle error notifications
193
+ // ourselves because 403 responses are expected.
157
194
ProjectsService
158
195
. canCreate ( )
159
196
. then ( function ( ) {
0 commit comments