Skip to content

Conversation

@iainhallam
Copy link
Contributor

@iainhallam iainhallam commented Feb 26, 2018

This addition addresses #145 and adds an inline syntax following the existing Struct model, plus a shorthand for a single variable; examples follow.

Value from the current page:

{{$myschema.myfield}}

Value from another page:

{{$"ns:second.page".myschema.myfield}}

Filters can be added manually following a question mark; to keep flexibility for future features like summarize, this means you need to restrict to the page you want yourself. Filters must be in double quotes:

{{$$ID$.myschema.myfield ? filter: "myfield < 5" or: "myfield > 5"}}

Filtering supports the usual Struct keywords, filter, where, filterand, and, filteror, or, followed immediately by a colon, or the shortcuts & and |. The value above can be written:

{{$$ID$.myschema.myfield ? & "myfield < 5" | "myfield > 5"}}

@iainhallam
Copy link
Contributor Author

I think that this check failed due to external factors - is there a way to rerun the tests?

@iainhallam
Copy link
Contributor Author

@splitbrain I believe the build failure was at the time that the stable build didn't work with PHP 7 - is it possible to rerun the tests any way, please?

@eilko
Copy link

eilko commented Mar 14, 2019

@splitbrain can this request be merged please?

@moz0817
Copy link

moz0817 commented Mar 16, 2019

Very useful extension - thank you very much. I have two annotations:

1: It don't works with relative sites like sidebar or pageheader. This might be useful two.
2: If the shown values would be inline editable - my luck would be unbelievable ;-). Then it's possible to create your own edit forms.

@annda
Copy link
Contributor

annda commented Apr 23, 2019

This looks very good, I would also like to see the inline syntax merged. The new feature probably does not require any test, maybe for the InlineConfigParser

@splitbrain what do you think?

Copy link
Member

@splitbrain splitbrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea and agree that it should be merged soon. The code looks very good already, but there are some things I'd like to see addressed first. See my inline comments for details.

