{# Copyright (c) 2016, NVIDIA CORPORATION.  All rights reserved. #}
<!-- Pretrained Model -->
<style>
 #models-table > thead > tr > th:nth-child(1) {
     width: 100%
 }
</style>

<div class="col-md-12" ng-show="tab.isSet(3)">
    <div class="row">
        <div class="col-xs-12">
            <div class="pull-right">
                Load Model
                <ul class="nav nav-pills">
                    {% for category in load_model_options.keys()|sort %}
                    {% set options = load_model_options[category] %}
                    <li class="dropdown active">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            {{category}} <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            {% for id in options.keys()|sort %}
                            {% set option = options[id] %}
                            <li><a id="{{option["id"]}}" href="{{option["url"]}}">{{option["title"]}}</a></li>
                            {% endfor %}
                        </ul>
                    </li>
                    {% endfor %}
                </ul>
            </div>
            <div style="position:absolute; bottom:0">
                <label>Group Jobs:
                    <input type="checkbox"
                           ng-model="jc.storage.show_groups">
                </label>
            </div>
        </div>
    </div>
    <div class="well">
        <div ng-controller="pretrained_models_controller as c">
            {[ jobs = (jc.pretrained_model_jobs | filter:search_text | sort_with_empty_at_end:this:jc.storage.show_groups); '' ]}
            <div class="row">
                <div class="col-xs-12">
                    <!-- Filter -->
                    <div class="pull-right">
                        <form>
                            <div class="form-group">
                                <div class="input-group">
                                    <div class="input-group-addon"><i class="glyphicon glyphicon-search"></i></div>
                                    <input type="text" class="form-control" placeholder="Filter" ng-model="search_text">
                                </div>
                            </div>
                        </form>
                    </div>
                    {[enabled = any_selected();'']}
                    {[group_enabled = jc.storage.show_groups && enabled;'']}
                    <!-- Delete Button -->
                    <a class="btn btn-xs btn-danger"
                       ng-disabled="!enabled"
                       ng-click="!enabled || delete_jobs();">
                        Delete
                    </a>
                    <a class="btn btn-xs btn-primary"
                       ng-disabled="!group_enabled"
                       ng-click="!group_enabled || group_jobs();">
                        Group
                    </a>
                </div>
            </div>
            <table id="pretrained-models-table"
                   ng-mouseleave="mouseleave()"
                   class="table table-bordered table-striped list-group selectable"
                   width="100%">
                <col ng-repeat="field in fields"
                     ng-style="$index == 0 ? '{}' : {'width':visualLength(field.name, field.min_width) + 'px'}">
                <thead>
                    <tr>
                        <th ng-repeat="field in fields">
                            <div ng-click="change_sorting(field.name, $event)">
                                <small>
                                    {[ field.name ]}
                                </small>
                                <i class="glyphicon"
                                   ng-class="get_icon(field.name)" style="width:14px">
                                </i>
                            </div>
                        </th>
                    </tr>
                </thead>
                <tbody ng-if="jobs.length">
                    <tr ng-repeat-start="job in jobs"
                        ng-hide="true">
                    </tr>
                    <!-- group bar -->
                    <tr class="unselectable group-bar"
                        ng-if="jc.storage.show_groups && ($first || jobs[$index-1].group != job.group)">
                        <td colspan="{[ fields.length ]}" style="background-color:#cccccc">
                            <div ng-click="c.hideRows[job.group] = !c.hideRows[job.group];">
                                <span class="glyphicon"
                                      ng-class="c.hideRows[job.group] ? 'glyphicon-triangle-right' : 'glyphicon-triangle-bottom'">
                                </span>
                                <strong>{[ job.group ? job.group : 'Ungrouped' ]}</strong>
                            </div>
                        </td>
                    </tr>

                    <!-- job rows -->
                    <tr ng-attr-id="{[ job.id ]}"
                        tabindex="0"
                        ng-hide="c.hideRows[job.group]"
                        ng-mousedown="mousedown($index, $event)"
                        ng-mousemove="mousemove($index, $event)"
                        ng-mouseup="mouseup($index, $event)"
                        ng-click="click($index, $event)"
                        ng-keydown="keydown($event)"
                        ng-class="{selected:job.selected}">
                        <td ng-bind="job.name"></td>
                        <td><dg-framework></dg-framework></td>
                        <td ng-bind-html="job.username|html"></td>
                        <td><dg-has-labels></dg-has-labels></td>
                        <td class="text-{[job.status_css]}">
                            {[ job.status ]}
                        </td>
                        <td start="{[job.elapsed]}">
                            <small title="{[ print_time_diff(job.elapsed) ]}">
                                {[ print_time_diff_terse(job.elapsed) ]}
                            </small>
                        </td>
                        <td start="{[job.submitted]}">
                            <small ng-if="!is_today(job.submitted)"
                                   title="{[ job.submitted * 1000 | date:'medium' ]}">
                                {[ job.submitted * 1000 | date:'MMM d, yy' ]}
                            </small>
                            <small ng-if="is_today(job.submitted)"
                                   title="{[ job.submitted * 1000 | date:'medium' ]}">
                                {[ job.submitted * 1000 | date:'h:mm a' ]}
                            </small>
                        </td>
                    </tr>
                    <tr ng-repeat-end
                        ng-hide="true">
                    </tr>
                </tbody>
                <tbody ng-if="jobs.length == 0">
                    <tr>
                        <td colspan="{[fields.length]}">
                            <h5>
                                No Pretrained Models
                            </h5>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
