Commit 28e4fc16 by Jason Song Committed by GitHub

Merge pull request #430 from lepdou/index_page_refactor

bugfix:add illegal appId to visited app list
parents c57a690b 174a4c75
......@@ -13,7 +13,7 @@ public interface FavoriteRepository extends PagingAndSortingRepository<Favorite,
List<Favorite> findByAppIdOrderByPositionAscDataChangeCreatedTimeAsc(String appId, Pageable page);
Favorite findFirst1ByUserIdOrderByPositionAscDataChangeCreatedTimeAsc(String userId);
Favorite findFirstByUserIdOrderByPositionAscDataChangeCreatedTimeAsc(String userId);
Favorite findByUserIdAndAppId(String userId, String appId);
}
......@@ -91,7 +91,7 @@ public class FavoriteService {
checkUserOperatePermission(favorite);
String userId = favorite.getUserId();
Favorite firstFavorite = favoriteRepository.findFirst1ByUserIdOrderByPositionAscDataChangeCreatedTimeAsc(userId);
Favorite firstFavorite = favoriteRepository.findFirstByUserIdOrderByPositionAscDataChangeCreatedTimeAsc(userId);
long minPosition = firstFavorite.getPosition();
favorite.setPosition(minPosition - 1);
......
......@@ -25,50 +25,15 @@ function ConfigBaseInfoController($rootScope, $scope, $location, toastr, UserSer
UserService.load_user().then(function (result) {
$rootScope.pageContext.userId = result.userId;
loadAppInfo();
handleFavorite();
recordVisitApp();
},function (result) {
toastr.error(AppUtil.errorMsg(result), "获取用户登录信息失败");
});
loadAppInfo();
handlePermission();
}
function recordVisitApp() {
//save user recent visited apps
var VISITED_APPS_STORAGE_KEY = "VisitedAppsV2";
var visitedAppsObject = JSON.parse(localStorage.getItem(VISITED_APPS_STORAGE_KEY));
var hasSaved = false;
if (visitedAppsObject) {
var visitedApps = visitedAppsObject[$rootScope.pageContext.userId];
if (visitedApps && visitedApps.length > 0){
visitedApps.forEach(function (app) {
if (app == appId) {
hasSaved = true;
return;
}
});
}
} else {
visitedAppsObject = {};
visitedAppsObject[$rootScope.pageContext.userId] = [];
}
var currentUserVisitedApps = visitedAppsObject[$rootScope.pageContext.userId];
if (!hasSaved) {
//if queue's length bigger than 6 will remove oldest app
if (currentUserVisitedApps.length >= 6){
currentUserVisitedApps.splice(0, 1);
}
currentUserVisitedApps.push($rootScope.pageContext.appId);
localStorage.setItem(VISITED_APPS_STORAGE_KEY,
JSON.stringify(visitedAppsObject));
}
}
function loadAppInfo() {
$scope.notFoundApp = true;
AppService.load($rootScope.pageContext.appId).then(function (result) {
......@@ -78,6 +43,7 @@ function ConfigBaseInfoController($rootScope, $scope, $location, toastr, UserSer
$scope.appBaseInfo.orgInfo = result.orgName + '(' + result.orgId + ')';
loadNavTree();
recordVisitApp();
$(".J_appFound").removeClass("hidden");
}, function (result) {
......@@ -112,6 +78,41 @@ function ConfigBaseInfoController($rootScope, $scope, $location, toastr, UserSer
};
}
function recordVisitApp() {
//save user recent visited apps
var VISITED_APPS_STORAGE_KEY = "VisitedAppsV2";
var visitedAppsObject = JSON.parse(localStorage.getItem(VISITED_APPS_STORAGE_KEY));
var hasSaved = false;
if (visitedAppsObject) {
var visitedApps = visitedAppsObject[$rootScope.pageContext.userId];
if (visitedApps && visitedApps.length > 0) {
visitedApps.forEach(function (app) {
if (app == appId) {
hasSaved = true;
return;
}
});
}
} else {
visitedAppsObject = {};
visitedAppsObject[$rootScope.pageContext.userId] = [];
}
var currentUserVisitedApps = visitedAppsObject[$rootScope.pageContext.userId];
if (!hasSaved) {
//if queue's length bigger than 6 will remove oldest app
if (currentUserVisitedApps.length >= 6) {
currentUserVisitedApps.splice(0, 1);
}
currentUserVisitedApps.push($rootScope.pageContext.appId);
localStorage.setItem(VISITED_APPS_STORAGE_KEY,
JSON.stringify(visitedAppsObject));
}
}
function loadNavTree() {
AppService.load_nav_tree($rootScope.pageContext.appId).then(function (result) {
var navTree = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment