
{% extends "base.html" %}
{% block pagename %}firestarter{% endblock %}
{% block title %}Запустить стрельбу{% endblock %}
{% load lookup %}
{% load join %}

{% block body %}


<div class="header-bottom-padding"></div>
<div class="container-fluid" style="padding-bottom: 15px;">
	{% block waiter %}
	<div class="waiter_body alert alert-warning" id="waiter_body" style="display: none;">
		<span>Ждём запуска онлайн-стрельбы с танка <span id="tank" style="font-weight: bold;"></span>:<span id="port" style="font-weight: bold;"></span></span>
		<br>
		<label style="font-weight: bold;">Статус:&emsp;</label><span id="status" data-status=""></span>
		<span style="margin-left: 0.4em;"><i class="krutilka fa fa-circle-o-notch fa-spin" aria-hidden="true"></i></span>
		<span style="" id="link" data-link=""></span>
	</div>
	{% endblock %}

	{% block error %}
		{% if error %}
            <div class="error_block alert alert-danger" id="error_block" role="alert">
                <span id="error_text">{{ error }}</span>
                <span id="ammo_suggestion" class="firestarter-suggest__ammo link-dotted clickable"></span>
            </div>
            {% if error_link %}
			    <a target="_blank" href="{{ error_link }}">{{ error_link }}</a>
		    {% endif %}
		{% else %}
            <div class="error_block alert alert-danger" id="error_block" style="display: none" role="alert">
                <span id="error_text"></span>
                <span id="ammo_suggestion" class="firestarter-suggest__ammo link-dotted clickable"></span>
            </div>
		{% endif %}
	{% endblock %}

	<div class="input-group firestarter-input">
		<span class="input-group-addon firestarter-input__title">Танк</span>
	    <form class="form-control" id="tank_type_select">
			<input class="firestarter-tank_type" data-type="tank" type="radio" name="tank" value='common'/>
			<span class="tank_label firestarter-input__title">Общественный</span>
			<input class="firestarter-tank_type" data-type="tank" type="radio" name="tank" value='host'/>
			<span class="tank_label firestarter-input__title">Хост</span>
			<input class="firestarter-tank_type" data-type="tank" type="radio" name="tank" value='nanny'/>
			<span class="tank_label firestarter-input__title">Nanny</span>
			<input class="firestarter-tank_type" data-type="tank" type="radio" name="tank" value='sandbox'/>
			<span class="tank_label firestarter-input__title">Sandbox</span>
		</form>
	</div>

	<div class="form-control tank_help_message">
		<span id="tank_help_message">
			{{ help_message }}
		</span>
    </div>

