<% @rss_feeds = {'All projects' => {:controller => 'projects', :action => 'index', :format => 'rss'}} %>
<% @projects.each { |p| @rss_feeds["#{p.name} builds"] = "/projects/${p.id}?format=rss" } %>

<div id="projects">
  <% @projects.each_with_index do |project, seq| %>
      <% next if project.respond_to?("is_legacy?") && project.is_legacy? %>
			<% next if current_user.nil? && !project.public_viewable %>
			<% if !project.public_viewable %>
			
				<% if (current_user.is_admin? || current_user.has_role?(:builder, project) || current_user.has_role?(:team_member, project))  %>								
					<%= partial(:'projects/project', :locals => {:project => project, :seq => seq}) %>
				<% end %>

			<% else %>	

					<%= partial(:'projects/project', :locals => {:project => project, :seq => seq}) %>
			
			<% end %>
					
  <% end %>

  <% if @projects.empty? %>
      <div id="no_projects_help">
        <div style="padding: 1em;">
          <p>
            <%= I18n.t(:no_projects_under_buildwise_home )%>:            
            [<code><%= h File.join(BUILDWISE_HOME) %></code>].
          </p>
          <div>
						<a href="/projects/new" class="btn btn-default btn-success" id="new_project_link" style="text-shadow: none;"><%= I18n.t(:create_new_project)%></a>
					</div>
        </div>
      </div>

      <div style="margin-left: 20px; margin-bottom: 10px;">Supported Source Control Systems:<strong> Git</strong>.
<!--
        <ul>
          <% $supported_scms.each do |name, value| %>
              <% if value %>
                  <li><%= name.humanize %></li>
              <% end %>
          <% end %>
        </ul>
        <span class="instruction"><%= I18n.t(:scm_check_intro) %></span>
-->		  
      </div>

  <% end %>
  
  
  <div id="more-projects-on-load">
  </div>
  
</div>

<!-- streaming sinatra, to append to data div -->
<% if @all_projects && @project_per_page && @all_projects.size > @project_per_page  %>
  <div class="d-flex justify-content-center mt-4" style="margin: 10px;">
    <input type="hidden" id="offset" value="<%= @offset %>"/>    
    <button type="button" id="load-more-projects-btn" onclick="load_more();" class="btn btn-success">Load More ... <i id="load-project-spinner" class="fa fa-spinner fa-spin fa-lg fa-fw" aria-hidden="true" style="display:none;"></i></button>
  </div>
<% end %>

  
<!-- for easier to check log 
call 
  periodically_call_remote :url => { :action => 'index', :format => 'js'}, :method => 'get',
-->

<script type="text/javascript">
	
	$(document).ready(function() {	
	  $('select').select2();	
	});
	
  function load_more() {
    $("#load-project-spinner").show();
    var offset = $("#offset").val();
    $.getScript("/projects/load_more?offset=" + offset);
  }
  
</script>