Skip to content

Commit

Permalink
Merge pull request #11 from performant-software/feature/udf5_configur…
Browse files Browse the repository at this point in the history
…e_fields

UDF #5 - Configure fields
  • Loading branch information
dleadbetter authored Sep 26, 2022
2 parents b7d6335 + 1b45cb3 commit 8d86a9e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $ gem install user_defined_fields

## Usage

#### Migrations
### Migrations
To install the database table necessary to support user defined fields, use the following command:

```bash
Expand Down Expand Up @@ -49,5 +49,31 @@ class AddUserDefinedFieldsToMyModel < ActiveRecord::Migration[7.0]
end
```

### Components

User defined fields can be configured one of two ways: At the application level, or at the model level.

##### Application Level
If configured at the application level, each record in the specified table will contain the same user defined fields.

For example: You could define `first_name` and `last_name` fields for all of the `people` records. Anytime a user is editing a a person form, the `first_name` and `last_name` fields will be available as inputs.

```jsx
<UserDefinedFieldsList />
```

##### Model Level
If configured at the model level, records can contain different fields dependent on a parent record.

For example: You could define a `location` field for `resources` that belong to Project A, then define a `project_stage` field for `resources` that belong to Project B. On the edit for for Project A, only the `location` field will be available. On the edit form for Project B, only the `project_stage` field will be available.

```jsx
<UserDefinedFieldsEmbeddedList
items={props.item.user_defined_fields}
onDelete={props.onDeleteChildAssociation.bind(this, 'user_defined_fields')}
onSave={props.onSaveChildAssociation.bind(this, 'user_defined_fields')}
/>
```

## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
module UserDefinedFields
class UserDefinedFieldsController < ApplicationController
search_attributes :table_name, :column_name

protected

def apply_filters(query)
query = super

query = filter_defineable(query)

query
end

private

def filter_defineable(query)
return query unless params[:defineable_id].present? && params[:defineable_type].present?

query.where(defineable_id: params[:defineable_id], defineable_type: params[:defineable_type])
end
end
end

0 comments on commit 8d86a9e

Please sign in to comment.