<commit_before>/**
 * @fileoverview Provides a layer info service. That service is a function used
 * to retrieve and display the info (metadata) for a layer.
 */

goog.provide('app.ShowLayerinfo');

goog.require('ngeo.CreatePopup');


/**
 * @typedef {function(ol.layer.Layer)}
 */
app.ShowLayerinfo;


/**
 * @param {angularGettext.Catalog} gettextCatalog Gettext catalog.
 * @param {angular.$http} $http Angular $http service
 * @param {angular.$sce} $sce Angular $sce service
 * @param {ngeo.CreatePopup} ngeoCreatePopup Ngeo popup factory service
 * @return {app.ShowLayerinfo} The show layer info function.
 * @ngInject
 */
app.showLayerinfoFactory = function(gettextCatalog,
                                    $http,
                                    $sce,
                                    ngeoCreatePopup) {

  /**
   * @type {ngeo.Popup}
   */
  var popup = ngeoCreatePopup();

  return (
      /**
       * @param {ol.layer.Layer} layer The layer
       */
      function(layer) {
        var title = /** @type {string} */ (layer.get('label'));
        popup.setTitle(title);

        $http.jsonp(
            'http://shop.geoportail.lu/Portail/inspire/webservices/getMD.jsp',
            {params: {
              'uid': layer.get('metadata')['metadata_id'],
              'lang': gettextCatalog.currentLanguage,
              'cb': 'JSON_CALLBACK'
            }
            }).success(function(data, status, headers, config) {
              if (status == 200) {
                data.root[0]['uid'] = layer.get('metadata')['metadata_id'];
                if ('legend_name' in layer.get('metadata')) {
                  data.root[0]['legend_name'] =
                      layer.get('metadata')['legend_name'];
                  data.root[0]['legend_url'] = $sce.trustAsResourceUrl(
                      '//wiki.geoportail.lu/doku.php?id=' +
                          gettextCatalog.currentLanguage + ':legend:' +
                          data.root[0]['legend_name'] + '&do=export_html');
                  data.root[0]['has_legend'] = true;
                }else {
                  data.root[0]['has_legend'] = false;
                }
                data.root[0]['is_error'] = false;
                popup.setContent(data.root[0]);
                popup.show();
          }else {
                popup.setContent({'is_error': true});
                popup.show();
          }
        }). error(function(data, status, headers, config) {<commit_msg>use local variables<commit_after>/**
 * @fileoverview Provides a layer info service. That service is a function used
 * to retrieve and display the info (metadata) for a layer.
 */

goog.provide('app.ShowLayerinfo');

goog.require('ngeo.CreatePopup');


/**
 * @typedef {function(ol.layer.Layer)}
 */
app.ShowLayerinfo;


/**
 * @param {angularGettext.Catalog} gettextCatalog Gettext catalog.
 * @param {angular.$http} $http Angular $http service
 * @param {angular.$sce} $sce Angular $sce service
 * @param {ngeo.CreatePopup} ngeoCreatePopup Ngeo popup factory service
 * @return {app.ShowLayerinfo} The show layer info function.
 * @ngInject
 */
app.showLayerinfoFactory = function(gettextCatalog,
                                    $http,
                                    $sce,
                                    ngeoCreatePopup) {

  /**
   * @type {ngeo.Popup}
   */
  var popup = ngeoCreatePopup();

  return (
      /**
       * @param {ol.layer.Layer} layer The layer
       */
      function(layer) {
        var title = /** @type {string} */ (layer.get('label'));
        var local_metadata = layer.get('metadata');

        popup.setTitle(title);

        $http.jsonp(
            'http://shop.geoportail.lu/Portail/inspire/webservices/getMD.jsp',
            {params: {
              'uid': local_metadata['metadata_id'],
              'lang': gettextCatalog.currentLanguage,
              'cb': 'JSON_CALLBACK'
            }
            }).success(function(data, status, headers, config) {
              if (status == 200) {
                var remote_metadata = data.root[0];
                remote_metadata['uid'] = local_metadata['metadata_id'];
                if ('legend_name' in local_metadata) {
                  remote_metadata['legend_name'] =
                      local_metadata['legend_name'];
                  remote_metadata['legend_url'] = $sce.trustAsResourceUrl(
                      '//wiki.geoportail.lu/doku.php?id=' +
                          gettextCatalog.currentLanguage + ':legend:' +
                          remote_metadata['legend_name'] + '&do=export_html');
                  remote_metadata['has_legend'] = true;
                }else {
                  remote_metadata['has_legend'] = false;
                }
                remote_metadata['is_error'] = false;
                popup.setContent(remote_metadata);
                popup.show();
          }else {
                popup.setContent({'is_error': true});
                popup.show();
          }
        }). error(function(data, status, headers, config) {
{'fraction_non_alphanumeric': 0.1356873636183297, 'fraction_numerical': 0.0029756000793493354, 'mean_word_length': 1.8042269187986653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5931133', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1389, 'n_words': 270}