Browse Source

Work on events

Maarten van den Berg 8 years ago
parent
commit
db17a7b6a9

+ 5 - 4
app/controllers/activities_controller.rb

28
   # POST /activities.json
28
   # POST /activities.json
29
   def create
29
   def create
30
     @activity = Activity.new(activity_params)
30
     @activity = Activity.new(activity_params)
31
+    @activity.group = @group
31
 
32
 
32
     respond_to do |format|
33
     respond_to do |format|
33
       if @activity.save
34
       if @activity.save
34
-        format.html { redirect_to @activity, notice: 'Activity was successfully created.' }
35
+        format.html { redirect_to group_activity_url(@group, @activity), notice: 'Activity was successfully created.' }
35
         format.json { render :show, status: :created, location: @activity }
36
         format.json { render :show, status: :created, location: @activity }
36
       else
37
       else
37
         format.html { render :new }
38
         format.html { render :new }
45
   def update
46
   def update
46
     respond_to do |format|
47
     respond_to do |format|
47
       if @activity.update(activity_params)
48
       if @activity.update(activity_params)
48
-        format.html { redirect_to @activity, notice: 'Activity was successfully updated.' }
49
+        format.html { redirect_to group_activity_url(@group, @activity), notice: 'Activity was successfully updated.' }
49
         format.json { render :show, status: :ok, location: @activity }
50
         format.json { render :show, status: :ok, location: @activity }
50
       else
51
       else
51
         format.html { render :edit }
52
         format.html { render :edit }
59
   def destroy
60
   def destroy
60
     @activity.destroy
61
     @activity.destroy
61
     respond_to do |format|
62
     respond_to do |format|
62
-      format.html { redirect_to activities_url, notice: 'Activity was successfully destroyed.' }
63
+      format.html { redirect_to group_activities_url(@group), notice: 'Activity was successfully destroyed.' }
63
       format.json { head :no_content }
64
       format.json { head :no_content }
64
     end
65
     end
65
   end
66
   end
76
 
77
 
77
     # Never trust parameters from the scary internet, only allow the white list through.
78
     # Never trust parameters from the scary internet, only allow the white list through.
78
     def activity_params
79
     def activity_params
79
-      params.fetch(:activity, {})
80
+      params.require(:activity).permit(:public_name, :secret_name, :description, :location, :start, :end, :deadline, :show_hidden)
80
     end
81
     end
81
 end
82
 end

+ 1 - 1
app/controllers/groups_controller.rb

77
 
77
 
78
     # Never trust parameters from the scary internet, only allow the white list through.
78
     # Never trust parameters from the scary internet, only allow the white list through.
79
     def group_params
79
     def group_params
80
-      params.fetch(:group, {})
80
+      params.require(:group).permit(:name)
81
     end
81
     end
82
 end
82
 end

+ 36 - 0
app/views/activities/_form.html.erb

12
   <% end %>
12
   <% end %>
13
 
13
 
14
   <div class="actions">
14
   <div class="actions">
15
+    <div class="form-group">
16
+      <div class="row">
17
+        <div class="col-md-6">
18
+          <%= f.label :public_name %>
19
+          <%= f.text_field :public_name, class: 'form-control' %>
20
+        </div>
21
+        <div class="col-md-6">
22
+          <%= f.label :secret_name %>
23
+          <%= f.text_field :secret_name, class: 'form-control' %>
24
+        </div>
25
+      </div>
26
+    </div>
27
+    <div class="form-group">
28
+      <div class="row">
29
+        <div class="col-md-6">
30
+          <%= f.label :start %>
31
+          <%= f.datetime_field :start, class: 'form-control' %>
32
+        </div>
33
+        <div class="col-md-6">
34
+          <%= f.label :end %>
35
+          <%= f.datetime_field :end, class: 'form-control' %>
36
+        </div>
37
+      </div>
38
+    </div>
39
+    <div class="form-group">
40
+      <%= f.label :description %>
41
+      <%= f.text_area :description, class: 'form-control' %>
42
+    </div>
43
+    <div class="form-group">
44
+      <%= f.label :deadline %>
45
+      <%= f.datetime_field :deadline, class: 'form-control' %>
46
+    </div>
47
+    <div class="form-group">
48
+      <%= f.label :show_hidden %>
49
+      <%= f.check_box :show_hidden %>
50
+    </div>
15
     <%= f.submit %>
51
     <%= f.submit %>
16
   </div>
52
   </div>
17
 <% end %>
53
 <% end %>

+ 1 - 1
app/views/activities/edit.html.erb

2
 
2
 
3
 <%= render 'form', activity: @activity %>
3
 <%= render 'form', activity: @activity %>
4
 
4
 
5
-<%= link_to 'Show', group_activity(@group, @activity) %> |
5
+<%= link_to 'Show', group_activity_path(@group, @activity) %> |
6
 <%= link_to 'Back', group_activities_path(@group) %>
6
 <%= link_to 'Back', group_activities_path(@group) %>

+ 18 - 1
app/views/activities/show.html.erb

1
-<p id="notice"><%= notice %></p>
1
+<h2><%= @activity.public_name %></h2>
2
+
3
+<ul>
4
+  <li>Secretly <%= @activity.secret_name %></li>
5
+  <li><%= @activity.description %></li>
6
+  <li><%= @activity.location %></li>
7
+  <li><%= @activity.start %> - <%= @activity.end %></li>
8
+  <li>Deadline <%= @activity.deadline %></li>
9
+</ul>
10
+
11
+<h2>Participants (<%= @activity.participants.count %>)</h2>
12
+<ul>
13
+  <% @activity.participants.each do |p| %>
14
+    <li>
15
+      <%= p.person.full_name %>, <%= p.is_organizer %>, <%= p.attending %>
16
+    </li>
17
+  <% end %>
18
+</ul>
2
 
19
 
3
 <%= link_to 'Edit', edit_group_activity_path(@group, @activity) %> |
20
 <%= link_to 'Edit', edit_group_activity_path(@group, @activity) %> |
4
 <%= link_to 'Back', group_activities_path(@group) %>
21
 <%= link_to 'Back', group_activities_path(@group) %>

+ 4 - 0
app/views/groups/_form.html.erb

12
   <% end %>
12
   <% end %>
13
 
13
 
14
   <div class="actions">
14
   <div class="actions">
15
+    <div class="form-group">
16
+      <%= f.label :name %>
17
+      <%= f.text_field :name, class: 'form-control' %>
18
+    </div>
15
     <%= f.submit %>
19
     <%= f.submit %>
16
   </div>
20
   </div>
17
 <% end %>
21
 <% end %>

+ 3 - 0
app/views/groups/show.html.erb

21
     </li>
21
     </li>
22
   <% end %>
22
   <% end %>
23
 </ul>
23
 </ul>
24
+<%= link_to "Manage activities", group_activities_path(@group) %>
24
 
25
 
26
+<div>
25
 <%= link_to 'Edit', edit_group_path(@group) %> |
27
 <%= link_to 'Edit', edit_group_path(@group) %> |
26
 <%= link_to 'Back', groups_path %>
28
 <%= link_to 'Back', groups_path %>
29
+</div>