<div id="examineManagement" ng-controller="Umbraco.Dashboard.ExamineMgmtController">

    <h3 class="bold">Examine Management</h3>

    <div ng-show="loading">
        <div class="umb-healthcheck-group__details-status-overlay"></div>
        <umb-load-indicator></umb-load-indicator>
    </div>

    <div ng-hide="loading" class="umb-healthcheck-group__details">

        <div class="umb-healthcheck-group__details-group-title">
            <div class="umb-healthcheck-group__details-group-name">Indexers</div>
        </div>

        <div class="umb-healthcheck-group__details-checks">
            <div class="umb-healthcheck-group__details-check">
                <div class="umb-healthcheck-group__details-check-title">
                    <div class="umb-healthcheck-group__details-check-name">Manage Examine's indexes</div>
                    <div class="umb-healthcheck-group__details-check-description">Allows you to view the details of each index and provides some tools for managing the indexes</div>
                </div>

                <div class="umb-healthcheck-group__details-status" ng-repeat="indexer in indexerDetails">

                    <div class="umb-healthcheck-group__details-status-icon-container">
                        <i class="umb-healthcheck-status-icon" ng-class="{'icon-check color-green' : indexer.isHealthy, 'icon-delete color-red' : !indexer.isHealthy}"></i>
                    </div>

                    <div class="umb-healthcheck-group__details-status-content">
                        <div class="umb-healthcheck-group__details-status-text">
                            <div ng-show="!indexer.isHealthy">
                                {{indexer.name}}
                            </div>
                            <a class="btn-link -underline" href="" ng-click="toggle(indexer, 'showProperties')" ng-show="indexer.isHealthy">
                                {{indexer.name}}
                            </a>
                            <div ng-if="!indexer.isHealthy" class="text-error">
                                The index cannot be read and will need to be rebuilt
                            </div>
                        </div>

                        <div class="umb-healthcheck-group__details-status-actions" ng-if="!indexer.isHealthy">
                            <div class="umb-healthcheck-group__details-status-action">
                                <button type="button" class="umb-era-button -blue"
                                        ng-show="!indexer.isProcessing && (!indexer.processingAttempts || indexer.processingAttempts < 100)"
                                        ng-click="rebuildIndex(indexer)">
                                    Rebuild index
                                </button>
                            </div>
                        </div>

                        <div class="umb-healthcheck-group__details-status-actions" ng-show="indexer.isHealthy && indexer.showProperties">
                            <ul>
                                <li>
                                    <a href="" ng-click="toggle(indexer, 'showTools')">Index info & tools</a>

                                    <div ng-show="indexer.showTools && indexer.isLuceneIndex">
                                        <div>
                                            <br />

                                            <div ng-show="!indexer.isProcessing && (!indexer.processingAttempts || indexer.processingAttempts < 100)"
                                                 class="umb-healthcheck-group__details-status-action">
                                                <button type="button" class="umb-era-button -blue" ng-click="rebuildIndex(indexer)">Rebuild index</button>
                                            </div>

                                            <div ng-show="indexer.processingAttempts >= 100">
                                                The process is taking longer than expected, check the umbraco log to see if there have been any errors during this operation
                                            </div>
                                        </div>
                                        <table class="table table-bordered table-condensed">
                                            <caption>&nbsp;</caption>
                                            <tr>
                                                <th>Documents in index</th>
                                                <td>{{indexer.documentCount}}</td>
                                            </tr>
                                            <tr>
                                                <th>Fields in index</th>
                                                <td>{{indexer.fieldCount}}</td>
                                            </tr>
                                            <tr>
                                                <th>Has deletions?</th>
                                                <td>
                                                    <span>{{indexer.deletionCount > 0}}</span>
                                                    (<span>{{indexer.deletionCount}}</span>)
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>Optimized?</th>
                                                <td>
                                                    <span>{{indexer.isOptimized}}</span>
                                                </td>
                                            </tr>

                                        </table>
                                    </div>
                                </li>
                                <li ng-show="indexer.indexCriteria.IncludeNodeTypes.length > 0 || indexer.indexCriteria.ExcludeNodeTypes.length > 0 || indexer.indexCriteria.ParentNodeId">
                                    <a href="" ng-click="toggle(indexer, 'showNodeTypes')">Node types</a>
                                    <table ng-show="indexer.showNodeTypes" class="table table-bordered table-condensed">
                                        <tr ng-show="indexer.indexCriteria.IncludeNodeTypes.length > 0">
                                            <th>Include node types</th>
                                            <td>{{indexer.indexCriteria.IncludeNodeTypes | json}}</td>
                                        </tr>
                                        <tr ng-show="indexer.indexCriteria.ExcludeNodeTypes.length > 0">
                                            <th>Exclude node types</th>
                                            <td>{{indexer.indexCriteria.ExcludeNodeTypes | json}}</td>
                                        </tr>
                                        <tr ng-show="indexer.indexCriteria.ParentNodeId">
                                            <th>Parent node id</th>
                                            <td>{{indexer.indexCriteria.ParentNodeId}}</td>
                                        </tr>
                                    </table>
                                </li>
                                <li ng-show="indexer.indexCriteria.StandardFields.length > 0">
                                    <a href="" ng-click="toggle(indexer, 'showSystemFields')">System fields</a>
                                    <table ng-show="indexer.showSystemFields" class="table table-bordered table-condensed">
                                        <caption>&nbsp;</caption>
                                        <thead>
                                            <tr>
                                                <th>Name</th>
                                                <th>Enable sorting</th>
                                                <th>Type</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr ng-repeat="field in indexer.indexCriteria.StandardFields">
                                                <th>{{field.Name}}</th>
                                                <td>{{field.EnableSorting}}</td>
                                                <td>{{field.Type}}</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </li>
                                <li ng-show="indexer.indexCriteria.UserFields.length > 0">
                                    <a href="" ng-click="toggle(indexer, 'showUserFields')">User fields</a>
                                    <table ng-show="indexer.showUserFields" class="table table-bordered table-condensed">
                                        <caption>&nbsp;</caption>
                                        <thead>
                                            <tr>
                                                <th>Name</th>
                                                <th>Enable sorting</th>
                                                <th>Type</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr ng-repeat="field in indexer.indexCriteria.UserFields">
                                                <th>{{field.Name}}</th>
                                                <td>{{field.EnableSorting}}</td>
                                                <td>{{field.Type}}</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </li>
                                <li>
                                    <a href="" ng-click="toggle(indexer, 'showProviderProperties')">Provider properties</a>
                                    <table ng-show="indexer.showProviderProperties" class="table table-bordered table-condensed">
                                        <caption>&nbsp;</caption>
                                        <tr ng-repeat="(key, val) in indexer.providerProperties track by $index">
                                            <th>{{key}}</th>
                                            <td>{{val}}</td>
                                        </tr>
                                    </table>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <div ng-show="indexer.isProcessing">
                        <div class="umb-healthcheck-group__details-status-overlay"></div>
                        <umb-load-indicator></umb-load-indicator>
                    </div>
                </div>
            </div>
        </div>

        <br />

        <div class="umb-healthcheck-group__details-group-title">
            <div class="umb-healthcheck-group__details-group-name">Searchers</div>
        </div>

        <div class="umb-healthcheck-group__details-checks">
            <div class="umb-healthcheck-group__details-check">
                <div class="umb-healthcheck-group__details-check-title">
                    <div class="umb-healthcheck-group__details-check-name">Search indexes</div>
                    <div class="umb-healthcheck-group__details-check-description">Allows you to search the indexes and view the searcher properties</div>
                </div>

                <div class="umb-healthcheck-group__details-status" ng-repeat="searcher in searcherDetails">

                    <div class="umb-healthcheck-group__details-status-icon-container">
                        <i class="umb-healthcheck-status-icon icon-info"></i>
                    </div>
                    
                    <div class="umb-healthcheck-group__details-status-content">
                        <div class="umb-healthcheck-group__details-status-text">
                            <a class="btn-link -underline" href="" ng-click="toggle(searcher, 'showProperties')">
                                {{searcher.name}}
                            </a>
                        </div>
                        
                        <div class="umb-healthcheck-group__details-status-actions" ng-show="searcher.showProperties">
                            <ul>
                                <li class="search-tools">

                                    <a href="" ng-click="toggle(searcher, 'showTools')">Search tools</a>

                                    <div ng-show="searcher.showTools">
                                        <a class="hide" href="" ng-click="closeSearch(searcher)" ng-show="searcher.isSearching">Hide search results</a>

                                        <br />

                                        <form>

                                            <div class="row form-search">
                                                <div class="span8 input-append">
                                                    <input type="text" class="search-query" ng-model="searcher.searchText" no-dirty-check />
                                                    <button type="submit" class="btn btn-info" ng-click="search(searcher)" ng-disabled="searcher.isProcessing">Search</button>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <label for="{{searcher.name}}-textSearch" class="radio inline">
                                                    <input type="radio" name="searchType" id="{{searcher.name}}-textSearch" value="text" ng-model="searcher.searchType" no-dirty-check />
                                                    Text Search
                                                </label>
                                                <label for="{{searcher.name}}-luceneSearch" class="radio inline">
                                                    <input type="radio" name="searchType" id="{{searcher.name}}-luceneSearch" value="lucene" ng-model="searcher.searchType" no-dirty-check />
                                                    Lucene Search
                                                </label>
                                            </div>


                                        </form>

                                        <div class="search-results" ng-show="searcher.isSearching">

                                            <div ng-show="indexer.isProcessing" class="umb-loader-wrapper" ng-show="indexer.isProcessing">
                                                <div class="umb-loader"></div>
                                            </div>

                                            <table ng-hide="searcher.isProcessing" class="table table-bordered table-condensed">
                                                <thead>
                                                    <tr>
                                                        <th class="score">Score</th>
                                                        <th class="id">Id</th>
                                                        <th>Values</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr ng-repeat="result in searcher.searchResults">
                                                        <td>{{result.Score}}</td>
                                                        <td>{{result.Id}}</td>
                                                        <td>
                                                            <span ng-repeat="(key,val) in result.Fields track by $index">
                                                                <span class=""><em>{{key}}</em>:</span>
                                                                <span class="text-info">{{val}}</span>
                                                            </span>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </li>
                                <li>
                                    <a href="" ng-click="toggle(searcher, 'showProviderProperties')">Provider properties</a>
                                    <table ng-show="searcher.showProviderProperties" class="table table-bordered table-condensed">
                                        <caption>&nbsp;</caption>
                                        <tr ng-repeat="(key, val) in searcher.providerProperties track by $index">
                                            <th>{{key}}</th>
                                            <td>{{val}}</td>
                                        </tr>
                                    </table>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>


    </div>



</div>
