Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields ordering doesn't work in the list view #859

Closed
heaven opened this issue Nov 26, 2011 · 6 comments
Closed

Fields ordering doesn't work in the list view #859

heaven opened this issue Nov 26, 2011 · 6 comments
Milestone

Comments

@heaven
Copy link

heaven commented Nov 26, 2011

Regarding to this statement: "If you specifically declare fields, only defined fields will be visible and they will be presented in the order defined". Currently fields are ordered in some strange way and also all fields are included, not only those I've specified.
Last problem could be resolved by using exclude_fields but still can't find a way how to set up fields order.

list do
  field :id do
  end
  field :jid do
  end
  field :progress do
  end
  exclude_fields :target, :response
end

Ordering was: Jid, Progress, Id
I have also tried this way:

list do
  field :id
  include_all_fields
  exclude_fields :target, :response
end

But got next order: Progress, Jid, Id

@bbenezech
Copy link
Collaborator

Do you order them outside of a section scope?
If you do, use configure instead of field.

I need to document this a bit more.

@heaven
Copy link
Author

heaven commented Nov 26, 2011

Hi, sorry, I am not understanding what a section do you mean. This is how I using it:

config.model DelayedJob do
  weight -1

  list do
    sort_by :progress
    field :id
    field :jid
    field :progress
    exclude_fields :target, :response
  end
end

@heaven heaven closed this as completed Nov 26, 2011
@heaven heaven reopened this Nov 26, 2011
@heaven
Copy link
Author

heaven commented Nov 26, 2011

Sorry, closed mechanically.

@bbenezech
Copy link
Collaborator

Can you post your whole config? You must be using some field statements outside of a section (list/edit/..) scope or even outside a model scope. Otherwise it would be really weird.

@heaven
Copy link
Author

heaven commented Nov 29, 2011

Hi, sure:

