<commit_before>var conceptViewer = {
  concepts: {},
  loaded: false,
  shownConcept: null,

  load: function (lang) {
    // Load the conceptViewer into the DOM
    if(this.loaded) { return; }

    // TODO :: allow changing list of languages
    var allLangs = [
      {id: 'blockly', lbl: 'Blockly'},
      {id: 'scratch', lbl: 'Scratch'},
      {id: 'python', lbl: 'Python'}
      ];
    var langOptions = '';
    for(var i=0; i<allLangs.length; i++) {
      langOptions += '<option value="' + allLangs[i].id + '"';
      if((!lang && i == 0) || allLangs[i].id == lang) {
        langOptions += ' selected';
      }
      langOptions += '>' + allLangs[i].lbl + '</option>';
    }

    $('body').append(''
      + '<div id="conceptViewer" style="display: none;">'
      + '  <div class="content">'
      + '   <div class="panel-heading">'
      + '     <h2 class="sectionTitle"><span class="icon fas fa-list-ul"></span>Aide</h2>'
      + '     <div class="exit" onclick="conceptViewer.hide();"><span class="icon fas fa-times"></span></div>'
      + '   </div>'
      + '     <div class="navigation">'
      + '      <div class="navigationLanguage">'
      + '        <label>Sélectionnez un langage…</label>'
      + '        <select class="languageSelect" onchange="conceptViewer.languageChanged();">'
      + langOptions
      + '        </select>'
      + '      </div>'
      + '      <div class="navigationContent"></div>'
      + '    </div>'
      + '    <div class="viewer">'
      + '      <iframe class="viewerContent" name="viewerContent"></iframe>'
      + '    </div>'
      + '  </div>'
      + '</div>');

    var that = this;
    $('#conceptViewer').on('click', function (event) {
      if (!$(event.target).closest('#conceptViewer .content').length) {
        that.hide();
      }
    });
    this.loaded = true;
  },

  loadNavigation: function () {

    var navContent = "\
      <label for='showNavigationContent' class='showNavigationContent'>Sélectionnez une rubrique…</label>\
      <input type='checkbox' id='showNavigationContent' role='button'>\
      <ul>";
    var defaultUrl = null;
    for (var i=0; i<this.concepts.length; i++) {
      var curConcept = this.concepts[i];
      if(curConcept.isDefault) {
        defaultUrl = curConcept.url;
      }
      navContent += '<li data-id="'+curConcept.id+'">'
                  + '  <a onclick="conceptViewer.showConcept(\''+curConcept.id+'\');">'
                  + curConcept.name
                  + '  </a></li>';
    }
    navContent += "</ul>";
    $('#conceptViewer .navigationContent').html(navContent);

    // Try first to show again the concept we were viewing
    if(this.shownConcept && this.showConcept(this.shownConcept, false)) {
      return;
    } else if (defaultUrl) {
      // else show the default concept
      this.loadUrl(defaultUrl);
    } else {
      // else show nothing
      this.loadUrl('');
      this.shownConcept = null;
    }
  },

  loadConcepts: function (newConcepts) {
    // Load new concept information
    this.load();
    this.concepts = newConcepts;
    this.loadNavigation();
  },

  show: function (initConcept) {
    // Display the conceptViewer
    this.load();
    $('#conceptViewer').fadeIn(500);

    if (this.shownConcept && (initConcept || typeof initConcept == 'undefined')) {
      this.showConcept(this.shownConcept);
    }
  },

  hide: function () {
    // Hide the conceptViewer
    this.load();
    $('#conceptViewer').fadeOut(500);
    this.loadUrl('');
  },

  showConcept: function (concept, show) {
    // Show a specific concept
    // Either a concept object can be given, either a concept ID can be given
    // directly
    var conceptUrl = null;
    var conceptId = null;
    if (concept.url) {
      conceptUrl = concept.url;
      conceptId = concept.id;
    } else {
      conceptId = concept.id ? concept.id : concept;
      for (var i=0; i<this.concepts.length; i++) {
        if(this.concepts[i].id == conceptId) {
          conceptUrl = this.concepts[i].url;
        }
      }
    }
    if (conceptUrl) {
      this.shownConcept = conceptId;
      if(show || typeof show == 'undefined') { this.show(false); }

      var language = $('#conceptViewer .languageSelect').val();
      var urlSplit = conceptUrl.split('#');
      if(urlSplit[1]) {
        urlSplit[urlSplit.length-1] = language+'-'+urlSplit[urlSplit.length-1];
      } else {
        urlSplit[1] = language;
      }
      conceptUrl = urlSplit.join('#');

      this.loadUrl(conceptUrl);
      $('#conceptViewer .navigationContent ul li').removeClass('selected');
      $('#conceptViewer .navigationContent ul li[data-id='+conceptId+']').addClass('selected');
      $('#showNavigationContent').prop('checked', false);
      return true;
    } else {
      return false;
    }
  },

  loadUrl: function (url) {
    // Load an URL into the iframe
    if(window.conceptViewerUrlFunction) {
      url = window.conceptViewerUrlFunction(url);
    }
    $('#conceptViewer .viewerContent').attr('src', url);
  },

  hasConcept: function (conceptName) {
    // Check if a specific concept exists in the list of concepts
    for (var i=0; i<this.concepts.length; i++) {
      if(this.concepts[i].id == conceptName) {
        return true;
      }
    }
    return false;
  },

  languageChanged: function () {
    this.loadNavigation();
  }
}

