<!--
  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 class="no-activities" ng-if="tasks.length === 0">No activities</div>
<div ng-if="tasks.length !== 0" class="task-list">
    <div class="form-group search-bar-with-controls">
        <div class="btn-group activity-tag-filter" uib-dropdown keyboard-nav="true" dropdown-append-to="model.appendTo">
            <button id="single-button" type="button" class="btn btn-default" uib-dropdown-toggle>
                Displaying <kbd>{{model.filterByTag | lowercase}}</kbd> <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="single-button">
                <li role="menuitem" class="activity-tag-filter-tag" ng-repeat="(tag,value) in filters track by tag" ng-model="model.filterByTag" uib-btn-radio="tag">
                    {{tag | lowercase}}</span> <span class="badge">{{value}}</span>
                </li>
            </ul>
        </div>

        <input type="text" class="form-control activity-name-filter" placeholder="Filter by name" ng-model="filterValue" />
    </div>
    
    <div class="table-responsive activity-table">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th>
                    Status
                </th>
                <th>
                    Activity
                </th>
                <th>
                    Started
                </th>
                <th>
                    Duration
                </th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="task in tasks | activityTagFilter : model.filterByTag | activityFilter:filterValue as filterResult track by task.id">
                <td class="status">
                    <a ui-sref="main.inspect.activities.detail({entityId: task.entityId, activityId: task.id})">
                    <brooklyn-status-icon value="{{task.currentStatus}}"></brooklyn-status-icon>
                    </a>
                </td>
                <td class="name">
                    <a ui-sref="main.inspect.activities.detail({entityId: task.entityId, activityId: task.id})">{{task.displayName}}
                    </a>
                </td>
                <td class="started">
                    <a ui-sref="main.inspect.activities.detail({entityId: task.entityId, activityId: task.id})">
                        {{task.startTimeUtc | timeAgoFilter}}
                    </a>
                </td>
                <td class="duration">
                    <a ui-sref="main.inspect.activities.detail({entityId: task.entityId, activityId: task.id})"
                        	ng-if="task.startTimeUtc">
                        {{getTaskDuration(task) | durationFilter}} <span ng-if="task.endTimeUtc === null">and counting</span>
                    </a>
                </td>
            </tr>
            <tr ng-if="filterResult.length == 0 ">
                <td colspan="4" class="text-center"><h4>
                    No tasks found matching
                    <span ng-if="filterValue">current filter <code>{{filterValue}}</code> and</span>
                    type <code>{{model.filterByTag | lowercase}}</code>
                </h4></td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
