<commit_before>{# do not load headers, etc if this is an ajax request #}
{% if not request.is_xhr %}

    {% extends "bootstrap/base.html" %}

    {% block title %}Edit Model{% endblock %}

    {% block styles %}
	{{ super() }}
	<style>
	 html, body {height:100%}
	 div.container {height:100%}
	 div.page-header {height:10%, overflow:hide}
	 div.row {height:85%}
	 div.page-header div.row {height:100%}
	 div.scroll {height:100%; overflow:auto}
	 .childofactive {background-color: #FCF8E3}
	 div.alert {margin-bottom:2px; padding-top:8px; padding-bottom:8px;}
	 h1 {margin-top:0px}
	 /*body, .btn, .form-control, .glyphicon {font-size:small;}*/
	 .linklike {cursor:pointer; }
	 .Assembly td:first-child:after {content:"↴"; padding-left:0.15em; color:green;}
	 #componentsdiv td[data-column=weight] {display:none}
	 #editor td[data-column=description] {display:none}
	 .form-inline, .form-inline div.input-group {display:inline-block}
	     
	</style>
    {% endblock %} 

    {% block scripts %}
	{{ super() }}
	<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js" ></script>
	<script type="text/javascript" >
	 //$("#assemblytable tbody tr.component, #unplacedtable tbody tr.component").draggable({'helper':'clone'});
	 //$("#assemblytable tbody").sortable({'helper':"clone", 'placeholder':'warning', 'containment':});
	 
	 //necessary script for sortable table widget
	 $("tbody.sortable").sortable({
	     'placeholder':'warning',
	     'update':function(event, ui){sortIndices(event.target);},
	 });
	 //prevent buttons from looking still depressed
	 $(".btn").mouseup(function(){
	     $(this).blur();
	 });

	 function filtercomponents(){
	     var filtertext = $("#filtercomponents").val();
	     var allrows = $("#componentsdiv tr.component, #specsdiv tr.spec");
	     if(filtertext.length < 2){
		 allrows.show();
		 return allrows;
	     }
	     var regex = new RegExp(filtertext);
	     allrows.hide();
	     allrows.filter(function(){
		 var rawobj = $(this).data('rawobj') || {};
		 var mytext = $(this).children("td").text() + " "+
			      Object.keys(rawobj).map(key => rawobj[key]).join(" ");
		 return regex.test(mytext);
		 
	     }).show();
	     return allrows;
	 }

	 //trigger a post action from a link
	 //args are additional non-url arguments
	 function dopost(event){
	     event.preventDefault();
	     var target = $(event.target);
	     var cfmessage = target.data("confirm");
	     if(!cfmessage || confirm(cfmessage)){
		 var form = $("<form method='POST' action='"+target.attr("href")+"'>");
		 var args = target.data('form');
		 if(args){
		     for(var key in args){
			 $("<input>").attr("name",key).val(args[key]).appendTo(form);
		     }
		 }
		 form.appendTo("body").submit();
		 
	     }
	 }
	 
	</script>
    {% endblock %}
{% endif %}

{% import "bootstrap/wtf.html" as wtf %}


{% macro componentrow(comp, level) %}
    <tr class="linklike component 
	       {% if editcomponent is defined %} 
	       {% if comp.id == editcomponent.id %} info 
	       {% elif editcomponent.isparentof(comp,deep=False) %} childofactive {% endif %}
	       {% endif %}
	       {%- if comp.getcomponents is defined %} Assembly {% endif -%} "
	       data-component="{{ comp.id }}" 
	       data-name="{{ comp.name }}" 
	       data-cls="{{ 'Assembly' if comp.getcomponents is defined else 'Component' }}"
	       onclick="window.location='{{ url_for('.editcomponent',modelid=model.id, componentid=comp.id) }}'" >
	<td data-column="name" style="padding-left:{{ 15*level }}px" >{{ comp.name }}</td>
	<td data-column="description">{{ comp.description or "" }}</td>
	<td>
	    {%- if editcomponent is defined and editcomponent.getcomponents is defined and not comp.isparentof(editcomponent) -%}
		<a class="placecomp" href="javascript:void(0)" 
		   onclick="event.stopPropagation(); addrow('#components',$(this).parents('tr'))">
		    <span class="small glyphicon glyphicon-circle-arrow-right"></span>
		</a>
	    {%- else -%}
		<span class="small glyphicon" ></span>
	    {%- endif -%}
	</td>
    </tr>
{% endmacro %}

{% macro componenttable(components, recursive=true, id="") %}
    <table class="table table-condensed table-hover comptable" id="{{ id }}">
	<thead>
	    <tr><th>Name</th><th>Description</th><th></tr>
	</thead>
	<tbody>
	    {% for comp in components recursive %}
		{% if comp == model.assemblyroot %}
		    <tr><th colspan="2" style="background-color:#fafafa;" > Assembly Tree</th></tr>
		{% endif %}
		{{ componentrow(comp, loop.depth0) }}
		{% if recursive %}
		    {% if comp.getcomponents is defined %}
			{{ loop(comp.getcomponents(deep=False, withweight=False, merge=False)) }}
		    {% endif %}
		{% endif %}
		{% if comp == model.assemblyroot %}
		    <tr><th colspan="2" style="background-color:#fafafa;" > Unplaced components</th></tr>
		{% endif %}
	    {% endfor %}
	    
	</tbody>
    </table>
{% endmacro %}


{% macro specrow(spec) %}
    <tr class="linklike spec {% if editspec is defined and spec.id == editspec.id -%} info {%- endif -%}
	       {%- if editcomponent is defined and spec in editcomponent.findspecs(deep=False) -%} childofactive {%- endif -%}"
        onclick="window.location='{{ url_for('.editspec',modelid=model.id, specid=spec.id) }}';" 
	data-id="{{ spec.id }}"
	data-name="{{ spec.name }}"
	data-category="{{ spec.category }}"
	data-distribution="{{ spec.distribution }}"
	data-rate="{{ spec.getratestr() }}"
    >
	<td data-column="name" >{{ spec.name }}</td>
	<td data-column="category" >{{ spec.category }}</td>
	<td data-column="distribution" >{{ spec.distribution }}</td>
	<td data-column="rate" >{{ spec.getratestr(2) }}</td>
	<td>
	    {%- if editcomponent is defined -%}
		<a class="placespec" href="javascript:void(0)" 
		   onclick="event.stopPropagation(); addrow($('#specs'),$(this).parents('tr'))">
		    <span class="small glyphicon glyphicon-circle-arrow-right"></span>
		</a>
	    {%- else -%}
		<span class="small glyphicon" ></span>
	    {%- endif -%}
	</td>
    </tr>
{% endmacro %}

{% macro spectable(specs, id="") %}
    <table class="table table-condensed table-hover spectable table-responsive" id="{{ id }}">
	<thead>
	    <tr><th>Name</th><th>Category</th><th>Dist.</th><th>Rate</th><th></th></tr>
	</thead>
	<tbody>
	    {% for spec in specs %}
		{{ specrow(spec) }}
	    {% endfor %}
	</tbody>
    </table>
{% endmacro %}



{% block content %}
    <div class="container" id="" >
	<div class="page-header"> 
	    <div class="row" >
		<div class="col-sm-4"> 
		    <h1>Editing Model: <small>{{ model.name }} v{{ model.version }}
		    </small></h1>
		    <small>{{ model.description }}</small>
		</div>
		<div class="col-sm-3" >
		    <button class="btn btn-success">Save New Version</button> 
		    <button class="btn btn-danger btn-sm">Discard Changes</button>
		</div>
		<div class="col-sm-5" >
		    <div id="messages">
			{% for cat,msg in get_flashed_messages(with_categories=true) %}
			    <div class="alert alert-{{ cat }} alert-dismissable" >
				{{ msg }}
				<a href="#"  class="close" data-dismiss="alert" >
				    &times;
				</a>
			    </div>
			{% endfor %}
		    </div>
		</div>
	    </div>
	    
	</div>
    

	<div class="row" >
	    <div class="col-sm-6 scroll">
		
		<ul class="nav nav-tabs" >
		    <li {%- if editspec is not defined %} class="active" {% endif -%}>
			<a data-toggle="tab" href="#componentsdiv">Components</a>
		    </li>
		    <li {%- if editspec is defined %} class="active" {% endif -%}>
			<a data-toggle="tab" href="#specsdiv">Specifications</a>
		    </li>
		    <li>
			<div class="input-group pull-right" >
			    <input type="text" class="form-control" id="filtercomponents" placeholder="Search" 
				   oninput="filtercomponents()" size="30" >
			    <div class="input-group-btn">
				<button class="btn btn-default" 
					onclick="$('#filtercomponents').val('');filtercomponents()" >
				    <span class="glyphicon glyphicon-remove" ></span>
				</button>
			    </div>
			</div>
		    </li>
		</ul>
		
		<div class="tab-content" >
		    
		    <div id="componentsdiv" class="tab-pane fade {% if editspec is not defined %}in active{% endif %}" >
			<h2>Components <small>
			    <form action="{{ url_for('.newcomponent',modelid=model.id) }}" 
				  method="POST" class="pull-right form-inline" >
				<label>Create new:</label>
				<span class="btn-group" >
				    <button type="submit" class="btn btn-default btn-sm" name="class" value="Component" >
					Component
				    </button>
				    <button type="submit" class="btn btn-default btn-sm" name="class" value="Assembly" >
					Assembly
				    </button>
				</span>
			    </form></small>
			</h2>
		
			
			{{  componenttable([model.assemblyroot] + model.get_unplaced_components(), true, "assemblytable") }}
			{# <h3>Unplaced Components </h3>
			{{ componenttable(model.get_unplaced_components(), true, "unplacedtable") }}#}
			
		    </div> {# close components div #}

	    
		    <div id="specsdiv" class="tab-pane fade {% if editspec is defined %}in active{% endif %}" >
			<h2>Specifications <small>
			    <form class="form-inline pull-right" action="{{ url_for('.newspec',modelid=model.id) }}" 
				  method="POST">
				<div class="form-group push-right" >
				    <label for="newspec">Create new: </label>
				    <select class="form-control" id="newspec" name="type" 
					    onchange="$(this).parents('form').submit();" >
					<option style="color:gray;font-style:italic"> Select a spec type</option>
					{% for spectype in spectypes %}
					    <option value="{{ spectype }}">{{ spectype }}</option>
					{% endfor %}
				    </select>
				</div>
			    </form>
			</small></h2>
			{{ spectable(model.specs.values()) }}
		    </div> {# close specsdiv #}
		</div> {# close tab-content  #}
	    </div> {# close col-sm-6 #}
	    
	    <div class="col-sm-6 scroll" >
		<div id="editor"  >
		    {% if form is defined %}
			{% if editcomponent is defined %}
			    {% include "editcomponent.html" %}
			{% elif editspec is defined %}
			    {% include "editspec.html" %}
			{% endif %}
		    {% endif %}
		</div>
	    </div>
	</div>
    </div>
{% endblock %}
<commit_msg>add some more info about hierarchy to display<commit_after>{# do not load headers, etc if this is an ajax request #}
{% if not request.is_xhr %}

    {% extends "bootstrap/base.html" %}

    {% block title %}Edit Model{% endblock %}

    {% block styles %}
	{{ super() }}
	<style>
	 html, body {height:100%}
	 div.container {height:100%}
	 div.page-header {height:10%, overflow:hide}
	 div.row {height:85%}
	 div.page-header div.row {height:100%}
	 div.scroll {height:100%; overflow:auto}
	 .childofactive, .parentofactive {background-color: #FCF8E3}
	 div.alert {margin-bottom:2px; padding-top:8px; padding-bottom:8px;}
	 h1 {margin-top:0px}
	 /*body, .btn, .form-control, .glyphicon {font-size:small;}*/
	 .linklike {cursor:pointer; }
	 .Assembly td:first-child:after {content:"↴"; padding-left:0.15em; color:green;}
	 #componentsdiv td[data-column=weight] {display:none}
	 #editor td[data-column=description] {display:none}
	 .form-inline, .form-inline div.input-group {display:inline-block}
	     
	</style>
    {% endblock %} 

    {% block scripts %}
	{{ super() }}
	<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js" ></script>
	<script type="text/javascript" >
	 //$("#assemblytable tbody tr.component, #unplacedtable tbody tr.component").draggable({'helper':'clone'});
	 //$("#assemblytable tbody").sortable({'helper':"clone", 'placeholder':'warning', 'containment':});
	 
	 //necessary script for sortable table widget
	 $("tbody.sortable").sortable({
	     'placeholder':'warning',
	     'update':function(event, ui){sortIndices(event.target);},
	 });
	 //prevent buttons from looking still depressed
	 $(".btn").mouseup(function(){
	     $(this).blur();
	 });

	 function filtercomponents(){
	     var filtertext = $("#filtercomponents").val();
	     var allrows = $("#componentsdiv tr.component, #specsdiv tr.spec");
	     if(filtertext.length < 2){
		 allrows.show();
		 return allrows;
	     }
	     var regex = new RegExp(filtertext);
	     allrows.hide();
	     allrows.filter(function(){
		 var rawobj = $(this).data('rawobj') || {};
		 var mytext = $(this).children("td").text() + " "+
			      Object.keys(rawobj).map(key => rawobj[key]).join(" ");
		 return regex.test(mytext);
		 
	     }).show();
	     return allrows;
	 }

	 //trigger a post action from a link
	 //args are additional non-url arguments
	 function dopost(event){
	     event.preventDefault();
	     var target = $(event.target);
	     var cfmessage = target.data("confirm");
	     if(!cfmessage || confirm(cfmessage)){
		 var form = $("<form method='POST' action='"+target.attr("href")+"'>");
		 var args = target.data('form');
		 if(args){
		     for(var key in args){
			 $("<input>").attr("name",key).val(args[key]).appendTo(form);
		     }
		 }
		 form.appendTo("body").submit();
		 
	     }
	 }
	 
	</script>
    {% endblock %}
{% endif %}

{% import "bootstrap/wtf.html" as wtf %}


{% macro componentrow(comp, level) %}
    <tr class="linklike component 
	       {% if editcomponent is defined %} 
	       {% if comp.id == editcomponent.id %} info 
	       {% elif editcomponent.isparentof(comp,deep=False) %} childofactive 
	       {% elif comp.isparentof(editcomponent, deep=False) %} parentofactive {% endif %}
	       
	       {% endif %}
	       {%- if comp.getcomponents is defined %} Assembly {% endif -%} 
	       {%- if editspec is defined and editspec in comp.findspecs(deep=False) -%} parentofactive {% endif -%}"
	       data-component="{{ comp.id }}" 
	       data-name="{{ comp.name }}" 
	       data-cls="{{ 'Assembly' if comp.getcomponents is defined else 'Component' }}"
	       onclick="window.location='{{ url_for('.editcomponent',modelid=model.id, componentid=comp.id) }}'" >
	<td data-column="name" style="padding-left:{{ 15*level }}px" >{{ comp.name }}</td>
	<td data-column="description">{{ comp.description or "" }}</td>
	<td>
	    {%- if editcomponent is defined and editcomponent.getcomponents is defined and not comp.isparentof(editcomponent) -%}
		<a class="placecomp" href="javascript:void(0)" 
		   onclick="event.stopPropagation(); addrow('#components',$(this).parents('tr'))">
		    <span class="small glyphicon glyphicon-circle-arrow-right"></span>
		</a>
	    {%- else -%}
		<span class="small glyphicon" ></span>
	    {%- endif -%}
	</td>
    </tr>
{% endmacro %}

{% macro componenttable(components, recursive=true, id="") %}
    <table class="table table-condensed table-hover comptable" id="{{ id }}">
	<thead>
	    <tr><th>Name</th><th>Description</th><th></tr>
	</thead>
	<tbody>
	    {% for comp in components recursive %}
		{% if comp == model.assemblyroot %}
		    <tr><th colspan="2" style="background-color:#fafafa;" > Assembly Tree</th></tr>
		{% endif %}
		{{ componentrow(comp, loop.depth0) }}
		{% if recursive %}
		    {% if comp.getcomponents is defined %}
			{{ loop(comp.getcomponents(deep=False, withweight=False, merge=False)) }}
		    {% endif %}
		{% endif %}
		{% if comp == model.assemblyroot %}
		    <tr><th colspan="2" style="background-color:#fafafa;" > Unplaced components</th></tr>
		{% endif %}
	    {% endfor %}
	    
	</tbody>
    </table>
{% endmacro %}


{% macro specrow(spec) %}
    <tr class="linklike spec {% if editspec is defined and spec.id == editspec.id -%} info {%- endif -%}
	       {%- if editcomponent is defined and spec in editcomponent.findspecs(deep=False) -%} childofactive {%- endif -%}"
        onclick="window.location='{{ url_for('.editspec',modelid=model.id, specid=spec.id) }}';" 
	data-id="{{ spec.id }}"
	data-name="{{ spec.name }}"
	data-category="{{ spec.category }}"
	data-distribution="{{ spec.distribution }}"
	data-rate="{{ spec.getratestr() }}"
    >
	<td data-column="name" >{{ spec.name }}</td>
	<td data-column="category" >{{ spec.category }}</td>
	<td data-column="distribution" >{{ spec.distribution }}</td>
	<td data-column="rate" >{{ spec.getratestr(2) }}</td>
	<td>
	    {%- if editcomponent is defined -%}
		<a class="placespec" href="javascript:void(0)" 
		   onclick="event.stopPropagation(); addrow($('#specs'),$(this).parents('tr'))">
		    <span class="small glyphicon glyphicon-circle-arrow-right"></span>
		</a>
	    {%- else -%}
		<span class="small glyphicon" ></span>
	    {%- endif -%}
	</td>
    </tr>
{% endmacro %}

{% macro spectable(specs, id="") %}
    <table class="table table-condensed table-hover spectable table-responsive" id="{{ id }}">
	<thead>
	    <tr><th>Name</th><th>Category</th><th>Dist.</th><th>Rate</th><th></th></tr>
	</thead>
	<tbody>
	    {% for spec in specs %}
		{{ specrow(spec) }}
	    {% endfor %}
	</tbody>
    </table>
{% endmacro %}



{% block content %}
    <div class="container" id="" >
	<div class="page-header"> 
	    <div class="row" >
		<div class="col-sm-4"> 
		    <h1>Editing Model: <small>{{ model.name }} v{{ model.version }}
		    </small></h1>
		    <small>{{ model.description }}</small>
		</div>
		<div class="col-sm-3" >
		    <button class="btn btn-success">Save New Version</button> 
		    <button class="btn btn-danger btn-sm">Discard Changes</button>
		</div>
		<div class="col-sm-5" >
		    <div id="messages">
			{% for cat,msg in get_flashed_messages(with_categories=true) %}
			    <div class="alert alert-{{ cat }} alert-dismissable" >
				{{ msg }}
				<a href="#"  class="close" data-dismiss="alert" >
				    &times;
				</a>
			    </div>
			{% endfor %}
		    </div>
		</div>
	    </div>
	    
	</div>
    

	<div class="row" >
	    <div class="col-sm-6 scroll">
		
		<ul class="nav nav-tabs" >
		    <li {%- if editspec is not defined %} class="active" {% endif -%}>
			<a data-toggle="tab" href="#componentsdiv">Components</a>
		    </li>
		    <li {%- if editspec is defined %} class="active" {% endif -%}>
			<a data-toggle="tab" href="#specsdiv">Specifications</a>
		    </li>
		    <li>
			<div class="input-group pull-right" >
			    <input type="text" class="form-control" id="filtercomponents" placeholder="Search" 
				   oninput="filtercomponents()" size="30" >
			    <div class="input-group-btn">
				<button class="btn btn-default" 
					onclick="$('#filtercomponents').val('');filtercomponents()" >
				    <span class="glyphicon glyphicon-remove" ></span>
				</button>
			    </div>
			</div>
		    </li>
		</ul>
		
		<div class="tab-content" >
		    
		    <div id="componentsdiv" class="tab-pane fade {% if editspec is not defined %}in active{% endif %}" >
			<h2>Components <small>
			    <form action="{{ url_for('.newcomponent',modelid=model.id) }}" 
				  method="POST" class="pull-right form-inline" >
				<label>Create new:</label>
				<span class="btn-group" >
				    <button type="submit" class="btn btn-default btn-sm" name="class" value="Component" >
					Component
				    </button>
				    <button type="submit" class="btn btn-default btn-sm" name="class" value="Assembly" >
					Assembly
				    </button>
				</span>
			    </form></small>
			</h2>
		
			
			{{  componenttable([model.assemblyroot] + model.get_unplaced_components(), true, "assemblytable") }}
			{# <h3>Unplaced Components </h3>
			{{ componenttable(model.get_unplaced_components(), true, "unplacedtable") }}#}
			
		    </div> {# close components div #}

	    
		    <div id="specsdiv" class="tab-pane fade {% if editspec is defined %}in active{% endif %}" >
			<h2>Specifications <small>
			    <form class="form-inline pull-right" action="{{ url_for('.newspec',modelid=model.id) }}" 
				  method="POST">
				<div class="form-group push-right" >
				    <label for="newspec">Create new: </label>
				    <select class="form-control" id="newspec" name="type" 
					    onchange="$(this).parents('form').submit();" >
					<option style="color:gray;font-style:italic"> Select a spec type</option>
					{% for spectype in spectypes %}
					    <option value="{{ spectype }}">{{ spectype }}</option>
					{% endfor %}
				    </select>
				</div>
			    </form>
			</small></h2>
			{{ spectable(model.specs.values()) }}
		    </div> {# close specsdiv #}
		</div> {# close tab-content  #}
	    </div> {# close col-sm-6 #}
	    
	    <div class="col-sm-6 scroll" >
		<div id="editor"  >
		    {% if form is defined %}
			{% if editcomponent is defined %}
			    {% include "editcomponent.html" %}
			{% elif editspec is defined %}
			    {% include "editspec.html" %}
			{% endif %}
		    {% endif %}
		</div>
	    </div>
	</div>
    </div>
{% endblock %}

{'fraction_non_alphanumeric': 0.198943661971831, 'fraction_numerical': 0.005379499217527386, 'mean_word_length': 3.1809445921079536, 'pattern_counts': {'":': 0, '<': 353, '<?xml version=': 0, '>': 353, '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': '126583', 'n_tokens_mistral': 7837, 'n_tokens_neox': 6602, 'n_words': 1418}