UX: display expired events

UX: display expired events

diff --git a/app/models/discourse_calendar/post_event.rb b/app/models/discourse_calendar/post_event.rb
index 8392cb0..420efdf 100644
--- a/app/models/discourse_calendar/post_event.rb
+++ b/app/models/discourse_calendar/post_event.rb
@@ -135,11 +135,34 @@ module DiscourseCalendar
     end
 
     def can_user_update_attendance(user)
+      !self.is_expired? &&
       self.post.user != user &&
-      self.status == PostEvent.statuses[:public] ||
       (
-        self.status == PostEvent.statuses[:private] &&
-        self.invitees.exists?(user_id: user.id)
+        self.status == PostEvent.statuses[:public] ||
+        (
+          self.status == PostEvent.statuses[:private] &&
+          self.invitees.exists?(user_id: user.id)
+        )
+      )
+    end
+
+    def is_expired?
+      Time.now > (self.ends_at || self.starts_at)
+    end
+
+    def display_invitees?(current_user)
+      !self.is_expired? &&
+      self.status != PostEvent.statuses[:standalone] &&
+      (
+        self.display_invitees == PostEvent.display_invitees_options[:everyone] ||
+        (
+          self.display_invitees == PostEvent.display_invitees_options[:invitees_only] &&
+          self.invitees.exists?(user_id: current_user.id)
+        ) ||
+        (
+          self.display_invitees == PostEvent.display_invitees_options[:none] &&
+          self.post.user == current_user
+        )
       )
     end
   end
diff --git a/app/serializers/discourse_calendar/post_event_serializer.rb b/app/serializers/discourse_calendar/post_event_serializer.rb
index 0beccc7..a9cbe79 100644
--- a/app/serializers/discourse_calendar/post_event_serializer.rb
+++ b/app/serializers/discourse_calendar/post_event_serializer.rb
@@ -17,11 +17,16 @@ module DiscourseCalendar
     attributes :name
     attributes :can_act_on_post_event
     attributes :can_update_attendance
+    attributes :is_expired
 
     def can_act_on_post_event
       scope.can_act_on_post_event?(object)
     end
 
+    def is_expired
+      object.is_expired?
+    end
+
     def status
       PostEvent.statuses[object.status]
     end
@@ -41,7 +46,7 @@ module DiscourseCalendar
     end
 
     def should_display_invitees
-      display_invitees?
+      object.display_invitees?(scope.current_user)
     end
 
     def can_update_attendance
@@ -56,10 +61,6 @@ module DiscourseCalendar
       BasicUserSerializer.new(object.post.user, embed: :objects, root: false)
     end
 
-    def include_stats?
-      display_invitees?
-    end
-
     def stats
       counts = object.invitees.group(:status).count
 
@@ -97,29 +98,12 @@ module DiscourseCalendar
     end
 
     def include_sample_invitees?
-      display_invitees?
+      object.display_invitees?(scope.current_user)
     end
 
     def sample_invitees
       invitees = object.most_likely_going(scope.current_user)
       ActiveModel::ArraySerializer.new(invitees, each_serializer: InviteeSerializer)
     end
-
-    private
-
-    def display_invitees?
-      object.status != PostEvent.statuses[:standalone] &&
-      (
-        object.display_invitees == PostEvent.display_invitees_options[:everyone] ||
-        (
-          object.display_invitees == PostEvent.display_invitees_options[:invitees_only] &&
-          object.invitees.exists?(user_id: scope.current_user.id)
-        ) ||
-        (
-          object.display_invitees == PostEvent.display_invitees_options[:none] &&
-          object.post.user == scope.current_user
-        )
-      )
-    end
   end
 end
diff --git a/assets/javascripts/discourse/widgets/post-event-dates.js.es6 b/assets/javascripts/discourse/widgets/post-event-dates.js.es6
index b741d29..b1c7d8e 100644
--- a/assets/javascripts/discourse/widgets/post-event-dates.js.es6
+++ b/assets/javascripts/discourse/widgets/post-event-dates.js.es6
@@ -7,5 +7,10 @@ export default createWidget("post-event-dates", {
   template: hbs`
     {{d-icon "clock"}}
     <span class="date">{{{attrs.localDates}}}</span>
+    {{#if attrs.postEvent.is_expired}}
+      <span class="participants">
+        {{i18n "event.post_ui.participants" count=attrs.postEvent.stats.going}}
+      </span>
+    {{/if}}
   `
 });
