Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week5 Sharath Balaji T #135

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions week_4/activity-tracker/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

gem "devise"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
Expand Down
14 changes: 14 additions & 0 deletions week_4/activity-tracker/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
bcrypt (3.1.18)
bindex (0.8.1)
bootsnap (1.15.0)
msgpack (~> 1.2)
Expand All @@ -87,6 +88,12 @@ GEM
debug (1.7.1)
irb (>= 1.5.0)
reline (>= 0.3.1)
devise (4.8.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
erubi (1.12.0)
globalid (1.0.0)
activesupport (>= 5.0)
Expand Down Expand Up @@ -127,6 +134,7 @@ GEM
nio4r (2.5.8)
nokogiri (1.14.0-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
public_suffix (5.0.1)
puma (5.6.5)
nio4r (~> 2.0)
Expand Down Expand Up @@ -168,6 +176,9 @@ GEM
regexp_parser (2.6.1)
reline (0.3.2)
io-console (~> 0.5)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.5)
rubyzip (2.3.2)
selenium-webdriver (4.7.1)
Expand All @@ -192,6 +203,8 @@ GEM
railties (>= 6.0.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand All @@ -216,6 +229,7 @@ DEPENDENCIES
bootsnap
capybara
debug
devise
importmap-rails
jbuilder
puma (~> 5.0)
Expand Down
76 changes: 76 additions & 0 deletions week_4/activity-tracker/app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
class ActivitiesController < ApplicationController
before_action :set_activity, only: %i[ show edit update destroy ]

# GET /activities or /activities.json
def index
@activities = Activity.all
end

# GET /activities/1 or /activities/1.json
def show
end

# GET /activities/new
def new
@activity = Activity.new
end

# GET /activities/1/edit
def edit
end

# GET /activities/stats/
def stats
@total_duration = Activity.sum(:duration)
@total_calories = Activity.sum(:calories)
end

# POST /activities or /activities.json
def create
@activity = Activity.new(activity_params)

respond_to do |format|
if @activity.save
format.html { redirect_to activity_url(@activity), notice: "Activity was successfully created." }
format.json { render :show, status: :created, location: @activity }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @activity.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /activities/1 or /activities/1.json
def update
respond_to do |format|
if @activity.update(activity_params)
format.html { redirect_to activity_url(@activity), notice: "Activity was successfully updated." }
format.json { render :show, status: :ok, location: @activity }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @activity.errors, status: :unprocessable_entity }
end
end
end

# DELETE /activities/1 or /activities/1.json
def destroy
@activity.destroy

respond_to do |format|
format.html { redirect_to activities_url, notice: "Activity was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_activity
@activity = Activity.find(params[:id])
end

# Only allow a list of trusted parameters through.
def activity_params
params.require(:activity).permit(:title, :activity_type, :start, :duration, :calories)
end
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class ApplicationController < ActionController::Base

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class StaticPagesController < ApplicationController

def index
end

def about
end
end
2 changes: 2 additions & 0 deletions week_4/activity-tracker/app/helpers/activities_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ActivitiesHelper
end
2 changes: 2 additions & 0 deletions week_4/activity-tracker/app/helpers/static_pages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module StaticPagesHelper
end
2 changes: 2 additions & 0 deletions week_4/activity-tracker/app/models/activity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Activity < ApplicationRecord
end
6 changes: 6 additions & 0 deletions week_4/activity-tracker/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
34 changes: 34 additions & 0 deletions week_4/activity-tracker/app/views/activities/_activity.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="in"><div id="<%= dom_id activity %>">
<p>
<strong>Title:</strong>
<%= activity.title %>
</p>

<p>
<strong>Activity type:</strong>
<%= activity.activity_type %>
</p>

<p>
<strong>Start:</strong>
<%= activity.start %>
</p>

<p>
<strong>Duration:</strong>
<%= activity.duration %>
</p>

<p>
<strong>Calories:</strong>
<%= activity.calories %>
</p>

</div>
</div>
<style>
.in{ margin: auto;
width: 50%;
border: 5px dashed gray;
text-align: center;background: lightgray;}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! activity, :id, :title, :activity_type, :start, :duration, :calories, :created_at, :updated_at
json.url activity_url(activity, format: :json)
49 changes: 49 additions & 0 deletions week_4/activity-tracker/app/views/activities/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div class="in"><%= form_with(model: activity) do |form| %>
<% if activity.errors.any? %>
<div style="color: red">
<h2><%= pluralize(activity.errors.count, "error") %> prohibited this activity from being saved:</h2>

<ul>
<% activity.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.label :title, style: "display: block" %>
<%= form.text_field :title %>
</div>

<div>
<%= form.label :activity_type, style: "display: block" %>
<%= form.text_field :activity_type %>
</div>

<div>
<%= form.label :start, style: "display: block" %>
<%= form.datetime_field :start %>
</div>

<div>
<%= form.label :duration, style: "display: block" %>
<%= form.text_field :duration %>
</div>

<div>
<%= form.label :calories, style: "display: block" %>
<%= form.number_field :calories %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
</div>
<style>
.in{ margin: auto;
width: 50%;
border: 5px dashed gray;
text-align: center;background: lightgray;}
</style>
17 changes: 17 additions & 0 deletions week_4/activity-tracker/app/views/activities/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="in"><h1>Editing activity</h1>

<%= render "form", activity: @activity %>

<br>

<div>
<%= link_to "Show this activity", @activity %> |
<%= link_to "Back to activities", activities_path %>
</div>
</div>
<style>
.in{ margin: auto;
width: 50%;
border: 5px dashed gray;
text-align: center;background: lightgray;}
</style>
24 changes: 24 additions & 0 deletions week_4/activity-tracker/app/views/activities/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="in">
<p style="color: green"><%= notice %></p>

<h1>Activities</h1>

<div id="activities">
<% @activities.each do |activity| %>
<%= render activity %>
<p>
<%= link_to "Show this activity", activity %>
</p>
<% end %>
</div>

<%= link_to "New activity", new_activity_path %><br>
<%= link_to "Go to Statistics", stats_activities_path %><br>
<%= link_to "Return to Home", static_pages_index_path %>
</div>
<style>
.in{ margin: auto;
width: 50%;
border: 5px dashed gray;
text-align: center;background: lightgray;}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @activities, partial: "activities/activity", as: :activity
16 changes: 16 additions & 0 deletions week_4/activity-tracker/app/views/activities/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="in"><h1>New activity</h1>

<%= render "form", activity: @activity %>

<br>

<div>
<%= link_to "Back to activities", activities_path %>
</div>
</div>
<style>
.in{ margin: auto;
width: 50%;
border: 5px dashed gray;
text-align: center;background: lightgray;}
</style>
17 changes: 17 additions & 0 deletions week_4/activity-tracker/app/views/activities/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<p style="color: green"><%= notice %></p>
<div class="in">
<%= render @activity %>

<div>
<%= link_to "Edit this activity", edit_activity_path(@activity) %> |
<%= link_to "Back to activities", activities_path %>

<%= button_to "Destroy this activity", @activity, method: :delete %>
</div>
</div>
<style>
.in{ margin: auto;
width: 50%;
border: 5px dashed gray;
text-align: center;background: lightgray;}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "activities/activity", activity: @activity
14 changes: 14 additions & 0 deletions week_4/activity-tracker/app/views/activities/stats.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="in">
<h1>Activity Statistics</h1><br>

<p><strong>Total Duration:</strong> <%= @total_duration %></p><br>
<p><strong>Total Calories:</strong> <%= @total_calories %></p>
<%=link_to "Back to Activities",activities_path%>
</div>

<style>
.in{ margin: auto;
width: 50%;
border: 5px dashed gray;
text-align: center;background: lightgray;}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
</head>

<body>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
</body>
</html>
3 changes: 3 additions & 0 deletions week_4/activity-tracker/app/views/static_pages/about.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>ABOUT</h1>
<p>This is a fitness app</p>
<%= link_to "Return to Home", static_pages_index_path %>
12 changes: 12 additions & 0 deletions week_4/activity-tracker/app/views/static_pages/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1>Welcome to Activity Tracker!!!</h1>
<%if user_signed_in? %>
<div>Logged in as: <%=current_user.email%> </div>
<%=link_to "Edit Account Settings",edit_user_registration_path%><br>
<%=link_to "Go to Activities",activities_path%>
<%=link_to "About",about_path%>
<%=button_to "Logout",destroy_user_session_path, method: :delete %>

<%else%>
<%=link_to "Sign In",new_user_session_path%><br>
<%=link_to "Sign Up",new_user_registration_path%>
<%end%>
Loading