Skip to content

Commit

Permalink
feat: Upgrade Number Field
Browse files Browse the repository at this point in the history
  • Loading branch information
staylorwr committed May 7, 2021
1 parent defbda6 commit 3a61e4d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 84 deletions.
4 changes: 2 additions & 2 deletions assets/src/components/FieldFilters/NumberFieldFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export default {
type: Object
}
},
methods: {
setOperand (e) {
this.$emit('change', { ...this.filter, operand: e.target.value, valid: true });
}
}
};
</script>
</script>
62 changes: 0 additions & 62 deletions assets/src/components/Form/NumberField.vue

This file was deleted.

9 changes: 1 addition & 8 deletions assets/src/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ Vue.component('index-password-field', IndexTextField);
Vue.component('detail-password-field', DetailTextField);
Vue.component('form-password-field', PasswordField);

// NumberField
import NumberField from '@/components/Form/NumberField.vue';

Vue.component('index-number-field', IndexTextField);
Vue.component('detail-number-field', DetailTextField);
Vue.component('form-number-field', NumberField);

// File

import IndexFile from '@/components/Index/File';
Expand Down Expand Up @@ -179,4 +172,4 @@ import IndexBooleanGroupField from '@/components/Index/BooleanGroup.vue';

Vue.component('form-boolean-group', FormBooleanGroupField);
Vue.component('detail-boolean-group', DetailBooleanGroupField);
Vue.component('index-boolean-group', IndexBooleanGroupField);
Vue.component('index-boolean-group', IndexBooleanGroupField);
21 changes: 20 additions & 1 deletion lib/ex_teal/fields/number.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@ defmodule ExTeal.Fields.Number do
@moduledoc false
use ExTeal.Field

def component, do: "number-field"
def component, do: "text-field"

def with_options(field, options) when is_map(options) do
%{field | options: options}
end

@impl ExTeal.Field
def value_for(field, model, _type) do
value = Map.get(model, field.field)

cond do
is_integer(value) ->
Integer.to_string(value)

is_float(value) ->
Float.to_string(value)

true ->
value
end
end

@impl ExTeal.Field
def filterable_as, do: ExTeal.FieldFilter.Number
end
2 changes: 1 addition & 1 deletion test/ex_teal/api/many_to_many_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ defmodule ExTeal.Api.ManyToManyTest do
[f1] = body.fields

assert f1.attribute == "order"
assert f1.value == 2
assert f1.value == "2"
end
end

Expand Down
16 changes: 6 additions & 10 deletions test/ex_teal/fields/number_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ defmodule ExTeal.Fields.NumberTest do

test "has a component" do
field = Number.make(:amount)
assert field.component == "number-field"
assert field.component == "text-field"
end

test "has a field filter" do
field = Number.make(:amount)
assert field.filterable == ExTeal.FieldFilter.Number
end

test "is shown on edit" do
Expand All @@ -42,15 +47,6 @@ defmodule ExTeal.Fields.NumberTest do
test "accepts a map and stores them as options" do
field = Number.make(:price)
assert field.options == %{}

options = %{
"min" => "0",
"max" => "100",
"step" => "1"
}

field = Number.with_options(field, options)
assert field.options == options
end
end
end

0 comments on commit 3a61e4d

Please sign in to comment.