<!-- Modal service configure -->
<div class="modal fade" id="serviceConfigureModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'services.configure.title' | tr:{ name: serviceConfigure.service.displayName } }}</h4>
      </div>
      <div class="modal-body">
        <form name="serviceConfigureForm" role="form" novalidate ng-submit="serviceConfigure.submit()" autocomplete="off">
          <fieldset>
            <p class="has-error text-center" ng-show="serviceConfigure.error">{{ serviceConfigure.error }}</p>

            <div class="form-group">
              <label class="control-label" style="display: block;" for="memoryLimit">
                {{ 'services.memoryLimit' | tr }}: <b>{{ serviceConfigure.memoryLimit / 1024 / 1024 + 'MB' }}</b>
                <button type="button" class="btn btn-xs btn-default pull-right" ng-click="serviceConfigure.resetToDefaults()">{{ 'services.configure.resetToDefaults' | tr }}</button>
              </label>
              <div style="padding: 0 10px;">
                <slider id="memoryLimit" ng-model="serviceConfigure.memoryLimit" step="134217728" tooltip="hide" ticks="serviceConfigure.memoryTicks" ticks-snap-bounds="67108864"></slider>
              </div>
            </div>

            <div class="form-group" ng-show="serviceConfigure.service.name === 'sftp'">
              <br>
              <label class="control-label">{{ 'services.configure.accessControl' | tr }}</label>
              <p class="small">{{ 'services.configure.accessControlDescription' | tr }}</p>
              <div class="checkbox">
                <label>
                  <input type="checkbox" ng-model="serviceConfigure.requireAdmin"> {{ 'services.configure.requireAdminRoleLabel' | tr }}</input>
                </label>
              </div>
            </div>

            <input class="ng-hide" type="submit" ng-disabled="serviceConfigureForm.$invalid || serviceConfigure.busy"/>
          </fieldset>
        </form>
      </div>
      <div class="modal-footer ">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="submit" class="btn btn-outline btn-success pull-right" ng-click="serviceConfigure.submit(serviceConfigure.memoryLimit)" ng-disabled="serviceConfigureForm.$invalid || serviceConfigure.busy"><i class="fa fa-circle-notch fa-spin" ng-show="serviceConfigure.busy"></i> {{ 'main.dialog.save' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<div class="content">

  <div class="text-left">
    <h1>{{ 'services.title' | tr }}
    <button class="btn btn-default pull-right" ng-click="refreshAll()">{{ 'services.refresh' | tr }}</button>
  </div>

  <div class="card" style="margin-bottom: 15px;">
    <div class="row">
      <div class="col-md-12">
        <p>{{ 'services.description' | tr }}</p>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <div class="row ng-hide" ng-show="!servicesReady">
          <div class="col-md-12 text-center">
            <h2><i class="fa fa-circle-notch fa-spin"></i></h2>
          </div>
        </div>
        <div class="row animateMeOpacity ng-hide" ng-show="servicesReady">
          <div class="col-md-12">
            <table class="table table-hover">
              <thead>
                <tr>
                  <th style="width: 5%;"></th>
                  <th style="width: 20%">{{ 'services.service' | tr }}</th>
                  <th style="width: 50%">{{ 'services.memoryUsage' | tr }}</th>
                  <th style="width: 20%" class="text-center">{{ 'services.memoryLimit' | tr }}</th>
                  <th style="width: 5%" class="text-right">{{ 'main.actions' | tr }}</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td><i class="fa fa-circle" uib-tooltip="active" style="color: #27CE65"></i></td>
                  <td class="elide-table-cell">cloudron</td>
                  <td class="elide-table-cell"></td>
                  <td class="elide-table-cell text-center"></td>
                  <td class="text-right no-wrap" style="vertical-align: bottom">
                    <a class="btn btn-xs btn-default" href="/logs.html?id=box" target="_blank" uib-tooltip="{{ 'logs.title' | tr }}"><i class="fa fa-file-alt"></i></a>
                  </td>
                </tr>
                <tr ng-repeat="service in services | filter:{ isRedis: false } | orderBy:'name'">
                  <td>
                    <i class="fa fa-circle" uib-tooltip="{{ service.status }}" ng-style="{ color: service.status === 'active' ? '#27CE65' : (service.status === 'starting' ? '#f0ad4e' : '#d9534f') }" ng-show="service.status"></i>
                    <i class="fa fa-circle-notch fa-spin" ng-hide="service.status"></i>
                  </td>
                  <td class="elide-table-cell">
                    {{ service.displayName }}
                  </td>
                  <td class="elide-table-cell">
                    <div class="progress progress-striped" ng-show="service.config.memoryLimit">
                      <div class="progress-bar progress-bar-success" role="progressbar" style="width: {{ service.memoryPercent }}%"></div>
                    </div>
                  </td>
                  <td class="elide-table-cell text-center">
                    <span ng-show="service.config.memoryLimit">{{ service.config.memoryLimit | prettyByteSize }}</span>
                  </td>
                  <td class="text-right no-wrap" style="vertical-align: bottom">
                    <button class="btn btn-xs btn-default" ng-click="serviceConfigure.show(service)" uib-tooltip="{{ 'services.configureActionTooltip' | tr }}" ng-show="service.config.memoryLimit"><i class="fa fa-pencil-alt"></i></button>
                    <button class="btn btn-xs btn-default" ng-click="restartService(service.name)" uib-tooltip="{{ 'services.restartActionTooltip' | tr }}"><i class="fa fa-sync-alt" ng-class="{ 'fa-spin': service.status === 'starting' }"></i></button>
                    <a class="btn btn-xs btn-default" ng-href="{{ '/logs.html?id=' + service.name }}" target="_blank" uib-tooltip="{{ 'logs.title' | tr }}"><i class="fa fa-file-alt"></i></a>
                  </td>
                </tr>
                <tr ng-show="hasRedisServices" ng-click="redisServicesExpanded = !redisServicesExpanded" class="hand">
                  <td>
                    <i class="fas fa-angle-right" ng-class="{'fa-rotate-90': redisServicesExpanded }"></i>
                  </td>
                  <td colspan="4">redis</td>
                </tr>
                <tr ng-show="redisServicesExpanded" ng-repeat="service in services | filter:{ isRedis: true } | orderBy:'name'">
                  <td>
                    <i class="fa fa-circle" uib-tooltip="{{ service.status }}" ng-style="{ color: service.status === 'active' ? '#27CE65' : (service.status === 'starting' ? '#f0ad4e' : '#d9534f') }" ng-show="service.status"></i>
                    <i class="fa fa-circle-notch fa-spin" ng-hide="service.status"></i>
                  </td>
                  <td class="elide-table-cell">
                    {{ service.displayName }}
                  </td>
                  <td class="elide-table-cell">
                    <div class="progress progress-striped" ng-show="service.config.memoryLimit">
                      <div class="progress-bar progress-bar-success" role="progressbar" style="width: {{ service.memoryPercent }}%"></div>
                    </div>
                  </td>
                  <td class="elide-table-cell text-center">
                    <span ng-show="service.config.memoryLimit">{{ service.config.memoryLimit | prettyByteSize }}</span>
                  </td>
                  <td class="text-right no-wrap" style="vertical-align: bottom">
                    <button class="btn btn-xs btn-default" ng-click="serviceConfigure.show(service)" uib-tooltip="{{ 'services.configureActionTooltip' | tr }}" ng-show="service.config.memoryLimit"><i class="fa fa-pencil-alt"></i></button>
                    <button class="btn btn-xs btn-default" ng-click="restartService(service.name)" uib-tooltip="{{ 'services.restartActionTooltip' | tr }}"><i class="fa fa-sync-alt" ng-class="{ 'fa-spin': service.status === 'starting' }"></i></button>
                    <a class="btn btn-xs btn-default" ng-href="{{ '/logs.html?id=' + service.name }}" target="_blank" uib-tooltip="{{ 'logs.title' | tr }}"><i class="fa fa-file-alt"></i></a>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
