Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoHsuProgrammingLab committed Oct 14, 2024
2 parents b31672d + 0911fd4 commit 70d149b
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 14 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ https://elrc-app-dfcfc7cd862b.herokuapp.com/

---

# Legacy Readme:
# Readme:

# Synergistic Leadership Theory Survey Application

[![Test Coverage](https://api.codeclimate.com/v1/badges/62f4dd4fb092b4211973/test_coverage)](https://codeclimate.com/repos/65caed0abc0d27237b1794c9/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/62f4dd4fb092b4211973/maintainability)](https://codeclimate.com/repos/65caed0abc0d27237b1794c9/maintainability)
<!--[![Test Coverage](https://api.codeclimate.com/v1/badges/62f4dd4fb092b4211973/test_coverage)](https://codeclimate.com/repos/65caed0abc0d27237b1794c9/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/62f4dd4fb092b4211973/maintainability)](https://codeclimate.com/repos/65caed0abc0d27237b1794c9/maintainability) -->
![rubocop](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/barnden/c7b2d5e19079e12445b300407e383294/raw/badge.json)

- [Deployed Application](https://elrc-app-dfcfc7cd862b.herokuapp.com/)
- [Code Climate Reports](https://codeclimate.com/repos/65caed0abc0d27237b1794c9/maintainability)
- [GitHub Repo](https://github.com/tamu-edu-students/csce606-ELRC-Synergistic-Leadership-Theory)
- [Pivotal Tracker](https://www.pivotaltracker.com/n/projects/2690137)
- [Slack](https://app.slack.com/client/T06GRHECJEM/C06GY2R74KX)
- [Code Climate Reports](https://codeclimate.com/github/tamu-edu-students/csce606-ELRC-OLEI_Project)
- [GitHub Repo](https://github.com/tamu-edu-students/csce606-ELRC-OLEI_Project)
- [Pivotal Tracker](https://www.pivotaltracker.com/n/projects/2720653)
- [Slack](https://app.slack.com/client/T07NQ098G0G/C07NE1HS2BB)

<details open="open">
<summary>Table of Contents</summary>
Expand Down
2 changes: 2 additions & 0 deletions rails_root/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ gem 'sprockets-rails'
# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '>= 5.0'

gem 'kaminari'

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem 'importmap-rails'

Expand Down
13 changes: 13 additions & 0 deletions rails_root/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ GEM
json (2.7.1)
jwt (2.8.1)
base64
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
language_server-protocol (3.17.0.3)
launchy (3.0.0)
addressable (~> 2.8)
Expand Down Expand Up @@ -519,6 +531,7 @@ DEPENDENCIES
factory_bot_rails
importmap-rails
jbuilder
kaminari
omniauth-auth0 (~> 3.0)
omniauth-rails_csrf_protection (~> 1.0)
pg
Expand Down
7 changes: 2 additions & 5 deletions rails_root/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* Ruby version: 3.3.0

* System dependencies

Expand All @@ -21,4 +19,3 @@ Things you may want to cover:

* Deployment instructions

* ...
6 changes: 6 additions & 0 deletions rails_root/app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#admins_controller.rb
class AdminsController < ApplicationController
def index
@survey_responses = SurveyResponse.get_all_responses(page: params[:page], per_page: 20)
end
end
2 changes: 2 additions & 0 deletions rails_root/app/helpers/admins_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AdminsHelper
end
4 changes: 4 additions & 0 deletions rails_root/app/models/survey_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def self.generate_share_code(params)
params.nil? ? SecureRandom.hex(3) : params[:share_code] || SecureRandom.hex(3)
end

def self.get_all_responses(page: 1, per_page: 20)
SurveyResponse.includes(:profile).order(created_at: :desc).page(page).per(per_page)
end

def self.create_survey_response(profile, share_code)
SurveyResponse.create(profile:, share_code:)
end
Expand Down
36 changes: 36 additions & 0 deletions rails_root/app/views/admins/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<main>
<h1 class="visually-hidden">Admin Dashboard</h1>
<% if session[:userinfo].present? %>
<h1>ADMIN DASHBOARD</h1>
<h2>Welcome <%= session[:userinfo]['name'] %></h2>
<hr>
<h3>Survey Responses</h3>
<div class="table-responsive">
<table class = "table">
<thead>
<tr>
<th>ID</th>
<th>Profile</th>
<th>Share Code</th>
<th>Created At</th>
</tr>
</thead>
<% if @survey_responses.present? %>
<tbody>
<% @survey_responses.each do |response| %>
<tr>
<td><%= response.id %></td>
<td><%= response.profile.user_id %></td>
<td><%= response.share_code %></td>
<td><%= response.created_at.strftime('%Y-%m-%d %H:%M:%S') %></td>
</tr>
<% end %>
</tbody>
<% end %>
</table>
</div>
<% else %>
<h1>Welcome.</h1>
<h1>You are not logged in. Please login.</h1>
<% end %>
</main>
14 changes: 14 additions & 0 deletions rails_root/config/initializers/kaminari_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

Kaminari.configure do |config|
# config.default_per_page = 25
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
# config.max_pages = nil
# config.params_on_first_page = false
end
2 changes: 2 additions & 0 deletions rails_root/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

Rails.application.routes.draw do
get 'admins/index'
resources :survey_questions
# Defines the root path route ("/")
root 'home#index'

get 'home/index'
get 'about', to: 'about#index'
get '/admin', to: 'admins#index'

# get 'survey', to: 'survey_responses#new', as: 'survey'
# get 'survey/page/:page', to: 'survey_responses#survey', as: 'survey_page'
Expand Down
15 changes: 15 additions & 0 deletions rails_root/spec/helpers/admins_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the AdminsHelper. For example:
#
# describe AdminsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe AdminsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
11 changes: 11 additions & 0 deletions rails_root/spec/requests/admins_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'rails_helper'

RSpec.describe "Admins", type: :request do
describe "GET /index" do
it "returns http success" do
get "/admins/index"
expect(response).to have_http_status(:success)
end
end

end
5 changes: 5 additions & 0 deletions rails_root/spec/views/admins/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe "admins/index.html.erb", type: :view do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 70d149b

Please sign in to comment.