You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ra...@apache.org on 2018/03/20 10:36:30 UTC

[cloudstack] branch master updated: [CLOUDSTACK-10329] Button in ACL rules page to export all rules as a CSV file (#2494)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new cd3a128  [CLOUDSTACK-10329] Button in ACL rules page to export all rules as a CSV file (#2494)
cd3a128 is described below

commit cd3a128090626d4afb991d7b7667d25da8ee950f
Author: Rafael Weingärtner <ra...@gmail.com>
AuthorDate: Tue Mar 20 07:36:24 2018 -0300

    [CLOUDSTACK-10329] Button in ACL rules page to export all rules as a CSV file (#2494)
---
 ui/css/cloudstack3.css      |  30 +++++++++++++++
 ui/images/exportCsvIcon.png | Bin 0 -> 102959 bytes
 ui/l10n/ar.js               |   1 +
 ui/l10n/ca.js               |   1 +
 ui/l10n/de_DE.js            |   1 +
 ui/l10n/en.js               |   1 +
 ui/l10n/es.js               |   1 +
 ui/l10n/fr_FR.js            |   1 +
 ui/l10n/hu.js               |   1 +
 ui/l10n/it_IT.js            |   1 +
 ui/l10n/ja_JP.js            |   1 +
 ui/l10n/ko_KR.js            |   1 +
 ui/l10n/nb_NO.js            |   1 +
 ui/l10n/nl_NL.js            |   1 +
 ui/l10n/pl.js               |   1 +
 ui/l10n/pt_BR.js            |   1 +
 ui/l10n/ru_RU.js            |   1 +
 ui/l10n/zh_CN.js            |   1 +
 ui/scripts/vpc.js           |  91 +++++++++++++++++++++++++++++++++++++-------
 19 files changed, 124 insertions(+), 13 deletions(-)

diff --git a/ui/css/cloudstack3.css b/ui/css/cloudstack3.css
index 2acabdb..1ef2d84 100644
--- a/ui/css/cloudstack3.css
+++ b/ui/css/cloudstack3.css
@@ -3241,6 +3241,7 @@ div.toolbar div.button.main-action,
   height: 12px;
 }
 
+div.toolbar div.button.export:hover,
 div.toolbar div.button.add:hover,
 div.toolbar div.button.refresh:hover,
 div.toolbar div.button.main-action:hover,
@@ -13414,3 +13415,32 @@ div.panel.copy-template-destination-list div.list-view div.fixed-header{
 .multi-edit-add-list .ui-button.copytemplatecancel {
     left: 310px;
 }
+
+div.button.export {
+	position: relative;
+	left: 0px;
+	top: 5px;
+	font-size: 12px;
+	font-weight: 100;
+	color: #000000;
+	margin: 0 10px 0 0;
+	cursor: pointer;
+	text-shadow: 0px 1px 1px #DEE5EA;
+	padding: 5px 5px 5px 5px;
+	background: linear-gradient(to bottom, rgba(247,247,247,1) 1%,rgba(234,234,234,1) 100%);
+	border: 1px solid #B7B7B7;
+	float: right;
+	border-radius: 4px 4px 4px 4px;
+	height: 12px;
+}
+
+div.button.export a {
+	padding: 0px 0 3px 20px;
+	background: url(../images/exportCsvIcon.png) no-repeat;
+	position: relative;
+	left: 0px;
+	top: 0px;
+	background-size: 15.5px;
+	text-decoration: none;
+	color: black;
+}
\ No newline at end of file
diff --git a/ui/images/exportCsvIcon.png b/ui/images/exportCsvIcon.png
new file mode 100644
index 0000000..cc486ec
Binary files /dev/null and b/ui/images/exportCsvIcon.png differ
diff --git a/ui/l10n/ar.js b/ui/l10n/ar.js
index f692743..db0dab0 100644
--- a/ui/l10n/ar.js
+++ b/ui/l10n/ar.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Accounts",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL List Rules",
     "label.acl.name": "ACL Name",
     "label.acl.replaced": "ACL replaced",
diff --git a/ui/l10n/ca.js b/ui/l10n/ca.js
index 276b3e5..5d98467 100644
--- a/ui/l10n/ca.js
+++ b/ui/l10n/ca.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Accounts",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL List Rules",
     "label.acl.name": "ACL Name",
     "label.acl.replaced": "ACL replaced",
diff --git a/ui/l10n/de_DE.js b/ui/l10n/de_DE.js
index 76374f6..4decf80 100644
--- a/ui/l10n/de_DE.js
+++ b/ui/l10n/de_DE.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Benutzerkonten",
     "label.acl": "ACL",
     "label.acl.id": "ACL-Kennung",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL-Listenregeln",
     "label.acl.name": "ACL-Name",
     "label.acl.replaced": "ACL ersetzt",
diff --git a/ui/l10n/en.js b/ui/l10n/en.js
index 6d99430..ae7ca7b 100644
--- a/ui/l10n/en.js
+++ b/ui/l10n/en.js
@@ -102,6 +102,7 @@ var dictionary = {
 "label.accounts":"Accounts",
 "label.acl":"ACL",
 "label.acl.id":"ACL ID",
+"label.acl.export": "Export ACLs",
 "label.acl.list.rules":"ACL List Rules",
 "label.acl.name":"ACL Name",
 "label.acl.replaced":"ACL replaced",
diff --git a/ui/l10n/es.js b/ui/l10n/es.js
index 37f8425..cbdf787 100644
--- a/ui/l10n/es.js
+++ b/ui/l10n/es.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Cuentas",
     "label.acl": "ACL",
     "label.acl.id": "ID de ACL",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "Lista de Reglas ACL",
     "label.acl.name": "Nombre de ACL",
     "label.acl.replaced": "ACL reemplazada",
diff --git a/ui/l10n/fr_FR.js b/ui/l10n/fr_FR.js
index 2d03b64..42f93c0 100644
--- a/ui/l10n/fr_FR.js
+++ b/ui/l10n/fr_FR.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Comptes",
     "label.acl": "ACL",
     "label.acl.id": "ID ACL",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "Liste règles ACL",
     "label.acl.name": "Nom ACL",
     "label.acl.replaced": "ACL remplacée",
diff --git a/ui/l10n/hu.js b/ui/l10n/hu.js
index f4d20e5..41edd47 100644
--- a/ui/l10n/hu.js
+++ b/ui/l10n/hu.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Számlák",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL List Rules",
     "label.acl.name": "ACL név",
     "label.acl.replaced": "ACL lehelyettesítve",
diff --git a/ui/l10n/it_IT.js b/ui/l10n/it_IT.js
index bcc3a0f..30d0b32 100644
--- a/ui/l10n/it_IT.js
+++ b/ui/l10n/it_IT.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Utenti",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL List Rules",
     "label.acl.name": "ACL Name",
     "label.acl.replaced": "ACL replaced",
diff --git a/ui/l10n/ja_JP.js b/ui/l10n/ja_JP.js
index efa937a..24f99e7 100644
--- a/ui/l10n/ja_JP.js
+++ b/ui/l10n/ja_JP.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "アカウント",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL ルールのリスト",
     "label.acl.name": "ACL 名",
     "label.acl.replaced": "ACL が置き換えられました",
diff --git a/ui/l10n/ko_KR.js b/ui/l10n/ko_KR.js
index de2d6ba..19d80fb 100644
--- a/ui/l10n/ko_KR.js
+++ b/ui/l10n/ko_KR.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "계정 정보",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL List Rules",
     "label.acl.name": "ACL Name",
     "label.acl.replaced": "ACL replaced",
diff --git a/ui/l10n/nb_NO.js b/ui/l10n/nb_NO.js
index 57fda63..6adc995 100644
--- a/ui/l10n/nb_NO.js
+++ b/ui/l10n/nb_NO.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Kontoer",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL Liste Regler",
     "label.acl.name": "ACL Navn",
     "label.acl.replaced": "ACL erstattet",
diff --git a/ui/l10n/nl_NL.js b/ui/l10n/nl_NL.js
index 4bf253d..f460214 100644
--- a/ui/l10n/nl_NL.js
+++ b/ui/l10n/nl_NL.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Accounts",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL lijst regels",
     "label.acl.name": "ACL naam",
     "label.acl.replaced": "ACL vervangen",
diff --git a/ui/l10n/pl.js b/ui/l10n/pl.js
index 7b7a89b..0d89f1e 100644
--- a/ui/l10n/pl.js
+++ b/ui/l10n/pl.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Konta",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL List Rules",
     "label.acl.name": "ACL Name",
     "label.acl.replaced": "ACL replaced",
diff --git a/ui/l10n/pt_BR.js b/ui/l10n/pt_BR.js
index 45de206..52066c3 100644
--- a/ui/l10n/pt_BR.js
+++ b/ui/l10n/pt_BR.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Contas",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "Lista de regas de ACL",
     "label.acl.name": "Nome da ACL",
     "label.acl.replaced": "ACL trocado",
diff --git a/ui/l10n/ru_RU.js b/ui/l10n/ru_RU.js
index 0321f71..b297b40 100644
--- a/ui/l10n/ru_RU.js
+++ b/ui/l10n/ru_RU.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "Учётные записи",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL List Rules",
     "label.acl.name": "ACL Name",
     "label.acl.replaced": "ACL replaced",
diff --git a/ui/l10n/zh_CN.js b/ui/l10n/zh_CN.js
index 1d617d6..c6965c6 100644
--- a/ui/l10n/zh_CN.js
+++ b/ui/l10n/zh_CN.js
@@ -101,6 +101,7 @@ var dictionary = {
     "label.accounts": "帐户",
     "label.acl": "ACL",
     "label.acl.id": "ACL ID",
+    "label.acl.export": "Export ACLs",
     "label.acl.list.rules": "ACL列表策略",
     "label.acl.name": "ACL 名称",
     "label.acl.replaced": "ACL 已替换",
diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js
index 7a2a302..dcf8e38 100644
--- a/ui/scripts/vpc.js
+++ b/ui/scripts/vpc.js
@@ -15,6 +15,53 @@
 // specific language governing permissions and limitations
 // under the License.
 (function($, cloudStack) {
+    var isNumeric = function (n) {
+        return !isNaN(parseFloat(n));
+    };
+    var createSafeCsvValue = function(value){
+        if(value){
+            return '"' + value + '"';
+        }
+        return "";
+    };
+    
+    var generateCsvForAclRules = function(aclRules){
+        var csv = createSafeCsvValue('id') + ',';
+        for(var field in aclRuleFields){
+            var fieldLabel = aclRuleFields[field].label;
+            var fieldLabelTranslated = _l(fieldLabel);
+            csv = csv + createSafeCsvValue(fieldLabelTranslated) + ',';
+        }
+        csv = csv.substr(0, csv.length - 1) + '\n';
+        if(!aclRules){
+            return csv;
+        }
+        aclRules.forEach(function(entry){
+            csv = csv + 
+            createSafeCsvValue(entry.id) + ',' + 
+            createSafeCsvValue(entry.number) + ',' +
+            createSafeCsvValue(entry.cidrlist) + ',' +
+            createSafeCsvValue(entry.action) + ',' ;
+            
+            if(isNumeric(entry.protocol)){
+                csv = csv +
+                createSafeCsvValue(_l('label.protocol.number')) + ',' +
+                createSafeCsvValue(entry.protocol) + ',';
+            }else{
+                csv = csv +
+                createSafeCsvValue(entry.protocol) + ',' +
+                createSafeCsvValue('') + ',';
+            }
+            csv = csv +
+            createSafeCsvValue(entry.startport) + ',' +
+            createSafeCsvValue(entry.endport) + ',' +
+            createSafeCsvValue(entry.icmptype) + ',' +
+            createSafeCsvValue(entry.icmpcode) + ',' +
+            createSafeCsvValue(entry.traffictype) + ',' +
+            createSafeCsvValue(entry.reason) + '\n';
+        });
+        return csv;
+    };
     var assignVMAction = function() {
         return {
             label: 'label.assign.vms',
@@ -1327,8 +1374,9 @@
                                             networkid: false
                                         },
                                         dataProvider: function(args) {
+                                            var aclListId = args.context.aclLists[0].id;
                                             $.ajax({
-                                                url: createURL('listNetworkACLs&aclid=' + args.context.aclLists[0].id),
+                                                url: createURL('listNetworkACLs&aclid=' + aclListId),
                                                 success: function(json) {
                                                     var items = json.listnetworkaclsresponse.networkacl;
 
@@ -1369,6 +1417,9 @@
                                                                 	 }
                                                                 	 if(data.protocol != 'protocolnumber'){
                                                                 		 data.protocolnumber = undefined;
+                                                                	 }else{
+                                                                	     data.protocol = data.protocolnumber;
+                                                                	     data.protocolnumber = undefined;
                                                                 	 }
                                                                 	 if(data.protocol === 'all'){
                                                                 		 data.startport = undefined;
@@ -1389,6 +1440,32 @@
                                                         });
                                                         jQuery('#details-tab-aclRules').siblings('div.toolbar').append($addAclRuleDivButton);
                                                     }
+                                                    if(jQuery('#details-tab-aclRules').siblings('div.toolbar').children('div.export').size() === 0){
+                                                        var $exportAclsDivButton = jQuery('<div>').addClass('button export');
+                                                        var $linkExportAclRulesButtonMessage = jQuery('<a>').html(_l('label.acl.export'));
+                                                        
+                                                        $exportAclsDivButton.html($linkExportAclRulesButtonMessage);
+                                                        $exportAclsDivButton.click(function(){
+                                                            
+                                                            $.ajax({
+                                                                url: createURL('listNetworkACLs&aclid=' + aclListId),
+                                                                type: "GET",
+                                                                async: false,
+                                                                success: function(json) {
+                                                                    var acls = json.listnetworkaclsresponse.networkacl;
+                                                                    var csv = generateCsvForAclRules(acls);
+                                                                    
+                                                                    window.URL = window.URL || window.webkiURL;
+                                                                    var blob = new Blob([csv]);
+                                                                    var blobURL = window.URL.createObjectURL(blob);
+                                                                    
+                                                                    $linkExportAclRulesButtonMessage.attr("href", blobURL);
+                                                                    $linkExportAclRulesButtonMessage.attr("download", "aclRules.csv");
+                                                                }
+                                                            });
+                                                        });
+                                                        jQuery('#details-tab-aclRules').siblings('div.toolbar').append($exportAclsDivButton);
+                                                    }
                                                 }
                                             });
                                         }
@@ -4371,18 +4448,6 @@
                                     return capability.name == 'LbSchemes';
                                 }) : [];
 
-                                /*      var lbSchemes = $.grep(
-                  $.grep(
-                    tier.service,
-                    function(service) {
-                      return service.name == 'Lb';
-                    }
-                  )[0].capability,
-                  function(capability) {
-                    return capability.name == 'LbSchemes';
-                  }
-                );*/
-
                                 var hasLbScheme = function(schemeVal) {
                                     return $.grep(
                                         lbSchemes,

-- 
To stop receiving notification emails like this one, please contact
rafael@apache.org.