Jump to content

[SOLVED] Best method to create calculation across multiple pages, in the admin, like a spreadsheet


Recommended Posts

Posted

Hi All,

I haven't found this answer in the docs or forums. I know how to program a template that would display multi-page field calculations like a spreadsheet, e.g. with 100 pages, each with a dollar value in a field, display the total dollar value of a subset of the 100 pages based on a "sold" data field value.

I know how to put that template / url / page behind a password.

What I'm not clear about is whether or not PW has an easier method than that. For example, in the standard admin, create a page/template that has the summary fields in it and pull the calculations from the "item" pages whenever the summary page is accessed or a button is pressed. Or something like that. So that the calculations can be viewed in the admin without having to build a password protected, programmed front-end page.

Of course, a spreadsheet can do all this easily, but after thousands of records, it becomes rather unwieldy, in my opinion.

What do people recommend?

Thanks,

Peter

 

Posted
1 hour ago, Peter Falkenberg Brown said:

For example, in the standard admin, create a page/template that has the summary fields in it and pull the calculations from the "item" pages whenever the summary page is accessed or a button is pressed

Typically two choices if you want a custom 'view' in the admin. 

  1. If custom view per page, i.e. as some sort of field / inputfield: have a look at the growing number of runtime markup fields in the module's directory
  2. A dedicated admin page view: You will need to create a custom module.

More specifically, regarding data, and lots of it or spreadsheet-like data, have a look at @bernhard's modules and work in the forum. Looks like he has done extensive work in this respect. 

I am in a bit of a rush so cannot be more concrete. Hope this helps you get started.

  • Like 2
Posted

Hey @Peter Falkenberg Brown I'm not exactly sure what you are trying to do, but if you want some kind of excel-like data listing (maybe with filter and sorting functionality) you can have a look at RockHitCounter which uses a quick and simple implementation of tabulator.info to list page hit statistics:

https://github.com/baumrock/RockHitCounter/blob/main/ProcessRockHitCounter.module.php

https://github.com/baumrock/RockHitCounter/blob/main/fields/table.php

If you simply want to show aggregated data in the admin page edit then as @kongondo said you can use one of the runtime markup fields. Or a hook:

// site/ready.php
$wire->addHookAfter("ProcessPageEdit::buildFormContent", function($event) {
  $page = $event->process->getPage();
  if($page->template != 'yourpagetemplate') return;

  /** @var InputfieldWrapper $form */
  $form = $event->return;

  $f = $this->wire(new InputfieldMarkup()); /** @var InputfieldMarkup $f */
  $f->label = 'My Markup Field';
  $f->icon = 'exclamation-triangle';
  $f->value = 'Dynamic Markup @ ' . date('Y-m-d H:i:s');

  // insert dynamic field after the "title" field
  $form->insertAfter($f, $form->get('title'));
});

 

  • Like 1
Posted

Hi @dotnetic,

 

(An aside: I created a spreadsheet that does all of this very quickly. Easy as pie. However, in some cases, a PW database might be better, thus my questions. On the other hand, maybe trying to fit PW with the functionality of spreadsheets is a waste of time. You know... the right tool for the job.)

Yes, the PagesSum module is exactly what I need. Thank you!

But... in the Admin section, with the standard tree of page types (i.e. templates), assuming that I have a branch of pages called "sales," then where and how could I display the sum of those sales pages (from a field called "sale_price") on the admin page?

I haven't adequately dug into the task of modifying the admin page. In a custom app, all based on php template docs, I would simply display that total on the apps version of the "home" page, i.e. like the Admin tree page. But in the PW Admin page, I haven't yet learned how to add a routine to display something like that on the top level admin page.

Is there a document somewhere in the PW knowledge base on how to do that?

I've already made one small modification to the admin's core files in the wire directory, in a file called "AdminTheme.php." In that file, in the routine

public function ___getExtraMarkup()

I change this code:

if($isLoggedin && $this->wire('config')->advanced) {

	# $parts['footer'] = "<p class='AdvancedMode'><i class='fa fa-flask'></i> " . $this->_('Advanced Mode') . "</p>";

	$parts['footer'] = str_repeat('&nbsp;', 10) . "DB: " . wire('config')->dbName . "<br><br>";
}

... so that the admin page would display the name of the database in use (to avoid a dev version using the live db by mistake).

( @ryan Ryan, I think this would be a good addition to the core.)

I realize that it's a Bad Idea to modify core files, so in terms of modifications to the admin home/tree page, with the Sum function display, I'm hoping that there's a hook method, or some other way to get that data displayed on the page, without messing with the core files.

Thanks!

Peter

 

Posted
4 hours ago, Peter Falkenberg Brown said:

then where and how could I display the sum of those sales pages (from a field called "sale_price") on the admin page?

I would suggest using something like the great Dashboard (Dashboard) - ProcessWire Module. You can easily add a custom PHP file to render whatever you want on a separate "Dashboard" page. It even has nice predefined "panels" with can show something like a sum with an up or downtrend arrow.

Dashboard

It is very easy to setup and comes with good examples.

  • Like 2
  • Peter Falkenberg Brown changed the title to [SOLVED] Best method to create calculation across multiple pages, in the admin, like a spreadsheet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...