{% extends 'TopxiaAdminBundle::layout.html.twig' %}

{% set script_controller = 'app/installed' %}

{% set menu = 'admin_app_installed' %}

{% block main %}

  <div class="mbl btn-group">

      <a href="{{ url('admin_app_installed', {postStatus: 'all'}) }}" type="button" class="btn btn-default btn-sm {% if type == 'all'%} btn-primary{% endif %}">全部</a>

      <a href=" {{ url('admin_app_installed', {postStatus: 'theme'}) }}" type="button" class="btn btn-default btn-sm {% if type == 'theme'%}btn-primary{% endif %}">主题</a>

      <a href=" {{ url('admin_app_installed', {postStatus: 'app'}) }}" type="button" class="btn btn-default btn-sm {% if type == 'app'%}btn-primary{% endif %}">应用</a>
  </div>

  <table class="table table-striped table-hover">
    <thead>
    </thead>
    <tbody>
      {% if type == 'all' %}
      {% set apps = apps %}
      {% elseif type == 'theme'%}
      {% set apps = theme %}
      {% elseif type == 'app' %}
      {% set apps = plugin %}
      {% endif  %}

      {% for app in apps %}
  
        {% if app.installed|default(0) or app.purchased or (app.userAccess|default(null) == "ok" ) and (app.price == 0 and not  app.licensed ) %}
        <tr>
          <td>
              {% if app.code == "MAIN" %}
                <img src="/assets/img/default/MAIN_icon.png" class="app-img pull-left mrl mtm"/>
              {% else %}
                <img src="http://open.edusoho.com/files/product/{{ app.icon }}" class="app-img pull-left mrl mtm"/>
              {% endif %}
              
            <div class="mtm">
              
                <h4>
                  <a target="_blank" href="http://open.edusoho.com/app/{{ app.code }}"><strong class="text-primary">{{ app.name }}</strong>
                  </a>            
                </h4>     
    
            </div>
            
            <div class="info mtm mbm clearfix">
              <div class="left-info pull-left">

                <div class="text-muted">作者： {{ app.developerName }}</div>
                <div class="mts text-muted">{% if app.type == "theme" %}主题{% else %}应用{% endif %}
                </div>
                <div class="class-rating mtm">
                  {% if app.installed|default(0) %}
                  <span class="text-muted">版本：{{ app.version }}</span>
                  {% else %}
                  <span class="text-muted">版本：{{ app.latestVersion }}</span>
                  {% endif %}
                </div>
              </div>

              <div class="middle-info pull-left ">
                {% if app.installed|default(0) %}
                  <div class="text-muted">最后更新： {{ app.updatedTime|date('Y-m-d') }}</div>
                {% else %}
                  <div class="text-muted">最后更新： {{ app.latestTime|date('Y-m-d') }}</div>
                {% endif %}
              </div>
              
              {% if app.installed|default(0) %}
                  {% if app.code|lower != 'MAIN' %}
                    {% set url = appMeta[app.code].manage_index|default('') %}
                  {% endif %}
              <div class="right-info pull-right">
                  {% if url != '' %}
                  <a href="{{url(url)}}"  class="btn btn-primary">管理</a>
                  {% endif %}

                  {% if setting('developer.debug') and app.code|lower != 'main' %}
                    <br>
                    <a href="javascript:;" data-url="{{ path('admin_app_uninstall', {code:app.code}) }}" class="btn btn-danger uninstall-btn mtm">卸载</a>
                  {% endif %}
              </div>
              {% else %}
              <div class="right-info pull-right">
                  <a href="#" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_app_package_update_modal', {id:app.latestPackageId, type:'install'}) }}" class="btn btn-primary" data-keyboard="false" data-backdrop="static">安装
                  </a>

              </div>
              {% endif %}
            </div>
          </td>
    
        </tr>
        {% endif %}

      {% endfor %}
    </tbody>
  </table>

{% endblock %}