-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
106 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Controller for lobbytrack report | ||
class LobbytrackController < ApplicationController | ||
def show | ||
@lobbytrack = LobbyTrack.query(params[:id]) | ||
return if @lobbytrack.any? | ||
if Settings.lobbytrack_ips.include?(client_ip.to_s) | ||
flash[:error] = 'You cannot access Lobbytrack from the current client IP address' | ||
else | ||
flash[:warning] = "There is no attendance history for id #{params[:id]}" | ||
end | ||
redirect_to root_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Class to connect to LobbyTraclk | ||
class LobbyTrack | ||
include ActiveModel::Model | ||
|
||
require 'tiny_tds' | ||
|
||
@client = TinyTds::Client.new username: Settings.lobbytrack_user, password: Settings.lobbytrack_password, | ||
host: Settings.lobbytrack_host, port: Settings.lobbytrack_port, | ||
database: Settings.lobbytrack_db | ||
|
||
def self.query(id) | ||
@client.active? ? @client.execute(sql(id)).each : @client.close | ||
end | ||
|
||
def self.sql(id) | ||
'SELECT CardHolderID, DateIn, ReportField1, ReportField2, LookupField1' \ | ||
' FROM Jolly.dbo.logAttendance' \ | ||
" WHERE CardHolderID = '#{id}'" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div class="home-page-section"> | ||
<h2>Visitor attendance report</h2> | ||
<h4> | ||
<p>ID: <%= @lobbytrack.first.values[0] %></p> | ||
<p>Name: <%= @lobbytrack.first.values[2] %> <%= @lobbytrack.first.values[3] %></p> | ||
<p>Email: <%= @lobbytrack.first.values[4] %></p> | ||
</h4> | ||
<p> | ||
<h4>Visits:</h4> | ||
</p> | ||
<div> | ||
<% @lobbytrack.each_with_index do |row, index| %> | ||
<ul> | ||
<li><%= index %>: <%= row.values[1] ? row.values[1].strftime('%F %R') : '' %></li> | ||
</ul> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="btn-group"> | ||
<%= main_menu_button %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20180905171401_add_lobbytrack_to_authorized_user.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddLobbytrackToAuthorizedUser < ActiveRecord::Migration | ||
def change | ||
add_column :authorized_user, :lobbytrack, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe LobbytrackController, type: :controller do | ||
describe 'get#show', type: :lobbytrack do | ||
before do | ||
stub_current_user(FactoryBot.create(:authorized_user)) | ||
end | ||
it 'returns the array of data if the id exists' do | ||
get :show, id: '1104840' | ||
expect(response).to render_template 'show' | ||
end | ||
it 'returns to the home page if the id does not exist' do | ||
get :show, id: '123' | ||
expect(flash).to be_present | ||
expect(response).to redirect_to root_path | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters