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

Referenced fields on custom dashboard collections do not work properly #703

Closed
jamespsterling opened this issue Sep 22, 2015 · 6 comments
Closed
Assignees
Labels

Comments

@jamespsterling
Copy link

I have a custom dashboard collection using reference fields. When I use the reference fields in the standard model, they work as expected. When I use them in the custom dashboard collection, they do not work at all, except when I define their type as reference_many. In this case, they work sporadically. (ex see: submissionMonth and carrierId fields)

Standard data model:

    // submissions
    submissions.listView()
    .title('Submissions')
    .fields([
        nga.field('id').label('Id'),
        nga.field('status').label('Status'),
        nga.field('dateSubmitted', 'datetime')
            .format('yyyy-MM-dd')
            .isDetailLink(true),
        nga.field('dateAccepted', 'datetime')
            .format('MM dd, yyyy'),
        nga.field('submissionMonth', 'reference')
            .label('Submission Month')
            .targetEntity(months)
            .targetField(nga.field('month')),
        nga.field('submissionYear'),
        nga.field('carrierId', 'reference')
            .label('Carrier')
            .targetEntity(carrier)
            .targetField(nga.field('name'))
    ]);

Custom collections model:

    admin.dashboard(nga.dashboard()
        .addCollection(nga.collection(submissions)
            .name('accepted_submissions')
            .title('Accepted Submissions')
            .fields([
                nga.field('status', 'choice')
                    .choices(statusChoices)
                    .cssClasses(function(entry) {
                        if (!entry) return;
                        if (entry.values.status == 'accepted') {
                            return 'text-center bg-success';
                        }
                        if (entry.values.status == 'rejected') {
                            return 'text-center bg-danger';
                        }
                        return 'text-center bg-warning';
                    }),     
                nga.field('dateSubmitted', 'datetime').format('medium').label('Submitted').isDetailLink(true),
                nga.field('dateAccepted', 'datetime').label('Accepted').format('MMM d'),
                nga.field('submissionMonth', 'reference')
                    .label('Month')
                    .targetEntity(months)
                    .targetField(nga.field('month')),
                nga.field('submissionYear').label('Year'),
                nga.field('carrierId', 'reference')
                    .label('Carrier')
                    .isDetailLink(false)
                    .targetEntity(carrier)
                    .targetField(nga.field('name')),
            ])
            .listActions([
                '<ma-edit-button entry="::entry" entity="::entity" size="xs" label=""></ma-edit-button>',
                '<approve-submission size="xs" review="entry"></approve-submission>'
            ])
            .sortField('submissionYear')
            .sortField('submissionMonth')
            .sortDir('DESC')
            .order(2)
            .perPage(10)
            .permanentFilters({status: 'accepted'})
        )
        .template(customDashboardTemplate)
    );
@fzaninotto
Copy link
Member

Let me reduce the description to your problem. You say that the following configuration works in the listView:

// submissions
submissions.listView()
.fields([
    nga.field('carrierId', 'reference')
        .label('Carrier')
        .targetEntity(carrier)
        .targetField(nga.field('name'))
]);

While the following doesn't work in the dashboard:

admin.dashboard(nga.dashboard()
    .addCollection(nga.collection(submissions)
        .fields([
            nga.field('carrierId', 'reference')
                .label('Carrier')
                .isDetailLink(false)
                .targetEntity(carrier)
                .targetField(nga.field('name')),
        ])
    )
);

Right? Are you using the HEAD of the master branch, or a tagged version?

@jamespsterling
Copy link
Author

Correct. Using HEAD on master.

@fzaninotto fzaninotto added the bug label Sep 30, 2015
@jamespsterling
Copy link
Author

If it helps any, this is the error I get when trying to use reference columns on custom dashboard layout,

TypeError: Cannot read property 'getFirstEntry' of undefined
    at link.pre (http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:14:26710)
    at http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:23:3694
    at ae (http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:23:3751)
    at w (http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:22:29682)
    at s (http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:22:25689)
    at http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:22:25185
    at link (http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:14:22773)
    at http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:23:3694
    at ae (http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:23:3751)
    at w (http://fitise.corp.york-claims.com/scripts/vendor/ng-admin.min.js:22:29868) <ma-reference-column field="::field" value="::value" datastore="::datastore">

@josephwmorse
Copy link

I am having the same problem as well. When I use a reference field in a list or show view, it works fine. But if I use it in a collection, it rarely works (never in a custom dashboard, and only sometimes in the out-of-the-box dashboard). The error I get is e.datastore does not exist (using the minified version of 0.9.1)

@josephwmorse
Copy link

My issue was fixed by adding a datastore="dashboardController.datastore" attribute on my ma-dashboard-panel tags in my custom template HTML. That attribute is missing from one of the columns in the default dashboard; also the dashboard configuration documentation does not mention that it needs to be included.

@jamespsterling
Copy link
Author

Confirmed, solved my issue as well. Thanks @josephwmorse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants