Skip to content

Commit

Permalink
feat(#122): support of additional field of type "nomenclature"
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Mar 2, 2024
1 parent 7487ac4 commit f70d19f
Show file tree
Hide file tree
Showing 22 changed files with 1,137 additions and 814 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.geonature.occtax.features.nomenclature.data

import fr.geonature.occtax.features.nomenclature.domain.EditableNomenclatureType
import fr.geonature.occtax.features.nomenclature.domain.EditableField
import fr.geonature.occtax.settings.PropertySettings

/**
Expand All @@ -11,14 +11,14 @@ import fr.geonature.occtax.settings.PropertySettings
interface INomenclatureSettingsLocalDataSource {

/**
* Gets all [EditableNomenclatureType] matching given nomenclature main type.
* If the default main type is requested, returns all default [EditableNomenclatureType]
* Gets all [EditableField] matching given nomenclature main type.
* If the default main type is requested, returns all default [EditableField]
* whatever the given [PropertySettings].
*
* @return a list of [EditableNomenclatureType]
* @return a list of [EditableField]
*/
suspend fun getNomenclatureTypeSettings(
type: EditableNomenclatureType.Type,
type: EditableField.Type,
vararg defaultPropertySettings: PropertySettings
): List<EditableNomenclatureType>
): List<EditableField>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.geonature.occtax.features.nomenclature.data

import fr.geonature.occtax.features.nomenclature.domain.EditableNomenclatureType
import fr.geonature.occtax.features.nomenclature.domain.EditableField
import fr.geonature.occtax.features.record.domain.AllMediaRecord
import fr.geonature.occtax.features.record.domain.CountingRecord
import fr.geonature.occtax.features.record.domain.PropertyValue
Expand All @@ -15,128 +15,141 @@ class NomenclatureSettingsLocalDataSourceImpl :
INomenclatureSettingsLocalDataSource {

private val defaultNomenclatureTypes = listOf(
EditableNomenclatureType(
EditableNomenclatureType.Type.DEFAULT,
"TYP_GRP",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE
EditableField(
type = EditableField.Type.DEFAULT,
code = "TYP_GRP",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "TYP_GRP"
),
EditableNomenclatureType(
EditableNomenclatureType.Type.INFORMATION,
"METH_OBS",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE
EditableField(
type = EditableField.Type.INFORMATION,
code = "METH_OBS",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "METH_OBS"
),
EditableNomenclatureType(
EditableNomenclatureType.Type.INFORMATION,
"ETA_BIO",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE
EditableField(
type = EditableField.Type.INFORMATION,
code = "ETA_BIO",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "ETA_BIO"
),
EditableNomenclatureType(
EditableNomenclatureType.Type.INFORMATION,
"METH_DETERMIN",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE,
EditableField(
type = EditableField.Type.INFORMATION,
code = "METH_DETERMIN",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "METH_DETERMIN",
default = false
),
EditableNomenclatureType(
EditableNomenclatureType.Type.INFORMATION,
"determiner",
EditableNomenclatureType.ViewType.TEXT_SIMPLE,
EditableField(
type = EditableField.Type.INFORMATION,
code = "determiner",
viewType = EditableField.ViewType.TEXT_SIMPLE,
default = false
),
EditableNomenclatureType(
EditableNomenclatureType.Type.INFORMATION,
"STATUT_BIO",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE,
EditableField(
type = EditableField.Type.INFORMATION,
code = "STATUT_BIO",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "STATUT_BIO",
default = false
),
EditableNomenclatureType(
EditableNomenclatureType.Type.INFORMATION,
"OCC_COMPORTEMENT",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE,
EditableField(
type = EditableField.Type.INFORMATION,
code = "OCC_COMPORTEMENT",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "OCC_COMPORTEMENT",
default = false
),
EditableNomenclatureType(
EditableNomenclatureType.Type.INFORMATION,
"NATURALITE",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE,
EditableField(
type = EditableField.Type.INFORMATION,
code = "NATURALITE",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "NATURALITE",
default = false
),
EditableNomenclatureType(
EditableNomenclatureType.Type.INFORMATION,
"PREUVE_EXIST",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE,
EditableField(
type = EditableField.Type.INFORMATION,
code = "PREUVE_EXIST",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "PREUVE_EXIST",
default = false
),
EditableNomenclatureType(
EditableNomenclatureType.Type.INFORMATION,
"comment",
EditableNomenclatureType.ViewType.TEXT_MULTIPLE,
EditableField(
type = EditableField.Type.INFORMATION,
code = "comment",
viewType = EditableField.ViewType.TEXT_MULTIPLE,
default = false
),
EditableNomenclatureType(
EditableNomenclatureType.Type.COUNTING,
"STADE_VIE",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE
EditableField(
type = EditableField.Type.COUNTING,
code = "STADE_VIE",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "STADE_VIE"
),
EditableNomenclatureType(
EditableNomenclatureType.Type.COUNTING,
"SEXE",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE
EditableField(
type = EditableField.Type.COUNTING,
code = "SEXE",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "SEXE"
),
EditableNomenclatureType(
EditableNomenclatureType.Type.COUNTING,
"OBJ_DENBR",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE
EditableField(
type = EditableField.Type.COUNTING,
code = "OBJ_DENBR",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "OBJ_DENBR"
),
EditableNomenclatureType(
EditableNomenclatureType.Type.COUNTING,
"TYP_DENBR",
EditableNomenclatureType.ViewType.NOMENCLATURE_TYPE
EditableField(
type = EditableField.Type.COUNTING,
code = "TYP_DENBR",
viewType = EditableField.ViewType.NOMENCLATURE_TYPE,
nomenclatureType = "TYP_DENBR"
),
EditableNomenclatureType(
EditableNomenclatureType.Type.COUNTING,
CountingRecord.MIN_KEY,
EditableNomenclatureType.ViewType.MIN_MAX
EditableField(
type = EditableField.Type.COUNTING,
code = CountingRecord.MIN_KEY,
viewType = EditableField.ViewType.MIN_MAX
).apply {
value = PropertyValue.Number(
code,
1
)
},
EditableNomenclatureType(
EditableNomenclatureType.Type.COUNTING,
CountingRecord.MAX_KEY,
EditableNomenclatureType.ViewType.MIN_MAX
EditableField(
type = EditableField.Type.COUNTING,
code = CountingRecord.MAX_KEY,
viewType = EditableField.ViewType.MIN_MAX
).apply {
value = PropertyValue.Number(
code,
1
)
},
EditableNomenclatureType(
EditableNomenclatureType.Type.COUNTING,
AllMediaRecord.MEDIAS_KEY,
EditableNomenclatureType.ViewType.MEDIA
EditableField(
type = EditableField.Type.COUNTING,
code = AllMediaRecord.MEDIAS_KEY,
viewType = EditableField.ViewType.MEDIA
).apply {
value = PropertyValue.Media(code)
}
)

override suspend fun getNomenclatureTypeSettings(
type: EditableNomenclatureType.Type,
type: EditableField.Type,
vararg defaultPropertySettings: PropertySettings
): List<EditableNomenclatureType> {
if (defaultPropertySettings.isEmpty() || type == EditableNomenclatureType.Type.DEFAULT) {
): List<EditableField> {
if (defaultPropertySettings.isEmpty() || type == EditableField.Type.DEFAULT) {
return defaultNomenclatureTypes.filter { it.type == type }
}

return defaultPropertySettings
.mapNotNull { property ->
defaultNomenclatureTypes.find { it.code == property.key }
?.let {
EditableNomenclatureType(
EditableField(
type = it.type,
code = it.code,
viewType = it.viewType,
nomenclatureType = it.nomenclatureType,
visible = property.visible,
default = property.default,
value = it.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,31 @@ import fr.geonature.occtax.features.record.domain.PropertyValue
import kotlinx.parcelize.Parcelize

/**
* Describes an editable nomenclature type with value.
* Describes an editable field type with value.
*
* @author S. Grimault
*/
@Parcelize
data class EditableNomenclatureType(
data class EditableField(
val type: Type,
val code: String,
val viewType: ViewType,

/**
* Whether this editable field is linked with a nomenclature type.
*/
val nomenclatureType: String? = null,

val visible: Boolean = true,
val default: Boolean = true,

/**
* Whether this editable field is considered as an additional field or not.
*/
val additionalField: Boolean = false,

/**
* Nomenclature type's label.
* Editable field's label.
*/
val label: String? = null,

Expand All @@ -29,7 +39,7 @@ data class EditableNomenclatureType(
val values: List<PropertyValue> = emptyList(),

/**
* The current value for this nomenclature type.
* The current value for this editable field.
*/
var value: PropertyValue? = null,

Expand All @@ -40,27 +50,27 @@ data class EditableNomenclatureType(
) : Parcelable {

/**
* Describes main editable nomenclature type.
* Describes the main category of an editable field.
*/
enum class Type {
/**
* Default nomenclature types.
* Default category.
*/
DEFAULT,

/**
* Nomenclature types used for main information.
* Used for main information.
*/
INFORMATION,

/**
* Nomenclature types used for describing counting.
* Used for describing counting.
*/
COUNTING
}

/**
* Describes an editable nomenclature type view type.
* Describes an editable field's view type.
*/
enum class ViewType {
/**
Expand All @@ -74,7 +84,7 @@ data class EditableNomenclatureType(
CHECKBOX,

/**
* As dropdown menu items.
* As dropdown nomenclature items.
*/
NOMENCLATURE_TYPE,

Expand Down
Loading

0 comments on commit f70d19f

Please sign in to comment.