InfyOmLabs / laravel-generator

API and Admin Panel CRUD Generator for Laravel.
https://www.infyom.com/open-source
MIT License
3.79k stars 812 forks source link

[Enhancement] New Feature Request #160

Open phillipmadsen opened 8 years ago

phillipmadsen commented 8 years ago

Posible addition to fields file and output.

{
    "fieldInput": "title:string,20",    // field name with database type and options
    "htmlType": "text",                 // field html type
    "validations": "required",          // field validations
    "searchable": false,                // is field searchable
    "fillable": false,                  // if field should be fillable
    "primary": true,                    // does field is primary key
    "inForm": false,                    // if field should be included in create and edit form
    "inIndex": false,                    // if field should be included in index.blade.php
    "bsColumnSize": 8    // Bootstrap Column Size

}

Bootstrap Column Size for the form fields

options 1-12

will be added to classes :+1:

col-md-{bsColumnSize}

col-sm-{bsColumnSize}

col-lg-{bsColumnSize}

To be used in each form field in stubs:

<!-- $FIELD_NAME_TITLE$ Field -->
<div class="form-group {{ col-sm-12 col-lg-12 }}">
    {!! Form::label('$FIELD_NAME$', '$FIELD_NAME_TITLE$:') !!}
    {!! Form::textarea('$FIELD_NAME$', null, ['class' => 'form-control', 'rows' => '5']) !!}
</div>
phillipmadsen commented 8 years ago

I am working on this option on my forked version. I am having trouble remembering which file overwrites the stub files can you tell me where so I can add $BS_COLUMN_SIZE$ for the stub classes. I will keep looking but you can probably help me get there faster.

thanks

mitulgolakiya commented 8 years ago

@phillipmadsen as of now, our field templates are fixed. so we are using fixed column width. You can add a dynamic param in each field template. And then while compiling template you can replace it.

Here we are generating fields: https://github.com/InfyOmLabs/laravel-generator/blob/develop/src/Generators/Scaffold/ViewGenerator.php#L148

Here we are parsing fields json and preparing field dynamic variables: https://github.com/InfyOmLabs/laravel-generator/blob/develop/src/Utils/GeneratorFieldsInputUtil.php#L90

Here dynamic variables for fields are prepared: https://github.com/InfyOmLabs/laravel-generator/blob/develop/src/Common/CommandData.php#L42

Let me know if this helps.

phillipmadsen commented 8 years ago

I already made the change on my files but still have one part I cannot get. I have implemented this:

{
    "fieldInput": "title:string,20",    // field name with database type and options
    "htmlType": "text",                 // field html type
    "validations": "required",          // field validations
    "searchable": false,                // is field searchable
    "fillable": false,                  // if field should be fillable
    "primary": true,                    // does field is primary key
    "inForm": false,                    // if field should be included in create and edit form
    "inIndex": false,                    // if field should be included in index.blade.php
    "bsColumnSize": 8    // Bootstrap Column Size
}

and made the appropriete changes on my files to use this.

https://github.com/phillipmadsen/laravel-generator/blob/develop/src/Utils/GeneratorFieldsInputUtil.php

      if (isset($field['bsColumnSize'])) {
                $bscolumnsize = $field['bsColumnSize'];
            } else {
                $bscolumnsize = 6;
            }
            $fieldSettings = [
                'searchable'   => $searchable,
                'fillable'     => $fillable,
                'primary'      => $primary,
                'inForm'       => $inForm,
                'inIndex'      => $inIndex,
                'bsColumnSize' => $bscolumnsize
            ];

and

'inForm'         => isset($fieldSettings['inForm']) ? $fieldSettings['inForm'] : true,
'inIndex'        => isset($fieldSettings['inIndex']) ? $fieldSettings['inIndex'] : true,
'bsColumnSize'   => isset($fieldSettings['bsColumnSize']) ? $fieldSettings['bsColumnSize'] : 6,

But how do I get the assinged variable to overwrite this .stub with the appropriate data?

<!-- $FIELD_NAME_TITLE$ Field -->
<div class="form-group col-sm-$BSCOLUMNSIZE$ col-lg-$BSCOLUMNSIZE$">
    {!! Form::label('$FIELD_NAME$', '$FIELD_NAME_TITLE$:') !!}
    {!! Form::textarea('$FIELD_NAME$', null, ['class' => 'form-control', 'rows' => '5']) !!}
</div>

Meaning these parts. col-sm-$BSCOLUMNSIZE$ col-lg-$BSCOLUMNSIZE$

I assume something along the lines of adding it to this might work? but want to as you first.

 $this->fieldNamesMapping = [
            '$FIELD_NAME_TITLE$' => 'fieldTitle',
            '$FIELD_NAME$'       => 'fieldName',
            '$BSCOLUMNSIZE$'       => 'bsColumnSize',
        ];

or how can I get the genration to overwrite $BSCOLUMNSIZE$ with the value from the fields_file correctly?