Răsfoiți Sursa

add history query. (#3878)

* add history query.

* add CHANGES.md.
Zhuohao Li 3 ani în urmă
părinte
comite
9e0b1ee9a9

+ 1 - 0
CHANGES.md

@@ -75,6 +75,7 @@ Apollo 1.9.0
 * [use jdk 8 to publish apollo-client-config-data](https://github.com/ctripcorp/apollo/pull/3880)
 * [fix apollo config data loader with profiles](https://github.com/ctripcorp/apollo/pull/3870)
 * [polish log](https://github.com/ctripcorp/apollo/pull/3882)
+* [add history query](https://github.com/ctripcorp/apollo/pull/3878)
 
 ------------------
 All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/6?closed=1)

+ 10 - 3
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/CommitController.java

@@ -20,9 +20,11 @@ import com.ctrip.framework.apollo.biz.entity.Commit;
 import com.ctrip.framework.apollo.biz.service.CommitService;
 import com.ctrip.framework.apollo.common.dto.CommitDTO;
 import com.ctrip.framework.apollo.common.utils.BeanUtils;
+import com.ctrip.framework.apollo.core.utils.StringUtils;
 import org.springframework.data.domain.Pageable;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
@@ -39,9 +41,14 @@ public class CommitController {
 
   @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit")
   public List<CommitDTO> find(@PathVariable String appId, @PathVariable String clusterName,
-                              @PathVariable String namespaceName, Pageable pageable){
-
-    List<Commit> commits = commitService.find(appId, clusterName, namespaceName, pageable);
+                              @PathVariable String namespaceName, @RequestParam(required = false) String key, Pageable pageable){
+
+    List<Commit> commits;
+    if (StringUtils.isEmpty(key)) {
+      commits = commitService.find(appId, clusterName, namespaceName, pageable);
+    } else {
+      commits = commitService.findByKey(appId, clusterName, namespaceName, key, pageable);
+    }
     return BeanUtils.batchTransform(CommitDTO.class, commits);
   }
 

+ 1 - 0
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java

@@ -38,4 +38,5 @@ public interface CommitRepository extends PagingAndSortingRepository<Commit, Lon
   @Query("update Commit set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3")
   int batchDelete(String appId, String clusterName, String namespaceName, String operator);
 
+  List<Commit> findByAppIdAndClusterNameAndNamespaceNameAndChangeSetsLikeOrderByIdDesc(String appId, String clusterName, String namespaceName,String changeSets, Pageable page);
 }

+ 5 - 0
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java

@@ -51,6 +51,11 @@ public class CommitService {
             appId, clusterName, namespaceName, lastModifiedTime, page);
   }
 
+  public List<Commit> findByKey(String appId, String clusterName, String namespaceName, String key,Pageable page){
+    String queryKey = "\"key\":\""+ key +"\"";
+    return commitRepository.findByAppIdAndClusterNameAndNamespaceNameAndChangeSetsLikeOrderByIdDesc(appId, clusterName, namespaceName, "%"+ queryKey + "%", page);
+  }
+
   @Transactional
   public int batchDelete(String appId, String clusterName, String namespaceName, String operator){
     return commitRepository.batchDelete(appId, clusterName, namespaceName, operator);

+ 10 - 0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java

@@ -383,6 +383,16 @@ public class AdminServiceAPI {
 
       return Arrays.asList(commitDTOs);
     }
+
+    public List<CommitDTO> findByKey(String appId, Env env, String clusterName, String namespaceName, String key, int page, int size) {
+
+      CommitDTO[] commitDTOs = restTemplate.get(env,
+              "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?key={key}&page={page}&size={size}",
+              CommitDTO[].class,
+              appId, clusterName, namespaceName, key, page, size);
+
+      return Arrays.asList(commitDTOs);
+    }
   }
 
   @Service

+ 8 - 1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/CommitController.java

@@ -17,6 +17,7 @@
 package com.ctrip.framework.apollo.portal.controller;
 
 import com.ctrip.framework.apollo.common.dto.CommitDTO;
+import com.ctrip.framework.apollo.core.utils.StringUtils;
 import com.ctrip.framework.apollo.portal.environment.Env;
 import com.ctrip.framework.apollo.portal.component.PermissionValidator;
 import com.ctrip.framework.apollo.portal.service.CommitService;
@@ -47,12 +48,18 @@ public class CommitController {
   @GetMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/commits")
   public List<CommitDTO> find(@PathVariable String appId, @PathVariable String env,
                               @PathVariable String clusterName, @PathVariable String namespaceName,
+                              @RequestParam(required = false) String key,
                               @Valid @PositiveOrZero(message = "page should be positive or 0") @RequestParam(defaultValue = "0") int page,
                               @Valid @Positive(message = "size should be positive number") @RequestParam(defaultValue = "10") int size) {
     if (permissionValidator.shouldHideConfigToCurrentUser(appId, env, namespaceName)) {
       return Collections.emptyList();
     }
 
-    return commitService.find(appId, Env.valueOf(env), clusterName, namespaceName, page, size);
+    if (StringUtils.isEmpty(key)) {
+      return commitService.find(appId, Env.valueOf(env), clusterName, namespaceName, page, size);
+    } else {
+      return commitService.findByKey(appId, Env.valueOf(env), clusterName, namespaceName, key, page, size);
+    }
+
   }
 }

+ 7 - 0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/CommitService.java

@@ -44,4 +44,11 @@ public class CommitService {
     return dtoList;
   }
 
+  public List<CommitDTO> findByKey(String appId, Env env, String clusterName, String namespaceName, String key, int page, int size) {
+    List<CommitDTO> dtoList = commitAPI.findByKey(appId, env, clusterName, namespaceName, key, page, size);
+    this.additionalUserInfoEnrichService.enrichAdditionalUserInfo(dtoList,
+            BaseDtoUserInfoEnrichedAdapter::new);
+    return dtoList;
+  }
+
 }

+ 2 - 0
apollo-portal/src/main/resources/static/i18n/en.json

@@ -242,6 +242,8 @@
   "Component.Namespace.Master.Items.Body.HistoryView.Deleted": "Delete",
   "Component.Namespace.Master.Items.Body.HistoryView.LoadMore": "Load more",
   "Component.Namespace.Master.Items.Body.HistoryView.NoHistory": "No Change History",
+  "Component.Namespace.Master.Items.Body.HistoryView.FilterHistory": "Filter History",
+  "Component.Namespace.Master.Items.Body.HistoryView.FilterHistory.SortByKey": "Filter the history by key",
   "Component.Namespace.Master.Items.Body.Instance.Tips": "Tips: Only show instances who have fetched configurations in the last 24 hrs ",
   "Component.Namespace.Master.Items.Body.Instance.UsedNewItem": "Instances using the latest configuration",
   "Component.Namespace.Master.Items.Body.Instance.NoUsedNewItem": "Instances using outdated configuration",

+ 2 - 0
apollo-portal/src/main/resources/static/i18n/zh-CN.json

@@ -242,6 +242,8 @@
   "Component.Namespace.Master.Items.Body.HistoryView.Deleted": "删除",
   "Component.Namespace.Master.Items.Body.HistoryView.LoadMore": "加载更多",
   "Component.Namespace.Master.Items.Body.HistoryView.NoHistory": "无更改历史",
+  "Component.Namespace.Master.Items.Body.HistoryView.FilterHistory": "过滤更改历史",
+  "Component.Namespace.Master.Items.Body.HistoryView.FilterHistory.SortByKey": "按key过滤更改历史",
   "Component.Namespace.Master.Items.Body.Instance.Tips": "实例说明:只展示最近一天访问过Apollo的实例",
   "Component.Namespace.Master.Items.Body.Instance.UsedNewItem": "使用最新配置的实例",
   "Component.Namespace.Master.Items.Body.Instance.NoUsedNewItem": "使用非最新配置的实例",

+ 34 - 0
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js

@@ -64,7 +64,9 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio
             scope.refreshNamespace = refreshNamespace;
             scope.switchView = switchView;
             scope.toggleItemSearchInput = toggleItemSearchInput;
+            scope.toggleHistorySearchInput = toggleHistorySearchInput;
             scope.searchItems = searchItems;
+            scope.searchHistory = searchHistory;
             scope.loadCommitHistory = loadCommitHistory;
             scope.toggleTextEditStatus = toggleTextEditStatus;
             scope.goToSyncPage = goToSyncPage;
@@ -129,6 +131,7 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio
                 namespace.displayControl = {
                     currentOperateBranch: 'master',
                     showSearchInput: false,
+                    showHistorySearchInput: false,
                     show: scope.showBody
                 };
                 scope.showNamespaceBody = namespace.showNamespaceBody ? true : scope.showBody;
@@ -472,6 +475,7 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio
                     scope.env,
                     namespace.baseInfo.clusterName,
                     namespace.baseInfo.namespaceName,
+                    namespace.HistorySearchKey,
                     namespace.commitPage,
                     size)
                     .then(function (result) {
@@ -859,6 +863,36 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio
                 namespace.viewItems = items;
             }
 
+            function toggleHistorySearchInput(namespace) {
+                namespace.displayControl.showHistorySearchInput = !namespace.displayControl.showHistorySearchInput;
+            }
+
+            function searchHistory(namespace) {
+                namespace.commits = [];
+                namespace.commitPage = 0;
+                var size = 10;
+                CommitService.find_commits(scope.appId,
+                    scope.env,
+                    namespace.baseInfo.clusterName,
+                    namespace.baseInfo.namespaceName,
+                    namespace.HistorySearchKey,
+                    namespace.commitPage,
+                    size)
+                    .then(function (result) {
+                        if (result.length < size) {
+                            namespace.hasLoadAllCommit = true;
+                        }
+
+                        for (var i = 0; i < result.length; i++) {
+                            //to json
+                            result[i].changeSets = JSON.parse(result[i].changeSets);
+                            namespace.commits.push(result[i]);
+                        }
+                    }, function (result) {
+                        toastr.error(AppUtil.errorMsg(result), $translate.instant('ApolloNsPanel.LoadingHistoryError'));
+                    });
+            }
+
             //normal release and gray release
             function publish(namespace) {
 

+ 2 - 1
apollo-portal/src/main/resources/static/scripts/services/CommitService.js

@@ -23,13 +23,14 @@ appService.service('CommitService', ['$resource', '$q','AppUtil', function ($res
         }
     });
     return {
-        find_commits: function (appId, env, clusterName, namespaceName, page, size) {
+        find_commits: function (appId, env, clusterName, namespaceName, key, page, size) {
             var d = $q.defer();
             commit_resource.find_commits({
                                              appId: appId,
                                              env: env,
                                              clusterName: clusterName,
                                              namespaceName: namespaceName,
+                                             key: key,
                                              page: page,
                                              size: size
                                          },

+ 13 - 0
apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html

@@ -191,6 +191,13 @@
                         data-target="#commitModal" ng-show="namespace.isTextEditing && namespace.viewType == 'text'"
                         ng-click="modifyByText(namespace)">
 
+                    <button type="button" class="btn btn-default btn-sm" data-tooltip="tooltip" data-placement="bottom"
+                            title="{{'Component.Namespace.Master.Items.Body.HistoryView.FilterHistory.SortByKey' | translate }}" ng-show="namespace.viewType == 'history' && namespace.displayControl.currentOperateBranch == 'master'
+                        && !namespace.isLinkedNamespace" ng-click="toggleHistorySearchInput(namespace)">
+                        <span class="glyphicon glyphicon-filter"></span>
+                        {{'Component.Namespace.Master.Items.Body.HistoryView.FilterHistory' | translate }}
+                    </button>
+
                     <button type="button" class="btn btn-default btn-sm" data-tooltip="tooltip" data-placement="bottom"
                         title="{{'Component.Namespace.Master.Items.SortByKey' | translate }}" ng-show="namespace.viewType == 'table' && namespace.displayControl.currentOperateBranch == 'master'
                         && !namespace.isLinkedNamespace" ng-click="toggleItemSearchInput(namespace)">
@@ -764,6 +771,12 @@
 
             <!--history view-->
             <div class="J_historyview history-view" ng-show="namespace.viewType == 'history'">
+                <!-- 过滤更改历史 -->
+                <div class="search-input" ng-show="namespace.displayControl.showHistorySearchInput">
+                    <input type="text" class="form-control"
+                           placeholder="{{'Component.Namespace.Master.Items.Body.FilterByKey' | translate }}"
+                           ng-model="namespace.HistorySearchKey" ng-change="searchHistory(namespace)">
+                </div>
                 <div class="media" ng-show="namespace.commits && namespace.commits.length"
                     ng-repeat="commits in namespace.commits">
                     <div class="media-body">