<commit_before>const directoryTree = require('directory-tree');

const pathIdPairs = require('./path-id-pairs/path-id-pairs');
const pathIdPairsHandlerForTreeView = require('./path-id-pairs/path-id-pairs-handler-for-tree-view');
const exifManager = require('./exif-manager');

let directoryTreeRoot;

/**
 * Update selected directory to be managed in selected-directory-manager.
 * @param {string} selectedPath 
 */
exports.update = async function(selectedPath) {
  directoryTreeRoot = directoryTree(selectedPath);
  updatePathIdPairs();
  await exifManager.update(directoryTreeRoot);
}

function updatePathIdPairs() {
  pathIdPairs.reset();
  return updatePathIdPairsRecursively([directoryTreeRoot]);
}

function updatePathIdPairsRecursively(directoryTreeElementArray) {
  directoryTreeElementArray.forEach(
    (directoryTreeElement) => {
      pathIdPairs.registerPath(directoryTreeElement.path);
      if(directoryTreeElement.hasOwnProperty("children")) {
        updatePathIdPairsRecursively(directoryTreeElement.children);
      }
    }
  )
}

/**
 * Generate data for jsTree.
 */
exports.generateDataForJsTree = function() {
  return generateDataForJsTreeRecursively([directoryTreeRoot]);
}

function generateDataForJsTreeRecursively(directoryTreeElementArray) {
  var jstreeElementArray = [];
  directoryTreeElementArray.forEach(
    (directoryTreeElement) => {
      var jstreeElement = {
        id: pathIdPairsHandlerForTreeView.getIdForTreeView(directoryTreeElement.path),
        text: directoryTreeElement.name,
        state: { disabled: isDisabled(directoryTreeElement) }
      };
      if(directoryTreeElement.hasOwnProperty("children")) {
        jstreeElement.children = generateDataForJsTreeRecursively(directoryTreeElement.children);
        const isAllChildrenDisabled = jstreeElement.children.every(child => child.state.disabled);
        jstreeElement.state.disabled = isAllChildrenDisabled;
      }
      jstreeElementArray.push(jstreeElement);
    }
  );
  return jstreeElementArray;
}

function isDisabled(directoryTreeElement) {
  const isFile = () => directoryTreeElement.type === "file";
  const gpsCoordinatesExist = exifManager.getGpsCoordinates(directoryTreeElement.path) !== null;
  return isFile() && !gpsCoordinatesExist;
}<commit_msg>Fix selected-directory-manager.js according to ESLint<commit_after>const directoryTree = require('directory-tree');
const _ = require('lodash');

const pathIdPairs = require('./path-id-pairs/path-id-pairs');
const pathIdPairsHandlerForTreeView = require('./path-id-pairs/path-id-pairs-handler-for-tree-view');
const exifManager = require('./exif-manager');

let directoryTreeRoot;

/**
 * Update selected directory to be managed in selected-directory-manager.
 * @param {string} selectedPath
 */
exports.update = async function (selectedPath) {
  directoryTreeRoot = directoryTree(selectedPath);
  updatePathIdPairs();
  await exifManager.update(directoryTreeRoot);
};

function updatePathIdPairs() {
  pathIdPairs.reset();
  return updatePathIdPairsRecursively([directoryTreeRoot]);
}

function updatePathIdPairsRecursively(directoryTreeElementArray) {
  directoryTreeElementArray.forEach(
    directoryTreeElement => {
      pathIdPairs.registerPath(directoryTreeElement.path);
      if (_.has(directoryTreeElement, 'children')) {
        updatePathIdPairsRecursively(directoryTreeElement.children);
      }
    }
  );
}

/**
 * Generate data for jsTree.
 */
exports.generateDataForJsTree = function () {
  return generateDataForJsTreeRecursively([directoryTreeRoot]);
};

function generateDataForJsTreeRecursively(directoryTreeElementArray) {
  const jstreeElementArray = [];
  directoryTreeElementArray.forEach(
    directoryTreeElement => {
      const jstreeElement = {
        id: pathIdPairsHandlerForTreeView.getIdForTreeView(directoryTreeElement.path),
        text: directoryTreeElement.name,
        state: { disabled: isDisabled(directoryTreeElement) }
      };
      if (_.has(directoryTreeElement, 'children')) {
        jstreeElement.children = generateDataForJsTreeRecursively(directoryTreeElement.children);
        const isAllChildrenDisabled = jstreeElement.children.every(child => child.state.disabled);
        jstreeElement.state.disabled = isAllChildrenDisabled;
      }
      jstreeElementArray.push(jstreeElement);
    }
  );
  return jstreeElementArray;
}

function isDisabled(directoryTreeElement) {
  const isFile = directoryTreeElement.type === 'file';
  const gpsCoordinatesExist = exifManager.getGpsCoordinates(directoryTreeElement.path) !== null;
  return isFile && !gpsCoordinatesExist;
}
{'fraction_non_alphanumeric': 0.10711952971913782, 'fraction_numerical': 0.0, 'mean_word_length': 5.1171770972037285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '6797099', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1305, 'n_words': 197}