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

Commit bfdab7e

Browse files
committed
October release challenge 2
#89 (major requirement) #88 (major requirement) #87 (major requirement) #86 (major requirement) #83 #82 #74 #71 #35 (major requirement) #79 (major requirement) #76
1 parent d366ae6 commit bfdab7e

13 files changed

+540
-375
lines changed

src/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ module.exports = {
3535
},
3636
HOOK_BASE_URL: process.env.HOOK_BASE_URL || 'http://topcoderx.topcoder-dev.com',
3737
TOPCODER_ENV: process.env.TOPCODER_ENV || 'dev',
38-
LABELS: process.env.LABELS || [{ name: 'tcx_OpenForPickup', color: '428BCA' }, { name: 'tcx_Assigned', color: '004E00' }, { name: 'tcx_ReadyForReview', color: 'D1D100' }, { name: 'tcx_Paid', color: '7F8C8D' }, { name: 'tcx_Feedback', color: 'FF0000' }, { name: 'tcx_FixAccepted', color: '69D100' }],
38+
LABELS: process.env.LABELS || [{ name: 'tcx_OpenForPickup', color: '428BCA' }, { name: 'tcx_Assigned', color: '004E00' }, { name: 'tcx_ReadyForReview', color: 'D1D100' }, { name: 'tcx_Paid', color: '7F8C8D' }, { name: 'tcx_Feedback', color: 'FF0000' }, { name: 'tcx_FixAccepted', color: '69D100' },
39+
{name:'Not Ready', color: '000000'}],
3940
ALLOWED_TOPCODER_ROLES: process.env.ALLOWED_TOPCODER_ROLES || ['administrator', 'admin', 'connect manager', 'connect admin', 'copilot', 'connect copilot'],
4041
COPILOT_ROLE: process.env.COPILOT_ROLE || 'copilot',
4142
HELP_LINK: process.env.HELP_LINK || 'https://github.com/topcoder-platform/topcoder-x-ui/wiki',

src/controllers/CopilotPaymentController.js

+4-15
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,13 @@ async function updateAll(req) {
2222
}
2323

