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

Skill picker blockchain#1241 #1244

Merged
merged 7 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/services/group.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import angular from 'angular'

(function () {
'use strict'

angular.module('tc.services').factory('GroupService', GroupService)

GroupService.$inject = ['ApiService']

function GroupService(ApiService) {
var service = ApiService.restangularV3

// Retrieves the registration status of the member for the given program
service.getMembers = function(userId, programId) {
return service.one('groups',programId).one('members').get()
}

// Registers the given member for the given program.
service.addMember = function(userId, programId) {
return service.one('groups', programId).one('members').customPOST({
memberId : userId +'', membershipType : 'user'
})
}

return service
}
})()
83 changes: 56 additions & 27 deletions app/skill-picker/skill-picker.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import _ from 'lodash'

angular.module('tc.skill-picker').controller('SkillPickerController', SkillPickerController)

SkillPickerController.$inject = ['$scope', 'CONSTANTS', 'ProfileService', '$state', 'userProfile', 'featuredSkills', 'logger', 'toaster', 'MemberCertService', '$q']
SkillPickerController.$inject = ['$scope', 'CONSTANTS', 'ProfileService', '$state', 'userProfile', 'featuredSkills', 'logger', 'toaster', 'MemberCertService','GroupService', '$q']

function SkillPickerController($scope, CONSTANTS, ProfileService, $state, userProfile, featuredSkills, logger, toaster, MemberCertService, $q) {
function SkillPickerController($scope, CONSTANTS, ProfileService, $state, userProfile, featuredSkills, logger, toaster, MemberCertService, GroupService, $q) {
var vm = this
vm.ASSET_PREFIX = CONSTANTS.ASSET_PREFIX
vm.IOS_PROGRAM_ID = parseInt(CONSTANTS.SWIFT_PROGRAM_ID)
vm.PREDIX_PROGRAM_ID = parseInt(CONSTANTS.PREDIX_PROGRAM_ID)
vm.IBM_COGNITIVE_PROGRAM_ID = parseInt(CONSTANTS.IBM_COGNITIVE_PROGRAM_ID)
vm.BLOCKCHAIN_PROGRAM_ID = parseInt(CONSTANTS.BLOCKCHAIN_PROGRAM_ID)
vm.submitSkills = submitSkills
vm.featuredSkills = featuredSkills
vm.userId = userProfile.userId
Expand All @@ -22,7 +23,7 @@ import _ from 'lodash'
vm.tracks = {}
vm.mySkills = []
vm.disableDoneButton = false
vm.showCommunity = false
vm.showCommunity = true
vm.loadingCommunities = false
vm.communities = {}
vm.isPageDirty = isPageDirty
Expand Down Expand Up @@ -82,6 +83,14 @@ import _ from 'lodash'
dirty: true,
display: true
}
vm.communities['blockchain'] = {
displayName: 'Blockchain',
programId: vm.BLOCKCHAIN_PROGRAM_ID,
status: false,
dirty: false,
display: true,
groupCommunity: true
}
vm.communities['ios'] = {
displayName: 'iOS',
programId: vm.IOS_PROGRAM_ID,
Expand All @@ -95,10 +104,11 @@ import _ from 'lodash'
status: false,
dirty: false,
display: true
}
}
_addWatchToCommunity(vm.communities['ios'])
_addWatchToCommunity(vm.communities['blockchain'])
_addWatchToCommunity(vm.communities['predix'])
_addWatchToCommunity(vm.communities['ibm_cognitive'])
_addWatchToCommunity(vm.communities['ibm_cognitive'])
}

