-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathui-grid.grouping.min.js
6 lines (6 loc) · 10.8 KB
/
ui-grid.grouping.min.js
1
2
3
4
5
6
/*!
* ui-grid - v4.12.7 - 2024-04-12
* http://ui-grid.info/
* Copyright (c) 2024 ; License: MIT
*/
!function(){"use strict";var r=angular.module("ui.grid.grouping",["ui.grid","ui.grid.treeBase"]);r.constant("uiGridGroupingConstants",{featureName:"grouping",rowHeaderColName:"treeBaseRowHeaderCol",EXPANDED:"expanded",COLLAPSED:"collapsed",aggregation:{COUNT:"count",SUM:"sum",MAX:"max",MIN:"min",AVG:"avg"}}),r.service("uiGridGroupingService",["$q","uiGridGroupingConstants","gridUtil","rowSorter","GridRow","gridClassFactory","i18nService","uiGridConstants","uiGridTreeBaseService",function(r,t,u,a,c,s,p,e,l){var d={initializeGrid:function(e,r){l.initializeGrid(e,r),e.grouping={},e.grouping.groupHeaderCache={},d.defaultGridOptions(e.options),e.registerRowsProcessor(d.groupRows,400),e.registerColumnBuilder(d.groupingColumnBuilder),e.registerColumnsProcessor(d.groupingColumnProcessor,400);var o={grouping:{aggregationChanged:{},groupingChanged:{}}},i={grouping:{getGrouping:function(r){var o=d.getGrouping(e);return o.grouping.forEach(function(r){r.colName=r.col.name,delete r.col}),o.aggregations.forEach(function(r){r.colName=r.col.name,delete r.col}),o.aggregations=o.aggregations.filter(function(r){return!r.aggregation.source||"grouping"!==r.aggregation.source}),r&&(o.rowExpandedStates=d.getRowExpandedStates(e.grouping.groupingHeaderCache)),o},setGrouping:function(r){d.setGrouping(e,r)},groupColumn:function(r){r=e.getColumn(r);d.groupColumn(e,r)},ungroupColumn:function(r){r=e.getColumn(r);d.ungroupColumn(e,r)},clearGrouping:function(){d.clearGrouping(e)},aggregateColumn:function(r,o,i){r=e.getColumn(r);d.aggregateColumn(e,r,o,i)}}};e.api.registerEventsFromObject(o),e.api.registerMethodsFromObject(i),e.api.core.on.sortChanged(r,d.tidyPriorities)},defaultGridOptions:function(r){r.enableGrouping=!1!==r.enableGrouping,r.groupingShowCounts=!1!==r.groupingShowCounts,r.groupingNullLabel=void 0===r.groupingNullLabel?"Null":r.groupingNullLabel,r.enableGroupHeaderSelection=!0===r.enableGroupHeaderSelection},groupingColumnBuilder:function(r,i,o){var e,n,g;!1!==r.enableGrouping&&(void 0===i.grouping&&void 0!==r.grouping?(i.grouping=angular.copy(r.grouping),void 0!==i.grouping.groupPriority&&-1<i.grouping.groupPriority&&(i.treeAggregationFn=l.nativeAggregations()[t.aggregation.COUNT].aggregationFn,i.treeAggregationFinalizerFn=d.groupedFinalizerFn)):void 0===i.grouping&&(i.grouping={}),void 0!==i.grouping&&void 0!==i.grouping.groupPriority&&0<=i.grouping.groupPriority&&(i.suppressRemoveSort=!0),r={name:"ui.grid.grouping.group",title:p.get().grouping.group,icon:"ui-grid-icon-indent-right",shown:function(){return void 0===this.context.col.grouping||void 0===this.context.col.grouping.groupPriority||this.context.col.grouping.groupPriority<0},action:function(){d.groupColumn(this.context.col.grid,this.context.col)}},e={name:"ui.grid.grouping.ungroup",title:p.get().grouping.ungroup,icon:"ui-grid-icon-indent-left",shown:function(){return void 0!==this.context.col.grouping&&void 0!==this.context.col.grouping.groupPriority&&0<=this.context.col.grouping.groupPriority},action:function(){d.ungroupColumn(this.context.col.grid,this.context.col)}},n={name:"ui.grid.grouping.aggregateRemove",title:p.get().grouping.aggregate_remove,shown:function(){return void 0!==this.context.col.treeAggregationFn},action:function(){d.aggregateColumn(this.context.col.grid,this.context.col,null)}},!(g=function(r,o){o=o||p.get().grouping["aggregate_"+r]||r;o={name:"ui.grid.grouping.aggregate"+r,title:o,shown:function(){return void 0===this.context.col.treeAggregation||void 0===this.context.col.treeAggregation.type||this.context.col.treeAggregation.type!==r},action:function(){d.aggregateColumn(this.context.col.grid,this.context.col,r)}};u.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.grouping.aggregate"+r)||i.menuItems.push(o)})!==i.colDef.groupingShowGroupingMenu&&(u.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.grouping.group")||i.menuItems.push(r),u.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.grouping.ungroup")||i.menuItems.push(e)),!1!==i.colDef.groupingShowAggregationMenu)&&(angular.forEach(l.nativeAggregations(),function(r,o){g(o)}),angular.forEach(o.treeCustomAggregations,function(r,o){g(o,r.menuTitle)}),u.arrayContainsObjectWithProperty(i.menuItems,"name","ui.grid.grouping.aggregateRemove")||i.menuItems.push(n))},groupingColumnProcessor:function(r,o){return r=d.moveGroupColumns(this,r,o)},groupedFinalizerFn:function(r){var o=this;void 0!==r.groupVal?(r.rendered=r.groupVal,o.grid.options.groupingShowCounts&&"date"!==o.colDef.type&&"object"!==o.colDef.type&&(r.rendered+=" ("+r.value+")")):r.rendered=null},moveGroupColumns:function(r,o){return!1!==r.options.moveGroupColumns&&(o.forEach(function(r,o){r.groupingPosition=o}),o.sort(function(r,o){var i=r.isRowHeader?r.headerPriority:void 0===r.grouping||void 0===r.grouping.groupPriority||r.grouping.groupPriority<0?null:r.grouping.groupPriority,e=o.isRowHeader?o.headerPriority:void 0===o.grouping||void 0===o.grouping.groupPriority||o.grouping.groupPriority<0?null:o.grouping.groupPriority;return null!==i&&null===e?-1:null!==e&&null===i?1:null!==i&&null!==e?i-e:r.groupingPosition-o.groupingPosition}),o.forEach(function(r){delete r.groupingPosition})),o},groupColumn:function(r,o){void 0===o.grouping&&(o.grouping={});var i=d.getGrouping(r);o.grouping.groupPriority=i.grouping.length,o.previousSort=angular.copy(o.sort),o.sort?void 0!==o.sort.direction&&null!==o.sort.direction||(o.sort.direction=e.ASC):o.sort={direction:e.ASC},o.treeAggregation={type:t.aggregation.COUNT,source:"grouping"},o.colDef&&angular.isFunction(o.colDef.customTreeAggregationFn)?o.treeAggregationFn=o.colDef.customTreeAggregationFn:o.treeAggregationFn=l.nativeAggregations()[t.aggregation.COUNT].aggregationFn,o.treeAggregationFinalizerFn=d.groupedFinalizerFn,r.api.grouping.raise.groupingChanged(o),r.api.core.raise.sortChanged(r,r.getColumnSorting()),r.queueGridRefresh()},ungroupColumn:function(r,o){void 0!==o.grouping&&(delete o.grouping.groupPriority,delete o.treeAggregation,delete o.customTreeAggregationFinalizer,o.previousSort&&(o.sort=o.previousSort,delete o.previousSort),d.tidyPriorities(r),r.api.grouping.raise.groupingChanged(o),r.api.core.raise.sortChanged(r,r.getColumnSorting()),r.queueGridRefresh())},aggregateColumn:function(r,o,i,e){void 0!==o.grouping&&void 0!==o.grouping.groupPriority&&0<=o.grouping.groupPriority&&d.ungroupColumn(r,o);var n={};void 0!==r.options.treeCustomAggregations[i]?n=r.options.treeCustomAggregations[i]:void 0!==l.nativeAggregations()[i]&&(n=l.nativeAggregations()[i]),o.treeAggregation={type:i,label:"string"==typeof e?e:p.get().aggregation[n.label]||n.label},o.treeAggregationFn=n.aggregationFn,o.treeAggregationFinalizerFn=n.finalizerFn,r.api.grouping.raise.aggregationChanged(o),r.queueGridRefresh()},setGrouping:function(i,r){void 0!==r&&(d.clearGrouping(i),r.grouping&&r.grouping.length&&0<r.grouping.length&&r.grouping.forEach(function(r){r=i.getColumn(r.colName);r&&d.groupColumn(i,r)}),r.aggregations&&r.aggregations.length&&r.aggregations.forEach(function(r){var o=i.getColumn(r.colName);o&&d.aggregateColumn(i,o,r.aggregation.type)}),r.rowExpandedStates)&&d.applyRowExpandedStates(i.grouping.groupingHeaderCache,r.rowExpandedStates)},clearGrouping:function(o){var r=d.getGrouping(o);0<r.grouping.length&&r.grouping.forEach(function(r){r.col||(r.col=o.getColumn(r.colName)),d.ungroupColumn(o,r.col)}),0<r.aggregations.length&&r.aggregations.forEach(function(r){r.col||(r.col=o.getColumn(r.colName)),d.aggregateColumn(o,r.col,null)})},tidyPriorities:function(r){void 0!==r&&void 0===r.grid||void 0===this.grid||(r=this.grid);var i=[],e=[],o=(r.columns.forEach(function(r,o){void 0!==r.grouping&&void 0!==r.grouping.groupPriority&&0<=r.grouping.groupPriority?i.push(r):void 0!==r.sort&&void 0!==r.sort.priority&&0<=r.sort.priority&&e.push(r)}),i.sort(function(r,o){return r.grouping.groupPriority-o.grouping.groupPriority}),i.forEach(function(r,o){r.grouping.groupPriority=o,r.suppressRemoveSort=!0,void 0===r.sort&&(r.sort={}),r.sort.priority=o}),i.length);e.sort(function(r,o){return r.sort.priority-o.sort.priority}),e.forEach(function(r){r.sort.priority=o,r.suppressRemoveSort=r.colDef.suppressRemoveSort,o++})},groupRows:function(e){if(0!==e.length){for(var n=this,g=(n.grouping.oldGroupingHeaderCache=n.grouping.groupingHeaderCache||{},n.grouping.groupingHeaderCache={},d.initialiseProcessingState(n)),r=function(r,o){var i=n.getCellValue(u,r.col);r.initialised&&0===a.getSortFn(r.col)(i,r.currentValue)||(d.insertGroupHeader(n,e,t,g,o),t++)},t=0;t<e.length;t++){var u=e[t];u.visible&&g.forEach(r)}delete n.grouping.oldGroupingHeaderCache}return e},initialiseProcessingState:function(r){var i=[];return d.getGrouping(r).grouping.forEach(function(r,o){i.push({fieldName:r.field,col:r.col,initialised:!1,currentValue:null,currentRow:null})}),i},getGrouping:function(r){var o=[],i=[];return r.columns.forEach(function(r){r.grouping&&void 0!==r.grouping.groupPriority&&0<=r.grouping.groupPriority&&o.push({field:r.field,col:r,groupPriority:r.grouping.groupPriority,grouping:r.grouping}),r.treeAggregation&&r.treeAggregation.type&&i.push({field:r.field,col:r,aggregation:r.treeAggregation})}),o.sort(function(r,o){return r.groupPriority-o.groupPriority}),o.forEach(function(r,o){r.grouping.groupPriority=o,r.groupPriority=o,delete r.grouping}),{grouping:o,aggregations:i}},insertGroupHeader:function(r,o,i,e,n){var g=e[n].col,g=r.getCellValue(o[i],g),t=g;function u(r){return angular.isObject(r)?JSON.stringify(r):r}null==g&&(t=r.options.groupingNullLabel);for(var a,p=r.grouping.oldGroupingHeaderCache,l=0;l<n;l++)p&&p[u(e[l].currentValue)]&&(p=p[u(e[l].currentValue)].children);for(p&&p[u(g)]?(a=p[u(g)].row).entity={}:(a=new c({},null,r),s.rowTemplateAssigner.call(r,a)),a.entity["$$"+e[n].col.uid]={groupVal:t},a.treeLevel=n,a.groupHeader=!0,a.internalRow=!0,a.enableCellEdit=!1,a.enableSelection=r.options.enableGroupHeaderSelection,e[n].initialised=!0,e[n].currentValue=g,e[n].currentRow=a,d.finaliseProcessingState(e,n+1),o.splice(i,0,a),p=r.grouping.groupingHeaderCache,l=0;l<n;l++)p=p[u(e[l].currentValue)].children;p[u(g)]={row:a,children:{}}},finaliseProcessingState:function(r,o){for(var i=o;i<r.length;i++)r[i].initialised=!1,r[i].currentRow=null,r[i].currentValue=null},getRowExpandedStates:function(r){var i;return void 0===r?{}:(i={},angular.forEach(r,function(r,o){i[o]={state:r.row.treeNode.state},r.children?i[o].children=d.getRowExpandedStates(r.children):i[o].children={}}),i)},applyRowExpandedStates:function(i,r){void 0!==r&&angular.forEach(r,function(r,o){i[o]&&(i[o].row.treeNode.state=r.state,r.children)&&i[o].children&&d.applyRowExpandedStates(i[o].children,r.children)})}};return d}]),r.directive("uiGridGrouping",["uiGridGroupingConstants","uiGridGroupingService",function(r,n){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(r,o,i,e){!1!==e.grid.options.enableGrouping&&n.initializeGrid(e.grid,r)},post:function(r,o,i,e){}}}}}])}();