Skip to content

Commit 05994c2

Browse files
committed
feat: use v5 endpoint for tags
1 parent a309c8d commit 05994c2

File tree

6 files changed

+113
-77
lines changed

6 files changed

+113
-77
lines changed

src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ module.exports.frontendConfigs = {
9494
TOPCODER_VALUES: {
9595
dev: {
9696
TC_API_V4_URL: process.env.TC_API_V4_URL || 'https://api.topcoder-dev.com/v4',
97+
TC_API_V5_URL: process.env.TC_API_V5_URL || 'https://api.topcoder-dev.com/v5',
9798
},
9899
prod: {
99100
TC_API_V4_URL: process.env.TC_API_V4_URL || 'https://api.topcoder.com/v4',
101+
TC_API_V5_URL: process.env.TC_API_V5_URL || 'https://api.topcoder.com/v5',
100102
},
101103
},
102104
TOPCODER_ENV: process.env.TOPCODER_ENV || 'dev',

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* This is a service to access the backend api.
55
*/
6-
'use strict';
6+
77

88
angular.module('topcoderX')
99
.factory('ProjectService', ['Helper', '$http', '$rootScope', 'AuthService', function (Helper, $http, $rootScope, AuthService) {
@@ -17,17 +17,15 @@ angular.module('topcoderX')
1717
* @param project the project to be created
1818
*/
1919
ProjectService.create = function (project) {
20-
return $http.post(Helper.baseUrl + '/api/v1/projects', project).then(function (response) {
21-
return response;
22-
});
20+
return $http.post(Helper.baseUrl + '/api/v1/projects', project);
2321
};
2422

2523
/**
2624
* Get projects
2725
*/
2826
ProjectService.getProjects = function (status, showAll, perPage, lastKey, query) {
2927
var url = Helper.baseUrl + '/api/v1/projects?status=' + status + '&showAll=' + showAll + '&perPage=' + perPage +
30-
(lastKey ? '&lastKey=' + lastKey : '' );
28+
(lastKey ? '&lastKey=' + lastKey : '');
3129
if (query) {
3230
url = Helper.baseUrl + '/api/v1/projects/search?status=' + status + '&showAll=' + showAll + '&perPage=' + perPage +
3331
'&query=' + query;
@@ -63,7 +61,7 @@ angular.module('topcoderX')
6361
ProjectService.getUserToken = function (username, tokenType) {
6462
return $http.get(Helper.baseUrl + '/api/v1/users/accessToken?username=' + username + '&tokenType=' + tokenType).then(function (response) {
6563
return response;
66-
})
64+
});
6765
};
6866

6967
/**
@@ -145,52 +143,57 @@ angular.module('topcoderX')
145143
* @param perPage the items to retrieve per page
146144
* @param page the page index
147145
*/
148-
ProjectService.getConnectProjects = function(perPage, page) {
146+
ProjectService.getConnectProjects = function (perPage, page) {
149147
return $http({
150148
method: 'GET',
151149
url: $rootScope.appConfig.TC_API_V5_URL + '/projects/',
152150
headers: {
153-
"Content-Type": "application/json",
154-
"Authorization": "Bearer " + AuthService.getTokenV3()
151+
'Content-Type': 'application/json',
152+
Authorization: 'Bearer ' + AuthService.getTokenV3(),
155153
},
156154
params: {
157155
fields: 'id,name',
158156
sort: 'lastActivityAt desc',
159-
perPage: perPage,
160-
page: page,
161-
status: 'active'
162-
}
157+
perPage,
158+
page,
159+
status: 'active',
160+
},
163161
});
164162
};
165163

166164
/**
167165
* Get connect project by id
168166
* @param id the id
169167
*/
170-
ProjectService.getConnectProject = function(id) {
168+
ProjectService.getConnectProject = function (id) {
171169
return $http({
172170
method: 'GET',
173171
url: $rootScope.appConfig.TC_API_V5_URL + '/projects/' + id,
174172
headers: {
175-
"Content-Type": "application/json",
176-
"Authorization": "Bearer " + AuthService.getTokenV3()
177-
}
173+
'Content-Type': 'application/json',
174+
Authorization: 'Bearer ' + AuthService.getTokenV3(),
175+
},
178176
});
179177
};
180178

181179
/**
182180
* Get technology tags
183181
*/
184-
ProjectService.getTags = function() {
182+
ProjectService.searchTags = function (searchQuery) {
183+
if (!searchQuery || searchQuery.length === 0) {
184+
return Promise.resolve({data: []});
185+
}
185186
return $http({
186187
method: 'GET',
187-
url: $rootScope.appConfig.TOPCODER_VALUES[$rootScope.appConfig.TOPCODER_ENV].TC_API_V4_URL + '/technologies',
188+
url: $rootScope.appConfig.TOPCODER_VALUES[$rootScope.appConfig.TOPCODER_ENV].TC_API_V5_URL + '/emsi-skills/skills/auto-complete',
189+
params: {
190+
term: searchQuery,
191+
},
188192
headers: {
189-
"Content-Type": "application/json",
190-
"Authorization": "Bearer " + AuthService.getTokenV3()
191-
}
193+
'Content-Type': 'application/json',
194+
Authorization: 'Bearer ' + AuthService.getTokenV3(),
195+
},
192196
});
193197
};
194-
195198
return ProjectService;
196199
}]);

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

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* This is the upsertproject controller.
55
*/
6-
'use strict';
6+
77

88
angular.module('topcoderX').controller('ProjectController', ['currentUser', '$scope', '$timeout', 'ProjectService',
99
'$rootScope', '$state', 'Alert', '$uibModal', 'Helper', 'Tutorial', '$window',
@@ -20,24 +20,28 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
2020
title: '',
2121
tcDirectId: '',
2222
repoUrl: '',
23+
tags: [],
2324
copilot: currentUser.roles.indexOf($rootScope.appConfig.copilotRole) > -1 ? currentUser.handle : '',
2425
rocketChatWebhook: null,
2526
rocketChatChannelName: null,
2627
archived: false,
27-
createCopilotPayments: false
28+
createCopilotPayments: false,
2829
};
2930
$scope.connectProjects = [];
3031
if ($rootScope.project) {
3132
$scope.title = 'Manage a Project';
3233
$scope.project = $rootScope.project;
33-
$scope.project.tags = !!$rootScope.project.tags ? $rootScope.project.tags.split(',') : [];
34+
// Switch from v4 tags to v5 tags
35+
if (angular.isString($scope.project.tags)) {
36+
$scope.project.tags = [];
37+
}
3438
$scope.project.repoUrl = $rootScope.project.repoUrls.join(',');
3539
$scope.editing = true;
3640
if ($rootScope.project.tcDirectId) {
3741
ProjectService.getConnectProject($rootScope.project.tcDirectId).then(function (resp) {
3842
var connectProject = {
3943
id: resp.data.id,
40-
name: resp.data.name
44+
name: resp.data.name,
4145
};
4246
$scope.connectProjects.unshift(connectProject);
4347
});
@@ -51,15 +55,14 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
5155
$scope.loadingConnectProjects = true;
5256

5357
$scope.tags = [];
54-
$scope.fetchTags = function() {
55-
ProjectService.getTags().then(function (resp) {
56-
const s = new Set(resp.data.result.content.map(function(tag) { return tag.name; }));
57-
$scope.tags = Array.from(s).sort();
58+
59+
$scope.searchTags = function (searchQuery) {
60+
ProjectService.searchTags(searchQuery).then(function (resp) {
61+
$scope.tags = resp.data;
5862
});
59-
}
60-
$scope.fetchTags();
63+
};
6164

62-
$scope.fetchConnectProjects = function($event) {
65+
$scope.fetchConnectProjects = function ($event) {
6366
if (!$event) {
6467
$scope.page = 1;
6568
$scope.connectProjects = [];
@@ -73,20 +76,20 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
7376
return;
7477
}
7578
$scope.loadingConnectProjects = true;
76-
ProjectService.getConnectProjects(20, $scope.page).then(function(resp) {
79+
ProjectService.getConnectProjects(20, $scope.page).then(function (resp) {
7780
var projects = resp.data.filter(function (p) {
7881
return $rootScope.project && $rootScope.project.tcDirectId ? p.id !== $rootScope.project.tcDirectId : true;
7982
});
8083
$scope.connectProjects = $scope.connectProjects.concat(projects);
81-
})['finally'](function() {
84+
}).finally(function () {
8285
$scope.loadingConnectProjects = false;
8386
});
8487
};
8588
$scope.fetchConnectProjects();
8689

8790
// function to add labels to the current project.
8891
$scope.addLabels = function () {
89-
ProjectService.createLabel({ projectId: $scope.project.id }).then(function () {
92+
ProjectService.createLabel({projectId: $scope.project.id}).then(function () {
9093
Alert.info('Label Added Successfully', $scope);
9194
}).catch(function (error) {
9295
Alert.error(error.data.message, $scope);
@@ -95,22 +98,20 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
9598

9699
// function to add hooks to the current project.
97100
$scope.addHooks = function () {
98-
ProjectService.createHooks({ projectId: $scope.project.id }).then(function (result) {
101+
ProjectService.createHooks({projectId: $scope.project.id}).then(function (result) {
99102
if (result && result.data.updated === true) {
100-
Alert.info('Existing Webhook Updated Successfully', $scope);
101-
}
102-
else {
103+
Alert.info('Existing Webhook Updated Successfully', $scope);
104+
} else {
103105
Alert.info('Webhook Added Successfully', $scope);
104106
}
105-
106107
}).catch(function (error) {
107108
Alert.error(error.data.message, $scope);
108109
});
109110
};
110111

111112
// function to add wiki rules to the current project
112113
$scope.addWikiRules = function () {
113-
ProjectService.addWikiRules({ projectId: $scope.project.id }).then(function () {
114+
ProjectService.addWikiRules({projectId: $scope.project.id}).then(function () {
114115
Alert.info('Wiki Rules Added Successfully', $scope);
115116
}).catch(function (error) {
116117
Alert.error(error.data.message, $scope);
@@ -128,30 +129,27 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
128129
if (project.copilot === '') {
129130
project.copilot = null;
130131
}
131-
// project.repoUrls = project.repoUrl.split(',');
132-
const _project = Object.assign({}, project);
133-
delete _project.repoUrls;
134132
if ($scope.editing) {
135133
ProjectService.update(project).then(function () {
136134
Alert.info('Project Updated Successfully', $scope);
137-
setTimeout(function() {
135+
setTimeout(function () {
138136
$state.go('app.projects');
139137
}, 3000);
140138
}).catch(function (error) {
141139
Alert.error(error.data.message, $scope);
142-
setTimeout(function() {
140+
setTimeout(function () {
143141
$state.go('app.projects');
144142
}, 3000);
145143
});
146144
} else {
147145
ProjectService.create(project).then(function () {
148146
Alert.info('Project has been added successfully, and Topcoder X issue labels, webhook, and wiki rules have been added to the repository', $scope);
149-
setTimeout(function() {
147+
setTimeout(function () {
150148
$state.go('app.projects');
151149
}, 3000);
152150
}).catch(function (error) {
153151
Alert.error(error.data.message, $scope);
154-
setTimeout(function() {
152+
setTimeout(function () {
155153
$state.go('app.projects');
156154
}, 3000);
157155
});
@@ -164,13 +162,13 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
164162
templateUrl: 'app/upsertproject/recreate-dialog.html',
165163
controller: 'RecreateDialogController',
166164
resolve: {
167-
currentUser: function () {
165+
currentUser() {
168166
return currentUser;
169167
},
170-
appConfig: function () {
168+
appConfig() {
171169
return $rootScope.appConfig;
172170
},
173-
project: function () {
171+
project() {
174172
return $scope.project;
175173
},
176174
},
@@ -183,27 +181,26 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
183181
templateUrl: 'app/upsertproject/transfer-ownership-dialog.html',
184182
controller: 'TransferOwnershipDialogController',
185183
resolve: {
186-
currentUser: function () {
184+
currentUser() {
187185
return currentUser;
188186
},
189-
appConfig: function () {
187+
appConfig() {
190188
return $rootScope.appConfig;
191189
},
192-
project: function () {
190+
project() {
193191
return $scope.project;
194192
},
195193
},
196194
});
197195
};
198196

199197
if (tutorial) {
200-
setTimeout(function() {
201-
var dialog = {
202-
message: 'Add your first project. Fill the project name, Direct ID, Repo URL of your Gitlab/Github Repository and the copilot.',
203-
action: 'close'
204-
};
205-
Tutorial.show(dialog, $scope);
206-
}, 2500);
198+
setTimeout(function () {
199+
var dialog = {
200+
message: 'Add your first project. Fill the project name, Direct ID, Repo URL of your Gitlab/Github Repository and the copilot.',
201+
action: 'close',
202+
};
203+
Tutorial.show(dialog, $scope);
204+
}, 2500);
207205
}
208-
209206
}]);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ <h2>{{title}}</h2>
7878
<br />
7979
<br />
8080
<label class="form-label">Tags:</label>
81-
<ui-select multiple ng-model="project.tags" theme="bootstrap" close-on-select="false" on-select="$select.selected.sort()">
81+
<ui-select multiple ng-model="project.tags" theme="bootstrap" close-on-select="false">
8282
<ui-select-match placeholder="Select...">
83-
{{$item}}
83+
{{$item.name}}
8484
</ui-select-match>
85-
<ui-select-choices repeat="tag in tags | filter: $select.search">
86-
{{tag}}
85+
<ui-select-choices repeat="tag in tags"
86+
refresh="searchTags($select.search)"
87+
refresh-delay="0">
88+
{{tag.name}}
8789
</ui-select-choices>
8890
</ui-select>
8991
<small class="form-hint">Select the Tags to be associated with.</small>

src/models/Project.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,36 @@ const schema = new Schema({
2222
title: {type: String, required: true},
2323
tcDirectId: {
2424
type: Number,
25-
required: true
25+
required: true,
2626
},
2727
tags: {
28-
type: String,
28+
type: 'list',
29+
list: [{
30+
type: 'map',
31+
map: {
32+
id: {type: String, required: true},
33+
name: {type: String, required: true},
34+
},
35+
}],
2936
required: true,
30-
default: ''
37+
default: [],
38+
fromDynamo(value) {
39+
if (value.S) {
40+
return value.S;
41+
}
42+
if (value.L) {
43+
return value.L.map((item) => {
44+
if (item.M && item.M.name && item.M.id) {
45+
return {
46+
id: item.M.id.S,
47+
name: item.M.name.S,
48+
};
49+
}
50+
return null;
51+
});
52+
}
53+
return [];
54+
},
3155
},
3256
rocketChatWebhook: {type: String, required: false},
3357
rocketChatChannelName: {type: String, required: false},
@@ -40,7 +64,7 @@ const schema = new Schema({
4064
default: Date.now,
4165
},
4266
createCopilotPayments: {type: String, required: false},
43-
isConnect: {type: Boolean, required: false, default: true}
67+
isConnect: {type: Boolean, required: false, default: true},
4468
});
4569

4670
module.exports = schema;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy