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

Allow default model be generated with user having to visit every UI component #21

Open
cjh1 opened this issue Oct 27, 2016 · 4 comments
Labels

Comments

@cjh1
Copy link

cjh1 commented Oct 27, 2016

Currently you have to visit every component in order to successfully generate a model, it should be possible for a user to just take all the defaults or some of them ...

@cjh1
Copy link
Author

cjh1 commented Oct 27, 2016

@TristanWright Here you go

@nandangokhale
Copy link

Hello,

I started experimenting with SimPut in this repository only a couple of days ago as it is part of HPCCloud, which we are examining in order to develop an application. I seem to have come across this issue as well. I created a simple 'contact-card' type as follows.

The 'contact-card.hbs' template file is simply the following:

First Name: {{{firstName}}}
Last Name: {{{lastName}}}

The front-end consists of two simple views where the user can specify his/her First Name and Last Name, as show in the 'model.js' file:

module.exports = {
    defaultActiveView: 'firstNameView',
    order: [
        'firstNameView',
        'lastNameView',
    ],
    views: {
        firstNameView: {
            label: 'First Name',
            attributes: ['firstNameAttr'],
        },
        lastNameView: {
            label: 'Last Name',
            attributes: ['lastNameAttr']
        },
    },
    definitions: {
        firstNameAttr: {
            label: 'First Name',
            parameters: [
                {
                    id: 'firstNameAttrId',
                    type: 'string',
                    size: 1,
                    default: 'Joe',
                    label: 'First Name',
                },
            ],
        },
        lastNameAttr: {
            label: 'Last Name',
            parameters: [
                {
                    id: 'lastNameAttrId',
                    type: 'string',
                    size: 1,
                    default: 'Bloggs',
                    label: 'Last Name',
                },
            ],
        },
    },
};

The 'convert.js' file is just:

const contactCardTemplate = require('./templates/contact-card.hbs');

module.exports = function convert(viewModel) {

    console.log(viewModel);

    const contactParams = {};
    contactParams['firstName'] = viewModel.data.firstNameView[0].firstNameAttr.firstNameAttrId.value[0];
    contactParams['lastName'] = viewModel.data.lastNameView[0].lastNameAttr.lastNameAttrId.value[0];

    const results = {
        'contact.txt' : contactCardTemplate(contactParams),
    };

  return { results, model: viewModel };
};

If the user does not explicitly visit the Last Name view in the front-end, the entry for the Last Name (with the default value of 'Bloggs') does not get created in the viewModel object , causing the convert.js function to fail.

Are there plans to create entries for default values in the viewModel? Or is the developer expected to do some sanity checking in the convert.js function?

Thanks.

@jourdain
Copy link
Collaborator

So far the idea was that the convert.js should contains some sanity check as it can provide a list of error on what could be missing. Also, the convert function can have access to the datamodel as well so the defaults value could be retrieved if needed.

@nandangokhale
Copy link

Ok, fair enough. And thanks for the tip on importing the dataModel into the convert function in order to get access to the defaults.

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

4 participants