Commit f040cb76 authored by Thibaut Vallee's avatar Thibaut Vallee
Browse files

fichier manquants

parent 3475981c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ INSERT INTO UNICAEN_PRIVILEGE_CATEGORIE (
    ORDRE
)
values
    ('administration',           'Administration',                    'Application\Provider\Privilege', 1001),
    ('administration',           'Administration',                    'Application\Provider\Privilege', 1001)
  ON CONFLICT (CODE) DO
UPDATE SET
    LIBELLE=excluded.LIBELLE,
+2 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@
      "[ -d 'vendor/laminas-api-tools/api-tools-doctrine-querybuilder' ] || git clone https://github.com/orderadmin/api-tools-doctrine-querybuilder vendor/laminas-api-tools/api-tools-doctrine-querybuilder"
    ],
    "post-install-cmd": [
        "cp -r vendor/unicaen/utilisateur-api/config/api.global.php.dist   config/autoload/api.global.php",
        "cp -r vendor/unicaen/utilisateur-api/config/api.local.php.dist   config/autoload/api.local.php"
    ],
    "post-update-cmd": [
    ],
+140 −0
Original line number Diff line number Diff line
<?php

use Application\Application\View\Renderer\PhpRenderer;

/**
 * Copie du ficher @file vendor/api-tools-documentation-swagger/view/api-tools-documentation-swagger/show.html
 * en adaptant la route vers les définitions : 'api/definition-yaml'
 *
 * @var PhpRenderer $this
 * @var string $api
 * @var string $version
 *
 * @see DocumentationController::afficherAction()
 */

$base = $this->basePath() . '/api-tools-documentation-swagger/';
?>


<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Swagger UI</title>
        <link rel="icon" type="image/png" href="<?php echo $base ?>images/favicon-32x32.png" sizes="32x32" />
        <link rel="icon" type="image/png" href="<?php echo $base ?>images/favicon-16x16.png" sizes="16x16" />
<!-- Unistrap-->
        <link href='/css/swagger-unistrap.css' media='screen' rel='stylesheet' type='text/css'/>

        <link href='<?php echo $base ?>css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
        <link href='<?php echo $base ?>css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
        <link href='<?php echo $base ?>css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
        <link href='<?php echo $base ?>css/reset.css' media='print' rel='stylesheet' type='text/css'/>
        <link href='<?php echo $base ?>css/print.css' media='print' rel='stylesheet' type='text/css'/>

        <script src='<?php echo $base ?>lib/object-assign-pollyfill.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/jquery-1.12.4.min.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/jquery.slideto.min.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/jquery.wiggle.min.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/handlebars-v4.7.3.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/lodash.min.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/backbone-min.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>swagger-ui.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/highlight.9.1.0.pack.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/highlight.9.1.0.pack_extended.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/jsoneditor.min.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/marked.js' type='text/javascript'></script>
        <script src='<?php echo $base ?>lib/swagger-oauth.js' type='text/javascript'></script>

        <!-- Some basic translations -->
        <!-- <script src='lang/translator.js' type='text/javascript'></script> -->
        <!-- <script src='lang/ru.js' type='text/javascript'></script> -->
        <!-- <script src='lang/en.js' type='text/javascript'></script> -->

        <script type="text/javascript">
            $(function () {

                hljs.configure({
                    highlightSizeThreshold: 5000
                });

                // Pre load translate...
                if (window.SwaggerTranslator) {
                    window.SwaggerTranslator.translate();
                }

                var acceptHeader = {
                    apply: function (obj, authorizations) {
                        if (obj.url.match(/<?= preg_quote($this->url('api/definition-yaml', ['api' => null]), '/') ?>/)) {
                            obj.headers['Accept'] = 'application/vnd.swagger+json';
                            obj.headers['accept'] = 'application/vnd.swagger+json';
                            obj.headers['documentation-accept-header'] = 'application/vnd.swagger+json';
                        }
                        return true;
                    }
                };

                window.swaggerUi = new SwaggerUi({
                    url: "<?php echo $this->url('api/definition-yaml', ['api' => $api, 'version' => $version]) ?>",
                    dom_id: "swagger-ui-container",
                    supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
                    authorizations: {"documentation-accept-header": acceptHeader},
                    onComplete: function (swaggerApi, swaggerUi) {
                        if (typeof initOAuth == "function") {
                            initOAuth({
                                clientId: "your-client-id",
                                clientSecret: "your-client-secret-if-required",
                                realm: "your-realms",
                                appName: "your-app-name",
                                scopeSeparator: " ",
                                additionalQueryStringParams: {}
                            });
                        }

                        if (window.SwaggerTranslator) {
                            window.SwaggerTranslator.translate();
                        }
                    },
                    onFailure: function (data) {
                        log("Unable to Load SwaggerUI");
                    },
                    docExpansion: "none",
                    jsonEditor: false,
                    defaultModelRendering: 'schema',
                    showRequestHeaders: false
                });

                window.swaggerUi.load();

                function log() {
                    if ('console' in window) {
                        console.log.apply(console, arguments);
                    }
                }
            });
        </script>
    </head>

    <body class="swagger-section swagger-unistrap">

    <div id='header'>
        <div class="swagger-ui-wrap">
            <a id="logo" href="http://swagger.io"><img class="logo__img" alt="swagger" height="30" width="30" src="<?php echo $base ?>images/logo_small.png" /><span class="logo__title">Swagger</span></a>
            <a id="back-to-app" class="" href="/" data-sw-translate><?php echo $this->appInfos()->nom ?></a>

            <form id='api_selector'>
                <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
                <div id='auth_container'></div>
                <div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
            </form>
        </div>

    </div>

    <div id="message-bar" class="swagger-ui-wrap" data-sw-translate>&nbsp;</div>
    <div id="swagger-ui-container" class="swagger-ui-wrap"></div>

    </body>
