{% extends "layout.html" %}
{% block content %}
<section class="section">
    <div class="section-header">
        <h1><a href="{{url_for('redisboard.db_detail', db=db)}}">Database {{db}}</a></h1>
        <div class="section-header-button">
            <a href="#" class="btn btn-primary" id="new-key-btn">Add New</a>
            <a href="#" class="btn btn-danger" data-confirm="Are you sure to flush DB{{db}}?"
                data-confirm-yes="flush_db('{{db}}')">Flush DB</a>
        </div>
        <div class="section-header-breadcrumb">
            <div class="breadcrumb-item">Keys: {{ db_detail._keys}} </div>
            <div class="breadcrumb-item">Expires: {{ db_detail.expires }}</div>
        </div>
    </div>

    <div class="section-body">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h4>
                            <div class="float-left">
                                <select class="form-control selectric">
                                    <option>Action For Selected</option>
                                    <option value="expire">Expire</option>
                                    <option value="delete">Delete</option>
                                </select>
                            </div>
                        </h4>

                        <div class="card-header-form">
                            <form>
                                <div class="input-group">
                                    <input type="text" class="form-control" placeholder="Search" name="keypattern"
                                        value="{{keypattern}}">
                                    <div class="input-group-btn">
                                        <button class="btn btn-primary" type="submit" data-toggle="tooltip"
                                            title="For speed, use scan for each 1000 data"><i
                                                class="fas fa-search"></i></button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <tr>
                                    <th>
                                        <div class="custom-checkbox custom-control">
                                            <input type="checkbox" data-checkboxes="mygroup" data-checkbox-role="dad"
                                                class="custom-control-input" id="checkbox-all">
                                            <label for="checkbox-all" class="custom-control-label">&nbsp;</label>
                                        </div>
                                    </th>
                                    <th>Keys({{ db_detail['key_details']|length }})</th>
                                    <th class="text-center">Type</th>
                                    <th class="text-center">Encoding</th>
                                    <th class="text-center">TTL</th>
                                    <th class="text-center">Size</th>
                                    <th>Action</th>
                                </tr>
                                {% for key_detail in db_detail['key_details'] %}
                                <tr>
                                    <td class="p-0 text-center">
                                        <div class="custom-checkbox custom-control">
                                            <input type="checkbox" data-checkboxes="mygroup"
                                                class="custom-control-input" id="checkbox-{{loop.index}}" name="id"
                                                data-keyname="{{key_detail.name}}">
                                            <label for="checkbox-{{loop.index}}"
                                                class="custom-control-label">&nbsp;</label>
                                        </div>
                                    </td>
                                    <td><a href="{{url_for('redisboard.key_detail',db=db, key=key_detail.name|quote_plus)}}"
                                            data-toggle="tooltip"
                                            data-original-title="{{ key_detail.name }}">{{ key_detail.name|truncate(20) }}</a>
                                    </td>
                                    {% if key_detail.error %}
                                    <td class="error" colspan="6">
                                        ERROR: {{ key_detail.error }}
                                    </td>
                                    {% else %}
                                    <td class="text-center">
                                        <div class="badge {{badge_class.get(key_detail.type)}}">{{ key_detail.type }}
                                        </div>
                                    </td>
                                    <td class="text-center">{{ key_detail.encoding }}</td>
                                    <td class="text-center">{{ key_detail.ttl }}</td>
                                    <td class="text-center">{{ key_detail.length }}</td>
                                    <td><a href="#" class="btn btn-danger"
                                            data-confirm="Really?|Do you want to delete {{ key_detail.name }}?"
                                            data-confirm-yes="delete_key('{{ key_detail.name|quote_plus }}', '{{db}}')"><i
                                                class="fas fa-trash"></i></a></td>
                                    {% endif %}
                                </tr>
                                {% endfor %}
                            </table>
                        </div>
                        {% if db_detail._keys > count %}
                        <div class="card-footer">
                            <ul class="pagination float-right">
                                <li class="page-item">
                                    <a class="page-link"
                                        href="{{url_for('redisboard.db_detail', db=db, cursor=db_detail.cursor, keypattern=keypattern)}}">
                                        {% if db_detail.cursor == 0 %}
                                        Index Page
                                        {% else %}
                                        Next Page
                                        {% endif %}
                                    </a>
                                </li>
                            </ul>
                        </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

    </div>
</section>
<div class="modal fade" tabindex="-1" role="dialog" id="batchTTL">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Set TTL For These Keys</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <p>Set <code>-1</code> for not expired forever</p>
                <div class="form-group">
                    <label>Expires</label>
                    <div class="input-group">
                        <div class="input-group-prepend">
                            <div class="input-group-text">
                                <i class="fas fa-clock"></i>
                            </div>
                        </div>
                        <input type="text" class="form-control" name="batchttl" placeholder="after * seconds">
                    </div>
                </div>
            </div>
            <div class="modal-footer bg-whitesmoke br">
                <button type="button" class="btn btn-primary" id="batch-ttl-btn">Save</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" tabindex="-1" role="dialog" id="batchDel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Are you sure to delete these keys</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer br">
                <button type="button" class="btn btn-danger" id="batch-del-btn">Yes</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" tabindex="-1" role="dialog" id="addKey">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Add A Key</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form method="POST" action="{{url_for('redisboard.add_key', db=db)}}">
                <div class="modal-body">
                    <div class="form-group">
                        <label>Keyname</label>
                        <div class="input-group">
                            <input type="text" class="form-control" name="keyname" placeholder="" required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="form-label">Type</label>
                        <div class="selectgroup w-100">
                            <label class="selectgroup-item">
                                <input type="radio" name="type" value="string" class="selectgroup-input" checked="">
                                <span class="selectgroup-button">String</span>
                            </label>
                            <label class="selectgroup-item">
                                <input type="radio" name="type" value="list" class="selectgroup-input">
                                <span class="selectgroup-button">List</span>
                            </label>
                            <label class="selectgroup-item">
                                <input type="radio" name="type" value="hash" class="selectgroup-input">
                                <span class="selectgroup-button">Hash</span>
                            </label>
                            <label class="selectgroup-item">
                                <input type="radio" name="type" value="set" class="selectgroup-input">
                                <span class="selectgroup-button">Set</span>
                            </label>
                            <label class="selectgroup-item">
                                <input type="radio" name="type" value="zset" class="selectgroup-input">
                                <span class="selectgroup-button">Zset</span>
                            </label>
                        </div>
                    </div>
                    <div class="form-group" id="index" style="display: none">
                        <label>Index</label>
                        <div class="input-group">
                            <input type="text" class="form-control" name="index" placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Value</label>
                        <div class="input-group">
                            <input type="text" class="form-control" name="value" required>
                        </div>
                        <small class="form-text text-muted" id="value-label" style="display: none">Separate multiple
                            values with ","</small>
                    </div>
                </div>
                <div class="modal-footer bg-whitesmoke br">
                    <button type="submit" class="btn btn-primary" id="add-key-btn">Save</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}


{% block js %}
<script src="{{ url_for('redisboard.static', filename='js/database.js') }}"></script>
{% endblock %}