<commit_before>goog.require 'wzk.ui.grid.Grid'
goog.require 'goog.dom.dataset'

class wzk.ui.grid.PaneMode

  ###*
    @type {string}
  ###
  @SNIPPET: 'snippet-container'

  ###*
    @type {string}
  ###
  @PARAM: 'i'

  ###*
    @enum {string}
  ###
  @ATTRS:
    LINK: 'webLink'
    INDEX: 'webLinkI'

  ###*
    @enum {string}
  ###
  @DATA:
    MODE: 'mode'

  ###*
    @param {Element} table
    @return {boolean}
  ###
  @usePane: (table) ->
    mode = goog.dom.dataset.get table, wzk.ui.grid.PaneMode.DATA.MODE
    mode? and mode is 'pane'

  ###*
    @param {wzk.resource.Client} client
    @param {wzk.dom.Dom} dom
    @param {wzk.app.Processor} proc
    @param {wzk.stor.StateStorage} ss
    @param {wzk.resource.Query} query
  ###
  constructor: (@client, @dom, @proc, @ss, @query) ->

  ###*
    @param {wzk.ui.grid.Grid} grid
  ###
  watchOn: (grid) ->
    grid.listen wzk.ui.grid.Grid.EventType.SELECTED_ITEM, @handleSelected
    @loadModel()

  ###*
    @protected
    @param {goog.events.Event} e
  ###
  handleSelected: (e) =>
    @loadSnippets (`/** @type {wzk.resource.Model} */`) e.target

  ###*
    @protected
  ###
  loadModel: ->
    id = @ss.get wzk.ui.grid.PaneMode.PARAM
    if id
      @client.get @query.composeGet(id), @loadSnippets

  ###*
    @protected
    @param {wzk.resource.Model} model
  ###
  loadSnippets: (model) =>
    @ss.set wzk.ui.grid.PaneMode.PARAM, model['id']
    A = wzk.ui.grid.PaneMode.ATTRS
    for el in @dom.clss wzk.ui.grid.PaneMode.SNIPPET
      link = goog.dom.dataset.get el, A.LINK
      url = model['_web_links'][link]
      i = goog.dom.dataset.get el, A.INDEX
      if i?
        url = url[i]
      if url?
        @processSnippet url, el

  ###*
    @protected
    @param {string} url
    @param {Element} el
  ###
  processSnippet: (url, el) ->
    @client.request url + '?popup=1', 'GET', {}, (json) =>
      el.innerHTML = json['content']
      @proc.process el, @dom.getDocument(), @client.xhrFac<commit_msg>Changed PaneMode for snippets #100<commit_after>goog.require 'wzk.ui.grid.Grid'
goog.require 'goog.dom.dataset'

class wzk.ui.grid.PaneMode

  ###*
    @enum {string}
  ###
  @SNIPPET:
    CLS: 'snippet-container'
    PARAM: 'content'

  ###*
    @type {string}
  ###
  @PARAM: 'i'

  ###*
    @enum {string}
  ###
  @ATTRS:
    LINK: 'webLink'
    INDEX: 'webLinkI'

  ###*
    @enum {string}
  ###
  @DATA:
    MODE: 'mode'

  ###*
    @param {Element} table
    @return {boolean}
  ###
  @usePane: (table) ->
    mode = goog.dom.dataset.get table, wzk.ui.grid.PaneMode.DATA.MODE
    mode? and mode is 'pane'

  ###*
    @param {wzk.resource.Client} client
    @param {wzk.dom.Dom} dom
    @param {wzk.app.Processor} proc
    @param {wzk.stor.StateStorage} ss
    @param {wzk.resource.Query} query
  ###
  constructor: (@client, @dom, @proc, @ss, @query) ->

  ###*
    @param {wzk.ui.grid.Grid} grid
  ###
  watchOn: (grid) ->
    grid.listen wzk.ui.grid.Grid.EventType.SELECTED_ITEM, @handleSelected
    @loadModel()

  ###*
    @protected
    @param {goog.events.Event} e
  ###
  handleSelected: (e) =>
    @loadSnippets (`/** @type {wzk.resource.Model} */`) e.target

  ###*
    @protected
  ###
  loadModel: ->
    id = @ss.get wzk.ui.grid.PaneMode.PARAM
    if id
      @client.get @query.composeGet(id), @loadSnippets

  ###*
    @protected
    @param {wzk.resource.Model} model
  ###
  loadSnippets: (model) =>
    @ss.set wzk.ui.grid.PaneMode.PARAM, model['id']
    A = wzk.ui.grid.PaneMode.ATTRS
    for el in @dom.clss wzk.ui.grid.PaneMode.SNIPPET.CLS
      link = goog.dom.dataset.get el, A.LINK
      url = model['_web_links'][link]
      i = goog.dom.dataset.get el, A.INDEX
      if i?
        url = url[i]
      if url?
        @processSnippet url, el

  ###*
    @protected
    @param {string} url
    @param {Element} el
  ###
  processSnippet: (url, el) ->
    PARAM = wzk.ui.grid.PaneMode.SNIPPET.PARAM
    @client.request url + '?snippet=' + PARAM, 'GET', {}, (json) =>
      if json['snippets']?
        el.innerHTML = json['snippets'][PARAM]
      @proc.process el, @dom.getDocument(), @client.xhrFac
{'fraction_non_alphanumeric': 0.1833252072159922, 'fraction_numerical': 0.0009751340809361287, 'mean_word_length': 2.577157802964255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4525351', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1566, 'n_words': 307}