<commit_before>View = require './view'

Slave = require '../models/Slave'
Slaves = require '../collections/Slaves'

class SlavesView extends View

    template: require '../templates/slaves/base'
    slaveTemplate: require '../templates/slaves/slave'

    initialize: ->
        for eventName in ['sync', 'add', 'remove', 'change']
            @listenTo @collection, eventName, @render

        @listenTo @collection, 'reset', =>
            @$el.empty()

    events: =>
        _.extend super,
            'click [data-action="remove"]':       'removeSlave'
            'click [data-action="decommission"]': 'decommissionSlave'
            'click [data-action="reactivate"]':   'reactivateSlave'

    render: ->
        return if not @collection.synced and @collection.isEmpty?()
        @$el.html @template()

        active = new Slaves(
            @collection.filter (model) ->
              model.get('state') in ['ACTIVE']
        )
        decommission = new Slaves(
            @collection.filter (model) ->
              model.get('state') in ['DECOMMISSIONING', 'DECOMMISSIONED', 'STARTING_DECOMMISSION']
        )
        inactive = new Slaves(
            @collection.filter (model) ->
              model.get('state') in ['DEAD', 'MISSING_ON_STARTUP']
        )

        @$('#active').html @slaveTemplate
            data:     active.toJSON()
        @$('#decommission').html @slaveTemplate
            data:     decommission.toJSON()
        @$('#inactive').html @slaveTemplate
            data:     inactive.toJSON()

    removeSlave: (event) =>
        $target = $(event.currentTarget)<commit_msg>fix slave state enum value usage<commit_after>View = require './view'

Slave = require '../models/Slave'
Slaves = require '../collections/Slaves'

class SlavesView extends View

    template: require '../templates/slaves/base'
    slaveTemplate: require '../templates/slaves/slave'

    initialize: ->
        for eventName in ['sync', 'add', 'remove', 'change']
            @listenTo @collection, eventName, @render

        @listenTo @collection, 'reset', =>
            @$el.empty()

    events: =>
        _.extend super,
            'click [data-action="remove"]':       'removeSlave'
            'click [data-action="decommission"]': 'decommissionSlave'
            'click [data-action="reactivate"]':   'reactivateSlave'

    render: ->
        return if not @collection.synced and @collection.isEmpty?()
        @$el.html @template()

        active = new Slaves(
            @collection.filter (model) ->
              model.get('state') in ['ACTIVE']
        )
        decommission = new Slaves(
            @collection.filter (model) ->
              model.get('state') in ['DECOMISSIONING', 'DECOMISSIONED', 'STARTING_DECOMISSION']
        )
        inactive = new Slaves(
            @collection.filter (model) ->
              model.get('state') in ['DEAD', 'MISSING_ON_STARTUP']
        )

        @$('#active').html @slaveTemplate
            data:     active.toJSON()
        @$('#decommission').html @slaveTemplate
            data:     decommission.toJSON()
        @$('#inactive').html @slaveTemplate
            data:     inactive.toJSON()

    removeSlave: (event) =>
        $target = $(event.currentTarget)
{'fraction_non_alphanumeric': 0.14734895191122072, 'fraction_numerical': 0.0, 'mean_word_length': 2.162768031189084, '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': '3815172', 'n_tokens_mistral': 928, 'n_tokens_neox': 910, 'n_words': 202}