<commit_before>import El from 'el.js'

import Events from '../events'
import m      from '../mediator'

import html from '../templates/main'

export default class Main extends El.Form
  tag: 'daisho-main'
  html: html

  configs:
    'activeOrg':    []
    'search':       []

  error: null
  orgs:  null

  init: ->
    # use the parent data as data, this is special case
    @data = @parentData

    super()

    # should have logged in by now do grab the orgs and look up active org key
    @orgs = {}
    for i, org of @data.get 'orgs'
      @orgs[i] = org.fullName

    @client.setKey @data.get('orgs')[@data.get('activeOrg')]['live-secret-key']

    # when things are updated, update to latest page
    @on 'update', =>
      current = @services.page.current.root
      if current?
        $el = $(current)
        $page = $(@root).find '#page'
        $page.children().detach()
        $page.append $el
        current.scheduleUpdate?()

    # if active org is updated, restart the app
    m.on Events.Change, (name, val)=>
      if name == 'activeOrg'
        @client.setKey @data.get('orgs')[val]['live-secret-key']
        window.location.reload()

  logout: ->
    m.trigger Events.Logout, res
    window.location.reload()

  _submit: (event) -><commit_msg>delay reload until active org is ready<commit_after>import El from 'el.js'

import Events from '../events'
import m      from '../mediator'

import html from '../templates/main'

export default class Main extends El.Form
  tag: 'daisho-main'
  html: html

  configs:
    'activeOrg':    []
    'search':       []

  error: null
  orgs:  null

  init: ->
    # use the parent data as data, this is special case
    @data = @parentData

    super()

    # should have logged in by now do grab the orgs and look up active org key
    @orgs = {}
    for i, org of @data.get 'orgs'
      @orgs[i] = org.fullName

    @client.setKey @data.get('orgs')[@data.get('activeOrg')]['live-secret-key']

    # when things are updated, update to latest page
    @on 'update', =>
      current = @services.page.current.root
      if current?
        $el = $(current)
        $page = $(@root).find '#page'
        $page.children().detach()
        $page.append $el
        current.scheduleUpdate?()

    # if active org is updated, restart the app
    m.on Events.Change, (name, val)=>
      if name == 'activeOrg'
        @client.setKey @data.get('orgs')[val]['live-secret-key']
        requestAnimationFrame ->
          window.location.reload()

  logout: ->
    m.trigger Events.Logout, res
    window.location.reload()

  _submit: (event) ->
{'fraction_non_alphanumeric': 0.13944530046224962, 'fraction_numerical': 0.0, 'mean_word_length': 2.453457446808511, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '5485981', 'n_tokens_mistral': 846, 'n_tokens_neox': 818, 'n_words': 251}