Jump to content
bernhard

RockGrid - powerful, performant and beautiful data listing tool

Recommended Posts

Earlier in this topic I asked about autoHeight for rows. Now I have created a nice and only slightly hacky solution for it (no hacks in libs, just working around stuff). The existing simple option is not acceptable in our use case, because even the official docs say:

Quote

For large data grids (eg 10,000+ rows) the time taken to calculate the heights may take to long and you may decide not to use the feature in these circumstances. The row limit depends on your browser choice, computer speed and data so you will need to decide for yourself how much data is to much for this feature.

When using autoHeight for 35k rows, I got twice the message "the web page seems to be running slow, do you want to stop it". I don't even dare to imagine what would happen on an old smartphone.

The obvious (to me) solution was to calculate automatic height on demand only for the handful of rows displayed at a time. This has to happen on page load, on filtering and on pagination navigation. Due how pagination is implemented, a hoop had to be jumped through with it as well (to avoid an infinite loop). To be clear: the ag-Grid API offered no immediately useful event I could listen to! viewportChanged sounded like it would work, but in practice it failed to cover page navigation.

var paginationAttached = false;
var paginationHandler = function (event) { rowHeighter(grid, event); }
function rowHeighter(grid, event) {
    // calculate row height for displayed rows to wrap text
    var cols = [ grid.gridOptions.columnApi.getColumn("code"), grid.gridOptions.columnApi.getColumn("variation") ];
    grid.gridOptions.api.getRenderedNodes().forEach(function(node) {
        node.columnController.isAutoRowHeightActive = function() { return true; };
        node.columnController.getAllAutoRowHeightCols = function() { return cols; };
        node.setRowHeight(grid.gridOptions.api.gridOptionsWrapper.getRowHeightForNode(node));
    });
    
    // if listening to paginationChange, onRowHeightChanged creates an infinite loop, so work around it
    if(paginationAttached === false) {
        grid.gridOptions.api.onRowHeightChanged();
        grid.gridOptions.api.addEventListener('paginationChanged', paginationHandler);
        paginationAttached = true;
    } else {
        grid.gridOptions.api.removeEventListener('paginationChanged', paginationHandler);
        grid.gridOptions.api.onRowHeightChanged();
        grid.gridOptions.api.addEventListener('paginationChanged', paginationHandler);
    }
}

You can see here that I had to brute-force overwrite a couple of functions in the ag-Grid row height calculation logic. I define the columns I want to target for the auto height and trick the getAllAutoRowHeightCols to just provide them.

My filter event listener in RockGridItemAfterInit is

grid.gridOptions.api.addEventListener('filterChanged', function(event) { rowHeighter(grid, event); });

A CSS rule is also required:

div[col-id="variation"].ag-cell, div[col-id="code"].ag-cell {
    white-space: normal;
}

Using automatic row heights brought about an issue with the default fixed height grid: a wild scrollbar appeared! I found out I can make the grid height adapt, putting this into RockGridItemBeforeInit:

// pagination with a fixed number of rows and adapting grid height
grid.gridOptions.paginationAutoPageSize = false;
grid.gridOptions.paginationPageSize = 15;
grid.gridOptions.domLayout = 'autoHeight';

Then I decided the pagination controls should live above the grid, because otherwise their position will change annoyingly whenever the grid height changes. Putting this into RockGridItemAfterInit:

// move the pagination panel to the top, because the dynamic row heights would change its position at the bottom
var pagingPanel = document.querySelector('.ag-paging-panel');
var rootWrapper = document.querySelector('.ag-root-wrapper');
rootWrapper.prepend(pagingPanel);

 

  • Like 2

Share this post


Link to post
Share on other sites

Thx for sharing that @Beluga! Do you think the aggrid core team could be interested in your solution? Maybe they can implement it somehow?

  • Like 1

Share this post


Link to post
Share on other sites
9 minutes ago, bernhard said:

Thx for sharing that @Beluga! Do you think the aggrid core team could be interested in your solution? Maybe they can implement it somehow?

