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

Commit 8368b32

Browse files
committed
Drop down selector for Connect project instead of text field
#443
1 parent 0f49c5c commit 8368b32

File tree

6 files changed

+65
-5
lines changed

6 files changed

+65
-5
lines changed

.DS_Store

0 Bytes
Binary file not shown.

configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The following config parameters are supported, they are defined in `src/config.j
3535
|AWS_CONNECTION_TIMEOUT | The timeout used to check if the app is healthy. |10000 |
3636
|TC_LOGIN_URL | TC login url | |
3737
|DYNAMODB_WAIT_TABLE_FOR_ACTIVE_TIMEOUT | Dynamodb wait for active timeout |10 minutes |
38+
|TC_API_V5_URL | Topcoder API v5 url for retrieving list of Connect Projects | |
3839

3940

4041
## GitHub OAuth App Setup

src/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ module.exports.frontendConfigs = {
8383
TOPCODER_URL: process.env.TOPCODER_URL || 'https://topcoder-dev.com',
8484
GITHUB_TEAM_URL: process.env.GITHUB_TEAM_URL || 'https://github.com/orgs/',
8585
GITLAB_GROUP_URL: process.env.GITLAB_GROUP_URL || 'https://gitlab.com/groups/',
86+
TC_API_V5_URL: process.env.TC_API_V5_URL || 'https://api.topcoder-dev.com/v5',
8687
};

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

+46-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
angular.module('topcoderX')
9-
.factory('ProjectService', ['Helper', '$http', function (Helper, $http) {
9+
.factory('ProjectService', ['Helper', '$http', '$rootScope', 'AuthService', function (Helper, $http, $rootScope, AuthService) {
1010
// object we will return
1111
var ProjectService = {};
1212
var projectsDataPromise = {};
@@ -140,5 +140,50 @@ angular.module('topcoderX')
140140
});
141141
};
142142

143+
/**
144+
* Get associated connect projects that the current user has access to
145+
*/
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({
166+
perPage: perPage,
167+
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;
185+
});
186+
}
187+
143188
return ProjectService;
144189
}]);

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

+12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
4040
}
4141

4242
$scope.isAdminUser = Helper.isAdminUser(currentUser);
43+
$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+
}
51+
});
52+
}).catch(function (error) {
53+
Alert.error(error.data.message, $scope);
54+
});
4355

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

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ <h2>{{title}}</h2>
5656
<br />
5757
<br />
5858
<label class="form-label">Connect ID:</label>
59-
<input class="form-control" type="number" ng-model="project.tcDirectId" required />
60-
<small class="form-hint">The Topcoder Connect Project ID of the project. You can obtain this through the URL to the
61-
project in Topcoder Connect. For example:
62-
"https://connect.topcoder.com/projects/16598" - Enter ID "16598"</small>
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>
62+
<small class="form-hint">Select the Topcoder Connect Project ID of the project. The above list contains all Topcoder Connect Projects
63+
you have access to.</small>
6364
<span ng-show="projectForm.project.tcDirectId.$touched && projectForm.project.tcDirectId.$invalid">The
6465
TC Connect Project ID is required.</span>
6566
<br />

0 commit comments

Comments
 (0)