<commit_before># out: ../lib/controller.datafluxes.js
Dataflux = require "./dataflux"
log = require "./logFactory"
conf = require "./confFactory"
path = require "./path-helper"


module.exports =
class DatafluxesController
  constructor: ->
    @objects = []
    @path = path
    @log = log.makeLog()
    @conf = conf.makeConf()
    @conf.load "settings"
    @conf.load "datafluxes"
    @selectedObjectIndex = null
    @selectedObject = null

  loadObjects: ->
    @conf.load "datafluxes"
    for df, index in @conf.datafluxes
      dataflux = new Dataflux(df.srcFolder, df.dataFluxFolder, df.options)
      dataflux.name = df.name
      dataflux.walk()
      dataflux.watch()
      if df.autoCommit
        dataflux.autoFlush()
      @objects.push dataflux
      if df.selected
        @selectedObjectIndex = index
        @selectedObject = df

  addDataflux: (srcFolder, fluxFolder) ->
    if srcFolder is undefined
      @log.error "No source folder is specified!"
      throw new Error "No src folder is specified"
    else if @checkFolder srcFolder
      if fluxFolder is undefined
        fluxFolder = @path.join srcFolder, @conf.settings.datafluxDefaultDir.value
      new_df = new Dataflux(srcFolder, fluxFolder)
      new_df.name = srcFolder
      @objects.push(new_df)

  checkFolder: (folderPath) ->
    for df in @objects
      if df.srcFolder is folderPath
        @log.error "#{folderPath} already added to the controller."
        return false
      else if @path.isSubfolder df.srcFolder, folderPath
        @log.error "#{folderPath} is a subfolder of an existing dataflux folder."
        return false
      else if @path.isSubfolder folderPath, df.srcFolder
        @log.error "The subfolder #{df.srcFolder} is already a dataflux!"
        return false
    return true

  removeDataflux: (index) ->
    @objects.splice index, 1

  write: ->
    @conf.datafluxes = @getObjects()
    @conf.write "datafluxes"
<commit_msg>#17 walk and watch method added, when add folder<commit_after># out: ../lib/controller.datafluxes.js
Dataflux = require "./dataflux"
log = require "./logFactory"
conf = require "./confFactory"
path = require "./path-helper"


module.exports =
class DatafluxesController
  constructor: ->
    @objects = []
    @path = path
    @log = log.makeLog()
    @conf = conf.makeConf()
    @conf.load "settings"
    @conf.load "datafluxes"
    @selectedObjectIndex = null
    @selectedObject = null

  loadObjects: ->
    @conf.load "datafluxes"
    for df, index in @conf.datafluxes
      dataflux = new Dataflux(df.srcFolder, df.dataFluxFolder, df.options)
      dataflux.name = df.name
      dataflux.walk()
      dataflux.watch()
      if df.autoCommit
        dataflux.autoFlush()
      @objects.push dataflux
      if df.selected
        @selectedObjectIndex = index
        @selectedObject = df

  addDataflux: (srcFolder, fluxFolder) ->
    if srcFolder is undefined
      @log.error "No source folder is specified!"
      throw new Error "No src folder is specified"
    else if @checkFolder srcFolder
      if fluxFolder is undefined
        fluxFolder = @path.join srcFolder, @conf.settings.datafluxDefaultDir.value
      new_df = new Dataflux(srcFolder, fluxFolder)
      new_df.name = srcFolder
      new_df.walk()
      new_df.watch()
      @objects.push(new_df)

  checkFolder: (folderPath) ->
    for df in @objects
      if df.srcFolder is folderPath
        @log.error "#{folderPath} already added to the controller."
        return false
      else if @path.isSubfolder df.srcFolder, folderPath
        @log.error "#{folderPath} is a subfolder of an existing dataflux folder."
        return false
      else if @path.isSubfolder folderPath, df.srcFolder
        @log.error "The subfolder #{df.srcFolder} is already a dataflux!"
        return false
    return true

  removeDataflux: (index) ->
    @objects.splice index, 1

  write: ->
    @conf.datafluxes = @getObjects()
    @conf.write "datafluxes"

{'fraction_non_alphanumeric': 0.10126582278481013, 'fraction_numerical': 0.0010126582278481013, 'mean_word_length': 2.752136752136752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '906631', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1174, 'n_words': 340}