Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AvocadoHQ/avo
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Aug 18, 2020
2 parents e5d4572 + 89d0a9a commit 0d98fb2
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/frontend/js/components/Edit/SelectField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
:class="inputClasses"
v-model="value"
>
<option value="null" disabled>{{field.placeholder}}</option>
<option v-if="!value" :value="value" v-text="field.placeholder" disabled selected hidden/>
<option v-for="(option, key) in field.options"
:value="key"
:key="key"
v-text="option"
v-text="(!field.display_value && option) ? option : key"
/>
</select>
</edit-field-wrapper>
Expand Down
6 changes: 3 additions & 3 deletions app/frontend/js/components/Index/GravatarField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export default {
],
computed: {
element() {
if (this.field.as_link_to_resource) return 'router-link'
if (this.field.link_to_resource) return 'router-link'
return 'div'
},
to() {
if (this.field.as_link_to_resource) {
if (this.field.link_to_resource) {
return {
name: 'show',
params: {
Expand All @@ -54,7 +54,7 @@ export default {
return null
},
title() {
if (this.field.as_link_to_resource) return `View ${this.resourceNameSingular}`
if (this.field.link_to_resource) return `View ${this.resourceNameSingular}`
return null
},
Expand Down
6 changes: 3 additions & 3 deletions app/frontend/js/components/Index/IdField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export default {
],
computed: {
element() {
if (this.field.as_link_to_resource) return 'router-link'
if (this.field.link_to_resource) return 'router-link'
return 'div'
},
to() {
if (this.field.as_link_to_resource) {
if (this.field.link_to_resource) {
return {
name: 'show',
params: {
Expand All @@ -47,7 +47,7 @@ export default {
return null
},
title() {
if (this.field.as_link_to_resource) return `View ${this.resourceNameSingular}`
if (this.field.link_to_resource) return `View ${this.resourceNameSingular}`
return null
},
Expand Down
4 changes: 2 additions & 2 deletions app/frontend/js/components/Index/SelectField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export default {
data: () => ({}),
props: ['field'],
computed: {
displayValue() {
label() {
return this.field.options[this.field.value]
},
value() {
if (this.field.display_with_value && this.displayValue) return this.displayValue
if (!this.field.display_value && this.label) return this.label
return this.field.value
},
Expand Down
6 changes: 3 additions & 3 deletions app/frontend/js/components/Index/TextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export default {
],
computed: {
element() {
if (this.field.as_link_to_resource) return 'router-link'
if (this.field.link_to_resource) return 'router-link'
return 'div'
},
to() {
if (this.field.as_link_to_resource) {
if (this.field.link_to_resource) {
return {
name: 'show',
params: {
Expand All @@ -47,7 +47,7 @@ export default {
return null
},
title() {
if (this.field.as_link_to_resource) return `View ${this.resourceNameSingular}`
if (this.field.link_to_resource) return `View ${this.resourceNameSingular}`
return null
},
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/js/components/Show/SelectField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
return this.field.options[this.field.value]
},
value() {
if (this.field.display_with_value && this.label) return this.label
if (!this.field.display_value && this.label) return this.label
return this.field.value
},
Expand Down
6 changes: 3 additions & 3 deletions lib/avo/app/fields/badge_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def initialize(name, **args, &block)

hide_on [:edit, :create]

default_map = { info: :info, success: :success, danger: :danger, warning: :warning }
@map = args[:map].present? ? default_map.merge(args[:map]) : default_map
default_options = { info: :info, success: :success, danger: :danger, warning: :warning }
@options = args[:options].present? ? default_options.merge(args[:options]) : default_options
end

def hydrate_field(fields, model, resource, view)
Expand All @@ -24,7 +24,7 @@ def hydrate_field(fields, model, resource, view)

value = {}

@map.invert.each do |values, type|
@options.invert.each do |values, type|
db_value = model[id] || ''

if [values].flatten.map { |value| value.to_s }.include? db_value
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/app/fields/gravatar_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(name, **args, &block)
@rounded = args[:rounded].present? ? args[:rounded] : true
@size = args[:size].present? ? args[:size].to_i : 40
@default = args[:default].present? ? ERB::Util.url_encode(args[:default]).to_s : ''
@as_link_to_resource = args[:as_link_to_resource].present? ? args[:as_link_to_resource] : false
@link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
end

def hydrate_field(fields, model, resource, view)
Expand All @@ -33,7 +33,7 @@ def hydrate_field(fields, model, resource, view)
rounded: @rounded,
default: @default,
size: @size,
as_link_to_resource: @as_link_to_resource,
link_to_resource: @link_to_resource,
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/app/fields/id_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def initialize(name, **args, &block)

super(name, **args, &block)

@as_link_to_resource = args[:as_link_to_resource].present? ? args[:as_link_to_resource] : false
@link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
end

def hydrate_field(fields, model, resource, view)
{
as_link_to_resource: @as_link_to_resource,
link_to_resource: @link_to_resource,
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/app/fields/select_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ def initialize(name, **args, &block)
super(name, **args, &block)

@options = args[:options].present? ? args[:options] : {}
@display_with_value = args[:display_with_value].present? ? args[:display_with_value] : false
@display_value = args[:display_value].present? ? args[:display_value] : false
@placeholder = args[:placeholder].present? ? args[:placeholder].to_s : 'Choose an option'
end

def hydrate_field(fields, model, resource, view)
{
options: @options,
display_with_value: @display_with_value,
display_value: @display_value,
placeholder: @placeholder,
}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/app/fields/text_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def initialize(name, **args, &block)

super(name, **args, &block)

@as_link_to_resource = args[:as_link_to_resource].present? ? args[:as_link_to_resource] : false
@link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
end

def hydrate_field(fields, model, resource, view)
{
as_link_to_resource: @as_link_to_resource,
link_to_resource: @link_to_resource,
}
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/dummy/app/avo/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def initialize
end

fields do
id as_link_to_resource: true
id link_to_resource: true
text :name, required: true
status :status, failed_when: [:closed, :rejected, :failed], loading_when: [:loading, :running, :waiting], nullable: true
badge :stage, map: { info: [:discovery, :ideea], success: :done, warning: 'on hold', danger: :cancelled }
select :stage, hide_on: [:show, :index], options: { discovery: 'Discovery', ideea: 'Ideea', done: 'Done', 'on hold': 'On hold', cancelled: 'Cancelled' }, placeholder: 'Choose the stage.'
select :stage, hide_on: [:show, :index], options: { discovery: 'Discovery', ideea: 'Ideea', done: 'Done', 'on hold': 'On hold', cancelled: 'Cancelled' }, placeholder: 'Choose the stage.', display_value: true
badge :stage, options: { info: [:discovery, :ideea], success: :done, warning: 'on hold', danger: :cancelled }
currency :budget, currency: 'EUR', locale: 'de-DE'
country :country
number :users_required
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/avo/resources/team_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize

fields do
id
select :level, options: { beginner: 'Beginner', intermediate: 'Intermediate', advanced: 'Advanced' }, default: -> (model, resource, view, field) { Time.now.hour < 12 ? 'advanced' : 'beginner' }
select :level, options: { beginner: 'Beginner', intermediate: 'Intermediate', advanced: 'Advanced' }, display_value: true, default: -> (model, resource, view, field) { Time.now.hour < 12 ? 'advanced' : 'beginner' }
belongs_to :user
belongs_to :team
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/avo/resources/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize

fields do
id
gravatar :email, as_link_to_resource: true
gravatar :email, link_to_resource: true
heading 'User information'
text :first_name, required: true, placeholder: 'John'
text :last_name, required: true, placeholder: 'Doe'
Expand Down
12 changes: 6 additions & 6 deletions spec/dummy/config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
threads min_threads_count, max_threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
port ENV.fetch('PORT') { 3030 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
environment ENV.fetch('RAILS_ENV') { 'development' }

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# workers ENV.fetch('WEB_CONCURRENCY') { 2 }

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
Expand Down
4 changes: 2 additions & 2 deletions spec/system/avo/default_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
wait_for_loaded

if Time.now.hour < 12
expect(find_field_element(:level)).to have_text 'Advanced'
expect(find_field_element(:level)).to have_text 'advanced'
else
expect(find_field_element(:level)).to have_text 'Beginner'
expect(find_field_element(:level)).to have_text 'beginner'
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe 'AsLinkToResources', type: :system do
RSpec.describe 'LinkToResource', type: :system do
describe 'for id field' do
let!(:project) { create :project }

Expand Down
4 changes: 2 additions & 2 deletions spec/system/avo/select_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
visit "/avo/resources/projects/#{project.id}/edit"

select 'Romania', from: :country
find("[field-id='stage'] [data-slot='value'] select").select 'Discovery'
find("[field-id='stage'] [data-slot='value'] select").select 'discovery'

click_on 'Save'
wait_for_loaded
Expand All @@ -40,7 +40,7 @@
visit "/avo/resources/projects/#{project.id}/edit"

select 'Romania', from: :country
find("[field-id='stage'] [data-slot='value'] select").select 'Cancelled'
find("[field-id='stage'] [data-slot='value'] select").select 'cancelled'

click_on 'Save'
wait_for_loaded
Expand Down

0 comments on commit 0d98fb2

Please sign in to comment.