prefeiturasp/SME-PratoAberto-Editor

View on GitHub
templates/visualizador_cardapio.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Calendário</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">



    <style>
        .row {
            margin-top: 20px;
            margin-bottom: 20px;
            padding: 0 10px;
        }

        .row.tbl {
            padding-top: 40px;
        }

        .table td {
            /*height: 150px;*/
            max-height: 150px;
            text-align: left;
            max-width: 0;
            /*width: 14.285714285714285714285714285714%;
            *width: 14.285714285714285714285714285714%;*/

        }

        .table th {
            /*text-align: left;*/
            padding-top: 8px;
            background-color: #D9F7FA;
        }

        .navbar-nav {
            margin-top: 8px;
        }

        .clickable {
            cursor: pointer;
        }

        .panel-heading div {
            margin-top: -18px;
            font-size: 15px;
        }

        .panel-heading div span {
            margin-left: 5px;
        }

        .panel-body {
            display: none;
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- NAVBAR -->
        <div class="row">
            <nav class="navbar navbar-default">
                <div class="container-fluid">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                        <a class="navbar-brand" href="#">Prato Aberto - Editor de Cardápio</a>
                    </div>
                    <div class="collapse navbar-collapse">
                        <ul class="nav navbar-nav navbar-right">
                            <a type="button" class="btn btn-default " href="{{ referrer }}">
                                <span class="glyphicon glyphicon-chevron-left"></span> VOLTAR PARA CARDÁPIOS
                            </a>
                        </ul>
                    </div>
                </div>
            </nav>
        </div>

        <!-- Informações do agrupamento -->
        <div class="container">
            <div style="text-align: left">
                <span type="button" class="btn btn-lg btn-default disabled" id="tipo_atendimento">{{ tipo_atendimento
                    }}</span>
                <span type="button" class="btn btn-lg btn-default disabled" id="tipo_unidade">{{ tipo_unidade }}</span>
                <span type="button" class="btn btn-lg btn-default disabled" id="idade">{{ idade }}</span>
                <span type="button" class="btn btn-lg btn-default disabled" id="agrupamento">{{ agrupamento }}</span>
            </div>
        </div>

        <!-- Acrescentar a tabela para o calendario -->
        <div class="row tbl">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">Editor de Cardápio</h3>
                    <div class="pull-right">
                        <span class="clickable filter" data-toggle="tooltip" title="Toggle table filter"
                            data-container="body">
                            <i class="glyphicon glyphicon-filter"></i>
                        </span>
                    </div>
                </div>
                <div class="panel-body">
                    <input type="text" class="form-control" id="task-table-filter" data-action="filter"
                        data-filters="#task-table" placeholder="Filter Tasks" />
                </div>
                <table class="table table-hover table-striped" id="task-table">
                    <thead>
                        <tr>
                            <th class="col-md-1" onclick="w3.sortHTML('#task-table', '.item', 'td:nth-child(1)')"
                                style="cursor:pointer">DIA<i class="fa fa-sort" aria-hidden="true"></i></th>
                            <th class="col-md-1" onclick="w3.sortHTML('#task-table', '.item', 'td:nth-child(2)')"
                                style="cursor:pointer">SEMANA <i class="fa fa-sort" aria-hidden="true"></i></th>
                            <th class="col-md-2" onclick="w3.sortHTML('#task-table', '.item', 'td:nth-child(3)')"
                                style="cursor:pointer">TIPO REFEIÇÃO <i class="fa fa-sort" aria-hidden="true"></i></th>
                            <th class="col-md-4" onclick="w3.sortHTML('#task-table', '.item', 'td:nth-child(4)')"
                                style="cursor:pointer">LISTA DE ALIMENTOS <i class="fa fa-sort" aria-hidden="true"></i>
                            </th>
                            <th class="col-md-4">RECEITA</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for cardapio in cardapios %}
                        {% for tipo_refeicao, lista_alimentos in cardapio['cardapio'].items() %}
                        <tr class="item" id="{{ cardapio['_id']['$oid'] }}">
                            <td class="col-md-1">
                                <p class="text-center">{{ cardapio['data'] }}</p>
                            </td>
                            <td class="col-md-1">
                                <p class="text-center">{{ cardapio['dia_semana'] }}</p>
                            </td>
                            <td class="col-md-2">{{ tipo_refeicao }}</td>
                            <td class="lista-alimentos col-md-4">
                                {% for ingrediente in cardapio['cardapio_original'][tipo_refeicao] %}
                                {{ ingrediente }},
                                {% endfor %}
                            </td>
                            <td class="col-md-4">
                                {% for ingrediente in lista_alimentos %}
                                {{ ingrediente }},
                                {% endfor %}
                            </td>
                        </tr>
                        {% endfor %}
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- Mantem a aba selecionada mesmo depois de mudar de data -->
    <script>
        $(function () {
            // for bootstrap 3 use 'shown.bs.tab', for bootstrap 2 use 'shown' in the next line
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // save the latest tab; use cookies if you like 'em better:
                localStorage.setItem('lastTab', $(this).attr('href'));
            });

            // go to the latest tab, if it exists:
            var lastTab = localStorage.getItem('lastTab');
            if (lastTab) {
                $('[href="' + lastTab + '"]').tab('show');
            }
        });
    </script>

    <!-- Botões de ordenação da tabela -->
    <script src="/editor/static/js/w3.js"></script>

    <!-- Script com a funcionalidade do filtro da tabela -->
    <script>
        /**
        *   I don't recommend using this plugin on large tables, I just wrote it to make the demo useable. It will work fine for smaller tables
        *   but will likely encounter performance issues on larger tables.
        *
        *       <input type="text" class="form-control" id="dev-table-filter" data-action="filter" data-filters="#dev-table" placeholder="Filter Developers" />
        *       $(input-element).filterTable()
        *
        *   The important attributes are 'data-action="filter"' and 'data-filters="#table-selector"'
        */
        (function () {
            'use strict';
            var $ = jQuery;
            $.fn.extend({
                filterTable: function () {
                    return this.each(function () {
                        $(this).on('keyup', function (e) {
                            $('.filterTable_no_results').remove();
                            var $this = $(this),
                                search = $this.val().toLowerCase(),
                                target = $this.attr('data-filters'),
                                $target = $(target),
                                $rows = $target.find('tbody tr');

                            if (search == '') {
                                $rows.show();
                            } else {
                                $rows.each(function () {
                                    var $this = $(this);
                                    $this.text().toLowerCase().indexOf(search) === -1 ? $this.hide() : $this.show();
                                })
                                if ($target.find('tbody tr:visible').size() === 0) {
                                    var col_count = $target.find('tr').first().find('td').size();
                                    var no_results = $('<tr class="filterTable_no_results"><td colspan="' + col_count + '">No results found</td></tr>')
                                    $target.find('tbody').append(no_results);
                                }
                            }
                        });
                    });
                }
            });
            $('[data-action="filter"]').filterTable();
        })(jQuery);

        $(function () {
            // attach table filter plugin to inputs
            $('[data-action="filter"]').filterTable();

            $('.container').on('click', '.panel-heading span.filter', function (e) {
                var $this = $(this),
                    $panel = $this.parents('.panel');

                $panel.find('.panel-body').slideToggle();
                if ($this.css('display') != 'none') {
                    $panel.find('.panel-body input').focus();
                }
            });
            $('[data-toggle="tooltip"]').tooltip();
        })
    </script>

</body>

</html>