RailsAdmin.config do |config|

  config.current_user_method { current_user } # auto-generated

  config.main_app_name { ['CRM', 'Admin'] } # auto-generated

  config.authorize_with :cancan

  config.compact_show_view = false

  config.excluded_models << []

  config.label_methods << :to_label # Default is [:name, :title]

  config.models do
    list do
      exclude_fields :id
    end
  end

  [Phone, ProfileInfluence, ProfileInterest, PostCondition, StateProvince, ProfilePhoto].each do |klass|
    config.model klass do
      visible false
    end
  end

  config.model Profile do
    weight 0
    list do
      field :first_name
      field :last_name
      field :ha_status do
        label 'Status'
        searchable [:value]
      end
      field :primary_email_address_string do
        label 'Primary Email Address'
      end
      field :deceased do
        visible false
      end
      field :participation_frequency do
        visible false
      end
      field :nickname do
        visible false
      end
      field :gender do
        visible false
      end
      field :timezone do
        visible false
      end
      field :birthday do
        visible false
      end
      field :first_seen_date do
        visible false
      end
      field :last_updated do
        visible false
      end
      field :do_not_contact do
        visible false
      end
    end

    show do
      group :default do
        field :name do
          label ''
          formatted_value do
            bindings[:view].render :partial => 'profile_show_name'
          end
        end
        field :ha_status do
          label 'Status'
        end
        field :gender
        field :timezone
        field :participation_frequency do
          label "Participation"
        end
      end
      group :tags_g do
        label 'Tags'
        field :tags do
        end
      end
      group :health_sites_g do
        label 'Health Sites'
        field :health_sites do
        end
      end
      group :influences_and_interests do
        label ''
        field :interests do
          label ''
          pretty_value do
            bindings[:view].render :partial => 'profile_show_influences_and_interests'
          end
        end
      end
      group :phone do
        field :phones do
          label ''
          pretty_value do
            bindings[:view].render :partial => 'profile_show_phones'
          end
        end
      end
      group :email do
        field :email_addresses do
          label ''
          pretty_value do
            bindings[:view].render :partial => 'profile_show_email'
          end
        end
      end
      group :social do
        field :social_profiles do
          label ''
          pretty_value do
            bindings[:view].render :partial => 'profile_show_social_profiles'
          end
        end
      end
      # ridiculous, need everything as groups for ordering
      group :projects_g do
        label 'Projects'
        field :projects do
          label ''
          pretty_value do
            bindings[:view].render :partial => 'profile_show_projects'
          end
        end
      end
      group :notes_g do
        label 'Notes'
        field :notes do
          label ''
          pretty_value do
            bindings[:view].render :partial => 'profile_show_notes'
          end
        end
      end
      group :photos_g do
        label 'Photos'
        field :photos do
          label ''
          pretty_value do
            bindings[:view].render :partial => 'profile_show_photos'
          end
        end
      end
    end

    edit do
      field :first_name
      field :last_name
      field :ha_status do
        label "Status"
      end
      field :gender
      field :timezone
      field :participation_frequency
      field :primary_email_address do
        visible do
          bindings[:object].valid?
        end
        partial "profile_primary_email_address"
      end
      #field :email_addresses
      field :do_not_contact
      field :deceased
      field :photos
      field :interests do
        associated_collection_cache_all true
        label "Interested Conditions"
      end
      field :influences do
        associated_collection_cache_all true
        label "Influencer Conditions"
      end
      field :health_sites do
        associated_collection_cache_all true
        label "Health Sites"
      end
      field :tags do
        associated_collection_cache_all true
        label "Tags"
      end
      field :projects
      field :notes
      #field :social_profiles
    end

    create do
      field :phones do
        visible do # workaround
          unless bindings[:object].phones.any?
            bindings[:object].phones.build
          end
        end
        partial "profile_phone"
      end
      field :email_addresses do
        visible do # workaround
          unless bindings[:object].email_addresses.any?
            bindings[:object].email_addresses.build
          end
          true
        end
        partial "profile_email_address"
      end
      field :photos
      field :interests do
        associated_collection_cache_all true
        label "Interested Conditions"
      end
      field :influences do
        associated_collection_cache_all true
        label "Influencer Conditions"
      end
      field :projects
      field :social_profiles do
        visible do # workaround
          unless bindings[:object].social_profiles.any?
            bindings[:object].social_profiles.build(:social_service_type => 'Blog')
            bindings[:object].social_profiles.build(:social_service_type => 'Facebook')
            bindings[:object].social_profiles.build(:social_service_type => 'Twitter')
            bindings[:object].social_profiles.build
          end
          true
        end
        partial "profile_social_profiles"
      end

      field :notes do
        visible do # workaround
          unless bindings[:object].notes.any?
            bindings[:object].notes.build
          end
          true
        end
        partial "profile_notes"
      end

      # field :projects do
      #   visible do # workaround
      #     unless bindings[:object].projects.any?
      #       bindings[:object].projects.build
      #     end
      #   end
      #   create_partial "profile_projects"
      # end
    end
  end

  config.model DelayedJob do
    weight -1

    list do
      sort_by :progress
      field :id
      field :jid
      field :progress
      exclude_fields :target, :response
    end
  end

  config.model ProfilePhoto do
    parent Profile

    #list do
    #end

    #show do
    #end

    #edit do
    #end
  end

  config.model ProfileSearch do
    label 'Searches'
    parent Profile

    list do
      field :name do
        formatted_value do
          href = bindings[:view].main_app.search_profiles_path(:search => bindings[:object].data)
          bindings[:view].link_to(value, href, :target => "_blank" )
        end
      end
      field :user do
        searchable [:name, :email]
      end
      exclude_fields :data, :created_at, :updated_at
    end

    #show do
    #end

    #edit do
    #end
  end

  config.model SocialProfile do
    label "Social Profiles"
    parent Profile
    list do
      field :profile
      include_all_fields # all other default fields will be added after, conveniently
      exclude_fields :created_at, :updated_at, :id # but you still can remove fields
    end

    show do
      field :profile_url do
        pretty_value do
          bindings[:view].render :partial => "social_profile_show_profile_url"
        end
      end
      field :social_service_type do
        label "Service type"
      end
      field :profile
    end

    edit do
      field :profile_url
      field :social_service_type
      field :profile
    end
  end

  config.model Address do
    parent Profile

    list do
      include_all_fields
      field :state_province do
        label "State"
      end
      exclude_fields :created_at, :postal_code, :updated_at, :id, :label, :latitude, :longitude, :accuracy, :normalized
    end

    edit do
      field :address1
      field :address2

      field :city
      field :state_province
      field :postal_code
      field :country
      field :label
    end

    show do
      field :profile
      field :label
      field :address1
      field :address2
      field :city
      field :postal_code
      field :country
    end

    create do
      field :profile
      field :address1
      field :address2

      field :city
      field :state_province
      field :postal_code
      field :country
      field :label
    end

  end

  config.model EmailAddress do
    label "Email Addresses"
    parent Profile

    create do
      field :primary
      field :address
      field :opt_in_status
      field :opt_in_details
      field :label
      field :profile
    end

    edit do
      field :primary
      field :address
      field :opt_in_status
      field :opt_in_details
      field :label
    end

  end

  config.model ProfileInterest do
    label "Interest"
  end

  config.model ProfileInfluence do
    label "Influence"
  end

  config.model HealthSite do
    weight 3
  end

  config.model HealthSiteMember do
    weight 4
  end

  config.model Note do
    parent Profile
    list do
      field :profile do
        searchable [:first_name, :last_name, :nickname]
      end
      :project
      include_all_fields # all other default fields will be added after, conveniently
      exclude_fields :captured_at, :updated_at, :id # but you still can remove fields
    end

    show do
      group :default do
        field :title
        field :body
        field :profile
        field :project
        field :created_by
        field :updated_by
        field :captured_at
        field :created_at
      end
    end
  end

  config.model User do
    object_label_method :to_label
  end

  config.model Condition do
    weight 2
    sort_by :name

    list do
      field :name
      field :contact_list_id
      field :interested_count do
        label "interested"
      end
      field :interested_opted_in_count do
        label "interested opt ins"
      end
      field :influencers_count do
        label "influencers"
      end
      field :influencers_opted_in_count do
        label "influencers opt ins"
      end
    end

    show do
      group :default do
        field :name
        field :contact_list_id
        field :interested
        field :influencers
      end
    end
  end

  config.model Project do
    weight 1
    label "Projects"

    list do
      field :profiles do
        searchable []
      end
      field :created_by do
        searchable [:name, :email, :role]
      end
      field :updated_by do
        searchable [:name, :email, :role]
      end
      include_all_fields
      exclude_fields :created_at, :updated_at, :id
    end
  end

  config.model Tag do
    weight 5
    label "Tags"

    list do
      field :profiles do
        searchable [:first_name, :last_name]
      end
      include_all_fields
      exclude_fields :created_at, :updated_at, :id
    end

    edit do
      field :name
      field :profiles
    end
  end
end

@bbenezech
Copy link
Collaborator

Wao, nice initializer :D

Yep, just what I thought, the culprit should be:

  config.models do
    list do
      exclude_fields :id
    end
  end

Exclude_field is not excluding :id here... because there is nothing added yet. Instead it's adding ALL other fields except :id!

This should be fixed before release because this really is counter-intuitive!

Meanwhile, you can put this block at the very end, or just hide them with visible false

Both will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants