@@ -49,9 +49,35 @@ function Organization (instance, view) {
49
49
self . display_name = ko . computed ( function ( ) {
50
50
return self . name ( ) || self . slug ( ) ;
51
51
} ) ;
52
+ self . filter_id = ko . computed ( function ( ) {
53
+ return self . id ( ) ;
54
+ } ) ;
55
+ self . filter_type = 'org' ;
52
56
self . filtered = ko . computed ( function ( ) {
53
- var id = view . filter_org ( ) ;
54
- return id && id != self . id ( ) ;
57
+ var filter = view . filter_by ( ) ;
58
+ return ( filter . id && filter . id != self . filter_id ( ) ) || ( filter . type && filter . type != self . filter_type ) ;
59
+ } ) ;
60
+ }
61
+
62
+ function Account ( instance , view ) {
63
+ var self = this ;
64
+ self . id = ko . observable ( instance . id ) ;
65
+ self . username = ko . observable ( instance . username ) ;
66
+ self . active = ko . observable ( instance . active ) ;
67
+ self . avatar_url = ko . observable (
68
+ append_url_params ( instance . avatar_url , { size : 32 } )
69
+ ) ;
70
+ self . provider = ko . observable ( instance . provider ) ;
71
+ self . display_name = ko . computed ( function ( ) {
72
+ return self . username ( ) ;
73
+ } ) ;
74
+ self . filter_id = ko . computed ( function ( ) {
75
+ return self . provider ( ) . id ;
76
+ } ) ;
77
+ self . filter_type = 'own' ;
78
+ self . filtered = ko . computed ( function ( ) {
79
+ var filter = view . filter_by ( ) ;
80
+ return ( filter . id && filter . id != self . filter_id ( ) ) || ( filter . type && filter . type != self . filter_type ) ;
55
81
} ) ;
56
82
}
57
83
@@ -62,7 +88,7 @@ function Project (instance, view) {
62
88
self . full_name = ko . observable ( instance . full_name ) ;
63
89
self . description = ko . observable ( instance . description ) ;
64
90
self . vcs = ko . observable ( instance . vcs ) ;
65
- self . organization = ko . observable ( ) ;
91
+ self . organization = ko . observable ( instance . organization ) ;
66
92
self . html_url = ko . observable ( instance . html_url ) ;
67
93
self . clone_url = ko . observable ( instance . clone_url ) ;
68
94
self . ssh_url = ko . observable ( instance . ssh_url ) ;
@@ -140,38 +166,44 @@ function ProjectImportView (instance, config) {
140
166
self . page_current = ko . observable ( null ) ;
141
167
self . page_next = ko . observable ( null ) ;
142
168
self . page_previous = ko . observable ( null ) ;
143
- self . filter_org = ko . observable ( null ) ;
144
- self . filter_own = ko . observable ( null ) ;
169
+ // organization slug or account provider name
170
+ // { id: 'GitHub', type: 'own' }
171
+ self . filter_by = ko . observable ( { id : null , type : null } ) ;
145
172
173
+ self . accounts_raw = ko . observableArray ( ) ;
146
174
self . organizations_raw = ko . observableArray ( ) ;
147
- self . organizations = ko . computed ( function ( ) {
148
- var organizations = [ ] ,
175
+ self . filters = ko . computed ( function ( ) {
176
+ var filters = [ ] ,
177
+ accounts_raw = self . accounts_raw ( ) ,
149
178
organizations_raw = self . organizations_raw ( ) ;
179
+ for ( n in accounts_raw ) {
180
+ var account = new Account ( accounts_raw [ n ] , self ) ;
181
+ filters . push ( account ) ;
182
+ }
150
183
for ( n in organizations_raw ) {
151
184
var organization = new Organization ( organizations_raw [ n ] , self ) ;
152
- organizations . push ( organization ) ;
185
+ filters . push ( organization ) ;
153
186
}
154
- return organizations ;
187
+ return filters ;
155
188
} ) ;
156
189
self . projects = ko . observableArray ( ) ;
157
190
158
191
ko . computed ( function ( ) {
159
- var org = self . filter_org ( ) ,
160
- own = self . filter_own ( ) ,
192
+ var filter = self . filter_by ( ) ,
161
193
url = self . page_current ( ) || self . urls [ 'remoterepository-list' ] ;
162
194
163
195
if ( ! self . page_current ( ) ) {
164
- if ( org ) {
196
+ if ( filter . type == ' org' ) {
165
197
url = append_url_params (
166
198
self . urls [ 'remoterepository-list' ] ,
167
- { org : org }
199
+ { org : filter . id }
168
200
) ;
169
201
}
170
202
171
- if ( own ) {
203
+ if ( filter . type == ' own' ) {
172
204
url = append_url_params (
173
205
self . urls [ 'remoterepository-list' ] ,
174
- { own : own }
206
+ { own : filter . id }
175
207
) ;
176
208
}
177
209
}
@@ -210,6 +242,17 @@ function ProjectImportView (instance, config) {
210
242
} ) ;
211
243
} ;
212
244
245
+ self . get_accounts = function ( ) {
246
+ $ . getJSON ( self . urls [ 'remoteaccount-list' ] )
247
+ . success ( function ( accounts ) {
248
+ self . accounts_raw ( accounts . results ) ;
249
+ } )
250
+ . error ( function ( error ) {
251
+ var error_msg = error . responseJSON . detail || error . statusText ;
252
+ self . error ( { message : error_msg } ) ;
253
+ } ) ;
254
+ } ;
255
+
213
256
self . sync_projects = function ( ) {
214
257
var url = self . urls . api_sync_remote_repositories ;
215
258
@@ -219,6 +262,7 @@ function ProjectImportView (instance, config) {
219
262
tasks . trigger_task ( { url : url , token : self . csrf_token } )
220
263
. then ( function ( data ) {
221
264
self . get_organizations ( ) ;
265
+ self . get_accounts ( ) ;
222
266
} )
223
267
. fail ( function ( error ) {
224
268
self . error ( error ) ;
@@ -240,27 +284,23 @@ function ProjectImportView (instance, config) {
240
284
self . page_current ( self . page_previous ( ) ) ;
241
285
} ;
242
286
243
- self . set_filter_org = function ( id ) {
244
- var current_id = self . filter_org ( ) ;
245
- if ( current_id == id ) {
246
- id = null ;
287
+ self . set_filter_by = function ( id , type ) {
288
+ var filter = self . filter_by ( ) ;
289
+ if ( filter . id == id ) {
290
+ filter . id = null ;
291
+ filter . type = null ;
247
292
}
248
- // This needs to use deferred updates
249
- self . filter_org ( id ) ;
250
- self . filter_own ( false ) ;
251
- self . page_current ( null ) ;
252
- } ;
253
-
254
- self . set_filter_own = function ( account ) {
255
- var current_account = self . filter_own ( ) ;
256
- if ( current_account == account ) {
257
- account = null ;
293
+ else {
294
+ filter . id = id ;
295
+ filter . type = type ;
258
296
}
259
297
260
- // This needs to use deferred updates
261
- self . filter_own ( account ) ;
262
- self . filter_org ( null ) ;
263
- self . page_current ( null ) ;
298
+ // This needs to use deferred updates because we are setting
299
+ // `filter_by` and `page_current`
300
+ self . filter_by ( filter ) ;
301
+ if ( filter . id ) {
302
+ self . page_current ( null ) ;
303
+ }
264
304
} ;
265
305
}
266
306
@@ -278,6 +318,7 @@ function append_url_params (url, params) {
278
318
279
319
ProjectImportView . init = function ( domobj , instance , config ) {
280
320
var view = new ProjectImportView ( instance , config ) ;
321
+ view . get_accounts ( ) ;
281
322
view . get_organizations ( ) ;
282
323
ko . applyBindings ( view , domobj ) ;
283
324
return view ;
0 commit comments