diff --git a/app/assets/stylesheets/app.scss b/app/assets/stylesheets/app.scss new file mode 100644 index 0000000..deb6210 --- /dev/null +++ b/app/assets/stylesheets/app.scss @@ -0,0 +1,22 @@ +.avatar { + display: inline-block; + overflow: hidden; + line-height: 1; + vertical-align: middle; + border-radius: 3px; +} +.user-nav .avatar { + float: left; + margin-right: 5px; +} +.dropdown-caret { + display: inline-block; + width: 0; + height: 0; + vertical-align: middle; + content: ""; + border: 4px solid; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; +} diff --git a/app/controllers/course_controller.rb b/app/controllers/course_controller.rb index 7f37cf6..e5fc01c 100644 --- a/app/controllers/course_controller.rb +++ b/app/controllers/course_controller.rb @@ -4,7 +4,7 @@ class CourseController < ApplicationController def show @course_name = Setting.course @course_org = nil - if @course_name + if !@course_name.blank? mo = machine_octokit @course_org = mo.org(@course_name) else @@ -14,7 +14,7 @@ def show end def setup - if Setting.course + if !Setting.course.blank? redirect_to course_path, alert: "A course has already been set up for this application" else client = session_octokit diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ef59381..dc5afcc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,7 @@ class UsersController < ApplicationController before_action :authenticate_user! before_action :require_instructor!, :except => [:match_to_student] - before_action :correct_user?, :except => [:index, :set_as_instructor] + before_action :correct_user?, :only => [:show] def index @users = User.all @@ -11,6 +11,15 @@ def show @user = User.find(params[:id]) end + def settings + @user_settings = current_user.settings + end + + def update_settings + current_user.settings.discoverable = params[:discoverable] == "1" + redirect_to settings_path, notice: "Settings have been updated" + end + def toggle_instructor_privilege user = User.find(params[:id]) if is_instructor? diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..c9c9ab2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,11 @@ module ApplicationHelper + def github_profile_img_for(user, height=20, width=20) + image_tag( + "https://avatars2.githubusercontent.com/u/#{user.uid}?v=3&s=40", + height: "#{height}", + width: "#{width}", + alt: "@#{user.username}", + class: "avatar" + ) + end end diff --git a/app/models/user.rb b/app/models/user.rb index 4eadaab..6a6cf8d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ApplicationRecord + include RailsSettings::Extend def self.create_with_omniauth(auth) create! do |user| @@ -11,6 +12,14 @@ def self.create_with_omniauth(auth) end end + def discoverable? + self.settings.discoverable == true + end + + def self.discoverable_users + User.with_settings_for('discoverable').select {|u| u.discoverable? } + end + def attempt_match_to_student(client, machine) course = Setting.course return if not course diff --git a/app/views/layouts/_nav_links_for_auth.html.erb b/app/views/layouts/_nav_links_for_auth.html.erb index 2b1155e..01f3cfe 100644 --- a/app/views/layouts/_nav_links_for_auth.html.erb +++ b/app/views/layouts/_nav_links_for_auth.html.erb @@ -1,12 +1,23 @@ <% if user_signed_in? %> -
  • <%= link_to 'Sign out', signout_path %>
  • + <% else %> -
  • <%= link_to 'Sign in', signin_path %>
  • -<% end %> -<% if user_signed_in? %> -
  • <%= link_to 'Course', course_path %>
  • -<% end %> -<% if is_instructor? %> -
  • <%= link_to 'Users', users_path %>
  • -
  • <%= link_to 'Course Roster', students_path %>
  • +
  • <% end %> diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index d4b66f0..dbe8971 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -13,6 +13,8 @@ diff --git a/app/views/layouts/_navigation_links.html.erb b/app/views/layouts/_navigation_links.html.erb index 3540e84..fede149 100644 --- a/app/views/layouts/_navigation_links.html.erb +++ b/app/views/layouts/_navigation_links.html.erb @@ -1,2 +1,8 @@ <%# add navigation links to this file %> - +<% if user_signed_in? %> +
  • <%= link_to 'Course', course_path %>
  • +<% end %> +<% if is_instructor? %> +
  • <%= link_to 'Users', users_path %>
  • +
  • <%= link_to 'Course Roster', students_path %>
  • +<% end %> diff --git a/app/views/users/settings.html.erb b/app/views/users/settings.html.erb new file mode 100644 index 0000000..e1035d3 --- /dev/null +++ b/app/views/users/settings.html.erb @@ -0,0 +1,25 @@ +
    +

    User Settings

    + + <%= form_tag(update_settings_path) do -%> +

    In order to work in pairs or groups for your assignments, you must be "discoverable" by your classmates.

    +

    The information that becomes accessible to your fellow classmates if you become "discoverable" includes but is not limited to: +

    +

    +

    Do you wish to be set as "discoverable" so that you can be found by your classmates?

    + +
    + +
    + +
    <%= button_tag 'Save Settings', class: "btn btn-primary" %>
    + <% end -%> +
    diff --git a/config/app.yml b/config/app.yml index e9edea6..0b0e6ab 100644 --- a/config/app.yml +++ b/config/app.yml @@ -1,7 +1,6 @@ # config/app.yml for rails-settings-cached defaults: &defaults - foo: "Foo" - bar: 123 + discoverable: false instructors: [] development: diff --git a/config/routes.rb b/config/routes.rb index e3ce670..01326d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,13 +7,16 @@ post '/students/import' resources :students + + get '/settings' => 'users#settings' + post '/settings' => 'users#update_settings', :as => :update_settings resources :users do member do post 'toggle_instructor_privilege' post 'match' => 'users#match_to_student' end end - + get '/auth/:provider/callback' => 'sessions#create' get '/signin' => 'sessions#new', :as => :signin get '/signout' => 'sessions#destroy', :as => :signout