<!-- Modal postinstall confirm -->
<div class="modal fade" id="appPostInstallConfirmModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <img ng-src="{{appPostInstallConfirm.app.iconUrl}}" onerror="this.onerror=null;this.src='img/appicon_fallback.png'" class="app-info-icon"/>
        <h5 class="app-info-title">
          {{ appPostInstallConfirm.app.manifest.title }}
          <span class="app-info-meta text-small">{{ 'app.appInfo.package' | tr }} <a ng-href="/#/appstore/{{appPostInstallConfirm.app.manifest.id}}?version={{appPostInstallConfirm.app.manifest.version}}">v{{ appPostInstallConfirm.app.manifest.version }}</a> </span>
          <br/>
          <span ng-show="appPostInstallConfirm.app.manifest.documentationUrl"><a target="_blank" ng-href="{{appPostInstallConfirm.app.manifest.documentationUrl}}">{{ 'app.docsAction' | tr }}</a> </span>
          <br/>
        </h5>
      </div>
      <div class="modal-body">
        <p ng-show="appPostInstallConfirm.app.manifest.addons.email">{{ 'app.appInfo.ssoEmail' | tr }}</p>
        <p ng-show="appPostInstallConfirm.app.sso && !appPostInstallConfirm.app.manifest.addons.email">{{ 'app.appInfo.sso' | tr }}</p>

        <div ng-bind-html="appPostInstallConfirm.app.manifest.postInstallMessage | markdown2html"></div>
        <div ng-show="appPostInstallConfirm.app.manifest.documentationUrl" ng-bind-html="'app.appInfo.appDocsUrl' | tr:{ docsUrl: appPostInstallConfirm.app.manifest.documentationUrl, title: appPostInstallConfirm.app.manifest.title, forumUrl: (appPostInstallConfirm.app.manifest.forumUrl || 'https://forum.cloudron.io') }"></div>
      </div>
      <div class="modal-footer">
        <div class="form-group pull-left">
          <input type="checkbox" id="appPostInstallConfirmCheckbox" ng-model="appPostInstallConfirm.confirmed">
          <label class="control-label" for="appPostInstallConfirmCheckbox">{{ 'app.appInfo.postInstallConfirmCheckbox' | tr }}</label>
        </div>
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.close' | tr }}</button>
        <a class="btn btn-success" ng-href="{{ appPostInstallConfirm.confirmed ? ('https://' + appPostInstallConfirm.app.fqdn) : '' }}" target="_blank" ng-disabled="!appPostInstallConfirm.confirmed" ng-click="appPostInstallConfirm.submit()">{{ 'app.appInfo.openAction' | tr:{ app: appPostInstallConfirm.app.manifest.title } }}</a>
      </div>
    </div>
  </div>
</div>

