Giter Site home page Giter Site logo

grav-plugin-data-manager's Introduction

Grav Data Manager Plugin

The Data Manager Plugin for Grav adds the ability to visualize data. This is particularly useful for the admin and form plugins. Additional plugins may store data content, and the Data plugin - properly configured - is able to show their data too.

| IMPORTANT!!! This plugin is currently in development as is to be considered a beta release. As such, use this in a production environment at your own risk!. More features will be added in the future.

Installation

The Data plugin is easy to install with GPM.

$ bin/gpm install data-manager

Or clone from GitHub and put in the user/plugins/data-manager folder.

Configuration

You don't need any configuration to start using the plugin. Knowing how to configure it, as illustrated later, will allow you to take advantage of a few handy customization options.

Remember: copy the user/plugins/data-manager/data-manager.yaml into user/config/plugins/data-manager.yaml and make your modifications in your user folder.

Usage

Once installed the Data plugin shows a Data Manager item in the admin menu. Click that, and the Data plugin will show you the available data types found in the user/data folder.

Clicking a data type will show the list of items. For example you might have a contact form setup in your site, using the Form plugin. A Contact type should show up, depending on how you called that form data items (data types names are taken from the user/data/ folder names, unless customized - see below).

For example you might have a form.md contact form with:

---
title: A page with a form
form:
    name: contactform
    fields:
        - name: name
          label: Name
          placeholder: Enter your name
          autofocus: on
          autocomplete: on
          type: text
          validate:
            required: true

        - name: email
          label: Email
          placeholder: Enter your email address
          type: text
          validate:
            rule: email
            required: true

    buttons:
        - type: submit
          value: Submit
        - type: reset
          value: Reset

    process:
        - save:
            fileprefix: contact-
            dateformat: Ymd-His-u
            extension: yaml
            body: "{% include 'forms/data.txt.twig' %}"
        - message: Thank you for your feedback!
---

# Nice contact form

In this case, you have a name and an email field. If you enable the plugin and go in the admin side, you'll see under the Data menu the Contactform type.

Click that, and all the contact information entered is browsable, listed by filename, and you can click an item to show its details.

Customization

All the things listed above come out of the box, without you needing to do anything special. Now, let's make the list more user friendly.

List customization

By default the list shows items listed by the filename. You might want to show some more information in the list, so you can for example have 2 columns, name and email.

Open the user/config/plugins/data-manager.yaml and add the structure of the data files, and the files extension. The name of the type is the one of the data/ subfolder (in the case of the Form plugin, set by form.name)

types:
  contactform:
    list:
      columns:
        -
            field: name
            label: Name
        -
            field: email
            label: Email

Columns with nested content

To show in the items list nested content, use an array:

list:
  columns:
    -
      field: ['address', 'email']
      label: Email

Will render the address.email value.

Single item customization

enabled: true

types:
  contactform:
    item:
      fields:
        name:
          name: Token
        email:
          name: Email

Will render those fields listed, and just those fields. By default, the single item view lists all the fields found in the file.

File extension customization

Usually data is saved in .yaml files. You can change that per-type by setting:

types:
  contactform:
    file_extension: '.txt'

Customize the type name

By default the Types list shows the folder name. You can add

types:
  contactform:
    name: Contact Form

to provide a better name.

Override items list and item detail templates

You can override items list and item details Twig templates using a plugin.

By doing this, you can build plugins that

  1. store data in the data/ folder
  2. have complete control over the data rendering in the admin-side

You can register the templates in the admin-side and put them in your plugin templates folder under partials/data-manager/[typename]/item.html.twig and/or partials/data-manager/[typename]/items.html.twig.

Programmatically exclude a data folder from the Data Manager

Say you are developing a plugin that stores in the data/ folder, and you want to create your own admin interface to show the data. No problem! You can instruct the Data Manager plugin to ignore your data type (data/ subfolder).

Just listen for the onDataTypeExcludeFromDataManagerPluginHook event