<div class="input-group firestarter-input tank_params tank_value" style="display:none;">
	    <span class="input-group-addon firestarter-input__title" >Адрес</span>
		<input class="form-control firestarter-input__tank" placeholder="Танк" data-type="use_tank" size=50 value="{{ conf|lookup:'metaconf'|lookup:'firestarter'|lookup:'tank' }}" name="tank_input"/>
		{% if recent_user_tanks %}
		<span class="input-group-addon firestarter-suggest__container">
			Недавние:
			{% for tank in recent_user_tanks %}
				<span class="firestarter-suggest firestarter-suggest__tank link-dotted clickable">{{ tank }}</span>
			{% endfor %}
		</span>
		{% endif %}
	</div>

	<div class="input-group firestarter-input tank_params sandbox_params" style="display:none;">
		<span class="input-group-addon firestarter-input__title" >Владелец задачи</span>
		<input class="form-control firestarter-input__owner" placeholder="Владелец sandbox задачи" data-type="owner" size=50 value="{{ conf|lookup:'metaconf'|lookup:'firestarter'|lookup:'owner' }}" name="owner"/>
		<span class="input-group-addon firestarter-input__title" >Секрет</span>
		<input class="form-control firestarter-input__secret" placeholder="Секрет из секретницы" data-type="secret" size=50 value="{{ conf|lookup:'metaconf'|lookup:'firestarter'|lookup:'secret' }}" name="secret"/>
		<span class="input-group-addon firestarter-input__title" >Ключ</span>
		<input class="form-control firestarter-input__key" placeholder="Ключ с oauth токеном для sandbox" data-type="key" size=50 value="{{ conf|lookup:'metaconf'|lookup:'firestarter'|lookup:'key' }}" name="key"/>
	</div>

	<div class="input-group firestarter-input">
		<span class="input-group-addon firestarter-input__title" >Мишень *</span>
		<input class="form-control firestarter-input__target" placeholder="Мишень" data-type="address" size=50 value="{{ conf|lookup:'phantom'|lookup:'address' }}" name="target_input"/>
		{% if recent_user_targets %}
		<span class="input-group-addon firestarter-suggest__container">
			Недавние:
			{% for target in recent_user_targets %}
				<span class="firestarter-suggest firestarter-suggest__target link-dotted clickable">{{ target }}</span>
			{% endfor %}
		</span>
		{% endif %}
	</div>

	<div class="input-group firestarter-input">
		<span class="input-group-addon firestarter-input__title" >Задача (task) *</span>
		<input class="form-control firestarter-input__task" placeholder="Задача (таск)" data-type="task" size=50 value="{{ conf|lookup:'uploader'|lookup:'task' }}" name="task_input"/>
		{% if recent_user_tasks %}
		<span class="input-group-addon firestarter-suggest__container">
			Недавние:
			{% for task in recent_user_tasks %}
				<span class="firestarter-suggest firestarter-suggest__task link-dotted clickable">{{ task }}</span>
			{% endfor %}
		</span>
		{% endif %}
	</div>
	<div class="input-group firestarter-input">
		<span class="input-group-addon firestarter-input__title" >Схема нагрузки *</span>
		{% if conf|lookup:'phantom'|lookup:'load_profile'|lookup:'load_type' == 'instances' %}
			<input class="form-control firestarter-input__loadscheme" data-type="instances_schedule" placeholder="Схема нагрузки" size=50 value="{{ conf|lookup:'phantom'|lookup:'load_profile'|lookup:'schedule' }}" name="loadscheme_input"/>
		{% else %}
			<input class="form-control firestarter-input__loadscheme" data-type="rps_schedule" placeholder="Схема нагрузки" size=50 value="{{ conf|lookup:'phantom'|lookup:'load_profile'|lookup:'schedule' }}" name="loadscheme_input"/>
		{% endif %}
		<span class="input-group-addon firestarter-suggest__container">
			Например:
			<span class="firestarter-suggest firestarter-suggest__loadscheme link-dotted clickable">line(1,10,30s)</span>
			<span class="firestarter-suggest firestarter-suggest__loadscheme link-dotted clickable">const(10,10m)</span>
			<span class="firestarter-suggest firestarter-suggest__loadscheme link-dotted clickable">step(10, 20, 5, 10s)</span>
		</span>
	</div>
	<div class="input-group firestarter-input">
		<span class="input-group-addon firestarter-input__title" >URI</span>
		<input class="form-control" placeholder="URI (через пробел)" data-type="uris" value="{{ conf|lookup:'phantom'|lookup:'uris'|join:'\t' }}" id="uris_input" name="uris_input"/>
	</div>
	<div class="row">
		<div class="col-md-10">
			<div class="input-group firestarter-input">
				<span class="input-group-addon firestarter-input__title" id="input-group-addon__ammo">Патроны&emsp;<i style="display: none; margin-top:-1px" class="krutilka fa fa-circle-o-notch fa-spin" aria-hidden="true"></i></span>
				<select class="form-control firestarter-input__ammo selectpicker" style="margin-left: 0px;" data-type="ammofile" data-live-search="true" data-style="btn-secondary" id="ammo_select" size="1" name="ammo_select">
					<option value="">--</option>
					{% if ammofiles %}
						<option value="" disabled='disabled' style="font-weight: bold;">Мои патроны</option>
					{% endif %}
					{% for ammo in ammofiles %}
						{% if ammo.path == conf|lookup:'phantom'|lookup:'ammofile' %}
							<option selected value="{{ ammo.path }}">{{ ammo.dsc }}</option>
						{% else %}
							<option value="{{ ammo.path }}">{{ ammo.dsc }}</option>
						{% endif %}
					{% endfor %}
				</select>
			</div>
		</div>
		<div class="col-md-2" style="float: right; padding-left: 0;">
	    	<button class="btn btn-secondary firestarter-input" id="upload_ammo_button" type="button" data-toggle="collapse" data-target="#ammoUploadForm" aria-expanded="false" aria-controls="ammoUploadForm">Залить файл <span class="caret"></span></button>
		</div>
	</div>

	{% include "ammo_upload_form.html" %}

    <div class="row">
		<div class="col-md-10">
			<div class="input-group firestarter-input">
				<span class="input-group-addon firestarter-input__title" id="input-group-addon__pandora_binary">Пушка (pandora)&emsp;<i style="display: none; margin-top:-1px" class="krutilka fa fa-circle-o-notch fa-spin" aria-hidden="true"></i></span>
				<select class="form-control firestarter-input__pandora_binary selectpicker" style="margin-left: 0px;" data-type="pandora_binary" data-live-search="true" data-style="btn-secondary" id="pandora_binary_select" size="1" name="pandora_binary_select">
					<option value="">--</option>
					{% if pandora_binaries %}
						<option value="" disabled='disabled' style="font-weight: bold;">Мои пушки</option>
					{% endif %}
					{% for pandora_binary in pandora_binaries %}
						{% if pandora_binary.path == conf|lookup:'pandora'|lookup:'pandora_cmd' %}
							<option selected value="{{ pandora_binary.path }}">{{ pandora_binary.dsc }}</option>
						{% else %}
							<option value="{{ pandora_binary.path }}">{{ pandora_binary.dsc }}</option>
						{% endif %}
					{% endfor %}
				</select>
			</div>
		</div>
		<div class="col-md-2" style="float: right; padding-left: 0;">
	    	<button class="btn btn-secondary firestarter-input" id="upload_pandora_binary_button" type="button" data-toggle="collapse" data-target="#pandoraBinaryUploadForm" aria-expanded="false" aria-controls="pandoraBinaryUploadForm">Залить файл <span class="caret"></span></button>
		</div>
	</div>

	{% include "pandora_binary_upload_form.html" %}

	<div class="input-group firestarter-input">
		<span class="input-group-addon firestarter-input__title" >Имя стрельбы</span>
		<input class="form-control firestarter-input" placeholder="Имя стрельбы" data-type="job_name" size=120 maxlength=120 value="{{ conf|lookup:'uploader'|lookup:'job_name' }}" id="job_name_input" name="job_name_input"/>
	</div>
	<div class="input-group firestarter-input">
		<span class="input-group-addon firestarter-input__title" >Описание</span>
		<input class="form-control" placeholder="Описание стрельбы" data-type="job_dsc" size=120 maxlength=120 value="{{ conf|lookup:'uploader'|lookup:'job_dsc' }}" id="job_dsc_input" name="job_dsc_input"/>
	</div>
	<div class="input-group firestarter-input">
		<span class="input-group-addon firestarter-input__title" >Версия</span>
		<input class="form-control" placeholder="Версия" data-type="ver" size=120 maxlength=120 value="{{ conf|lookup:'uploader'|lookup:'ver' }}" id="job_ver_input" name="job_ver_input"/>
	</div>