</html>
 No newline at end of file
+46 −0
Original line number Diff line number Diff line
<?php
use Application\Application\View\Renderer\PhpRenderer;

/**
 * @var PhpRenderer $this
 */

$this->headTitle("Web Services");
?>

<div class="page">
    <div class="headTitle">
        <h4 class="big_title">
            <i class="fas fa-cogs"></i> Les Web Services
        </h4>
    </div>

<table class="table table-striped">
    <thead>
    <tr>
        <th>API</th>
        <th>Versions</th>
    </tr>
    </thead>
    <tbody><?php foreach ($this->apis as $api):
        $name = $api['name']; ?>
        <tr>
            <td><?php echo "MeteoSI $name" ?></td>
            <td><?php
                $view     = $this;
                $versions = array_map(function ($version) use ($name, $view) {
                    return sprintf(
                        '<a target="_blank" href="%s">v%s</a>',
                        $view->url('api/documentation', array(
                            'api' => sprintf('%s-v%s', $name, $version),
                        )),
                        $view->escapeHtml($version)
                    );
                }, $api['versions']);
                echo implode('&nbsp;|&nbsp;', $versions);
                ?></td>
        </tr>
    <?php endforeach; ?></tbody>
</table>

</div>
 No newline at end of file
+235 −0
Original line number Diff line number Diff line
<?php

use Api\Form\ApiTestForm;
use Application\Application\View\Renderer\PhpRenderer;

/**
 * @var PhpRenderer $this
 * @var ApiTestForm $form
 *
 * @see RequestController::testerAction()
 */

$fct = $this->formControlText();
$fcg = $this->formControlGroup();

$this->headTitle("Web Services");
?>

<div id="fil-ariane">
    <ol class="breadcrumb">
        <li><a href="<?php echo $this->url('home', [], [], true); ?>" title="Accueil de l'application"><i class="fas fa-home"></i></a></li>
        <li>Les Web Services</li>
    </ol>
</div>

<div class="fieldset">
    <?php echo $this->form()->openTag($form->prepare()); ?>

    <h3>Tester l'API</h3>

    <div class="row">
        <div class="col-md-6">
            <?php echo $fcg($form->get('service')); ?>
            <?php echo $fct->setPrefix('/api')->render($form->get('url')); ?>
            <?php echo $this->formButton($form->get('envoyer')); ?>
        </div>
    </div>

    <?php echo $this->form()->closeTag(); ?>
</div>

<div id="api-request" class="well small">
    <div class="status-code" title="Response Status Code"></div>
    <div>
        <strong>Request URL :</strong> <span id="request-url"></span><br/>
        <strong>Request Method :</strong> <span id="request-method"></span><br/>
        <strong>Response Status :</strong> <span id="response-status"></span><br/>
    </div>
</div>

<div id="api-result">
    <pre>
        <code class="json">
        </code>
    </pre>
</div>

<div id="hide" style="display: none">
    <table id="api-table-result" class="table table-hover table-condensed" width="100%">
    </table>
</div>


