diff --git a/Gemfile b/Gemfile index 518307a..c233f96 100644 --- a/Gemfile +++ b/Gemfile @@ -72,4 +72,6 @@ end gem 'activeadmin', github: 'activeadmin/activeadmin' gem 'devise', github: 'plataformatec/devise' -gem 'jquery-rails' \ No newline at end of file +gem 'jquery-rails' + +gem "starter_generators", :git => "https://github.com/raghubetina/starter_generators" diff --git a/Gemfile.lock b/Gemfile.lock index 3a608e1..753b5d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,6 +58,12 @@ GIT responders warden (~> 1.2.3) +GIT + remote: https://github.com/raghubetina/starter_generators + revision: c38d341cecde6ff086d8e7882f781f82c2870ffd + specs: + starter_generators (0.9.6) + GEM remote: https://rubygems.org/ specs: @@ -375,6 +381,7 @@ DEPENDENCIES spring spring-watcher-listen (~> 2.0.0) sqlite3 + starter_generators! tzinfo-data uglifier (>= 1.3.0) wdm @@ -383,4 +390,4 @@ DEPENDENCIES webmock BUNDLED WITH - 1.14.6 + 1.15.4 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000..5cb5922 --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,3 @@ +@charset "utf-8"; + +@import "bootstrap-4-spacers"; diff --git a/app/assets/stylesheets/bootstrap-4-spacers.scss b/app/assets/stylesheets/bootstrap-4-spacers.scss new file mode 100644 index 0000000..a4b8c35 --- /dev/null +++ b/app/assets/stylesheets/bootstrap-4-spacers.scss @@ -0,0 +1,95 @@ +.pt-0 { + padding-top: 0; +} + +.pt-1 { + padding-top: 1rem; +} + +.pt-2 { + padding-top: 2rem; +} + +.pt-3 { + padding-top: 3rem; +} + +.pt-4 { + padding-top: 5rem; +} + +.pt-5 { + padding-top: 8rem; +} + +.pb-0 { + padding-bottom: 0; +} + +.pb-1 { + padding-bottom: 1rem; +} + +.pb-2 { + padding-bottom: 2rem; +} + +.pb-3 { + padding-bottom: 3rem; +} + +.pb-4 { + padding-bottom: 5rem; +} + +.pb-5 { + padding-bottom: 8rem; +} + +.mt-0 { + margin-top: 0; +} + +.mt-1 { + margin-top: 1rem; +} + +.mt-2 { + margin-top: 2rem; +} + +.mt-3 { + margin-top: 3rem; +} + +.mt-4 { + margin-top: 5rem; +} + +.mt-5 { + margin-top: 8rem; +} + +.mb-0 { + margin-bottom: 0; +} + +.mb-1 { + margin-bottom: 1rem; +} + +.mb-2 { + margin-bottom: 2rem; +} + +.mb-3 { + margin-bottom: 3rem; +} + +.mb-4 { + margin-bottom: 5rem; +} + +.mb-5 { + margin-bottom: 8rem; +} diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb new file mode 100644 index 0000000..51ca49f --- /dev/null +++ b/app/controllers/activities_controller.rb @@ -0,0 +1,83 @@ +class ActivitiesController < ApplicationController + def index + @activities = Activity.all + @categories = Category.all + + render("activities/index.html.erb") + end + + def show + @activity = Activity.find(params[:id]) + + render("activities/show.html.erb") + end + + def new + @activity = Activity.new + @categories = Category.all + + render("activities/new.html.erb") + end + + def create + @activity = Activity.new + @categories = Category.all + + @activity.name = params[:name] + @activity.address = params[:address] + @activity.category_id = params[:category_id] + @activity.date = params[:date] + @activity.meet_time = params[:meet_time] + @activity.proposer_id = params[:proposer_id] + @activity.visual = params[:visual] + @activity.duration = params[:duration] + @activity.cost_level = params[:cost_level] + + save_status = @activity.save + + if save_status == true + redirect_to("/activities/#{@activity.id}", :notice => "Activity created successfully.") + else + render("activities/new.html.erb") + end + end + + def edit + @activity = Activity.find(params[:id]) + + render("activities/edit.html.erb") + end + + def update + @activity = Activity.find(params[:id]) + + @activity.name = params[:name] + @activity.address = params[:address] + @activity.category_id = params[:category_id] + @activity.meet_time = params[:meet_time] + @activity.proposer_id = params[:proposer_id] + @activity.visual = params[:visual] + @activity.duration = params[:duration] + @activity.cost_level = params[:cost_level] + + save_status = @activity.save + + if save_status == true + redirect_to("/activities/#{@activity.id}", :notice => "Activity updated successfully.") + else + render("activities/edit.html.erb") + end + end + + def destroy + @activity = Activity.find(params[:id]) + + @activity.destroy + + if URI(request.referer).path == "/activities/#{@activity.id}" + redirect_to("/", :notice => "Activity deleted.") + else + redirect_back(:fallback_location => "/", :notice => "Activity deleted.") + end + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4355099..4d1db83 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,14 @@ class ApplicationController < ActionController::Base # protect_from_forgery with: :exception + before_action :authenticate_user! + + before_action :configure_permitted_parameters, if: :devise_controller? + + protected + + def configure_permitted_parameters + devise_parameter_sanitizer.permit(:sign_up, :keys => [:username, :avatar_url]) + + devise_parameter_sanitizer.permit(:account_update, :keys => [:avatar_url]) + end end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000..7155901 --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,67 @@ +class CategoriesController < ApplicationController + def index + @categories = Category.all + + render("categories/index.html.erb") + end + + def show + @category = Category.find(params[:id]) + + render("categories/show.html.erb") + end + + def new + @category = Category.new + + render("categories/new.html.erb") + end + + def create + @category = Category.new + + @category.name = params[:name] + @category.icon = params[:icon] + + save_status = @category.save + + if save_status == true + redirect_to("/categories/#{@category.id}", :notice => "Category created successfully.") + else + render("categories/new.html.erb") + end + end + + def edit + @category = Category.find(params[:id]) + + render("categories/edit.html.erb") + end + + def update + @category = Category.find(params[:id]) + + @category.name = params[:name] + @category.icon = params[:icon] + + save_status = @category.save + + if save_status == true + redirect_to("/categories/#{@category.id}", :notice => "Category updated successfully.") + else + render("categories/edit.html.erb") + end + end + + def destroy + @category = Category.find(params[:id]) + + @category.destroy + + if URI(request.referer).path == "/categories/#{@category.id}" + redirect_to("/", :notice => "Category deleted.") + else + redirect_back(:fallback_location => "/", :notice => "Category deleted.") + end + end +end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb new file mode 100644 index 0000000..264f0c0 --- /dev/null +++ b/app/controllers/groups_controller.rb @@ -0,0 +1,67 @@ +class GroupsController < ApplicationController + def index + @groups = Group.all + + render("groups/index.html.erb") + end + + def show + @group = Group.find(params[:id]) + + render("groups/show.html.erb") + end + + def new + @group = Group.new + + render("groups/new.html.erb") + end + + def create + @group = Group.new + + @group.creator_id = params[:creator_id] + @group.name = params[:name] + + save_status = @group.save + + if save_status == true + redirect_to("/groups/#{@group.id}", :notice => "Group created successfully.") + else + render("groups/new.html.erb") + end + end + + def edit + @group = Group.find(params[:id]) + + render("groups/edit.html.erb") + end + + def update + @group = Group.find(params[:id]) + + @group.creator_id = params[:creator_id] + @group.name = params[:name] + + save_status = @group.save + + if save_status == true + redirect_to("/groups/#{@group.id}", :notice => "Group updated successfully.") + else + render("groups/edit.html.erb") + end + end + + def destroy + @group = Group.find(params[:id]) + + @group.destroy + + if URI(request.referer).path == "/groups/#{@group.id}" + redirect_to("/", :notice => "Group deleted.") + else + redirect_back(:fallback_location => "/", :notice => "Group deleted.") + end + end +end diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb new file mode 100644 index 0000000..690e762 --- /dev/null +++ b/app/controllers/invites_controller.rb @@ -0,0 +1,69 @@ +class InvitesController < ApplicationController + def index + @invites = Invite.all + + render("invites/index.html.erb") + end + + def show + @invite = Invite.find(params[:id]) + + render("invites/show.html.erb") + end + + def new + @invite = Invite.new + + render("invites/new.html.erb") + end + + def create + @invite = Invite.new + + @invite.activity_id = params[:activity_id] + @invite.invitee_id = params[:invitee_id] + @invite.attend_status = params[:attend_status] + + save_status = @invite.save + + if save_status == true + redirect_to("/invites/#{@invite.id}", :notice => "Invite created successfully.") + else + render("invites/new.html.erb") + end + end + + def edit + @invite = Invite.find(params[:id]) + + render("invites/edit.html.erb") + end + + def update + @invite = Invite.find(params[:id]) + + @invite.activity_id = params[:activity_id] + @invite.invitee_id = params[:invitee_id] + @invite.attend_status = params[:attend_status] + + save_status = @invite.save + + if save_status == true + redirect_to("/invites/#{@invite.id}", :notice => "Invite updated successfully.") + else + render("invites/edit.html.erb") + end + end + + def destroy + @invite = Invite.find(params[:id]) + + @invite.destroy + + if URI(request.referer).path == "/invites/#{@invite.id}" + redirect_to("/", :notice => "Invite deleted.") + else + redirect_back(:fallback_location => "/", :notice => "Invite deleted.") + end + end +end diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb new file mode 100644 index 0000000..96edabb --- /dev/null +++ b/app/controllers/memberships_controller.rb @@ -0,0 +1,67 @@ +class MembershipsController < ApplicationController + def index + @memberships = Membership.all + + render("memberships/index.html.erb") + end + + def show + @membership = Membership.find(params[:id]) + + render("memberships/show.html.erb") + end + + def new + @membership = Membership.new + + render("memberships/new.html.erb") + end + + def create + @membership = Membership.new + + @membership.group_id = params[:group_id] + @membership.member_id = params[:member_id] + + save_status = @membership.save + + if save_status == true + redirect_to("/memberships/#{@membership.id}", :notice => "Membership created successfully.") + else + render("memberships/new.html.erb") + end + end + + def edit + @membership = Membership.find(params[:id]) + + render("memberships/edit.html.erb") + end + + def update + @membership = Membership.find(params[:id]) + + @membership.group_id = params[:group_id] + @membership.member_id = params[:member_id] + + save_status = @membership.save + + if save_status == true + redirect_to("/memberships/#{@membership.id}", :notice => "Membership updated successfully.") + else + render("memberships/edit.html.erb") + end + end + + def destroy + @membership = Membership.find(params[:id]) + + @membership.destroy + + if URI(request.referer).path == "/memberships/#{@membership.id}" + redirect_to("/", :notice => "Membership deleted.") + else + redirect_back(:fallback_location => "/", :notice => "Membership deleted.") + end + end +end diff --git a/app/models/activity.rb b/app/models/activity.rb new file mode 100644 index 0000000..e12c52f --- /dev/null +++ b/app/models/activity.rb @@ -0,0 +1,31 @@ +# == Schema Information +# +# Table name: activities +# +# id :integer not null, primary key +# name :string +# address :string +# category_id :integer +# meet_time :time +# proposer_id :integer +# visual :string +# duration :integer +# cost_level :string +# created_at :datetime not null +# updated_at :datetime not null +# date :string +# + +class Activity < ApplicationRecord + +# From first draft + # Direct Associations + has_many :invites, :dependent => :destroy + belongs_to :category + belongs_to :proposer, :class_name => "User" + + # Indirect Associations + has_many :invitees, :through => :invites, :source => :invitee + + +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000..ea46921 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,18 @@ +# == Schema Information +# +# Table name: categories +# +# id :integer not null, primary key +# name :string +# icon :string +# created_at :datetime not null +# updated_at :datetime not null +# + +class Category < ApplicationRecord + +# From first draft + # Direct Associations + has_many :activities + +end diff --git a/app/models/group.rb b/app/models/group.rb new file mode 100644 index 0000000..a77a7bf --- /dev/null +++ b/app/models/group.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: groups +# +# id :integer not null, primary key +# creator_id :integer +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# + +class Group < ApplicationRecord + +# From first draft + # Direct Associations + belongs_to :user, :foreign_key => "creator_id" + has_many :memberships, :dependent => :destroy + + #Indirect Associations + has_many :members, :through => :memberships, :source => :member + +end diff --git a/app/models/invite.rb b/app/models/invite.rb new file mode 100644 index 0000000..f3ad3ee --- /dev/null +++ b/app/models/invite.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: invites +# +# id :integer not null, primary key +# activity_id :integer +# invitee_id :integer +# attend_status :string +# created_at :datetime not null +# updated_at :datetime not null +# + +class Invite < ApplicationRecord + +# From first draft + # Direct Associations + belongs_to :activity + belongs_to :invitee, :class_name => "User" + +end diff --git a/app/models/membership.rb b/app/models/membership.rb new file mode 100644 index 0000000..ccef6a1 --- /dev/null +++ b/app/models/membership.rb @@ -0,0 +1,19 @@ +# == Schema Information +# +# Table name: memberships +# +# id :integer not null, primary key +# group_id :integer +# member_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# + +class Membership < ApplicationRecord + +# From first draft + # Direct Associations + belongs_to :member, :class_name => "User" + belongs_to :group + +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..c75e0ca --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,42 @@ +# == Schema Information +# +# Table name: users +# +# id :integer not null, primary key +# email :string default(""), not null +# encrypted_password :string default(""), not null +# reset_password_token :string +# reset_password_sent_at :datetime +# remember_created_at :datetime +# sign_in_count :integer default(0), not null +# current_sign_in_at :datetime +# last_sign_in_at :datetime +# current_sign_in_ip :string +# last_sign_in_ip :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_users_on_email (email) UNIQUE +# index_users_on_reset_password_token (reset_password_token) UNIQUE +# + +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable + +# From first draft + # Direct Associations + has_many :activities, :foreign_key => "proposer_id", :dependent => :destroy + has_many :invites, :foreign_key => "invitee_id", :dependent => :destroy + has_many :groups, :foreign_key => "creator_id", :dependent => :destroy + has_many :memberships, :foreign_key => "member_id", :dependent => :destroy + + # Indirect Associations + has_many :activity_invites, :through => :invites, :source => :activity + has_many :group_memberships, :through => :memberships, :source => :group + +end diff --git a/app/views/activities/edit.html.erb b/app/views/activities/edit.html.erb new file mode 100644 index 0000000..7fd3e08 --- /dev/null +++ b/app/views/activities/edit.html.erb @@ -0,0 +1,100 @@ + +<% if @activity.errors.any? %> + <% @activity.errors.full_messages.each do |message| %> +
| Name | +Address | +Category | +Meet time | +Proposer | +Visual | +Duration | +Cost level | +Actions | +
|---|---|---|---|---|---|---|---|---|
| <%= activity.name %> | +<%= activity.address %> | +<%= activity.category_id %> | +<%= activity.meet_time %> | +<%= activity.proposer_id %> | +<%= activity.visual %> | +<%= activity.duration %> | +<%= activity.cost_level %> | ++ Show + Edit + Delete + | +