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

Add columns selector JS component and change Rails view to use it #3439

Merged
merged 1 commit into from
Jun 11, 2019
Merged

Add columns selector JS component and change Rails view to use it #3439

merged 1 commit into from
Jun 11, 2019

Conversation

abelardogilm
Copy link
Contributor

References

#3429

Objectives

Create a new visual component to select which columns will be display on admin budget investments table. Selection will be stored for each user as cookie

Visual Changes

ezgif com-video-to-gif

Notes

How it works:

This new feature is based on a JS solution, given display logic to JQuery. To make it run, we just need a couple of data attributes in our table, and render a new shared partial to set checks wrapper

Once Jquery is loaded, It will search a DOM item with id: '#js-columns-selector' to initialize all columns selector JS logic.

  • First, columns_selector will extract from table information to build all checkboxes that we want to work as selectors. To do it, it will search all DOM elements which responds to $(".column-selecteable th[data-field]") and will add a new checkbox using header text as label, and data-field value as identifier
  • Second, will load or create if not exists a cookie passed as data-cookie property into our columns-selector trigger
  • Then it will add or remove class hidden to table columns using data-field property, and will check checkboxes if is included on cookie

Once is loaded, each checkboxes change will trigger an event which toggle column hidden class and update cookie with new value

Adding component to new table

  • Render Columns selector trigers and wrapper in our view
<%= render partial: "admin/shared/columns_selector",
        locals: { cookie: _COOKIE_VALUE_ , default: _DEFAULT_COLUMNS_ } %>
  • Add column-selecteable class to table
  • Add data-field=_FIELD_ attribute to each th we want to add to our chooser, field will identify table attribute
  • Add data-field=_FIELD_ attribute to each td we want to associate with our chooser

app/views/admin/shared/_columns_selector.html.erb Outdated Show resolved Hide resolved
app/views/admin/budget_investments/_investments.html.erb Outdated Show resolved Hide resolved
app/assets/stylesheets/admin.scss Outdated Show resolved Hide resolved
@@ -1249,6 +1249,44 @@ table {
}
}

.columns-selector {

span[class^="icon-"] {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid qualifying attribute selectors with an element.

app/assets/javascripts/cookies.js.coffee Outdated Show resolved Hide resolved
@abelardogilm abelardogilm changed the title Add columns selector JS component and change Rails view to use it WIP Add columns selector JS component and change Rails view to use it Apr 16, 2019
@abelardogilm abelardogilm changed the title WIP Add columns selector JS component and change Rails view to use it Add columns selector JS component and change Rails view to use it Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Roadmap
  
Release 1.1.0
Development

Successfully merging this pull request may close these issues.

None yet

3 participants