*
* @param int $show_not_found Whether to display the default text for no records
*/
public function render($show_not_found = 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to pass a boolean here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is taken directly from the config array, so will always be given a 0 or 1 depending on the config file. Should I convert a config 0 to Boolean false and config 1 to Boolean true before making use of the value, @splitbrain?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I would convert it.


/** @var AggregationValue $value */
$value = new AggregationValue($INFO['id'], $mode, $renderer, $search);
$value->render($show_not_found);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the above does not need to happen during metadata rendering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not where the value would be put into the text of the abstract when rendering metadata? This is quite a complex part of the DokuWiki code and I'm not at all sure I understand it!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think you might be right. I forgot about that. Maybe give it a quick try by putting the value right at the top of the page and see what ends up in the abstract

neoocean added a commit to neoocean/neoocean.net-dokuwiki-1 that referenced this pull request Jan 15, 2020
neoocean added a commit to neoocean/neoocean.net-dokuwiki-1 that referenced this pull request Jan 15, 2020
@fschrempf
Copy link
Contributor

@iainhallam Do you intend to respond to @splitbrain's review comments above?
It would be great to have this merged and it looks like you were close to bring this over the finish line back in 2018.

@fschrempf

This comment has been minimized.

@fschrempf
Copy link
Contributor

fschrempf commented Jan 24, 2021

One other thing I noticed with a rather special use case:

I want to overwrite the meta page title with data from a struct field. So I tested this PR in combination with the page title plugin. The page content rendering is correct, but the meta title shows "Nothing found" when show_not_found is enabled. So somehow the struct data is not passed to the meta renderer correctly!?

====== Header1 {{"$test.test"}} ======

Struct data: {{$test.test}}

<title>
{{$test.test}}
</title>

becomes:

grafik

@iainhallam
Copy link
Contributor Author

@iainhallam Thanks a lot for picking up this work. I just tested your latest changes and while I can get the value from the schema to be rendered correctly in normal text, it doesn't work in headings. Is this a known/expected limitation?

This is a limitation of DokuWiki - you can't have any syntax inside headers:

https://www.dokuwiki.org/faq:headerlinks

@iainhallam iainhallam marked this pull request as draft January 25, 2021 19:06
@fschrempf
Copy link
Contributor

Ok, for the first example. That's a DokuWiki limitation. What about the second example using the pagetitle plugin? I think that's a different case, as the syntax is actually parsed, only the data is missing in the meta rendering.

@iainhallam
Copy link
Contributor Author

Ok, for the first example. That's a DokuWiki limitation. What about the second example using the pagetitle plugin? I think that's a different case, as the syntax is actually parsed, only the data is missing in the meta rendering.

I'll need to take some time to delve into this - I don't feel I have a handle on the metadata parts of DW at the moment.

@fschrempf
Copy link
Contributor

I'll need to take some time to delve into this - I don't feel I have a handle on the metadata parts of DW at the moment.

Sure. I had a quick look for myself, but unfortunately I couldn't get the hang of it either so far. And I'm not even sure if this should be in the scope of this PR or rather something to look at after getting this merged.

@Juergen-aus-Zuendorf
Copy link

Juergen-aus-Zuendorf commented Jan 26, 2021

@iainhallam:
Could you perhaps test if your changes would support to use this variable inside an aggregation as filter, described in issue #145, comment "on 2 Apr 2019" ?

Example:

---- struct table ----
schema : fbg_ident, fbg_meta
cols   : fbg_ident.fbg-fkt, fbg_meta.fbg-mtyps
filter : fbg-schlagwort = {{$my_page.fbg_meta.fbg-mtyps}}
----

This would be extremely helpful. Thanks a lot in advance

Regards, Juergen

@iainhallam
Copy link
Contributor Author

@Juergen-aus-Zuendorf

---- struct table ----
schema : fbg_ident, fbg_meta
cols   : fbg_ident.fbg-fkt, fbg_meta.fbg-mtyps
filter : fbg-schlagwort = {{$my_page.fbg_meta.fbg-mtyps}}
----

This is already available for the current page using the format filter : fbg-schlagwort = $STRUCT.fbg_meta.fbg-mtyps$. See the docs at:

https://www.dokuwiki.org/plugin:struct:filters

My changes essentially add an inline syntax to the Struct configuration parser and an aggregation to display a single value, so this would be a change to the Struct configuration parser logic itself, that would need to add the ability to specify a page in that type of filter. Can you raise a separate issue for that, please?

@iainhallam iainhallam requested a review from splitbrain February 7, 2021 13:38
@iainhallam iainhallam marked this pull request as ready for review March 13, 2021 15:24
@splitbrain
Copy link
Member

Sorry for the delay in answering your comments. @annda if you're working on this, maybe fix the few little things from above right on merging.

@annda
Copy link
Contributor

annda commented Apr 21, 2021

I find this feature very useful and would like to finally merge it.

I have two questions though:

serial data: At this point there is no check on rid so the search might in some rare cases return serial data instead of page data. Is this something we should be concerned about? (Probably simply adding %rowid% = 0 to the filters in InlineConfigParser would take care of that.)

syntax: The {{$...}} pattern is concise and easy to write, but there is no obvious association with the plugin it belongs to. As someone who often needs to troubleshoot, I prefer the earlier version of {{structvalue ...}}. Any opinions on that, everyone?

@Juergen-aus-Zuendorf
Copy link

Juergen-aus-Zuendorf commented Apr 22, 2021

Although due to the long time span in the meantime, I already worked with iainhallam's extension (thanks for this) and now I would have to adjust the syntax everywhere:
On the one hand, {{structvalue ...}} is much better for association with the plugin. On the other hand, if you might want to search and replace syntax elements of the function, you can easily search the keyword "structvalue" with dokuwiki's search mechanism.

One more question: What's about the filtering syntax "{{$$..."?

@iainhallam
Copy link
Contributor Author

One more question: What's about the filtering syntax "{{$$..."?

@Juergen-aus-Zuendorf Where's that syntax used; have you got an example?

@Juergen-aus-Zuendorf
Copy link

Perhaps this is a misunderstanding from myside:

At the beginning of this thread you described the following:
{{$$ID$.myschema.myfield ? & "myfield < 5" | "myfield > 5"}}
Therefore, my previous question: "What's about the filtering syntax "{{$$..."?"
Is it possible to use placeholders within the syntax? And how should it be written in this case?

@iainhallam
Copy link
Contributor Author

At the beginning of this thread you described the following:
{{$$ID$.myschema.myfield ? & "myfield < 5" | "myfield > 5"}}
Therefore, my previous question: "What's about the filtering syntax "{{$$..."?"
Is it possible to use placeholders within the syntax? And how should it be written in this case?

Ah. The configuration is mainly syntactic sugar, so it passes the page ID straight on to the main Struct parser. That syntax is actually the same {{$ with the ID placeholder from the main Struct documentation, $ID$ (meaning this current page), as the page name.

It would perhaps be clearer to require a user to specify that they want the query to apply to all pages with something like:

/* Current page */
{{$myschema.myfield ? filter: "myfield < 5" or: "myfield > 5"}}

/* Specific page */
{{$other-page.myschema.myfield ? filter: "myfield < 5" or: "myfield > 5"}}

/* Search all pages */
{{$*.myschema.myfield ? filter: "myfield < 5" or: "myfield > 5"}}

@Juergen-aus-Zuendorf
Copy link

I think your suggestion is very good!

Alternatively, I would find it just as good to use the automatism with the placeholders, if this is documented in detail in the plugin description.

And once again my attempt (as syntactic sugar):
Couldn't the filtering likewise support the comparison with a Struct value of another page, e.g. in this form:
{{$myschema.myfield ? filter: "myfield = {{$other-page.otherschema.otherfield}}"}}

Best regards
Juergen

@iainhallam
Copy link
Contributor Author

I think your suggestion is very good!

Will have a go at redoing that part when I can.

Couldn't the filtering likewise support the comparison with a Struct value of another page, e.g. in this form:
{{$myschema.myfield ? filter: "myfield = {{$other-page.otherschema.otherfield}}"}}

Struct already has a syntax for that, and your bug report #552 should take care of specific pages. I won't be adding it to this aggregation.

@annda annda merged commit 812a20f into cosmocode:master Jun 17, 2021
@annda
Copy link
Contributor

annda commented Jun 17, 2021

@iainhallam Can you update the documentation?

@iainhallam
Copy link
Contributor Author

Documentation updated at https://www.dokuwiki.org/plugin:struct:aggregation.

@iainhallam iainhallam deleted the feature/value branch August 20, 2021 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants