| 
				
			 | 
			
			
				@@ -1,6 +1,6 @@ 
			 | 
		
	
		
			
			| 
				1
			 | 
			
				1
			 | 
			
			
				 class Api::ActivitiesController < ApiController 
			 | 
		
	
		
			
			| 
				2
			 | 
			
				
			 | 
			
			
				-  before_action :set_activity, only: [:show] 
			 | 
		
	
		
			
			| 
				3
			 | 
			
				
			 | 
			
			
				-  before_action :require_membership!, only: [:show] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				2
			 | 
			
			
				+  before_action :set_activity, only: [:show, :response_summary] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				3
			 | 
			
			
				+  before_action :require_membership!, only: [:show, :reponse_summary] 
			 | 
		
	
		
			
			| 
				4
			 | 
			
				4
			 | 
			
			
				   before_action :api_require_admin!, only: [:index] 
			 | 
		
	
		
			
			| 
				5
			 | 
			
				5
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				6
			 | 
			
				6
			 | 
			
			
				   # GET /api/activities 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -14,6 +14,69 @@ class Api::ActivitiesController < ApiController 
			 | 
		
	
		
			
			| 
				14
			 | 
			
				14
			 | 
			
			
				   def show 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				15
			 | 
			
			
				   end 
			 | 
		
	
		
			
			| 
				16
			 | 
			
				16
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				+  # GET /api/activities/1/response_summary 
			 | 
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				+  # GET /api/activities/1/response_summary.json 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+  def response_summary 
			 | 
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				+    as = @activity 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+      .participants 
			 | 
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				+      .joins(:person) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				23
			 | 
			
			
				+      .order('people.first_name ASC') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+    present = as 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+      .where(attending: true) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				28
			 | 
			
			
				+    unknown = as 
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+      .where(attending: nil) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+    absent = as 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+      .where(attending: false) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+    presentnames = present 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+      .map{|p| p.person.first_name } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+    unknownnames = unknown 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+      .map{|p| p.person.first_name } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+    absentnames = absent 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+      .map{|p| p.person.first_name } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+    if presentnames 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+      present_mess = I18n.t('activities.participant.these_present', count: present.count, names: presentnames.join(', ')) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+    else 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+      present_mess = I18n.t('activities.participant.none_present') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+    end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+    if unknownnames 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+      unknown_mess = I18n.t('activities.participant.these_unknown', count: unknown.count, names: unknownnames.join(', ')) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+    else 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+      unknown_mess = I18n.t('activities.participant.none_unknown') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+    end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+    if absentnames 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+      absent_mess = I18n.t('activities.participant.these_absent', count: absent.count, names: absentnames.join(', ')) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+    else 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+      absent_mess = I18n.t('activities.participant.none_absent') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+    end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+    @summary = { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+      present: { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+        count: present.count, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				+        names: presentnames, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				+        message: present_mess 
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+      }, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+      unknown: { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+        count: unknown.count, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				+        names: unknownnames, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+        message: unknown_mess 
			 | 
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				+      }, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				+      absent: { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				73
			 | 
			
			
				+        count: absent.count, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+        names: absentnames, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+        message: absent_mess 
			 | 
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				+      } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+  end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				17
			 | 
			
				80
			 | 
			
			
				   private 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				81
			 | 
			
			
				     # Use callbacks to share common setup or constraints between actions. 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				82
			 | 
			
			
				     def set_activity 
			 |