loading
Generated 2024-02-15T22:08:23-06:00

All Files ( 94.05% covered at 1.79 hits/line )

20 files in total.
168 relevant lines, 158 lines covered and 10 lines missed. ( 94.05% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
app/channels/application_cable/channel.rb 0.00 % 4 4 0 4 0.00
app/channels/application_cable/connection.rb 0.00 % 4 4 0 4 0.00
app/controllers/application_controller.rb 100.00 % 11 6 6 0 6.67
app/controllers/blueprints_controller.rb 100.00 % 10 4 4 0 1.75
app/controllers/home_controller.rb 100.00 % 4 2 2 0 1.00
app/controllers/items_controller.rb 100.00 % 48 22 22 0 1.95
app/controllers/plans_controller.rb 100.00 % 161 57 57 0 2.30
app/controllers/sessions_controller.rb 100.00 % 30 20 20 0 1.25
app/helpers/application_helper.rb 100.00 % 3 1 1 0 1.00
app/helpers/items_helper.rb 100.00 % 2 1 1 0 1.00
app/helpers/plans_helper.rb 100.00 % 2 1 1 0 1.00
app/helpers/steps_helper.rb 100.00 % 2 1 1 0 1.00
app/jobs/application_job.rb 0.00 % 7 2 0 2 0.00
app/mailers/application_mailer.rb 100.00 % 9 6 6 0 1.00
app/models/application_record.rb 100.00 % 3 2 2 0 1.00
app/models/item.rb 100.00 % 3 2 2 0 1.00
app/models/plan.rb 100.00 % 5 3 3 0 1.00
app/models/step.rb 100.00 % 6 4 4 0 1.00
app/models/user.rb 100.00 % 28 14 14 0 1.36
lib/omniauth/strategies/events360.rb 100.00 % 28 12 12 0 1.00

Controllers ( 100.0% covered at 2.23 hits/line )

6 files in total.
111 relevant lines, 111 lines covered and 0 lines missed. ( 100.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
app/controllers/application_controller.rb 100.00 % 11 6 6 0 6.67
app/controllers/blueprints_controller.rb 100.00 % 10 4 4 0 1.75
app/controllers/home_controller.rb 100.00 % 4 2 2 0 1.00
app/controllers/items_controller.rb 100.00 % 48 22 22 0 1.95
app/controllers/plans_controller.rb 100.00 % 161 57 57 0 2.30
app/controllers/sessions_controller.rb 100.00 % 30 20 20 0 1.25

Channels ( 0.0% covered at 0.0 hits/line )

2 files in total.
8 relevant lines, 0 lines covered and 8 lines missed. ( 0.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
app/channels/application_cable/channel.rb 0.00 % 4 4 0 4 0.00
app/channels/application_cable/connection.rb 0.00 % 4 4 0 4 0.00

Models ( 100.0% covered at 1.2 hits/line )

5 files in total.
25 relevant lines, 25 lines covered and 0 lines missed. ( 100.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
app/models/application_record.rb 100.00 % 3 2 2 0 1.00
app/models/item.rb 100.00 % 3 2 2 0 1.00
app/models/plan.rb 100.00 % 5 3 3 0 1.00
app/models/step.rb 100.00 % 6 4 4 0 1.00
app/models/user.rb 100.00 % 28 14 14 0 1.36

Mailers ( 100.0% covered at 1.0 hits/line )

1 files in total.
6 relevant lines, 6 lines covered and 0 lines missed. ( 100.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
app/mailers/application_mailer.rb 100.00 % 9 6 6 0 1.00

Helpers ( 100.0% covered at 1.0 hits/line )

4 files in total.
4 relevant lines, 4 lines covered and 0 lines missed. ( 100.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
app/helpers/application_helper.rb 100.00 % 3 1 1 0 1.00
app/helpers/items_helper.rb 100.00 % 2 1 1 0 1.00
app/helpers/plans_helper.rb 100.00 % 2 1 1 0 1.00
app/helpers/steps_helper.rb 100.00 % 2 1 1 0 1.00

Jobs ( 0.0% covered at 0.0 hits/line )

1 files in total.
2 relevant lines, 0 lines covered and 2 lines missed. ( 0.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
app/jobs/application_job.rb 0.00 % 7 2 0 2 0.00

Libraries ( 100.0% covered at 1.0 hits/line )

1 files in total.
12 relevant lines, 12 lines covered and 0 lines missed. ( 100.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
lib/omniauth/strategies/events360.rb 100.00 % 28 12 12 0 1.00

app/channels/application_cable/channel.rb

0.0% lines covered

4 relevant lines. 0 lines covered and 4 lines missed.
    
  1. module ApplicationCable
  2. class Channel < ActionCable::Channel::Base
  3. end
  4. end

app/channels/application_cable/connection.rb

0.0% lines covered

4 relevant lines. 0 lines covered and 4 lines missed.
    
  1. module ApplicationCable
  2. class Connection < ActionCable::Connection::Base
  3. end
  4. end

app/controllers/application_controller.rb

100.0% lines covered

6 relevant lines. 6 lines covered and 0 lines missed.
    
  1. 1 class ApplicationController < ActionController::Base
  2. 1 before_action :set_current_user
  3. 1 def set_current_user
  4. # finds user with session data and stores it if present
  5. 34 @current_user = User.find_by(email: session[:user_email]) if session[:user_email]
  6. end
  7. 1 def require_user_logged_in!
  8. # allows only logged in user
  9. 2 redirect_to root_path, alert: 'You must be signed in' if @current_user.nil?
  10. end
  11. end

app/controllers/blueprints_controller.rb

100.0% lines covered

4 relevant lines. 4 lines covered and 0 lines missed.
    
  1. 1 class BlueprintsController < ApplicationController
  2. 1 layout "layouts/blueprints"
  3. 1 def index
  4. # sending data to 3d module
  5. # render '/docs/index.html'
  6. # ADDED HERE, read the saved floorplan.json from public folder, render in 3D when page is opened
  7. 4 @snapshot = JSON.parse(File.read(Rails.root.join('public', 'floorplan.json')))
  8. end
  9. end

app/controllers/home_controller.rb

100.0% lines covered

2 relevant lines. 2 lines covered and 0 lines missed.
    
  1. 1 class HomeController < ApplicationController
  2. 1 def index
  3. end
  4. end

app/controllers/items_controller.rb

100.0% lines covered

22 relevant lines. 22 lines covered and 0 lines missed.
    
  1. 1 class ItemsController < ApplicationController
  2. 1 before_action :set_item, only: %i[ show edit update destroy ]
  3. # POST /items or /items.json
  4. 1 def create
  5. 4 @item = Item.new(item_params)
  6. 4 if @item.save
  7. 2 render json: @item, status: :ok
  8. else
  9. 2 render json: @item.errors, status: :unprocessable_entity
  10. end
  11. end
  12. # search for items by step_id
  13. 1 def search
  14. 2 @items = Item.where(step_id: params[:step_id])
  15. 2 render json: @items
  16. end
  17. # PATCH/PUT /items/1 or /items/1.json
  18. 1 def update
  19. 1 if @item.update(item_params)
  20. 1 render json: @item, status: :ok
  21. end
  22. end
  23. # DELETE /items/1 or /items/1.json
  24. 1 def destroy
  25. 2 @item.destroy
  26. 2 respond_to do |format|
  27. 4 format.json { head :no_content }
  28. end
  29. end
  30. 1 private
  31. # Use callbacks to share common setup or constraints between actions.
  32. 1 def set_item
  33. 3 @item = Item.find(params[:id])
  34. end
  35. # Only allow a list of trusted parameters through.
  36. 1 def item_params
  37. 5 params.require(:item).permit(:name, :model, :width, :length, :depth, :rotation, :description, :xpos, :ypos, :zpos, :step_id, :setup_start_time, :setup_end_time, :breakdown_start_time, :breakdown_end_time)
  38. end
  39. end

app/controllers/plans_controller.rb

100.0% lines covered

57 relevant lines. 57 lines covered and 0 lines missed.
    
  1. 1 class PlansController < ApplicationController
  2. 1 before_action :set_plan, only: %i[ show edit update destroy ]
  3. 15 before_action :require_user_logged_in!, unless: -> { !Rails.env.production? }
  4. # def user_plans
  5. # @user = User.from_omniauth(request.env['omniauth.auth'])
  6. # @plans = @user.plans
  7. # end
  8. 1 def upload_existing_plan
  9. # Process the uploaded file
  10. # Redirect to a different page upon successful file upload
  11. 1 redirect_to plans_path, notice: 'File uploaded successfully.'
  12. end
  13. 1 layout "layouts/empty", only: [:new]
  14. # GET /plans or /plans.json
  15. 1 def index
  16. # @plans = Plan.all
  17. # Only display plans of the logged in user
  18. 1 @plans = Plan.where(owner: session[:user_email])
  19. end
  20. # GET /plans/1 or /plans/1.json
  21. 1 def show
  22. 1 redirect_to edit_plan_path(@plan)
  23. end
  24. # GET /plans/new
  25. 1 def new
  26. 1 @plan = Plan.new
  27. 1 @plan.steps.build # Build an empty Step associated with the new Plan
  28. end
  29. # GET /plans/1/edit
  30. 1 def edit
  31. end
  32. 1 def floorplans2d
  33. 1 @plan = Plan.find(params[:id])
  34. end
  35. 1 def preview3d
  36. 4 snapshot_data_json = params[:snapshot_data]
  37. 4 snapshot_data = JSON.parse(snapshot_data_json)
  38. 4 scaler = 31.4
  39. 4 json_content = JSON.parse(File.read(Rails.root.join('lib', 'design.room3d')))
  40. # Update the corners of the floorplan
  41. 4 json_content["floorplan"]["corners"] = {
  42. "7922010e-f5f3-2e53-46f4-3819ea8cdc12" => {
  43. "x" => 0,
  44. "y" => 0,
  45. },
  46. "a8b17dd7-026c-de11-3077-01a169d1b795" => {
  47. "x" => snapshot_data["venue_width"] * scaler,
  48. "y" => 0,
  49. },
  50. "8039b51e-5a0b-8843-3129-32e647a42002" => {
  51. "x" => 0,
  52. "y" => snapshot_data["venue_length"] * scaler,
  53. },
  54. "8a66d562-2eb4-2147-763c-7962e4208a0a" => {
  55. "x" => snapshot_data["venue_width"] * scaler,
  56. "y" => snapshot_data["venue_length"] * scaler,
  57. }
  58. }
  59. # Add items to the floorplan
  60. 4 snapshot_data["items"].each do |item, values|
  61. 4 json_content["items"].append({
  62. "item_name" => values["item_name"],
  63. "item_type" => values["item_type"],
  64. "model_url" => values["item_model"],
  65. "xpos" => values["item_xpos"] * scaler,
  66. "ypos" => 0,
  67. "zpos" => values["item_zpos"] * scaler,
  68. "rotation" => 0,
  69. "scale_x" => 1,
  70. "scale_y" => 1,
  71. "scale_z" => 1,
  72. "fixed" => false
  73. })
  74. end
  75. # Write the updated information to a JSON file stored in the public folder called "floorplan.json"
  76. 4 File.write(Rails.root.join('public', 'floorplan.json'), JSON.pretty_generate(json_content))
  77. 4 redirect_to blueprints_path
  78. end
  79. # POST /plans or /plans.json
  80. 1 def create
  81. 1 @plan = Plan.new(plan_params)
  82. 1 respond_to do |format|
  83. 1 if @plan.save
  84. 2 format.html { redirect_to plans_path, notice: "Plan was successfully created." }
  85. # else # Currently doesn't handle error cases
  86. # format.html { render :new, status: :unprocessable_entity }
  87. # format.json { render json: @plan.errors, status: :unprocessable_entity }
  88. end
  89. end
  90. end
  91. # PATCH/PUT /plans/1 or /plans/1.json
  92. 1 def update
  93. 2 respond_to do |format|
  94. 2 if update_plan_with_steps
  95. 4 format.html { redirect_to plans_path, notice: 'Plan was successfully updated.' }
  96. 2 format.json { render :show, status: :ok, location: @plan }
  97. end
  98. end
  99. end
  100. 1 def update_plan_with_steps
  101. 2 if plan_params[:steps_attributes].nil?
  102. 1 return @plan.update(plan_params)
  103. end
  104. 1 steps_attributes = plan_params[:steps_attributes].to_unsafe_h
  105. 1 steps_attributes.each do |key, step_params|
  106. 1 %i[start_time end_time break1_start_time break1_end_time break2_start_time break2_end_time].each do |attr|
  107. 6 step_params[attr] = combine_date_and_time(step_params[:start_date], step_params[attr])
  108. end
  109. end
  110. 1 @plan.update(plan_params.merge(steps_attributes: steps_attributes))
  111. end
  112. 1 def combine_date_and_time(date, time)
  113. 6 return nil if date.blank? || time.blank?
  114. 6 DateTime.parse("#{date} #{time} #{Time.zone.now.strftime("%Z")}")
  115. end
  116. # DELETE /plans/1 or /plans/1.json
  117. 1 def destroy
  118. 1 @plan.destroy
  119. 1 respond_to do |format|
  120. 2 format.html { redirect_to plans_url, notice: "Plan was successfully destroyed." }
  121. 1 format.json { head :no_content }
  122. end
  123. end
  124. 1 private
  125. # Use callbacks to share common setup or constraints between actions.
  126. 1 def set_plan
  127. 5 @plan = Plan.find(params[:id])
  128. end
  129. # Only allow a list of trusted parameters through.
  130. 1 def plan_params
  131. # params.require(:plan).permit(:name, :owner, :venue_length, :venue_width, :user_email, steps_attributes: [:id, :start_date, :start_time, :end_time, :break1_start_time, :break1_end_time, :break2_start_time, :break2_end_time, :_destroy])
  132. 6 params.require(:plan).permit(:name, :owner, :timezone, :venue_length, :venue_width, steps_attributes: [:id, :start_date, :start_time, :end_time, :break1_start_time, :break1_end_time, :break2_start_time, :break2_end_time, :_destroy])
  133. end
  134. end

app/controllers/sessions_controller.rb

100.0% lines covered

20 relevant lines. 20 lines covered and 0 lines missed.
    
  1. 1 class SessionsController < ApplicationController
  2. 1 def new; end
  3. 1 def create
  4. 3 if Rails.env.production?
  5. 2 @user = User.from_omniauth(request.env['omniauth.auth'])
  6. 2 logger.info("IN PRODUCTION")
  7. 2 if @user.present?
  8. # session[:user_id] = @user.id
  9. 1 session[:user_email] = @user.email
  10. 1 redirect_to plans_path, notice: 'Logged in successfully as ' + @user.email
  11. 1 logger.info(@user.id)
  12. else
  13. 1 flash.alert = "User not found."
  14. 1 flash.now[:alert] = 'Invalid request'
  15. 1 redirect_to root_path, notice: 'Invalid username/email or password'
  16. end
  17. else
  18. 1 logger.info("NOT IN PRODUCTION")
  19. 1 @user = User.new(name: "Dummy User", email: "test@email.com")
  20. 1 session[:user_email] = @user.email
  21. 1 redirect_to plans_path, notice: 'Logged in successfully'
  22. end
  23. end
  24. 1 def destroy
  25. # deletes user session
  26. 1 session[:user_id] = nil
  27. 1 redirect_to root_path, notice: 'Logged Out'
  28. end
  29. end

app/helpers/application_helper.rb

100.0% lines covered

1 relevant lines. 1 lines covered and 0 lines missed.
    
  1. 1 module ApplicationHelper
  2. end

app/helpers/items_helper.rb

100.0% lines covered

1 relevant lines. 1 lines covered and 0 lines missed.
    
  1. 1 module ItemsHelper
  2. end

app/helpers/plans_helper.rb

100.0% lines covered

1 relevant lines. 1 lines covered and 0 lines missed.
    
  1. 1 module PlansHelper
  2. end

app/helpers/steps_helper.rb

100.0% lines covered

1 relevant lines. 1 lines covered and 0 lines missed.
    
  1. 1 module StepsHelper
  2. end

app/jobs/application_job.rb

0.0% lines covered

2 relevant lines. 0 lines covered and 2 lines missed.
    
  1. class ApplicationJob < ActiveJob::Base
  2. # Automatically retry jobs that encountered a deadlock
  3. # retry_on ActiveRecord::Deadlocked
  4. # Most jobs are safe to ignore if the underlying records are no longer available
  5. # discard_on ActiveJob::DeserializationError
  6. end

app/mailers/application_mailer.rb

100.0% lines covered

6 relevant lines. 6 lines covered and 0 lines missed.
    
  1. 1 class ApplicationMailer < ActionMailer::Base
  2. 1 default from: "from@example.com"
  3. 1 layout "mailer"
  4. 1 def example_email(user)
  5. 1 @user = user
  6. 1 mail(to: @user.email, subject: 'Subject of the email')
  7. end
  8. end

app/models/application_record.rb

100.0% lines covered

2 relevant lines. 2 lines covered and 0 lines missed.
    
  1. 1 class ApplicationRecord < ActiveRecord::Base
  2. 1 primary_abstract_class
  3. end

app/models/item.rb

100.0% lines covered

2 relevant lines. 2 lines covered and 0 lines missed.
    
  1. 1 class Item < ActiveRecord::Base
  2. 1 belongs_to :step
  3. end

app/models/plan.rb

100.0% lines covered

3 relevant lines. 3 lines covered and 0 lines missed.
    
  1. 1 class Plan < ActiveRecord::Base
  2. 1 has_many :steps, dependent: :destroy
  3. 1 accepts_nested_attributes_for :steps, allow_destroy: true # allows steps to be destroyed when plan is destroyed
  4. # belongs_to :user
  5. end

app/models/step.rb

100.0% lines covered

4 relevant lines. 4 lines covered and 0 lines missed.
    
  1. 1 class Step < ActiveRecord::Base
  2. 1 belongs_to :plan
  3. 1 has_many :items, dependent: :destroy
  4. 1 accepts_nested_attributes_for :items, allow_destroy: true # allows items to be destroyed when step is destroyed
  5. end

app/models/user.rb

100.0% lines covered

14 relevant lines. 14 lines covered and 0 lines missed.
    
  1. 1 class User < ApplicationRecord
  2. # adds virtual attributes for authentication
  3. 1 has_secure_password
  4. # validates user_name
  5. 1 validates :name, presence: true, uniqueness: true
  6. # validates email
  7. 1 validates :email, presence: true, uniqueness: true, format: { with: /\A[^@\s]+@[^@\s]+\z/, message: 'Invalid email' }
  8. # relationship with Floorplan
  9. # has_many :plans
  10. 1 def self.from_omniauth(access_token)
  11. 2 data = access_token.info
  12. 2 email = data['email']
  13. 2 name = data['name']
  14. 2 password = SecureRandom.urlsafe_base64(20).tr('lIO0', 'sxyz')
  15. # User.find_or_create_by(email:)
  16. 2 where(email: email).first_or_create do |user|
  17. 1 user.email = email
  18. 1 user.name = name
  19. 1 user.password = password
  20. 1 user.password_confirmation = password
  21. # user.initial_access = Time.now
  22. # user.last_access = Time.now
  23. end
  24. end
  25. end

lib/omniauth/strategies/events360.rb

100.0% lines covered

12 relevant lines. 12 lines covered and 0 lines missed.
    
  1. 1 require 'omniauth-oauth2'
  2. 1 module OmniAuth
  3. 1 module Strategies
  4. 1 class Events360 < OmniAuth::Strategies::OAuth2
  5. 1 option :name, :events360
  6. 1 option :client_options,
  7. site: ENV["NXT_APP_URL"],
  8. authorize_path: "/oauth/authorize"
  9. 1 uid do
  10. 1 raw_info["id"]
  11. end
  12. 1 info do
  13. {
  14. 1 name: raw_info["name"],
  15. email: raw_info["email"]
  16. }
  17. end
  18. 1 def raw_info
  19. 1 @raw_info ||= access_token.get("/api/user").parsed
  20. end
  21. end
  22. end
  23. end