-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from ellykits/issue-91-fiz-a-bug-with-rule-engine
Updated forms to recreate the rule engine bug
- Loading branch information
Showing
86 changed files
with
2,540 additions
and
1,020 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
neat-form-core/src/androidTest/resources/jacoco-agent.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output=none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 58 additions & 16 deletions
74
neat-form-core/src/main/java/com/nerdstone/neatformcore/domain/builders/FormBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,90 @@ | ||
package com.nerdstone.neatformcore.domain.builders | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import com.nerdstone.neatandroidstepper.core.widget.NeatStepperLayout | ||
import com.nerdstone.neatformcore.domain.model.JsonFormStepBuilderModel | ||
import com.nerdstone.neatformcore.domain.model.NFormViewData | ||
import com.nerdstone.neatformcore.domain.view.FormValidator | ||
import com.nerdstone.neatformcore.rules.RulesFactory | ||
import com.nerdstone.neatformcore.viewmodel.DataViewModel | ||
import com.nerdstone.neatformcore.viewmodel.FormViewModel | ||
import com.nerdstone.neatformcore.views.handlers.ViewDispatcher | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* [FormBuilder] contract is implemented by any builder using any preferred Schema. | ||
* | ||
* [formString] is the string representation of the form depending on the schema which can be JSON | ||
* YAML or even XML | ||
* | ||
* The form builder also uses the [formValidator] to validate fields. | ||
* | ||
* Before building views, views are first registered withing the [registeredViews] map. This is a map | ||
* that holds the view type against the actual class type of the view that will used to create the view for example | ||
* for an EditText inside the view type map you will have | ||
* ["edit_text" -> EditTextNFormView::class] | ||
* | ||
* This map can be overridden if you have custom views that you also want rendered. Just remember to register the views | ||
* before building the form. | ||
* | ||
*/ | ||
interface FormBuilder { | ||
|
||
var jsonString: String? | ||
var formString: String? | ||
|
||
val context: Context | ||
|
||
var neatStepperLayout: NeatStepperLayout | ||
var dataViewModel: DataViewModel | ||
|
||
var viewModel: DataViewModel | ||
|
||
var formValidator: FormValidator | ||
val formValidator: FormValidator | ||
|
||
var registeredViews: HashMap<String, KClass<*>> | ||
|
||
fun buildForm( | ||
jsonFormStepBuilderModel: JsonFormStepBuilderModel? = null, viewList: List<View>? = null | ||
): FormBuilder | ||
var formViewModel: FormViewModel | ||
|
||
fun createFormViews( | ||
context: Context, views: List<View>? = null, | ||
jsonFormStepBuilderModel: JsonFormStepBuilderModel? = null | ||
) | ||
val rulesFactory: RulesFactory | ||
val viewDispatcher: ViewDispatcher | ||
|
||
/** | ||
* This method reads the rules file available withing the given [context] and returns true when done | ||
* false otherwise. You also setup the [rulesFileType] in order for this to work. The form builder | ||
* uses Rules engine that allows you to write rules either in JSON or YML format. | ||
*/ | ||
fun registerFormRulesFromFile( | ||
context: Context, rulesFileType: RulesFactory.RulesFileType | ||
context: Context, rulesFileType: RulesFactory.RulesFileType | ||
): Boolean | ||
|
||
/** | ||
* This method returns a map of the form data. Where the key is the field name and the value is of | ||
* type [NFormViewData] | ||
*/ | ||
fun getFormData(): HashMap<String, NFormViewData> | ||
|
||
/** | ||
* This method returns Form metadata as specified on the form | ||
*/ | ||
fun getFormMetaData(): Map<String, Any> | ||
|
||
/** | ||
* This method returns a JSON string representation of the form data including the metadata specified on the | ||
* form. | ||
*/ | ||
fun getFormDataAsJson(): String | ||
|
||
/** | ||
* Use this method to add view types to the [registeredViews] property | ||
*/ | ||
fun registerViews() | ||
|
||
/** | ||
* Call this method before building the form to supply the fields with data obtained from [formDataJson]. You | ||
* can optionally pass [readOnlyFields] which will be disabled. | ||
*/ | ||
fun withFormData( | ||
formDataJson: String, readOnlyFields: MutableSet<String> = mutableSetOf() | ||
): FormBuilder | ||
|
||
/** | ||
* This method is called right after the views have been created. The data provided will be delegated to | ||
* the view model which will call the method for setting values on its observers (fields) | ||
*/ | ||
fun preFillForm() | ||
} |
4 changes: 3 additions & 1 deletion
4
...re/src/main/java/com/nerdstone/neatformcore/domain/listeners/CalculationChangeListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
...rm-core/src/main/java/com/nerdstone/neatformcore/domain/model/JsonFormStepBuilderModel.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
neat-form-core/src/main/java/com/nerdstone/neatformcore/domain/view/FormValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.