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 newline at end of file diff --git a/src/app/v5_challenges/challenge.detail.controller.js b/src/app/v5_challenges/challenge.detail.controller.js new file mode 100644 index 0000000..286f29e --- /dev/null +++ b/src/app/v5_challenges/challenge.detail.controller.js @@ -0,0 +1,65 @@ +'use strict'; + +var module = angular.module('supportAdminApp'); + +module.controller('v5challenge.DetailController', ['$scope', '$rootScope', 'AuthService', 'ChallengeService', 'Alert', '$stateParams', '$state', + function ($scope, $rootScope, $authService, $challengeService, $alert, $stateParams, $state) { + $scope.isLoading = true; + $scope.pageTitle = $state.current.data.pageTitle; + $scope.challenge = {}; + $scope.id = $stateParams.id; + $scope.challengeData = ''; + + /** + * Check if user is logged in. + */ + $scope.authorized = function () { + return $authService.isLoggedIn(); + }; + + /** + * prettify the json. + * @param {object} json the json. + * @param {boolean} prettify check if prettify. + */ + function prettifyJson(json, prettify) { + if (typeof json !== 'string') { + if (prettify) { + json = JSON.stringify(json, null, 2); + } else { + json = JSON.stringify(json); + } + } + return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, + function (match) { + if (/^"/.test(match)) { + if (/:$/.test(match)) { + return '' + match + ''; + } + } + var entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + return match.replace(/[&<>"'\/]/g, function (s) { + return entityMap[s]; + }); + } + ); + }; + + // fetch challenge detail + $challengeService.v5.getChallengeById($stateParams.id).then(function (data) { + $scope.challenge = data; + $scope.challengeData = prettifyJson(data, true); + }).catch(function (error) { + $alert.error(error.error, $rootScope); + }).finally(function () { + $scope.isLoading = false; + }); + } +]); \ No newline at end of file diff --git a/src/app/v5_challenges/challenge.detail.html b/src/app/v5_challenges/challenge.detail.html new file mode 100644 index 0000000..4e7d520 --- /dev/null +++ b/src/app/v5_challenges/challenge.detail.html @@ -0,0 +1,36 @@ +
+
+

{{pageTitle}}

+
+ +
+ +
+ +
+
+
+
+
+ +
+
+
+ + {{challenge.name}} +
+

+                    
+
+
+
+
+
\ No newline at end of file diff --git a/src/app/v5_challenges/challenge.manage.user.controller.js b/src/app/v5_challenges/challenge.manage.user.controller.js new file mode 100644 index 0000000..49987e8 --- /dev/null +++ b/src/app/v5_challenges/challenge.manage.user.controller.js @@ -0,0 +1,137 @@ +'use strict'; + +var module = angular.module('supportAdminApp'); + +module.controller('v5challenge.ManageUserController', ['$scope', '$rootScope', 'AuthService', 'ChallengeService', 'Alert', '$stateParams', '$state', '$uibModal', + function ($scope, $rootScope, $authService, $challengeService, $alert, $stateParams, $state, $modal) { + $scope.isLoading = false; + $scope.id = $stateParams.id; + $scope.title = $state.current.data.pageTitle; + $scope.isLoading = true; + $scope.totalCount = 0; + $scope.users = []; + $scope.roles = []; + + $scope.filterCriteria = { + page: 1, + perPage: 100 + }; + + // get resource roles + $challengeService.v5.getResourceRoles().then(function (data) { + $scope.roles = data; + }).catch(function (roleError) { + $alert.error(roleError.error, $rootScope); + }); + + /** + * gets the user data. + */ + $scope.search = function () { + $scope.isLoading = true; + var filter = '&page=' + $scope.filterCriteria.page + + '&perPage=' + $scope.filterCriteria.perPage; + $challengeService.v5.getChallengeResources($stateParams.id, filter).then(function (data) { + $scope.users = data.result; + $scope.totalCount = data.totalCount; + }).catch(function (error) { + $alert.error(error.error, $rootScope); + }).finally(function () { + $scope.isLoading = false; + }); + }; + + /** + * gets the role by id. + * @param {string} roleId the role id. + */ + $scope.getRole = function (roleId) { + var role = _.find($scope.roles, function (x) { + if (x.id == roleId) { + return x; + } + }); + if (role) { + return role.name; + } else { + return 'NOT FOUND'; + } + }; + + /** + * handles the remove user click. + * @param {object} user the selected user. + */ + $scope.removeUser = function (user) { + var confirmation = 'Are you sure? You want to remove user ' + user.memberHandle + '?'; + if (window.confirm(confirmation)) { + user.isRemoving = true; + $challengeService.v5.deleteChallengeResource({ + challengeId: $stateParams.id, memberHandle: user.memberHandle, roleId: user.roleId + }).then(function () { + $scope.search(); + }).catch(function (error) { + $alert.error(error.error, $rootScope); + }).finally(function () { + user.isRemoving = false; + }); + } + }; + + /** + * handles add user click. + */ + $scope.openAddUserDialog = function () { + var modalInstance = $modal.open({ + size: 'sm', + templateUrl: 'app/v5_challenges/add-user-challenge.html', + controller: 'v5challenge.AddUserController', + resolve: { + parentScope: function () { + return $scope; + }, + challenge: function () { + return { id: $stateParams.id }; + } + } + }); + }; + + /** + * handles change to a specific page. + * @param {number} pageNumber the page number. + */ + $scope.changePage = function (pageNumber) { + if (pageNumber === 0 || pageNumber > $scope.getLastPage() || $scope.filterCriteria.page === pageNumber) { + return false; + } + $scope.filterCriteria.page = pageNumber; + $scope.search(); + }; + + /** + * get the number array that shows the pagination bar. + */ + $scope.getPageArray = function () { + var res = []; + for (var i = $scope.filterCriteria.page - 5; i <= $scope.filterCriteria.page; i++) { + if (i > 0) { + res.push(i); + } + } + for (var i = $scope.filterCriteria.page + 1; i <= $scope.getLastPage() && i <= $scope.filterCriteria.page + 5; i++) { + res.push(i); + } + return res; + }; + + /** + * handles move to the last page. + */ + $scope.getLastPage = function () { + return parseInt($scope.totalCount / 100) + 1; + }; + + $scope.search(); + } +]); \ No newline at end of file diff --git a/src/app/v5_challenges/challenge.manage.user.html b/src/app/v5_challenges/challenge.manage.user.html new file mode 100644 index 0000000..e0e6cc6 --- /dev/null +++ b/src/app/v5_challenges/challenge.manage.user.html @@ -0,0 +1,100 @@ +
+
+
+
+
+
+
+

{{title}}

+
+
+ + +
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
HandleRoleRegistered 
{{user.memberHandle}} + loading.. + + {{getRole(user.roleId)}} + + {{user.created}} + + + +
+ +
+
No users

+
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/src/app/v5_challenges/challenges.list.controller.js b/src/app/v5_challenges/challenges.list.controller.js new file mode 100644 index 0000000..fcf910d --- /dev/null +++ b/src/app/v5_challenges/challenges.list.controller.js @@ -0,0 +1,123 @@ +'use strict'; + +var module = angular.module('supportAdminApp'); + +module.controller('v5challenge.ListController', ['$scope', '$rootScope', 'AuthService', 'ChallengeService', 'Alert', + function ($scope, $rootScope, $authService, $challengeService, $alert) { + $scope.isLoading = false; + $scope.totalChallenges = 0; + $scope.searched = false; + $scope.filterCriteria = { + page: 1, + perPage: 25, + challengeId: null, + legacyId: null, + type: null, + track: null, + status: 'Active', + }; + $scope.statusOptions = [ + 'New', + 'Draft', + 'Active', + 'Completed' + ]; + $scope.challengeTypes = []; + $scope.challengeTracks = []; + $scope.challenges = []; + + // load challenge types + $challengeService.v5.getChallengeTypes().then(function (challengeTypes) { + $scope.challengeTypes = challengeTypes; + }).catch(function (challengeTypeError) { + $alert.error(challengeTypeError.error, $rootScope); + }); + + // load challenge tracks + $challengeService.v5.getChallengeTracks().then(function (challengeTracks) { + $scope.challengeTracks = challengeTracks; + }).catch(function (challengeTypeError) { + $alert.error(challengeTypeError.error, $rootScope); + }); + + /** + * Check if user is logged in. + */ + $scope.authorized = function () { + return $authService.isLoggedIn(); + }; + + /** + * handles the search button click. + */ + $scope.search = function () { + $scope.searched = true + $alert.clear(); + $scope.isLoading = true; + var filter = ''; + filter = 'page=' + $scope.filterCriteria.page + + '&perPage=' + $scope.filterCriteria.perPage + + '&status=' + $scope.filterCriteria.status; + + if ($scope.filterCriteria.legacyId) { + filter += '&legacyId=' + $scope.filterCriteria.legacyId; + } + + if ($scope.filterCriteria.type) { + filter += '&types[]=' + $scope.filterCriteria.type; + } + + if ($scope.filterCriteria.track) { + filter += '&tracks[]=' + $scope.filterCriteria.track; + } + + if ($scope.filterCriteria.challengeId) { + filter += '&id=' + $scope.filterCriteria.challengeId; + } + + $challengeService.v5.search(filter).then(function (response) { + $scope.challenges = response.result; + $scope.totalChallenges = response.totalCount; + }).catch(function (error) { + $alert.error(error.error, $rootScope); + }).finally(function () { + $scope.isLoading = false; + }); + }; + + /** + * gets the pagination array. + */ + $scope.getPageArray = function () { + var res = []; + for (var i = $scope.filterCriteria.page - 5; i <= $scope.filterCriteria.page; i++) { + if (i > 0) { + res.push(i); + } + } + for (var i = $scope.filterCriteria.page + 1; i <= $scope.getLastPage() && i <= $scope.filterCriteria.page + 5; i++) { + res.push(i); + } + return res; + }; + + /** + * handles the change pagination. + * @param {number} pageNumber the selected page number. + */ + $scope.changePage = function (pageNumber) { + if (pageNumber === 0 || pageNumber > $scope.getLastPage() || $scope.filterCriteria.page === pageNumber) { + return false; + } + $scope.filterCriteria.page = pageNumber; + $scope.search(); + }; + + /** + * gets the last page of pagination. + */ + $scope.getLastPage = function () { + return parseInt($scope.totalChallenges / 25) + 1; + }; + } +]); \ No newline at end of file diff --git a/src/app/v5_challenges/challenges.list.html b/src/app/v5_challenges/challenges.list.html new file mode 100644 index 0000000..f180ef6 --- /dev/null +++ b/src/app/v5_challenges/challenges.list.html @@ -0,0 +1,125 @@ +
+
+

v5 Challenge Management

+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+
+
+
+ +
+
+

No record found.

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
TitleStatus# Registrants# Submissions
+ + {{challenge.name}} + + {{challenge.status}}{{challenge.numOfRegistrants}}{{challenge.numOfSubmissions}} + Manage Users +
+ +
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/src/components/common/navigation.html b/src/components/common/navigation.html index fa92360..6f54b84 100644 --- a/src/components/common/navigation.html +++ b/src/components/common/navigation.html @@ -11,6 +11,9 @@
  • Challenge Management
  • +
  • + v5 Challenge Management +
  • User Management