2424
/**
25-
* get all the payment for the current copilot
25+
* searches the payment according to criteria for the current copilot
2626
* @param {Object} req the request
2727
* @param {Object} res the response
2828
* @returns {Object} the result
2929
*/
30-
async function getAll(req) {
31-
const payments = await CopilotPaymentService.getAll(req.query, req.currentUser);
32-
const active = [];
33-
const closed = [];
34-
35-
payments.forEach(function (payment) {
36-
if (payment.closed === true) {
37-
closed.push(payment);
38-
} else {
39-
active.push(payment);
40-
}
41-
});
42-
return { activePayments: active, closedPayments: closed };
30+
async function search(req) {
31+
return await CopilotPaymentService.search(req.query, req.currentUser);
4332
}
4433

4534
/**
@@ -74,7 +63,7 @@ async function remove(req) {
7463

7564

7665
module.exports = {
77-
getAll,
66+
search,
7867
create,
7968
update,
8069
remove,

src/front/src/app/add-copilot-payment/add-copilot-payment-controller.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ angular.module('topcoderX')
2424

2525
// get topcoderx projects
2626
$scope.getProjects = function () {
27-
ProjectService.getProjects().then(function (response) {
27+
ProjectService.getProjects('active', true).then(function (response) {
2828
$scope.projects = response.data;
2929
}).catch(function (error) {
3030
_handleError(error, 'There are no projects in Topcoder-X. Please create a project first.');
@@ -61,6 +61,6 @@ angular.module('topcoderX')
6161
_handleError(error, 'An error occurred while updating Payment.');
6262
});
6363
}
64-
};
64+
};
6565
}
6666
]);

src/front/src/app/add-copilot-payment/add-copilot-payment.html

+9-10
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ <h2>{{title}}</h2>
1515
<select ng-model="payment.project" class="form-control" required>
1616
<option ng-repeat="project in projects" value={{project.id}}>{{project.title}}</option>
1717
</select>
18-
<span ng-show="paymentForm.payment.project.$touched && paymentForm.payment.project.$invalid">The payment Project is required.</span>
18+
<span ng-show="paymentForm.payment.project.$touched && paymentForm.payment.project.$invalid">The
19+
payment Project is required.</span>
1920
<br />
2021
<label class="form-label">Amount:</label>
21-
<input class="form-control" type="number" ng-model="payment.amount" required/>
22-
<span ng-show="paymentForm.payment.amount.$touched && paymentForm.payment.amount.$invalid">The payment Amount is required.</span>
22+
<input class="form-control" type="number" ng-model="payment.amount" required />
23+
<span ng-show="paymentForm.payment.amount.$touched && paymentForm.payment.amount.$invalid">The
24+
payment Amount is required.</span>
2325
<br />
2426
<label class="form-label">Description:</label>
25-
<input class="form-control" type="text" ng-model="payment.description" required/>
26-
<span ng-show="paymentForm.payment.description.$touched && paymentForm.payment.description.$invalid">The payment Description is required.</span>
27+
<input class="form-control" type="text" ng-model="payment.description" required />
28+
<span ng-show="paymentForm.payment.description.$touched && paymentForm.payment.description.$invalid">The
29+
payment Description is required.</span>
2730
<br />
2831
<br />
2932
<button type="submit" class="with-button btn btn-sm btn-info" ng-click="paymentForm.$valid && save()">
@@ -36,8 +39,4 @@ <h2>{{title}}</h2>
3639
</div>
3740
</div>
3841
</div>
39-
</div>
40-
41-
42-
43-
42+
</div>

src/front/src/app/copilot-payments/copilot-payment.service.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ angular.module('topcoderX')
2121
};
2222

2323
/**
24-
* get copilot payment items
25-
*
24+
* searches copilot payment items
25+
* @param {String} status the status
26+
* @param {String} sortBy the sort by
27+
* @param {String} sortDir the sort direction
28+
* @param {Number} pageNo the page number
29+
* @param {Number} pageSize the page size
2630
*/
27-
service.getAll = function (query) {
28-
return $http.get(baseUrl + '/api/v1/payments/copilot?sortBy=' + query).then(function (response) {
29-
return response;
30-
});
31+
service.search = function (status, sortBy, sortDir, pageNo, pageSize) {
32+
return $http.get(baseUrl + '/api/v1/payments/copilot?status=' + status + '&sortBy=' + sortBy + '&sortDir=' + sortDir + '&page=' + pageNo + '&perPage=' + pageSize)
33+
.then(function (response) {
34+
return response;
35+
});
3136
};
3237

3338
/**

src/front/src/app/copilot-payments/copilot-payments-controller.js

+112-37
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,33 @@ angular.module('topcoderX')
44
.controller('CopilotPaymentsController', ['$scope', '$rootScope', '$state', 'CopilotPaymentService', '$filter', 'Alert', 'Dialog', '$log', '$timeout',
55
function ($scope, $rootScope, $state, CopilotPaymentService, $filter, Alert, Dialog, $log, $timeout) {
66
$scope.title = 'Copilot payment page';
7-
$scope.payments = [];
8-
$scope.isLoaded = false;
97
$scope.totalPendingAmounts = 0;
108
$scope.topcoderUrl = '';
119
$scope.status = '';
10+
11+
$scope.tableConfig = {
12+
active: {
13+
pageNumber: 1,
14+
pageSize: 20,
15+
isLoading: false,
16+
sortBy: 'project',
17+
sortDir: 'desc',
18+
totalPages: 1,
19+
initialized: false,
20+
closed: false,
21+
},
22+
inactive: {
23+
pageNumber: 1,
24+
pageSize: 20,
25+
isLoading: false,
26+
sortBy: 'project',
27+
sortDir: 'desc',
28+
totalPages: 1,
29+
initialized: false,
30+
closed: true,
31+
},
32+
};
33+
1234
$scope.goPayment = function (payment) {
1335
if (payment) {
1436
$rootScope.payment = payment;
@@ -28,27 +50,31 @@ angular.module('topcoderX')
2850
});
2951
};
3052

31-
$scope.getPayments = function (status) {
32-
$scope.isLoaded = false;
33-
CopilotPaymentService.getAll('project').then(function (res) {
34-
if (status === 'active') {
35-
$scope.payments = res.data.activePayments;
36-
$scope.totalPendingAmounts = 0;
37-
for (var i = 0; i < $scope.payments.length; i++) {
38-
$scope.totalPendingAmounts += $scope.payments[i].amount;
53+
/**
54+
* gets the payment
55+
* @param {String} provider the provider
56+
*/
57+
$scope.getPayments = function (provider) {
58+
$scope.totalPendingAmounts = 0;
59+
$scope.status = provider;
60+
var config = $scope.tableConfig[provider];
61+
config.isLoading = true;
62+
CopilotPaymentService.search(config.closed, config.sortBy, config.sortDir, config.pageNumber, config.pageSize)
63+
.then(function (res) {
64+
if (provider === 'active') {
65+
for (var i = 0; i < res.data.docs.length; i++) {
66+
$scope.totalPendingAmounts += res.data.docs[i].amount;
67+
}
3968
}
40-
$scope.isLoaded = true;
41-
$scope.status = 'active';
42-
}
43-
if (status === 'closed') {
44-
$scope.payments = res.data.closedPayments;
45-
$scope.isLoaded = true;
46-
$scope.status = 'closed';
47-
}
48-
}).catch(function (err) {
49-
$scope.isLoaded = true;
50-
_handleError(err, 'Error getting payments.');
51-
});
69+
config.items = res.data.docs;
70+
config.pages = res.data.pages;
71+
config.initialized = true;
72+
config.isLoading = false;
73+
}).catch(function (err) {
74+
config.isLoading = false;
75+
config.initialized = true;
76+
_handleError(err, 'An error occurred while getting the data for ' + provider + '.');
77+
});
5278
};
5379

