From 6d8ce5d38784fb2a063a4b3bee13816ac3170b2c Mon Sep 17 00:00:00 2001 From: anonymousjaggu <31332424+anonymousjaggu@users.noreply.github.com> Date: Sat, 31 Oct 2020 10:50:38 +0545 Subject: [PATCH] v5-challenge --- README.md | 2 + config.json | 10 +- src/app/app.js | 76 +++--- src/app/challenges/challenges.service.js | 227 +++++++++++++++++- src/app/users/users.service.js | 72 +++--- .../add-user-challenge.controller.js | 71 ++++++ src/app/v5_challenges/add-user-challenge.html | 42 ++++ .../challenge.detail.controller.js | 65 +++++ src/app/v5_challenges/challenge.detail.html | 36 +++ .../challenge.manage.user.controller.js | 137 +++++++++++ .../v5_challenges/challenge.manage.user.html | 100 ++++++++ .../challenges.list.controller.js | 123 ++++++++++ src/app/v5_challenges/challenges.list.html | 125 ++++++++++ src/components/common/navigation.html | 3 + 14 files changed, 1024 insertions(+), 65 deletions(-) create mode 100644 src/app/v5_challenges/add-user-challenge.controller.js create mode 100644 src/app/v5_challenges/add-user-challenge.html create mode 100644 src/app/v5_challenges/challenge.detail.controller.js create mode 100644 src/app/v5_challenges/challenge.detail.html create mode 100644 src/app/v5_challenges/challenge.manage.user.controller.js create mode 100644 src/app/v5_challenges/challenge.manage.user.html create mode 100644 src/app/v5_challenges/challenges.list.controller.js create mode 100644 src/app/v5_challenges/challenges.list.html diff --git a/README.md b/README.md index 7c49fbc..38b01d3 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ The following configuration parameters are available: | GROUP_V5_API_URL | URL of the v5 Groups API | | LOOKUP_V5_API_URL | URL of the v5 Devices API | | TERMS_V5_API_URL | URL of the v5 Terms API | +| CHALLENGES_V5_API_URL | URL of the v5 Challenges API | +| RESOURCE_V5_API_URL | URL of the v5 Resources API | | AGREEABILITY_TYPES | List of Agreeable types and its UUID from Database | | AGREE_FOR_DOCUSIGN_TEMPLATE | UUID from Database of the `"DocuSign Template"` Agreeable type | | AGREE_ELECTRONICALLY | UUID from Database of the `Electronically` Agreeable Type | diff --git a/config.json b/config.json index b427e74..87271fa 100644 --- a/config.json +++ b/config.json @@ -15,6 +15,8 @@ "GROUP_V5_API_URL": "http://localhost:3000/v5", "LOOKUP_V5_API_URL": "http://localhost:3000/v5", "TERMS_V5_API_URL": "http://localhost:3000/v5", + "CHALLENGES_V5_API_URL": "https://api.topcoder-dev.com/v5", + "RESOURCE_V5_API_URL": "https://api.topcoder-dev.com/v5", "AGREEABILITY_TYPES": [ { "id": "f3cb81fa-d1ed-4231-b6c6-770f4f1ce8a4", @@ -53,6 +55,8 @@ "GROUP_V5_API_URL": "https://api.topcoder-dev.com/v5", "LOOKUP_V5_API_URL": "https://api.topcoder-dev.com/v5", "TERMS_V5_API_URL": "https://api.topcoder-dev.com/v5", + "CHALLENGES_V5_API_URL": "https://api.topcoder-dev.com/v5", + "RESOURCE_V5_API_URL": "https://api.topcoder-dev.com/v5", "AGREEABILITY_TYPES": [ { "id": "f3cb81fa-d1ed-4231-b6c6-770f4f1ce8a4", @@ -91,6 +95,8 @@ "GROUP_V5_API_URL": "http://localhost:9000", "LOOKUP_V5_API_URL": "http://localhost:3000/v5", "TERMS_V5_API_URL": "http://localhost:3000/v5", + "CHALLENGES_V5_API_URL": "https://api.topcoder-dev.com/v5", + "RESOURCE_V5_API_URL": "https://api.topcoder-dev.com/v5", "AGREEABILITY_TYPES": [ { "id": "f3cb81fa-d1ed-4231-b6c6-770f4f1ce8a4", @@ -129,6 +135,8 @@ "GROUP_V5_API_URL": "https://api.topcoder.com/v5", "LOOKUP_V5_API_URL": "https://api.topcoder.com/v5", "TERMS_V5_API_URL": "https://api.topcoder.com/v5", + "CHALLENGES_V5_API_URL": "https://api.topcoder-dev.com/v5", + "RESOURCE_V5_API_URL": "https://api.topcoder-dev.com/v5", "AGREEABILITY_TYPES": [ { "id": "f3cb81fa-d1ed-4231-b6c6-770f4f1ce8a4", @@ -151,4 +159,4 @@ "AGREE_ELECTRONICALLY": "5b2798b2-ae82-4210-9b4d-5d6428125ccb", "DEFAULT_TERMS_TYPE_ID": 5 } -} +} \ No newline at end of file diff --git a/src/app/app.js b/src/app/app.js index 7a39271..25f2ad9 100755 --- a/src/app/app.js +++ b/src/app/app.js @@ -4,30 +4,30 @@ * support-admin-app */ angular.module('supportAdminApp', [ - 'ngAnimate', - 'ngCookies', - 'ngTouch', - 'ngSanitize', - 'ngResource', - 'csvReader', - 'ui.router', - 'ui.bootstrap', - 'app.constants', - 'angular-clipboard', - 'ng-file-model', - 'btorfs.multiselect', - 'ui.bootstrap.datetimepicker', - 'angularMoment', - 'angular-jwt', - 'ui.tinymce']) + 'ngAnimate', + 'ngCookies', + 'ngTouch', + 'ngSanitize', + 'ngResource', + 'csvReader', + 'ui.router', + 'ui.bootstrap', + 'app.constants', + 'angular-clipboard', + 'ng-file-model', + 'btorfs.multiselect', + 'ui.bootstrap.datetimepicker', + 'angularMoment', + 'angular-jwt', + 'ui.tinymce']) // In the run phase of your Angular application .run(function (AuthService) { // init AuthService, it has to be done once, when app starts AuthService.init(); }) .config(function ($stateProvider, $urlRouterProvider, $locationProvider, $compileProvider) { - var authenticate = ['AuthService', '$q', '$state', function(AuthService, $q, $state) { - return AuthService.authenticate().catch(function(err) { + var authenticate = ['AuthService', '$q', '$state', function (AuthService, $q, $state) { + return AuthService.authenticate().catch(function (err) { // if we get error that use doesn't have permissions // then go to auth page, which will show permissions denied error if (err === AuthService.ERROR.NO_PERMISSIONS) { @@ -43,9 +43,9 @@ angular.module('supportAdminApp', [ templateUrl: 'app/auth/auth.html', data: { pageTitle: 'Authentication' }, resolve: { - auth: ['AuthService', '$q', function(AuthService, $q) { + auth: ['AuthService', '$q', function (AuthService, $q) { // for auth state we use another resolver then all other states - return AuthService.authenticate().catch(function(err) { + return AuthService.authenticate().catch(function (err) { // if we get error that use doesn't have permissions // we still resolve the promise and proceed to auth page // which will show permissions denied error @@ -141,10 +141,10 @@ angular.module('supportAdminApp', [ value: 'develop', name: 'Develop' }, - { - value: 'design', - name: 'Design' - }]; + { + value: 'design', + name: 'Design' + }]; $scope.tagStatuses = [{ value: 'approved', @@ -154,14 +154,14 @@ angular.module('supportAdminApp', [ name: 'Pending' }]; - TagService.getTechnologyStatuses().then(function(techStatuses) { - _.forEach(techStatuses, function(status) { + TagService.getTechnologyStatuses().then(function (techStatuses) { + _.forEach(techStatuses, function (status) { status.value = _.lowerCase(status.description); status.name = status.description; }); $scope.techStatuses = techStatuses; }); - $scope.getTagStatuses = function(domainType) { + $scope.getTagStatuses = function (domainType) { if (domainType === 'technology') { return $scope.techStatuses; } else { @@ -415,7 +415,25 @@ angular.module('supportAdminApp', [ .state('index.challenges', { url: 'challenges', templateUrl: 'app/challenges/challenges.html', - data: { pageTitle: 'Challenge Management'}, + data: { pageTitle: 'Challenge Management' }, + resolve: { auth: authenticate } + }) + .state('index.v5challenges', { + url: 'v5-challenges', + templateUrl: 'app/v5_challenges/challenges.list.html', + data: { pageTitle: 'Challenge Management' }, + resolve: { auth: authenticate } + }) + .state('index.v5ChallengeDetail', { + url: 'v5-challenge-details/:id', + templateUrl: 'app/v5_challenges/challenge.detail.html', + data: { pageTitle: 'Challenge Detail' }, + resolve: { auth: authenticate } + }) + .state('index.v5ChallengeManageUser', { + url: 'v5-challenge-manage-users/:id', + templateUrl: 'app/v5_challenges/challenge.manage.user.html', + data: { pageTitle: 'Manage Users' }, resolve: { auth: authenticate } }) .state('index.ideas', { @@ -464,7 +482,7 @@ angular.module('supportAdminApp', [ templateUrl: 'app/terms/terms.users.list.html', controller: 'terms.ListTermsUsersController', data: { pageTitle: 'Term Users' }, - params:{ + params: { title: null }, resolve: { auth: authenticate } diff --git a/src/app/challenges/challenges.service.js b/src/app/challenges/challenges.service.js index 58d7bac..def8e71 100644 --- a/src/app/challenges/challenges.service.js +++ b/src/app/challenges/challenges.service.js @@ -1,14 +1,24 @@ 'use strict'; angular.module('supportAdminApp') - .factory('ChallengeService', ['$q', '$http', 'API_URL', - function($q, $http, API_URL) { + .factory('ChallengeService', ['$q', '$http', 'API_URL', 'CHALLENGES_V5_API_URL', 'RESOURCE_V5_API_URL', + function ($q, $http, API_URL, V5_API_URL, RESOURCE_V5_API_URL) { var service = { findChallengeById: findChallengeById, getChallengePhases: getChallengePhases, updateChallengeFixedFee: updateChallengeFixedFee, updateChallengePercentageFee: updateChallengePercentageFee, + v5: { + search: search, + getChallengeTypes: getChallengeTypes, + getChallengeTracks: getChallengeTracks, + getChallengeById: getChallengeById, + getChallengeResources: getChallengeResources, + getResourceRoles: getResourceRoles, + deleteChallengeResource: deleteChallengeResource, + addChallengeResource: addChallengeResource + } } return service; @@ -18,7 +28,7 @@ angular.module('supportAdminApp') */ function _processRequest(request) { return request.then( - function(response) { + function (response) { if (response.data.result.content || response.data.result.content.length > 0) { return response.data.result.content.length > 0 ? response.data.result.content[0] : response.data.result.content; } else { @@ -29,7 +39,7 @@ angular.module('supportAdminApp') return $q.reject(err); } }, - function(error) { + function (error) { var err; if (error && error.data && error.data.result) { err = { @@ -148,7 +158,7 @@ angular.module('supportAdminApp') var request = $http({ method: 'PUT', url: API_URL + '/v3/challenges/' + challenge.id, - data: JSON.stringify({ + data: JSON.stringify({ param: { fixedFee: challenge.fixedFee } @@ -170,7 +180,7 @@ angular.module('supportAdminApp') var request = $http({ method: 'PUT', url: API_URL + '/v3/challenges/' + challenge.id, - data: angular.toJson({ + data: angular.toJson({ param: { percentageFee: challenge.percentageFee } @@ -183,5 +193,210 @@ angular.module('supportAdminApp') return _processRequest(request); }; + /** + * Handle API response error. + * @param {Error} error the error as received in catch callback. + * @param {Object} deferred the deferred object. + */ + function handleError(error, deferred) { + var err; + if (error && error.data) { + err = { + status: error.status, + error: error.data.message + }; + } + if (!err) { + err = { + status: error.status, + error: error.message + }; + } + deferred.reject(err); + }; + + /** + * search the challenges using v5 api. + * @param {string} filter the filter query. + * @returns {Promise} the promise base api result. + */ + function search(filter) { + var deferred = $q.defer(); + + $http({ + method: 'GET', + url: V5_API_URL + '/challenges?' + filter, + headers: { + "Content-Type": "application/json" + } + }).then(function (response) { + var data = { + result: response.data, + totalCount: response.headers('x-total') + }; + deferred.resolve(data); + }).catch(function (error) { + handleError(error, deferred); + }); + return deferred.promise; + }; + + /** + * gets the challenge types. + * @returns {Promise} the promise base api result. + */ + function getChallengeTypes() { + var deferred = $q.defer(); + + $http({ + method: 'GET', + url: V5_API_URL + '/challenge-types?isActive=true', + headers: { + "Content-Type": "application/json" + } + }).then(function (response) { + deferred.resolve(response.data); + }).catch(function (error) { + handleError(error, deferred); + }); + return deferred.promise; + }; + + /** + * gets the challenge tracks. + * @returns {Promise} the promise base api result. + */ + function getChallengeTracks() { + var deferred = $q.defer(); + + $http({ + method: 'GET', + url: V5_API_URL + '/challenge-tracks', + headers: { + "Content-Type": "application/json" + } + }).then(function (response) { + deferred.resolve(response.data); + }).catch(function (error) { + handleError(error, deferred); + }); + return deferred.promise; + }; + + /** + * gets the challenge details by id. + * @param {string} id the challenge id. + * @returns {Promise} the promise base api result. + */ + function getChallengeById(id) { + var deferred = $q.defer(); + + $http({ + method: 'GET', + url: V5_API_URL + '/challenges/' + id, + headers: { + "Content-Type": "application/json" + } + }).then(function (response) { + deferred.resolve(response.data); + }).catch(function (error) { + handleError(error, deferred); + }); + return deferred.promise; + }; + + /** + * get the challenge resources + * @param {string} challengeId the challenge id. + * @returns {Promise} the promise base api result. + */ + function getChallengeResources(challengeId, filter) { + var deferred = $q.defer(); + + $http({ + method: 'GET', + url: RESOURCE_V5_API_URL + '/resources?challengeId=' + challengeId + filter, + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Access-Control-Expose-Headers': '*' + } + }).then(function (response) { + var data = { + result: response.data, + totalCount: response.headers('x-total') + }; + deferred.resolve(data); + }).catch(function (error) { + handleError(error, deferred); + }); + return deferred.promise; + }; + + /** + * get the resource roles. + * @returns {Promise} the promise base api result. + */ + function getResourceRoles() { + var deferred = $q.defer(); + + $http({ + method: 'GET', + url: RESOURCE_V5_API_URL + '/resource-roles', + headers: { + 'Content-Type': 'application/json', + } + }).then(function (response) { + deferred.resolve(response.data); + }).catch(function (error) { + handleError(error, deferred); + }); + return deferred.promise; + }; + + /** + * delete the challenge resource. + * @param {object} data the data. + * @returns {Promise} the promise base api result. + */ + function deleteChallengeResource(data) { + var deferred = $q.defer(); + + $http({ + method: 'DELETE', + url: RESOURCE_V5_API_URL + '/resources', + headers: { + 'Content-Type': 'application/json', + }, + data: data + }).then(function (response) { + deferred.resolve(response.data); + }).catch(function (error) { + handleError(error, deferred); + }); + return deferred.promise; + }; + + /** + * add the resource in the challenge. + * @param {object} data the resource data. + */ + function addChallengeResource(data) { + var deferred = $q.defer(); + + $http({ + method: 'POST', + url: RESOURCE_V5_API_URL + '/resources', + headers: { + 'Content-Type': 'application/json', + }, + data: data + }).then(function (response) { + deferred.resolve(response.data); + }).catch(function (error) { + handleError(error, deferred); + }); + return deferred.promise; + } }]); diff --git a/src/app/users/users.service.js b/src/app/users/users.service.js index 65e3821..1ce65a9 100644 --- a/src/app/users/users.service.js +++ b/src/app/users/users.service.js @@ -25,7 +25,7 @@ angular /** find user by ID */ UserService.findById = function (userId) { if (!userId) { - return $q.reject({error: 'userId must be specified.'}); + return $q.reject({ error: 'userId must be specified.' }); } var request = $http({ @@ -46,7 +46,7 @@ angular var query = ""; angular.forEach({ "fields": opts.fields || "id,handle,email,active,emailActive,status,credential,firstName,lastName,createdA" + - "t,modifiedAt", + "t,modifiedAt", "filter": opts.filter, "limit": opts.limit, //"offset": null, "orderBy": null, @@ -143,36 +143,36 @@ angular }, helper.handleError); }, // updateEmail() - /** - * updates a user status - */ - UserService.updateStatus = function (userId, status, comment) { + /** + * updates a user status + */ + UserService.updateStatus = function (userId, status, comment) { - var payload = JSON.stringify({ + var payload = JSON.stringify({ param: { status: status } }), - param = comment - ? '?comment=' + encodeURIComponent(comment) - : '', - request = $http({ - method: 'PATCH', - url: API_URL + '/v3/users/' + userId + '/status' + param, - headers: defaultHeaders, - data: payload - }); - - return request.then(function (response) { - $log.debug(response); - return UserService.createUser(response.data.result.content); - }, helper.handleError); - }; // updateStatus() + param = comment + ? '?comment=' + encodeURIComponent(comment) + : '', + request = $http({ + method: 'PATCH', + url: API_URL + '/v3/users/' + userId + '/status' + param, + headers: defaultHeaders, + data: payload + }); + + return request.then(function (response) { + $log.debug(response); + return UserService.createUser(response.data.result.content); + }, helper.handleError); + }; // updateStatus() /** get achievements for the specified user id */ UserService.getAchievements = function (userId) { if (!userId) { - return $q.reject({error: 'userId must be specified.'}); + return $q.reject({ error: 'userId must be specified.' }); } var request = $http({ @@ -221,7 +221,7 @@ angular /** get profile by handle */ UserService.getProfile = function (handle) { if (!handle) { - return $q.reject({error: 'handle must be specified.'}); + return $q.reject({ error: 'handle must be specified.' }); } var request = $http({ @@ -262,7 +262,7 @@ angular * @param {Object} profile The user SSO profile. */ UserService.createOrUpdateSSOUserLogin = function (userId, profile) { - var payload = JSON.stringify({param: profile}); + var payload = JSON.stringify({ param: profile }); var request = $http({ method: 'POST', url: API_URL + '/v3/users/' + userId + '/createOrUpdateSSOUserLogin', @@ -319,7 +319,7 @@ angular */ UserService.createSsoUserLogin = function (userId, userLogin) { - var payload = JSON.stringify({param: userLogin}); + var payload = JSON.stringify({ param: userLogin }); var request = $http({ method: 'POST', @@ -342,7 +342,7 @@ angular */ UserService.updateSsoUserLogin = function (userId, userLogin) { - var payload = JSON.stringify({param: userLogin}); + var payload = JSON.stringify({ param: userLogin }); var request = $http({ method: 'PUT', @@ -384,12 +384,26 @@ angular UserService.getUserByHandleFilter = function (handle) { var request = $http({ method: 'GET', - url : basePath +'/users?fields=id,handle&filter=handle=' + handle + url: basePath + '/users?fields=id,handle&filter=handle=' + handle }); return request.then(function (response) { return response.data.result.content }, helper.handleError) - } + } + + /** + * gets the member suggest by handle. + * @param {string} handle the handle. + */ + UserService.getMemberSuggestByHandle = function (handle) { + var request = $http({ + method: 'GET', + url: basePath + '/members/_suggest/' + handle + }); + return request.then(function (response) { + return response.data.result.content + }, helper.handleError) + }; return UserService; } diff --git a/src/app/v5_challenges/add-user-challenge.controller.js b/src/app/v5_challenges/add-user-challenge.controller.js new file mode 100644 index 0000000..3b891a1 --- /dev/null +++ b/src/app/v5_challenges/add-user-challenge.controller.js @@ -0,0 +1,71 @@ +module.controller('v5challenge.AddUserController', [ + '$scope', + '$timeout', + '$uibModalInstance', + 'UserService', + 'ChallengeService', + 'Alert', + 'parentScope', + 'challenge', + function ($scope, $timeout, $modalInstance, UserService, $challengeService, $alert, $parentScope, challenge) { + $scope.challenge = challenge + $scope.handle = ''; + $scope.isLoading = false; + $scope.handles = []; + $scope.roles = []; + $scope.roleId = null; + + $challengeService.v5.getResourceRoles().then(function (data) { + $scope.roles = data; + }).catch(function (roleError) { + $alert.error(roleError.error, $rootScope); + }); + + /** + * Close dialog. + */ + $scope.close = function () { + $modalInstance.close(); + }; + + /** + * searches the handle. + * @param {string} filter the filter. + */ + $scope.searchHandle = function (filter) { + $scope.isLoading = true; + return UserService.getMemberSuggestByHandle(filter).then(function (data) { + $scope.isLoading = false; + return _.map(data, function (x) { return x.handle }); + }) + }; + + /** + * handles save click. + */ + $scope.save = function () { + $scope.clearError() + $scope.isLoading = true; + + $challengeService.v5.addChallengeResource({ + challengeId: $scope.challenge.id, + memberHandle: $scope.handle, + roleId: $scope.roleId + }).then(function () { + $alert.success('User has been added.', $scope); + $parentScope.search(); + }).catch(function (error) { + $alert.error(error.error, $scope); + }).finally(function () { + $scope.isLoading = false; + }); + }; + + /** + * clears the alerts. + */ + $scope.clearError = function () { + $alert.clear(); + }; + } +]); diff --git a/src/app/v5_challenges/add-user-challenge.html b/src/app/v5_challenges/add-user-challenge.html new file mode 100644 index 0000000..84285c8 --- /dev/null +++ b/src/app/v5_challenges/add-user-challenge.html @@ -0,0 +1,42 @@ +
+
+
+ No record found.
+| Title | +Status | +# Registrants | +# Submissions | +||
|---|---|---|---|---|---|
| + + {{challenge.name}} + + | +{{challenge.status}} | +{{challenge.numOfRegistrants}} | +{{challenge.numOfSubmissions}} | ++ Manage Users + | +|
| + + | +|||||