Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Introducing the embedded_list field type #714

Merged
merged 12 commits into from Oct 20, 2015
Merged

Conversation

fzaninotto
Copy link
Member

The new embedded_list type maps an array of objects inside an entry, e.g.

{  
   "id":1,
   "title":"Accusantium qui nihil voluptatum quia voluptas maxime ab similique",
   "comments":[  
      {  
         "author":{  
            "name":"Edmond Schulist"
         },
         "body":"I ought to tell me your history, you know,' the Hatter and the happy summer days. THE.",
         "created_at":"2012-08-07"
      },
      {  
         "author":{  
            "name":"Logan Schowalter"
         },
         "body":"I don't want to be?' it asked. 'Oh, I'm not Ada,' she said, 'and see whether it's marked \"poison\" or not'; for she had asked it aloud; and in despair she put her hand on the end of the.",
         "created_at":"2012-08-05"
      }
   ]
}

You can now map the comments field:

posts.showView().fields([
    nga.field('id'),
    nga.field('title'),
    nga.field('comments', 'embedded_list')
        .targetEntity(nga.entity('comments'))
        .targetFields([
            nga.field('id').isDetailLink(true),
            nga.field('author.name').label('Author'),
            nga.field('created_at').label('Posted'),
            nga.field('body').label('Comment')
        ])
        .listActions(['edit'])
]);

This will display in the show view as a datagrid, exactly like referenced_list.

image

And in an editionView like nested forms:

image

Of course, embedded entries don't require an entity. If they only live inside another entry, simply don't set the targetEntity. In that case, there can be no detailLink or default listActions, as there is no Entity to link to.

posts.showView().fields([
    nga.field('id'),
    nga.field('title'),
    nga.field('comments', 'embedded_list')
        .targetFields([
            nga.field('author.name').label('Author'),
            nga.field('created_at').label('Posted'),
            nga.field('body').label('Comment')
        ])
]);

embedded_list fields support sorting and filtering:

posts.showView().fields([
    nga.field('id'),
    nga.field('title'),
    nga.field('comments', 'embedded_list')
        .targetEntity(nga.entity('comments'))
        .targetFields([
            nga.field('id').isDetailLink(true),
            nga.field('author.name').label('Author'),
            nga.field('created_at').label('Posted'),
            nga.field('body').label('Comment')
        ])
        .sortField('id')
        .sortDir('DESC')
        .permanentFilters({
             published: true
        })
        .listActions(['edit'])
]);

This is a long-requested feature, and it should fix numerous issues (#241, #308, #627, #666)

  • implement read widget using dataGrid
  • implement write widget using embedded forms
  • add tests
  • add doc

@jpetitcolas jpetitcolas mentioned this pull request Oct 8, 2015
@fzaninotto
Copy link
Member Author

Switching to RFR

@fzaninotto fzaninotto changed the title [WIP] Introducing the embedded_list field type [RFR] Introducing the embedded_list field type Oct 16, 2015
@Gargam
Copy link

Gargam commented Oct 19, 2015

Hello :)
I'm playing with this QR and I have issues with a boolean field (not the field text that is created and updated successfully)
I've tried

        nga.field('field', 'embedded_list')
            .targetFields([
                nga.field('text'),
                nga.field('isRight','boolean')
            ])

Even with a .choice field the value sent to server is "null" in creationView and in Edition.

@fzaninotto
Copy link
Member Author

I can reproduce the bug with boolean field but not with choice field. For the boolean field bug, maybe it's related to #736, let's see if fixing that one helps.

@fzaninotto
Copy link
Member Author

@Gargam confirmend, the bug isn't linked to embedded_list - it's already in master for all boolean fields. It'll be fixed by #744

@Gargam
Copy link

Gargam commented Oct 20, 2015

@fzaninotto Thanks for the update :).
Keep the gook work

fzaninotto added a commit that referenced this pull request Oct 20, 2015
[RFR] Introducing the embedded_list field type
@fzaninotto fzaninotto merged commit 0d95179 into master Oct 20, 2015
@fzaninotto fzaninotto deleted the embedded_list branch October 20, 2015 19:31
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.

None yet

2 participants