Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: public namespace basic function #3850

Merged
merged 17 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from 9 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
7 changes: 7 additions & 0 deletions apollo-portal/src/main/resources/static/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,18 @@
"Index.LoadMore": "Load more",
"Index.FavoriteItems": "Favorite projects",
"Index.Topping": "Top",
"Index.FavoriteCancel": "Remove favorite",
"Index.FavoriteTip": "You haven't favorited any items yet. You can favorite items on the project homepage.",
"Index.RecentlyViewedItems": "Recent projects",
"Index.GetCreateAppRoleFailed": "Failed to get the information of create project permission",
"Index.Topped": "Top Successfully",
"Index.CancelledFavorite": "Remove favorite successfully",
"Index.PublicNamespace": "Public namespaces",
"Index.SearchNamespace": "Search Public Namespace(AppId or Namespace)",
"Index.PublicNamespaceTip": "You haven't created any public namespaces yet. You can create them in your projects.",
"Index.appTable.operation": "Operation",
"Index.appTable.Format": "Format",
"Index.appTable.Comment": "Comment",
"Cluster.CreateCluster": "Create Cluster",
"Cluster.Tips.1": "By adding clusters, the same program can use different configuration in different clusters (such as different data centers)",
"Cluster.Tips.2": "If the different clusters use the same configuration, there is no need to create clusters",
Expand Down
7 changes: 7 additions & 0 deletions apollo-portal/src/main/resources/static/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,18 @@
"Index.LoadMore": "加载更多",
"Index.FavoriteItems": "收藏的项目",
"Index.Topping": "置顶",
"Index.FavoriteCancel": "取消收藏",
"Index.FavoriteTip": "您还没有收藏过任何项目,在项目主页可以收藏项目哟~",
"Index.RecentlyViewedItems": "最近浏览的项目",
"Index.GetCreateAppRoleFailed": "获取创建应用权限信息失败",
"Index.Topped": "置顶成功",
"Index.CancelledFavorite": "取消收藏成功",
"Index.PublicNamespace": "公共Namespace",
"Index.SearchNamespace": "搜索公共Namespace(AppId、Namespace)",
"Index.PublicNamespaceTip": "您还没有任何公共Namespace,在你的项目中可以创建哟~",
"Index.appTable.operation": "操作",
"Index.appTable.Format": "格式",
"Index.appTable.Comment": "备注",
"Cluster.CreateCluster": "新建集群",
"Cluster.Tips.1": "通过添加集群,可以使同一份程序在不同的集群(如不同的数据中心)使用不同的配置",
"Cluster.Tips.2": "如果不同集群使用一样的配置,则没有必要创建集群",
Expand Down
240 changes: 172 additions & 68 deletions apollo-portal/src/main/resources/static/index.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,142 @@
*
*/
index_module.controller('IndexController', ['$scope', '$window', '$translate', 'toastr', 'AppUtil', 'AppService',
'UserService', 'FavoriteService',
IndexController]);
'UserService', 'FavoriteService', 'NamespaceService',
IndexController]
)
.directive('inputSelect', function() {
return {
link: function(scope, element, attr) {
element.on('click', function(evt) {
evt.target.parentElement.previousElementSibling.value = evt.target.textContent;
scope.inValue = evt.target.textContent;
if(evt.target.parentElement.getElementsByClassName('item-bg').length){
angular.element(evt.target.parentElement.getElementsByClassName('item-bg')[0]).removeClass('item-bg');
}
angular.element(evt.target).addClass('item-bg');
angular.element(evt.target.parentElement).addClass('hidden-cls');
return true;
});
}
};
})
.directive('inputSearch', function() {
nobodyiam marked this conversation as resolved.
Show resolved Hide resolved
return {
link: function(scope, element, attr) {
var isFocus = true;
var isOver = false;
element.on('focus', function(){
angular.element(this.nextElementSibling).removeClass('hidden-cls');
})
element.on('keydown', function(evt){
if(!this.nextElementSibling.children.length){
return false;
}
if(isFocus){
var currentLi = this.parentElement.getElementsByClassName('item-bg')[0];
if(38 === evt.keyCode && currentLi && currentLi.previousElementSibling){//向上
var currentLi = this.parentElement.getElementsByClassName('item-bg')[0],
liHeight = currentLi ? currentLi.clientHeight : '',
offTop = liHeight;
angular.element(currentLi).removeClass('item-bg');
angular.element(currentLi.previousElementSibling).addClass('item-bg');

for(var i = 0, len = this.nextElementSibling.children.length; i < len; i++){
if(this.nextElementSibling.children[i] === currentLi){
break;
}
offTop = offTop + liHeight;
}
offTop = Math.max(0, offTop - 2 * liHeight);
if(this.nextElementSibling.scrollTop > offTop){
this.nextElementSibling.scrollTop = offTop;
}
}else if(40 === evt.keyCode){//向下
var currentLi = this.parentElement.getElementsByClassName('item-bg')[0],
liHeight = currentLi ? currentLi.clientHeight : '',
offTop = liHeight;
if(!currentLi){
angular.element(this.nextElementSibling.firstElementChild).addClass('item-bg');
return true;
}
if(currentLi.nextElementSibling){
angular.element(currentLi).removeClass('item-bg');
angular.element(currentLi.nextElementSibling).addClass('item-bg');
}

for(var i = 0, len = this.nextElementSibling.children.length; i < len; i++){
if(this.nextElementSibling.children[i] === currentLi){
break;
}
offTop = offTop + liHeight;
}
if(this.nextElementSibling.scrollTop > offTop){
return false;
}
if(this.nextElementSibling.clientHeight < offTop && this.nextElementSibling.scrollTop + this.nextElementSibling.clientHeight - liHeight < offTop){
this.nextElementSibling.scrollTop = offTop - this.nextElementSibling.clientHeight + liHeight;
}

}else if(13 === evt.keyCode && currentLi){
var isHidden = angular.element(evt.target.nextElementSibling).hasClass('hidden-cls');
if(isHidden){
angular.element(evt.target.nextElementSibling).removeClass('hidden-cls');
}else{
evt.target.value = currentLi.innerText;
angular.element(currentLi.parentElement).addClass('hidden-cls');
scope.inValue = evt.target.value;
}
}
}
})
element.on('input',function(evt){
if(angular.element(this.nextElementSibling).hasClass('hidden-cls')){
angular.element(this.nextElementSibling).removeClass('hidden-cls')
}
if(this.nextElementSibling.children.length){
angular.element(this.nextElementSibling.getElementsByClassName('item-bg')[0]).removeClass('item-bg');
angular.element(this.nextElementSibling.children[0]).addClass('item-bg');
}
scope.$emit('selectInput', {
inputId: evt.target.id,
inputText: evt.target.value
});
});
angular.element(element[0].nextElementSibling).on('mousemove', function(){
isOver = true;
})
angular.element(element[0].nextElementSibling).on('mouseleave', function(){
isOver = false;
})
element.on('blur',function(evt){
if(!isOver){
angular.element(this.nextElementSibling).addClass('hidden-cls');
}
});
}
};
});