I just now went looking in their issue trackers and found this in their enterprise support tracker (in category tab "Standard Feature Requests):

AG-1202 Allow rendering rows dynamically adapting their height to their content

That does sound like what I want, but thanks to their closed system, we have no way of knowing the exact contents of the issue! 💀👹😡

There is also this, which would only be for paying customers:

Enterprise Row Model AG-1039 Allow dynamic row heights and maxBlocksInCache

This is in Parked category:

AG-2228 Allow lazy loading of rows when using autoHeight, ie on scroll to configured amount of rows, append n more rows at the bottom

So looks like this stuff is on their radar (which I would have assumed based on how they acknowledge the pain point in their docs). Let's wait and see and for now enjoy my hack 😄 All this hacking does have the effect of improving my self-confidence and wanting to learn JS more deeply 🙂

  • Like 2

Share this post


Link to post
Share on other sites

Hi

I discovered ag-grid documentation (since I solved all my Rockfinder problems, thanks!). I have really general questions.

  • How I should decide what to put in BeforeInit vs AfterInit? For example, why the visible/hidden column are in AfterInit?
  • I want to have a modified version of YesNo plugin. How I can do that? For now, I rename with a slightly different name and add it in /assets/Rockgrid folder. Is it the good way to do it (it works BTW)?
  • Where I should put CSS file? I added in /assets/Rockgrid/style.css and link into my PHP file. However, for some reasons, I'm not able to use row classes. The class is well added in html but CSS classes's are overridden. However If I used instead inline CSS directly in the JS file, the row is correctly styled.
  • I have many Rockgrid fields, sharing some columns. How I can define some common column headers (definition, style, etc..) instead of re-write on each field.js file?

Thanks!

Mel

Share this post


Link to post
Share on other sites
7 hours ago, mel47 said:

How I should decide what to put in BeforeInit vs AfterInit? For example, why the visible/hidden column are in AfterInit?

Usually it's fine to put everything in BeforeInit. Sometimes AfterInit is needed (for example if you have dynamic columns calculated on runtime).

7 hours ago, mel47 said:

I want to have a modified version of YesNo plugin. How I can do that? For now, I rename with a slightly different name and add it in /assets/Rockgrid folder. Is it the good way to do it (it works BTW)?

Yes, that's fine.

7 hours ago, mel47 said:

Where I should put CSS file? I added in /assets/Rockgrid/style.css and link into my PHP file. However, for some reasons, I'm not able to use row classes. The class is well added in html but CSS classes's are overridden. However If I used instead inline CSS directly in the JS file, the row is correctly styled.

CSS should be loaded automatically: https://github.com/BernhardBaumrock/FieldtypeRockGrid/tree/master/plugins#creating-custom-plugins; I don't know why your css classes are overwritten, sorry.

8 hours ago, mel47 said:

I have many Rockgrid fields, sharing some columns. How I can define some common column headers (definition, style, etc..) instead of re-write on each field.js file?

See the readme here https://github.com/BernhardBaumrock/FieldtypeRockGrid/tree/master/coldefs

And a very simple example https://github.com/BernhardBaumrock/FieldtypeRockGrid/blob/master/coldefs/fixedWidth.js

You can then just use col = RockGrid.colDefs.yourColdefName(col); in BeforeInit

Share this post


Link to post
Share on other sites
On 9/24/2018 at 4:04 PM, Beluga said:

I like RockGrid very much and the new smart filter is a really nice addition. I will look into paying you after we launch the site.

Thank you Beluga! Just received your generous donation 🙂 Really appreciated! Thx! Glad if it helped you for your project even if it seems that you switched to another library now?! Thank you for all your feedback and contributions to this project!

Share this post


Link to post
Share on other sites
2 hours ago, bernhard said:

Thank you Beluga! Just received your generous donation 🙂 Really appreciated! Thx! Glad if it helped you for your project even if it seems that you switched to another library now?! Thank you for all your feedback and contributions to this project!

Well, RockGrid and RockFinder are still essential to make it work with PW no matter which JS lib we use 🙂

I will look into donating to Tabulator next to cover all bases.

Regarding the earlier discussion about creating a module that makes RockGrid and Apex Charts talk to each other: I might look into it after my plate is cleared of various stuff (such as launching this proverb project).

  • Like 1

Share this post


Link to post
Share on other sites

The new rockfinder updates make it easy to extend grids:

Extending Grids

Sometimes several RockGrids are very similar and you don't want to duplicate your code. You can create one base file and include this file from others:

// trainings.php
$finder = new RockFinder([
  'template' => 'training',
  'sort' => 'from',
], [
  'first',
  'from',
  'to',
]);
$finder->addField('coach', ['title']);
$finder->addField('client', ['fullname']);

// trainings_booked.php
include(__DIR__.'/trainings.php');

$finder->setSelectorValue('client', $this->user); // only show trainings of current user
$finder->addField('done'); // add column to show if the training was completed

$this->setData($finder);

You can then create another file, for example trainings_available.php to show all trainings that are in the future and available for booking:

include(__DIR__.'/trainings.php');

$finder->setSelectorValue('from>', time());
$finder->setSelectorValue('client', null); // client must not be set -> means available for booking

$this->setData($finder);
  • Like 2

Share this post


Link to post
Share on other sites

Hi,

New problem but I'm quite sure it was not there before, but I don't know since when. I upgrade to last version 1.1.1 but didn't help. I get this error. The grids (more than 1 with different queries) appear with "loading" but nothing happens. Error is from Chrome, but same one in Firefox.

(index):2 Uncaught SyntaxError: Unexpected token W in JSON at position 1 at JSON.parse (<anonymous>) at XMLHttpRequest.xhr.onreadystatechange (RockGridItem.js?t=1550464515:271)

Thanks

 


 
 

Share this post


Link to post
Share on other sites
On 6/30/2018 at 5:38 PM, bernhard said:

Support: Please note that this module might not be as easy and plug&play as many other modules. It needs a good understanding of agGrid (and JavaScript in general) and it likely needs some looks into the code to get all the options. Please understand that I can not provide free support for every request here in the forum. I try to answer all questions that might also help others or that might improve the module but for individual requests I offer paid support for 60€ per hour (excl vat).

Hi mel47,

sorry to hear that. Check your finder with RockFinderTester, maybe it is somehow broken. If that does not work you can write me a PM support request and maybe provide a login to your system so that I can check what is going on. You need to make sure that the response of the AJAX requests are valid JSON. Also check all your error logs, maybe you find some helpful information there.

  • Like 1

Share this post


Link to post
Share on other sites
On 2/18/2019 at 12:01 AM, mel47 said:

Hi,

New problem but I'm quite sure it was not there before, but I don't know since when. I upgrade to last version 1.1.1 but didn't help. I get this error. The grids (more than 1 with different queries) appear with "loading" but nothing happens. Error is from Chrome, but same one in Firefox.

(index):2 Uncaught SyntaxError: Unexpected token W in JSON at position 1 at JSON.parse (<anonymous>) at XMLHttpRequest.xhr.onreadystatechange (RockGridItem.js?t=1550464515:271)

Thanks

 



 
 

Solved. Had to return in PHP7.1 because zlib is "on" instead of "off" on my server when set to PHP7.2.

 

Share this post


Link to post
Share on other sites

Just added support for tippy.js to show nice tooltips with additional information. For example here I needed to show all available invoices related to one project of one month and I don't want different line heights, so I show the links on hover:

ajvRWQQ.png

Using tippy.js

img

col = grid.getColDef('ids');
col.headerName = 'Rechnung';
col.cellRenderer = function(params) {
  if(!params.value) return '';
  var ids =  params.data.ids.split(',');
  var out = 'IDs: ' + ids.join(', ');
  var tippy = 'One per line:<br>' + ids.join('<br>');
  return RockGrid.tippy(out, tippy);
}
  • Like 6

Share this post


Link to post
Share on other sites

If I want to show tens of thousands of rows, but just 100 per page, the only options I have at the moment are:

  • Load all rows and let agGrid handle the pagination (fast navigation, slow initial load)
  • Just show 100 results (fast initial load, but data is incomplete)
  • implement my own server side ajax implementation for pagination (fast, but higher development effort)

Is that right? Or does RockFinder already provide a solution for pagination without having to load all the data? If it doesn't: Is that something that falls in the scope of RockFinder and you @bernhard would like it to be implemented?

Share this post


Link to post
Share on other sites

Hi @MrSnoozles

you are right - RockGrid is intended to load all data to the client at once. Doing this via paginated ajax calls would have a lot of side effects and is not planned. For example if you have column statistics showing the sum of all rows, that would not be possible when data was paginated (and not fully loaded into the grid). Also sorting would work totally different. aggrid supports this feature, but it would need a LOT more work to also support this in RockGrid. Not only for development of RockGrid but also for development of every single field/grid.

When I have complex queries then I usually display only a subset of the data, for example all entries of year XXXX. You can see some performance tests here:

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Just had a very interesting conversation with @wbmnfktr and wanted to share this little preview of a quite big upgrade coming soon called "RockGridActions". I'll share some more infos soon. The great thing about it is that it is built modularly so that we'll be able to use it almost plug&play for RockTabulator ( @Beluga)

  • Like 14

Share this post


Link to post
Share on other sites

Imagine you have a nice conversation with someone and only a few hours afterwards you are knee-deep into a module and possibilities you never thought of. Thank you @bernhard for hijacking my plans for the weekend. 😉 

  • Like 6
  • Haha 1

Share this post


Link to post
Share on other sites

@bernhard Thanks for the great module! Just started to use in in a project and it has helped me save a ton of time!

Is it possible to create a grid just by PHP? Saw that there was a Javascript possibility but i would need to create grid from a form submit.

Share this post


Link to post
Share on other sites

Hi @gottberg

glad to hear that. Sometimes I feel that the potential of this or similar modules is underestimated. If you only need a HTML grid (table) then you might be better off using MarkupAdminDataTable. RockGrid is by design a grid with user input like filtering and sorting and custom colorizations based on cell values. If you don't need all that just create a plain html table.

Does that help?

Share this post


Link to post
Share on other sites
1 minute ago, bernhard said:

Hi @gottberg

glad to hear that. Sometimes I feel that the potential of this or similar modules is underestimated. If you only need a HTML grid (table) then you might be better off using MarkupAdminDataTable. RockGrid is by design a grid with user input like filtering and sorting and custom colorizations based on cell values. If you don't need all that just create a plain html table.

Does that help?

Thanks for fast reply! Well in this case i would want the export to csv which would be convenient since the project uses RockGrid for many of the listings. 🙂 I could save the form to a own template which would only be updated on submit, then i would get the export feature too 🙂

Share this post


Link to post
Share on other sites

Sorry, I don't get what you are saying 🙂 

BTW: Of course you can just show a simple grid without modifying it via javascript. That's explained in the quickstart: https://github.com/BernhardBaumrock/FieldtypeRockGrid/wiki/Quickstart (actually there is nothing to explain if you don't use any javascript modifications). But as soon as you want to style or tweak your grid (eg custom Headernames) you need javascript.

Would be happy to see some screenshots so maybe others do also get inspired by your work 😉 

Share this post


Link to post
Share on other sites
21 hours ago, bernhard said:

Sorry, I don't get what you are saying 🙂 

BTW: Of course you can just show a simple grid without modifying it via javascript. That's explained in the quickstart: https://github.com/BernhardBaumrock/FieldtypeRockGrid/wiki/Quickstart (actually there is nothing to explain if you don't use any javascript modifications). But as soon as you want to style or tweak your grid (eg custom Headernames) you need javascript.

Would be happy to see some screenshots so maybe others do also get inspired by your work 😉 

I meant that i would create a template to which the form would be submited so that i could use RockGrid as usual. I did that and i works great for this use! 🙂 

I would love to share but since its for the customers internal use im not allowed to share anything.. 😕

Once again thank you! 

Share this post


Link to post
Share on other sites
38 minutes ago, gottberg said:

I meant that i would create a template to which the form would be submited so that i could use RockGrid as usual. I did that and i works great for this use! 🙂 

Still don't get it. We have forms all over PW (and the web), so it's hard to guess which one you are talking about... and I have also no idea what you mean by using RockGrid "as usual" - but I'm curious: Are you using it on the Frontend?

Share this post


Link to post
Share on other sites
54 minutes ago, bernhard said:

