diff --git a/app/assets/stylesheets/retros.scss b/app/assets/stylesheets/retros.scss
new file mode 100644
index 0000000..44e2de4
--- /dev/null
+++ b/app/assets/stylesheets/retros.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the retros controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: https://sass-lang.com/
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 6b4dcfa..e891916 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,3 +1,8 @@
class ApplicationController < ActionController::Base
before_action :authenticate_user!
+ helper_method :current_user_teams
+
+ def current_user_teams
+ current_user.teams
+ end
end
diff --git a/app/controllers/retros_controller.rb b/app/controllers/retros_controller.rb
new file mode 100644
index 0000000..94070ac
--- /dev/null
+++ b/app/controllers/retros_controller.rb
@@ -0,0 +1,29 @@
+class RetrosController < ApplicationController
+ before_action :find_retro, only: [:show]
+
+ def new
+ end
+
+ def create
+ @retro = Retro.new(retro_params)
+ if @retro.save
+ redirect_to @retro
+ else
+ flash[:error] = 'Retro session could not be created.'
+ redirect_to new_retro_path
+ end
+ end
+
+ def show
+ end
+
+ private
+
+ def retro_params
+ params.require(:retro).permit(:team_id, :date)
+ end
+
+ def find_retro
+ @retro = Retro.find(params[:id])
+ end
+end
diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb
index 6f7e3ae..4cec2c3 100644
--- a/app/controllers/teams_controller.rb
+++ b/app/controllers/teams_controller.rb
@@ -1,5 +1,89 @@
class TeamsController < ApplicationController
+ before_action :find_team, except: [:index]
+ before_action :team_users, only: [:show, :edit]
+
def index
- @teams = Team.all
+ end
+
+ def show
+ end
+
+ def edit
+ end
+
+ def update
+ begin
+ @team.update!(team_params)
+ flash[:success] = 'Team was successfully updated.'
+ redirect_to team_path
+ rescue StandardError => e
+ flash[:error] = 'Oops, please try again.'
+ reload
+ end
+ end
+
+ def destroy
+ begin
+ @team.destroy!
+ flash[:success] = 'Team is gone forever.'
+ redirect_to teams_path
+ rescue StandardError => e
+ flash[:error] = 'Oops, please try again.'
+ reload
+ end
+ end
+
+ def add_user
+ company = @team.company
+
+ begin
+ user = company.users.find_by!(email: params[:user][:email])
+ raise UserAlreadyPresentError if user.already_present?(@team)
+
+ @team.users << user
+ flash[:success] = 'Say hi to your new team member!'
+ rescue ActiveRecord::RecordNotFound => e
+ flash[:error] = 'User could not been found in your company.'
+ rescue UserAlreadyPresentError
+ flash[:error] = "You can only have one #{user.name}."
+ rescue StandardError => e
+ flash[:error] = 'Oops, please try again.'
+ end
+
+ reload
+ end
+
+ def remove_user_from_team
+ begin
+ relation = UserTeam.find_by!(user_id: params[:user_id], team_id: @team.id)
+ relation.destroy!
+ flash[:success] = 'User was successfully removed. Farewell...'
+ rescue ActiveRecord::RecordNotFound => e
+ flash[:error] = 'User is not in the team anyway.'
+ rescue StandardError => e
+ flash[:error] = 'Oops, please try again.'
+ end
+
+ reload
+ end
+
+ private
+
+ class UserAlreadyPresentError < StandardError; end
+
+ def find_team
+ @team = Team.find(params[:id])
+ end
+
+ def team_users
+ @team_users = @team.users
+ end
+
+ def team_params
+ params.require(:team).permit(:name, :description)
+ end
+
+ def reload
+ redirect_back(fallback_location: edit_team_path)
end
end
diff --git a/app/helpers/retros_helper.rb b/app/helpers/retros_helper.rb
new file mode 100644
index 0000000..f33f70f
--- /dev/null
+++ b/app/helpers/retros_helper.rb
@@ -0,0 +1,2 @@
+module RetrosHelper
+end
diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js
index d75f8ee..3595145 100644
--- a/app/javascript/packs/application.js
+++ b/app/javascript/packs/application.js
@@ -22,4 +22,7 @@ require('jquery')
$(document).on('turbolinks:load', function () {
// $('.ui.dropdown').dropdown(); use this later on @canan
+ $('.message .close').on('click', function() {
+ $(this).closest('.message').hide();
+ });
})
\ No newline at end of file
diff --git a/app/models/answer.rb b/app/models/answer.rb
new file mode 100644
index 0000000..17f0fb3
--- /dev/null
+++ b/app/models/answer.rb
@@ -0,0 +1,5 @@
+class Answer < ApplicationRecord
+ belongs_to :user
+ belongs_to :retro
+ has_many :entries, dependent: :destroy
+end
diff --git a/app/models/entry.rb b/app/models/entry.rb
new file mode 100644
index 0000000..d5ebe60
--- /dev/null
+++ b/app/models/entry.rb
@@ -0,0 +1,4 @@
+class Entry < ApplicationRecord
+ belongs_to :answer
+ validates :detail, presence: true, length: { minimum: 2, maximum: 255 }
+end
diff --git a/app/models/outcome.rb b/app/models/outcome.rb
new file mode 100644
index 0000000..8cdc381
--- /dev/null
+++ b/app/models/outcome.rb
@@ -0,0 +1,2 @@
+class Outcome < ApplicationRecord
+end
diff --git a/app/models/retro.rb b/app/models/retro.rb
new file mode 100644
index 0000000..afdf56a
--- /dev/null
+++ b/app/models/retro.rb
@@ -0,0 +1,11 @@
+class Retro < ApplicationRecord
+ # date and time validation
+ belongs_to :team
+ has_many :outcomes, dependent: :destroy
+ has_many :answers, dependent: :destroy
+
+ def active?
+ status == 'active'
+ end
+
+end
diff --git a/app/models/team.rb b/app/models/team.rb
index fcf3434..83d5a35 100644
--- a/app/models/team.rb
+++ b/app/models/team.rb
@@ -3,5 +3,7 @@ class Team < ApplicationRecord
validates :company_id, presence: true
belongs_to :company
+ has_many :user_teams, dependent: :destroy
has_many :users, through: :user_teams
+ has_many :retros
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 0736b38..6a41f2c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -10,5 +10,11 @@ class User < ApplicationRecord
uniqueness: { case_sensitive: false },
format: { with: VALID_EMAIL_REGEX }
+ belongs_to :company, optional: true
+ has_many :user_teams, dependent: :destroy
has_many :teams, through: :user_teams
+
+ def already_present?(resource)
+ resource.users.include?(self)
+ end
end
diff --git a/app/models/user_team.rb b/app/models/user_team.rb
index d3e34ed..a6e9842 100644
--- a/app/models/user_team.rb
+++ b/app/models/user_team.rb
@@ -1,4 +1,6 @@
class UserTeam < ApplicationRecord
+ belongs_to :team
+ belongs_to :user
validates :user_id, presence: true
validates :team_id, presence: true
end
diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb
index 2196e83..f3b3f03 100644
--- a/app/views/devise/registrations/edit.html.erb
+++ b/app/views/devise/registrations/edit.html.erb
@@ -57,7 +57,3 @@
-
-
-
-
diff --git a/app/views/layouts/_messages.html.erb b/app/views/layouts/_messages.html.erb
new file mode 100644
index 0000000..173bb49
--- /dev/null
+++ b/app/views/layouts/_messages.html.erb
@@ -0,0 +1,28 @@
+<% flash.each do |message_type, message_content| %>
+<% if notice %>
+
<%= notice %>
- <% end %> - <% if alert %> -<%= alert %>
- <% end %> - <%= yield %> +