A
A
artemlight2013-02-25 13:14:01
Programming
artemlight, 2013-02-25 13:14:01

CRUD bike - is it worth it?

Hi %username%.
At the moment, I just finished writing a tricky software that manages vpn connections in our organization. And since not only I will have to use this, they decided that a certain gui was needed for this business, namely, a web interface.
In general, the matter is not God knows how complicated - 50<N<100 hubs, from each of them SNMP statistics are dripped to the analytics center via two channels, after the statistics are analyzed, a semi-automatic transition to another routing configuration is carried out. Of the manual pieces, only the approval of the administrator on duty is required here, so that in the event of something terrible, everything can be quickly returned to its place.
Accordingly, for sensible management of this matter, two forms of information presentation are needed - summary statistics (remarkably shown by zabbix), and viewing a certain set of specific parameters with the possibility of editing them (including group ones).
In fact, this is implemented through a bundle of codeigniter + bootstrap, a sign with a list of hubs, forms with parameters, and an “make changes” button. And writing the code that manages all this drives me into frank anguish, because for this you need:

  • Make up the control form
  • Load it with ajax
  • Check if there were any errors while loading the form
  • Request data from the management interface
  • Wait for this data and check it for validity
  • Convert them to JSON and scatter them over the form
  • Wait until the user clicks the button
  • validate data on the client
  • validate data in web service
  • wait for management interface processing
  • display an error to the user, if any
  • Do not forget at the same time that there are different XSS
  • And it would be necessary to authenticate it somehow

And that's if I haven't forgotten anything yet.
The most annoying thing is that almost all of this code has to be written anew each time for each form. But there are also functions for disabling / deleting / blocking hubs (which is generally implemented at the Management Interface level in one line!), And you need to write a full-fledged gui to it, with windows “do you really want to?” etc.
As a result, out of desperation, I came up with the following bike.
The current state of objects of the same type is described by the same sets of fields. In other words, this is a quite typical table, as in any DBMS, except perhaps without indexes and other things. State changes are linked by code to certain events - we get a typical one-to-many relationship. Those. the final output of MI starts to resemble the result of a regular select with a couple of left joins to some tables.
And now, in fact, the bike itself.
For each field in the table, we bind the user-friendly name and type of the user-editor (types cannot be used - for example, for a field with a date it is a calendar, but a field with an int can be either just an int or a link to some ID, where you have to stir up which -some custom-select).
Further, some kind of ActiveRecord is a class that describes the construction of a select query. Accordingly, we immediately see which tables and in which roles we participate (master-subordinate), and based on this we can automatically create an HTML form.
Next up is validation. Validation rules can be set both for the class as a whole (at the moment the query class is created) and for individual fields involved in the query (at the moment the table class is described). In addition, validation by field type is required.
Actually, after that, the development of the next form will be reduced to three things:
1) description of tables and relationships between them
2) input of metadata (field names, validation rules, etc.)
3) launching a function that initiates the life cycle of the edit / create window, and has a single parameter - the name of the class that describes the specific request
. In fact, all this monstrously resembles the usual Microsoft Access and its form creation wizard. There is only one difference - it should work in the browser.
I sincerely want to believe that all of the above has already been implemented by someone. Are there any automation tools for managing html forms with similar functionality?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jen777, 2013-02-25
@jen777

A quick Google search turned up several options. The operation of autogenerating code based on a database is called DB Scaffolding. there are a couple of services and systems that create or simplify the creation of such forms:
www.phpscaffold.com/ - Creates PHP scripts based on a database dump.
ajaxcrud.com/ - The system simplifies the creation of CRUD forms by describing the form fields in the code.
www.grocerycrud.com/ is a very simple and convenient CRUD builder. In just a couple of lines, you have the crud for any table in the database.
Further search on similar services for different programming languages ​​and databases will lead you to the desired result.

A
artemlight, 2016-03-15
@artemlight

For the last six months I have been working with the .net Entity Framework - how much more convenient and concise my bike was.
Eh.

A
Alexander Sharihin, 2016-09-23
@Pinsky

The Yii2 framework for PHP has a crud generator. With him, such things are sawn in a day)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question