summaryrefslogtreecommitdiff
path: root/app/views/forums/index.html.erb
blob: ba9011788bd05be98b086d6fde36b0e8289115e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<% title "Forums" %>

<%= link_to "All Threads", forumthreads_path, class: "btn blue right" %>
<br>
<div id="forum_groups">
  <% @groups.each do |group| %>
    <div class="item-group" id="group-<%= group.id %>">
      <div class="header">
        <%= group.name %>
        <%= link_to "edit", edit_forumgroup_path(group), class: "editlink" if admin? %>
        <div class="clear-right"></div>
      </div>

      <div class="items bold">
        <% group.forums.sort_by{ |f| f.position || 0 }.each do |f| %>
          <% if f.can_view?(current_user) %>
            <div class="item">
              <%= link_to f.name, f, id: "forum-#{f.id}"%>
              <div class="item-info">
                <% if last_thread = f.threads.last %>
                  <% last_reply = Threadreply.where(forumthread: f.threads).order(:id).last %>
                  <% if last_reply && last_reply.created_at > last_thread.created_at %>
                    <% if last_reply.thread.can_read?(current_user) %>
                      <%= last_reply.author.name %>
                      <%
                        position = last_reply.thread.replies.count - 1
                        page     = position / Kaminari.config.default_per_page + 1
                      %>
                      <%= link_to "replied", forumthread_path(last_reply.thread, page: page) + "#reply-#{last_reply.id}" %>
                      <%= ago last_reply.created_at %>.
                    <% else %>
                      Hidden
                    <% end %>
                  <% else %>
                    <% if last_thread.can_read?(current_user) %>
                      <%= last_thread.author.name %>
                      <%= link_to "posted", forumthread_path(last_thread) %>
                      <%= ago last_thread.created_at %>.
                    <% else %>
                      Hidden
                    <% end %>
                  <% end %>
                <% else %>
                  No posts yet.
                <% end %>
              </div>
              <div class="clear"></div>
            </div>
          <% end %>
        <% end %>
      </div>

    </div>
  <% end %>
</div>

<% if admin? %>
  <%= link_to "New group", new_forumgroup_path, class: "btn blue" %>
<% elsif mod? %>
  <%= link_to "New group", "#", class: "btn blue", disabled: true %>
<% end %>