<form role="form">
	<div class="form-group">
		<label for="xqueryInput" class="control-label">XQuery</label>
		<textarea class="form-control" id="xqueryInput" ng-model="query" rows="10"></textarea>
	</div>
	<button class="btn btn-default" ng-click="searchXQuery()">Search</button>
	<button class="btn btn-primary pull-right" data-toggle="modal" data-target="#xqueryHistoryModal">History</button>
</form>
<br />

<div class="panel panel-default" ng-show="error">
	<div class="panel-heading">
		<a class="accordion-toggle" data-toggle="collapse" data-target="#collapse_error"><b>Error:</b> <i>{{error.message}}</i></a>
	</div>
	<div id="collapse_error" class="panel-collapse collapse in">
		<div class="panel-body">
			<pre>{{error.stacktrace}}</pre>
		</div>			
	</div>
</div>


<p ng-hide="error"><b>Number of results:</b> {{results.length}}<br /></p>

<div class="panel panel-default" ng-repeat="r in results track by $index">
	<div class="panel-heading">
		<a class="accordion-toggle" data-toggle="collapse" data-target="#collapse_{{$index}}"><b> Result: </b><i>{{$index + 1}}</i></a>
	</div>
	<div id="collapse_{{$index}}" class="panel-collapse collapse in">
		<div class="panel-body">
			<pre>{{r}}</pre>
		</div>
	</div>
</div>


<div id="xqueryHistoryModal" class="modal fade" tabindex="-1" role="dialog">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">&times;</button>
				<h4 class="modal-title">History</h4>
			</div>
			<div class="modal-body" style="height: 400px; overflow-y: scroll">
				<p class="text-center" ng-show="history.length == 0">
					<b>History is empty</b>
				</p>
				<div ng-repeat="e in history | reverse">
					<span><a href="javascript:void(0)" data-dismiss="modal" ng-click="updateXQuery(e.query)">{{e.date | date:"yyyy-MM-dd HH:mm:ss"}}</a></span>
					<pre>{{e.query}}</pre>
				</div>
			</div>
			<div class="modal-footer">
				<button class="btn btn-primary" data-dismiss="modal">Clear history</button>
				<button class="btn btn-default" data-dismiss="modal">Close</button>
			</div>
		</div>
	</div>
</div>
