You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/07/28 11:42:45 UTC

[GitHub] [cloudstack] davidjumani commented on a change in pull request #5103: Extend the Annotations framework

davidjumani commented on a change in pull request #5103:
URL: https://github.com/apache/cloudstack/pull/5103#discussion_r678205733



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/annotation/AddAnnotationCmd.java
##########
@@ -40,11 +41,17 @@
 
     @Parameter(name = ApiConstants.ANNOTATION, type = CommandType.STRING, description = "the annotation text")
     private String annotation;
+
     @Parameter(name = ApiConstants.ENTITY_TYPE, type = CommandType.STRING, description = "the entity type (only HOST is allowed atm)")
     private String entityType;
+
     @Parameter(name = ApiConstants.ENTITY_ID, type = CommandType.STRING, description = "the id of the entity to annotate")
     private String entityUuid;
 
+    @Parameter(name = ApiConstants.ADMINS_ONLY, type = CommandType.BOOLEAN,
+            description = "the annotation is visible for admins only")

Review comment:
       ```suggestion
               description = "the annotation is visible for admins only. Default is true")
   ```

##########
File path: ui/src/components/view/AnnotationsTab.vue
##########
@@ -0,0 +1,282 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+<template>
+
+  <div class="account-center-team" v-if="annotationType && 'listAnnotations' in $store.getters.apis">
+    <a-spin :spinning="loadingAnnotations">
+      <div class="title">
+        {{ $t('label.comments') }} ({{ notes.length }})
+      </div>
+      <a-divider :dashed="true" />
+      <a-list
+        v-if="notes.length"
+        :dataSource="notes"
+        itemLayout="horizontal"
+        size="small" >
+        <a-list-item slot="renderItem" slot-scope="item">
+          <a-comment
+            class="comment"
+            :content="item.annotation"
+            :datetime="$toLocaleDate(item.created)"
+            :author="item.username" >
+            <a-avatar
+              slot="avatar"
+              icon="message" />
+            <a-popconfirm
+              :title="$t('label.make') + ' ' + (item.adminsonly ? $t('label.annotation.everyone') : $t('label.annotation.admins.only')) + ' ?'"
+              v-if="['Admin'].includes($store.getters.userInfo.roletype)"
+              slot="actions"
+              key="visibility"
+              @confirm="updateVisibility(item)"
+              :okText="$t('label.yes')"
+              :cancelText="$t('label.no')" >
+              <a-icon
+                type="eye"
+                :style="[{
+                  color: item.adminsonly ? $config.theme['@primary-color'] : $config.theme['@disabled-color']
+                }]" />
+              <span>
+                {{ item.adminsonly ? $t('label.annotation.admins.only') : $t('label.annotation.everyone') }}
+              </span>
+            </a-popconfirm>
+          </a-comment>
+          <a-button
+            v-if="'removeAnnotation' in $store.getters.apis && isAdminOrAnnotationOwner(item)"
+            type="danger"
+            icon="delete"
+            shape="circle"
+            size="small"
+            @click="deleteNote(item)" >
+          </a-button>
+        </a-list-item>
+      </a-list>
+
+      <a-divider :dashed="true" />
+      <a-comment v-if="'addAnnotation' in $store.getters.apis">
+        <a-avatar
+          slot="avatar"
+          icon="edit"
+          @click="showNotesInput = true" />
+        <div slot="content" v-ctrl-enter="saveNote">
+          <a-textarea
+            rows="4"
+            @change="handleNoteChange"
+            :value="annotation"
+            :placeholder="$t('label.add.note')" />
+          <a-checkbox @change="toggleNoteVisibility" v-if="['Admin'].includes(this.$store.getters.userInfo.roletype)" style="margin-top: 10px">
+            {{ $t('label.annotation.admins.only') }}
+          </a-checkbox>
+          <a-button
+            style="margin-top: 10px; float: right"
+            @click="saveNote"
+            type="primary" >
+            {{ $t('label.save') }}
+          </a-button>
+        </div>
+      </a-comment>
+    </a-spin>
+  </div>
+</template>
+
+<script>
+
+import { api } from '@/api'
+
+export default {
+  name: 'AnnotationsTab',
+  props: {
+    resource: {
+      type: Object,
+      required: true
+    },
+    items: {
+      type: Array,
+      default: () => []
+    }
+  },
+  inject: ['parentFetchData'],
+  data () {
+    return {
+      loadingAnnotations: false,
+      notes: [],
+      annotation: '',
+      annotationType: '',
+      annotationAdminsOnly: false,
+      showNotesInput: false
+    }
+  },
+  watch: {
+    resource: function (newItem, oldItem) {
+      this.resource = newItem
+      this.resourceType = this.$route.meta.resourceType
+      this.annotationType = this.generateAnnotationType()
+      if (this.annotationType) {
+        this.getAnnotations()
+      }
+    }
+  },
+  created () {
+    this.fetchData()
+  },
+  methods: {
+    generateAnnotationType () {
+      switch (this.resourceType) {
+        case 'UserVm': return 'VM'
+        case 'Domain': return 'DOMAIN'
+        case 'Host': return 'HOST'
+        case 'Volume': return 'VOLUME'
+        case 'Snapshot': return 'SNAPSHOT'
+        case 'VMSnapshot': return 'VM_SNAPSHOT'
+        case 'VMInstanceGroup': return 'INSTANCE_GROUP'
+        case 'SSHKeyPair': return 'SSH_KEYPAIR'
+        case 'KubernetesCluster': return 'KUBERNETES_CLUSTER'
+        case 'Network': return 'NETWORK'
+        case 'Vpc': return 'VPC'
+        case 'PublicIpAddress': return 'PUBLIC_IP_ADDRESS'
+        case 'VPNCustomerGateway': return 'VPN_CUSTOMER_GATEWAY'
+        case 'Template': return 'TEMPLATE'
+        case 'ISO': return 'ISO'
+        case 'ServiceOffering': return 'SERVICE_OFFERING'
+        case 'DiskOffering': return 'DISK_OFFERING'
+        case 'NetworkOffering': return 'NETWORK_OFFERING'
+        case 'Zone': return 'ZONE'
+        case 'Pod': return 'POD'
+        case 'Cluster': return 'CLUSTER'
+        case 'PrimaryStorage': return 'PRIMARY_STORAGE'
+        case 'SecondaryStorage': return 'SECONDARY_STORAGE'
+        case 'SystemVm': return 'SYSTEM_VM'
+        case 'VirtualRouter': return 'VR'

Review comment:
       ```suggestion
           case 'VirtualRouter': return 'VR'
           case 'Kubernetes: return ''KUBERNETES_CLUSTER'
   ```

##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/annotation/ListAnnotationsCmd.java
##########
@@ -41,11 +41,25 @@
 
     @Parameter(name = ApiConstants.ID, type = CommandType.STRING, description = "the id of the annotation")
     private String uuid;
+
     @Parameter(name = ApiConstants.ENTITY_TYPE, type = CommandType.STRING, description = "the entity type")
     private String entityType;
+
     @Parameter(name = ApiConstants.ENTITY_ID, type = CommandType.STRING, description = "the id of the entity for which to show annotations")
     private String entityUuid;
 
+    @Parameter(name = ApiConstants.USER_ID, type = CommandType.STRING,
+            description = "optional: the id of the user of the annotation", required = false)
+    private String userUuid;
+
+    @Parameter(name = ApiConstants.ANNOTATION_FILTER,
+            type = CommandType.STRING,
+            required = true,
+            description = "possible values are \"self\" and \"all\". "
+                    + "* self : annotations that have been created by the calling user. "
+                    + "* all : all templates (only usable by admins).")

Review comment:
       ```suggestion
                       + "* all : all annotations (only usable by admins).")
   ```

##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/annotation/AddAnnotationCmd.java
##########
@@ -40,11 +41,17 @@
 
     @Parameter(name = ApiConstants.ANNOTATION, type = CommandType.STRING, description = "the annotation text")
     private String annotation;
+
     @Parameter(name = ApiConstants.ENTITY_TYPE, type = CommandType.STRING, description = "the entity type (only HOST is allowed atm)")
     private String entityType;
+
     @Parameter(name = ApiConstants.ENTITY_ID, type = CommandType.STRING, description = "the id of the entity to annotate")
     private String entityUuid;
 
+    @Parameter(name = ApiConstants.ADMINS_ONLY, type = CommandType.BOOLEAN,
+            description = "the annotation is visible for admins only")

Review comment:
       My bad




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org