From e814cc0fe55fd032e736fc2c3b8a882e7c6826d3 Mon Sep 17 00:00:00 2001 From: johnsonpham Date: Fri, 9 Jan 2015 13:14:22 +0700 Subject: [PATCH 1/3] keep navigtion bar open when user refresh page if it open before --- src/main/webapp/assets/modules/chart/chart.con.js | 1 + src/main/webapp/assets/modules/common/json.val.js | 3 ++- .../webapp/assets/modules/navigation/navigation.ser.js | 10 +++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/webapp/assets/modules/chart/chart.con.js b/src/main/webapp/assets/modules/chart/chart.con.js index 3bae3d862..d3681a703 100644 --- a/src/main/webapp/assets/modules/chart/chart.con.js +++ b/src/main/webapp/assets/modules/chart/chart.con.js @@ -15,4 +15,5 @@ angular.module('Chart').controller('chartController', function ($scope, jsonValu connectionFactory.receiveTechnicalTerms(); navigationService.reSetingPositionLangIcon(); + navigationService.keepNaviBar(); }); \ No newline at end of file diff --git a/src/main/webapp/assets/modules/common/json.val.js b/src/main/webapp/assets/modules/common/json.val.js index 9b6e29625..3af075061 100644 --- a/src/main/webapp/assets/modules/common/json.val.js +++ b/src/main/webapp/assets/modules/common/json.val.js @@ -7,7 +7,8 @@ angular.module("Common").constant("jsonValue", { storage: { key: "key", - back2Me: "back2Me" + back2Me: "back2Me", + navigation: "navigation" }, histograms: { diff --git a/src/main/webapp/assets/modules/navigation/navigation.ser.js b/src/main/webapp/assets/modules/navigation/navigation.ser.js index e5857f8bb..224622426 100644 --- a/src/main/webapp/assets/modules/navigation/navigation.ser.js +++ b/src/main/webapp/assets/modules/navigation/navigation.ser.js @@ -1,7 +1,8 @@ -angular.module("Navigation").factory("navigationService", function (utils, jsonValue, $rootScope, $http, $location, tourService, userService) { +angular.module("Navigation").factory("navigationService", function (localStorageService, utils, jsonValue, $rootScope, $http, $location, tourService, userService) { var $$ = { naviControl: function () { + //localStorageService.set(jsonValue.storage.navigation, 'close'); $('.manager-navi').find('.fa-bars').on('tap click', function () { if ($(this).hasClass('active')) { $('.main-navi-block').animate({ @@ -22,6 +23,7 @@ angular.module("Navigation").factory("navigationService", function (utils, jsonV }); $(this).removeClass('active'); + localStorageService.set(jsonValue.storage.navigation, 'close'); } else { var view = utils.getView(); @@ -41,6 +43,7 @@ angular.module("Navigation").factory("navigationService", function (utils, jsonV 'width': '100%' }).css('display', 'block'); $(this).addClass('active'); + localStorageService.set(jsonValue.storage.navigation, 'open'); } }); }, @@ -156,7 +159,8 @@ angular.module("Navigation").factory("navigationService", function (utils, jsonV $('.main-navi-block').css('background','url(images/line-h.png) #000 right top repeat-y'); }, keepNaviBar: function(){ - utils.registerNotification(jsonValue.notifications.userInfo, function(userInfo) { + var status = localStorageService.get(jsonValue.storage.navigation); + if(status == 'open'){ $('.main-navi-block').css({ 'width': '85px', 'position': 'fixed' @@ -164,7 +168,7 @@ angular.module("Navigation").factory("navigationService", function (utils, jsonV $('.navi-container').css({'width': '100%', 'display': 'block'}); $('.manager-navi').find('.fa-bars').addClass('active'); instance.addSpaceforNavi(); - }); + } } } From 1da0105b1033fca47532ddfdca2b87bfb8891f02 Mon Sep 17 00:00:00 2001 From: johnsonpham Date: Fri, 9 Jan 2015 13:38:19 +0700 Subject: [PATCH 2/3] remove console.log in history.fac.js --- src/main/webapp/assets/modules/common/history.fac.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/webapp/assets/modules/common/history.fac.js b/src/main/webapp/assets/modules/common/history.fac.js index 9eb08c5e8..ef6baa9c2 100644 --- a/src/main/webapp/assets/modules/common/history.fac.js +++ b/src/main/webapp/assets/modules/common/history.fac.js @@ -10,7 +10,6 @@ angular.module("Common").factory("historyFactory", function (jsonValue, $locatio $("body").css("background-color", "#201d1e"); instance.trackHistory(); } - console.log(historyStack); utils.sendNotification(jsonValue.notifications.changeUrl/*, current.$$route.originalPath, next.$$route.originalPath*/); }); From e7192bb7e8248884b582252808d2d3e231bbba51 Mon Sep 17 00:00:00 2001 From: khoa-nd Date: Fri, 9 Jan 2015 14:27:43 +0700 Subject: [PATCH 3/3] Async call to social network to fetch user info --- .../service/impl/AbstractSocialService.java | 92 ++++++++++--------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/techlooper/service/impl/AbstractSocialService.java b/src/main/java/com/techlooper/service/impl/AbstractSocialService.java index 4e1639943..ea94dfb0f 100644 --- a/src/main/java/com/techlooper/service/impl/AbstractSocialService.java +++ b/src/main/java/com/techlooper/service/impl/AbstractSocialService.java @@ -20,6 +20,7 @@ import javax.annotation.Resource; import java.util.Optional; +import java.util.concurrent.CompletableFuture; import static com.techlooper.entity.AccessGrant.AccessGrantBuilder.accessGrant; import static com.techlooper.entity.UserEntity.UserEntityBuilder.userEntity; @@ -29,60 +30,65 @@ */ public abstract class AbstractSocialService implements SocialService { - @Resource - protected UserService userService; + @Resource + protected UserService userService; - @Resource - protected Mapper dozerBeanMapper; + @Resource + protected Mapper dozerBeanMapper; - @Resource - protected TextEncryptor textEncryptor; + @Resource + protected TextEncryptor textEncryptor; - protected SocialConfig socialConfig; + protected SocialConfig socialConfig; - public AbstractSocialService(JsonConfigRepository jsonConfigRepository, SocialProvider socialProvider) { - socialConfig = jsonConfigRepository.getSocialConfig().stream() - .filter(config -> socialProvider == config.getProvider()).findFirst().get(); - } + public AbstractSocialService(JsonConfigRepository jsonConfigRepository, SocialProvider socialProvider) { + socialConfig = jsonConfigRepository.getSocialConfig().stream() + .filter(config -> socialProvider == config.getProvider()).findFirst().get(); + } + + public com.techlooper.entity.AccessGrant getAccessGrant(String accessCode) { + AccessGrant access = getOAuth2ConnectionFactory().getOAuthOperations().exchangeForAccess(accessCode, socialConfig.getRedirectUri(), null); + return dozerBeanMapper.map(access, com.techlooper.entity.AccessGrant.class); + } - public com.techlooper.entity.AccessGrant getAccessGrant(String accessCode) { - AccessGrant access = getOAuth2ConnectionFactory().getOAuthOperations().exchangeForAccess(accessCode, socialConfig.getRedirectUri(), null); - return dozerBeanMapper.map(access, com.techlooper.entity.AccessGrant.class); - } + public com.techlooper.entity.AccessGrant getAccessGrant(String accessToken, String accessSecret) { + OAuth1Operations oAuthOperations = getOAuth1ConnectionFactory().getOAuthOperations(); + if (Optional.ofNullable(accessToken).isPresent()) { + OAuthToken token = oAuthOperations.exchangeForAccessToken( + new AuthorizedRequestToken(new OAuthToken(accessToken, null), accessSecret), null); + return dozerBeanMapper.map(token, com.techlooper.entity.AccessGrant.class); + } + OAuthToken token = oAuthOperations.fetchRequestToken(socialConfig.getRedirectUri(), null); + String authorizeUrl = oAuthOperations.buildAuthorizeUrl(token.getValue(), OAuth1Parameters.NONE); + return accessGrant().withAuthorizeUrl(authorizeUrl).build(); + } - public com.techlooper.entity.AccessGrant getAccessGrant(String accessToken, String accessSecret) { - OAuth1Operations oAuthOperations = getOAuth1ConnectionFactory().getOAuthOperations(); - if (Optional.ofNullable(accessToken).isPresent()) { - OAuthToken token = oAuthOperations.exchangeForAccessToken( - new AuthorizedRequestToken(new OAuthToken(accessToken, null), accessSecret), null); - return dozerBeanMapper.map(token, com.techlooper.entity.AccessGrant.class); + protected AccessGrant getAccessGrant(com.techlooper.entity.AccessGrant accessGrant) { + return new AccessGrant(accessGrant.getAccessToken(), accessGrant.getScope(), accessGrant.getRefreshToken(), accessGrant.getExpireTime()); } - OAuthToken token = oAuthOperations.fetchRequestToken(socialConfig.getRedirectUri(), null); - String authorizeUrl = oAuthOperations.buildAuthorizeUrl(token.getValue(), OAuth1Parameters.NONE); - return accessGrant().withAuthorizeUrl(authorizeUrl).build(); - } - protected AccessGrant getAccessGrant(com.techlooper.entity.AccessGrant accessGrant) { - return new AccessGrant(accessGrant.getAccessToken(), accessGrant.getScope(), accessGrant.getRefreshToken(), accessGrant.getExpireTime()); - } + public OAuth2ConnectionFactory getOAuth2ConnectionFactory() { + throw new UnsupportedOperationException("Method is not supported"); + } + + public OAuth1ConnectionFactory getOAuth1ConnectionFactory() { + throw new UnsupportedOperationException("Method is not supported"); + } - public OAuth2ConnectionFactory getOAuth2ConnectionFactory() { - throw new UnsupportedOperationException("Method is not supported"); - } + public abstract UserProfile getProfile(com.techlooper.entity.AccessGrant accessGrant); - public OAuth1ConnectionFactory getOAuth1ConnectionFactory() { - throw new UnsupportedOperationException("Method is not supported"); - } + public UserEntity saveFootprint(com.techlooper.entity.AccessGrant accessGrant, String key) { + UserEntity entity = userService.findUserEntityByKey(key); + if (!Optional.ofNullable(entity).isPresent()) { + throw new EntityNotFoundException("Can not find User by key: " + key); + } - public abstract UserProfile getProfile(com.techlooper.entity.AccessGrant accessGrant); + CompletableFuture.supplyAsync(() -> getProfile(accessGrant)).thenAccept((profile) -> { + userEntity(entity).withProfile(socialConfig.getProvider(), profile); + userService.save(entity); + }); - public UserEntity saveFootprint(com.techlooper.entity.AccessGrant accessGrant, String key) { - UserEntity entity = userService.findUserEntityByKey(key); - if (!Optional.ofNullable(entity).isPresent()) { - throw new EntityNotFoundException("Can not find User by key: " + key); + userEntity(entity).withProfile(socialConfig.getProvider(), null); + return entity; } - userEntity(entity).withProfile(socialConfig.getProvider(), getProfile(accessGrant)); - userService.save(entity); - return entity; - } }