<div ng-controller="Wizdom365TimerjobController">
    <div ng-show="viewMode == 'timerjobs'">
        <div class="lt-module-page__top lt-module-page-top">
            <div class="lt-module-page-top__title mr-auto">
                <h1>{{'Timerjobs' | translate}}</h1>
            </div>
        </div>

        <div class="panel lt-module-page__content-panel">
            <p>{{'Timerjob status autorefresh every 5 seconds' | translate}}</p>
            <br />
            <div>
                <table class="table">
                    <thead>
                        <tr>
                            <th>{{'Name' | translate}}</th>
                            <th>{{'Status' | translate}}</th>
                            <th>{{'Last run' | translate}}</th>
                            <th>{{'Last completed' | translate}}</th>
                            <th>{{'Interval for scheduled run' | translate}}</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="job in jobs | orderBy : 'name'">
                            <td>{{job.name}}</td>
                            <td>{{job.status}}&nbsp;<span ng-if="!job.enabled">({{'Disabled' | translate}})</span></td>
                            <td><span ng-hide="job.started.indexOf('0001') == 0"> {{job.started | date : 'medium'}}</span></td>
                            <td><span ng-hide="job.ended.indexOf('0001') == 0">{{job.ended | date : 'medium'}}</span></td>
                            <td>
                                <span ng-if="job.intervalInMinutes != job.defaultIntervalInMinutes || job.runFrom || job.runTo">{{'Custom:'}} </span>
                                {{job.scheduleText}}
                                <span ng-if="job.runFrom && job.runTo"> starting between {{job.runFromDateTime | date: 'shortTime'}} and {{job.runToDateTime | date: 'shortTime'}}</span>
                                <span ng-if="job.runFrom && !job.runTo"> starting after {{job.runFromDateTime | date: 'shortTime'}}</span>
                                <span ng-if="!job.runFrom && job.runTo"> starting before {{job.runToDateTime | date: 'shortTime'}}</span>
                            </td>
                            <td>
                                <div class="d-flex">
                                    <a href="" class="btn btn-default btn-sm" ng-click="runJob(job)">{{'Run now' | translate}}</a>
                                    <a href="" class="btn btn-default btn-sm" ng-click="getLogs(job)">{{'Show logs' | translate}}</a>
                                    <a href="" class="btn btn-default btn-sm" ng-click="editJob(job)">{{'Edit' | translate}}</a>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>

                <wizdom365-spinner loading="loading"></wizdom365-spinner>
            </div>
        </div>
    </div>
    <div ng-show="viewMode == 'logs'">
        <div class="lt-module-page__top lt-module-page-top">
            <div class="lt-module-page-top__title mr-auto">
                <h1>{{'Timerjobs' | translate}}</h1>
            </div>
            <div class="lt-module-page-top__actions">
                <a href="" class="btn btn-primary" ng-click="viewMode = 'timerjobs'">
                    <i class="streamline icon-arrow-left-1"></i>
                    <span>{{'Back to timerjobs' | translate}}</span>
                </a>
                <a href="" class="btn btn-primary" ng-click="runJob(job)">
                    <span>{{'Run now' | translate}}</span>
                    <i class="streamline icon-arrow-right"></i>
                </a>
            </div>
        </div>

        <div class="panel lt-module-page__content-panel">
            <div class="panel-heading">
                {{'Logs for' | translate}} {{job.name}}
            </div>
            <pre>
                {{job.lastRunLog}}
            </pre>
            <wizdom365-spinner loading="loading"></wizdom365-spinner>
        </div>
    </div>
</div>

