<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<div id="schema" class="loaded">

  <div class="clearfix">

    <div id="frame">
    <div id="actions" class="actions clearfix" ng-show="isSchemaUpdatable">
      <button id="addField" class="action" ng-click="toggleAddField()"><span>Add Field</span></button>
      <button id="addDynamicField" class="action" ng-click="toggleAddDynamicField()"><span>Add Dynamic Field</span></button>
      <button id="addCopyField" class="action" ng-click="toggleAddCopyField()"><span>Add Copy Field</span></button>

      <div class="action add" data-rel="add" ng-show="showAddField" escape-pressed="hideAll()">

          <p class="clearfix"><label for="add_name">name:</label>
          <input type="text" id="add_name" ng-model="newField.name" focus-when="showAddField" placeholder="enter a field name"></p>

          <p class="clearfix"><label for="add_type">field type:</label>
          <select chosen type="text" id="add_type" ng-model="newField.type" ng-options="type for type in types"></select>
          </p>

          <p class="clearfix" ng-show="adding=='field'"><label for="add_default">default:</label>
          <input type="text" id="add_default" ng-model="newField.default" placeholder="enter a default value if needed"></p>

          <p class="clearfix">
            <label class="checkbox" for="add_stored">
              <input type="checkbox" ng-model="newField.stored" id="add_stored" title="Full field should be stored in index." ng-true-value="'true'" ng-false-value="'false'">
            stored
            </label>
          </p>

          <p class="clearfix">
            <label class="checkbox" for="add_indexed">
              <input type="checkbox" ng-model="newField.indexed" id="add_indexed" title="Field should be indexed." ng-true-value="'true'" ng-false-value="'false'">
            indexed
            </label>
          </p>

          <p class="clearfix">
            <label class="checkbox" for="add_docValues">
              <input type="checkbox" ng-model="newField.docValues" id="add_docValues" title="DocValues should be stored for the field." ng-true-value="'true'" ng-false-value="'false'">
            docValues
            </label>
          </p>

          <p class="clearfix">
            <label class="checkbox" for="add_multiValued">
              <input type="checkbox" ng-model="newField.multiValued" id="add_multiValued" title="Multiple values are allowed for this field." ng-true-value="'true'" ng-false-value="'false'">
            multiValued
            </label>
          </p>

          <p class="clearfix" ng-show="adding=='field'">
            <label class="checkbox" for="add_required">
              <input type="checkbox" ng-model="newField.required" id="add_required" title="Field must be provided for all documents." ng-true-value="'true'" ng-false-value="'false'">
            required
            </label>
          </p>

          <p class="clearfix">
            <a ng-click="showOmit=!showOmit">
              <span class="add_showhide" ng-hide="showOmit">Show omit options</span>
              <span class="add_showhide open" ng-show="showOmit">Hide omit options</span>
            </a>
          </p>

          <div ng-show="showOmit">

            <p class="clearfix">
              <label class="checkbox" for="add_omitNorms">
                <input type="checkbox" ng-model="newField.omitNorms" id="add_omitNorms" title="Full field should be omitNorms in index." ng-true-value="'true'" ng-false-value="'false'">
              omitNorms
              </label>
            </p>

            <p class="clearfix">
              <label class="checkbox" for="add_omitTermFreqAndPositions">
                <input type="checkbox" ng-model="newField.omitTermFreqAndPositions" id="add_omitTermFreqAndPositions" title="Full field should be omitTermFreqAndPositions in index." ng-true-value="'true'" ng-false-value="'false'">
              omitTermFreqAndPositions
              </label>
            </p>

            <p class="clearfix">
              <label class="checkbox" for="add_omitPositions">
                <input type="checkbox" ng-model="newField.omitPositions" id="add_omitPositions" title="Full field should be omitPositions in index." ng-true-value="'true'" ng-false-value="'false'">
              omitPositions
              </label>
            </p>
          </div>

          <p class="clearfix">
            <a ng-click="showTermVectors=!showTermVectors">
              <span class="add_showhide" ng-hide="showTermVectors">Show term vector options</span>
              <span class="add_showhide open" ng-show="showTermVectors">Hide term vector options</span>
            </a>
          </p>
          <div ng-show="showTermVectors">

             <p class="clearfix">
              <label class="checkbox" for="add_termVectors">
                <input type="checkbox" ng-model="newField.termVectors" id="add_termVectors" title="Full field should be termVectors in index." ng-true-value="'true'" ng-false-value="'false'">
              termVectors
              </label>
            </p>

            <p class="clearfix">
              <label class="checkbox" for="add_termPositions">
                <input type="checkbox" ng-model="newField.termPositions" id="add_termPositions" title="Full field should be termPositions in index." ng-true-value="'true'" ng-false-value="'false'">
              termPositions
              </label>
            </p>

            <p class="clearfix">
              <label class="checkbox" for="add_termOffsets">
                <input type="checkbox" ng-model="newField.termOffsets" id="add_termOffsets" title="Full field should be termOffsets in index." ng-true-value="'true'" ng-false-value="'false'">
              termOffsets
              </label>
            </p>

            <p class="clearfix">
              <label class="checkbox" for="add_termPayloads">
                <input type="checkbox" ng-model="newField.termPayloads" id="add_termPayloads" title="Full field should be termPayloads in index." ng-true-value="'true'" ng-false-value="'false'">
              termPayloads
              </label>
            </p>

          </div>

          <p class="clearfix">
            <a ng-click="showSort=!showSort">
              <span class="add_showhide" ng-hide="showSort">Show sort options</span>
              <span class="add_showhide open" ng-show="showSort">Show sort options</span>
            </a>
          </p>
          <div ng-show="showSort">
            <p class="clearfix">
              <label class="checkbox" for="add_sortMissingFirst">
                <input type="checkbox" ng-model="newField.sortMissingFirst" id="add_sortMissingFirst" title="Full field should be sortMissingFirst in index." ng-true-value="'true'" ng-false-value="'false'">
              sortMissingFirst
              </label>
            </p>

            <p class="clearfix">
              <label class="checkbox" for="add_sortMissingLast">
                <input type="checkbox" ng-model="newField.sortMissingLast" id="add_sortMissingLast" title="Full field should be sortMissingLast in index." ng-true-value="'true'" ng-false-value="'false'">
              sortMissingLast
              </label>
            </p>

          </div>

          <div ng-repeat="error in addErrors" ng-show="addErrors" class="clearfix note error">
            <span>{{error}}</span></div>

          <p class="clearfix buttons">
            <button ng-show="adding=='field'" type="submit" class="submit" ng-class="{success: added}" ng-click="addField()"><span>Add Field</span></button>
            <button ng-show="adding=='dynamicField'" type="submit" class="submit" ng-class="{success: added}" ng-click="addDynamicField()"><span>Add Dynamic Field</span></button>
            <button type="reset" class="reset" ng-click="hideAll()"><span>Cancel</span></button>
          </p>



      </div>

      <div class="action add" data-rel="add" ng-show="showAddCopyField" escape-pressed="hideAll()">

        <form>

          <p class="clearfix"><label for="add_source">source:</label>
          <input type="text" id="add_source" ng-model="copyField.source" focus-when="showAddCopyField" placeholder="specify your source field or pattern"></p>

          <p class="clearfix"><label for="add_dest">destination:</label>
          <input type="text" id="add_dest" ng-model="copyField.dest" placeholder="specify your destination field or pattern"></p>

          <div ng-repeat="error in addCopyFieldErrors" ng-show="addCopyFieldErrors" class="clearfix note error">
            <span>{{error}}</span></div>

          <p class="clearfix buttons">
            <button type="submit" class="submit" ng-class="{success: added}" ng-click="addCopyField()"><span>Add CopyField</span></button>
            <button type="reset" class="reset" ng-click="hideAll()"><span>Cancel</span></button>
          </p>

        </form>

      </div>
    </div>

    <div id="data">

      <div id="field">

        <div class="field-options" ng-show="showing">

          <div class="block head">
            <h2>
              <span class="type">{{selectedType}}</span>:
              <span class="name">{{name}}</span>
            </h2>
          </div>

          <div class="partial" ng-show="display.partialState">

            <p>Because your Index is empty, we do not have enough Information about this Field</p>

          </div>

          <dl class="options clearfix">

            <dt class="field-type" ng-show="analysis.data.className">Field-Type:</dt>
            <dd class="field-type" ng-show="analysis.data.className">{{analysis.data.className}}</dd>

            <dt class="similarity" ng-show="display.similarity.className">Similarity:</dt>
            <dd class="similarity" ng-show="display.similarity.className" data-tip="{{ display.similarity.className }}">{{ display.similarity.details }}</dd>

            <dt class="position-increment-gap" ng-show="display.positionIncrementGap"><abbr title="Position Increment Gap">PI Gap</abbr>:</dt>
            <dd class="position-increment-gap" ng-show="display.positionIncrementGap">{{ display.positionIncrementGap }}</dd>

            <dt class="docs" ng-show="display.docs">Docs:</dt>
            <dd class="docs" ng-show="display.docs"><a href="{{display.docsUrl}}">{{display.docs | number}}</a></dd>

            <dt class="distinct" ng-show="display.distinct">Distinct:</dt>
            <dd class="distinct" ng-show="display.distinct">{{display.distinct}}</dd>

          </dl>

          <table class="flags" cellspacing="0" cellpadding="0" border="0" ng-show="display.columns.length!=0">

            <thead>

              <tr>
                <td>Flags:</td>
                <th ng-repeat="key in display.columns">{{key.name}}</th>

              </tr>

            </thead>

              <tbody>
              <tr ng-repeat="row in display.rows track by row.name">
              <th>{{row.name}}</th>
              <td colspan="2" class="text" ng-show="row.comment">{{row.comment}}</td>
              <td ng-repeat="cell in row.cells"
                  ng-class="{'check':cell.value}">
                  <span ng-show="cell.value">âˆ?</span>
                  <span ng-show="!cell.value">&nbsp;</span>
              </td>
              </tr>
              </tbody>

          </table>

          <ul class="analyzer">
            <li class="clearfix {{analyzer.key}}" ng-class="{open: analyzer.show}" ng-repeat="analyzer in analysis.analyzers">

              <p><a class="analysis" ng-href="#/{{core}}/analysis?{{analysis.query}}"><span>{{analyzer.name}}&nbsp;Analyzer:</span></a></p>
              <dl>
                <dt><a ng-click="toggleAnalyzer(analyzer)" class="toggle">{{analyzer.detail.className}}</a></dt>
              </dl>
              <ul ng-show="analyzer.show">
                <li class="clearfix {{componentType.key}} data" ng-repeat="componentType in analyzer.detail.componentTypes" ng-show="componentType.components">
                  <p>{{componentType.label}}:</p>
                  <dl>
                      <dt ng-repeat-start="component in componentType.components">{{component.className}}</dt>
                      <dd ng-repeat-end ng-repeat="arg in component.args"
                          ng-class="{'ico-1': arg.booleanValue, 'ico-0': arg.booleanValue==false}">
                          {{arg.name}}<span ng-show="arg.value">: {{arg.value}}</span>
                      </dd>
                  </dl>
                </li>
              </ul>
            </li>
          </ul>

        </div>

        <div class="terminfo-holder loaded clearfix" ng-class="{disabled: noTermData}" ng-show="is.field && !display.partialState">

          <div class="trigger">

            <button class="submit" ng-click="toggleTerms()"><span ng-class="{loader:isLoadingTerms}">Load Term Info</span></button>
            <br/>
            <span ng-show="isCloudEnabled">N.B. Loaded from a single core - not from the whole collection.</span>

            <a ng-show="showTerms" ng-click="toggleAutoload()" ng-class="{on:isAutoload}" class="autoload" title="Automatically load Term Info?"><span>Autoload</span></a>

          </div>

          <p ng-show="showTerms && noTerms" class="status">Sorry, no Term Info available :(</p>

          <div ng-show="showTerms && termInfo.topTerms" class="topterms-holder">

            <form>
            <p class="head">
              <input type="text" ng-model="topTermsCount" ng-change="loadTermInfo()">
              <a class="max-holder" ng-click="loadAllTopTerms()" title="Load all Top-Terms">/<span class="max">{{termInfo.maxTerms | number}}</span></a> Top-Terms:
              <a id="query_link" href="#/{{core}}/query?q={{name}}:[* TO *]"><span>Query</span>&nbsp;</a>
            </p>
            </form>

            <ul>
                <li class="clearfix" ng-repeat="countGroup in termInfo.topTerms">
                    <p><span>{{countGroup.count}}</span></p>
                    <ul>
                        <li ng-repeat="term in countGroup.terms" ng-class="{odd:$odd}"><a ng-href="#/{{core}}/query?q=%7B!term+f%3D{{name | uriencode}}%7D{{term | uriencode}}">{{term}}</a></li>
                    </ul>
                </li>

            </ul>

          </div>

          <div ng-show="showTerms && termInfo.histogram" class="histogram-holder">

            <p class="head">Histogram:</p>
            <ul>
               <li ng-repeat="row in termInfo.histogram" ng-class="{odd:$odd}">
                 <dl class="clearfix" style="width: {{(( row.value / termInfo.histogramMax ) * 100 )}}%;">
                   <dt><span>{{ row.key | number}}</span></dt>
                   <dd><span>{{ row.value | number }}</span></dd>
                 </dl>
               </li>

            </ul>

          </div>

        </div>

      </div>

    </div>

    <div id="related">
     <select id="type_or_name"
             ng-model="fieldOrType"
             chosen
             data-placeholder="Please select ..."
             ng-change="selectFieldOrType()"
             ng-options="f.value as f.label group by f.group for f in fieldsAndTypes"></select>

      <dl id="f-df-t">

        <dt class="field" ng-class="{active: selectedType=='Field'}" ng-show="leftbar.fields">Field</dt>
        <dd class="field" ng-class="{active: selectedType=='Field'}" ng-repeat="field in leftbar.fields"><a href="#/{{core}}/schema?field={{field}}">{{field}}</a></dd>

        <dt class="copyfield" ng-show="leftbar.copyFieldSources">Copied from</dt>
        <dd class="copyfield" ng-repeat="field in leftbar.copyFieldSources">
            <div class="clearfix" ng-hide="isSchemaUpdatable">
              <a href="#/{{core}}/schema?field={{field.name}}">{{field.name}}</a>
            </div>
            <div class="clearfix updatable" ng-show="isSchemaUpdatable">
              <a style="float:left;width:80%" href="#/{{core}}/schema?field={{field.name}}">{{field.name}}</a>
              <span ng-click="toggleDeleteCopyField(field)" class="rem">&nbsp;</span>
            </div>
            <div class="action delete" ng-show="field.show">
                <form class="delete">

                  <p class="clearfix"><em>Are you sure you want to delete this CopyField?</em></p>
                  <div ng-repeat="error in field.errors" ng-show="field.errors" class="clearfix note error">
                    <span>{{error}}</span></div>

                  <p class="clearfix buttons">
                    <button class="submit" ng-class="{success: field.deleted}" ng-click="deleteCopyField(field, field.name, name)"><span>Delete</span></button>
                    <button type="reset" class="reset" ng-click="toggleDeleteCopyField(field)"><span>Cancel</span></button>
                  </p>
                </form>
            </div>
        </dd>

        <dt class="copyfield" ng-show="leftbar.copyFieldDests">Copied to</dt>
        <dd class="copyfield" ng-repeat="field in leftbar.copyFieldDests">
            <div class="clearfix" ng-hide="isSchemaUpdatable">
              <a href="#/{{core}}/schema?field={{field.name}}">{{field.name}}</a>
            </div>
            <div class="clearfix updatable" ng-show="isSchemaUpdatable">
              <a href="#/{{core}}/schema?field={{field.name}}">{{field.name}}</a>
              <span ng-click="toggleDeleteCopyField(field)" class="rem">&nbsp;</span>
            </div>
            <div class="action delete" ng-show="field.show">
                <form class="delete">

                  <p class="clearfix"><em>Are you sure you want to delete this CopyField?</em></p>
                  <div ng-repeat="error in field.errors" ng-show="field.errors" class="clearfix note error">
                    <span>{{error}}</span></div>

                  <p class="clearfix buttons">
                    <button class="submit" ng-class="{success: field.deleted}" ng-click="deleteCopyField(field, name, field.name)"><span>Delete</span></button>
                    <button type="reset" class="reset" ng-click="toggleDeleteCopyField(field)"><span>Cancel</span></button>
                  </p>
                </form>
            </div>
        </dd>
        <dt class="dynamic-field" ng-class="{active: selectedType=='Dynamic Field'}" ng-show="leftbar.dynamicFields">Dynamic Field {{dynamicFields}} / {{dynamicFields.length()}}</dt>
        <dd class="dynamic-field" ng-class="{active: selectedType=='Dynamic Field'}" ng-repeat="field in leftbar.dynamicFields"><a href="#/{{core}}/schema?dynamic-field={{field}}">{{field}}</a></dd>

        <dt class="type" ng-class="{active: selectedType=='Type'}" ng-show="leftbar.types">Type</dt>
        <dd class="type" ng-class="{active: selectedType=='Type'}" ng-repeat="type in leftbar.types"><a href="#/{{core}}/schema?type={{type}}">{{type}}</a></dd>

        <dt></dt>
        <dd class="active delete-field" ng-show="isSchemaUpdatable &amp;&amp; leftbar.fields &amp;&amp;!showDelete"><button ng-click="toggleDelete()"><span>delete field</span></button></dd>
        <dd class="active delete-field" ng-show="isSchemaUpdatable &amp;&amp; leftbar.dynamicFields &amp;&amp;!showDelete"><button ng-click="toggleDelete()"><span>delete dynamic field</span></button></dd>

        <div class="action delete" ng-show="showDelete">

            <form class="delete">

              <p class="clearfix"><em>Are you sure you want to delete this {{selectedType}}?</em></p>
              <div ng-repeat="error in deleteErrors" ng-show="deleteErrors" class="clearfix note error">
                <span>{{error}}</span></div>

              <p class="clearfix buttons">
                <button class="submit" ng-class="{success: deleted}" ng-click="delete()"><span>Delete</span></button>
                <button type="reset" class="reset" ng-click="toggleDelete()"><span>Cancel</span></button>
              </p>
            </form>
        </div>
      </dl>

      <dl class="ukf-dsf">

        <dt class="unique-key-field" ng-class="{active: isUniqueKeyField}" ng-show="uniqueKeyField">Unique Key Field</dt>
        <dd class="unique-key-field" ng-class="{active: isUniqueKeyField}"><a ng-href="#/{{core}}/schema?field={{uniqueKeyField}}">{{uniqueKeyField}}</a></dd>

        <dt class="default-search-field" ng-class="{active: isDefaultSearchField}" ng-show="defaultSearchField">Default Search Field</dt>
        <dd class="default-search-field" ng-class="{active: isDefaultSearchField}"><a ng-href="#/{{core}}/schema?field={{defaultSearchField}}">{{defaultSearchField}}</a></dd>

        <dt class="similarity" ng-class="{active: similarity.className}">Global Similarity:</dt>
        <dd class="similarity" ng-class="{active: similarity.className}" data-tip="{{ similarity.className }}">{{ similarity.details }}</dd>

      </dl>

    </div>
      </div>

  </div>

</div>