function IndexController($scope, $window, $translate, toastr, AppUtil, AppService, UserService, FavoriteService) {
function IndexController($scope, $window, $translate, toastr, AppUtil, AppService, UserService, FavoriteService, NamespaceService) {

$scope.userId = '';
$scope.whichContent = '1';

$scope.getUserCreatedApps = getUserCreatedApps;
$scope.getUserFavorites = getUserFavorites;

$scope.getPublicNamespaces = getPublicNamespaces;
$scope.goToAppHomePage = goToAppHomePage;
$scope.goToCreateAppPage = goToCreateAppPage;
$scope.toggleOperationBtn = toggleOperationBtn;
$scope.toTop = toTop;
$scope.deleteFavorite = deleteFavorite;
$scope.morePublicNamespace = morePublicNamespace;
$scope.changeContent = changeContent;

$scope.inValue = '';
$scope.inValue_display = '';
$scope.initList = [];
$scope.dataList = [];

function initCreateApplicationPermission() {
AppService.has_create_application_role($scope.userId).then(
Expand All @@ -51,6 +172,10 @@ function IndexController($scope, $window, $translate, toastr, AppUtil, AppServic
$scope.favoritesPage = 0;
$scope.favorites = [];
$scope.hasMoreFavorites = true;
$scope.publicNamespacePage = 0;
$scope.publicNamespaces = [];
$scope.hasMorePublicNamespaces = true;
$scope.allPublicNamespaces = [];
$scope.visitedApps = [];

initCreateApplicationPermission();
Expand All @@ -59,7 +184,10 @@ function IndexController($scope, $window, $translate, toastr, AppUtil, AppServic

getUserFavorites();

getPublicNamespaces();

initUserVisitedApps();

});

function getUserCreatedApps() {
Expand Down Expand Up @@ -114,11 +242,22 @@ function IndexController($scope, $window, $translate, toastr, AppUtil, AppServic
app.favoriteId = favorite.id;
$scope.favorites.push(app);
});

});
})
}

function getPublicNamespaces() {
var size = 10;
nobodyiam marked this conversation as resolved.
Show resolved Hide resolved
NamespaceService.find_public_namespaces()
.then(function (result) {
$scope.allPublicNamespaces = result;
nobodyiam marked this conversation as resolved.
Show resolved Hide resolved
$scope.dataList = $scope.allPublicNamespaces;
$scope.initList = $scope.allPublicNamespaces;
console.log("dataList",$scope.dataList);
morePublicNamespace();
})
}

function initUserVisitedApps() {
var VISITED_APPS_STORAGE_KEY = "VisitedAppsV2";
var visitedAppsObject = JSON.parse(localStorage.getItem(VISITED_APPS_STORAGE_KEY));
Expand Down Expand Up @@ -182,4 +321,41 @@ function IndexController($scope, $window, $translate, toastr, AppUtil, AppServic
getUserFavorites();
}

function morePublicNamespace() {
var rest = $scope.allPublicNamespaces.length - $scope.publicNamespacePage * 10;
if (rest <= 10) {
for (var i = 0; i < rest; i++) {
$scope.publicNamespaces.push($scope.allPublicNamespaces[$scope.publicNamespacePage * 10 + i])
}
$scope.hasMorePublicNamespaces = false;
} else {
for (var j = 0; j < 10; j++) {
$scope.publicNamespaces.push($scope.allPublicNamespaces[$scope.publicNamespacePage * 10 + j])
}
}
$scope.publicNamespacePage += 1;
}

function changeContent(contentIndex) {
$scope.whichContent = contentIndex;
}

$scope.$on('selectInput', function (evt, inputObj) {
if (inputObj.inputId === 'select-input-mark') {
$scope.inValue = '';
$scope.inValue_display = inputObj.inputText;
$scope.fuzzyQuery();
}
});
$scope.fuzzyQuery = function () {
$scope.dataList = [];
angular.forEach($scope.initList, function (item) {
if (item.name.indexOf($scope.inValue_display) !== -1) {
$scope.dataList.push(item);
}
});
$scope.$apply();
console.log($scope.dataList);
};

}
Loading