File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,21 +4,36 @@ class PinnedLinksController < ApplicationController
44 before_action :verify_mod_on_current_community , only : [ :edit , :update ]
55
66 def index
7- links = if current_user . at_least_global_moderator? && params [ :global ] == '2'
8- PinnedLink . unscoped
9- elsif current_user . at_least_global_moderator? && params [ :global ] == '1'
10- PinnedLink . where ( community : nil )
11- else
12- PinnedLink . where ( community : @community )
13- end
7+ @period = params [ :period ] . presence || 'present'
8+
9+ @links = if current_user . at_least_global_moderator? && params [ :global ] == '2'
10+ PinnedLink . unscoped
11+ elsif current_user . at_least_global_moderator? && params [ :global ] == '1'
12+ PinnedLink . where ( community : nil )
13+ else
14+ PinnedLink . where ( community : @community )
15+ end
16+
17+ @links = case @period
18+ when 'past'
19+ @links . past
20+ when 'present'
21+ @links . present
22+ when 'future'
23+ @links . future
24+ else
25+ @links
26+ end
27+
1428 @links = case params [ :filter ]
1529 when 'all'
16- links . all
30+ @ links. all
1731 when 'inactive'
18- links . where ( active : false ) . all
32+ @ links. where ( active : false ) . all
1933 else
20- links . where ( active : true ) . all
34+ @ links. where ( active : true ) . all
2135 end
36+
2237 render layout : 'without_sidebar'
2338 end
2439
Original file line number Diff line number Diff line change @@ -7,6 +7,31 @@ class PinnedLink < ApplicationRecord
77 includes ( :post , post : [ :community ] )
88 }
99
10+ # a past link is one that ended in the past
11+ scope :past , lambda {
12+ timed . where ( 'shown_before < ?' , DateTime . now )
13+ }
14+
15+ # a present link is not timed or started in the past and ends in the future
16+ scope :present , lambda {
17+ where ( shown_after : nil , shown_before : nil ) . or (
18+ timed . where ( 'shown_after <= ?' , DateTime . now )
19+ . where ( 'shown_before > ?' , DateTime . now )
20+ )
21+ }
22+
23+ # a future link is one that both starts and ends in the future
24+ scope :future , lambda {
25+ timed . where ( 'shown_after > ?' , DateTime . now )
26+ . where ( 'shown_before > ?' , DateTime . now )
27+ }
28+
29+ scope :timed , lambda {
30+ after = where . not ( shown_after : nil )
31+ before = where . not ( shown_before : nil )
32+ before . or ( after )
33+ }
34+
1035 validate :check_post_or_url
1136
1237 # Is the link time-constrained?
Original file line number Diff line number Diff line change 2828 class : "button is-muted is-outlined #{ ( params [ :filter ] == 'all' ) ? 'is-active' : '' } " %>
2929 </ div >
3030 </ div >
31+ < div class ="grid--cell ">
32+ < div class ="button-list is-gutterless ">
33+ <%= link_to 'past' ,
34+ query_url ( period : 'past' ) ,
35+ class : "button is-muted is-outlined #{ 'is-active' if @period == 'past' } " %>
36+ <%= link_to 'present' ,
37+ query_url ( period : 'present' ) ,
38+ class : "button is-muted is-outlined #{ 'is-active' if @period == 'present' } " %>
39+ <%= link_to 'future' ,
40+ query_url ( period : 'future' ) ,
41+ class : "button is-muted is-outlined #{ 'is-active' if @period == 'future' } " %>
42+ <%= link_to 'any' ,
43+ query_url ( period : 'any' ) ,
44+ class : "button is-muted is-outlined #{ 'is-active' if @period == 'any' } " %>
45+ </ div >
46+ </ div >
3147 < div class ="grid--cell is-flexible ">
3248 </ div >
3349 < div class ="grid--cell ">
You can’t perform that action at this time.
0 commit comments