<commit_before>kd                    = require 'kd'
KDListView            = kd.ListView
KDModalView           = kd.ModalView
KDOverlayView         = kd.OverlayView

hljs                  = require 'highlight.js'
showError             = require 'app/util/showError'

StackTemplateListItem = require './stacktemplatelistitem'


module.exports = class StackTemplateList extends KDListView

  constructor: (options = {}, data) ->

    options.cssClass   = kd.utils.curry 'stack-template-list', options.cssClass
    options.itemClass ?= StackTemplateListItem

    super options, data


  # TODO Check if the template is in use and warn user about that! ~ GG
  deleteItem: (item) ->

    stack = item.getData()

    # Since KDModalView.confirm not passing overlay options
    # to the base class (KDModalView) I had to do this hack
    # Remove this when issue fixed in Framework ~ GG
    overlay = new KDOverlayView cssClass: 'second-overlay'

    modal   = KDModalView.confirm
      title       : 'Remove stack'
      description : 'Do you want to remove ?'
      ok          :
        title     : 'Yes'
        callback  :  => stack.delete (err) =>
          modal.destroy()
          @emit 'ItemDeleted', item  unless showError err

    modal.once   'KDObjectWillBeDestroyed', overlay.bound 'destroy'
    overlay.once 'click',                   modal.bound   'destroy'

    return modal


  showItemContent: (item) ->

    stackTemplate = item.getData()
    content = JSON.stringify stackTemplate, null, 2
    cred = hljs.highlight('json', content).value

    new KDModalView
      title          : stackTemplate.title
      subtitle       : stackTemplate.modifiedAt
      cssClass       : 'has-markdown content-modal'
      height         : 500
      overlay        : yes
      overlayOptions : cssClass : 'second-overlay'
      content        : "<pre><code>#{cred}</code></pre>"<commit_msg>Show stack template content modal in template list<commit_after>kd                    = require 'kd'
KDListView            = kd.ListView
KDModalView           = kd.ModalView
KDOverlayView         = kd.OverlayView

hljs                  = require 'highlight.js'
showError             = require 'app/util/showError'

StackTemplateListItem = require './stacktemplatelistitem'
StackTemplateContentModal = require './stacktemplatecontentmodal'


module.exports = class StackTemplateList extends KDListView

  constructor: (options = {}, data) ->

    options.cssClass   = kd.utils.curry 'stack-template-list', options.cssClass
    options.itemClass ?= StackTemplateListItem

    super options, data


  # TODO Check if the template is in use and warn user about that! ~ GG
  deleteItem: (item) ->

    stack = item.getData()

    # Since KDModalView.confirm not passing overlay options
    # to the base class (KDModalView) I had to do this hack
    # Remove this when issue fixed in Framework ~ GG
    overlay = new KDOverlayView cssClass: 'second-overlay'

    modal   = KDModalView.confirm
      title       : 'Remove stack'
      description : 'Do you want to remove ?'
      ok          :
        title     : 'Yes'
        callback  :  => stack.delete (err) =>
          modal.destroy()
          @emit 'ItemDeleted', item  unless showError err

    modal.once   'KDObjectWillBeDestroyed', overlay.bound 'destroy'
    overlay.once 'click',                   modal.bound   'destroy'

    return modal


  showItemContent: (item) ->

    new StackTemplateContentModal {}, item.getData()
{'fraction_non_alphanumeric': 0.08721934369602763, 'fraction_numerical': 0.0011514104778353484, 'mean_word_length': 2.351012536162006, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '7478613', 'n_tokens_mistral': 998, 'n_tokens_neox': 926, 'n_words': 278}