Skip to content

Multiple gallery filters #125

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

Closed
brian-rose opened this issue Jun 24, 2021 · 5 comments · Fixed by #178
Closed

Multiple gallery filters #125

brian-rose opened this issue Jun 24, 2021 · 5 comments · Fixed by #178
Assignees
Labels
hackathon Issue highlighted for active hackathon session infrastructure Infrastructure related issue

Comments

@brian-rose
Copy link
Member

Currently our Resource Gallery uses tags under three different categories (Domains, Formats, Packages) for filtering.

How feasible is it to enable multi-dimensional filtering? e.g. Formats=Video & Packages=Xarray

I think this capability will become more important as the gallery grows.

@brian-rose brian-rose added the infrastructure Infrastructure related issue label Jun 24, 2021
@kmpaul kmpaul added the hackathon Issue highlighted for active hackathon session label Aug 12, 2021
@kmpaul kmpaul added high priority and removed hackathon Issue highlighted for active hackathon session labels Oct 7, 2021
@kmpaul
Copy link
Collaborator

kmpaul commented Oct 7, 2021

Below is an example HTML page with javascript and CSS to allow a "list of elements" (which could be cards in the gallery) to expand/contract based on changing the display property of each element (from none to block and back). Obviously, this is just a start to a solution to this problem. For this to work:

  1. Each card in the gallery would have to be tagged with a CSS class that (somehow) corresponds to the tags associated with that card (e.g., class="pythia pangeo video tutorial").
  2. We need a way of having the visitor to the site select all of the "filters" they want to use. This might mean allowing the user to select multiple items in each dropdown. I know this is possible, but I don't know how to do it off the top of my head.
  3. Once a new filter is selected, it toggles it on/off, triggering the javascript function to change the CSS display property from none to block or vice versa.
  4. When a filter is turned OFF, it should visually indicate that in the menu (e.g., a line through the text or something). When a filter is turned ON, it should also visually indicate it (e.g., it doesn't have a line through it).
  5. Can we animate this transition? Typically, you cannot animate via straight HTML/CSS transitions in the display property. Which means that this approach would lead to sudden/immediate changes in the gallery list. It would be really nice if we could slickly animate this with, for example, fading out the removed elements and then smoothly moving the cards together to fill in the gaps (or the reverse, smoothly moving the cards apart and then fading cards back into place). I don't know how to do that.
<!DOCTYPE html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Filter Test</title>
  <script>
    function filter(classes) {
      for (var i = 0; i < classes.length; i++) {
        var elements = document.getElementsByClassName(classes[i]);
        for (var j = 0; j < elements.length; j++) {
          e = elements[j];
          if (e.style.display === "none") {
            e.style.display = "block";
          } else {
            e.style.display = "none";
          }
        }
      }
    }
  </script>
  <style>
    div {
      padding: 1rem;
    }
    .red {
      display: block;
      background-color: red;
    }
    .blue {
      display: block;
      background-color: blue;
    }
  </style>
</head>
<html>
  <body>

    <button onclick="filter(['red'])">Hide/Show Red</button>
    <button onclick="filter(['blue'])">Hide/Show Blue</button>

    <div class="red" id="div1">
      This is div element #1.
    </div>

    <div class="blue" id="div2">
      This is div element #2.
    </div>

    <div class="blue" id="div3">
      This is div element #3.
    </div>

    <div class="red" id="div4">
      This is div element #4.
    </div>

    <div class="blue" id="div5">
      This is div element #5.
    </div>

  </body>
</html>

@clyne
Copy link
Contributor

clyne commented Oct 7, 2021

@kmpaul you indicated that this is just a start, but the todo items you listed don't seem terribly insurmountable (and some may even be optional for an interim solution). Is the takeaway that the desired capability is more readily doable than what was thought during our earlier discussion, or am I misinterpreting your findings?

@kmpaul
Copy link
Collaborator

kmpaul commented Oct 7, 2021

I do think this is doable with static webpages using this methodology. I believe this kind of approach could be done without much difficulty, with a little care.

@clyne
Copy link
Contributor

clyne commented Oct 7, 2021

That sounds like great news! Thanks for clarifying.

@brian-rose brian-rose added the hackathon Issue highlighted for active hackathon session label Oct 28, 2021
@brian-rose
Copy link
Member Author

@jukent will be working on this during today's hackathon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hackathon Issue highlighted for active hackathon session infrastructure Infrastructure related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants