Skip to content
Merged
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
1 change: 1 addition & 0 deletions app/assets/stylesheets/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ $header-color: #000103;
$background-color: #333138;
$line-color: #515052;
$font-color: #fffffa;
$font-secondary-color: #878787;
$highlight-color: #00538F;
$link-hover-color: #cccccc;
$font-size: 20px;
Expand Down
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
@import "header";
@import "pagination";
@import "buttons";
@import "form";
@import "progress_bar";
18 changes: 18 additions & 0 deletions app/assets/stylesheets/buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,22 @@
display: flex;
align-items: center;
gap: 1rem;
}

.card-button {
color: $font-secondary-color;
text-align: center;
padding: $roundness;
border-radius: $roundness;
background-color: inherit;
border: 1px solid $line-color;
margin: 0 0 10px;
max-width: 100%;
text-decoration: none;
font-size: 0.8em;

&:hover {
box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
color: lighten($line-color, 20%);
}
}
45 changes: 45 additions & 0 deletions app/assets/stylesheets/form.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@import "variables";

.form-heading {
display: flex;
align-items: center;
gap: 0.5rem;

margin-bottom: 0.5rem;

h1 {
margin: 0;
}
}

.gt-form {
input, select {
height: 34px;
width: 100%;
padding: 0 5px;
outline: none;
border-radius: 5px;
background-color: $line-color;
color: $font-color;
border: 2px solid $background-color;
margin-bottom: 4px;
}

input[type="submit"] {
background-color: $highlight-color;
border: none;
padding: 2px 10px;
border-radius: 5px;
margin-top: 4px;

&:hover{
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}
}
}

.form-card-container {
width: 100%;
max-width: 600px;
margin: 0 auto;
}
42 changes: 6 additions & 36 deletions app/assets/stylesheets/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,6 @@ main {
box-sizing: border-box;
}

.gt-form {
input {
padding: 0 5px;
outline: none;
border-radius: 5px;
background-color: $line-color;
color: $font-color;
border: 2px solid $background-color;
}

input[type="submit"] {
background-color: $highlight-color;
border: none;
padding: 2px 10px;
border-radius: 5px;

&:hover{
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}
}
}

.quicklog { /*Can probably switch to gt-form once polished (TODO)*/
//width: 400px;
margin-top: 0;
Expand Down Expand Up @@ -220,8 +198,7 @@ main {
}

.due-date {
color: $line-color;
font-size: 0.9em;
color: $font-secondary-color;
font-style: italic;
}

Expand All @@ -233,20 +210,13 @@ main {
}
}

.form-heading {
display: flex;
align-items: center;
gap: 0.5rem;

margin-bottom: 0.5rem;

h1 {
margin: 0;
}
}

.col.mod-code {
width: 100px !important;
flex: 0 0 100px;
max-width: 100px;
}

.font-secondary {
color: $font-secondary-color;
font-size: 0.8em;
}
8 changes: 8 additions & 0 deletions app/assets/stylesheets/progress_bar.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@import "variables";

.progress-bar {
margin: 0;
padding: 0;
border-radius: 1px;
background-color: $line-color;
height: 3px;

Expand All @@ -16,4 +19,9 @@
.px-12px {
padding-left: 12px;
padding-right: 12px;
}

.mx-12px {
margin-left: 12px;
margin-right: 12px;
}
16 changes: 15 additions & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def home
.where(years: { user_id: current_user.id })
.includes(:uni_modules)

@years = Year.where(user_id: current_user.id).includes(:semesters)
@years = Year.where(user_id: current_user.id).includes(:semesters).order(weighting: :desc)

# Get the cumulative time logged for each module
@module_data = @uni_modules.map do |mod|
Expand All @@ -27,6 +27,20 @@ def home
}
end

@assessment_data = current_user.exam_results
.includes(:exam)
.map { |res| [res.exam.due, res.score] }

@exam_data = current_user.exam_results
.includes(:exam)
.select { |res| res.exam&.due.present? && res.score.present? }
.map do |res|
{
name: res.exam.name,
data: [[res.exam.due.to_date, res.score.to_f]]
}
end

@exam_type_data = Exam.joins(:uni_module)
.where(uni_modules: { id: @uni_modules.map(&:id) })
.group(:type)
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/uni_modules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class UniModulesController < ApplicationController
# GET /uni_modules or /uni_modules.json
def index
@uni_modules = UniModule.joins(semester: :year).where(years: { user_id: current_user.id })

if params[:search].present?
query = "%#{params[:search]}%"
@uni_modules = @uni_modules.where("LOWER(uni_modules.code) LIKE ? OR LOWER(uni_modules.name) LIKE ?", query.downcase, query.downcase)
end
end

# GET /uni_modules/1 or /uni_modules/1.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/years_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def set_year

# Only allow a list of trusted parameters through.
def year_params
params.require(:year).permit(:name)
params.require(:year).permit(:name, :weighting)
end
end
6 changes: 6 additions & 0 deletions app/models/semester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def achieved_score(user)
total_weight.zero? ? 0 : (weighted_sum / total_weight)
end

def progress(user)
total_credits = uni_modules.sum(:credits)
completed_credits = uni_modules.sum { |m| m.completion_percentage(user) * m.credits }
total_credits.zero? ? 0 : (completed_credits / total_credits)
end

private

def generate_share_token
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class User < ApplicationRecord
:recoverable, :rememberable, :validatable

has_many :years, dependent: :destroy
has_many :exam_results, dependent: :destroy
has_many :exams, through: :exam_results
has_many :uni_modules, through: :uni_module_targets
has_many :timelogs, dependent: :destroy
Expand Down
9 changes: 9 additions & 0 deletions app/models/year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ def credits
semesters.includes(:uni_modules).sum { |s| s.credits }
end

# The average of all the grades of the semesters in this year
def weighted_average(user)
return 0 if semesters.empty?
total_weight = semesters.sum { |s| s.credits }
weighted_sum = semesters.sum { |s| s.credits * s.weighted_average(user) }
total_weight.zero? ? 0 : (weighted_sum / total_weight)
end

# The percentage of credits completed by the user in this year
def progress(user)
return 0 if semesters.empty?
completed_credits = semesters.sum { |s| s.progress(user) }
completed_credits / semesters.count
end

# The accumulated score of all the completed exams in this year
def achieved_score(user)
return 0 if semesters.empty?
semesters.sum { |semester| semester.achieved_score(user) } / semesters.size
Expand Down
73 changes: 36 additions & 37 deletions app/views/devise/registrations/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
.container
.gt-card.gt-form
%h2
Edit #{resource_name.to_s.humanize}
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f|
= render "devise/shared/error_messages", resource: resource
.field
= f.label :email
.gt-card.gt-form
%h2
Edit #{resource_name.to_s.humanize}
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f|
= render "devise/shared/error_messages", resource: resource
.field
= f.label :email
%br/
= f.email_field :email, autofocus: true, autocomplete: "email"
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
%div
Currently waiting confirmation for: #{resource.unconfirmed_email}
.field
= f.label :password
%i (leave blank if you don't want to change it)
%br/
= f.password_field :password, autocomplete: "new-password"
- if @minimum_password_length
%br/
= f.email_field :email, autofocus: true, autocomplete: "email"
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
%div
Currently waiting confirmation for: #{resource.unconfirmed_email}
.field
= f.label :password
%i (leave blank if you don't want to change it)
%br/
= f.password_field :password, autocomplete: "new-password"
- if @minimum_password_length
%br/
%em
= @minimum_password_length
characters minimum
.field
= f.label :password_confirmation
%br/
= f.password_field :password_confirmation, autocomplete: "new-password"
.field
= f.label :current_password
%i (we need your current password to confirm your changes)
%br/
= f.password_field :current_password, autocomplete: "current-password"
.actions
= f.submit "Update"
%h3 Cancel my account
%div
Unhappy? #{button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete}
= link_to "Back", :back
%em
= @minimum_password_length
characters minimum
.field
= f.label :password_confirmation
%br/
= f.password_field :password_confirmation, autocomplete: "new-password"
.field
= f.label :current_password
%i (we need your current password to confirm your changes)
%br/
= f.password_field :current_password, autocomplete: "current-password"
.actions
= f.submit "Update"
%h3 Cancel my account
%div
Unhappy? #{button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete}
= link_to "Back", :back
45 changes: 22 additions & 23 deletions app/views/devise/registrations/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
.container
.gt-card.gt-form
%h2 Sign up
= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= render "devise/shared/error_messages", resource: resource
.field
= f.label :email
%br/
= f.email_field :email, autofocus: true, autocomplete: "email"
.field
= f.label :password
- if @minimum_password_length
%em
(#{@minimum_password_length} characters minimum)
%br/
= f.password_field :password, autocomplete: "new-password"
.field
= f.label :password_confirmation
%br/
= f.password_field :password_confirmation, autocomplete: "new-password"
.actions
= f.submit "Sign up"
= render "devise/shared/links"
.gt-card.gt-form
%h2 Sign up
= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= render "devise/shared/error_messages", resource: resource
.field
= f.label :email
%br/
= f.email_field :email, autofocus: true, autocomplete: "email"
.field
= f.label :password
- if @minimum_password_length
%em
(#{@minimum_password_length} characters minimum)
%br/
= f.password_field :password, autocomplete: "new-password"
.field
= f.label :password_confirmation
%br/
= f.password_field :password_confirmation, autocomplete: "new-password"
.actions
= f.submit "Sign up"
= render "devise/shared/links"
Loading
Loading