diff --git a/app/controllers/page_collection_submissions_controller.rb b/app/controllers/page_collection_submissions_controller.rb index c251d79b..3cc7dff5 100644 --- a/app/controllers/page_collection_submissions_controller.rb +++ b/app/controllers/page_collection_submissions_controller.rb @@ -1,9 +1,10 @@ class PageCollectionSubmissionsController < ApplicationController + before_action :set_page_collection, only: [:index] before_action :set_page_collection_submission, only: [:show, :edit, :update, :destroy] # GET /page_collection_submissions def index - @page_collection_submissions = PageCollectionSubmission.all + @page_collection_submissions = @page_collection.page_collection_submissions end # GET /page_collection_submissions/1 @@ -24,9 +25,10 @@ class PageCollectionSubmissionsController < ApplicationController @page_collection_submission = PageCollectionSubmission.new(page_collection_submission_params) if @page_collection_submission.save - redirect_to @page_collection_submission, notice: 'Page collection submission was successfully created.' + redirect_to @page_collection_submission.page_collection, notice: 'Page submitted!' else - render :new + raise "railsed create" + # render :new end end @@ -35,7 +37,8 @@ class PageCollectionSubmissionsController < ApplicationController if @page_collection_submission.update(page_collection_submission_params) redirect_to @page_collection_submission, notice: 'Page collection submission was successfully updated.' else - render :edit + raise "failed edit" + # render :edit end end @@ -47,6 +50,10 @@ class PageCollectionSubmissionsController < ApplicationController private + def set_page_collection + @page_collection = PageCollection.find(params[:page_collection_id]) + end + # Use callbacks to share common setup or constraints between actions. def set_page_collection_submission @page_collection_submission = PageCollectionSubmission.find(params[:id]) @@ -58,7 +65,8 @@ class PageCollectionSubmissionsController < ApplicationController content_type: params.require(:page_collection_submission).require(:content).split('-').first, content_id: params.require(:page_collection_submission).require(:content).split('-').second, user_id: current_user.id, - submitted_at: DateTime.current + submitted_at: DateTime.current, + page_collection_id: params.require(:page_collection_submission).require(:page_collection_id) } end end diff --git a/app/models/page_collection.rb b/app/models/page_collection.rb index 5bee7b5a..cf543ade 100644 --- a/app/models/page_collection.rb +++ b/app/models/page_collection.rb @@ -1,6 +1,20 @@ class PageCollection < ApplicationRecord belongs_to :user + has_many :page_collection_submissions + + def pending_submissions + page_collection_submissions.where(accepted_at: nil) + end + + def accepted_submissions + page_collection_submissions.where.not(accepted_at: nil) + end + + def contributors + User.where(id: accepted_submissions.pluck(:user_id)) + end + serialize :page_types, Array def self.color diff --git a/app/models/page_collection_submission.rb b/app/models/page_collection_submission.rb index 041cc27c..432fea2e 100644 --- a/app/models/page_collection_submission.rb +++ b/app/models/page_collection_submission.rb @@ -1,4 +1,5 @@ class PageCollectionSubmission < ApplicationRecord belongs_to :content, polymorphic: true + belongs_to :page_collection belongs_to :user end diff --git a/app/models/page_groupers/character_magic.rb b/app/models/page_groupers/character_magic.rb index cfa5bc36..c3b71b69 100644 --- a/app/models/page_groupers/character_magic.rb +++ b/app/models/page_groupers/character_magic.rb @@ -1,5 +1,5 @@ class CharacterMagic < ApplicationRecord belongs_to :character - belongs_to :magic - belongs_to :user, optional: true, optional: true + belongs_to :magic, optional: true + belongs_to :user, optional: true end diff --git a/app/views/page_collection_submissions/index.html.erb b/app/views/page_collection_submissions/index.html.erb index 6f47318d..1aff4755 100644 --- a/app/views/page_collection_submissions/index.html.erb +++ b/app/views/page_collection_submissions/index.html.erb @@ -1,25 +1,57 @@ -

<%= notice %>

+
+
+
+
+
Pending submissions
+

+ Submitters will be notified if you accept their content. +

+
+
+
-

Page Collection Submissions