diff --git a/assets/javascripts/discourse/widgets/post-event-invitees.js.es6 b/assets/javascripts/discourse/widgets/post-event-invitees.js.es6
index 74ee1f1..d361feb 100644
--- a/assets/javascripts/discourse/widgets/post-event-invitees.js.es6
+++ b/assets/javascripts/discourse/widgets/post-event-invitees.js.es6
@@ -7,7 +7,9 @@ export default createWidget("post-event-invitees", {
   transform(attrs) {
     return {
       isPrivateEvent: attrs.postEvent.status === "private",
-      showAll: attrs.postEvent.stats && attrs.postEvent.stats.invited > 10
+      showAll:
+        attrs.postEvent.should_display_invitees &&
+        attrs.postEvent.stats.invited > 10
     };
   },
 
diff --git a/assets/javascripts/discourse/widgets/post-event.js.es6 b/assets/javascripts/discourse/widgets/post-event.js.es6
index 5bce405..43f38ca 100644
--- a/assets/javascripts/discourse/widgets/post-event.js.es6
+++ b/assets/javascripts/discourse/widgets/post-event.js.es6
@@ -120,10 +120,14 @@ export default createWidget("post-event", {
         </div>
         <div class="post-event-info">
           <div class="status-and-name">
-            <span class={{transformed.statusClass}} title={{transformed.postEventStatusDescription}}>
-              {{transformed.statusIcon}}
-              <span>{{transformed.postEventStatusLabel}}</span>
-            </span>
+            {{#if state.postEvent.is_expired}}
+              <span class="status expired">expired</span>
+            {{else}}
+              <span class={{transformed.statusClass}} title={{transformed.postEventStatusDescription}}>
+                {{transformed.statusIcon}}
+                <span>{{transformed.postEventStatusLabel}}</span>
+              </span>
+            {{/if}}
             <span class="name">
               {{transformed.postEventName}}
             </span>
@@ -163,12 +167,15 @@ export default createWidget("post-event", {
 
       {{attach widget="post-event-dates" attrs=(hash localDates=attrs.localDates postEvent=state.postEvent)}}
 
+      {{#unless state.postEvent.is_expired}}
       {{#if state.postEvent.should_display_invitees}}
         <hr />
         {{attach widget="post-event-invitees" attrs=(hash postEvent=state.postEvent)}}
       {{/if}}
+      {{/unless}}
 
       <footer class="post-event-footer">
+        {{#unless state.postEvent.is_expired}}
         {{attach
           widget="button"
           attrs=(hash
@@ -178,6 +185,8 @@ export default createWidget("post-event", {
             action="addToGoogleCalendar"
           )
         }}
+        {{/unless}}
+
         {{attach
           widget="button"
           attrs=(hash
@@ -187,6 +196,8 @@ export default createWidget("post-event", {
             action="sendPMToCreator"
           )
         }}
+
+        {{#unless state.postEvent.is_expired}}
         {{#if state.postEvent.can_act_on_post_event}}
         {{#if transformed.isPublicEvent}}
           {{attach
@@ -201,6 +212,7 @@ export default createWidget("post-event", {
           }}
         {{/if}}
         {{/if}}
+        {{/unless}}
       </footer>
     {{/if}}
   `
diff --git a/assets/javascripts/initializers/post-event-decorator.js.es6 b/assets/javascripts/initializers/post-event-decorator.js.es6
index 1e8acf0..1d2c511 100644
--- a/assets/javascripts/initializers/post-event-decorator.js.es6
+++ b/assets/javascripts/initializers/post-event-decorator.js.es6
@@ -19,6 +19,7 @@ function _attachWidget(api, cooked, postEvent) {
   const existing = cooked.querySelector(".post-event");
 
   if (postEvent) {
+    console.log(postEvent);
     let widgetHeight = 175;
     if (postEvent.should_display_invitees) {
       widgetHeight += 125;
diff --git a/assets/stylesheets/common/post-event.scss b/assets/stylesheets/common/post-event.scss
index 989a7e1..697b5bd 100644

[... diff too long, it was truncated ...]

GitHub sha: 32dc03d7

This might be more readable if you used multiple return statements.

Might want to remove this

Already done :+1: oooppsss

1 Like