/**
Expand All @@ -120,42 +130,59 @@ import _ from 'lodash'
* Checks registration status of each community and updates the state of each community.
*/
function checkCommunityStatus() {
var promises = []
var eventAPIpromises = [], groupAPIPromises = []
for (var name in vm.communities) {
var community = vm.communities[name]
promises.push(MemberCertService.getMemberRegistration(vm.userId, community.programId))
if(community.groupCommunity){
groupAPIPromises.push(GroupService.getMembers(vm.userId, community.programId))
}else{
eventAPIpromises.push(MemberCertService.getMemberRegistration(vm.userId, community.programId))
}
}

vm.loadingCommunities = true

$q.all(promises)
$q.all(groupAPIPromises)
.then(function(responses) {
let members = responses[0] || []
vm.loadingCommunities = false
members.forEach(function(member) {
if (member && member.memberId === vm.userId) {
addWatchToExistingCommunity(member.groupId)
}
})
})
.catch(function(err) {
logger.error('Could not load communities with group data', err)
vm.loadingCommunities = false
})

$q.all(eventAPIpromises)
.then(function(responses) {
vm.loadingCommunities = false
responses.forEach(function(program) {
if (program) {
var community = _.find(vm.communities, {programId: program.eventId})
if (community) {
// Show existing communites selected
community.status = true
if (community.unregister){
community.unregister()
_addWatchToCommunity(community)
}
}
if (program) {
addWatchToExistingCommunity(program.eventId)
}
})
// if there exists at least 1 community which can be displayed, set showCommunity flag to true
var community = _.find(vm.communities, {display: true})
if (community) {
vm.showCommunity = true
}
})
.catch(function(err) {
logger.error('Could not load communities with member cert registration data', err)

vm.loadingCommunities = false
})
}

function addWatchToExistingCommunity(programId){
var community = _.find(vm.communities, {programId: programId})
if (community) {
community.status = true
if (community.unregister){
community.unregister()
_addWatchToCommunity(community)
}
}
}

/**
* Toggles the given skill for the user. If it is not added, adds it and if already added, removes it.
*/
Expand Down Expand Up @@ -204,7 +231,11 @@ import _ from 'lodash'
var community = vm.communities[communityName]
if (community.dirty === true) {
if (community.status === true) {
promises.push(MemberCertService.registerMember(vm.userId, community.programId))
if(community.groupCommunity){
promises.push(GroupService.addMember(vm.userId, community.programId))
}else{
promises.push(MemberCertService.registerMember(vm.userId, community.programId))
}
}
}
}
Expand All @@ -219,9 +250,7 @@ import _ from 'lodash'
})
.catch(function(err) {
logger.error('Could not update update user skills or register members for community', err)

vm.saving = false

toaster.pop('error', 'Whoops!', 'Something went wrong. Please try again later.')
})
}
Expand Down
3 changes: 3 additions & 0 deletions app/skill-picker/skill-picker.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
.community__icon(ng-class="{'community__icon--disabled': !community.status}")
img(ng-if="communityKey == 'ibm_cognitive' && community.status", src=require("../../assets/images/ico-ibm_cognitive-community.svg"))
img(ng-if="communityKey == 'ibm_cognitive' && !community.status", src=require("../../assets/images/ico-ibm_cognitive-community-grey.svg"))
img(ng-if="communityKey == 'blockchain' && community.status", src=require("../../assets/images/ico-predix-community.svg"))
img(ng-if="communityKey == 'blockchain' && !community.status", src=require("../../assets/images/ico-predix-community-grey.svg"))
img(ng-if="communityKey == 'ios' && community.status", src=require("../../assets/images/ico-ios-community.svg"))
img(ng-if="communityKey == 'ios' && !community.status", src=require("../../assets/images/ico-ios-community-grey.svg"))
img(ng-if="communityKey == 'predix' && community.status", src=require("../../assets/images/ico-predix-community.svg"))
Expand All @@ -21,6 +23,7 @@
span.community__title(class="{{!community.status && 'disabled'}}") {{community.displayName}}
.community__description
span(ng-if="communityKey == 'ibm_cognitive'") Cognitive Community
span(ng-if="communityKey == 'blockchain'") Help create the future of Blockchain-based applications
span(ng-if="communityKey == 'ios'") Mobile app design and development for iOS, with Swift emphasis
span(ng-if="communityKey == 'predix'") Design and development on GE’s platform for the Industrial Internet of Things

Expand Down
3 changes: 2 additions & 1 deletion app/topcoder.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ angular.module('CONSTANTS', []).constant('CONSTANTS', {
'NEW_CHALLENGES_URL' : 'https://www.topcoder.com/challenges/develop/upcoming/',
'SWIFT_PROGRAM_ID' : 3445,
'PREDIX_PROGRAM_ID' : process.env.PREDIX_PROGRAM_ID || 3448,
'IBM_COGNITIVE_PROGRAM_ID' : process.env.IBM_COGNITIVE_PROGRAM_ID || 3449,
'IBM_COGNITIVE_PROGRAM_ID' : process.env.IBM_COGNITIVE_PROGRAM_ID || 3449,
'BLOCKCHAIN_PROGRAM_ID' : process.env.BLOCKCHAIN_PROGRAM_ID || 20000010,
'UPCOMING_SRMS_URL' : 'https://www.topcoder.com/challenges/data/upcoming/',
'EVENT_USER_LOGGED_IN' : 'user_logged_in',
'EVENT_USER_LOGGED_OUT' : 'user_logged_out',
Expand Down