+ <% @page_collection_submissions.each do |page_collection_submission| %> +
+ <% content = page_collection_submission.content %> +
+
+ <%= link_to content do %> + <%= image_tag content.random_public_image %> + <% end %> +
+
+
+
+ <%= content.class.icon %> + <%= content.name %> +
+
+ Submitted by + <%= link_to content.user, class: "#{User.color}-text" do %> + <%= content.user.display_name %> + <% end %> +
+ <%= time_ago_in_words page_collection_submission.submitted_at %> ago +
+
+
+ <%= link_to '#', class: 'green-text' do %> + check + Approve + <% end %> + <%= link_to '#', class: 'red-text right' do %> + close + Pass + <% end %> +
+
+
+
+ <% end %> - - - - - - - - - <% @page_collection_submissions.each do |page_collection_submission| %> - - - - - - <% end %> - -
<%= link_to 'Show', page_collection_submission %><%= link_to 'Edit', edit_page_collection_submission_path(page_collection_submission) %><%= link_to 'Destroy', page_collection_submission, method: :delete, data: { confirm: 'Are you sure?' } %>
- -
- -<%= link_to 'New Page Collection Submission', new_page_collection_submission_path %> +
+

+ <%= link_to "Back to #{@page_collection.title}", @page_collection, class: "#{PageCollection.color}-text" %> +

+
+
\ No newline at end of file diff --git a/app/views/page_collections/show.html.erb b/app/views/page_collections/show.html.erb index 8ff4bcc7..f9c612c2 100644 --- a/app/views/page_collections/show.html.erb +++ b/app/views/page_collections/show.html.erb @@ -30,6 +30,7 @@
<%= form_for PageCollectionSubmission.new do |f| %> + <%= f.hidden_field :page_collection_id, value: @page_collection.id %>
<%= f.select :content do %> <% @current_user_content.each do |content_type, content_list| %> @@ -43,29 +44,52 @@ <% end %>
- Only pages you've marked "public" may be shared. + Only pages you've marked "public" may be submitted.
- <%= f.submit (@page_collection.user == current_user ? 'Add' : 'Submit'), class: 'btn green white-text' %> + <%= f.submit (@page_collection.user == current_user ? 'Add' : 'Submit'), class: "btn #{PageCollection.color} white-text" %> <% end %>
Collection description (editable)
-
+ +
In this collection
+
<% @page_collection.page_types.each do |pt| %> <% klass = pt.constantize %> - <%= link_to '#' + pt do %> - <%= pt.downcase %> + <%= link_to('#' + pt, class: "collection-item #{klass.color} white-text") do %> + <%= klass.icon %> + <%= pt.pluralize %> <% end %> <% end %>
-
- Contributors + +
Curator
+
+ <%= link_to @page_collection.user, class: "#{User.color}-text" do %> + <%= image_tag @page_collection.user.image_url(size=20), class: 'left circle', style: 'margin-right: 8px;' %> + <%= @page_collection.user.display_name %> + <% end %>
+
+ + <% if @page_collection.contributors.any? %> +
Contributors
+ <% @page_collection.contributors.each do |user| %> +
+ <%= link_to user, class: "#{User.color}-text" do %> + <%= image_tag user.image_url(size=20), class: 'left circle', style: 'margin-right: 8px;' %> + <%= user.display_name %> + <% end %> +
+ <% end %> +
+ <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index 4de9630b..5e699a0b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,7 @@ Rails.application.routes.draw do end resources :page_collections, path: '/collections' do get '/explore', to: 'page_collections#explore', on: :collection + get '/submissions', to: 'page_collection_submissions#index', as: 'pending_submissions' end resources :page_collection_submissions diff --git a/db/migrate/20200502021338_create_page_collection_submissions.rb b/db/migrate/20200502021338_create_page_collection_submissions.rb index e69329a4..cfccff54 100644 --- a/db/migrate/20200502021338_create_page_collection_submissions.rb +++ b/db/migrate/20200502021338_create_page_collection_submissions.rb @@ -5,6 +5,7 @@ class CreatePageCollectionSubmissions < ActiveRecord::Migration[6.0] t.references :user, null: false, foreign_key: true t.datetime :accepted_at t.datetime :submitted_at + t.references :page_collection, null: false t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 6ab1b24a..5e0d2676 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2131,9 +2131,11 @@ ActiveRecord::Schema.define(version: 2020_05_02_021338) do t.integer "user_id", null: false t.datetime "accepted_at" t.datetime "submitted_at" + t.integer "page_collection_id", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["content_type", "content_id"], name: "polycontent_collection_index" + t.index ["page_collection_id"], name: "index_page_collection_submissions_on_page_collection_id" t.index ["user_id"], name: "index_page_collection_submissions_on_user_id" end