This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new 62b332e0ded api, ui: listing archived events (#7396)
62b332e0ded is described below

commit 62b332e0ded9ed8f4d3be3b36e56b6d24f5aa274
Author: Abhishek Kumar <[email protected]>
AuthorDate: Tue Apr 11 22:26:41 2023 +0530

    api, ui: listing archived events (#7396)
    
    Fixes #7217
    
    Signed-off-by: Abhishek Kumar <[email protected]>
---
 .../org/apache/cloudstack/api/ApiConstants.java    |  1 +
 .../api/command/user/event/ListEventsCmd.java      |  7 +++++
 .../cloudstack/api/response/EventResponse.java     |  8 ++++++
 .../java/com/cloud/api/query/QueryManagerImpl.java |  4 ++-
 .../java/com/cloud/event/dao/EventJoinDaoImpl.java |  3 ++
 ui/public/locales/en.json                          |  2 ++
 ui/src/components/view/InfoCard.vue                |  3 ++
 ui/src/config/section/event.js                     |  9 ++++++
 ui/src/views/AutogenView.vue                       | 32 ++++++++++++++++++----
 9 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java 
b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
index 5b7b4f674ca..6e93d45abdb 100644
--- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
@@ -32,6 +32,7 @@ public class ApiConstants {
     public static final String ALLOCATED_ONLY = "allocatedonly";
     public static final String ANNOTATION = "annotation";
     public static final String API_KEY = "apikey";
+    public static final String ARCHIVED = "archived";
     public static final String ASYNC_BACKUP = "asyncbackup";
     public static final String AUTO_SELECT = "autoselect";
     public static final String USER_API_KEY = "userapikey";
diff --git 
a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java
 
b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java
index 202bd36bdb5..89f1c7090e0 100644
--- 
a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java
+++ 
b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java
@@ -72,6 +72,9 @@ public class ListEventsCmd extends 
BaseListProjectAndAccountResourcesCmd {
     @Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, 
description = "the type of the resource associated with the event", 
since="4.17.0")
     private String resourceType;
 
+    @Parameter(name = ApiConstants.ARCHIVED, type = CommandType.BOOLEAN, 
description = "true to list archived events otherwise false", since="4.19.0")
+    private Boolean archived;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -116,6 +119,10 @@ public class ListEventsCmd extends 
BaseListProjectAndAccountResourcesCmd {
         return resourceType;
     }
 
+    public boolean getArchived() {
+        return archived != null && archived;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
diff --git 
a/api/src/main/java/org/apache/cloudstack/api/response/EventResponse.java 
b/api/src/main/java/org/apache/cloudstack/api/response/EventResponse.java
index a3ca777be5a..8f65492cb70 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/EventResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/EventResponse.java
@@ -93,6 +93,10 @@ public class EventResponse extends BaseResponse implements 
ControlledViewEntityR
     @Param(description = "whether the event is parented")
     private String parentId;
 
+    @SerializedName(ApiConstants.ARCHIVED)
+    @Param(description = "whether the event has been archived or not")
+    private Boolean archived;
+
     public void setId(String id) {
         this.id = id;
     }
@@ -173,4 +177,8 @@ public class EventResponse extends BaseResponse implements 
ControlledViewEntityR
     public void setProjectName(String projectName) {
         this.projectName = projectName;
     }
+
+    public void setArchived(Boolean archived) {
+        this.archived = archived;
+    }
 }
diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java 
b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
index 6fecd2c3c6d..c33aac83b40 100644
--- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
@@ -790,7 +790,9 @@ public class QueryManagerImpl extends 
MutualExclusiveIdsManagerBase implements Q
             sc.setParameters("resourceType", resourceType.toString());
         }
 
-        sc.setParameters("archived", false);
+        if (id == null) {
+            sc.setParameters("archived", cmd.getArchived());
+        }
 
         Pair<List<EventJoinVO>, Integer> eventPair = null;
         // event_view will not have duplicate rows for each event, so
diff --git a/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java 
b/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java
index c73f57529b8..24c699a35ad 100644
--- a/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java
@@ -110,6 +110,9 @@ public class EventJoinDaoImpl extends 
GenericDaoBase<EventJoinVO, Long> implemen
         responseEvent.setParentId(event.getStartUuid());
         responseEvent.setState(event.getState());
         responseEvent.setUsername(event.getUserName());
+        if (event.getArchived()) {
+            responseEvent.setArchived(true);
+        }
         Long resourceId = event.getResourceId();
         responseEvent.setResourceType(event.getResourceType());
         ApiCommandResourceType resourceType = 
ApiCommandResourceType.fromString(event.getResourceType());
diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json
index ac109e70c1f..cdc013f82dc 100644
--- a/ui/public/locales/en.json
+++ b/ui/public/locales/en.json
@@ -187,6 +187,7 @@
 "label.action.vmsnapshot.revert": "Revert to VM snapshot",
 "label.action.vmstoragesnapshot.create": "Take VM volume snapshot",
 "label.actions": "Actions",
+"label.active": "Active",
 "label.activate.project": "Activate project",
 "label.activeviewersessions": "Active sessions",
 "label.add": "Add",
@@ -329,6 +330,7 @@
 "label.apply.tungsten.network.policy": "Apply Network Policy",
 "label.apply.tungsten.tag": "Apply tag",
 "label.archive": "Archive",
+"label.archived": "Archived",
 "label.archive.alerts": "Archive alerts",
 "label.archive.events": "Archive events",
 "label.as.default": "as default",
diff --git a/ui/src/components/view/InfoCard.vue 
b/ui/src/components/view/InfoCard.vue
index 9f449f3a0dd..f28f19c7d0e 100644
--- a/ui/src/components/view/InfoCard.vue
+++ b/ui/src/components/view/InfoCard.vue
@@ -84,6 +84,9 @@
               <a-tag v-if="resource.internetprotocol && ['IPv6', 
'DualStack'].includes(resource.internetprotocol)">
                 {{ resource.internetprotocol ? $t('label.ip.v4.v6') : 
resource.internetprotocol }}
               </a-tag>
+              <a-tag v-if="resource.archived" 
:color="this.$config.theme['@warning-color']">
+                {{ $t('label.archived') }}
+              </a-tag>
               <a-tooltip placement="right" >
                 <template #title>
                   <span>{{ $t('label.view.console') }}</span>
diff --git a/ui/src/config/section/event.js b/ui/src/config/section/event.js
index 4673a64ad0d..5f4b27b88ed 100644
--- a/ui/src/config/section/event.js
+++ b/ui/src/config/section/event.js
@@ -29,6 +29,9 @@ export default {
     title: 'label.event.timeline',
     param: 'startid'
   }],
