<div class="queries">

	<div class="layout-side-onebox" re-resizable="{persist: 'side'}"><div class="inner1"><div class="inner2">

		<div class="box queries-box">
			<h2>
				<a class="show-cursor" ng-click="manageAccordion('results')">Query results</a>
				<!--button ng-click="cancelJob()" ng-show="isWaiting() && !jobCancelled && showQueryResults">Cancel</button-->
				<button type="button" class="btn btn-default" ng-click="redirectExportResults()" ng-show="results() && !isWaiting() && showQueryResults">
          Export results
        </button>
			</h2>
			<div class="content" ng-show="showQueryResults">
				<p class="waiting" ng-show="!isWaiting() && !results() || jobCancelled">
					Execute a query or select one from the history to see results.
				</p>

				<p class="waiting" ng-show="isWaiting() && !jobCancelled">
					Waiting for results...
				</p>

				<div ng-show="results()">

					<div ng-show="results().data.empty">
						Empty results
					</div>

					<div ng-show="results().error" class="error">
						<strong>Error</strong>
						<p>{{results().error}}</p>
					</div>

					<div class="btn-group" ng-show="results().data.type == 'grouped' || results().data.type == 'search_result'">
							<button type="button" class="btn btn-default" ng-click="collapseAll()" >Collapse all</button>
							<button type="button" class="btn btn-default" ng-click="expandAll()">Expand all</button>
					</div>

					<div class="navigation-content"
                         ng-style="getQueryResultsNavigationContetnStyle()"
                         ng-show="showQueryResults"
                         re-scroll-to="resultScrollPos"
                         re-scroll-saved="resultScroll">
						<p ng-show="results().data.type == 'scalar'" class="type-scalar">
							<strong>{{results().data.property}}</strong>: {{results().data.value}}
						</p>

						<table ng-show="results().data.type == 'table'" class="type-table" cellspacing="0" cellpadding="0" border="0">
							<thead>
								<tr>
									<th>&nbsp;</th>
									<th>{{results().data.property}}</th>
								</tr>
							</thead>
							<tbody ng-repeat="item in results().data.rows"
                                    ng-class="{current: isCurrent(item)}">
								<tr ng-show="item.pos">
									<td colspan="2" class="list-filename-header"
                                        ng-class="{current: isCurrent(item)}">
										{{item.pos.file | fileName}}:{{item.pos.start_line}}
									</td>
								</tr>
								<tr>
									<td class="list-content">
										<a
											ng-href="{{href(item, results().page)}}"
											ng-click="open($event, item);"
                                            ng-class="{current: isCurrent(item)}">
												<span>{{item.display}}</span>
										</a>
									</td>
									<td class="list-content">
                                        <div ng-repeat="elem in item.values">
                                            {{elem}}
                                        </div>
                                    </td>
								</tr>
							</tbody>
						</table>

						<ul ng-show="results().data.type == 'grouped'" class="type-grouped">
							<li ng-repeat="group in results().data.groups" class="openable" ng-class="{open: !group.closed}">
								<span class="before" ng-click="toggleOpen(group)"><i></i></span>
								<a
									class="header re-label"
									ng-href="{{href(group.header)}}"
									ng-click="open($event, group.header);"
									ng-dblclick="toggleOpen(group)"
									ng-class="{current: isCurrent(group.header)}"
									title="{{group.header.display}}">
										{{group.header.display}}
								</a>
								<ul ui-if="!group.closed">
									<li ng-repeat="item in group.rows">
										<a class="re-label item-label"
											ng-href="{{href(item, results().page)}}"
											ng-click="open($event, item, group)"
											ng-class="{current: isCurrent(item)}"
											title="{{item.pos.file}}">
                                            <div ng-show="item.pos" class="list-filename-header">
                                                {{item.pos.file | fileName}}:{{item.pos.start_line}}
                                            </div>
                                            <div class="list-filename-content">
                                                {{item.display}}
                                            </div>
										</a>
									</li>
								</ul>
							</li>
						</ul>

						<ul ng-show="results().data.type == 'list'" class="type-list">
							<li ng-repeat="item in results().data.rows">
								<i ng-show="!item.pos.start_line" class="before"></i>
								<a class="re-label item-label"
									ng-href="{{href(item, results().page)}}"
									ng-click="open($event, item);"
									ng-class="{current: isCurrent(item)}"
									title="{{item.display}}">
                                    <div ng-show="item.pos.start_line" class="list-filename-header">
                                        {{item.pos.file | fileName}}:{{item.pos.start_line}}
                                    </div>
                                    <div class="list-filename-content">
                                        {{item.display}}
                                    </div>
								</a>
							</li>
						</ul>

						<ul ng-show="results().data.type == 'chains'" class="type-chains">
							<li ng-repeat="chain in results().data.chains" ng-class-odd="'odd'">
								<a
									ng-repeat="item in chain.items"
									ng-href="{{href(item, results().page)}}"
									ng-click="open($event, item, chain);"
									ng-class="{current: isCurrent(item), indented: !$first}">
									<i ng-class="{hide: $first}" class="before"></i>
                                    <div>
                                    <div ng-show="item.pos" class="list-filename-header"
                                            ng-class="{current: isCurrent(item)}">
                                        {{item.pos.file | fileName}}:{{item.pos.start_line}}
                                    </div>
                                    <div class="list-filename-content" ng-class="{indented: !$first}">
                                        {{item.display}}
                                        <span ng-show="$last">{{chain.end}}</span>
                                    </div>
                                    </div>
								</a>
							</li>
						</ul>

            <!-- Search results -->
						<ul ng-show="results().data.type == 'search_result'" class="type-grouped">
							<li ng-repeat="file in results().data.result" class="openable" ng-class="{open: !file.closed}">
								<span class="before" ng-click="toggleOpen(file)"><i></i></span>
								<a
									class="header re-label"
									ng-href="{{href(file.fileName)}}"
									ng-dblclick="toggleOpen(file)"
									ng-class="{current: isCurrent(file)}"
									title="{{file.fileName}}">
										{{file.fileName}}
								</a>
								<ul ui-if="!file.closed">
									<li ng-repeat="chunk in file.chunks">
										<a class="re-label item-label"
											ng-href="{{searchHref(file, chunk, results().page)}}"
											ng-class="{current: isCurrent(chunk)}"
											title="{{chunk.startingPosition}}">
                        <div ng-show="chunk.startingPosition" class="list-filename-header">
                          {{file.fileName}}<!--:{{chunk.startingPosition}}-->
                        </div>
                        <div class="list-filename-content">
                          {{chunk.chunk}}
                        </div>
										</a>
									</li>
								</ul>
							</li>

						</ul>
					</div>
				</div>
			</div>
			<div class="btn-group pager-buttons" ng-show="results() && !results().error && showQueryResults">
				<button type="button" class="btn btn-default" ng-click="getPrev()"  ng-disabled="results().isFirstPage">Previous</button>
				<button type="button" class="btn btn-default" ng-click="getNext()" ng-disabled="results().isLastPage">Next</button>
			</div>
		</div>

        <div class="box queries-box">
			<h2>
				<a class="show-cursor" ng-show="isDatabase" ng-click="manageAccordion('browser')">Database browser</a>
				<a class="show-cursor" ng-show="!isDatabase" ng-click="manageAccordion('browser')">File system browser</a>
				<button type="button" class="btn btn-default" ng-show="!isDatabase && showDatabaseBrowser" ng-click="toDatabase()">See database</button>
				<button type="button" class="btn btn-default" ng-show="isDatabase && showDatabaseBrowser" ng-click="toFileSystem()">See filesystem</button>
			</h2>
			<div class="content navigation-content" ng-show="showDatabaseBrowser" ng-style="getNavigationContetnStyle()">
				<div class="buttons-file-viewer" ui-if="false"><!-- disabled now as we have the (smarter) context menu -->
					<button
							ng-show="!isDatabase"
							ng-disabled="!selected"
							ng-class="{disabled: !selected}"
							ng-click="add(selected)"
							class="hint--bottom"
							data-hint="Add {{selectedType()}} to database">
						Add</button>
					<button
							ng-show="isDatabase"
							ng-disabled="!selected"
							ng-class="{disabled: !selected}"
							ng-click="remove(selected)"
							class="hint--bottom"
							data-hint="Remove {{selectedType()}} from database">
						Remove</button>
					<button
							ng-show="isDatabase"
							ng-disabled="!selected"
							ng-class="{disabled: !selected}"
							ng-click="update(selected)"
							class="hint--bottom"
							data-hint="Reload {{selectedType()}} in database">
						Update</button>
				</div>

				<label ng-show="!isDatabase"  for="onlyErlang">
					<input ng-show="!isDatabase"  id="onlyErlang" type="checkbox" ng-model="options.onlyErlang" />
					<span ng-show="!isDatabase" >Show only erlang source files</span>
				</label>

                <label ng-show="!isDatabase" for="showHidden">
                    <input ng-show="!isDatabase" id="showHidden" type="checkbox" ng-model="options.showHidden" />
                    <span ng-show="!isDatabase">Show hidden files and directories</span>
                </label>

				<div class="field">
					<input type="text" ng-model="options.filter" placeholder="Filename filter" />
					<i ng-show="options.filter" class="icon-cancel" ng-click="options.filter = ''"></i>
				</div>

				<div ui-if="!tree.length" class="message">
					<p ui-if="tree.loading">
						Loading...
					</p>
					<p ui-if="!tree.loading">
						<span ng-show="isDatabase">Database is empty</span>
						<span ng-show="!isDatabase">Empty directory</span>
					</p>
				</div>

				<ul re-recursive="tree as data" re-context-menu="contextMenuForNode(data)" re-context-menu-class="database-context-menu">
					<li
						ng-repeat="item in data | filter:fsFilter"
						ng-class="{openable: item.folder, open: item.open, loading: item.children.loading}"
						class="ext-{{item.ext}}">
							<span class="before" ng-click="nodeToggleOpen(item)">
								<i ui-if="item.folder"></i>
							</span>
							<p
								class="re-label"
								ng-click="click(item)"
								ng-bind-html-unsafe="item.name | highlight:regexpFilter"
								re-context-menu-data="item"
								title="{{item.path}}"></p>
							<ul re-recursion="item.children"></ul>
					</li>
				</ul>
			</div>
		</div>

		<div class="box queries-box">
			<h2>
				<a class="show-cursor" ng-click="manageAccordion('funlist')">Function quicklist</a>
        <button type="button" class="btn btn-default" ng-click="regenerate()" ng-show="showFunctionQuicklist">Reload</button>
			</h2>
			<div class="content navigation-content" ng-show="showFunctionQuicklist" ng-style="getNavigationContetnStyle()">
                <ul>
                    <li ng-repeat="item in funlist">
                        <a ng-show="isPositioned(item)"
                           ng-href="{{FLhref(item)}}"
                           ng-click="openQuicklist($event, item)">
                            {{item.text}}
                        </a>
                        <span ng-show="!isPositioned(item)">
                            {{item.text}}
                        </span>
                    </li>
                </ul>
			</div>
		</div>
	</div></div></div>

	<div class="layout-cell main" ng-show="fileContent"><div class="inner1"><div class="inner2">
		<span class="filepath hint--bottom" data-hint="{{file}}">
			{{file}}
		</span>
		<div class="border" ng-click="removeHighlighting()">
			<textarea
				re-new-file="newFile"
				re-highlight="highlight"
				re-code-mirror="codeMirrorConfig"
				re-code-mirror-context-menu
                re-code-mirror-remember-search="viewCodeSearch"
				re-code-mirror-copy="true"
				re-code-mirror-select-all="true"
				re-context-menu="contextMenuFor(file, selection)"
				re-context-menu-class="queries-context-menu"
				placeholder=" "
                ng-model="fileContent"></textarea>
		</div>
	</div></div></div>

	<div class="layout-cell history" ng-hide="file" ng-controller="HistoryCtrl" ng-include="'partials/history.html'"></div>

</div>
