jeudi 24 janvier 2019

Can I better design my app to remove the need to create new models and routes manually when adding new items?

I am building a web app for my company that is used for maintenance of plant. The app will contain a list of plant types and each type will have a form to collect the inspection / maintenance details. Each question on the form has a checkbox or a radio button set and a notes section. I want to be able to easily create new items of plant and the form to support them. A lot of the questions are common between forms so I started by building each question on the form as a form_element in a sub directory of views\partials.

Folder Structure

bund_pump_operations.blade.php

<div class="form-group">
    <div class="row">
        <div class="card-body form-check form-check-inline">
            <div class="col-6">
                <label class="form-check-label mr-4" name="bund_pump_operations">
                    Record number of bund pump operations..
                </label>
            </div>
            <div class="col-6">
                <input class="form-check-input" type="number" name="operations" value="">
            </div>
        </div>
    </div>
</div>
<div class="form-group p-2">
    <label for="bund_pump_operations_notes">Notes</label>
    <input class="form-control" type="text" name="bund_pump_operations_notes" value="">
</div>

I am quickly realising that this is not really sustainable going forward as each form requires a db model to store the results and a route in the web.php.

section of web.php

Route::post('/aux_tx', 'AuxTxReportController@store')->name('aux_tx.store');
Route::put('/aux_tx/{id}', 'AuxTxReportController@update')->name('aux_tx.update');

Route::get('/aux_tx_swg/{id}', 'AuxTxSwitchgearReportController@show')->name('aux_tx_swg.show');

Route::get('/dno_incomer/{id}', 'DnoIncomerReportController@show')->name('dno_incomer.show');

Route::get('/generator/{id}', 'GeneratorReportController@show')->name('generator.show');

Route::get('grid_transformer/{id}', 'GridTransformerReportController@show')->name('grid_transformer.show');

Route::get('/vt_swg_panel/{id}', 'VtSwitchgearPanelReportController@show')->name('vt_swg_panel.show');

I currently store the model name in the db plant table

I use this to call the correct controller for the required Model from the view

<div class="col-3">
    <a href="/" class="float-right mr- 
        1 btn btn-sm btn-info">
        View
    </a>
</div>

This sends to correct controller where the form_type is hard coded. (not good I know)

Controller

My current approach requires hard coding when adding new items of plant, as well as creating new Models, Controllers and Routes to support them. What started as an app to maintain 6 different items of plant has now grown to a point where 11 new types are waiting to be added.

I need to change my design so new questions can be added, new forms can be added, and these forms populated with the required questions through admin back end. I need to store the results in a db and the be able to review the results by site and plant item.

I don't expect or really want anyone to tell me step by step what I need to do but help me think about this problem and how I deliver the app so no hard coding is required when adding new items of plant.

I have looked at storing questions as html in the database, having a table for all items of plant and creating a many to many relationship between the two to allocate questions to forms. I am however struggling on how to store the results as each plant item type will have a different set of results to store.

Hope my question isn't too confusing.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire