<commit_before># Helper stuff
Handlebars.registerPartial 'shard_name', $('#shard_name-partial').html()

# Namespace view
module 'NamespaceView', ->
    # Hardcoded!
    MAX_SHARD_COUNT = 32

    # All of our rendering code needs a view of available shards
    compute_renderable_shards_array = (namespace_uuid, shards) ->
        ret = []
        for i in [0...shards.length]
            primary_uuid = DataUtils.get_shard_primary_uuid namespace_uuid, shards[i]
            secondary_uuids = DataUtils.get_shard_secondary_uuids namespace_uuid, shards[i]
            ret.push
                name: human_readable_shard shards[i]
                shard: shards[i]
                shard_stats:
                    rows_approx: namespaces.get(namespace_uuid).compute_shard_rows_approximation(shards[i])
                notlast: i != shards.length - 1
                index: i
                primary:
                    uuid: primary_uuid
                    # primary_uuid may be null when a new shard hasn't hit the server yet
                    name: if primary_uuid then machines.get(primary_uuid).get('name') else null
                    status: if primary_uuid then DataUtils.get_machine_reachability(primary_uuid) else null
                    backfill_progress: if primary_uuid then DataUtils.get_backfill_progress(namespace_uuid, shards[i], primary_uuid) else null
                secondaries: _.map(secondary_uuids, (machine_uuids, datacenter_uuid) ->
                    datacenter_uuid: datacenter_uuid
                    datacenter_name: datacenters.get(datacenter_uuid).get('name')
                    machines: _.map(machine_uuids, (machine_uuid) ->
                        uuid: machine_uuid
                        name: machines.get(machine_uuid).get('name')
                        status: DataUtils.get_machine_reachability(machine_uuid)
                        backfill_progress: DataUtils.get_backfill_progress(namespace_uuid, shards[i], machine_uuid)
                        )
                    )
        return ret


    # Shards view
    # The sharding view consists of several lists. Here's the hierarchy:
    #   @Sharding
    #   |-- @Shard
    #   |   `-- @ShardDatacenterList: primary and secondary replicas organized by datacenter
    #   |       `-- @ShardDatacenter
    #   |           `-- @ShardMachineList: machines with primary and secondary replicas
    #   |               `-- @ShardMachine
    class @Sharding extends UIComponents.AbstractList
        className: 'namespace-shards'
        template: Handlebars.compile $('#namespace_view-sharding-template').html()

        events: ->
            'click .change-sharding-scheme': 'change_sharding_scheme'
        has_unsatisfiable_goals: false

        initialize: ->
            super @model.get('computed_shards'), NamespaceView.Shard, 'table.shards tbody',
                element_args:
                    namespace: @model

            @check_has_unsatisfiable_goals()
            issues.on 'all', @check_has_unsatisfiable_goals

        check_has_unsatisfiable_goals: =>
            if @has_unsatisfiable_goals is true
                found_unsatisfiable_goals = false
                for issue in issues.models
                    if issue.get('type') is 'UNSATISFIABLE_GOALS' and issue.get('namespace_id') is @model.get('id')
                        found_unsatisfiable_goals = true
                if found_unsatisfiable_goals is false
                    @has_unsatisfiable_goals = false
                    @.$('.blackout').toggleClass('blackout-active')
                    @.$el.toggleClass('namespace-shards-blackout')
            else
                for issue in issues.models
                    if issue.get('type') is 'UNSATISFIABLE_GOALS' and issue.get('namespace_id') is @model.get('id')
                        @has_unsatisfiable_goals = true
                        @.$('.blackout').toggleClass('blackout-active')
                        @.$el.toggleClass('namespace-shards-blackout')

        change_sharding_scheme: (event) =>
            event.preventDefault()
            @.$('.sharding').hide()
            view = new NamespaceView.ModifyShards @model.get('id')
            @.$('.change-shards').html view.render().el

    class @Shard extends Backbone.View
        tagName: 'tr'
        template: Handlebars.compile $('#namespace_view-shard-template').html()
        summary_template: Handlebars.compile $('#namespace_view-shard-summary-template').html()

        initialize: ->
            @namespace = @options.args.namespace

            @datacenter_list = new NamespaceView.ShardDatacenterList datacenters, NamespaceView.ShardDatacenter, 'div.datacenters',
                filter: (datacenter) =>
                    return true
                ###
                filter: (datacenter) =>
                    for datacenter_uuid of @model.get('secondary_uuids')
                        return true if datacenter.get('id') is datacenter_uuid
                    if @model.get('primary_uuid')
                        return true if datacenter.get('id') is machines.get(@model.get('primary_uuid')).get('datacenter_uuid')<commit_msg>Fix bug when a namespace-view is render a second time (for the blackout)<commit_after># Helper stuff
Handlebars.registerPartial 'shard_name', $('#shard_name-partial').html()

