<script id="resolve_issues-container-template" type="text/x-handlebars-template">
    <div class="container">
        <div id="issue-alerts"></div>
        <div class="issue-list"></div>
    </div>
</script>

<script id="resolve_issues-issue_list-template" type="text/x-handlebars-template">
    <div class="issues"></div>
</script>

<script id="declare_machine_dead-modal-template" type="text/x-handlebars-template">
    <div class="alert alert-error">
        <h4 class="title_center">Warning</h4>
        <p>If you declare this server dead, you will not be able to reconnect it later, even if it does reconnect, it will consider itself dead and will stop working.</p>
        <p>All the data on the server will be lost.</p>
    </div>
    <div class="alert alert-error error_answer"></div>
    <p>Are you sure you want to declare <strong>{{machine_name}}</strong> dead?</p>
</script>

<script id="fail_solve_issue-template" type="text/x-handlebars-template">
    Sorry, something went wrong. The issue might not be up to date, please refresh.
</script>

<script id="resolve_vclock-modal-template" type="text/x-handlebars-template">
    <div class="alert alert-error error_answer"></div>
    <p>Are you sure you want to use the value <strong>{{final_value}}</strong>?</p>
</script>

<script id="resolve_unsatisfiable_goals_modal-template" type="text/x-handlebars-template">
    <div class="alert alert-error error_answer"></div>
    <p>Are you sure you want to lower the number of replicas for table <a class="change-route" href="#tables/{{namespace_id}}">{{namespace_name}}</a> in the following datacenters or in the whole cluster:</p>
    <ul>
        {{#each datacenters_with_issues}}
        <li>
        {{#if is_universe}}
        Whole cluster
        {{else}}
        <a class="change-route" href="#datacenters/{{this.datacenter_id}}">{{this.datacenter_name}}</a> from
        {{/if}}
            <strong>{{this.num_replicas}}</strong> to <strong>{{num_machines}}</strong>
                {{#if this.change_ack}}
                <br /><strong>Warning</strong>: The number of acks will be lowered too.
                {{/if}}
            </li>
        {{/each}}
    </ul>
</script>

<script id="resolve_issues-resolved-template" type="text/x-handlebars-template">
    <div class="alert" data-alert="alert">
        <a class="close" href="#">&times;</a>
        {{#if name_conflict}}
            <p>You successfully solved the name conflict.</p>
        {{/if}}
        {{#if machine_dead}}
            <p>You successfully declared server <span class="name">{{machine_name}}</span> dead.</p>
        {{/if}}
        {{#if vclock_conflict}}
            <p>You successfully resolved the configuration value to <span class="name">{{final_value}}</span>.</p>
        {{/if}}
        {{#if unsatisfiable_goals}}
        <p>You successfully solved {{#unless can_be_solved}}a part of{{/unless}} the unsatisfiable goals issue.</p>
        {{/if}}
    </div>
</script>

<script id="resolve_issues-machine_down-template" type="text/x-handlebars-template">
    <div class="issue {{#if critical }}critical{{/if}}">
        <div class="issue-header">
            <button class="btn btn-danger solve-issue">Declare Dead</button>
            <p class="issue-type">Server down</p>
            <p class="message">{{name}} is unreachable</p>
            <p class="datetime"><abbr class="timeago" title="{{datetime}}">{{datetime}}</abbr></p>
        </div>
        <hr />
        <div class="issue-details">
            {{#if no_responsibilities}}
                <p>This server has no master or replica responsibilities.</p>
            {{else}}
                {{#if masters}}
                <p>This server is responsible for the following shards:</p>
                <ul>
                    {{#each masters}}
                        <li>Table <a class="change-route" href="#tables/{{uuid}}">{{name}}</a> for the shard {{shard}}.</li>
                    {{/each}}
                </ul>
                {{/if}}

                {{#if replicas}}
                <p>This server is a secondary for the following shards:</p>
                <ul>
                    {{#each replicas}}
                        <li>Table <a class="change-route" href="#tables/{{uuid}}">{{name}}</a> for the shard {{shard}}.</li>
                    {{/each}}
                </ul>
                {{/if}}
            {{/if}}
        </div>
    </div>
</script>

<script id="resolve_issues-name_conflict-template" type="text/x-handlebars-template">
    <div class="issue {{#if critical }}critical{{/if}} name-conflict">
        <div class="issue-header">
            <p class="issue-type">Name conflict</p>
            <p class="message">{{name}} is used by more than one {{type}}</p>
            <p class="datetime"><abbr class="timeago" title="{{datetime}}">{{datetime}}</abbr></p>
        </div>
        <hr />
        <div class="issue-details">
            <p>{{capitalize type}} with the name {{name}}:</p>
            <ul>
                {{#each contestants}}
                <li><a class="change-route" href="#{{pluralize_noun type 2}}/{{uuid}}"><span class="uuid">{{humanize_uuid uuid}}</span></a>
                (<a id="rename_{{uuid}}" href="#{{pluralize_noun type 2}}/{{uuid}}">rename</a>)</li>
                {{/each}}
            </ul>
        </div>
    </div>
</script>

<script id="resolve_issues-logfile_write-template" type="text/x-handlebars-template">
    <div class="issue {{#if critical }}critical{{/if}} name-conflict">
        <div class="issue-header">
            <button class="btn btn-danger solve-issue">Declare Dead</button>
            <p class="issue-type">Cannot write logs</p>
            <p class="message">File cannot be written on server <a class="change-route" href="/#servers/{{machine_uuid}}">{{machine_name}}</a></p>
            <p class="datetime"><abbr class="timeago" title="{{datetime}}">{{datetime}}</abbr></p>
        </div>
        <hr />
        <div class="issue-details">
            <p>Log file is inaccessible on server <a class="change-route" href="/#servers/{{machine_uuid}}">{{machine_name}}</a>. Please resolve the issue on the server, or declare it dead.<p>
        </div>
    </div>
</script>

<script id="resolve_issues-vclock_conflict-template" type="text/x-handlebars-template">
    <div class="issue {{#if critical }}critical{{/if}} name-conflict">
        <div class="issue-header">
            <p class="issue-type">Cluster configuration conflict</p>
            <p class="datetime"><abbr class="timeago" title="{{datetime}}">{{datetime}}</abbr></p>
        </div>
        <hr />
        <div class="issue-details">
            <p>This issue is caused by making changes to the cluster configuration on both sides of an intermittent network connection.</p>
            <p>The {{field}} of {{object_type}} <a href="#{{object_type_url}}/{{object_id}}">{{#if name_contest}}{{humanize_uuid object_id}}{{else}}{{object_name}}{{/if}}</a> has the following conflicting values:</h4>
            <ul>
                {{#each contestants}}
                    <li>{{value}} (<a id="resolve_{{contestant_id}}" href="#">use this value</a>)</li>
                {{/each}}
            </ul>
        </div>
    </div>
</script>

<script id="resolve_issues-unsatisfiable_goals-template" type="text/x-handlebars-template">
    <div class="issue {{#if critical }}critical{{/if}} name-conflict">
        <div class="issue-header">
            {{#if can_solve_issue}}
            <button class="btn btn-danger solve-issue">Lower replicas</button>
            {{else}}
            <button class="btn btn-danger try-solve-issue">Manually solve</button>
            {{/if}}
            <p class="issue-type">Unsatisfiable goals</p>
            <p class="datetime"><abbr class="timeago" title="{{datetime}}">{{datetime}}</abbr></p>
        </div>
        <hr />
        <div class="issue-details">
            {{#if no_primary}}
            <p>The primary datacenter of the table <a class="change-route" href="#tables/{{namespace_id}}">{{namespace_name}}</a> was not found (probably deleted). Please <a class="change-route" href="#tables/{{namespace_id}}">choose</a> another primary datacenter.</p>
            {{else}}
                <p>The goals specified for table <a class="change-route" href="#tables/{{namespace_id}}">{{namespace_name}}</a> cannot be satisfied.</p>
                {{#if can_solve_issue}}
                <p>The number of replicas requested for these datacenters or for the whole cluster is greater than the number of servers available:</p>
                <ul>
                    {{#each datacenters_with_issues}}
                    {{#if datacenter_removed}}
                    <li>A removed datacenter (id: <a href="#datacenters/{{datacenter_id}}">{{datacenter_id_small}}</a>): {{this.num_replicas}} {{pluralize_noun "replica" this.num_replicas}} specified, {{this.num_machines}} {{pluralize_noun "server" this.num_machines}} available.</li>
                    {{else}}
                    {{#if is_universe}}
                    <li>Whole cluster: {{this.num_replicas}} {{pluralize_noun "replica" this.num_replicas}} specified, {{this.num_machines}} {{pluralize_noun "server" this.num_machines}} available.</li>
                    {{else}}
                    <li>Datacenter <a class="change-route" href="#datacenters/{{this.datacenter_id}}">{{this.datacenter_name}}</a>: {{this.num_replicas}} {{pluralize_noun "replica" this.num_replicas}} specified, {{this.num_machines}} {{pluralize_noun "server" this.num_machines}} available.</li>
                    {{/if}}
                    {{/if}}
                    {{/each}}
                </ul>
                {{/if}}

                {{#if extra_replicas_accross_cluster}}
                <p>
                {{#if can_solve_issue}}Once you will have solved the issues above, you will still require{{else}}You have required{{/if}} {{extra_replicas_accross_cluster.value}} extra {{pluralize_noun "replica" extra_replicas_accross_cluster.value}} across the cluster. You have to lower the value of replicas in one of these datacenters or in the whole cluster:</p>
                <ul>
                    {{#each extra_replicas_accross_cluster.datacenters_that_can_help}}
                    {{#if is_universe}}
                        <li>Whole cluster: {{this.num_replicas_requested}} {{pluralize_noun "replica" this.num_replicas_requested}} requested.</li>
                    {{else}}
                        <li>Datacenter <a class="change-route" href="#datacenters/{{datacenter_id}}">{{datacenter_name}}</a>: {{this.num_replicas_requested}} {{pluralize_noun "replica" this.num_replicas_requested}} requested.</li>
                    {{/if}}
                    {{/each}}
                </ul>
                {{/if}}
            {{/if}}
        </div>
    </div>
</script>

<script id="resolve_issues-machine_ghost-template" type="text/x-handlebars-template">
    <div class="issue {{#if critical }}critical{{/if}} name-conflict">
        <div class="issue-header">
            <p class="issue-type">Zombie server</p>
            <p class="datetime"><abbr class="timeago" title="{{datetime}}">{{datetime}}</abbr></p>
        </div>
        <hr />
        <div class="issue-details">
            <p>A server was declared dead, but is now connected to the cluster.</p>
            <p class="description">Server's id: <a class="change-route" href="#servers/{{machine_id}}">{{machine_id}}</a></p>
            <p>Please manually remove it (e.g. by killing the RethinkDB process on the server).</p>
        </div>
    </div>
</script>

<script id="resolve_issues-port_conflict-template" type="text/x-handlebars-template">
    <div class="issue {{#if critical }}critical{{/if}} name-conflict">
        <div class="issue-header">
            <p class="issue-type">Port conflict</p>
            <p class="message">Could not bind to port</p>
            <p class="datetime"><abbr class="timeago" title="{{datetime}}">{{datetime}}</abbr></p>
        </div>
        <hr />
        <div class="issue-details">
            <p>A necessary port is already in use on this server</p>
            <p class="description">Server <a class="change-route" href="#servers/{{machine_id}}">{{machine_name}}</a> {{description}}.</p>
            <p>Some other process is likely using this port. Kill it or instruct it to release the port in order to resolve this issue.</p>
        </div>
    </div>
</script>

<script id="resolve_issues-unknown-template" type="text/x-handlebars-template">
    <div class="issue {{#if critical }}critical{{/if}} name-conflict">
        <div class="issue-header">
            <p class="issue-type">Unknown issue</p>
            <p class="message">{{issue_type}}</p>
            <p class="datetime"><abbr class="timeago" title="{{datetime}}">{{datetime}}</abbr></p>
        </div>
        <hr />
        <div class="issue-details">
            <p>An unknown issue was sent by the server. Please contact support.</p>
            <p>Raw data: </p><pre>{{raw_data}}</pre>
        </div>
    </div>
</script>

