jow- / luci-ng

LuCI on Angular
84 stars 26 forks source link

RFC: Uci components #40

Closed ianchi closed 7 years ago

ianchi commented 7 years ago

This is an alternative approach to the current cbi implementation. To avoid name collisions and to keep current functionality, everything is in the "uci" prefix namespace, but eventually this should be changed.

In the current approach cbi is implemented as directives that heavily interact with each other in various ways including accessing each other's scope. The directives are responsible not only for UI interaction but also have responsibility in the workflow of persisting data to the uci files. This makes it more difficult to build flexibility in pages definitions (some problems discussed in issue #36 ).

The idea in this alternative, is to implement the functionality but split in more isolated objects: 1.- Angular Components that manage UI interaction (switching from Directives to Components to enhance encapsulation and eventual migration to Angular2) 2.- Data model that is linked to the view to hold updated data 3.- Service that syncs model data changes to UCI files

In this way components only handle UI and use native Angular data binding to a model holding the data, no specific UCI interaction is handled here. The data model is used to pivot with the view via the components and with the underlying UCI file via a service that handles all that interaction on any changed/added/deleted data.

Components could be defined in two ways:

Additionally, a wrapper around cbi validation is added in order to use the standard Angular form validation functionality, and remove all need of specific code in each component.

Up to now this is a RFC and a proof of concept, and not all functionality is implemented yet. (for instance, only reading UCI files, no saving yet)

A very simple test page is included in the menu under Tabbed - Tests - UCI

jow- commented 7 years ago

Apart from the minor nitpick above I think we should merge this and continue on top of that.

ianchi commented 7 years ago

Ok, I'll complete the work on a basic "saving" functionality, use it to create some simple config page and then merge this. (So as not to pollute the main repo with many fixes afterwards). Meanwhile I'll keep this branch updated with the progress

ianchi commented 7 years ago

Completed basic saving and reset functionality.

The workflow used when pressing the "save" button is: 1) Save (to uci session's staging delta dir) 2) Apply changes (with rollback true) 3) Try to confirm changes (if this cannot go thru, the rollback mechanism will revert changes) 4) Reset form to saved changes (to resync with any externally changed data)

It's still pending to implement all the error handling.

ianchi commented 7 years ago

Will continue work in Angular 4 package started in #42