<!-- Modal app info -->
<div class="modal fade" id="appInfoModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <img ng-src="{{appInfo.app.iconUrl}}" onerror="this.onerror=null;this.src='img/appicon_fallback.png'" class="app-info-icon" style="padding-right: 10px;"/>
        <h4 style="margin-top: 0;">
          {{ appInfo.app.manifest.title }}
          <br/>
          <span class="text-small text-muted">{{ 'app.appInfo.package' | tr }} <a ng-href="/#/appstore/{{appInfo.app.manifest.id}}?version={{appInfo.app.manifest.version}}">v{{ appInfo.app.manifest.version }}</a></span>
          <br/>
          <span class="text-small text-muted" ng-show="appInfo.app.upstreamVersion">App v{{ appInfo.app.upstreamVersion }}</a></span>
        </h5>
      </div>
      <div class="modal-body">
        <p ng-hide="appInfo.app.appStoreId" ng-bind-html="'app.appInfo.customAppUpdateWarning' | tr:{ docsLink: 'https://docs.cloudron.io/custom-apps/tutorial/' }"></p>
        <p ng-show="appInfo.app.manifest.documentationUrl" ng-bind-html="'app.appInfo.appDocsUrl' | tr:{ docsUrl: appInfo.app.manifest.documentationUrl, title: appInfo.app.manifest.title, forumUrl: (appInfo.app.manifest.forumUrl || 'https://forum.cloudron.io') }"></p>

        <p ng-show="appInfo.app.manifest.addons.email">{{ 'app.appInfo.ssoEmail' | tr }}</p>
        <p ng-show="appInfo.app.sso && !appInfo.app.manifest.addons.email">{{ 'app.appInfo.sso' | tr }}</p>

        <a ng-show="appInfo.app.manifest.postInstallMessage" href="" data-toggle="collapse" data-parent="#accordion" data-target="#appinfoPostinstallMessage">
          <i class="fa fa-angle-right"></i> {{ 'app.appInfo.firstTimeCollapseHeader' | tr }}
        </a>

        <div id="appinfoPostinstallMessage" class="panel-collapse collapse">
          <br/>
          <div ng-bind-html="appInfo.app.manifest.postInstallMessage | markdown2html"></div>
        </div>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal">{{ 'main.dialog.close' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<script>
    function imageErrorHandler(elem) {
        'use strict';

        elem.src = elem.getAttribute('fallback-icon');
        elem.onerror = null;    // avoid retry after default icon cannot be loaded
    }
</script>

<div class="content content-large">

    <!-- Workaround for select-all issue, see commit message -->
    <div style="font-size: 1px;">&nbsp;</div>

    <div class="animateMeOpacity ng-hide" ng-show="installedApps.length === 0 && user.isAtLeastAdmin">
      <div class="col-md-12" style="text-align: center;">
        <br/><br/><br/><br/>
        <h1><i class="fa fa-cloud-download fa-fw"></i> {{ 'apps.noApps.title' | tr }}</h1>
        <br/></br>
        <h3 ng-bind-html="'apps.noApps.description' | tr:{ appStoreLink: '#/appstore' }"></h3>
      </div>
    </div>

    <div class="animateMeOpacity ng-hide" ng-show="installedApps.length === 0 && !user.isAtLeastAdmin">
      <div class="col-md-12" style="text-align: center;">
        <br/><br/><br/><br/>
        <h1>{{ 'apps.noAccess.title' | tr }}</h1>
        <br/></br>
        <h3>{{ 'apps.noAccess.description' | tr }}</h3>
      </div>
    </div>

    <div class="animateMeOpacity ng-hide" ng-show="installedApps.length > 0">
      <h1 class="view-header">
        {{ 'apps.title' | tr }}
        <div class="pull-right">
          <form class="form-inline">
            <input type="text" class="form-control" ng-show="installedApps.length > 8" placeholder="{{ 'apps.searchPlaceholder' | tr }}" id="appSearch" ng-model="appSearch"/>
            <multiselect ng-model="selectedGroup" ng-show="installedApps.length > 1 && groups.length > 1" ms-header="{{ selectedGroup.name }}" options="group.name for group in groups" data-multiple="false" filter-after-rows="5" scroll-after-rows="10"></multiselect>
            <multiselect ng-model="selectedState" ng-show="installedApps.length > 1" ms-header="{{ 'apps.stateFilterHeader' | tr }}" ms-selected="{{ selectedState }}" options="state.label for state in states" data-multiple="false"></multiselect>
            <multiselect ng-model="selectedTags" ng-show="tags.length > 0" ms-header="{{ 'apps.tagsFilterHeaderAll' | tr }}" ms-selected="{{ 'apps.tagsFilterHeader' | tr:{ tags: selectedTags.join(', ') } }}" options="tag for tag in tags" data-multiple="true" filter-after-rows="5" scroll-after-rows="10"></multiselect>
            <multiselect ng-model="selectedDomain" ng-show="filterDomains.length > 2" data-compare-by="domain" ms-selected="{{ selectedDomain.domain }}" options="domain.domain for domain in filterDomains" data-multiple="false" filter-after-rows="5" scroll-after-rows="10"></multiselect>
          </form>
        </div>
      </h1>
    </div>

    <div class="animateMeOpacity ng-hide" ng-show="installedApps.length > 0">
      <div class="app-grid">
        <div class="grid-item" ng-repeat="app in installedApps | selectedGroupAccessFilter:selectedGroup | selectedStateFilter:selectedState | selectedTagFilter:selectedTags | selectedDomainFilter:selectedDomain | appSearchFilter:appSearch | orderBy:'fqdn'">
          <a ng-href="{{ app | applicationLink }}" ng-click="user.isAtLeastAdmin && (((app | installError) === true || (app | installationActive) === true) && showAppConfigure(app, 'repair')) || ((app | appIsInstalledAndHealthy) && app.pendingPostInstallConfirmation && appPostInstallConfirm.show(app))" target="_blank" ng-class="{ 'hand': (app | appIsInstalledAndHealthy) || (app | installError)  || (app | installationActive)}">
            <div class="highlight grid-item-content" uib-tooltip="{{ app.fqdn }}" tooltip-class="long nowrap">
              <div class="grid-item-top">
                <div class="row">
                  <div class="col-xs-12 text-center" style="padding-left: 5px; padding-right: 5px;">
                    <br/>
                    <img ng-src="{{ app.iconUrl || 'img/appicon_fallback.png' }}" fallback-icon="img/appicon_fallback.png" onerror="imageErrorHandler(this)" class="app-icon"/>
                  </div>
                </div>
                <br/>
                <div class="row">
                  <div class="col-xs-12 text-center">
                    <div class="grid-item-top-title" data-fittext>{{ app.label || app.location || app.fqdn }}</div>
                    <div class="text-muted status" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden" uib-tooltip="{{ app | appProgressMessage }}" tooltip-class="long nowrap">
                      {{ app | installationStateLabel }}
                    </div>
                    <div class="status" ng-style="{ 'visibility': user.isAtLeastAdmin && (app | installationActive) ? 'visible' : 'hidden' }">
                      <div class="progress progress-striped active">
                        <div class="progress-bar progress-bar-success" role="progressbar" style="width: {{ app.progress }}%"></div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <div class="grid-item-actions" ng-show="user.isAtLeastAdmin">
                <a ng-href="#/app/{{ app.id}}/display" uib-tooltip="{{ 'apps.configActionTooltip' | tr }}" tooltip-placement="right" tooltip-class="grid-items-action-tooltip"><i class="fas fa-cogs"></i></a>
                <a ng-href="{{ '/logs.html?appId=' + app.id }}" target="_blank" uib-tooltip="{{ 'apps.logsActionTooltip' | tr }}" tooltip-placement="right" tooltip-class="grid-items-action-tooltip"><i class="fas fa-align-left"></i></a>
                <a ng-href="" class="hand" ng-click="appInfo.show(app)" uib-tooltip="{{ 'apps.infoActionTooltip' | tr }}" tooltip-placement="right" tooltip-class="grid-items-action-tooltip"><i class="fas fa-info-circle"></i></a>
                <a ng-href="{{ app | applicationLink }}{{ app.manifest.configurePath }}" target="_blank" ng-show="app.manifest.configurePath && (app | applicationLink)" uib-tooltip="{{ 'apps.adminPageActionTooltip' | tr }}" tooltip-placement="right" tooltip-class="grid-items-action-tooltip"><i class="fas fa-external-link-alt"></i></a>
              </div>

              <!-- we check the version here because the box updater does not know when an app gets updated -->
              <div class="app-update-badge" ng-click="showAppConfigure(app, 'updates')" ng-show="config.update[app.id].manifest.version && config.update[app.id].manifest.version !== app.manifest.version && (app | installSuccess)">
                <i class="fa fa-arrow-up fa-inverse"></i>
              </div>
            </div>
          </a>
        </div>
      </div>
    </div>
</div>
