{% extends "base.html" %}

{% block title %}Vendors & Products - {{ super() }}{% endblock %}

{% block content %}

<section class="content-header">
    <h1>Vendors & Products</h1>
    <ol class="breadcrumb">
        <li><a href="{{ url_for('main.home') }}">OpenCVE</a></li>
        <li class="active">Vendors & Products</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class='col-md-6 col-md-offset-3'>
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">
                        Search{% if request.args.get('vendor') %} in <strong>{{ request.args.get('vendor') | humanize }}</strong> vendor{% else %} in vendors and products{% endif %}
                    </h3>
                </div>
                <div class="box-body">
                    <form role="form" class="form-horizontal">
                        <div class="form-group">
                            <div class="col-md-12">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                    <button class="btn btn-primary" type="submit"><i class="fa fa-search"></i></button>
                                    </span>
                                    <form method="GET">
                                        {% if request.args.get('vendor') %}
                                        <input type="hidden" name="vendor" value="{{ request.args.get('vendor') }}" />
                                        {% endif %}
                                        <input type="text" placeholder="Search" class="form-control" name="search"
                                               value="{% if request.args.get('search') %}{{ request.args.get('search') }}{% endif %}">
                                    </form>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class='col-md-5'>
            {% if request.args.get('vendor') %}
            <div class="box box-info">
                <div class="box-header">
                    <div class="box-title"><i class="fa fa-filter"></i> Vendor <strong>{{ request.args.get('vendor') | humanize }}</strong> selected
                    </div>
                    <div class="box-tools pull-right">
                        <a type="button" class="btn btn-box-tool" data-toggle="remove"
                            href="{{ url_for('main.vendors') }}"><i class="fa fa-times"></i></a>
                    </div>
                </div>
            </div>
            {% else %}
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">Vendors ({{ vendors.total }})</h3>
                </div>
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover table-striped">
                        <tr>
                            <th>Vendor</th>
                            <th class="text-center">Products</th>
                            <th class="text-center">Actions</th>
                        </tr>
                        {% for vendor in vendors.items %}
                        <tr>
                            <td>{{ vendor.name | humanize }}</td>
                            <td class="text-center"><a href="{{ url_for('main.vendors', vendor=vendor.name) }}">{{
                                vendor.products|length }}</a></td>
                            <td class="text-center">
                                <div class="btn-group">
                                    {% if current_user.is_authenticated %}
                                    {% if vendor in current_user.vendors %}
                                    <button class="btn btn-danger btn-xs subscribe"
                                            id="unsubscribe_vendor_{{ vendor.id }}" type="button">Unsubscribe
                                    </button>
                                    {% else %}
                                    <button class="btn btn-default btn-xs subscribe"
                                            id="subscribe_vendor_{{ vendor.id }}" type="button"><i class="fa fa-bell-o"></i> Subscribe
                                    </button>
                                    {% endif %}
                                    {% else %}
                                    <a class="btn btn-default btn-xs"
                                       href="{{ url_for('user.login', next=request.url) }}" data-toggle="tooltip"
                                       data-container="body" title="You must be signed in to subscribe"><i class="fa fa-bell-o"></i> Subscribe</a>
                                    {% endif %}
                                    <a href="{{ url_for('main.cves', vendor=vendor.name) }}" class="btn btn-default btn-xs"><i class="fa fa-shield"></i> CVE</a>
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </table>
                    <div class="center">
                        {{ pagination_v.links }}
                    </div>
                </div>
            </div>
            {% endif %}
        </div>
        <div class='col-md-7'>
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">Products ({{ products.total }})</h3>
                </div>
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover table-striped">
                        <tr>
                            <th>Vendor</th>
                            <th>Product</th>
                            <th class="text-center">Actions</th>
                        </tr>
                        {% for product in products.items %}
                        <tr>
                            <td>{{ product.vendor.name | humanize }}</td>
                            <td>{{ product.name | humanize }}</td>
                            <td class="text-center">
                                <div class="btn-group">
                                    {% if current_user.is_authenticated %}
                                    {% if product in current_user.products %}
                                    <button class="btn btn-danger btn-xs subscribe"
                                            id="unsubscribe_product_{{ product.id }}" type="button">Unsubscribe
                                    </button>
                                    {% else %}
                                    <button class="btn btn-default btn-xs subscribe"
                                            id="subscribe_product_{{ product.id }}" type="button"><i class="fa fa-bell-o"></i> Subscribe
                                    </button>
                                    {% endif %}
                                    {% else %}
                                    <a class="btn btn-default btn-xs"
                                       href="{{ url_for('user.login', next=request.url) }}" data-toggle="tooltip"
                                       data-container="body" title="You must be signed in to subscribe"><i class="fa fa-bell-o"></i> Subscribe</a>
                                    {% endif %}
                                    <a href="{{ url_for('main.cves', vendor=product.vendor.name, product=product.name) }}" class="btn btn-default btn-xs"><i class="fa fa-shield"></i> CVE</a>
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </table>
                    <div class="center">
                        {{ pagination_p.links }}
                    </div>
                </div>
            </div>
        </div>

    </div>
</section>

{% endblock %}