+  filters: () => {
+    return ['active', 'archived']
+  },
   actions: [
     {
       api: 'archiveEvents',
@@ -45,6 +48,12 @@ export default {
         ids: {
           value: (record) => { return record.id }
         }
+      },
+      show: (record) => {
+        return !(record.archived)
+      },
+      groupShow: (selectedItems) => {
+        return selectedItems.filter(x => { return !(x.archived) }).length > 0
       }
     },
     {
diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue
index 6ddcb484567..c19712c5ea3 100644
--- a/ui/src/views/AutogenView.vue
+++ b/ui/src/views/AutogenView.vue
@@ -53,12 +53,7 @@
                   <a-select
                     v-if="!dataView && filters && filters.length > 0"
                     :placeholder="$t('label.filterby')"
-                    :value="$route.query.filter || (projectView && $route.name 
=== 'vm' ||
-                      ['Admin', 
'DomainAdmin'].includes($store.getters.userInfo.roletype) && ['vm', 'iso', 
'template'].includes($route.name)
-                        ? 'all' : ['publicip'].includes($route.name)
-                        ? 'allocated' : ['guestnetwork', 
'guestvlans'].includes($route.name)
-                        ? 'all' : ['volume'].includes($route.name)
-                        ? 'user' : 'self')"
+                    :value="filterValue"
                     style="min-width: 120px; margin-left: 10px"
                     @change="changeFilter"
                     showSearch
@@ -670,6 +665,25 @@ export default {
       return [...new Set(sizes)].sort(function (a, b) {
         return a - b
       }).map(String)
+    },
+    filterValue () {
+      if (this.$route.query.filter) {
+        return this.$route.query.filter
+      }
+      const routeName = this.$route.name
+      if ((this.projectView && routeName === 'vm') || (['Admin', 
'DomainAdmin'].includes(this.$store.getters.userInfo.roletype) && ['vm', 'iso', 
'template'].includes(routeName)) || ['guestnetwork', 
'guestvlans'].includes(routeName)) {
+        return 'all'
+      }
+      if (['publicip'].includes(routeName)) {
+        return 'allocated'
+      }
+      if (['volume'].includes(routeName)) {
+        return 'user'
+      }
+      if (['event'].includes(routeName)) {
+        return 'active'
+      }
+      return 'self'
     }
   },
   methods: {
@@ -1593,6 +1607,12 @@ export default {
         } else if (filter === 'allocatedonly') {
           query.allocatedonly = 'true'
         }
+      } else if (this.$route.name === 'event') {
+        if (filter === 'archived') {
+          query.archived = true
+        } else {
+          delete query.archived
+        }
       }
       query.filter = filter
       query.page = '1'

Reply via email to