Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit eb360cf

Browse files
authored
Merge pull request #446 from gets0ul/issue-445
Fix for Issue #445 Dev site - projects not loading
2 parents 8d73ae2 + 7077279 commit eb360cf

File tree

8 files changed

+68
-52
lines changed

8 files changed

+68
-52
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"superagent-promise": "^1.1.0",
8888
"typescript": "~2.3.3",
8989
"uuid": "^3.3.2",
90+
"ui-select": "~0.19.8",
9091
"winston": "^2.3.1",
9192
"tc-auth-lib": "topcoder-platform/tc-auth-lib#1.0.1"
9293
},

src/front/src/app/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ angular.module('topcoderX', [
77
'ngAnimate',
88
'ngCookies',
99
'ngTouch',
10+
'ui.select',
1011
'ngSanitize',
1112
'ngResource',
1213
'ui.router',

src/front/src/app/projects/project.service.js

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -142,48 +142,25 @@ angular.module('topcoderX')
142142

143143
/**
144144
* Get associated connect projects that the current user has access to
145+
* @param perPage the items to retrieve per page
146+
* @param page the page index
145147
*/
146-
ProjectService.getConnectProjects = function() {
147-
function createProjectRequest(pagingParams) {
148-
return $http({
149-
method: 'GET',
150-
url: $rootScope.appConfig.TC_API_V5_URL + '/projects/',
151-
headers: {
152-
"Content-Type": "application/json",
153-
"Authorization": "Bearer " + AuthService.AuthService.getTokenV3()
154-
},
155-
params: {
156-
fields: 'id,name,status',
157-
sort: 'lastActivityAt desc',
158-
perPage: pagingParams.perPage,
159-
page: pagingParams.page
160-
}
161-
});
162-
}
163-
164-
function getAll(getter, perPage, page, prev) {
165-
return getter({
148+
ProjectService.getConnectProjects = function(perPage, page) {
149+
return $http({
150+
method: 'GET',
151+
url: $rootScope.appConfig.TC_API_V5_URL + '/projects/',
152+
headers: {
153+
"Content-Type": "application/json",
154+
"Authorization": "Bearer " + AuthService.getTokenV3()
155+
},
156+
params: {
157+
fields: 'id,name,status',
158+
sort: 'lastActivityAt desc',
166159
perPage: perPage,
167160
page: page
168-
}).then(function (res) {
169-
if (res.status === 200) {
170-
var data = res.data;
171-
if (!data.length) return prev || [];
172-
var current = [];
173-
if (prev) {
174-
current = prev.concat(data);
175-
} else {
176-
current = data;
177-
}
178-
return getAll(getter, perPage, 1 + page, current);
179-
}
180-
return prev || [];
181-
});
182-
}
183-
return getAll(function (params) { return createProjectRequest(params) }, 20, 1).then(function(response) {
184-
return response;
161+
}
185162
});
186-
}
163+
};
187164

188165
return ProjectService;
189166
}]);

src/front/src/app/upsertproject/upsertproject.controller.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,28 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
4141

4242
$scope.isAdminUser = Helper.isAdminUser(currentUser);
4343
$scope.loadingConnectProjects = true;
44-
ProjectService.getConnectProjects().then(function (result) {
45-
$scope.loadingConnectProjects = false;
46-
$scope.connectProjects = result.map(function (p) {
47-
return {
48-
label: 'ID: ' + p.id + ', NAME: ' + p.name + ', STATUS: ' + p.status,
49-
value: p.id
50-
}
44+
$scope.connectProjects = [];
45+
$scope.fetchConnectProjects = function($event) {
46+
if (!$event) {
47+
$scope.page = 1;
48+
$scope.connectProjects = [];
49+
} else {
50+
$event.stopPropagation();
51+
$event.preventDefault();
52+
$scope.page++;
53+
}
54+
if ($scope.page === 500) {
55+
$scope.loadingConnectProjects = false;
56+
return;
57+
}
58+
$scope.loadingConnectProjects = true;
59+
ProjectService.getConnectProjects(20, $scope.page).then(function(resp) {
60+
$scope.connectProjects = $scope.connectProjects.concat(resp.data);
61+
})['finally'](function() {
62+
$scope.loadingConnectProjects = false;
5163
});
52-
}).catch(function (error) {
53-
Alert.error(error.data.message, $scope);
54-
});
64+
};
65+
$scope.fetchConnectProjects();
5566

5667
// function to add labels to the current project.
5768
$scope.addLabels = function () {

src/front/src/app/upsertproject/upsertproject.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,21 @@ <h2>{{title}}</h2>
5656
<br />
5757
<br />
5858
<label class="form-label">Connect ID:</label>
59-
<select ng-options="option.value as option.label for option in connectProjects" ng-model="project.tcDirectId"
60-
class="form-control" ng-disabled="loadingConnectProjects" required>
61-
</select>
59+
<ui-select ng-model="project.tcDirectId" theme="bootstrap">
60+
<ui-select-match placeholder="Select...">
61+
{{$select.selected.id}}
62+
</ui-select-match>
63+
<ui-select-choices repeat="cp.id as cp in connectProjects | filter: $select.search">
64+
id: {{cp.id}}, name: {{cp.name}}, status: {{cp.status}}
65+
<div ng-if="$index == $select.items.length-1">
66+
<button
67+
class="btn btn-xs btn-success"
68+
style="width: 100%; margin-top: 5px;"
69+
ng-click="fetchConnectProjects($event);"
70+
ng-disabled="loadingConnectProjects">Load more...</button>
71+
</div>
72+
</ui-select-choices>
73+
</ui-select>
6274
<small class="form-hint">Select the Topcoder Connect Project ID of the project. The above list contains all Topcoder Connect Projects
6375
you have access to.</small>
6476
<span ng-show="projectForm.project.tcDirectId.$touched && projectForm.project.tcDirectId.$invalid">The

src/front/src/app/vendor.less

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,15 @@ multiselect .btn-default {
7575
overflow-x: visible;
7676
min-height: 0.01%;
7777
}
78+
79+
.ui-select-container {
80+
margin: 20px 0px 3px;
81+
82+
.ui-select-search {
83+
width: 100% !important;
84+
}
85+
}
86+
.ui-select-match.btn-default-focus {
87+
outline: 0;
88+
box-shadow: none;
89+
}

src/front/src/index.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
@import url("../../../node_modules/metismenu/dist/metisMenu.css");
44
@import url("../../../node_modules/footable/css/footable.core.css");
5-
@import url("../../../node_modules/angularjs-datepicker/dist/angular-datepicker.min.css");
5+
@import url("../../../node_modules/angularjs-datepicker/dist/angular-datepicker.min.css");
6+
@import url("../../../node_modules/ui-select/dist/select.min.css");

src/front/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ require('pace-js');
3030
require('footable');
3131
require('jquery-ui-dist/jquery-ui');
3232
require('angularjs-datepicker');
33+
require('ui-select');
3334
window.shortid = require('shortid')

0 commit comments

Comments
 (0)