Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
final_project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
evilla_gomez_guian_principe
final_project
Commits
12415de3
Commit
12415de3
authored
Jul 20, 2016
by
Wills Gomez
Browse files
Options
Browse Files
Download
Plain Diff
vote tally count WIP
parents
fb786f5d
71527855
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
121 additions
and
27 deletions
+121
-27
users_controller.rb
Halalan/app/controllers/users/users_controller.rb
+1
-1
users_controller.rb
Halalan/app/controllers/users_controller.rb
+45
-0
user.rb
Halalan/app/models/user.rb
+7
-0
index.html.erb
Halalan/app/views/admin/candidates/index.html.erb
+6
-1
show.html.erb
Halalan/app/views/admin/candidates/show.html.erb
+3
-9
index.html.erb
Halalan/app/views/admin/positions/index.html.erb
+10
-0
show.html.erb
Halalan/app/views/admin/positions/show.html.erb
+3
-2
index.html.erb
Halalan/app/views/pages/index.html.erb
+31
-0
_form.html.erb
Halalan/app/views/voting/votes/_form.html.erb
+1
-1
routes.rb
Halalan/config/routes.rb
+1
-1
20160719111009_add_roles_to_user.rb
Halalan/db/migrate/20160719111009_add_roles_to_user.rb
+0
-5
20160719180641_add_role_to_users.rb
Halalan/db/migrate/20160719180641_add_role_to_users.rb
+6
-0
schema.rb
Halalan/db/schema.rb
+7
-7
No files found.
Halalan/app/controllers/users/
profile
_controller.rb
→
Halalan/app/controllers/users/
users
_controller.rb
View file @
12415de3
module
Users
class
Profile
Controller
<
ApplicationController
class
Users
Controller
<
ApplicationController
before_action
:authenticate_user!
def
index
@positions
=
Position
.
all
...
...
Halalan/app/controllers/users_controller.rb
0 → 100644
View file @
12415de3
class
UsersController
<
ApplicationController
before_filter
:authenticate_user!
before_filter
:admin_only
,
:except
=>
:show
def
index
@users
=
User
.
all
end
def
show
@user
=
User
.
find
(
params
[
:id
])
unless
current_user
.
admin?
unless
@user
==
current_user
redirect_to
:back
,
:alert
=>
"Access denied."
end
end
end
def
update
@user
=
User
.
find
(
params
[
:id
])
if
@user
.
update_attributes
(
secure_params
)
redirect_to
users_path
,
:notice
=>
"User updated."
else
redirect_to
users_path
,
:alert
=>
"Unable to update user."
end
end
def
destroy
user
=
User
.
find
(
params
[
:id
])
user
.
destroy
redirect_to
users_path
,
:notice
=>
"User deleted."
end
private
def
admin_only
unless
current_user
.
admin?
redirect_to
:back
,
:alert
=>
"Access denied."
end
end
def
secure_params
params
.
require
(
:user
).
permit
(
:role
)
end
end
\ No newline at end of file
Halalan/app/models/user.rb
View file @
12415de3
...
...
@@ -13,4 +13,11 @@ class User < ApplicationRecord
"
#{
self
.
first_name
}
#{
self
.
last_name
}
"
end
enum
role:
{
voter:
0
,
admin:
1
}
after_initialize
:set_default_role
,
:if
=>
:new_record?
def
set_default_role
self
.
role
=
:voter
end
end
Halalan/app/views/admin/candidates/index.html.erb
View file @
12415de3
...
...
@@ -7,11 +7,16 @@
<%
@positions
.
each
do
|
p
|
%>
<
<<<<<<
HEAD
<
h3
>
<%=
p
.
name
%>
</h3>
<ul
>
=======
<h2>
<%=
p
.
name
%>
</h2>
<ul>
>>>>>>> 715278555f37edd654b7c9770ce3962b9079fc3b
<%
p
.
candidates
.
each
do
|
c
|
%>
<li>
<%=
link_to
c
.
full_name
,
admin_candidate_path
(
c
.
id
)
%>
</li>
<%
end
%>
</ul>
<%
end
%>
<%
end
%>
Halalan/app/views/admin/candidates/show.html.erb
View file @
12415de3
...
...
@@ -4,11 +4,6 @@
<%=
link_to
"Delete"
,
admin_candidate_path
(
@candidate
.
id
),
method: :delete
%>
<br>
<h3>
Position:
<%=
@candidate
.
position
.
name
%>
</h3>
<%
m
=
0
f
=
0
o
=
0
%>
<%
m
=
0
f
=
0
...
...
@@ -32,18 +27,17 @@
<hr>
<table
width=
"100%"
>
<h4>
Gender of Voters
</h4>
<tr>
<th>
Male Voters
</th>
<th>
Female Voters
</th>
<th>
Other Voters
</th>
<th>
Total Active Votes
</th>
<th>
Total Active and Inactive Casted Votes
</th>
<th>
Total Votes
</th>
</tr>
<tr>
<td>
<%=
m
%>
</td>
<td>
<%=
f
%>
</td>
<td>
<%=
o
%>
</td>
<td>
<%=
m
+
f
+
o
%>
</td>
<td>
<%=
@candidate
.
votes
.
count
%>
</td>
</tr>
</table>
...
...
@@ -53,7 +47,7 @@
<ul>
<li>
<%
@candidate
.
votes
.
each
do
|
v
|
%>
<%=
"
#{
v
.
user
.
full_name
}
"
%>
<%=
"
#{
v
.
user
.
full_name
}
"
%>
<p>
Comments:
<%=
v
.
comment
%>
</p>
...
...
Halalan/app/views/admin/positions/index.html.erb
View file @
12415de3
...
...
@@ -3,6 +3,7 @@
<%=
link_to
"Add New Position"
,
new_admin_position_path
%>
<hr>
<
<<<<<<
HEAD
<%
@positions
.
each
do
|
c
|
%>
<
h2
><a
href=
"/admin/positions/show"
>
<%
c
.
name
%>
</a></h2>
<ul>
...
...
@@ -11,4 +12,13 @@
<%
end
%>
</ul>
=======
<%
@positions
.
each
do
|
p
|
%>
<h2>
<%=
link_to
p
.
name
,
admin_position_path
(
p
.
id
)
%>
</h2>
<ul>
<%
p
.
candidates
.
each
do
|
c
|
%>
<li>
<%=
link_to
c
.
full_name
,
admin_candidate_path
(
c
.
id
)
%>
</li>
<%
end
%>
</ul>
>>>>>>> 715278555f37edd654b7c9770ce3962b9079fc3b
<%
end
%>
\ No newline at end of file
Halalan/app/views/admin/positions/show.html.erb
View file @
12415de3
<h1>
<%=
@position
.
name
%>
</h1>
<%=
link_to
"Edit"
,
edit_admin_position_path
(
@position
.
id
)
%>
<br>
<%=
link_to
"Delete"
,
admin_position_path
(
@position
.
id
),
method: :delete
%>
<br>
<hr>
<h2>
Candidates for
<%=
@position
.
name
%>
</h2>
<h5>
Candidates for
<%=
@position
.
name
%>
</h5>
<ul>
<%
@position
.
candidates
.
each
do
|
c
|
%>
<li>
<%=
link_to
c
.
full_name
,
admin_candidate_path
(
c
.
id
)
%>
</li>
...
...
Halalan/app/views/pages/index.html.erb
View file @
12415de3
...
...
@@ -2,7 +2,19 @@
<br>
<br>
<%
if
user_signed_in?
%>
<%
case
current_user
.
role
%>
<%
when
'voter'
%>
<h3>
Welcome, Voter
</h3>
<%
when
'admin'
%>
<h3>
Welcome, Administrator
</h3>
<%
end
%>
<%
else
%>
<h3>
Welcome
</h3>
<%
end
%>
<%
@positions
.
each
do
|
p
|
%>
<
<<<<<<
HEAD
<
div
class =
"section"
>
<div
class =
"box"
>
<h4><center>
<%=
p
.
name
%>
</center></h4>
...
...
@@ -29,4 +41,23 @@
</table>
</div>
</div>
=======
<h4>
<%=
p
.
name
%>
</h4>
<table
class=
"table table-striped table-bordered"
>
<tr>
<th>
Name
</th>
<th>
Slogan
</th>
<th>
Total Votes
</th>
</tr>
<%
total
=
0
%>
<%
p
.
candidates
.
each
do
|
c
|
%>
<tr>
<td>
<%=
link_to
c
.
full_name
,
admin_candidate_path
(
c
.
id
)
%>
</td>
<td>
<%=
c
.
slogan
%>
</td>
<td>
<%=
c
.
votes
.
count
%>
</td>
</tr>
<%
end
%>
</table>
>>>>>>> 715278555f37edd654b7c9770ce3962b9079fc3b
<%
end
%>
\ No newline at end of file
Halalan/app/views/voting/votes/_form.html.erb
View file @
12415de3
...
...
@@ -10,5 +10,5 @@
I cast my vote for
<%=
f
.
association
:candidate
,
collection:
Candidate
.
where
(
position_id
:@pos
),
label_method: :full_name
,
value_method: :id
%>
<%=
f
.
input
:comment
,
label:
'Comment:'
%>
<%=
f
.
submit
%>
<%=
f
.
submit
label:
'Cast Vote'
%>
<%
end
%>
Halalan/config/routes.rb
View file @
12415de3
...
...
@@ -5,7 +5,7 @@ Rails.application.routes.draw do
resources
:users
get
"/profile"
,
to:
"users/
profile
#index"
get
"/profile"
,
to:
"users/
users
#index"
get
"/voting/new/:id"
,
to:
"voting/votes#new"
get
"/about"
=>
"pages#about"
,
as: :about
...
...
Halalan/db/migrate/20160719111009_add_roles_to_user.rb
deleted
100644 → 0
View file @
fb786f5d
class
AddRolesToUser
<
ActiveRecord
::
Migration
[
5.0
]
def
change
add_column
:users
,
:role
,
:string
,
:default
=>
'user'
end
end
Halalan/db/migrate/20160719180641_add_role_to_users.rb
0 → 100644
View file @
12415de3
class
AddRoleToUsers
<
ActiveRecord
::
Migration
[
5.0
]
def
change
remove_column
:users
,
:role
,
:string
,
:default
=>
'user'
add_column
:users
,
:role
,
:integer
end
end
Halalan/db/schema.rb
View file @
12415de3
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201607191
11009
)
do
ActiveRecord
::
Schema
.
define
(
version:
201607191
80641
)
do
create_table
"candidates"
,
force: :cascade
do
|
t
|
t
.
string
"first_name"
...
...
@@ -29,23 +29,23 @@ ActiveRecord::Schema.define(version: 20160719111009) do
end
create_table
"users"
,
force: :cascade
do
|
t
|
t
.
string
"email"
,
default:
""
,
null:
false
t
.
string
"encrypted_password"
,
default:
""
,
null:
false
t
.
string
"email"
,
default:
""
,
null:
false
t
.
string
"encrypted_password"
,
default:
""
,
null:
false
t
.
string
"reset_password_token"
t
.
datetime
"reset_password_sent_at"
t
.
datetime
"remember_created_at"
t
.
integer
"sign_in_count"
,
default:
0
,
null:
false
t
.
integer
"sign_in_count"
,
default:
0
,
null:
false
t
.
datetime
"current_sign_in_at"
t
.
datetime
"last_sign_in_at"
t
.
string
"current_sign_in_ip"
t
.
string
"last_sign_in_ip"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
string
"first_name"
t
.
string
"last_name"
t
.
string
"gender"
t
.
date
"birthday"
t
.
string
"role"
,
default:
"user
"
t
.
integer
"role
"
t
.
index
[
"email"
],
name:
"index_users_on_email"
,
unique:
true
t
.
index
[
"reset_password_token"
],
name:
"index_users_on_reset_password_token"
,
unique:
true
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment