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

Commit 98d8ee6

Browse files
committed
Topcoder-X - November 2019 Release Challenge
#269 (major requirement) #268 #267 #266 (major requirement) #265 (major requirement) #264 #211 #209 (major requirement)
1 parent b83b791 commit 98d8ee6

12 files changed

+106
-25
lines changed

.DS_Store

0 Bytes
Binary file not shown.

TopcoderXDeploy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Once you have registered your account, go into `Project Management` and add a ne
159159

160160
Use Topcoder Direct ID `7377` since this has a valid billing account in the dev environment.
161161

162-
Once it's been added, click `Edit` for the project in the list on `Project Management` and click `Add Webhooks`. Once the webhook has been added, you should be able to see it in the Gitlab project under `Settings` --> `Integrations` --> `Webhooks`
162+
Once it's been added, click `Manage` for the project in the list on `Project Management` and click `Add Webhooks`. Once the webhook has been added, you should be able to see it in the Gitlab project under `Settings` --> `Integrations` --> `Webhooks`
163163

164164
To test the webhook, create a new issue in the project with a title like `[$1] This is a test issue`
165165

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"angular-storage": "~0.0.11",
3636
"angular-touch": "~1.7.4",
3737
"angular-ui-bootstrap": "~2.5.0",
38-
"angular-ui-router": "~0.2.13",
38+
"angular-ui-router": "~1.0.23",
3939
"auth0-angular": "~4.0.4",
4040
"auth0-js": "^9.11.3",
4141
"auth0-lock": "^11.17.2",

src/common/db-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const logger = require('./logger');
1717
*/
1818
async function getById(model, id) {
1919
return await new Promise((resolve, reject) => {
20-
model.query('id').eq(id).exec((err, result) => {
20+
model.query('id').eq(id).consistent().all().exec((err, result) => {
2121
if (err) {
2222
logger.error(`DynamoDB getById error ${err}`);
2323
reject(err);
@@ -88,7 +88,7 @@ async function queryOneIssue(model, repositoryId, number, provider) {
8888
*/
8989
async function scanOne(model, scanParams) {
9090
return await new Promise((resolve, reject) => {
91-
model.scan(scanParams).exec((err, result) => {
91+
model.scan(scanParams).consistent().all().exec((err, result) => {
9292
if (err) {
9393
logger.error(`DynamoDB scanOne error ${err}`);
9494
reject(err);

src/front/src/app/main/issue.service.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@ angular.module('topcoderX')
99
.factory('IssueService', ['$http', 'Helper', function ($http, Helper) {
1010
var baseUrl = Helper.baseUrl;
1111
var service = {};
12+
var issuesDataPromise = {};
13+
var issuesGetLock = {};
1214

1315
/**
1416
* search for issues
1517
*/
1618
service.search = function (label, sortBy, sortDir, pageNo, pageSize) {
17-
return $http.get(baseUrl + '/api/v1/issues?label=' + label + '&sortBy=' + sortBy + '&sortDir=' + sortDir + '&page=' + pageNo + '&perPage=' + pageSize).then(function (response) {
19+
var url = baseUrl + '/api/v1/issues?label=' + label + '&sortBy=' + sortBy + '&sortDir=' + sortDir + '&page=' + pageNo + '&perPage=' + pageSize;
20+
21+
if (issuesGetLock[url]) {
22+
return issuesDataPromise[url];
23+
}
24+
25+
issuesGetLock[url] = true;
26+
issuesDataPromise[url] = $http.get(url).then(function (response) {
27+
issuesGetLock[url] = false;
1828
return response;
1929
});
30+
return issuesDataPromise[url];
2031
};
2132

2233
/**

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ angular.module('topcoderX')
99
.factory('ProjectService', ['Helper', '$http', function (Helper, $http) {
1010
// object we will return
1111
var ProjectService = {};
12+
var projectsDataPromise = {};
13+
var projectsGetLock = {};
14+
1215
/**
1316
* Create a project
1417
* @param project the project to be created
@@ -23,9 +26,17 @@ angular.module('topcoderX')
2326
* Get all projects
2427
*/
2528
ProjectService.getProjects = function (status, showAll) {
26-
return $http.get(Helper.baseUrl + '/api/v1/projects?status=' + status + '&showAll=' + showAll).then(function (response) {
29+
var url = Helper.baseUrl + '/api/v1/projects?status=' + status + '&showAll=' + showAll;
30+
if (projectsGetLock[url]) {
31+
return projectsDataPromise[url];
32+
}
33+
34+
projectsGetLock[url] = true;
35+
projectsDataPromise[url] = $http.get(url).then(function (response) {
36+
projectsGetLock[url] = false;
2737
return response;
2838
});
39+
return projectsDataPromise[url];
2940
};
3041

3142
/**

src/front/src/app/projects/projects.controller.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ angular.module('topcoderX')
5252
ProjectService.getProjects(status, $scope.filter.showAll).then(function (response) {
5353
$scope.isLoaded = true;
5454
$scope.projects = response.data;
55+
$scope.allProjects = angular.copy($scope.projects);
5556
$timeout(function () {
5657
$scope.init();
5758
}, 1000);
@@ -78,4 +79,32 @@ angular.module('topcoderX')
7879
$scope.filter.showAll = !$scope.filter.showAll;
7980
$scope.getProjects($scope.state.status);
8081
};
81-
}]);
82+
83+
84+
$scope.onSearchChange = function (obj) {
85+
$scope.searchText = obj.searchText;
86+
if (!obj.searchText || obj.searchText.length === 0) {
87+
$scope.getProjects($scope.state.status);
88+
}
89+
90+
if ($scope.allProjects.length > 0) {
91+
_searchLocal(obj.searchText);
92+
}
93+
};
94+
95+
$scope.onSearchIconClicked = function () {
96+
if ($scope.allProjects.length > 0 && $scope.searchText) {
97+
_searchLocal($scope.searchText);
98+
}
99+
};
100+
101+
function _searchLocal(query) {
102+
$scope.projects = $scope.allProjects.filter(function(value) {
103+
return value['title'].toLowerCase().includes(query.toLowerCase());
104+
})
105+
$timeout(function () {
106+
$('.footable').filter('[data-page="0"]').trigger('click');
107+
}, 1000);
108+
}
109+
110+
}]);

src/front/src/app/projects/projects.html

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ <h2>{{title}}</h2>
3030
<uib-tab index="0" heading="Current Projects" select="getProjects('active')">
3131
<br />
3232
<div ng-if="isLoaded">
33-
<div ng-show="projects.length===0">
33+
<div ng-show="allProjects.length===0">
3434
<div class="text-center m-t-lg">
3535
<h4>You don't have active projects right now. Please
3636
<button class="btn btn-sm btn-info" ng-click="goProject()">
@@ -41,7 +41,17 @@ <h4>You don't have active projects right now. Please
4141
</h4>
4242
</div>
4343
</div>
44-
<div ng-hide="projects.length===0">
44+
<div ng-hide="allProjects.length===0">
45+
<div class="col-lg-4" style="padding-left: 0px">
46+
<div class="input-group custom-search-form">
47+
<input ng-model="searchText" type="text" class="form-control" placeholder="Find projects" ng-change="onSearchChange(this)">
48+
<span class="input-group-btn">
49+
<button class="btn btn-default" type="button" ng-click="onSearchIconClicked('github')">
50+
<span class="glyphicon glyphicon-search"></span>
51+
</button>
52+
</span>
53+
</div>
54+
</div>
4555
<table class="footable table table-stripped toggle-arrow-tiny"
4656
data-page-navigation=".pagination" data-page-size="10">
4757
<thead>
@@ -68,12 +78,12 @@ <h4>You don't have active projects right now. Please
6878
<td class="col-lg-2" ng-show="isAdminUser">{{project.owner}}</td>
6979
<td class="col-lg-2">
7080
<button class="btn btn-sm btn-success" ng-click="goProject(project)">
71-
<strong>Edit</strong>
81+
<strong>Manage</strong>
7282
</button>
7383
</td>
7484
</tr>
7585
</tbody>
76-
<tfoot>
86+
<tfoot ng-hide="searchText">
7787
<tr>
7888
<td colspan="{{isAdminUser? 5: 4}}">
7989
<ul class="pagination pull-right"></ul>
@@ -87,10 +97,20 @@ <h4>You don't have active projects right now. Please
8797
<uib-tab index="1" heading="Archived Projects" select="getProjects('archived')">
8898
<br />
8999
<div ng-if="isLoaded">
90-
<div ng-show="projects.length===0" class="text-center m-t-lg">
100+
<div ng-show="allProjects.length===0" class="text-center m-t-lg">
91101
<p>No projects have been archived.</p>
92102
</div>
93-
<div ng-hide="projects.length===0">
103+
<div ng-hide="allProjects.length===0">
104+
<div class="col-lg-4" style="padding-left: 0px">
105+
<div class="input-group custom-search-form">
106+
<input ng-model="searchText" type="text" class="form-control" placeholder="Find projects" ng-change="onSearchChange(this)">
107+
<span class="input-group-btn">
108+
<button class="btn btn-default" type="button" ng-click="onSearchIconClicked()">
109+
<span class="glyphicon glyphicon-search"></span>
110+
</button>
111+
</span>
112+
</div>
113+
</div>
94114
<table class="footable table table-stripped toggle-arrow-tiny"
95115
data-page-size="10">
96116
<thead>
@@ -112,12 +132,12 @@ <h4>You don't have active projects right now. Please
112132
<td class="col-lg-2" ng-show="isAdminUser">{{archivedProject.owner}}</td>
113133
<td class="col-lg-2">
114134
<button class="btn btn-sm btn-success" ng-click="goProject(archivedProject)">
115-
<strong>Edit</strong>
135+
<strong>Manage</strong>
116136
</button>
117137
</td>
118138
</tr>
119139
</tbody>
120-
<tfoot>
140+
<tfoot ng-hide="searchText">
121141
<tr>
122142
<td colspan="{{isAdminUser? 5: 4}}">
123143
<ul class="pagination pull-right"></ul>

src/front/src/app/upsertissue/upsertissue.controller.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
'use strict';
77

88
angular.module('topcoderX').controller('IssueController', ['currentUser', '$scope', '$timeout', 'ProjectService', 'IssueService',
9-
'$rootScope', '$state', 'Alert',
9+
'$rootScope', '$state', 'Alert', '$log',
1010
function (currentUser, $scope, $timeout, ProjectService, IssueService, $rootScope, $state,
11-
Alert) {
11+
Alert, $log) {
1212
// Maintain the navigation state.
1313
$timeout(function () {
1414
angular.element('#projectsManagement').addClass('active');
1515
}, 0);
1616

1717
// get topcoderx projects
1818
$scope.getProjects = function () {
19+
$log.log('getProjects dipanggil cui... dari upsert');
20+
1921
ProjectService.getProjects('active', false).then(function (response) {
2022
$scope.projects = response.data;
2123
if ($scope.projects.length === 0) {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
2626
archived: false,
2727
};
2828
if ($rootScope.project) {
29-
$scope.title = 'Edit a Project';
29+
$scope.title = 'Manage a Project';
3030
$scope.project = $rootScope.project;
3131
$scope.project.id = $rootScope.project.id;
3232
$scope.project.copilot = $rootScope.project.copilot;
@@ -92,9 +92,14 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
9292
} else {
9393
ProjectService.create($scope.project).then(function () {
9494
Alert.info('Project has been added successfully, and Topcoder X issue labels, webhook, and wiki rules have been added to the repository', $scope);
95-
$state.go('app.projects');
95+
setTimeout(function() {
96+
$state.go('app.projects');
97+
}, 3000);
9698
}).catch(function (error) {
9799
Alert.error(error.data.message, $scope);
100+
setTimeout(function() {
101+
$state.go('app.projects');
102+
}, 3000);
98103
});
99104
}
100105
};

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h2>{{title}}</h2>
66
</div>
77

88
<div class="pull-right" ng-if="editing">
9-
<div class="pull-right col-lg-8" ng-if="editing">
9+
<div class="pull-right col-lg-12" ng-if="editing">
1010
<div class="pull-right col-lg-2" ng-if="!isAdminUser"></div>
1111
<div class="pull-right col-lg-2 with-button btn-top" ng-if="isAdminUser">
1212
<button class="btn btn-sm btn-info btn-top" ng-click="openTransferOwnershipDialog()">
@@ -20,8 +20,6 @@ <h2>{{title}}</h2>
2020
<strong>Recreate an Issue</strong>
2121
</button>
2222
</div>
23-
</div>
24-
<div class="pull-right col-lg-8" ng-if="editing">
2523
<div class="pull-right col-lg-2 with-button btn-top">
2624
<button class="btn btn-sm btn-info btn-top" ng-click="addWikiRules()">
2725
<strong>

src/services/ProjectService.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,14 @@ async function create(project, currentUser) {
127127

128128
const createdProject = await dbHelper.create(models.Project, project);
129129

130-
await createLabel({projectId: project.id}, currentUser);
131-
await createHook({projectId: project.id}, currentUser);
132-
await addWikiRules({projectId: project.id}, currentUser);
130+
try {
131+
await createLabel({projectId: project.id}, currentUser);
132+
await createHook({projectId: project.id}, currentUser);
133+
await addWikiRules({projectId: project.id}, currentUser);
134+
}
135+
catch (err) {
136+
throw new Error('Project created. Adding the webhook, issue labels, and wiki rules failed.');
137+
}
133138

134139
return createdProject;
135140
}

0 commit comments

Comments
 (0)