$this->enable([
    'onDataTypeExcludeFromDataManagerPluginHook' => ['onDataTypeExcludeFromDataManagerPluginHook', 0],
]);

and add the data type you want to exclude by adding it to a property of the Admin Plugin:

 public function onDataTypeExcludeFromDataManagerPluginHook()
 {
     $this->grav['admin']->dataTypesExcludedFromDataManagerPlugin[] = 'comments';
 }

Future improvements

This is a first revision of the plugin.

Ideas for the near future:

  • Allow plugins to define yaml for data,
  • Better integration with the Form plugin (auto-determine types definition)
  • Add a "process" field in the columns/fields to filter raw data (e.g. dates or booleans)

grav-plugin-data-manager's People

Contributors

cworreschk avatar flaviocopes avatar hughbris avatar johnmica avatar karmalakas avatar lufog avatar mahagr avatar ndrosis avatar rhukster avatar rotanadan avatar w00fz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

grav-plugin-data-manager's Issues

Installation error gpm_Instance.payload.payload is undefined

Hello,
if I want to install this plugin I get the following error:

Bildschirmfoto vom 2023-10-15 00-12-39

Content of the error message:

addNeededDependencyToList@https://MYDOMAIN.COM/user/plugins/admin/themes/grav/js/admin.min.js?c78ff7a9b8:10317:25
56299/getPackagesDependencies/<@https://MYDOMAIN.COM/user/plugins/admin/themes/grav/js/admin.min.js?c78ff7a9b8:10057:26
56299/request/<@https://MYDOMAIN.COM/user/plugins/admin/themes/grav/js/admin.min.js?c78ff7a9b8:890:12

I am using the grav theme v2.0.4

Nothing appears in the data manager

Hello,
i have a grav installation in a subfolder of my website, everything is working, the plugin is successfully installed and enabled but when i put data in my /user/data folder (zip files), i see nothing.
i've tried with jpg and png files to check if it was an extension problem, but i don't see anything in the data manager in the admin panel...

To be sure i have chmod 777 the user and the data folder but still nothing.

any idea ?

Also if it can helps, i've installed the download-counter plugin which should create some file or folder in the /user/data directory, but there is nothing as well.

How to format field names?

How can we display certain field names in Data Manager in a particular way? E.g. no matter how these fields are rendered by the plugin, DM prints them like this:

Url: 'https://domain.com/non-existant-page'
Time: '2024-03-02 12:19:27pm'
Referrer: ''
Ip: 1.2.3.4

I would like them to display like this:

URL: 'https://domain.com/non-existant-page'
Time: '2024-03-02 12:19:27pm'
Referrer: ''
IP: 1.2.3.4

After going over the Readme multiple times, I can't get this to work. Has anyone done this successfully?

Thanks.

Value of hidden field is displayed in thank you page

Hi,

I set up a very simple and basic form as shown in the grav documentation site.

I added the following hidden field:

- name: user-name
          type: hidden
          default: my-value

The form works fine, the data is saved and accessible via the data manager. But on the thank you page which is also the basic one as shown in the documentation; the value of the hidden field is showing in the list of submitted content.

Replace Data Manager menu icon

Pages menu icon and Data Manager menu icons looking similar. I think it can be better to replace current Data Manager menu icon with fa-database icon.
Now:
01
After:
02

Public access to CSV export

Apparently it seems the URL to download the CSV is publicly available. Just checked it by copying the link location of the "Download as CSV" file and pasting it in a private window. This lead me to being able to download the CSV file without authentication.

I see this as quite a security flaw, especially since the download URL does not change. Not sure if a robot or web crawler could find the URL, but I guess it's just a matter of time till the URL is crawled.

Plugin points to wrong data folder in multi-site grav setup

