<commit_before>require "lib/setup"
Spine = require "spine"

# Helpers
Keys = require "utils/keys"

# Models
Task    = require "models/task"
List    = require "models/list"
Setting = require "models/setting"

# Controllers
Tasks     = require "controllers/tasks"
Lists     = require "controllers/lists"
ListTitle = require "controllers/lists.title"
Panel     = require "controllers/panel"
Settings  = require "controllers/settings"
Auth      = require "controllers/auth"

Cookies = require "utils/cookies"

class App extends Spine.Controller

  elements:
    '.tasks': 'tasksContainer'
    '.sidebar': 'listsContainer'
    '.tasks .title': 'listTitle'
    'header': 'panel'
    '.settings': 'settings'
    '.auth': 'auth'

  events:
    "keydown": "collapseAllOnEsc"

  constructor: ->
    super

    # Load settings
    Setting.fetch()
    if Setting.count() is 0
      Setting.create()

    # Init settings
    window.settings = new Settings
      el: @settings

    # Init Auth
    new Auth
      el: @auth

    # Init panel
    new Panel
      el: @panel

    # Init tasks
    @tasks = new Tasks( el: @tasksContainer )

    # Init lists
    @lists = new Lists( el: @listsContainer )
    new ListTitle
      el: @listTitle

    # Load translations
    $.getJSON 'i18n/' + Setting.get("language") + '.json', (dict) =>
      $.i18n.setDictionary(dict)

      # Date picker translation
      $.getScript('i18n/datepicker/' + Setting.get("language") + '.js') unless Setting.get("language").substring(0,2) is "en"

      # Puts the translations in
      $("[data-tPlaceholder]").map ->
        $(this).attr "placeholder", $.i18n._($(this).attr("data-tPlaceholder"))

      $("[data-tText]").map ->
        $(this)._t $(this).attr "data-tText"

      $("[data-tTitle]").map ->
        $(this).attr "title", $.i18n._($(this).attr("data-tTitle"))

      # Load data for localStorage
      Task.fetch()
      List.fetch()

      # Create inbox list
      if not !!List.exists("inbox")
        List.create
          id: "inbox"
          name: "Inbox"
          permanent: yes

      List.find("inbox").updateAttribute("name", $.i18n._("Inbox"))

      # Select the first list on load
      @lists.showInbox()

    # Login to sync
    token = Cookies.getItem("token")
    uid = Cookies.getItem("uid")

    if token? and uid?
      Spine.Sync.connect uid, token, ->
        Setting.trigger "login"

    Setting.bind "haveToken", (data) ->
      Spine.Sync.connect data[0], data[1], ->
        Setting.trigger "login"

  collapseAllOnEsc: (e) =>
    if e.which is Keys.ESCAPE
      focusedInputs = $ "div:focus"
      if focusedInputs.length is 0
        @tasks.collapseAll()

module.exports = App
<commit_msg>Add in Keyboard Shortcuts<commit_after>require "lib/setup"
Spine = require "spine"

# Helpers
Keys = require "utils/keys"

# Models
Task    = require "models/task"
List    = require "models/list"
Setting = require "models/setting"

# Controllers
Tasks     = require "controllers/tasks"
Lists     = require "controllers/lists"
ListTitle = require "controllers/lists.title"
Panel     = require "controllers/panel"
Settings  = require "controllers/settings"
Auth      = require "controllers/auth"

Cookies = require "utils/cookies"

class App extends Spine.Controller

  elements:
    '.tasks': 'tasksContainer'
    '.sidebar': 'listsContainer'
    '.tasks .title': 'listTitle'
    'header': 'panel'
    '.settings': 'settings'
    '.auth': 'auth'

  events:
    "keyup": "handleShortcut"

  constructor: ->
    super

    # Load settings
    Setting.fetch()
    if Setting.count() is 0
      Setting.create()

    # Init settings
    window.settings = new Settings
      el: @settings

    # Init Auth
    new Auth
      el: @auth

    # Init panel
    new Panel
      el: @panel

    # Init tasks
    @tasks = new Tasks( el: @tasksContainer )

    # Init lists
    @lists = new Lists( el: @listsContainer )
    new ListTitle
      el: @listTitle

    # Load translations
    $.getJSON 'i18n/' + Setting.get("language") + '.json', (dict) =>
      $.i18n.setDictionary(dict)

      # Date picker translation
      $.getScript('i18n/datepicker/' + Setting.get("language") + '.js') unless Setting.get("language").substring(0,2) is "en"

      # Puts the translations in
      $("[data-tPlaceholder]").map ->
        $(this).attr "placeholder", $.i18n._($(this).attr("data-tPlaceholder"))

      $("[data-tText]").map ->
        $(this)._t $(this).attr "data-tText"

      $("[data-tTitle]").map ->
        $(this).attr "title", $.i18n._($(this).attr("data-tTitle"))

      # Load data for localStorage
      Task.fetch()
      List.fetch()

      # Create inbox list
      if not !!List.exists("inbox")
        List.create
          id: "inbox"
          name: "Inbox"
          permanent: yes

      List.find("inbox").updateAttribute("name", $.i18n._("Inbox"))

      # Select the first list on load
      @lists.showInbox()

    # Login to sync
    token = Cookies.getItem("token")
    uid = Cookies.getItem("uid")

    if token? and uid?
      Spine.Sync.connect uid, token, ->
        Setting.trigger "login"

    Setting.bind "haveToken", (data) ->
      Spine.Sync.connect data[0], data[1], ->
        Setting.trigger "login"

  handleShortcut: (e) =>
    focusedInputs = $ ":focus"

    # Collapses or Blurs
    if e.which is Keys.ESCAPE
      if focusedInputs.length is 0
        @tasks.collapseAll()
      else
        focusedInputs.blur()
    else
      # Handles keyboard shortcuts
      if focusedInputs.length is 0

        # New Task
        if e.which is 78
          $(".new-task").focus().val("")

        # New List
        else if e.which is 76
          $(".new-list").focus().val("")

        # Search
        else if e.which is 70
          $(".search input").focus().val("")

        # Print
        else if e.which is 80
          $(".buttons .print").trigger("click")

        # Settings
        else if e.which is 188
          $(".user").trigger("click")

        # Go to the prev list
        else if e.which is 75
          if $(".sidebar .current").prev().length is 0
            # Go to completed
            $(".sidebar .completed").trigger("click")
          else
            $(".sidebar .current").prev().trigger("click")
            # Cancel the Focus if shortcut is used
            $(".new-task").blur()

        # Go to the next list
        else if e.which is 74
          if $(".sidebar .current").next().hasClass("lists")
            # Go to first list
            $($(".sidebar .lists").children()[0]).trigger("click")
            $(".new-task").blur()
          else
            $(".sidebar .current").next().trigger("click")
            $(".new-task").blur()


module.exports = App

{'fraction_non_alphanumeric': 0.14817018744421304, 'fraction_numerical': 0.008033323415650105, 'mean_word_length': 2.269941634241245, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 21, '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': '299094', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2030, 'n_words': 529}