5480
$scope.getPayments('active');
@@ -90,19 +116,72 @@ angular.module('topcoderX')
90116
Dialog.show('Are you sure you want to delete this payment?', $scope);
91117
};
92118

93-
$scope.sort = function (criteria) {
94-
CopilotPaymentService.getAll(criteria).then(function (res) {
95-
if (status === 'active') {
96-
$scope.payments = res.data.activePayments;
97-
$scope.isLoaded = true;
98-
$scope.status = 'active';
119+
/**
120+
* handles the sort click
121+
* @param criteria the criteria
122+
* @param provider the provider
123+
*/
124+
$scope.sort = function (criteria, provider) {
125+
if (criteria === $scope.tableConfig[provider].sortBy) {
126+
if ($scope.tableConfig[provider].sortDir === 'asc') {
127+
$scope.tableConfig[provider].sortDir = 'desc';
128+
} else {
129+
$scope.tableConfig[provider].sortDir = 'asc';
99130
}
100-
if (status === 'closed') {
101-
$scope.payments = res.data.closedPayments;
102-
$scope.isLoaded = true;
103-
$scope.status = 'closed';
131+
} else {
132+
$scope.tableConfig[provider].sortDir = 'asc';
133+
}
134+
$scope.tableConfig[provider].sortBy = criteria;
135+
$scope.tableConfig[provider].pageNumber = 1;
136+
$scope.getPayments(provider);
137+
};
138+
139+
/**
140+
* handles the change page click
141+
* @param {Number} pageNumber the page number
142+
* @param {String} provider the selected provider
143+
*/
144+
$scope.changePage = function (pageNumber, provider) {
145+
if (pageNumber === 0 || pageNumber > $scope.tableConfig[provider].pages ||
146+
(pageNumber === $scope.tableConfig[provider].pages &&
147+
$scope.tableConfig[provider].pageNumber === pageNumber)) {
148+
return false;
149+
}
150+
$scope.tableConfig[provider].pageNumber = pageNumber;
151+
$scope.getPayments(provider);
152+
};
153+
154+
/**
155+
* handles the tab change click
156+
* @param {String} provider the selected provider
157+
*/
158+
$scope.tabChanged = function (provider) {
159+
$scope.tableConfig[provider].sortBy = 'project';
160+
$scope.tableConfig[provider].sortDir = 'desc';
161+
$scope.tableConfig[provider].pageNumber = 1;
162+
$scope.tableConfig[provider].initialized = false;
163+
$scope.getPayments(provider);
164+
};
165+
166+
/**
167+
* get the number array that shows the pagination bar
168+
* @param {String} provider the provider
169+
*/
170+
$scope.getPageArray = function (provider) {
171+
var res = [];
172+
173+
var pageNo = $scope.tableConfig[provider].pageNumber;
174+
var i = pageNo - 5;
175+
for (i; i <= pageNo; i++) {
176+
if (i > 0) {
177+
res.push(i);
104178
}
105-
});
179+
}
180+
var j = pageNo + 1;
181+
for (j; j <= $scope.tableConfig[provider].pages && j <= pageNo + 5; j++) {
182+
res.push(j);
183+
}
184+
return res;
106185
};
107186

108187
function onInit() {
@@ -115,9 +194,5 @@ angular.module('topcoderX')
115194
}
116195

117196
onInit();
118-
119-
$scope.init = function () {
120-
$('.footable').footable();
121-
};
122197
}
123198
]);

0 commit comments

Comments
 (0)