I am using the Grav Multi-site setup such that I have mainsite.com with two sub-sites: mainsite.com/subsite1 and mainsite.com/subsite2. When I log in to the admin panel using mainsite.com/admin I see the data manager pulls the data from user/data, however when I log into any of my sub-site admin panels the data manager still points to the mainsite's data folder rather than using the sub-site's folder using the path user/sites/subsite1/data. I tried to poke around and see if there was an easy way to redirect it but didn't find what I was looking for. Any suggestions on how to fix this would be appreciated!

Issue in page url after login

Issue in page url after login

site url : test.com

after login getting : test.com:8081/admin

Because of the port didn't getting the admin page, after removing port it is working fine

How to avoid port from url after login?

bug when multiple use of item.html.twig

Data-Manager is a great plugin for developing.!!! But it fails if used too often.

Briefly my problem

  • I have written two plugins, one customises the type list, called here var-dumper, the other customises the type details, called content-edit.
  • However, when I enable var-dumper, which customises type list, the customised type detail for the other plugin disappears.
  • Two types (using the terminology of DataManager) are involved.

In more detail

  • I have reduced the files to the bare minimum that causes the problem, so only the Admin part is in each plugin.
  • I include the pared-done php files, the data-manager twig files, and two data files in the expected format for each plugin.
  • When var-dumper is not enabled, then the file in the data/content-edit directory is rendered as customised.
  • When var-dumper is enabled, the same file is rendered by data-manager as if it is a non-customised *.yaml file.

Unless I have missed something, it seems there maybe a bug in data-manager when multiple non-standard datatypes are defined.

data-man-test.zip

Update: If the priority on enabling the onPluginsInitialized is changed from 0 to 100, then this will affect which plugin over-rides which. I'm not sure which plugin comes first when both are on the same priority. But after editing var-dumper I had to increase its priority to 100, and then found that its items.html.twig was not being used.

Always one 'notificaton' item present

With data manager 1.0.6 and 1.0.7 i have this issue:
In the data folder there is a folder notifications and in that folder is a file called endogen.yaml. Endogen is my username in that Grav installation.

The content of that file is - '10'

I don't understand what the purpose of that file is and also i'm not sure what Notifications are in that context.

Request: Add a delete button to the item window

This is a feature request.

I am using the Data Manager in conjunction with contact and other submission forms. So, any time a form is submitted, the contents are saved to the user>data folder as well as being emailed. This is handy as a reference in case the form is not received or lost, and also as a permanent record of a response eg agreeing to terms and conditions.

It is all working well with Grav 1.7.26. However, I thought it would be nice to have a way to delete items that you don't want. The main use case would be removing spam messages that are sent thought the email contact form.

CSV files created in root of Grav installation

When using the CSV export functionality, the CSV files are generated in the root of the Grav installation prior to delivering to the browser.

This is not ideal since it creates clutter and gets in the way when you're using version control for your whole site data.

From looking at the code it seems as though they were intended to be placed in a temp folder, but that doesn't appear to be working.

Add data items

I know this plugin is focussed on viewing data but it would be a great enhancement if it could also allow creating additional data items.

[feature-request] [help-request] Export functionality

For my department, I deployed grav as a simple one-page event CMS that can host multiple events on different hosts. Setting everything up (modular pages, admin plugin and other plugins) was a breeze. However, now it was brought to my attention that the registration form submissions (stored and displayed using the data-manager plugin) should also be exported as e.g., CSV. In general, I would say that my skills for developing themes and plugins for grav are quite good, however, for the better part of the last two weeks I could not figure out a way to implement an export feature in the plugin.

I was wanting to create two export functionalities, one on a per-type level and one on a per-item level (speaking in data-manger jargon). Doing all the processing and creating the download isn't a problem (thanks to looking into other plugins' code), yet the problem arises from integrating the form into the existing template files - or making a standard HTML form in the template files work.

The main export functionality is added to the onFormProcessed event callback, to which I have the plugin register. Within the callback, I check for all the right things and create the correct files, but this function never gets triggered.

Are there any plans on integrating an export functionality into the plugin? Or would there be any good tutorials on this topic available around the grav pages?

Error with submitted multiline text

