Commit a31943b3 authored by Stefano Alberto Russo's avatar Stefano Alberto Russo
Browse files

Added search bar and filtering for computing resources.

parent 96a477a2
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -12,8 +12,36 @@
      {% else %}
      <h1>Computing resources</h1>
      {% endif %}

      <hr/>

      {% if not data.computing %}
      <div class="form-filter" style="margin-bottom:20px">
        <form action="" method="POST">
          <input type="text" class="form-control" id="search_text" name="search_text" placeholder="Search..." style="width:200px; margin:0; display:inline" value="{{data.search_text}}" autofocus>
          <select class="form-control" id="search_owner" name="search_owner" style="width:120px; margin:0; display:inline">
            {% if data.search_owner == 'All' %}
            <option selected>All</option>
            {% else %}
            <option>All</option>
            {% endif %}
            {% if data.search_owner == 'Platform' %}
            <option selected>Platform</option>
            {% else %}
            <option>Platform</option>
            {% endif %}
            {% if data.search_owner == 'User' %}
            <option selected>User</option>
            {% else %}
            <option>User</option>
            {% endif %}
          </select>
          {% csrf_token %}
          <button type="submit" class="btn btn-secondary">Go</button>
          &nbsp; &nbsp; <font size=4.0em>|</font> &nbsp; <a href="#" class="disabled" style="pointer-events: none; color: #aaa;">Add new...</a>
        </form>
      </div>
      {% endif %}

      <div class="row" style="padding:5px">
      {% if data.computing %}
      {% include "components/computing.html" with computing=data.computing details=True %}
+27 −4
Original line number Diff line number Diff line
@@ -1204,6 +1204,12 @@ def computing(request):
    data['details'] = details
    data['action'] = action

    # Search/filter logic
    search_text = request.POST.get('search_text', '')
    search_owner = request.POST.get('search_owner', 'All')
    data['search_text'] = search_text
    data['search_owner'] = search_owner

    # Handle delete action
    if action == 'delete' and uuid:
        if not request.user.is_staff:
@@ -1260,10 +1266,27 @@ def computing(request):
            except Computing.DoesNotExist:
                data['computing'] = Computing.objects.get(uuid=computing_uuid, group=None)
    else:
        if request.user.is_staff:
            data['computings'] = Computing.objects.all()
        # Filtering logic for list view
        computings = Computing.objects.all()
        from django.db.models import Q
        if search_text:
            computings = computings.filter(
                Q(name__icontains=search_text) |
                Q(description__icontains=search_text) |
                Q(type__icontains=search_text) |
                Q(arch__icontains=search_text)
            )
        if search_owner != 'All':
            # User computign resurces not yet implemented
            if search_owner == 'Platform':
                pass
            else:
            data['computings'] = list(Computing.objects.filter(group=None)) + list(Computing.objects.filter(group__user=request.user))
                computings = []
            #if search_owner == 'Platform':
            #    computings = computings.filter(user=None)
            #elif search_owner == 'User':
            #    computings = computings.filter(user=None)
        data['computings'] = list(computings)

    return render(request, 'computing.html', {'data': data})