@@ -309,6 +309,9 @@ export class DashboardComponent implements OnInit {
309309 repoSearchTerm = '' ;
310310 reposLoading = false ;
311311 repoRows : RepoRow [ ] = [ ]
312+ allImportRepoRows : RepoRow [ ] = [ ] ;
313+ filteredImportRepoRows : RepoRow [ ] = [ ] ;
314+ importRepoSearchTerm = '' ;
312315 columns : any [ ] = [ ] ;
313316
314317 cloudRows : CloudSubscription [ ] = [ ] ;
@@ -1187,20 +1190,9 @@ export class DashboardComponent implements OnInit {
11871190 }
11881191 }
11891192
1190- tempRepos = [ ...this . repoRows ] ; // a copy of the original rows for filtering
1191-
11921193 updateFilterRepo ( event : any ) {
1193- const val = event . target . value . toLowerCase ( ) ;
1194-
1195- // filter our data based on multiple columns
1196- const filteredRepos = this . tempRepos . filter ( d =>
1197- d . name . toLowerCase ( ) . includes ( val ) ||
1198- d . namespace . toLowerCase ( ) . includes ( val ) ||
1199- d . repo_url . toLowerCase ( ) . includes ( val )
1200- ) ;
1201-
1202- // update the rows
1203- this . repoRows = filteredRepos ;
1194+ this . importRepoSearchTerm = ( event ?. target ?. value || '' ) . toLowerCase ( ) . trim ( ) ;
1195+ this . applyImportRepoFilter ( ) ;
12041196 }
12051197
12061198 onImportRepoPage ( event : { offset : number } ) {
@@ -1212,55 +1204,59 @@ export class DashboardComponent implements OnInit {
12121204 }
12131205
12141206 loadImportReposPage ( page = 0 ) {
1207+ if ( this . allImportRepoRows . length > 0 ) {
1208+ this . importRepoCurrentPage = page ;
1209+ this . refreshImportRepoView ( ) ;
1210+ return ;
1211+ }
1212+
12151213 this . isLoading = true ;
1216- const providerPage = page + 1 ;
1217- const pageSize = this . importRepoPageSize ;
12181214
12191215 if ( this . selectedRepo === 'GitLab' ) {
1220- this . gitLabService . getProjects ( this . accessToken , providerPage , pageSize ) . subscribe ( {
1221- next : ( projects ) => this . updateImportRepoPage ( projects . map ( ( proj : any ) => ( {
1216+ this . gitLabService . getAllProjects ( this . accessToken ) . subscribe ( {
1217+ next : ( projects ) => this . updateImportRepoRows ( projects . map ( ( proj : any ) => ( {
12221218 id : proj . id ,
12231219 name : proj . name ,
12241220 repo_url : proj . web_url ,
12251221 namespace : proj . path_with_namespace ,
12261222 imported : false
1227- } ) ) , page ) ,
1223+ } ) ) ) ,
12281224 error : ( error ) => this . handleImportRepoPageError ( error ) ,
12291225 complete : ( ) => this . isLoading = false
12301226 } ) ;
12311227 } else if ( this . selectedRepo === 'GitHub' ) {
1232- this . gitHubService . getRepositories ( this . accessToken , providerPage , pageSize ) . subscribe ( {
1233- next : ( projects ) => this . updateImportRepoPage ( projects . map ( ( proj : any ) => ( {
1228+ this . gitHubService . getAllRepositories ( this . accessToken ) . subscribe ( {
1229+ next : ( projects ) => this . updateImportRepoRows ( projects . map ( ( proj : any ) => ( {
12341230 id : proj . id ,
12351231 name : proj . name ,
12361232 repo_url : proj . web_url ,
12371233 namespace : proj . path_with_namespace ,
12381234 imported : false
1239- } ) ) , page ) ,
1235+ } ) ) ) ,
12401236 error : ( error ) => this . handleImportRepoPageError ( error ) ,
12411237 complete : ( ) => this . isLoading = false
12421238 } ) ;
12431239 } else if ( this . selectedRepo === 'Gitea' ) {
1244- this . giteaService . getRepositories ( this . accessToken , providerPage , pageSize ) . subscribe ( {
1245- next : ( projects ) => this . updateImportRepoPage ( projects . map ( ( proj : any ) => ( {
1240+ this . giteaService . getAllRepositories ( this . accessToken ) . subscribe ( {
1241+ next : ( projects ) => this . updateImportRepoRows ( projects . map ( ( proj : any ) => ( {
12461242 id : proj . id ,
12471243 name : proj . name ,
12481244 repo_url : proj . web_url ,
12491245 namespace : proj . path_with_namespace ,
12501246 imported : false
1251- } ) ) , page ) ,
1247+ } ) ) ) ,
12521248 error : ( error ) => this . handleImportRepoPageError ( error ) ,
12531249 complete : ( ) => this . isLoading = false
12541250 } ) ;
12551251 } else if ( this . selectedRepo === 'Bitbucket' ) {
1256- this . bitbucketService . getRepositories ( this . accessToken , providerPage , pageSize ) . subscribe ( {
1257- next : ( projects ) => this . updateImportRepoPage ( projects . map ( ( proj : any ) => ( {
1252+ this . bitbucketService . getAllRepositories ( this . accessToken ) . subscribe ( {
1253+ next : ( projects ) => this . updateImportRepoRows ( projects . map ( ( proj : any ) => ( {
12581254 id : proj . id ,
12591255 name : proj . name ,
12601256 repo_url : proj . web_url ,
12611257 namespace : proj . path_with_namespace ,
12621258 imported : false
1263- } ) ) , page ) ,
1259+ } ) ) ) ,
12641260 error : ( error ) => this . handleImportRepoPageError ( error ) ,
12651261 complete : ( ) => this . isLoading = false
12661262 } ) ;
@@ -1272,17 +1268,33 @@ export class DashboardComponent implements OnInit {
12721268 }
12731269 }
12741270
1275- private updateImportRepoPage ( repos : RepoRow [ ] , page : number ) {
1276- this . repoRows = repos ;
1277- this . importRepoCurrentPage = page ;
1278- const hasNextPage = repos . length === this . importRepoPageSize ;
1279- this . importRepoTotalCount = hasNextPage
1280- ? ( ( page + 1 ) * this . importRepoPageSize ) + 1
1281- : ( page * this . importRepoPageSize ) + repos . length ;
1282- this . repoRows . forEach ( repoRow => {
1283- repoRow . imported = this . rows . some ( row => row . repo_url === repoRow . repo_url ) ;
1284- } ) ;
1285- this . tempRepos = [ ...this . repoRows ] ;
1271+ private updateImportRepoRows ( repos : RepoRow [ ] ) {
1272+ this . allImportRepoRows = repos . map ( ( repo ) => ( {
1273+ ...repo ,
1274+ imported : this . rows . some ( row => row . repo_url === repo . repo_url )
1275+ } ) ) ;
1276+ this . applyImportRepoFilter ( ) ;
1277+ }
1278+
1279+ private applyImportRepoFilter ( ) {
1280+ if ( ! this . importRepoSearchTerm ) {
1281+ this . filteredImportRepoRows = [ ...this . allImportRepoRows ] ;
1282+ } else {
1283+ this . filteredImportRepoRows = this . allImportRepoRows . filter ( ( repo ) =>
1284+ repo . name . toLowerCase ( ) . includes ( this . importRepoSearchTerm ) ||
1285+ repo . namespace . toLowerCase ( ) . includes ( this . importRepoSearchTerm ) ||
1286+ repo . repo_url . toLowerCase ( ) . includes ( this . importRepoSearchTerm )
1287+ ) ;
1288+ }
1289+ this . importRepoCurrentPage = 0 ;
1290+ this . refreshImportRepoView ( ) ;
1291+ }
1292+
1293+ private refreshImportRepoView ( ) {
1294+ const start = this . importRepoCurrentPage * this . importRepoPageSize ;
1295+ const end = start + this . importRepoPageSize ;
1296+ this . importRepoTotalCount = this . filteredImportRepoRows . length ;
1297+ this . repoRows = this . filteredImportRepoRows . slice ( start , end ) ;
12861298 }
12871299
12881300 private handleImportRepoPageError ( error : any ) {
@@ -1349,6 +1361,10 @@ export class DashboardComponent implements OnInit {
13491361 this . accessToken = this . importRepoForm . value . accessToken ; // Store accessToken
13501362 this . importRepoCurrentPage = 0 ;
13511363 this . importRepoTotalCount = 0 ;
1364+ this . importRepoSearchTerm = '' ;
1365+ this . repoRows = [ ] ;
1366+ this . allImportRepoRows = [ ] ;
1367+ this . filteredImportRepoRows = [ ] ;
13521368
13531369 if ( this . selectedRepo === 'GitLab' ) {
13541370 this . gitLabService . setApiUrl ( this . repoUrl ) ;
@@ -1388,6 +1404,16 @@ export class DashboardComponent implements OnInit {
13881404 repoObject . repoUrl = this . bitbucketService . getApiUrl ( )
13891405 }
13901406 row . imported = true ;
1407+ const importedUrl = row . repo_url ;
1408+ this . allImportRepoRows = this . allImportRepoRows . map ( repo => ( {
1409+ ...repo ,
1410+ imported : repo . repo_url === importedUrl ? true : repo . imported
1411+ } ) ) ;
1412+ this . filteredImportRepoRows = this . filteredImportRepoRows . map ( repo => ( {
1413+ ...repo ,
1414+ imported : repo . repo_url === importedUrl ? true : repo . imported
1415+ } ) ) ;
1416+ this . refreshImportRepoView ( ) ;
13911417 this . dashboardService . createRepo ( repoObject , this . selectedRepo . toLowerCase ( ) ) . subscribe ( {
13921418 next : ( response ) => {
13931419 this . toastStatus = "success"
0 commit comments