As I could see, there is a closed issue about multiline text #2 , but apparently this seems still to be a pending issue. Recently, I was trying to get a full list of all submitted data in a single CSV, but as my standalone solution is tailored to my form, it's not really usable here. But I can give a hint how I have solved it:

The multiline-textarea was the last field of my form. So, when I read the contents of the text data, I split the full content at the label value of the textarea

$textarea = explode("\r\ntextmessage:",$fulltext,2);

Then I manipulate all the linebreaks in $textarea[1] which now contains only the value of "textmessage". And then I just implode the array again by using the label value again:

$fulltext = implode("\r\ntextmessage:",$textarea);

Now I can handle the remaining linebreaks, as there is only one line per input/textarea.

This could be done globally, maybe referring to the original form values, but as I am not a developer, this seems too much for me to do in this place.

[feature request]

the manager needs to be able to ignore certain folders under the data folder
-or- the ability to read into SQLITE files
-or- autodetect of sqlite files and ignore

Plugin abandoned?

Hi,

Has this plugin been abandoned by Team Grav? There have been no updates for 3 years despite open pull requests that add functionality without breaking backwards compatability.

I understand that there is only so much time for development of these things, and am happy to get involved, but only if my pull requests won't be wasted!

Thanks,
Ari

Store multiline in Yaml data file from a textarea form field

I have an error when I store a multiline from a textarea form field, because in Yaml data file the textarea field has stored without > or | and indentation for each row.
I suggest to modify line 6 of forms/data.txt.twig from:

{{- field.name ?? index }}: {{ string((value is iterable ? value|json_encode : value)) ~ "\r\n" }}

To:

{{- field.name ?? index }}: {{ string((value is iterable ? value|json_encode : ("\n" in value ? (">\r\n  " ~ value|replace({"\n": "\n  "})) : value))) ~ "\r\n" }}

Perhaps it is better to create a specific twig file to perform this.

Info/Data Cut-Off

See attachment ...

The subject is supposed to say "Test 4".
The message is supposed to say "Testing 123 ..."

I have tested this many times, sometimes it does not cut-off the data, other times it does. Sometimes it will cut-off data in Subject but not the Message.

Very odd.

Screen Shot 2019-06-09 at 4 49 10 PM

Nothing appears on the page.

Hello.
I have sucessfully installed this plugin but when I go to the "Data Manager" page on the admin board, nothing happend. There is a blank page.
Please help me.
Thank you,
Reotip.

Error because of 'licenses.yaml'

I installed the Data Manger 1.0.6 plugin and with it the file licenses.yaml gets created in the data folder. If i then try to view the data in admin, i get this error
FilesystemIterator::__construct(/Users/dave/Sites/user/data/licenses.yaml): failed to open dir: Not a directory

After deleting licenses.yaml the plugin works again.

BTW: The file is empty

Grav Data Manager User Permissions

Trying to figure out how to reference permissions for users to this - it seems unless I have SUPER set then access is not allowed? I've had a look through the source but couldn't find anything. Might be good if this could be appended to the README? Thanks =)

Error occurs while trying to browse data with submitted multiline text

This is form.md:


---
title: A page with a form
form:
    name: contactform
    fields:
        - name: name
          label: Name
          placeholder: Enter your name
          autofocus: on
          autocomplete: on
          type: text
          validate:
            required: true

        - name: email
          label: Email
          placeholder: Enter your email address
          type: text
          validate:
            rule: email
            required: true

        - name: message
          label: Message
          placeholder: Enter your message
          type: textarea
          validate:
            required: true

    buttons:
        - type: submit
          value: Submit

    process:
        - save:
            fileprefix: contact-
            dateformat: Ymd-His-u
            extension: txt
            body: "{% include 'forms/data.txt.twig' %}"
        - message: Thank you from your feedback!

---

# Nice contact form

{% include 'forms/form.html.twig' %}

There is no additional configuration of Data Manager and Form plugins.

If multiline message was submitted, then error occurs while trying to browse Contactform data:
Error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.