// TODO :: temporary values for now

// Specific configuration to go through the domain itself if there's a 'p=1'
// argument or we are on concours2.castor-informatique.fr
var baseUrl = window.location.protocol + '//'
    + ((window.location.search.indexOf('p=1') > -1
        || window.location.hostname == 'concours2.castor-informatique.fr')
       ? window.location.host : 'static4.castor-informatique.fr')
    + '/help/index.html';


var testConcepts = [
    {id: 'taskplatform', name: 'Résolution des exercices', url: baseUrl+'#taskplatform', language: 'all'},
    {id: 'language', name: "Création d'un programme", url: baseUrl+'#language'},
    {id: 'blockly_text_print', name: 'Afficher du texte', url: baseUrl+'#blockly_text_print'},
    {id: 'blockly_text_print_noend', name: 'Afficher consécutivement du texte', url: baseUrl+'#blockly_text_print_noend'},
    {id: 'blockly_controls_repeat', name: 'Boucles de répétition', url: baseUrl+'#blockly_controls_repeat'},
    {id: 'blockly_controls_if', name: 'Conditions si', url: baseUrl+'#blockly_controls_if'},
    {id: 'blockly_controls_if_else', name: 'Conditions si/sinon', url: baseUrl+'#blockly_controls_if_else'},
    {id: 'blockly_controls_whileUntil', name: 'Boucles tant que ou jusqu\'à', url: baseUrl+'#blockly_controls_whileUntil'},
    {id: 'blockly_logic_operation', name: 'Opérateurs logiques', url: baseUrl+'#blockly_logic_operation'},
    {id: 'extra_nested_repeat', name: 'Boucles imbriquées', url: baseUrl+'#extra_nested_repeat'},
    {id: 'extra_variable', name: 'Variables', url: baseUrl+'#extra_variable'},<commit_msg>concept viewer: change language selection to list, same as concept selection<commit_after>var conceptViewer = {
  concepts: {},
  loaded: false,
  shownConcept: null,
  selectedLanguage: null,

  load: function (lang) {
    // Load the conceptViewer into the DOM
    if(this.loaded) { return; }

    // TODO :: allow changing list of languages
    var allLangs = [
      {id: 'blockly', lbl: 'Blockly'},
      {id: 'scratch', lbl: 'Scratch'},
      {id: 'python', lbl: 'Python'}
      ];

    conceptViewer.selectedLanguage = lang;
    var navLanguage = '\
      <label for="showNavigationLanguage">Sélectionnez un langage…</label>\
      <input type="checkbox" id="showNavigationLanguage" role="button">\
      <ul>';
    for(var i=0; i<allLangs.length; i++) {
      navLanguage += '<li data-id="'+ allLangs[i].id + '"';
      if((!lang && i == 0) || allLangs[i].id == lang) {
        navLanguage +=  ' class="selected"';
      }
      navLanguage += '><span>' + allLangs[i].lbl + '</span>';
      navLanguage += '</li>';
    }
    navLanguage += '</ul>';

    $('body').append(''
      + '<div id="conceptViewer" style="display: none;">'
      + '  <div class="content">'
      + '   <div class="panel-heading">'
      + '     <h2 class="sectionTitle"><span class="icon fas fa-list-ul"></span>Aide</h2>'
      + '     <div class="exit" onclick="conceptViewer.hide();"><span class="icon fas fa-times"></span></div>'
      + '   </div>'
      + '     <div class="navigation">'
      + '      <div class="navigationLanguage">'
      + navLanguage
      + '      </div>'
      + '      <div class="navigationContent"></div>'
      + '    </div>'
      + '    <div class="viewer">'
      + '      <iframe class="viewerContent" name="viewerContent"></iframe>'
      + '    </div>'
      + '  </div>'
      + '</div>');

    var that = this;
    $('#conceptViewer').on('click', function (event) {
      if (!$(event.target).closest('#conceptViewer .content').length) {
        that.hide();
      }
    });
    this.loaded = true;

    $('#conceptViewer .navigationLanguage ul li').click(function(){
      conceptViewer.selectedLanguage = $(this).data('id');
      conceptViewer.languageChanged();
    });
  },

  loadNavigation: function () {

    var navContent = "\
      <label for='showNavigationContent' class='showNavigationContent'>Sélectionnez une rubrique…</label>\
      <input type='checkbox' id='showNavigationContent' role='button'>\
      <ul>";
    var defaultUrl = null;
    for (var i=0; i<this.concepts.length; i++) {
      var curConcept = this.concepts[i];
      if(curConcept.isDefault) {
        defaultUrl = curConcept.url;
      }
      navContent += '<li data-id="'+curConcept.id+'">'
                  + '  <a onclick="conceptViewer.showConcept(\''+curConcept.id+'\');">'
                  + curConcept.name
                  + '  </a></li>';
    }
    navContent += "</ul>";
    $('#conceptViewer .navigationContent').html(navContent);

    // Try first to show again the concept we were viewing
    if(this.shownConcept && this.showConcept(this.shownConcept, false)) {
      return;
    } else if (defaultUrl) {
      // else show the default concept
      this.loadUrl(defaultUrl);
    } else {
      // else show nothing
      this.loadUrl('');
      this.shownConcept = null;
    }
  },

  loadConcepts: function (newConcepts) {
    // Load new concept information
    this.load();
    this.concepts = newConcepts;
    this.loadNavigation();
  },

  show: function (initConcept) {
    // Display the conceptViewer
    this.load();
    $('#conceptViewer').fadeIn(500);

    if (this.shownConcept && (initConcept || typeof initConcept == 'undefined')) {
      this.showConcept(this.shownConcept);
    }
  },

  hide: function () {
    // Hide the conceptViewer
    this.load();
    $('#conceptViewer').fadeOut(500);
    this.loadUrl('');
  },

  showConcept: function (concept, show) {
    // Show a specific concept
    // Either a concept object can be given, either a concept ID can be given
    // directly
    var conceptUrl = null;
    var conceptId = null;
    if (concept.url) {
      conceptUrl = concept.url;
      conceptId = concept.id;
    } else {
      conceptId = concept.id ? concept.id : concept;
      for (var i=0; i<this.concepts.length; i++) {
        if(this.concepts[i].id == conceptId) {
          conceptUrl = this.concepts[i].url;
        }
      }
    }
    if (conceptUrl) {
      this.shownConcept = conceptId;
      if(show || typeof show == 'undefined') { this.show(false); }

      var language = conceptViewer.selectedLanguage;
      var urlSplit = conceptUrl.split('#');
      if(urlSplit[1]) {
        urlSplit[urlSplit.length-1] = language+'-'+urlSplit[urlSplit.length-1];
      } else {
        urlSplit[1] = language;
      }
      conceptUrl = urlSplit.join('#');

      this.loadUrl(conceptUrl);
      $('#conceptViewer .navigationContent ul li').removeClass('selected');
      $('#conceptViewer .navigationContent ul li[data-id='+conceptId+']').addClass('selected');
      $('#showNavigationContent').prop('checked', false);
      return true;
    } else {
      return false;
    }
  },

  loadUrl: function (url) {
    // Load an URL into the iframe
    if(window.conceptViewerUrlFunction) {
      url = window.conceptViewerUrlFunction(url);
    }
    $('#conceptViewer .viewerContent').attr('src', url);
  },

  hasConcept: function (conceptName) {
    // Check if a specific concept exists in the list of concepts
    for (var i=0; i<this.concepts.length; i++) {
      if(this.concepts[i].id == conceptName) {
        return true;
      }
    }
    return false;
  },

  languageChanged: function () {
    $('#showNavigationLanguage').prop('checked', false);
    this.loadNavigation();
  }
}

// TODO :: temporary values for now

// Specific configuration to go through the domain itself if there's a 'p=1'
// argument or we are on concours2.castor-informatique.fr
var baseUrl = window.location.protocol + '//'
    + ((window.location.search.indexOf('p=1') > -1
        || window.location.hostname == 'concours2.castor-informatique.fr')
       ? window.location.host : 'static4.castor-informatique.fr')
    + '/help/index.html';


var testConcepts = [
    {id: 'taskplatform', name: 'Résolution des exercices', url: baseUrl+'#taskplatform', language: 'all'},
    {id: 'language', name: "Création d'un programme", url: baseUrl+'#language'},
    {id: 'blockly_text_print', name: 'Afficher du texte', url: baseUrl+'#blockly_text_print'},
    {id: 'blockly_text_print_noend', name: 'Afficher consécutivement du texte', url: baseUrl+'#blockly_text_print_noend'},
    {id: 'blockly_controls_repeat', name: 'Boucles de répétition', url: baseUrl+'#blockly_controls_repeat'},
    {id: 'blockly_controls_if', name: 'Conditions si', url: baseUrl+'#blockly_controls_if'},
    {id: 'blockly_controls_if_else', name: 'Conditions si/sinon', url: baseUrl+'#blockly_controls_if_else'},
    {id: 'blockly_controls_whileUntil', name: 'Boucles tant que ou jusqu\'à', url: baseUrl+'#blockly_controls_whileUntil'},
    {id: 'blockly_logic_operation', name: 'Opérateurs logiques', url: baseUrl+'#blockly_logic_operation'},
    {id: 'extra_nested_repeat', name: 'Boucles imbriquées', url: baseUrl+'#extra_nested_repeat'},
    {id: 'extra_variable', name: 'Variables', url: baseUrl+'#extra_variable'},
{'fraction_non_alphanumeric': 0.16670165861851774, 'fraction_numerical': 0.003219259570298831, 'mean_word_length': 2.942068965517241, 'pattern_counts': {'":': 0, '<': 92, '<?xml version=': 0, '>': 86, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7236193', 'n_tokens_mistral': 4647, 'n_tokens_neox': 4552, 'n_words': 972}