{% extends "module.html.twig" %}

{% block moduleContent %}
<div>
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab-geral" data-toggle="tab">{% trans %}Sistema{% endtrans %}</a></li>
        <li><a href="#tab-triagem" data-toggle="tab">{% trans %}Triagem{% endtrans %}</a></li>
        <li><a href="#tab-api" data-toggle="tab">API</a></li>
        <li><a href="#tab-sobre" data-toggle="tab">{% trans %}Sobre{% endtrans %}</a></li>
    </ul>
    <div class="tab-content">
        <div id="tab-geral" class="tab-pane active">
            <fieldset>
                <legend>{% trans %}Banco de Dados{% endtrans %}</legend>
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>{% trans %}Chave{% endtrans %}</th>
                            <th>{% trans %}Valor{% endtrans %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for k,v in dbValues %}
                        <tr>
                            <td>{{ k }}</td>
                            <td>
                                {% if k == "password" %}
                                    ***
                                {% else %}
                                    {{ v }}
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </fieldset>
            <fieldset>
                <legend>{% trans %}Autenticação{% endtrans %}</legend>
                <div id="auth_message" style="display:none">
                    <div class="alert alert-success">
                        {% trans %}Configuração salva com sucesso{% endtrans %}
                    </div>
                </div>
                <div class="form-group auth-type">
                    <label for="auth_type">{% trans %}Tipo{% endtrans %}</label>
                    <select id="auth_type" class="form-control">
                        <option value="db" {% if auth.type == 'db' %}selected="selected"{% endif %}>{% trans %}Banco de Dados{% endtrans %}</option>
                        <option value="ldap" {% if auth.type == 'ldap' %}selected="selected"{% endif %}>{% trans %}LDAP e Banco de Dados{% endtrans %}</option>
                    </select>
                </div>
                <div id="auth-ldap" class="auth-config" {% if auth.type != 'ldap' %}style="display:none"{% endif %}>
                    <div class="form-group required">
                        <label for="auth_ldap_host" class="form-label">{% trans %}Servidor{% endtrans %}</label>
                        <input id="auth_ldap_host" name="host" type="text" class="form-control" value="{{ auth.ldap.host }}" />
                    </div>
                    <div class="form-group required">
                        <label for="auth_ldap_port">{% trans %}Porta{% endtrans %}</label>
                        <input id="auth_ldap_port" class="form-control" name="port" type="text" maxlength="6" value="{{ auth.ldap.port }}" />
                        <span class="help-block">ex: 389</span>
                    </div>
                    <div class="form-group required">
                        <label for="auth_ldap_host">{% trans %}Base DN{% endtrans %}</label>
                        <input id="auth_ldap_baseDn" name="baseDn" class="form-control" type="text" value="{{ auth.ldap.baseDn }}" />
                        <span class="help-block">ex: DC=novosga,DC=org</span>
                    </div>
                    <div class="form-group required">
                        <label for="auth_ldap_loginAttribute" class="form-label">{% trans %}Login Attribute{% endtrans %}</label>
                        <input id="auth_ldap_loginAttribute" name="loginAttribute" class="form-control" type="text" value="{{ auth.ldap.loginAttribute }}" />
                        <span class="help-block">ex: sAMAccountName</span>
                    </div>
                    <div class="form-group">
                        <label for="auth_ldap_user" class="form-label">{% trans %}Usuário{% endtrans %}</label>
                        <input id="auth_ldap_user" name="username" class="form-control" type="text" value="{{ auth.ldap.username }}" />
                    </div>
                    <div class="form-group">
                        <label for="auth_ldap_pass" class="form-label">{% trans %}Senha{% endtrans %}</label>
                        <input id="auth_ldap_pass" name="password" class="form-control" type="password" value="{{ auth.ldap.password }}" />
                    </div>
                    <div class="form-group">
                        <label for="auth_ldap_filter" class="form-label">{% trans %}Filtro{% endtrans %}</label>
                        <input id="auth_ldap_filter" name="filter" class="form-control" type="text" value="{{ auth.ldap.filter }}" />
                        <span class="help-block">ex: objectClass=user</span>
                    </div>
                </div>
                <div class="buttons">
                    <button id="auth_save" class="btn btn-primary" onclick="SGA.Admin.Auth.save()">
                        {% trans %}Salvar{% endtrans %}
                    </button>
                </div>
            </fieldset>
        </div>
        <div id="tab-triagem" class="tab-pane">
            <div class="form-group">
                <label for="numeracao" class="form-label">{% trans %}Tipo de numeração{% endtrans %}</label>
                <select id="numeracao" class="form-control" onchange="SGA.Admin.changeNumeracao()">
                    {% for k,v in numeracoes %}
                    <option value="{{ k }}" {% if k == numeracao %}selected="selected"{% endif %}>{{ v }}</option>
                    {% endfor %}
                </select>
            </div>
            <div class="form-group">
                <label class="form-label">{% trans %}Reiniciar senhas{% endtrans %}</label>
                <button class="btn btn-danger"
                        onclick="return SGA.Admin.reiniciarSenhas('{% trans %}Deseja realmente reiniciar as senhas de todas unidades?{% endtrans %}')">
                    {% trans %}Reiniciar{% endtrans %}
                </button>
            </div>
        </div>
        <div id="tab-api" class="tab-pane">
            <fieldset>
                <legend>Web API</legend>
                <p>As URLs abaixo são usadas para integrar o Novo SGA com outros projetos, como por exemplo o <strong>Painel Web</strong> e a <strong>Triagem Touch</strong>.</p>
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>Method</th>
                            <th>URI</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>
                                <span class="label label-danger">POST</span>
                            </td>
                            <td>
                                /api/token
                            </td>
                            <td>
                                Autentica o usuário retornando o token de acesso.
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="label label-success">GET</span>
                            </td>
                            <td>
                                /api/unidades
                            </td>
                            <td>
                                Retorna todas as unidades disponíveis
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="label label-success">GET</span>
                            </td>
                            <td>
                                /api/prioridades
                            </td>
                            <td>
                                Retorna todas as prioridades disponíveis
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="label label-success">GET</span>
                            </td>
                            <td>
                                /api/servicos
                            </td>
                            <td>
                                Retorna os serviços globais
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="label label-success">GET</span>
                            </td>
                            <td>
                                /api/servicos/:unidade
                            </td>
                            <td>
                                Retorna os serviços habilitados para a unidade informada
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="label label-danger">POST</span>
                            </td>
                            <td>
                                /api/distribui
                            </td>
                            <td>
                                Distribui uma nova senha para atendimento. Requer autenticação, um access_token válido e ativo.
                            </td>
                        </tr>
                    </tbody>
                </table>
            </fieldset>
            <fieldset>
                <legend>{% trans %}Clientes{% endtrans %}</legend>
                <p>Para acessar algumas URLs é necessário possuir um token de acesso, e para isso é necessário primeiro cadastrar a aplicação cliente.</p>
                <table id="oauth_clients" class="table table-striped">
                    <thead>
                        <tr>
                            <th>Client Id</th>
                            <th>Client Secret</th>
                            <th>Redirect URI</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                    <tfoot>
                        <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td class="buttons">
                                <a href="#dialog-clientid" data-toggle="modal" class="btn btn-default" onclick="$('#dialog-clientid :input').val('');">
                                    <span class="glyphicon glyphicon-plus"></span>
                                    {% trans %}Adicionar{% endtrans %}
                                </a>
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </fieldset>
        </div>
        <div id="tab-sobre" class="tab-pane">
            <div class="jumbotron">
                <h1>Novo SGA v{{ version }}</h1>
                <p>Sistema de Gerenciamento de Atendimento</p>
                <p>
                    <button id="btn-checkversion" class="btn btn-default btn-lg" role="button" onclick="return SGA.Admin.checkVersion();">
                        <span class="glyphicon glyphicon-refresh"></span>
                        {% trans %}Verificar nova versão{% endtrans %}
                    </button>
                    <a id="btn-downloader" href="#" class="btn btn-success btn-lg" role="button" style="display:none">
                        <span class="glyphicon glyphicon-download"></span>
                        Download <span class="version"></span>
                    </a>
                    <span id="update-alert" class="label label-success" style="display:none">
                        <span class="glyphicon glyphicon-ok"></span>
                        {% trans %}Parabéns, você possui a versão mais recente{% endtrans %}
                    </span>
                </p>
            </div>
            <h2>Comunidade</h2>
            <p>Procurando ajuda? Acesse um dos canais do projeto através dos links abaixo:</p>
            <div class="row">
                <div class="col-lg-4">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Blog
                        </div>
                        <div class="panel-body">
                            <p>Notícias relacionadas aos projetos do Novo SGA e lançamento de novas versões</p>
                            <p>
                                <a href="http://novosga.org/blog" class="btn btn-primary" target="_blank">
                                    <span class="glyphicon glyphicon-eye-open"></span>&nbsp;
                                    {% trans %}Acessar{% endtrans %}
                                </a>
                            </p>
                        </div>
                   </div>
                </div>
                <div class="col-lg-4">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Fórum
                        </div>
                        <div class="panel-body">
                            <p>Canal para tirar dúvidas sobre o uso ou instalação dos projetos.</p>
                            <p>
                                <a href="http://novosga.org/forum" class="btn btn-primary" target="_blank">
                                    <span class="glyphicon glyphicon-eye-open"></span>&nbsp;
                                    {% trans %}Acessar{% endtrans %}
                                </a>
                            </p>
                        </div>
                   </div>
                </div>
                <div class="col-lg-4">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Github
                        </div>
                        <div class="panel-body">
                            <p>Participe diretamente do desenvolvimento relatando problemas (issues).</p>
                            <p>
                                <a href="https://github.com/novosga/novosga" class="btn btn-primary" target="_blank">
                                    <span class="glyphicon glyphicon-eye-open"></span>&nbsp;
                                    {% trans %}Acessar{% endtrans %}
                                </a>
                            </p>
                        </div>
                   </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        SGA.Admin.Auth.init();
        SGA.Admin.WebApi.loadClients();
    </script>
</div>

{# reiniciar #}
<div id="dialog-reiniciar" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">{% trans %}Configuração{% endtrans %}</h4>
            </div>
            <div class="modal-body">
                <p>{% trans %}Senhas reiniciadas com sucesso{% endtrans %}</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">{% trans %}Fechar{% endtrans %}</button>
            </div>
        </div>
    </div>
</div>

{# oauth2 client id #}
<div id="dialog-clientid" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">OAuth2 client</h4>
            </div>
            <div class="modal-body">
                <form action="{{ baseUrl() }}/modules/sga.admin/add_oauth_client" method="post">
                    <div class="form-group">
                        <label for="client_id">Client Id</label>
                        <input type="text" id="client_id" name="client_id" class="form-control" required="true">
                    </div>
                    <div class="form-group">
                        <label for="client_secret">Client Secret</label>
                        <input type="password" id="client_secret" name="client_secret" class="form-control" required="true">
                    </div>
                    <div class="form-group">
                        <label for="redirect_uri">Redirect URL</label>
                        <input type="text" id="client_redirect_uri" name="redirect_uri" class="form-control" placeholder="http://">
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="SGA.Admin.WebApi.addClient(this)">{% trans %}Adicionar{% endtrans %}</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}