# Namespace view
module 'NamespaceView', ->
    # Hardcoded!
    MAX_SHARD_COUNT = 32

    # All of our rendering code needs a view of available shards
    compute_renderable_shards_array = (namespace_uuid, shards) ->
        ret = []
        for i in [0...shards.length]
            primary_uuid = DataUtils.get_shard_primary_uuid namespace_uuid, shards[i]
            secondary_uuids = DataUtils.get_shard_secondary_uuids namespace_uuid, shards[i]
            ret.push
                name: human_readable_shard shards[i]
                shard: shards[i]
                shard_stats:
                    rows_approx: namespaces.get(namespace_uuid).compute_shard_rows_approximation(shards[i])
                notlast: i != shards.length - 1
                index: i
                primary:
                    uuid: primary_uuid
                    # primary_uuid may be null when a new shard hasn't hit the server yet
                    name: if primary_uuid then machines.get(primary_uuid).get('name') else null
                    status: if primary_uuid then DataUtils.get_machine_reachability(primary_uuid) else null
                    backfill_progress: if primary_uuid then DataUtils.get_backfill_progress(namespace_uuid, shards[i], primary_uuid) else null
                secondaries: _.map(secondary_uuids, (machine_uuids, datacenter_uuid) ->
                    datacenter_uuid: datacenter_uuid
                    datacenter_name: datacenters.get(datacenter_uuid).get('name')
                    machines: _.map(machine_uuids, (machine_uuid) ->
                        uuid: machine_uuid
                        name: machines.get(machine_uuid).get('name')
                        status: DataUtils.get_machine_reachability(machine_uuid)
                        backfill_progress: DataUtils.get_backfill_progress(namespace_uuid, shards[i], machine_uuid)
                        )
                    )
        return ret


    # Shards view
    # The sharding view consists of several lists. Here's the hierarchy:
    #   @Sharding
    #   |-- @Shard
    #   |   `-- @ShardDatacenterList: primary and secondary replicas organized by datacenter
    #   |       `-- @ShardDatacenter
    #   |           `-- @ShardMachineList: machines with primary and secondary replicas
    #   |               `-- @ShardMachine
    class @Sharding extends UIComponents.AbstractList
        className: 'namespace-shards'
        template: Handlebars.compile $('#namespace_view-sharding-template').html()

        events: ->
            'click .change-sharding-scheme': 'change_sharding_scheme'
        has_unsatisfiable_goals: false

        initialize: ->
            super @model.get('computed_shards'), NamespaceView.Shard, 'table.shards tbody',
                element_args:
                    namespace: @model
            @render()

            @check_has_unsatisfiable_goals()
            issues.on 'all', @check_has_unsatisfiable_goals

        check_has_unsatisfiable_goals: =>
            if @has_unsatisfiable_goals is true
                found_unsatisfiable_goals = false
                for issue in issues.models
                    if issue.get('type') is 'UNSATISFIABLE_GOALS' and issue.get('namespace_id') is @model.get('id')
                        found_unsatisfiable_goals = true
                if found_unsatisfiable_goals is false
                    @has_unsatisfiable_goals = false
                    @.$el.toggleClass('namespace-shards-blackout')
                    @.$('.blackout').toggleClass('blackout-active')
            else
                for issue in issues.models
                    if issue.get('type') is 'UNSATISFIABLE_GOALS' and issue.get('namespace_id') is @model.get('id')
                        @has_unsatisfiable_goals = true
                        @.$el.toggleClass('namespace-shards-blackout')
                        @.$('.blackout').toggleClass('blackout-active')
            
        render: =>
            super()

            if @has_unsatisfiable_goals is true
                @.$('.blackout').addClass('blackout-active')
            else
                @.$('.blackout').removeClass('blackout-active')
            return @

        change_sharding_scheme: (event) =>
            event.preventDefault()
            @.$('.sharding').hide()
            view = new NamespaceView.ModifyShards @model.get('id')
            @.$('.change-shards').html view.render().el

    class @Shard extends Backbone.View
        tagName: 'tr'
        template: Handlebars.compile $('#namespace_view-shard-template').html()
        summary_template: Handlebars.compile $('#namespace_view-shard-summary-template').html()

        initialize: ->
            @namespace = @options.args.namespace

            @datacenter_list = new NamespaceView.ShardDatacenterList datacenters, NamespaceView.ShardDatacenter, 'div.datacenters',
                filter: (datacenter) =>
                    return true
                ###
                filter: (datacenter) =>
                    for datacenter_uuid of @model.get('secondary_uuids')
                        return true if datacenter.get('id') is datacenter_uuid
                    if @model.get('primary_uuid')
                        return true if datacenter.get('id') is machines.get(@model.get('primary_uuid')).get('datacenter_uuid')
{'fraction_non_alphanumeric': 0.0947506808151, 'fraction_numerical': 0.000751244248286224, 'mean_word_length': 1.952592181868589, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '7140160', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2800, 'n_words': 576}