<script type="text/javascript">
    $(function () {
        /**
         * Get an array of indexes for columns that have the given class name.
         *
         * @param columns list of DataTables column objects
         * @param className name of the class to look for
         * @returns array of indexes
         */
        function getColumnIndexesWithClass(columns, className) {
            var indexes = [];
            $.each(columns, function (index, columnInfo) {
                // note: doesn't attempt to support multiple class names on a column
                if (columnInfo.className == className) {
                    indexes.push(index);
                }
            });

            return indexes;
        }

        // colonnes par service à définir
        var columns_by_service = {
            'fonction': {
                'id': "ID",
                'code': "Code",
                'parent': "Parent",
                'libelle': "Libellé",
                'type': "Type",
                'niveau': "Niveau",
            },
        };

        $('body')
            .on('change', '#service', function () {
                that = $(this).val();
                var startUrl = that != null ? '/' + that : '';
                $('#url')
                    .val(startUrl)
                    .change();
            })
            .on('change paste input', '#url', function () {
                var button = $('#envoyer');
                $(this).val() !== ''
                    ? button.prop("disabled", false)
                    : button.prop("disabled", true);
            })
            .on('keydown', '#url', function (event) {
                var keyCode = (event.keyCode ? event.keyCode : event.which);
                if (keyCode === 13 && $(this).val() !== '') {
                    $('#envoyer').click();
                }
            })
            .on('click', '#envoyer', function () {
                var getUrl = window.location;
                var baseUrl = getUrl.protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
                var el = this;

                $('#hide').css('display', 'none');

                $.ajax({
                    headers: {
                        Accept: "application/json, text/plain, */*",
                    },
                    url: baseUrl + $("#url").val(),
                    beforeSend: function (xhr, obj) {
                        // Button
                        $(el).attr("disabled", true)
                            .find('i').attr('class', 'fas fa-pulse fa-spinner');

                        // Réinitialisation Json
                        $('#api-result>pre>code').html('');
                        $('#api-result').hide();

                        // Réinitialisation Datatables
                        if ($.fn.DataTable.isDataTable('#api-table-result')) {
                            var tableResult = $('#api-table-result');
                            tableResult.DataTable()
                                .clear()
                                .destroy();
                            tableResult.html('');
                        }
                    },
                    success: function (data, status, xhr) {
                        // Affichage du Json
                        $('#api-result>pre>code').html(JSON.stringify(data, undefined, 4));
                        document.querySelectorAll('pre code').forEach((block) => {
                            hljs.highlightBlock(block);
                        });
                        $('#api-result').show();

                        var service = $('#service').val();
                        if (service !== '') {
                            // Affichage Table des résultats
                            data = data.hasOwnProperty('id') ? [data] : data._embedded[service];
                            var columns = [];
                            if (typeof columns_by_service[service] !== 'undefined') {
                                // def_columns for Datatable
                                $.each(columns_by_service[service], function (k, v) {
                                    var tab = {'title': v, 'data': k, 'className': 'col-' + service + '-' + k};
                                    columns.push(tab);
                                });

                                $('#api-table-result').DataTable({
                                    data: data,
                                    order: [],
                                    columns: columns,
                                    columnDefs: [
                                        {
                                            "targets": getColumnIndexesWithClass(columns, 'col-fonction-libelle'),
                                            "render": function (data, type, row) {
                                                var lib = row._embedded.libelles[0];
                                                return typeof lib !== 'undefined' ? lib.libelle : null;
                                            },
                                        },
                                    ],
                                    "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "Tous"]],
                                    "language": {
                                        'lengthMenu': "Afficher _MENU_ &eacute;l&eacute;ments",
                                        "search": "Filtre de recherche : _INPUT_",
                                        "loadingRecords": "Chargement en cours...",
                                        'info': "<small class=\"text-highlight\">Affichage : <strong><i class=\"far fa-list-alt\"></i> _START_ - _END_ sur _TOTAL_</strong></small>",
                                        'infoEmpty': "",
                                        'infoFiltered': "<small class=\"text-highlight\">(_MAX_ &eacute;l&eacute;ments au total)</small>",
                                        'emptyTable': "Aucune donnée disponible.",
                                        'zeroRecords': "Aucun enregistrement trouvé.",
                                        "paginate": {
                                            "previous": "<i class=\"fas fa-chevron-left\"></i>",
                                            "next": "<i class=\"fas fa-chevron-right\"></i>"
                                        }
                                    },
                                });

                                $('#hide').css('display', 'block');
                            }
                        }
                    },
                    error: function (xhr, status, error) {
                        var response = xhr.responseJSON;
                        if (typeof response !== 'undefined') {
                            $('#api-result>pre>code').html(JSON.stringify(response, undefined, 4));
                            document.querySelectorAll('pre code').forEach((block) => {
                                hljs.highlightBlock(block);
                            });
                        } else {
                            $('#api-result>pre>code').html('[No Response Data]');
                        }
                        $('#api-result').show();
                    },
                    complete: function (xhr, status) {
                        // Information sur la requête
                        $('#api-request>div>span#request-url').html('<a target="_blank" href="' + this.url + '">' + this.url + '</a>');
                        $('#api-request>div>span#request-method').html(this.type);
                        $('#api-request>div>span#response-status').html(xhr.status + ' - ' + xhr.statusText);
                        $('#api-request>div.status-code').html(xhr.status).removeClass(function () {
                            var lastClass = $(this).attr("class").split(' ').pop().match('http-\d*');
                            return (lastClass) ? lastClass.input : '';
                        }).addClass('http-' + xhr.status);
                        $('#api-request').show();

                        // Button
                        $(el).attr("disabled", false)
                            .find('i').attr('class', 'fas fa-arrow-circle-right');
                    }
                });
            });

        $(document).on("keydown", "form", function (event) {
            return event.key !== "Enter";
        });
    });
</script>