<br style="font-size: 6pt;">
<button class="btn btn-brand" name="firestarter-submit" id="firestarter-submit">Огонь!</button>
<a style="margin-left: 0.4em;" target="_blank" class="b_link" href="https://wiki.yandex-team.ru/nagruzochnoetestirovanie/lunapark/Firestarter">Как стрелять?</a>
<a style="margin-left: 0.4em;" target="_blank" class="b_link" href="http://clubs.at.yandex-team.ru/tanks/702">Обратная связь</a>
<br>
<br style="font-size: 18pt;">
<div id="editorYaml" style="margin-bottom: 15px;" class="ace_editor ace-github firestarter-editor" ui-ace="{ useWrapMode : true, showGutter: true, onLoad: ace_loaded, onChange: ace_changed }">
{{ conf_yaml }}
</div>
<span>Мониторинг</span>
<div id="editorXML" style="margin-bottom: 15px;" class="ace_editor ace-github firestarter-editor" ui-ace="{ useWrapMode : true, showGutter: true, onLoad: ace_loaded, onChange: ace_changed }">
{{ monitoring_conf }}
</div>
</div>

<!--ace version is 1.1.3 https://cdnjs.com/libraries/ace/1.1.3-->
<script nonce='{{ common.CSP_SCRIPT_NONCE }}' src="/media/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script nonce='{{ common.CSP_SCRIPT_NONCE }}'>
    var editorYaml = ace.edit("editorYaml");
    document.getElementById('editorYaml').style.fontSize='10pt';
    editorYaml.getSession().setMode("ace/mode/yaml");
    editorYaml.setTheme("ace/theme/tomorrow_night");
    editorYaml.setShowPrintMargin(false);
    editorYaml.commands.addCommand({
    	  name: 'submit_form.',
    	  bindKey: {win: 'Ctrl-Enter', mac: 'Command-Enter'},
    	  exec: function(editorYaml) {
    		  	$("#firestarter-submit").click()
    		  }
    	  });
    editorYaml.setOptions({
	    maxLines: Infinity
	});
    var monitroing_editor_container = document.getElementById('editorXML');
    if (monitroing_editor_container) {
        var editorXML = ace.edit("editorXML");
        document.getElementById('editorXML').style.fontSize='10pt';
        editorXML.getSession().setMode("ace/mode/xml");
        editorXML.setTheme("ace/theme/tomorrow_night");
        editorXML.setShowPrintMargin(false);
        editorXML.commands.addCommand({
              name: 'submit_form.',
              bindKey: {win: 'Ctrl-Enter', mac: 'Command-Enter'},
              exec: function(editorXML) {
                    $("#firestarter-submit").click()
                  }
              });
        editorXML.setOptions({
            maxLines: Infinity
        });
    }
</script>

<script nonce='{{ common.CSP_SCRIPT_NONCE }}' type="text/javascript">
    $(document).ready(function(){
        $('#ammo_select').selectpicker();
        $('button.btn.dropdown-toggle.btn-secondary[data-id="ammo_select"]').css('margin-left', '0px');
        $('#pandora_binary_select').selectpicker();
        $('button.btn.dropdown-toggle.btn-secondary[data-id="pandora_binary_select"]').css('margin-left', '0px');
    });
</script>

<link href="/media/css/firestarter.css?version=43.4" type="text/css" rel="stylesheet" />
<script nonce='{{ common.CSP_SCRIPT_NONCE }}' type='text/javascript' src='/media/js/vendor/jquerymd5.js'></script>
<script nonce='{{ common.CSP_SCRIPT_NONCE }}' type='text/javascript' src='/media/js/firestarter.js?version=43.4'></script>
{% endblock %}
