CameronWard301 / airtable

A Dokuwiki plugin to sync data from airtable
GNU General Public License v3.0
2 stars 2 forks source link

Feature Request: Render DokuWiki style links #15

Open Joecorleone opened 3 years ago

Joecorleone commented 3 years ago

Hi @CameronWard301 , I am enjoying the possibilities provided by your plugin. In my case I am creating wiki pages for each of the records in a certain table in airtable and using the information from the table for an overview and on each individual page to have an automated description. I added a DokuWiki style link [[ namespace:page | label ]] to each record referencing the corresponding wiki page. Well, I realized, that links have to be rendered as you are doing here. In principle I can use absolute links to each wiki page and the field type "url" in airtable. Then they could be used in airtable. However, in many cases being able to provide a label for a link provides a better look in DokuWiki, like in [[ link | label ]]. Are you planning to support rendering of DokuWiki style links?

Edit: To summarize, I am actually just looking for a way to define a label for urls, to improve how links from airtable can be displayed in DokuWiki. In the end defining the label in a link like this https://wiki.url.com/doku.php?dwlabel="labelText"&id=namespace:page would be equally great. It would have the advantage, that the link can be used in airtable too.

Edit2: One thing I did not consider in the suggestion in "Edit" is, that this way the links are marked as external and not marked as (non)existing.

CameronWard301 commented 3 years ago

Hi @Joecorleone As far as I'm aware, dokuwiki syntax produced and rendered onto a page within a plugin is not parsed again by dokuwiki. So if you were to write dokuwiki syntax in airtable, it would be ignored by dokuwiki.

As I understand it, if the url contained dwlabel="labelText" then the plugin could then hide the url behind the label? So when you click on labelText it takes you to the url defined?

Let me know if I have understood correctly :)

Joecorleone commented 3 years ago

Hei, thanks for your reply. Yes, exactly I hoped it would be parsed again, but that seems not to be the case. So one has to parse it oneself ...

Yes, I thought offering the option to add a dwlabel="labelText" qualifier, would allow to keep the link usable in airtable. Then during the parsing renderAnyExternalLinks one could use the qualifier as a label to hide the text.


I had some fun playing around with your code. My knowledge of php is very lacklustre, so my solution is probably quite ugly. Anyway, I implemented a way to display the values in rating and checkbox fields as symbols. I can make fork, if you prefer.

syntax.php for displaying rating and checkbox as symbols Screenshot 2021-07-04 215343 command in DokuWiki {{airtable>type: "table" | record-url: "https://airtable.com/tblXYZ/viwABC?blocks=hide" | fields: "Project" , "Description", "Priority", "Completed" | where: "{Completed}=0" | order-by: "Priority" | order: "desc" | rating-fields: "Priority" | checkbox-fields: "Completed" }}

Edit: I just realized that the fields are called "rating" and "checkbox" in airtable. I changed it accordingly.

CameronWard301 commented 3 years ago

@Joecorleone I like the concept. Had a quick look at the fork. It would be better if the plugin could recognise the type of the fields entered and decide how to render them without the user specifying to do so.

Then you wouldn't have to write: priority-fields: "Priority" | checkmark-fields: "Completed", you could just write the fields like you have done earlier in the string.

What data does airtable API return for the "Priority" and "Completed" fields? Could the plugin recognise the type as a checkbox field?

Joecorleone commented 3 years ago

Yes, I absolutely agree. That would be much better. I will look through the API more. If the API returns the field type, that would be nice. The data returned by the API is 0 or 1 for a Checkbox field and 0 to 10 for a Rating field (depends on what was specified for the field).

CameronWard301 commented 3 years ago

@Joecorleone Ok, as far as I'm aware Airtable has a Meta API that could be used to get field types but they've closed access to it and haven't allowed any new members for about a year now (typical 😢 )

I'm wondering if it would be beneficial to specify the field type in the dokuwiki query so the plugin can process the data more effectively. Something like:

{{airtable>type: "table" | record-url: "https://airtable.com/tblXYZ/viwABC?blocks=hide" | fields: "Project:String" , "Description:String", "Priority:Rating", "Completed:Checkbox" | where: "{Completed}=0" | order-by: "Priority" | order: "desc" }}

It would mean more the user would have to type in and get right but could offer more functionality? Let me know what you think :)

Edit: Could also have a "link" type for any external links with the option to have a label there? It would be more convenient and efficient if we could use airtables Meta API but who knows when that might be available.

Joecorleone commented 3 years ago

Oh okay, I wasn't aware that they provided something like that previously. Now I am extra sad 😃 In regards to support displaying the rating and checkbox fields as desired, I definitely prefer your solution over mine. This way it is more extendable and flexible. In order to separate field name and type, does php have a right split function? I worry that people might use ":" in field names. How do you envision the link label? something like "urlFieldA:DokuLink" for [[ namespace:space | label ]] and "urlFieldB:ExtLink" for https://...?dwlabel="textLabel"&id=namespace:page ?

Edit: Just one comment. While defining the structure, maybe there is also a way for the user to specify the symbol to be used for rating (and checkbox). Airtable has these options: (checkmark,) star, heart, thumb and flag. Maybe there are cases, where this is relevant to the meaning. Maybe it can be just the a suffix like "Priority:Rating★" or using a separator as you prefer .

CameronWard301 commented 3 years ago

@Joecorleone Hmm true, yes probably people would have a colon in a field title. Maybe a user could write: fields: "Project"@String, "Priority"@Rating}} instead?

Then for links they could write: fields: "PartURL"@URL:"The Label" ? Or is this too complicated now?

Joecorleone commented 3 years ago

Well, to me fields: "Project"@String, "Priority"@Rating looks like a nice solution. I would say it is clearer, than having both field and type within the quotation marks.

I just checked how one would parse the input. Not pretty but manageable

function decode($string){
    $indexAt = strrpos($string, '@');
    $indexQM = strrpos($string, '"');
    if ($indexAt>$indexQM){
        $field = substr($string, 0,$indexAt);
        $type = substr($string, $indexAt+1,strlen($string)-$indexAt);
    } else {
        $field = $string;
        $type = "String";
    }
    echo "field " . $field . "\n";
    echo "type " . $type . "\n";
}

$stringA = '"Priority @ work"@Rating';
$stringB = '"Priority @ work"';

decode($stringA);
decode($stringB);

About the URL label, I see what you are trying to do. I guess there is a case for that option too. In my case, I have a list of projects in an airtable. This table I want to display in DokuWiki, while using the link as the name in the first column. Screenshot Corresponding internal DokuLink [[ projects:innovationloop2 | Innovation Loop 2 (data logger) ]]. For that I need to be able to define a label per record. Still a general label used for all links in a column, can be useful in other cases.

CameronWard301 commented 3 years ago

@Joecorleone Ahh I see, so you want to define the your link label in airtable? In which case adding dwlabel="textLabel" to your url would be the best option I think :)

CameronWard301 commented 2 years ago

@Joecorleone Check the latest dev branch, I think this is now resolved :)

Joecorleone commented 2 years ago

@CameronWard301 Hei, thanks for your effort and sorry, that I have not responded yet. I have been busy with other tasks recently. Hopefully, I can come back to this soon.