krafthaus / bauhaus

Laravel 4 Admin Generator
http://bauhaus.krafthaus.nl/
GNU General Public License v2.0
1 stars 0 forks source link

Edit a view #7

Open willmkt opened 10 years ago

willmkt commented 10 years ago

Hi, how can i modify the views files, i want to make some modifications to each view generated, or make a custom view?

jspekken commented 10 years ago

You can find the views in vendor/krafthaus/bauhaus/src/views/.

But it's generally a bad idea to edit files in the vendor folder because they could get overwritten with a composer update.

Maybe I'll look into a view exporting functionality. I let you know as soon as I know more.

willmkt commented 10 years ago

A export feature would be awesome, it would be cool if bauhaus generated code in the laravel project base, like jeffrey way generator scaffold did before.

Bauhaus has awesome features like the menu builder and the list,form,filters but it would be nice to have more control over the code generated.

Looking forward for the new features and improvements

Thanks for the awesome work on the project.

jspekken commented 10 years ago

For now I'll stick with a per model view override functionality.

When you want to create custom views, just override the following properties to reference your new custom view:

protected $masterViewString;
protected $listViewString;
protected $editViewString;
protected $createViewString;
protected $filterViewString;

Later this evening I'll create a command that exports the views to your app folder so that you can reference them from those properties.

jspekken commented 10 years ago

You can now export the views with $ php artisan bauhaus:export:views

willmkt commented 10 years ago

Thanks man this is very cool, but after the update i am getting an error:

Undefined variable: model (View: /Users/will/Desktop/transfer/vendor/krafthaus/bauhaus/src/views/dashboard/index.blade.php)

jspekken commented 10 years ago

I'm sorry for that, i've fixed the error

willmkt commented 10 years ago

One more thing when i said to export the views, was to export all the views separated individually like way generator used to on the scaffold each with your code.

Your export is already a cool feature.

Thanks man! keep up the good work.

jspekken commented 10 years ago

so, something like this? $ php artisan bauhaus:export:view list

or: $ php artisan bauhaus:export:view form

willmkt commented 10 years ago

Lets say that i created product table and generated the scaffold, the i would do $ php artisan bauhaus:export:view products

It would create only the the views that was specified.

jspekken commented 10 years ago

What if I build this command: $ php artisan bauhaus:export:view --type=[list|form|filters] --path=products that exports the view type that you wish to export in the path that you chose.

The only thing you have to do is to override the view string properties in your bauhaus model:

protected $listViewString = 'products.list';
protected $editViewString = 'products.form';
protected $createViewString = 'products.form';
protected $filterViewString = 'products.filters';

Your new views will then be easily customisable in your app folder and are only rendered on the product model.

willmkt commented 10 years ago

That will work, and it will give more control of the individual views.

Thanks man, this is very cool.

jspekken commented 10 years ago

Currently there is a problem with partial views and exporting the main views. Both the edit and share view share the same form view and the index view has a filter partial to keep things tidy.

Right now, when you run $ php artisan bauhaus:export:views all the views will be exported and you can use and/or copy the views you want to override.

I cannot think of a clean and good way to export the views separate because of the partials. Do you have any idea on how you like to do that?

willmkt commented 10 years ago

I have a suggestion:

Leave the export views as it is, and create $ php artisan bauhaus:scaffolfExport:product

That will generate the views, the model, the controller just as way generator scaffold used to generate on version 1.0.

So if i wanted to make changes just for that view it would be separated from the others.

What do you think

jspekken commented 10 years ago

Do you mean for the front-end or the backend? Exporting the single bauhaus controller with the views or generating models, views and controllers that get the data from bauhaus (its just your database)? Because I don't really things it's bauhaus' business to handle things on the front-end (separate packages are coming for that soon)

willmkt commented 10 years ago

For the backend

jspekken commented 10 years ago

Then it's only the views that have to be exported. There is not much you can change at the controller level and there are no models used, only the "big ass" admin class that controls all the logic.

The controller only passes the right admin instance to the views. The views then fetch the approriate data to render the column or forms.

Maybe I can make the admin class more flexibel where you can easily render the right data and/or views wherever you want. That allows for custom routes and custom views.

Is that something you want?:p

I'm sorry for the long discussion on this topic. But I really value your input. Thank you for that. Keep up the great work!

willmkt commented 10 years ago

You are right, there is no need to export all, only the views and routes.

