Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request Team254#1 from morops/theme_switch
Browse files Browse the repository at this point in the history
Theme switch
  • Loading branch information
morops authored Dec 27, 2017
2 parents 33c417d + 7ddf501 commit 8897fc3
Show file tree
Hide file tree
Showing 10 changed files with 983 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.log
*.pid
vendor
config.json
1 change: 1 addition & 0 deletions db/migrations/003_create_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
String :password, :null => false
String :salt, :null => false
String :permission, :null => false
String :theme, :null => false
end
end
end
2 changes: 1 addition & 1 deletion db/migrations/011_add_starting_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Sequel.migration do
up do
user = User.new(:email => "deleteme@team254.com", :first_name => "Delete", :last_name => "Me",
:permission => "admin", :enabled => 1)
:permission => "admin", :enabled => 1, :theme => "classic")
user.set_password("chezypofs")
user.save
end
Expand Down
5 changes: 4 additions & 1 deletion models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class User < Sequel::Model
HASH_BYTES = 24
SALT_BYTES = 24
PERMISSION_MAP = { "readonly" => "Read-only", "editor" => "Editor", "admin" => "Administrator" }

THEMES = {"classic" => "Classic", "cyborg" => "Cyborg", "slate" => "Slate"}
# Checks the given credentials against the database. Returns the user object on success and nil otherwise.
def self.authenticate(email, password)
user = User[:email => email]
Expand Down Expand Up @@ -40,4 +40,7 @@ def can_edit?
def can_administer?
self.permission == "admin"
end
def theme?(theme)
return theme == self.theme
end
end
1 change: 1 addition & 0 deletions parts_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ def send_email(to, subject, body)
@user_edit.last_name = params[:last_name] if params[:last_name]
@user_edit.set_password(params[:password]) if params[:password] && !params[:password].empty?
@user_edit.permission = params[:permission] if params[:permission]
@user_edit.theme = params[:theme] if params[:theme]
old_enabled = @user_edit.enabled
@user_edit.enabled = (params[:enabled] == "on") ? 1 : 0
if @user_edit.enabled == 1 && old_enabled == 0
Expand Down
9 changes: 9 additions & 0 deletions public/css/cyborg/bootstrap.min.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions public/css/dark/bootstrap.min.css

Large diffs are not rendered by default.

943 changes: 943 additions & 0 deletions public/css/slate/bootstrap.min.css

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions views/header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
<meta charset="utf-8">
<title>Cheesy Parts</title>
<link rel="shortcut icon" href="//media.team254.com/homepage/icons/favicon32.png">
<% if @user && @user.theme?("slate") %>
<link href="/css/slate/bootstrap.min.css" rel="stylesheet">
<% elsif @user && @user.theme?("cyborg") %>
<link href="/css/cyborg/bootstrap.min.css" rel="stylesheet">
<% else %>
<link href="/css/bootstrap.min.css" rel="stylesheet">
<% end %>
<link href="/css/bootstrap-datepicker.css" rel="stylesheet">
<link href='/css/css.css' rel='stylesheet' type='text/css' />
<script src="/js/jquery-1.8.3.min.js"></script>
Expand Down
6 changes: 6 additions & 0 deletions views/user_edit.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<option value=<%= key %><% if @user_edit.permission == key %> selected<% end %>><%= value %></option>
<% end %>
</select>
<label>Theme</label>
<select name="theme">
<% User::THEMES.each_pair do |key, value| %>
<option value=<%= key %><% if @user_edit.theme == key %> selected<% end %>><%= value %></option>
<% end %>
</select>
<label>Enabled?</label>
<input type="checkbox" name="enabled"<% if @user_edit.enabled == 1 %> checked<% end %> />
<br /><br />
Expand Down

0 comments on commit 8897fc3

Please sign in to comment.