Still don't get it. We have forms all over PW (and the web), so it's hard to guess which one you are talking about... and I have also no idea what you mean by using RockGrid "as usual" - but I'm curious: Are you using it on the Frontend?

Sorry, im bad at explaining. It's a backend module and i use RockGrid to display lots o different data. The data is loaded from PW.

The question i had from the beginning was if i could create a RockGrid with plain PHP. 

The module has a form that gets submited with data, and i wanted to create a RockGrid just with the POST data, that originally was not getting saved.

Now the data gets saved to a page and i can easily use RockGrid with that data.

Small offtopic question: Can i change the separator to comma somehow?

Thanks!

Share this post


Link to post
Share on other sites

Ok thx, now I get it 😉 I've planned that feature, but can't remember that I've ever used it, so I don't know if that still works (see option 2, InputfieldRockGrid.module.php):

7QtbN2e.png

1 hour ago, gottberg said:

Small offtopic question: Can i change the separator to comma somehow?

If you are talking about excel export: yes. I don't have any sample code, see /plugins/buttons/excel.js

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2019-11-15 2019-10-18 2019-08-08 2019-06-15 2019-06-02 2019-05-25 If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      (please have a look at the screenshots to get an idea what I'm talking about)
       




    • By Robin S
      I have had this module sitting in a 95% complete state for a while now and have finally made the push to get it out there. Thanks to @teppo for his Hanna Code Helper module which I referred to and borrowed from during development.
      http://modules.processwire.com/modules/hanna-code-dialog/
      https://github.com/Toutouwai/HannaCodeDialog
      HannaCodeDialog
      Provides a number of enhancements for working with Hanna Code tags in CKEditor. The main enhancement is that Hanna tags in a CKEditor field may be double-clicked to edit their attributes using core ProcessWire inputfields in a modal dialog.
      Requires the Hanna Code module and >= ProcessWire v3.0.0.
      Installation
      Install the HannaCodeDialog module using any of the normal methods.
      For any CKEditor field where you want the "Insert Hanna tag" dropdown menu to appear in the CKEditor toolbar, visit the field settings and add "HannaDropdown" to the "CKEditor Toolbar" settings field.
      Module configuration
      Visit the module configuration screen to set any of the following:
      Exclude prefix: Hanna tags named with this prefix will not appear in the CKEditor toolbar dropdown menu for Hanna tag insertion. Exclude Hanna tags: Hanna tags selected here will not appear in the CKEditor toolbar dropdown menu for Hanna tag insertion. Background colour of tag widgets: you can customise the background colour used for Hanna tags in CKEditor if you like. Dialog width: in pixels Dialog height: in pixels Features
      Insert tag from toolbar dropdown menu
      Place the cursor in the CKEditor window where you want to insert your Hanna tag, then select the tag from the "Insert Hanna tag" dropdown.

      Advanced: if you want to control which tags appear in the dropdown on particular pages or templates you can hook HannaCodeDialog::getDropdownTags. See the forum support thread for examples .
      Edit tag attributes in modal dialog
      Insert a tag using the dropdown or double-click an existing tag in the CKEditor window to edit the tag attributes in a modal dialog.

      Tags are widgets
      Hanna tags that have been inserted in a CKEditor window are "widgets" - they have a background colour for easy identification, are protected from accidental editing, and can be moved within the text by drag-and-drop.

      Options for tag attributes may be defined
      You can define options for a tag attribute so that editors must choose an option rather than type text. This is useful for when only certain strings are valid for an attribute and also has the benefit of avoiding typos.
      Add a new attribute for the Hanna tag, named the same as the existing attribute you want to add options for, followed by "__options". The options themselves are defined as a string, using a pipe character as a delimiter between options. Example for an existing attribute named "vegetables":
      vegetables__options=Spinach|Pumpkin|Celery|Tomato|Brussels Sprout|Potato You can define a default for an attribute as normal. Use a pipe delimiter if defining multiple options as the default, for example:
      vegetables=Tomato|Potato Dynamic options
      Besides defining static options as above, you can use one Hanna tag to dynamically generate options for another. For instance, you could create a Hanna tag that generates options based on images that have been uploaded to the page, or the titles of children of the page.
      Your Hanna tag that generates the options should echo a string of options delimited by pipe characters (i.e. the same format as a static options string).
      You will probably want to name the Hanna tag that generates the options so that it starts with an underscore (or whatever prefix you have configured as the "exclude" prefix in the module config), to avoid it appearing as an insertable tag in the HannaCodeDialog dropdown menu.
      Example for an existing attribute named "image":
      image__options=[[_images_on_page]] And the code for the _images_on_page tag:
      <?php $image_names = array(); $image_fields = $page->fields->find('type=FieldtypeImage')->explode('name'); foreach($image_fields as $image_field) { $image_names = array_unique( array_merge($image_names, $page->$image_field->explode('name') ) ); } echo implode('|', $image_names); Choice of inputfield for attribute
      You can choose the inputfield that is used for an attribute in the dialog.
      For text attributes the supported inputfields are text (this is the default inputfield for text attributes so it isn't necessary to specify it if you want it) and textarea. Note: any manual line breaks inside a textarea are removed because these will break the CKEditor tag widget.
      Inputfields that support the selection of a single option are select (this is the default inputfield for attributes with options so it isn't necessary to specify it if you want it) and radios.
      Inputfields that support the selection of multiple options are selectmultiple, asmselect and checkboxes.
      You can also specify a checkbox inputfield - this is not for attributes with defined options but will limit an attribute to an integer value of 1 or 0.
      The names of the inputfield types are case-insensitive.
      Example for an existing attribute named "vegetables":
      vegetables__type=asmselect Descriptions and notes for inputfields
      You can add a description or notes to an attribute and these will be displayed in the dialog.
      Example for an existing attribute named "vegetables":
      vegetables__description=Please select vegetables for your soup. vegetables__notes=Pumpkin and celery is a delicious combination. Notes
      When creating or editing a Hanna tag you can view a basic cheatsheet outlining the HannaCodeDialog features relating to attributes below the "Attributes" config inputfield.
      Advanced
      Define or manipulate options in a hook
      You can hook HannaCodeDialog::prepareOptions to define or manipulate options for a Hanna tag attribute. Your Hanna tag must include a someattribute__options attribute in order for the hook to fire. The prepareOptions method receives the following arguments that can be used in your hook:
      options_string Any existing string of options you have set for the attribute attribute_name The name of the attribute the options are for tag_name The name of the Hanna tag page The page being edited If you hook after HannaCodeDialog::prepareOptions then your hook should set $event->return to an array of option values, or an associative array in the form of $value => $label.
      Build entire dialog form in a hook
      You can hook after HannaCodeDialog::buildForm to add inputfields to the dialog form. You can define options for the inputfields when you add them. Using a hook like this can be useful if you prefer to configure inputfield type/options/descriptions/notes in your IDE rather than as extra attributes in the Hanna tag settings. It's also useful if you want to use inputfield settings such as showIf.
      When you add the inputfields you must set both the name and the id of the inputfield to match the attribute name.
      You only need to set an inputfield value in the hook if you want to force the value - otherwise the current values from the tag are automatically applied.
      To use this hook you only have to define the essential attributes (the "fields" for the tag) in the Hanna Code settings and then all the other inputfield settings can be set in the hook.
      Example buildForm() hook
      The Hanna Code attributes defined for tag "meal" (a default value is defined for "vegetables"):
      vegetables=Carrot meat cooking_style comments The hook code in /site/ready.php:
      $wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) { // The Hanna tag that is being opened in the dialog $tag_name = $event->arguments(0); // Other arguments if you need them /* @var Page $edited_page */ $edited_page = $event->arguments(1); // The page open in Page Edit $current_attributes = $event->arguments(2); // The current attribute values $default_attributes = $event->arguments(3); // The default attribute values // The form rendered in the dialog /* @var InputfieldForm $form */ $form = $event->return; if($tag_name === 'meal') { $modules = $event->wire('modules'); /* @var InputfieldCheckboxes $f */ $f = $modules->InputfieldCheckboxes; $f->name = 'vegetables'; // Set name to match attribute $f->id = 'vegetables'; // Set id to match attribute $f->label = 'Vegetables'; $f->description = 'Please select some vegetables.'; $f->notes = "If you don't eat your vegetables you can't have any pudding."; $f->addOptions(['Carrot', 'Cabbage', 'Celery'], false); $form->add($f); /* @var InputfieldRadios $f */ $f = $modules->InputfieldRadios; $f->name = 'meat'; $f->id = 'meat'; $f->label = 'Meat'; $f->addOptions(['Pork', 'Beef', 'Chicken', 'Lamb'], false); $form->add($f); /* @var InputfieldSelect $f */ $f = $modules->InputfieldSelect; $f->name = 'cooking_style'; $f->id = 'cooking_style'; $f->label = 'How would you like it cooked?'; $f->addOptions(['Fried', 'Boiled', 'Baked'], false); $form->add($f); /* @var InputfieldText $f */ $f = $modules->InputfieldText; $f->name = 'comments'; $f->id = 'comments'; $f->label = 'Comments for the chef'; $f->showIf = 'cooking_style=Fried'; $form->add($f); } }); Troubleshooting
      HannaCodeDialog includes and automatically loads the third-party CKEditor plugins Line Utilities and Widget. If you have added these plugins to your CKEditor field already for some purpose and experience problems with HannaCodeDialog try deactivating those plugins from the CKEditor field settings.
    • By horst
      Wire Mail SMTP

      An extension to the (new) WireMail base class that uses SMTP-transport

      This module integrates EmailMessage, SMTP and SASL php-libraries from Manuel Lemos into ProcessWire. I use this continously evolved libraries for about 10 years now and there was never a reason or occasion not to do so. I use it nearly every day in my office for automated composing and sending personalized messages with attachments, requests for Disposition Notifications, etc. Also I have used it for sending personalized Bulkmails many times.

      The WireMailSmtp module extends the new email-related WireMail base class introduced in ProcessWire 2.4.1 (while this writing, the dev-branch only).
       
      Here are Ryans announcement.



      Current Version 0.4.2
      Changelog: https://github.com/horst-n/WireMailSmtp/blob/master/CHANGELOG.md
      get it from the Modules Directory Install and Configure

      Download the module into your site/modules/ directory and install it.

      In the config page you fill in settings for the SMTP server and optionaly the (default) sender, like email address, name and signature.
      You can test the smtp settings directly there. If it says "SUCCESS! SMTP settings appear to work correctly." you are ready to start using it in templates, modules or bootstrap scripts.


      Usage Examples
      The simplest way to use it:
      $numSent = wireMail($to, $from, $subject, $textBody); $numSent = wireMail($to, '', $subject, $textBody); // or with a default sender emailaddress on config page This will send a plain text message to each recipient.
       
      You may also use the object oriented style:
      $mail = wireMail(); // calling an empty wireMail() returns a wireMail object $mail->to($toEmail, $toName); $mail->from = $yourEmailaddress; // if you don't have set a default sender in config // or if you want to override that $mail->subject($subject); $mail->body($textBody); $numSent = $mail->send(); Or chained, like everywhere in ProcessWire:
      $mail = wireMail(); $numSent = $mail->to($toEmail)->subject($subject)->body($textBody)->send(); Additionaly to the basics there are more options available with WireMailSmtp. The main difference compared to the WireMail BaseClass is the sendSingle option. With it you can set only one To-Recipient but additional CC-Recipients.
      $mail = wireMail(); $mail->sendSingle(true)->to($toEmail, $toName)->cc(array('person1@example.com', 'person2@example.com', 'person3@example.com')); $numSent = $mail->subject($subject)->body($textBody)->send(); The same as function call with options array:
      $options = array( 'sendSingle' => true, 'cc' => array('person1@example.com', 'person2@example.com', 'person3@example.com') ); $numSent = wireMail($to, '', $subject, $textBody, $options); There are methods to your disposal to check if you have the right WireMail-Class and if the SMTP-settings are working:
      $mail = wireMail(); if($mail->className != 'WireMailSmtp') { // Uups, wrong WireMail-Class: do something to inform the user and quit echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>"; return; } if(!$mail->testConnection()) { // Connection not working: echo "<p>Couldn't connect to the SMTP server. Please check the {$mail->className} modules config settings!</p>"; return; }  
      A MORE ADVANCED DEBUG METHOD!
      You can add some debug code into a template file and call a page with it:
      $to = array('me@example.com'); $subject = 'Wiremail-SMTP Test ' . date('H:i:s') . ' äöü ÄÖÜ ß'; $mail = wireMail(); if($mail->className != 'WireMailSmtp') { echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>"; } else { $mail->from = '--INSERT YOUR SENDER ADDRESS HERE --'; // <--- !!!! $mail->to($to); $mail->subject($subject); $mail->sendSingle(true); $mail->body("Titel\n\ntext text TEXT text text\n"); $mail->bodyHTML("<h1>Titel</h1><p>text text <strong>TEXT</strong> text text</p>"); $dump = $mail->debugSend(1); } So, in short, instead of using $mail->send(), use $mail->debugSend(1) to get output on a frontend testpage.
      The output is PRE formatted and contains the areas: SETTINGS, RESULT, ERRORS and a complete debuglog of the server connection, like this one:
       
      Following are a ...


      List of all options and features


      testConnection () - returns true on success, false on failures


      sendSingle ( true | false ) - default is false

      sendBulk ( true | false ) - default is false, Set this to true if you have lots of recipients (50+)


      to ($recipients) - one emailaddress or array with multiple emailaddresses

      cc ($recipients) - only available with mode sendSingle, one emailaddress or array with multiple emailaddresses

      bcc ($recipients) - one emailaddress or array with multiple emailaddresses

       
      from = 'person@example.com' - emailaddress, can be set in module config (called Sender Emailaddress) but it can be overwritten here

      fromName = 'Name Surname' - optional, can be set in module config (called Sender Name) but it can be overwritten here


      priority (3) - 1 = Highest | 2 = High | 3 = Normal | 4 = Low | 5 = Lowest

      dispositionNotification () or notification () - request a Disposition Notification


      subject ($subject) - subject of the message

      body ($textBody) - use this one alone to create and send plainText emailmessages

      bodyHTML ($htmlBody) - use this to create a Multipart Alternative Emailmessage (containing a HTML-Part and a Plaintext-Part as fallback)

      addSignature ( true | false ) - the default-behave is selectable in config screen, this can be overridden here
      (only available if a signature is defined in the config screen)

      attachment ($filename, $alternativeBasename = "") - add attachment file, optionally alternative basename


      send () - send the message(s) and return number of successful sent messages


      debugSend(1) - returns and / or outputs a (pre formatted) dump that contains the areas: SETTINGS, RESULT, ERRORS and a complete debuglog of the server connection. (See above the example code under ADVANCED DEBUG METHOD for further instructions!)


      getResult () - returns a dump (array) with all recipients (to, cc, bcc) and settings you have selected with the message, the message subject and body, and lists of successfull addresses and failed addresses,


      logActivity ($logmessage) - you may log success if you want

      logError ($logmessage) - you may log warnings, too. - Errors are logged automaticaly
       
       
      useSentLog (true | false) - intended for usage with e.g. third party newsletter modules - tells the send() method to make usage of the sentLog-methods - the following three sentLog methods are hookable, e.g. if you don't want log into files you may provide your own storage, or add additional functionality here

      sentLogReset ()  - starts a new LogSession - Best usage would be interactively once when setting up a new Newsletter

      sentLogGet ()  - is called automaticly within the send() method - returns an array containing all previously used emailaddresses

      sentLogAdd ($emailaddress)  - is called automaticly within the send() method
      Changelog: https://github.com/horst-n/WireMailSmtp/blob/master/CHANGELOG.md
       
       
    • By Robin S
      Sanitizer EasySlugger
      Allows the use of the EasySlugger library as Sanitizer methods.
      Installation
      Install the Sanitizer EasySlugger module.
      Usage
      The module adds four new sanitizer methods.
      slugger($string, $options)
      Similar to $sanitizer->pageName() - I'm not sure if there are any advantages over that method. Included because it is one of the methods offered by EasySlugger.
      $slug = $sanitizer->slugger('Lorem Ipsum'); // Result: lorem-ipsum utf8Slugger($string, $options)
      Creates slugs from non-latin alphabets.
      $slug = $sanitizer->utf8Slugger('这个用汉语怎么说'); // Result: zhe-ge-yong-han-yu-zen-me-shuo seoSlugger($string, $options)
      Augments the string before turning it into a slug. The conversions are related to numbers, currencies, email addresses and other common symbols.
      $slug = $sanitizer->seoSlugger('The price is $5.99'); // Result: the-price-is-5-dollars-99-cents See the EasySlugger readme for some more examples.
      seoUtf8Slugger($string, $options)
      A combination of utf8Slugger() and seoSlugger().
      $slug = $sanitizer->seoUtf8Slugger('价钱是 $5.99'); // Result: jia-qian-shi-5-dollars-99-cents $options argument
      Each of the methods can take an $options array as a second argument.
      separator (string): the character that separates words in the slug. Default: - unique (bool): Determines whether a random suffix is added at the end of the slug. Default: false $slug = $sanitizer->utf8Slugger('这个用汉语怎么说', ['separator' => '_', 'unique' => true]); // Result: zhe_ge_yong_han_yu_zen_me_shuo_3ad66c4  
      https://github.com/Toutouwai/SanitizerEasySlugger
      https://modules.processwire.com/modules/sanitizer-easy-slugger/
    • By Robin S
      If you've ever needed to insert links to a large number of files within CKEditor you may have found that the standard PW link modal is a somewhat slow way to do it.
      This module provides a quicker way to insert links to files on the page being edited. You can insert a link to an individual file, or insert an unordered list of links to all files on the page with a single click.
      CKEditor Link Files
      Adds a menu to CKEditor to allow the quick insertion of links to files on the page being edited.

      Features
      Hover a menu item to see the "Description" of the corresponding file (if present). Click a menu item to insert a link to the corresponding file at the current cursor position. The filename is used as the link text. If you Alt-click a menu item the file description is used as the link text (with fallback to filename if no description entered). If text is currently selected in the editor then the selected text is used as the link text. Click "* Insert links to all files *" to insert an unordered list of links to all files on the page. Also works with the Alt-click option. Menu is built via AJAX so newly uploaded files are included in the menu without the page needing to be saved. However, descriptions are not available for newly uploaded files until the page is saved. There is an option in the module config to include files from Repeater fields in the edited page. Nested Repeater fields (files inside a Repeater inside another Repeater) are not supported. Installation
      Install the CKEditor Link Files module.
      For any CKEditor field where you want the "Insert link to file" dropdown menu to appear in the CKEditor toolbar, visit the field settings and add "LinkFilesMenu" to the "CKEditor Toolbar" settings field.
       
      http://modules.processwire.com/modules/cke-link-files/
      https://github.com/Toutouwai/CkeLinkFiles
×
×
  • Create New...