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