You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2019/04/11 03:23:12 UTC

[ignite] branch master updated: IGNITE-9981 Web Console: Implemented advanced footer for grid.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0d7070d  IGNITE-9981 Web Console: Implemented advanced footer for grid.
0d7070d is described below

commit 0d7070dbde1b354f5f14ae3f55f87c9c16be3ea7
Author: Ilya Borisov <kl...@gmail.com>
AuthorDate: Thu Apr 11 10:22:42 2019 +0700

    IGNITE-9981 Web Console: Implemented advanced footer for grid.
---
 .../app/components/grid-showing-rows/component.js  |  6 +--
 .../app/components/grid-showing-rows/controller.js | 56 ++++++++++++++++++++--
 .../app/components/grid-showing-rows/style.scss    |  4 ++
 .../components/grid-showing-rows/template.tpl.pug  | 24 ++++++++++
 4 files changed, 83 insertions(+), 7 deletions(-)

diff --git a/modules/web-console/frontend/app/components/grid-showing-rows/component.js b/modules/web-console/frontend/app/components/grid-showing-rows/component.js
index 6cab628..ecb93d0 100644
--- a/modules/web-console/frontend/app/components/grid-showing-rows/component.js
+++ b/modules/web-console/frontend/app/components/grid-showing-rows/component.js
@@ -18,10 +18,10 @@
 import './style.scss';
 import controller from './controller';
 
+import templateUrl from './template.tpl.pug';
+
 export default {
-    template: `
-        <i ng-pluralize count="$ctrl.count" when="{'one': 'Showing: 1 row', 'other': 'Showing: {} rows'}"></i>
-    `,
+    templateUrl,
     controller,
     bindings: {
         gridApi: '<'
diff --git a/modules/web-console/frontend/app/components/grid-showing-rows/controller.js b/modules/web-console/frontend/app/components/grid-showing-rows/controller.js
index 67c407c..b9e2e8e 100644
--- a/modules/web-console/frontend/app/components/grid-showing-rows/controller.js
+++ b/modules/web-console/frontend/app/components/grid-showing-rows/controller.js
@@ -18,12 +18,14 @@
 import _ from 'lodash';
 
 export default class {
-    static $inject = ['$scope', 'uiGridConstants'];
+    static $inject = ['$scope', 'IgniteCopyToClipboard', 'uiGridExporterService', 'uiGridExporterConstants', 'IgniteMessages', 'CSV'];
 
-    constructor($scope, uiGridConstants) {
-        Object.assign(this, {$scope, uiGridConstants});
+    constructor($scope, IgniteCopyToClipboard, uiGridExporterService, uiGridExporterConstants, IgniteMessages, CSV) {
+        Object.assign(this, {$scope, IgniteCopyToClipboard, uiGridExporterService, uiGridExporterConstants, IgniteMessages, CSV});
 
         this.count = 0;
+        this.visible = 0;
+        this.selected = 0;
     }
 
     $onChanges(changes) {
@@ -33,15 +35,61 @@ export default class {
             this.gridApi.core.on.rowsVisibleChanged(this.$scope, () => {
                 this.applyValues();
             });
+            this.gridApi.selection.on.rowSelectionChanged(this.$scope, () => this.updateSelectedCount());
+            this.gridApi.selection.on.rowSelectionChangedBatch(this.$scope, () => this.updateSelectedCount());
         }
     }
 
+    updateSelectedCount() {
+        this.selected = this.gridApi.selection.getSelectedCount();
+    }
+
     applyValues() {
         if (!this.gridApi.grid.rows.length) {
             this.count = 0;
+            this.visible = 0;
+            this.selected = 0;
             return;
         }
 
-        this.count = _.sumBy(this.gridApi.grid.rows, (row) => Number(row.visible));
+        this.count = this.gridApi.grid.rows.length;
+        this.visible = _.sumBy(this.gridApi.grid.rows, (row) => Number(row.visible));
+        this.updateSelectedCount();
+    }
+
+    copyToClipBoard() {
+        if (this.count === 0 || !this.gridApi) {
+            this.IgniteMessages.showError('No data to be copied');
+            return;
+        }
+
+        const data = [];
+        const grid = this.gridApi.grid;
+        grid.options.exporterSuppressColumns = [];
+        const exportColumnHeaders = this.uiGridExporterService.getColumnHeaders(grid, this.uiGridExporterConstants.VISIBLE);
+
+        grid.rows.forEach((row) => {
+            if (!row.visible)
+                return;
+
+            const values = [];
+
+            exportColumnHeaders.forEach((exportCol) => {
+                const col = grid.columns.find(({ field }) => field === exportCol.name);
+
+                if (!col || !col.visible || col.colDef.exporterSuppressExport === true)
+                    return;
+
+                const value = grid.getCellValue(row, col);
+
+                values.push({ value });
+            });
+
+            data.push(values);
+        });
+
+        const csvContent = this.uiGridExporterService.formatAsCsv(exportColumnHeaders, data, this.CSV.getSeparator());
+
+        this.IgniteCopyToClipboard.copy(csvContent);
     }
 }
diff --git a/modules/web-console/frontend/app/components/grid-showing-rows/style.scss b/modules/web-console/frontend/app/components/grid-showing-rows/style.scss
index a37f1b5..5893a08 100644
--- a/modules/web-console/frontend/app/components/grid-showing-rows/style.scss
+++ b/modules/web-console/frontend/app/components/grid-showing-rows/style.scss
@@ -17,4 +17,8 @@
 
 grid-showing-rows {
 	color: #757575;
+
+	i {
+		margin-right: 15px;
+	}
 }
diff --git a/modules/web-console/frontend/app/components/grid-showing-rows/template.tpl.pug b/modules/web-console/frontend/app/components/grid-showing-rows/template.tpl.pug
new file mode 100644
index 0000000..bce9c86
--- /dev/null
+++ b/modules/web-console/frontend/app/components/grid-showing-rows/template.tpl.pug
@@ -0,0 +1,24 @@
+//-
+    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.
+
+
+i Total: {{$ctrl.count}}
+
+i Showing: {{$ctrl.visible}}
+
+i Selected: {{$ctrl.selected}} of {{$ctrl.count}}
+
+a(ng-click='$ctrl.copyToClipBoard()') #[i Copy to clipboard]