diff --git a/src/main/java/com/techlooper/config/web/DispatcherServletInitializer.java b/src/main/java/com/techlooper/config/web/DispatcherServletInitializer.java index 83c80f873..b456edda6 100644 --- a/src/main/java/com/techlooper/config/web/DispatcherServletInitializer.java +++ b/src/main/java/com/techlooper/config/web/DispatcherServletInitializer.java @@ -34,30 +34,35 @@ public class DispatcherServletInitializer extends AbstractAnnotationConfigDispat // @Value("${spring.profiles.active}") // private String profile; - public void onStartup(ServletContext servletContext) throws ServletException { - super.onStartup(servletContext); - servletContext.getSessionCookieConfig().setMaxAge(15770000); - servletContext.addListener(new SessionListener()); - } - - protected Class[] getRootConfigClasses() { - return null; - } - - protected Class[] getServletConfigClasses() { - return new Class[]{ - CoreConfiguration.class, - VnwDbConfiguration.class, - WebConfiguration.class, - SecurityConfiguration.class - }; - } - - protected String[] getServletMappings() { - return new String[]{"/"}; - } - - protected void customizeRegistration(Dynamic registration) { - registration.setInitParameter("dispatchOptionsRequest", "true"); - } + public void onStartup(ServletContext servletContext) throws ServletException { + super.onStartup(servletContext); + servletContext.getSessionCookieConfig().setMaxAge(15770000); + servletContext.addListener(new SessionListener()); + } + + protected Class[] getRootConfigClasses() { + return null; + } + + protected Class[] getServletConfigClasses() { + return new Class[]{ + CoreConfiguration.class, + VnwDbConfiguration.class, + WebConfiguration.class, + SecurityConfiguration.class + }; + } + + protected String[] getServletMappings() { + return new String[]{"/"}; + } + + protected void customizeRegistration(Dynamic registration) { + registration.setInitParameter("dispatchOptionsRequest", "true"); + } + + @Override + protected void registerContextLoaderListener(ServletContext servletContext) { + + } } diff --git a/src/main/java/com/techlooper/controller/ChallengeController.java b/src/main/java/com/techlooper/controller/ChallengeController.java index 594bf7a49..323c9d36a 100644 --- a/src/main/java/com/techlooper/controller/ChallengeController.java +++ b/src/main/java/com/techlooper/controller/ChallengeController.java @@ -28,154 +28,152 @@ @RestController public class ChallengeController { - private final static Logger LOGGER = LoggerFactory.getLogger(ChallengeController.class); - - @Resource - private ChallengeService challengeService; - - @Resource - private EmployerService employerService; - - @Resource - private LeadAPIService leadAPIService; - - @Resource - private ChallengeRegistrantRepository challengeRegistrantRepository; - - @Resource - private ChallengeRegistrantService challengeRegistrantService; - - @PreAuthorize("hasAuthority('EMPLOYER')") - @RequestMapping(value = "/challenge/publish", method = RequestMethod.POST) - public ChallengeResponse publishChallenge(@RequestBody ChallengeDto challengeDto, HttpServletRequest servletRequest) throws Exception { - int responseCode = 0; - String employerEmail = servletRequest.getRemoteUser(); - challengeDto.setAuthorEmail(employerEmail); - ChallengeEntity challengeEntity = challengeService.savePostChallenge(challengeDto); - boolean newEntity = challengeDto.getChallengeId() == null; - if (newEntity) { - if (challengeEntity != null) { - if (EmailValidator.validate(challengeEntity.getAuthorEmail())) { - challengeService.sendPostChallengeEmailToEmployer(challengeEntity); + private final static Logger LOGGER = LoggerFactory.getLogger(ChallengeController.class); + + @Resource + private ChallengeService challengeService; + + @Resource + private EmployerService employerService; + + @Resource + private LeadAPIService leadAPIService; + + @Resource + private ChallengeRegistrantRepository challengeRegistrantRepository; + + @Resource + private ChallengeRegistrantService challengeRegistrantService; + + @PreAuthorize("hasAuthority('EMPLOYER')") + @RequestMapping(value = "/challenge/publish", method = RequestMethod.POST) + public ChallengeResponse publishChallenge(@RequestBody ChallengeDto challengeDto, HttpServletRequest servletRequest) throws Exception { + int responseCode = 0; + String employerEmail = servletRequest.getRemoteUser(); + challengeDto.setAuthorEmail(employerEmail); + ChallengeEntity challengeEntity = challengeService.savePostChallenge(challengeDto); + boolean newEntity = challengeDto.getChallengeId() == null; + if (newEntity) { + if (challengeEntity != null) { + if (EmailValidator.validate(challengeEntity.getAuthorEmail())) { + challengeService.sendPostChallengeEmailToEmployer(challengeEntity); + } + challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.TRUE); + } + + // Call Lead Management API to create new lead on CRM system + try { + VnwUser employer = employerService.findEmployerByUsername(employerEmail); + VnwCompany company = employerService.findCompanyById(employer.getCompanyId()); + if (employer != null && company != null) { + responseCode = leadAPIService.createNewLead( + employer, company, LeadEventEnum.POST_CHALLENGE, challengeEntity.getChallengeName()); + + String logMessage = "Create Lead API Response Code : %d ,EmployerID : %d ,CompanyID : %d"; + LOGGER.info(String.format(logMessage, responseCode, employer.getUserId(), company.getCompanyId())); + } + } catch (Exception ex) { + LOGGER.error(ex.getMessage(), ex); + } + } else { + challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.FALSE); } - challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.TRUE); - } - - // Call Lead Management API to create new lead on CRM system - try { - VnwUser employer = employerService.findEmployerByUsername(employerEmail); - VnwCompany company = employerService.findCompanyById(employer.getCompanyId()); - if (employer != null && company != null) { - responseCode = leadAPIService.createNewLead( - employer, company, LeadEventEnum.POST_CHALLENGE, challengeEntity.getChallengeName()); - - String logMessage = "Create Lead API Response Code : %d ,EmployerID : %d ,CompanyID : %d"; - LOGGER.info(String.format(logMessage, responseCode, employer.getUserId(), company.getCompanyId())); + + return new ChallengeResponse(challengeEntity.getChallengeId(), responseCode); + } + + @RequestMapping(value = "/challenge/{challengeId}", method = RequestMethod.GET) + public ChallengeDetailDto getChallengeDetail(@PathVariable Long challengeId, HttpServletRequest request, HttpServletResponse response) throws Exception { + ChallengeDetailDto challengeDetail = challengeService.getChallengeDetail(challengeId, request.getRemoteUser()); + if (challengeDetail == null) response.setStatus(HttpServletResponse.SC_NOT_FOUND); + return challengeDetail; + } + + @RequestMapping(value = "/challenge/join", method = RequestMethod.POST) + public long joinChallenge(@RequestBody ChallengeRegistrantDto joinChallenge, HttpServletResponse response) throws Exception { + if (!EmailValidator.validate(joinChallenge.getRegistrantEmail())) { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + return 0L; } - } - catch (Exception ex) { - LOGGER.error(ex.getMessage(), ex); - } + return challengeService.joinChallenge(joinChallenge); } - else { - challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.FALSE); + + @RequestMapping(value = "/challenge/list", method = RequestMethod.GET) + public List listChallenges() throws Exception { + return challengeService.listChallenges(); + } + + @RequestMapping(value = "/challenge/stats", method = RequestMethod.GET) + public ChallengeStatsDto getChallengeStatistics() throws Exception { + ChallengeStatsDto challengeStatsDto = new ChallengeStatsDto(); + challengeStatsDto.setNumberOfChallenges(challengeService.getTotalNumberOfChallenges()); + challengeStatsDto.setNumberOfRegistrants(challengeService.getTotalNumberOfRegistrants()); + challengeStatsDto.setTotalPrizeAmount(challengeService.getTotalAmountOfPrizeValues()); + return challengeStatsDto; + } + + @PreAuthorize("hasAuthority('EMPLOYER')") + @RequestMapping(value = "/challenge/{id}", method = RequestMethod.DELETE) + public void deleteChallengeById(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response) { + if (!challengeService.delete(id, request.getRemoteUser())) { + response.setStatus(HttpServletResponse.SC_FORBIDDEN); + } } - return new ChallengeResponse(challengeEntity.getChallengeId(), responseCode); - } - - @RequestMapping(value = "/challenge/{challengeId}", method = RequestMethod.GET) - public ChallengeDetailDto getChallengeDetail(@PathVariable Long challengeId, HttpServletRequest request, HttpServletResponse response) throws Exception { - ChallengeDetailDto challengeDetail = challengeService.getChallengeDetail(challengeId, request.getRemoteUser()); - if (challengeDetail == null) response.setStatus(HttpServletResponse.SC_NOT_FOUND); - return challengeDetail; - } - - @RequestMapping(value = "/challenge/join", method = RequestMethod.POST) - public long joinChallenge(@RequestBody ChallengeRegistrantDto joinChallenge, HttpServletResponse response) throws Exception { - if (!EmailValidator.validate(joinChallenge.getRegistrantEmail())) { - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - return 0L; + @RequestMapping(value = "/challenges/{challengeId}", method = RequestMethod.GET) + public ChallengeDto findChallengeById(@PathVariable Long challengeId, HttpServletRequest request) throws Exception { + return challengeService.findChallengeById(challengeId, request.getRemoteUser()); } - return challengeService.joinChallenge(joinChallenge); - } - - @RequestMapping(value = "/challenge/list", method = RequestMethod.GET) - public List listChallenges() throws Exception { - return challengeService.listChallenges(); - } - - @RequestMapping(value = "/challenge/stats", method = RequestMethod.GET) - public ChallengeStatsDto getChallengeStatistics() throws Exception { - ChallengeStatsDto challengeStatsDto = new ChallengeStatsDto(); - challengeStatsDto.setNumberOfChallenges(challengeService.getTotalNumberOfChallenges()); - challengeStatsDto.setNumberOfRegistrants(challengeService.getTotalNumberOfRegistrants()); - challengeStatsDto.setTotalPrizeAmount(challengeService.getTotalAmountOfPrizeValues()); - return challengeStatsDto; - } - - @PreAuthorize("hasAuthority('EMPLOYER')") - @RequestMapping(value = "/challenge/{id}", method = RequestMethod.DELETE) - public void deleteChallengeById(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response) { - if (!challengeService.delete(id, request.getRemoteUser())) { - response.setStatus(HttpServletResponse.SC_FORBIDDEN); + + @PreAuthorize("hasAuthority('EMPLOYER')") + @RequestMapping(value = "/challenges/{challengeId}/registrants", method = RequestMethod.POST) + public Set getRegistrantsById(@PathVariable Long challengeId, @RequestBody RegistrantFilterCondition condition, + HttpServletRequest request, HttpServletResponse response) throws ParseException { + String owner = request.getRemoteUser(); + if (!challengeService.isOwnerOfChallenge(owner, challengeId)) { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + return null; + } + condition.setAuthorEmail(owner); + return challengeService.findRegistrantsByOwner(condition); } - } - - @RequestMapping(value = "/challenges/{challengeId}", method = RequestMethod.GET) - public ChallengeDto findChallengeById(@PathVariable Long challengeId, HttpServletRequest request) throws Exception { - return challengeService.findChallengeById(challengeId, request.getRemoteUser()); - } - - @PreAuthorize("hasAuthority('EMPLOYER')") - @RequestMapping(value = "/challenges/{challengeId}/registrants", method = RequestMethod.POST) - public Set getRegistrantsById(@PathVariable Long challengeId, @RequestBody RegistrantFilterCondition condition, - HttpServletRequest request, HttpServletResponse response) throws ParseException { - String owner = request.getRemoteUser(); - if (!challengeService.isOwnerOfChallenge(owner, challengeId)) { - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - return null; + + + @PreAuthorize("hasAuthority('EMPLOYER')") + @RequestMapping(value = "/challengeDetail/registrant", method = RequestMethod.POST) + public ChallengeRegistrantDto saveRegistrant(@RequestBody ChallengeRegistrantDto dto, HttpServletRequest request) { + return challengeService.saveRegistrant(request.getRemoteUser(), dto); } - condition.setAuthorEmail(owner); - return challengeService.findRegistrantsByOwner(condition); - } - - - @PreAuthorize("hasAuthority('EMPLOYER')") - @RequestMapping(value = "/challengeDetail/registrant", method = RequestMethod.POST) - public ChallengeRegistrantDto saveRegistrant(@RequestBody ChallengeRegistrantDto dto, HttpServletRequest request) { - return challengeService.saveRegistrant(request.getRemoteUser(), dto); - } - - @PreAuthorize("hasAuthority('EMPLOYER')") - @RequestMapping(value = "challengeRegistrant/fullName/{registrantId}", method = RequestMethod.GET) - public String getChallengeRegistrant(@PathVariable Long registrantId) { - ChallengeRegistrantEntity registrantEntity = challengeRegistrantRepository.findOne(registrantId); - return registrantEntity.getRegistrantFirstName() + " " + registrantEntity.getRegistrantLastName(); - } - - @PreAuthorize("hasAuthority('EMPLOYER')") - @RequestMapping(value = "/challenges/{challengeId}/registrantFunnel", method = RequestMethod.GET) - public List getChallengeRegistrantFunnel(@PathVariable Long challengeId, - HttpServletRequest request, HttpServletResponse response) { - List funnel = new ArrayList<>(); - if (challengeService.isOwnerOfChallenge(request.getRemoteUser(), challengeId)) { - funnel = challengeService.getChallengeRegistrantFunnel(challengeId); + + @PreAuthorize("hasAuthority('EMPLOYER')") + @RequestMapping(value = "challengeRegistrant/fullName/{registrantId}", method = RequestMethod.GET) + public String getChallengeRegistrant(@PathVariable Long registrantId) { + ChallengeRegistrantEntity registrantEntity = challengeRegistrantRepository.findOne(registrantId); + return registrantEntity.getRegistrantFirstName() + " " + registrantEntity.getRegistrantLastName(); } - else { - response.setStatus(HttpServletResponse.SC_FORBIDDEN); + + @PreAuthorize("hasAuthority('EMPLOYER')") + @RequestMapping(value = "/challenges/{challengeId}/registrantFunnel", method = RequestMethod.GET) + public List getChallengeRegistrantFunnel(@PathVariable Long challengeId, + HttpServletRequest request, HttpServletResponse response) { + List funnel = new ArrayList<>(); + String ownerEmail = request.getRemoteUser(); + if (challengeService.isOwnerOfChallenge(ownerEmail, challengeId)) { + funnel = challengeService.getChallengeRegistrantFunnel(challengeId, ownerEmail); + } else { + response.setStatus(HttpServletResponse.SC_FORBIDDEN); + } + return funnel; } - return funnel; - } - - @PreAuthorize("hasAuthority('EMPLOYER')") - @RequestMapping(value = "challenge/{challengeId}/registrants/{phase}", method = RequestMethod.GET) - public Set getChallengeRegistrantsByPhase(@PathVariable Long challengeId, @PathVariable ChallengePhaseEnum phase, - HttpServletRequest request, HttpServletResponse response) { - Set registrants = challengeRegistrantService.findRegistrantsByChallengeIdAndPhase(challengeId, phase, request.getRemoteUser()); - if (registrants == null) { - response.setStatus(HttpServletResponse.SC_FORBIDDEN); + + @PreAuthorize("hasAuthority('EMPLOYER')") + @RequestMapping(value = "challenge/{challengeId}/registrants/{phase}", method = RequestMethod.GET) + public Set getChallengeRegistrantsByPhase(@PathVariable Long challengeId, @PathVariable ChallengePhaseEnum phase, + HttpServletRequest request, HttpServletResponse response) { + Set registrants = challengeRegistrantService.findRegistrantsByChallengeIdAndPhase(challengeId, phase, request.getRemoteUser()); + if (registrants == null) { + response.setStatus(HttpServletResponse.SC_FORBIDDEN); + } + return registrants; } - return registrants; - } } diff --git a/src/main/java/com/techlooper/model/ChallengeSubmissionDto.java b/src/main/java/com/techlooper/model/ChallengeSubmissionDto.java index 874d35ef0..f8d058371 100644 --- a/src/main/java/com/techlooper/model/ChallengeSubmissionDto.java +++ b/src/main/java/com/techlooper/model/ChallengeSubmissionDto.java @@ -25,6 +25,16 @@ public class ChallengeSubmissionDto implements Serializable { private String submissionDateTime; + private ChallengePhaseEnum submissionPhase; + + public ChallengePhaseEnum getSubmissionPhase() { + return submissionPhase; + } + + public void setSubmissionPhase(ChallengePhaseEnum submissionPhase) { + this.submissionPhase = submissionPhase; + } + public Long getChallengeSubmissionId() { return challengeSubmissionId; } diff --git a/src/main/java/com/techlooper/service/ChallengeService.java b/src/main/java/com/techlooper/service/ChallengeService.java index a35e5ead7..8dccc08d8 100644 --- a/src/main/java/com/techlooper/service/ChallengeService.java +++ b/src/main/java/com/techlooper/service/ChallengeService.java @@ -107,5 +107,5 @@ List findChallengeSubmissionWithinPeriod( ChallengeRegistrantEntity findRegistrantByChallengeIdAndEmail(Long challengeId, String email); - List getChallengeRegistrantFunnel(Long challengeId); + List getChallengeRegistrantFunnel(Long challengeId, String ownerEmail); } diff --git a/src/main/java/com/techlooper/service/impl/ChallengeServiceImpl.java b/src/main/java/com/techlooper/service/impl/ChallengeServiceImpl.java index 16e2edf8c..7fb3d653c 100644 --- a/src/main/java/com/techlooper/service/impl/ChallengeServiceImpl.java +++ b/src/main/java/com/techlooper/service/impl/ChallengeServiceImpl.java @@ -337,6 +337,7 @@ public ChallengeRegistrantEntity joinChallengeEntity(ChallengeRegistrantDto chal return challengeRegistrantRepository.save(challengeRegistrantEntity); } catch (Exception e) { LOGGER.debug("Can not send email", e); + return challengeRegistrantEntity; } } @@ -806,12 +807,7 @@ public boolean sendEmailToDailyChallengeRegistrants(String challengeOwner, Long if (isOwnerOfChallenge(challengeOwner, challengeId)) { List registrants = findChallengeRegistrantWithinPeriod(challengeId, now, TimePeriodEnum.TWENTY_FOUR_HOURS); String csvEmails = registrants.stream().map(ChallengeRegistrantEntity::getRegistrantEmail).distinct().collect(joining(",")); - ChallengeDto challengeDto = findChallengeById(challengeId, null); try { - // In case sending email to only one registrant of this challenge (feedback action form) - if (registrants.size() == 1) { - bindEmailTemplateVariables(emailContent, challengeDto, registrants.get(0)); - } emailContent.setRecipients(InternetAddress.parse(csvEmails)); } catch (AddressException e) { LOGGER.debug("Can not parse email address", e); @@ -1010,8 +1006,9 @@ public ChallengeRegistrantDto acceptRegistrant(String ownerEmail, Long registran } @Override - public List getChallengeRegistrantFunnel(Long challengeId) { + public List getChallengeRegistrantFunnel(Long challengeId, String ownerEmail) { List funnel = new ArrayList<>(); + ChallengeDto challengeDto = findChallengeById(challengeId, ownerEmail); Map numberOfRegistrantsByPhase = challengeRegistrantService.countNumberOfRegistrantsByPhase(challengeId); Map numberOfSubmissionsByPhase = @@ -1024,7 +1021,10 @@ public List getChallengeRegistrantFunnel(Long cha if (numberOfSubmissionsByPhase.get(phase) != null) { submission = numberOfSubmissionsByPhase.get(phase).getSubmission(); } - funnel.add(new ChallengeRegistrantFunnelItem(phase, participant, submission)); + + if (isValidPhase(challengeDto, phase)) { + funnel.add(new ChallengeRegistrantFunnelItem(phase, participant, submission)); + } } // Long numberOfWinners = challengeRegistrantService.countNumberOfWinners(challengeId); @@ -1034,4 +1034,21 @@ public List getChallengeRegistrantFunnel(Long cha item1.getPhase().getOrder() - item2.getPhase().getOrder(); return funnel.stream().sorted(sortByPhaseComparator).collect(toList()); } + + private boolean isValidPhase(ChallengeDto challengeDto, ChallengePhaseEnum phase) { + switch (phase) { + case REGISTRATION: + return StringUtils.isNotEmpty(challengeDto.getRegistrationDate()); + case IDEA: + return StringUtils.isNotEmpty(challengeDto.getIdeaSubmissionDate()); + case UIUX: + return StringUtils.isNotEmpty(challengeDto.getUxSubmissionDate()); + case PROTOTYPE: + return StringUtils.isNotEmpty(challengeDto.getPrototypeSubmissionDate()); + case FINAL: + return StringUtils.isNotEmpty(challengeDto.getSubmissionDate()); + default: + return false; + } + } } diff --git a/src/main/java/com/techlooper/service/impl/JobAggregatorServiceImpl.java b/src/main/java/com/techlooper/service/impl/JobAggregatorServiceImpl.java index 3dbac3dad..7ce3ac286 100644 --- a/src/main/java/com/techlooper/service/impl/JobAggregatorServiceImpl.java +++ b/src/main/java/com/techlooper/service/impl/JobAggregatorServiceImpl.java @@ -327,7 +327,7 @@ private void mapJobCrawlSource(JobSearchResponse jobSearchResponse) { if (StringUtils.isNotEmpty(job.getCrawlSource())) { String crawlSource = job.getCrawlSource(); StringTokenizer tokenizer = new StringTokenizer(crawlSource, "-"); - while (tokenizer.hasMoreTokens()) { + if (tokenizer.hasMoreTokens()) { String sourceName = tokenizer.nextToken(); job.setCrawlSource(sourceName.toUpperCase()); } diff --git a/src/main/resources/template/challengeDailySummary.en.ftl b/src/main/resources/template/challengeDailySummary.en.ftl index a94527000..6032fb93e 100644 --- a/src/main/resources/template/challengeDailySummary.en.ftl +++ b/src/main/resources/template/challengeDailySummary.en.ftl @@ -341,7 +341,7 @@
- Review All + Review All Submissions
diff --git a/src/main/resources/template/challengeDailySummary.vi.ftl b/src/main/resources/template/challengeDailySummary.vi.ftl index 423121848..5dcc4a46e 100644 --- a/src/main/resources/template/challengeDailySummary.vi.ftl +++ b/src/main/resources/template/challengeDailySummary.vi.ftl @@ -341,7 +341,7 @@
- Xem Tất Cả + Xem Tất Cả Bài Gửi
diff --git a/src/main/webapp/assets/modules/common/challenge/submissionChallenge.js b/src/main/webapp/assets/modules/common/challenge/submissionChallenge.js index 9222284f7..dfe9708f8 100644 --- a/src/main/webapp/assets/modules/common/challenge/submissionChallenge.js +++ b/src/main/webapp/assets/modules/common/challenge/submissionChallenge.js @@ -1,4 +1,4 @@ -techlooper.directive("submissionChallenge", function (localStorageService, apiService, $timeout, $rootScope, $translate) { +techlooper.directive("submissionChallenge", function (localStorageService, apiService, $timeout, $rootScope, $location) { return { restrict: "E", replace: true, @@ -12,8 +12,10 @@ techlooper.directive("submissionChallenge", function (localStorageService, apiSe var mixChallenge = function () { scope.challenge.hideSubmitForm = function () { - scope.submissionForm.$setPristine(); - scope.submissionForm.$setUntouched(); + if (scope.submissionForm) { + scope.submissionForm.$setPristine(); + scope.submissionForm.$setUntouched(); + } delete scope.challenge.visibleSubmitForm; delete scope.submission.submissionURL; delete scope.submission.submissionDescription; @@ -70,6 +72,7 @@ techlooper.directive("submissionChallenge", function (localStorageService, apiSe return false; } $('.feedback-loading').css('visibility', 'inherit'); + $location.search({}); apiService.getUrlResponseCode(scope.submission.submissionURL) .success(function (code) { var inValid = (code == 404); @@ -88,7 +91,7 @@ techlooper.directive("submissionChallenge", function (localStorageService, apiSe }, 500); }); } - scope.submissionForm.submissionURL.$setValidity("invalidUrl", !inValid); + scope.submissionForm && scope.submissionForm.submissionURL.$setValidity("invalidUrl", !inValid); }) .finally(function () { $timeout(function () { diff --git a/src/main/webapp/assets/modules/common/feedback/feedbackDirective.js b/src/main/webapp/assets/modules/common/feedback/feedbackDirective.js index 60601ecb7..836bcc0fd 100644 --- a/src/main/webapp/assets/modules/common/feedback/feedbackDirective.js +++ b/src/main/webapp/assets/modules/common/feedback/feedbackDirective.js @@ -4,7 +4,7 @@ techlooper.directive("feedbackForm", function (apiService, $timeout) { replace: true, templateUrl: "modules/common/feedback/feedback.html", scope: { - composeEmail: "=", + composeEmail: "=" }, link: function (scope, element, attr, ctrl, composeEmail) { if (scope.composeEmail.registrantLastName) { @@ -22,14 +22,15 @@ techlooper.directive("feedbackForm", function (apiService, $timeout) { scope.composeEmail.content = scope.feedbackContent; } $('.feedback-loading').css('visibility', 'inherit'); - apiService.sendEmailToDailyChallengeRegistrants(scope.composeEmail.challengeId, scope.composeEmail.registrantId, scope.composeEmail) - .success(function () { + + apiService.sendFeedbackToRegistrant(scope.composeEmail.challengeId, scope.composeEmail.registrantId, scope.composeEmail) + .success(function(){ $timeout(function () { $('.feedback-loading').css('visibility', 'hidden'); scope.cancel(); }, 1200); }) - .error(function () { + .error(function(){ scope.composeEmail.error = false; $timeout(function () { $('.feedback-loading').css('visibility', 'hidden'); diff --git a/src/main/webapp/assets/modules/common/model/challengeRegistrant.js b/src/main/webapp/assets/modules/common/model/challengeRegistrant.js index 0399f8b9b..ac8ac9107 100644 --- a/src/main/webapp/assets/modules/common/model/challengeRegistrant.js +++ b/src/main/webapp/assets/modules/common/model/challengeRegistrant.js @@ -17,22 +17,6 @@ techlooper.filter("challengeRegistrant", function (apiService, $rootScope, jsonV }); } - //if (challengePhase == registrant.activePhase) { - // registrant.qualifiedCurrentPhase = !registrant.disqualified; - //} - //else { - // registrant.qualifiedCurrentPhase = true; - //} - registrant.activePhase = registrant.activePhase ? registrant.activePhase : jsonValue.challengePhase.getRegistration().enum; - if (challengePhase != registrant.activePhase) { - registrant.qualified = true; - } - else { - if (registrant.disqualified == true) { - registrant.qualified = false; - } - } - registrant.criteriaLoop = function () { var criteria = registrant.criteria; if (!criteria) return []; @@ -89,12 +73,35 @@ techlooper.filter("challengeRegistrant", function (apiService, $rootScope, jsonV return parseFloat(sum) + parseFloat(calculatePoint(cri)); }, 0)).format("0.0"); - registrant.getLastSubmission = function () { + registrant.recalculate = function (challengePhase) { if (registrant.submissions) { - return _.max(registrant.submissions, function (submission) {return submission.challengeSubmissionId;}); + registrant.lastSubmission = _.isEmpty(registrant.submissions) ? undefined : _.max(registrant.submissions, function (submission) {return submission.challengeSubmissionId;}); + registrant.phaseSubmissions = _.filter(registrant.submissions, function (submission) {return submission.submissionPhase == challengePhase;}); + } + + registrant.activePhase = registrant.activePhase ? registrant.activePhase : jsonValue.challengePhase.getRegistration().enum; + if (challengePhase != registrant.activePhase) { + registrant.qualified = true; + } + else if (registrant.disqualified == true) { + registrant.qualified = false; + } + } + + registrant.acceptSubmission = function (submission) { + if (!_.findWhere(registrant.submissions, submission)) { + registrant.submissions.unshift(submission); + registrant.recalculate(submission.submissionPhase); } } + registrant.recalculate(challengePhase); + + + //registrant. = function() { + // + //} + //registrant.qualifyMe = function(challengeDetail) { // delete registrant.disqualified; // delete registrant.disqualifiedReason; diff --git a/src/main/webapp/assets/modules/contest-detail/contestDetail.html b/src/main/webapp/assets/modules/contest-detail/contestDetail.html index 3a15638ec..3ae79d55c 100644 --- a/src/main/webapp/assets/modules/contest-detail/contestDetail.html +++ b/src/main/webapp/assets/modules/contest-detail/contestDetail.html @@ -245,8 +245,8 @@

+ ng-repeat="phase in registrantFunnel" ng-click="reviewPhase($index, phase, contestDetail.nextPhase)" + ng-class="{col3: registrantFunnel.length == 3, col4: registrantFunnel.length == 4, col5: registrantFunnel.length == 5, col6: registrantFunnel.length == 6, active: $index == selectedPhase}">
@@ -264,7 +264,7 @@

+ translate-value-number="{{phase.participant}}" ng-show="phase.participant > 0 && ((phase.phase | progress: 'challengePhaseTitle' | lowercase) == 'registration')">

+ ng-show="$index == selectedPhase && (phase.phase | progress: 'challengePhaseTitle' | lowercase) != 'winner' && (phase.phase | progress: 'challengePhaseTitle' | lowercase) != 'final app'">

+

@@ -295,14 +297,14 @@

{{'registrationDate' | translate}} -
+ ng-click="sortBySubmissionDate()"> {{'lastSubmissionDate' | translate}} - +
{{'submissions' | translate}} @@ -311,10 +313,9 @@

ng-click="sortByScore()" ng-show="(phase.phase | progress: 'challengePhaseTitle' | lowercase) == 'winner' || (phase.phase | progress: 'challengePhaseTitle' | lowercase) == 'final app'"> {{'score' | translate}} -

-
{{'qualifiedNextPhase' | translate}}
@@ -340,9 +341,9 @@

- + {{user.names}} - +

{{'disqualifyingReason' | translate}}: {{user.disqualifiedReason}}

@@ -350,11 +351,11 @@

- {{user.getLastSubmission().submissionDateTime}} + {{user.lastSubmission.submissionDateTime}}
@@ -364,10 +365,13 @@

- - - - + + + + +
@@ -390,97 +394,11 @@

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ diff --git a/src/main/webapp/assets/modules/contest-detail/contestDetailController.js b/src/main/webapp/assets/modules/contest-detail/contestDetailController.js index b8a7b4823..1c93a0835 100644 --- a/src/main/webapp/assets/modules/contest-detail/contestDetailController.js +++ b/src/main/webapp/assets/modules/contest-detail/contestDetailController.js @@ -1,8 +1,8 @@ techlooper.controller('contestDetailController', function ($scope, apiService, localStorageService, $location, $routeParams, - jsonValue, $translate, utils, $filter, $timeout, resourcesService) { + jsonValue, $translate, utils, $filter, $timeout, resourcesService, $timeout) { utils.sendNotification(jsonValue.notifications.loading); $scope.selectedPhase = 0; - + var activePhaseIndex = 0; var parts = $routeParams.id.split("-"); var lastPart = parts.pop(); if (parts.length < 2 || (lastPart !== "id")) { @@ -16,15 +16,15 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l return $location.url(sprintf("/challenge-detail/%s-%s-id", title, contestId)); } - $scope.reviewPhase = function (index, phase) { - utils.sendNotification(jsonValue.notifications.loading); - if (index) { - $scope.selectedPhase = index; + $scope.reviewPhase = function (index, phase, nextPhase) { + var phaseName = phase ? phase.phase : jsonValue.challengePhase.getRegistration().enum; + if (index && index > activePhaseIndex + 1) { + return; } else { - $scope.selectedPhase = 0; + $('.feedback-loading').css('visibility', 'inherit'); + $scope.selectedPhase = index; } - var phaseName = phase ? phase.phase : jsonValue.challengePhase.getRegistration().enum; apiService.getChallengeRegistrantsByPhase(contestId, phaseName).success(function (data) { $scope.registrantPhase = data; @@ -47,6 +47,9 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l } }).finally(function () { utils.sendNotification(jsonValue.notifications.loaded); + $timeout(function () { + $('.feedback-loading').css('visibility', 'hidden'); + }, 1200); }); }; @@ -56,22 +59,21 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l } $scope.sortBySubmissionDate = function () { - $scope.sortByRegistrationDateType = $scope.sortByRegistrationDateType == "asc" ? "desc" : "asc"; - utils.sortByNumber($scope.registrantPhase, "challengeSubmissionId", $scope.sortBySubmissionDateType); + $scope.sortBySubmissionDateType = $scope.sortBySubmissionDateType == "asc" ? "desc" : "asc"; + $scope.registrantPhase.sort(function (a, b) { + var interval = $scope.sortBySubmissionDateType == "asc" ? 1 : -1; + return interval * ((b.lastSubmission ? b.lastSubmission.challengeSubmissionId : 0) - (a.lastSubmission ? a.lastSubmission.challengeSubmissionId : 0)); + }); } $scope.sortByScore = function () { $scope.sortByScoreType = $scope.sortByScoreType == "asc" ? "desc" : "asc"; - utils.sortByNumber($scope.registrantPhase, "score", $scope.sortByScoreType); + $scope.registrantPhase.sort(function (a, b) { + var interval = $scope.sortByScoreType == "asc" ? 1 : -1; + return interval * ((b.totalPoint ? b.totalPoint : 0) - (a.totalPoint ? a.totalPoint : 0)); + }); }; - //$scope.sortBySubmissionDate = function () { - // $scope.sortByRegistrationDateType = $scope.sortByRegistrationDateType == "asc" ? "desc" : "asc"; - // utils.sortByNumber($scope.registrantPhase, "challengeSubmissionId", $scope.sortBySubmissionDateType); - //} - - $scope.reviewPhase(); - $scope.failJoin = false; $scope.action = ''; $scope.actionContent = ''; @@ -158,12 +160,13 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l localStorageService.set("joinContests", joinContests.join(",")); $filter("progress")($scope.contestDetail, "challenge"); - $scope.filterContestant(); + //$scope.filterContestant(); }) .error(function () { $scope.failJoin = true; }); } + apiService.getContestDetail(contestId) .success(function (data) { $scope.contestDetail = data; @@ -198,10 +201,16 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l $scope.registrantFunnel.currentPosition = i; } }); + //$scope.selectedPhase = $scope.registrantFunnel.currentPosition; + activePhaseIndex = $scope.registrantFunnel.currentPosition; + $scope.reviewPhase($scope.registrantFunnel.currentPosition, {phase: $scope.contestDetail.currentPhase}); + utils.sendNotification(jsonValue.notifications.loaded); }).error(function () { console.log('error'); + utils.sendNotification(jsonValue.notifications.loaded); }); } + $scope.fbShare = function () { ga("send", { hitType: "event", @@ -216,81 +225,6 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l $scope.sortKey = keyname; //set the sortKey to the param passed $scope.reverse = !$scope.reverse; //if true make it false and vice versa }; - //$scope.filterContestant = function () { - // utils.sendNotification(jsonValue.notifications.loading); - // var param = $location.search(); - // var registrantFilterCondition = {}; - // registrantFilterCondition.challengeId = contestId; - // - // if ($scope.filterType) { - // registrantFilterCondition.filterType = $scope.filterType; - // } else if (param.filterType) { - // registrantFilterCondition.filterType = param.filterType; - // $scope.filterType = param.filterType; - // } else { - // registrantFilterCondition.filterType = "registrantId"; - // } - // - // if ($scope.phase) { - // registrantFilterCondition.phase = $scope.phase; - // } else if (param.phase) { - // registrantFilterCondition.phase = param.phase; - // $scope.phase = param.phase; - // } else { - // registrantFilterCondition.phase = ""; - // } - // - // if ($scope.fromDate) { - // registrantFilterCondition.fromDate = $scope.fromDate; - // } else { - // registrantFilterCondition.fromDate = param.fromDate; - // $scope.fromDate = param.fromDate; - // } - // - // if ($scope.toDate) { - // registrantFilterCondition.toDate = $scope.toDate; - // } else { - // registrantFilterCondition.toDate = param.toDate; - // $scope.toDate = param.toDate - // } - // - // apiService.getChallengeRegistrants(registrantFilterCondition) - // .success(function (registrants) { - // $scope.registrants = registrants; - // //$scope.sortByStartDate(); - // if (param.a == "registrants") { - // var registrantTab = $('.nav-tabs a[href=".registrants"]'); - // if (registrantTab) { - // registrantTab.tab('show'); - // } - // } - // }).finally(function () { - // utils.sendNotification(jsonValue.notifications.loaded); - // }); - //}; - // - //$scope.filterContestant(); - - - // - //$scope.sortByStartDate = function () { - // delete $scope.sortScore; - // $scope.sortStartDate = $scope.sortStartDate || "asc"; - // $scope.sortStartDate = $(["asc", "desc"]).not([$scope.sortStartDate]).get()[0]; - // utils.sortByNumber($scope.registrants, "registrantId", $scope.sortStartDate); - //} - - //$scope.updateScore = function (registrant, $event) { - // $($event.currentTarget).addClass('green'); - // apiService.saveChallengeRegistrant(registrant) - // .success(function (rt) { - // registrant.score = rt.score; - // }).finally(function () { - // $timeout(function () { - // $($event.currentTarget).removeClass('green'); - // }, 1000); - // }); - //} $scope.config = { registrantsFilter: resourcesService.registrantsFilterConfig, @@ -311,5 +245,13 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l $scope.contestDetail.saveCriteria(); } + + $scope.$on("update-funnel", function (sc, registrant) { + $scope.getRegistrants(registrant.challengeId); + }); + + $scope.$on("success-submission-challenge", function (sc, registrant) { + $scope.getRegistrants(registrant.challengeId); + }); }); diff --git a/src/main/webapp/assets/modules/contest-detail/contestDetailDirective.js b/src/main/webapp/assets/modules/contest-detail/contestDetailDirective.js index 4548b3a6b..184d8d899 100644 --- a/src/main/webapp/assets/modules/contest-detail/contestDetailDirective.js +++ b/src/main/webapp/assets/modules/contest-detail/contestDetailDirective.js @@ -48,14 +48,23 @@ techlooper }); scope.registrant.qualify = function () { + if (scope.registrant.activePhase == scope.challenge.nextPhase) { + delete scope.registrant.visible; + return; + } + delete scope.registrant.disqualified; delete scope.registrant.disqualifiedReason; scope.registrant.activePhase = scope.challenge.nextPhase; apiService.saveChallengeRegistrant(scope.registrant) - .success(function() { - apiService.acceptChallengeRegistrant(scope.registrant.registrantId); + .success(function () { + apiService.acceptChallengeRegistrant(scope.registrant.registrantId) + .success(function (registrant) { + $rootScope.$broadcast("update-funnel", registrant); + }); }); scope.registrant.qualified = true; + delete scope.registrant.visible; }; @@ -98,8 +107,7 @@ techlooper scope.$on("success-submission-challenge", function (sc, submission) { if (scope.registrant.registrantId != submission.registrantId) return; - scope.registrant.submissions.unshift(submission); - console.log(scope.registrant.submissions); + scope.registrant.acceptSubmission(submission); }); utils.sortByNumber(scope.registrant.submissions, "challengeSubmissionId"); diff --git a/src/main/webapp/assets/modules/contest-detail/contestDetailQualification.html b/src/main/webapp/assets/modules/contest-detail/contestDetailQualification.html index 6b191e752..a69d0f3fa 100644 --- a/src/main/webapp/assets/modules/contest-detail/contestDetailQualification.html +++ b/src/main/webapp/assets/modules/contest-detail/contestDetailQualification.html @@ -1,6 +1,7 @@
-

+

diff --git a/src/main/webapp/assets/modules/contest-detail/contestDetailReviewSubmission.html b/src/main/webapp/assets/modules/contest-detail/contestDetailReviewSubmission.html index ad1473cf5..2f5b59de2 100644 --- a/src/main/webapp/assets/modules/contest-detail/contestDetailReviewSubmission.html +++ b/src/main/webapp/assets/modules/contest-detail/contestDetailReviewSubmission.html @@ -1,16 +1,19 @@
-