This discussion will go on until we get this feature right, thanks for attention.

jspekken commented 10 years ago

Ok, at last:)

It's now possible to talk to your bauhaus models directly via:

Bauhaus::getInstance('post');

This returns a simple bauhaus admin instance that you can use to create new views or other things. Below is a simple example:

// building/rendering a list from your model data with pagination
$model = Bauhaus::getInstance('post')->buildList();

foreach ($model->getListBuilder()->getResult() as $item) {
    foreach ($item->getFields() as $field) {
        echo $field->render();
    }
}

$model->getListBuilder()->getPaginator()->links();

To use this function, add this to your aliases:

'Bauhaus' => 'KraftHaus\Bauhaus\Facade\Bauhaus'

I will write a generate views command that creates simple/clean views that you can use to build these views more quickly.

willmkt commented 10 years ago

Hey that is great, i exported the view but when i edit it does not work.

I added the aliasses and did this command php artisan bauhaus:views:generate --view=list --model=product

One more thing, it is possible when you do the generate command to export all fields individually? and do separate form views, create, edit and update.

Thanks.

jspekken commented 10 years ago

The views that you've exported need to be called somewhere in your application. Right now, those views are a 'skeleton' for using Bauhaus on the frontend.

You have to do something like this:

// define the route
Route::get('orders', function () {
    $orders = Bauhaus::getInstance('orders')
        ->buildList();

    return View::make('orders.index')
        ->with('orders', $orders);
});

// the view:
<table>
    <thead>
        @foreach ($orders->getListMapper()->getFields() as $field)
            <tr>
                <th>#</th>
                <th>{{ $field->getLabel() }}</th>
            </tr>
        @endforeach
    </thead>
    <tbody>
        @foreach ($orders->getListBuilder()->getResult() as $item)
            <tr>
                <td>{{ $item->getIdentifier() }}</td>

                @foreach ($item->getFields() as $field)
                    <td>{{ $field->render() }}</td>
                @endforeach
            </tr>
        @endforeach
    </tbody>
</table>

That's almost the same as rendering the form. So you're flexible to use it as a list, a form (edit and/or create) or whatever you want. The way as I see it, this is the most flexible way where you can do whatever you want and load whatever you want by calling Bauhaus directly.

jspekken commented 10 years ago

To come back to your question. I'd say, if you want to render separate fields, manage that in your bauhaus model, just set the specific fields you want rendered there.

And about saving your data, I create an easy save/update functionality soon.

willmkt commented 10 years ago

Still not working, i defined the route and created the views.

It is still the same as before, nothing changed.

jspekken commented 10 years ago

Thats weird. Do you get any errors while running the route?

willmkt commented 10 years ago

No, i don't get anything.

that0n3guy commented 10 years ago

Ok, I'm a little confused with this. @willmkt is asking about backend views, but it looks like your answer is for frontend views.

I did some testing, here is what I did:

This works, except my view is not "themed".... I think this is the wrong way to go.... starting over:

This lets me modify everything about the view, except the form, as that is located in a partial. To mess with the form, I have to copy the partial and modify it. This works the way I want it I think.

So my question, why doesn't the command php artisan bauhaus:views:generate --view=form --model=product export the backend view instead of the front end view (edit: this should still be in here, I like that you can do frontend views... but it should be a different command or switch). Then make another command that exports the partials if thats needed.... or a switch --partials=yes or something.

My next question: how can I edit the save/update functionality (what you normally have in a controller)?

jspekken commented 10 years ago

Haha, I'm confused to. So the issue is that you cannot edit the partials directly? In the create view on line 39 you can found the include for the partial:

@include('krafthaus/bauhaus::models.partials._form')

if you edit that to:

@include('bauhaus.models.partials._form')

You should have your custom view with the custom partial (because they get exported too). Is that what you mean? Because I think I'm getting lost here :P

that0n3guy commented 10 years ago

Ha. The issue isn't so much an issue as it is an issue... does that make sense (ha, jk).

I can edit the partials just fine. I was just saying that maybe php artisan bauhaus:views:generate should be modified to export what bauhaus:views:export does... but just not export everything.

For example, maybe: php artisan bauhaus:views:generate --view=forms --model=product --partials=form. You can see I did 2 changes here:

The way it currently works is fine, but is just kind of confusing to most people. What do you think?

willmkt commented 10 years ago

Any update on editing a backend view?