Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Oct 8, 2018
2 parents ec084fc + 60c7e3a commit 26574e1
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 79 deletions.
2 changes: 1 addition & 1 deletion FieldtypeRockGrid.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function getModuleInfo() {
return array(
'title' => 'RockGrid',
'author' => 'Bernhard Baumrock, baumrock.com',
'version' => fgets(fopen(__DIR__ . '/changelog.md', 'r')),
'version' => '0.0.13',
'summary' => 'RockGrid Main Module',
'requires' => ['RockFinder'],
'installs' => ['InputfieldRockGrid'],
Expand Down
2 changes: 1 addition & 1 deletion InputfieldRockGrid.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function getModuleInfo() {
return array(
'title' => 'RockGrid',
'author' => 'Bernhard Baumrock, baumrock.com',
'version' => fgets(fopen(__DIR__ . '/changelog.md', 'r')),
'version' => '0.0.13',
'summary' => 'Allows rendering of agGrids in the PW admin.',
'requires' => 'FieldtypeRockGrid',
);
Expand Down
5 changes: 3 additions & 2 deletions RockGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function RockGrid() {
this.formatters = {};

// object holding colDefs
this.coldefs = {};
this.colDefs = {};

// manually defined global options
// these options are set for all grids
Expand Down Expand Up @@ -62,8 +62,9 @@ function RockGrid() {
* get a new empty column object
*/
RockGrid.prototype.getDefaultColumn = function(options) {
options = options || {};
var def = {
headerName: RockGrid.hoverSpan(options.headerName),
headerName: options.headerName ? RockGrid.hoverSpan(options.headerName) : '',
field: options.field || null,
minWidth: 100,

Expand Down
4 changes: 3 additions & 1 deletion RockGridItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,14 @@ function RockGridItem(gridOptions, dataColumns, frontendorbackend) {
* call the related coldef plugin and handover the current coldef
*/
RockGridItem.prototype.addColDefPlugin = function(col, params) {
console.warn('DEPRECATED!!! This method will be removed soon, update your code to remove this breaking change!');

// def can either be a 'string' ? or an objec : from;
// if it is an object we take the colDef property as name of the colDef plugin
// if it is a string, that's the name of the colDef plugin to call
var defName = params.name || params;
var colDef = this.getColDef(col);
var coldefFunction = RockGrid.coldefs[defName];
var coldefFunction = RockGrid.colDefs[defName];
if(typeof coldefFunction === 'function') coldefFunction(colDef, params);
else console.warn('No coldef-plugin found for ' + defName);
}
Expand Down
26 changes: 0 additions & 26 deletions changelog.md

This file was deleted.

4 changes: 3 additions & 1 deletion coldefs/currency.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
document.addEventListener('RockGridReady', function(e) {
RockGrid.coldefs.currency = function(colDef, params) {
RockGrid.colDefs.currency = function(colDef, params) {
var params = params || {};

// set coldefs
Expand All @@ -15,5 +15,7 @@ document.addEventListener('RockGridReady', function(e) {
prepend: '',
preset: 'euro',
}

return colDef;
};
});
21 changes: 14 additions & 7 deletions coldefs/date.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
document.addEventListener('RockGridReady', function(e) {
RockGrid.coldefs.date = function(colDef, params) {
var params = params || {};
colDef.cellRenderer = RockGrid.renderers.date;
colDef.cellRendererParams = {
format: params.format
RockGrid.colDefs.date = function(col) {
if(!col) return;

// set coldefs
col.valueGetter = function(params) {
if(typeof params.data == 'undefined') return;
var val = params.data[col.field];
var date = moment(val);

if(!date.isValid()) return '';
return date.format('YYYY-MM-DD');
}
colDef.filter = 'agDateColumnFilter';
};

return RockGrid.colDefs.fixedWidth(col, 100);
}
});
7 changes: 7 additions & 0 deletions coldefs/fixedWidth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
document.addEventListener('RockGridReady', function(e) {
RockGrid.colDefs.fixedWidth = function(col, width) {
col.width = width || 100;
col.suppressSizeToFit = true;
return col;
};
});
4 changes: 3 additions & 1 deletion coldefs/number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
document.addEventListener('RockGridReady', function(e) {
RockGrid.coldefs.number = function(colDef, params) {
RockGrid.colDefs.number = function(colDef, params) {
var params = params || {};

// set coldefs
Expand All @@ -13,5 +13,7 @@ document.addEventListener('RockGridReady', function(e) {
if(params.valueGetter) colDef.valueGetter = params.valueGetter;

colDef.type = 'numericColumn';

return colDef;
};
});
42 changes: 15 additions & 27 deletions coldefs/readme.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
# Attention: The concept of "colDefPlugins" is deprecated
# Library of useful column-definitions

I switched to a function-based concept and will update the docs as soon as possible.
ColDefs can be used to change columns to repeating needs. For example you can
use a coldef plugin to make the ID column not show the plain id as number but
to show clickable icons:

# Column Definitions Plugins

For some column types like dates or currencies you need to define multiple aspects. For numbers for example you need to make sure the value is a number (not a string) and you need to set the proper filter for that column. All those things can be placed in a coldef-plugin and then be reused across your grids or projects.

## Usage
```js
col = grid.getColDef('id');
col = RockGrid.colDefs.rowactions(col);
```

coldef-plugins are placed in the `/site/[assets|modules]/RockGrid/coldefs` folder. To add a new coldef-type see the existing files like `date.js` or `number.js`.
![rowactions](https://i.imgur.com/Ml0ipqq.png)

To use those plugins add them like so:
Some colDefs can also be defined with an extra options object:

```js
document.addEventListener('RockGridItemBeforeInit', function(e) {
if(e.target.id != 'RockGridItem_yourgridid') return;
var grid = RockGrid.getGrid(e.target.id);

grid.addColDefPlugins({
answercount: 'number',
});
col = grid.getColDef('id');
col = RockGrid.colDefs.rowactions(col, {
strShow: 'Open this page in a PW-Panel',
noTrash: true,
});
```

This will use the `number` coldef-plugin for the column `answercount` making it text-align: right and using the number-filter. If the colStats plugin is enabled this will also make it show the sum() of the column.

## Advanced

```js
answers: {name: 'number', valueGetter: function(params) {
var val = params.data[answercol.field];
if(!val) return 0;
return val.split(',').length;
}},
```
![custom-options](https://i.imgur.com/xMjK1nG.png)
26 changes: 17 additions & 9 deletions coldefs/rowactions.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
document.addEventListener('RockGridReady', function(e) {
RockGrid.coldefs.rowactions = function(colDef, options) {
RockGrid.colDefs.rowActions = function(col, options) {
var options = options || {};
if(!col) return;

colDef.width = options.width || 60;
colDef.suppressSizeToFit = true;
colDef.suppressMenu = true;
colDef.headerName = '';
colDef.suppressFilter = true;
colDef.cellStyle = {'text-align': 'center'};
col.width = options.width || 80;
col.suppressSizeToFit = true;
col.suppressMenu = true;
col.headerName = '';
col.suppressFilter = true;
col.cellStyle = {'text-align': 'center'};

colDef.cellRenderer = function(params) {
col.cellRenderer = function(params) {
if(!params.data || !params.data.id) return;

var items = [];

if(!options.noShow) items.push({
icon: 'fa fa-search',
href: ProcessWire.config.urls.admin + 'page/edit/?id=' + params.data[colDef.field],
href: ProcessWire.config.urls.admin + 'page/edit/?id=' + params.data[col.field],
str: options.strShow || RockGrid.str.show,
class: 'class="pw-panel"',
target: 'target="_blank"',
});
if(!options.noEdit) items.push({
icon: 'fa fa-edit',
href: ProcessWire.config.urls.admin + 'page/edit/?id=' + params.data[col.field],
str: options.strEdit || RockGrid.str.edit,
});
if(!options.noTrash) items.push({
icon: 'fa fa-trash',
href: '#',
Expand All @@ -30,6 +36,8 @@ document.addEventListener('RockGridReady', function(e) {

return RockGrid.renderers.actionItems(params, items);
};

return col;
};
});

Expand Down
3 changes: 0 additions & 3 deletions coldefs/rowactions.md

This file was deleted.

1 change: 1 addition & 0 deletions plugins/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// general translations
$this->rg->x('show', __('show'));
$this->rg->x('trash', __('trash'));
$this->rg->x('edit', __('edit'));
$this->rg->x('choose', __('choose'));
$this->rg->x('rows', __('Rows'));
$this->rg->x('refreshTimer', __('Refresh every ... seconds'));
Expand Down

0 comments on commit 26574e1

Please sign in to comment.