<commit_before>/* Copyright (c) 2012-2015 The TagSpaces Authors. All rights reserved.
 * Use of this source code is governed by a AGPL3 license that
 * can be found in the LICENSE file. */
/* global define, Handlebars, isCordova  */
define(function(require, exports, module) {
  'use strict';
  var homeFolderTitle = 'Home';

  console.log('Loading directories.ui.js ...');
  var TSCORE = require('tscore');
  var TSPRO = require('tspro');
  var directoryHistory = [];
  var dir4ContextMenu = null;
  var tsMetadataFolder = '.ts';
  var tsMetadataFile = 'tsm.json';
  var alternativeDirectoryNavigatorTmpl = Handlebars.compile(
    '{{#each dirHistory}}' +
    '<div class="btn-group dropup">' +
        '<button class="btn btn-link dropdown-toggle" data-menu="{{@index}}">' +
            '{{name}}&nbsp;&nbsp;<i class="fa fa-caret-right"></i>&nbsp;'  +
        '</button>' +
        '<div class="dropdown clearfix dirAltNavMenu" id="dirMenu{{@index}}">' +
            '<ul style="overflow-y: auto; max-height: 430px; width: 250px; padding: 5px; display: block;" role="menu" class="dropdown-menu">' +
                '<li class="dropdown-header"><button type="button" class="close">&times;</button>{{../actionsForDirectory}}&nbsp;"{{name}}"</li>' +
                '<li><a class="btn btn-link pull-left reloadCurrentDirectory" data-path="{{path}}"><i class="fa fa-refresh fa-fw"></i>&nbsp;{{../reloadCurrentDirectory}}</a></li>' +
                '<li class="notreadonly"><a class="btn btn-link pull-left createSubdirectory" data-path="{{path}}"><i class="fa fa-folder-o fa-fw"></i>&nbsp;{{../createSubdirectory}}</a></li>' +
                '<li class="notreadonly"><a class="btn btn-link pull-left renameDirectory" data-path="{{path}}"><i class="fa fa-paragraph fa-fw"></i>&nbsp;{{../renameDirectory}}</a></li>' +
                '<li class="divider" style="width: 100%"></li>' +
                '<li class="dropdown-header">{{../subfodersOfDirectory}}&nbsp;"{{name}}"</li>' +
                '{{#if children}}' +
                '{{#each children}}' +
                '<button class="btn dirButton" data-path="{{path}}" title="{{path}}" style="margin: 1px;">' +
                '<i class="fa fa-folder-o"></i>&nbsp;{{name}}</button>' +
                '{{/each}}' +
                '{{else}}' +
                '<div>{{../../noSubfoldersFound}}</div>' +
                '{{/if}}' +
            '</ul>' +
        '</div>' +
    '</div>' +
    '{{/each}}'
  );
  var mainDirectoryNavigatorTmpl = Handlebars.compile(
    '<div>{{#each dirHistory}}' +
    '<div class="accordion-group disableTextSelection" style="width: 99%; border: 0px #aaa solid;">' +
        '<div class="accordion-heading btn-group" key="{{path}}" style="width:100%; margin: 0; ">' +
            '<button class="btn btn-link btn-lg directoryIcon" data-toggle="collapse" data-target="#dirButtons{{@index}}" key="{{path}}" title="{{../toggleDirectory}}">' +
                '<i class="fa fa-folder fa-fw"></i>' +
            '</button>' +
            '<button class="btn btn-link directoryTitle ui-droppable" key="{{path}}" title="{{path}}">{{name}}</button>' +
            '<button class="btn btn-link btn-lg directoryActions" key="{{path}}" title="{{../directoryOperations}}">' +
                '<b class="fa fa-ellipsis-v"></b>' +
            '</button>' +
        '</div>' +
        '<div class="accordion-body collapse in" id="dirButtons{{@index}}">' +
            '<div class="accordion-inner" id="dirButtonsContent{{@index}}" style="padding: 4px;">' +
                '{{#if children}}' +
                '<div>{{#each children}}' +
                    '<button class="btn btn-sm dirButton ui-droppable" key="{{path}}" title="{{path}}" style="margin: 1px;">' +
                        '<i class="fa fa-folder-o"></i>&nbsp;{{name}}</button>' +
                '{{/each}}</div>' +
                '{{else}}' +
                    '<div>{{../../noSubfoldersFound}}</div>' +
                '{{/if}}' +
            '</div>' +
        '</div>' +
    '</div>' +
    '{{/each}}</div>'
  );
  var locationChooserTmpl = Handlebars.compile(
    '<li class="dropdown-header" data-i18n="ns.common:yourLocations">{{yourLocations}} ' +
        '<button type="button" class="close">×</button>' +
    '</li>' +
    '<li class="divider" ></li>' +
    '{{#each locations}}' +
    '<li style="line-height: 45px">' +
      '<button title="{{path}}" path="{{path}}" name="{{name}}" style="width: 180px; text-align: left; border: 0;" class="btn btn-default">' +
      '{{#if isDefault}}' +
        '<i style="color: darkred" class="fa fa-bookmark" data-i18n="[title]ns.dialogs:startupLocation"></i>&nbsp;{{name}}'  +
      '{{else}}' +
        '<i class="fa fa-bookmark"></i>&nbsp;{{name}}'  +
      '{{/if}}' +
      '</button>' +
      '<button type="button" data-i18n="[title]ns.common:editLocation" title="{{editLocationTitle}}" location="{{name}}" path="{{path}}" class="btn btn-link pull-right" style="margin-right: 5px; margin-top: 5px">' +
        '<i class="fa fa-pencil fa-lg"></i>' +
      '</button>' +
    '</li>' +
    '{{/each}}'
  );

  function openLocation(path) {
    console.log('Opening location in : ' + path);
    if (TSCORE.Config.getLoadLocationMeta()) {
      loadFolderMetaData(path);
    }
    TSCORE.currentLocationObject = TSCORE.Config.getLocation(path);
    if (TSCORE.currentLocationObject !== undefined) {
      document.title = TSCORE.currentLocationObject.name + ' | ' + TSCORE.Config.DefaultSettings.appName;
      $('#locationName').text(TSCORE.currentLocationObject.name).attr('title', path);
      // Handle open default perspective for a location
      var defaultPerspective = TSCORE.currentLocationObject.perspective;
      TSCORE.PerspectiveManager.changePerspective(defaultPerspective);
      // Saving the last opened location path in the settings
      TSCORE.Config.setLastOpenedLocation(path);
      
      if ($('#defaultLocation').prop('checked') === true 
          || $('#defaultLocationEdit').prop('checked') === true) {
        console.log("set default path " + path);
        TSCORE.Config.setDefaultLocation(path);
        $('#defaultLocation').prop('checked', false);
        $('#defaultLocationEdit').prop('checked', false);
      }
      
      TSCORE.Config.saveSettings();
    }
    // Clear search query
    TSCORE.clearSearchFilter();
    // Clears the directory history
    directoryHistory = [];
    navigateToDirectory(path);
    TSCORE.showLocationsPanel();
  }

  function loadFolderMetaData(path) {
      var metadataPath;
      if (isWeb) {
        metadataPath = path + TSCORE.dirSeparator + tsMetadataFolder + TSCORE.dirSeparator + tsMetadataFile;
      } else {
        metadataPath = 'file://' + path + TSCORE.dirSeparator + tsMetadataFolder + TSCORE.dirSeparator + tsMetadataFile;
      }
      $.get(metadataPath, function(data) {
        if (data.length > 1) {
          var metadata = JSON.parse(data);
          console.log('Location Metadata: ' + JSON.stringify(metadata));
          if (metadata.tagGroups.length > 0) {
            TSCORE.locationTags = metadata.tagGroups;
            TSCORE.generateTagGroups();<commit_msg>js styling<commit_after>/* Copyright (c) 2012-2015 The TagSpaces Authors. All rights reserved.
 * Use of this source code is governed by a AGPL3 license that
 * can be found in the LICENSE file. */
/* global define, Handlebars, isCordova  */
define(function(require, exports, module) {
  'use strict';
  var homeFolderTitle = 'Home';

  console.log('Loading directories.ui.js ...');
  var TSCORE = require('tscore');
  var TSPRO = require('tspro');
  var directoryHistory = [];
  var dir4ContextMenu = null;
  var tsMetadataFolder = '.ts';
  var tsMetadataFile = 'tsm.json';
  var alternativeDirectoryNavigatorTmpl = Handlebars.compile(
    '{{#each dirHistory}}' +
    '<div class="btn-group dropup">' +
        '<button class="btn btn-link dropdown-toggle" data-menu="{{@index}}">' +
            '{{name}}&nbsp;&nbsp;<i class="fa fa-caret-right"></i>&nbsp;'  +
        '</button>' +
        '<div class="dropdown clearfix dirAltNavMenu" id="dirMenu{{@index}}">' +
            '<ul style="overflow-y: auto; max-height: 430px; width: 250px; padding: 5px; display: block;" role="menu" class="dropdown-menu">' +
                '<li class="dropdown-header"><button type="button" class="close">&times;</button>{{../actionsForDirectory}}&nbsp;"{{name}}"</li>' +
                '<li><a class="btn btn-link pull-left reloadCurrentDirectory" data-path="{{path}}"><i class="fa fa-refresh fa-fw"></i>&nbsp;{{../reloadCurrentDirectory}}</a></li>' +
                '<li class="notreadonly"><a class="btn btn-link pull-left createSubdirectory" data-path="{{path}}"><i class="fa fa-folder-o fa-fw"></i>&nbsp;{{../createSubdirectory}}</a></li>' +
                '<li class="notreadonly"><a class="btn btn-link pull-left renameDirectory" data-path="{{path}}"><i class="fa fa-paragraph fa-fw"></i>&nbsp;{{../renameDirectory}}</a></li>' +
                '<li class="divider" style="width: 100%"></li>' +
                '<li class="dropdown-header">{{../subfodersOfDirectory}}&nbsp;"{{name}}"</li>' +
                '{{#if children}}' +
                '{{#each children}}' +
                '<button class="btn dirButton" data-path="{{path}}" title="{{path}}" style="margin: 1px;">' +
                '<i class="fa fa-folder-o"></i>&nbsp;{{name}}</button>' +
                '{{/each}}' +
                '{{else}}' +
                '<div>{{../../noSubfoldersFound}}</div>' +
                '{{/if}}' +
            '</ul>' +
        '</div>' +
    '</div>' +
    '{{/each}}'
  );
  var mainDirectoryNavigatorTmpl = Handlebars.compile(
    '<div>{{#each dirHistory}}' +
    '<div class="accordion-group disableTextSelection" style="width: 99%; border: 0px #aaa solid;">' +
        '<div class="accordion-heading btn-group" key="{{path}}" style="width:100%; margin: 0; ">' +
            '<button class="btn btn-link btn-lg directoryIcon" data-toggle="collapse" data-target="#dirButtons{{@index}}" key="{{path}}" title="{{../toggleDirectory}}">' +
                '<i class="fa fa-folder fa-fw"></i>' +
            '</button>' +
            '<button class="btn btn-link directoryTitle ui-droppable" key="{{path}}" title="{{path}}">{{name}}</button>' +
            '<button class="btn btn-link btn-lg directoryActions" key="{{path}}" title="{{../directoryOperations}}">' +
                '<b class="fa fa-ellipsis-v"></b>' +
            '</button>' +
        '</div>' +
        '<div class="accordion-body collapse in" id="dirButtons{{@index}}">' +
            '<div class="accordion-inner" id="dirButtonsContent{{@index}}" style="padding: 4px;">' +
                '{{#if children}}' +
                '<div>{{#each children}}' +
                    '<button class="btn btn-sm dirButton ui-droppable" key="{{path}}" title="{{path}}" style="margin: 1px;">' +
                        '<i class="fa fa-folder-o"></i>&nbsp;{{name}}</button>' +
                '{{/each}}</div>' +
                '{{else}}' +
                    '<div>{{../../noSubfoldersFound}}</div>' +
                '{{/if}}' +
            '</div>' +
        '</div>' +
    '</div>' +
    '{{/each}}</div>'
  );
  var locationChooserTmpl = Handlebars.compile(
    '<li class="dropdown-header" data-i18n="ns.common:yourLocations">{{yourLocations}} ' +
        '<button type="button" class="close">×</button>' +
    '</li>' +
    '<li class="divider" ></li>' +
    '{{#each locations}}' +
    '<li style="line-height: 45px">' +
      '<button title="{{path}}" path="{{path}}" name="{{name}}" style="width: 180px; text-align: left; border: 0;" class="btn btn-default">' +
      '{{#if isDefault}}' +
        '<i style="color: darkred" class="fa fa-bookmark" data-i18n="[title]ns.dialogs:startupLocation"></i>&nbsp;{{name}}'  +
      '{{else}}' +
        '<i class="fa fa-bookmark"></i>&nbsp;{{name}}'  +
      '{{/if}}' +
      '</button>' +
      '<button type="button" data-i18n="[title]ns.common:editLocation" title="{{editLocationTitle}}" location="{{name}}" path="{{path}}" class="btn btn-link pull-right" style="margin-right: 5px; margin-top: 5px">' +
        '<i class="fa fa-pencil fa-lg"></i>' +
      '</button>' +
    '</li>' +
    '{{/each}}'
  );

  function openLocation(path) {
    console.log('Opening location in : ' + path);
    if (TSCORE.Config.getLoadLocationMeta()) {
      loadFolderMetaData(path);
    }
    TSCORE.currentLocationObject = TSCORE.Config.getLocation(path);
    if (TSCORE.currentLocationObject !== undefined) {
      document.title = TSCORE.currentLocationObject.name + ' | ' + TSCORE.Config.DefaultSettings.appName;
      $('#locationName').text(TSCORE.currentLocationObject.name).attr('title', path);
      // Handle open default perspective for a location
      var defaultPerspective = TSCORE.currentLocationObject.perspective;
      TSCORE.PerspectiveManager.changePerspective(defaultPerspective);
      // Saving the last opened location path in the settings
      TSCORE.Config.setLastOpenedLocation(path);
      
      if ($('#defaultLocation').prop('checked') === true || $('#defaultLocationEdit').prop('checked') === true) {
        console.log("set default path " + path);
        TSCORE.Config.setDefaultLocation(path);
        $('#defaultLocation').prop('checked', false);
        $('#defaultLocationEdit').prop('checked', false);
      }
      
      TSCORE.Config.saveSettings();
    }
    // Clear search query
    TSCORE.clearSearchFilter();
    // Clears the directory history
    directoryHistory = [];
    navigateToDirectory(path);
    TSCORE.showLocationsPanel();
  }

  function loadFolderMetaData(path) {
      var metadataPath;
      if (isWeb) {
        metadataPath = path + TSCORE.dirSeparator + tsMetadataFolder + TSCORE.dirSeparator + tsMetadataFile;
      } else {
        metadataPath = 'file://' + path + TSCORE.dirSeparator + tsMetadataFolder + TSCORE.dirSeparator + tsMetadataFile;
      }
      $.get(metadataPath, function(data) {
        if (data.length > 1) {
          var metadata = JSON.parse(data);
          console.log('Location Metadata: ' + JSON.stringify(metadata));
          if (metadata.tagGroups.length > 0) {
            TSCORE.locationTags = metadata.tagGroups;
            TSCORE.generateTagGroups();
{'fraction_non_alphanumeric': 0.203214535290007, 'fraction_numerical': 0.006429070580013976, 'mean_word_length': 2.9262002743484223, 'pattern_counts': {'":': 0, '<': 179, '<?xml version=': 0, '>': 183, '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': '5143043', 'n_tokens_mistral': 4442, 'n_tokens_neox': 4329, 'n_words': 822}