-
Notifications
You must be signed in to change notification settings - Fork 13
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
1 parent
1565536
commit b541fcb
Showing
18 changed files
with
228 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
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,3 @@ | ||
// Place all the styles related to the CrowdInputs controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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,44 @@ | ||
class CrowdInputsController < ApplicationController | ||
before_action :set_crowd_input, only: [:show, :edit, :update, :destroy] | ||
before_action :authenticate_user! | ||
|
||
# GET /crowd_inputs | ||
# GET /crowd_inputs.json | ||
def index | ||
@crowd_inputs = CrowdInput.all | ||
end | ||
|
||
# GET /crowd_inputs/new | ||
def new | ||
@crowd_input = CrowdInput.new | ||
@crowd_input.tps_id = Tps.random_id | ||
end | ||
|
||
# POST /crowd_inputs | ||
# POST /crowd_inputs.json | ||
def create | ||
@crowd_input = CrowdInput.new(crowd_input_params) | ||
@crowd_input.user_id = current_user.id | ||
|
||
respond_to do |format| | ||
if @crowd_input.save | ||
format.html { redirect_to new_crowd_input_path, notice: 'Your previous input was successfully added.' } | ||
format.json { render :show, status: :created, location: @crowd_input } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @crowd_input.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_crowd_input | ||
@crowd_input = CrowdInput.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def crowd_input_params | ||
params.require(:crowd_input).permit(:user_id, :tps_id, :prabowo_count, :jokowi_count, :broken_count, :problem) | ||
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
class PagesController < ApplicationController | ||
def home | ||
if user_signed_in? | ||
redirect_to new_crowd_input_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CrowdInputsHelper | ||
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,8 @@ | ||
class CrowdInput < ActiveRecord::Base | ||
belongs_to :tps | ||
belongs_to :user | ||
|
||
def c1_url | ||
return tps.c1_url | ||
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,28 @@ | ||
.row | ||
.col-md-3 | ||
= form_for @crowd_input do |f| | ||
- if @crowd_input.errors.any? | ||
#error_explanation | ||
%h2= "#{pluralize(@crowd_input.errors.count, "error")} prohibited this crowd_input from being saved:" | ||
%ul | ||
- @crowd_input.errors.full_messages.each do |msg| | ||
%li= msg | ||
.form-group | ||
= f.hidden_field :tps_id | ||
.form-group | ||
= f.label :Prabowo | ||
= f.number_field :prabowo_count, :class => 'form-control' | ||
.form-group | ||
= f.label :Jokowi | ||
= f.number_field :jokowi_count, :class => 'form-control' | ||
.form-group | ||
= f.label :Rusak | ||
= f.number_field :broken_count, :class => 'form-control' | ||
.form-group | ||
= f.label :problem | ||
= f.text_area :problem, :class => 'form-control' | ||
.actions | ||
= f.submit 'Save', :class => 'btn btn-primary' | ||
= link_to "Lihat hasil", crowd_inputs_path, :class => 'btn btn-default' | ||
.col-md-9 | ||
= image_tag @crowd_input.c1_url, size:"600x800" |
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,23 @@ | ||
.row | ||
.col-md-12 | ||
%table.table.table-striped | ||
%tr | ||
%th User | ||
%th Tps | ||
%th Prabowo | ||
%th Jokowi | ||
%th Broken | ||
%th Problem | ||
|
||
- @crowd_inputs.each do |crowd_input| | ||
%tr | ||
%td= crowd_input.user.name | ||
%td= link_to crowd_input.tps_id, crowd_input.c1_url | ||
%td= crowd_input.prabowo_count | ||
%td= crowd_input.jokowi_count | ||
%td= crowd_input.broken_count | ||
%td= crowd_input.problem | ||
|
||
%br | ||
|
||
= link_to 'New input', new_crowd_input_path, "class" => 'btn btn-primary' |
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,4 @@ | ||
json.array!(@crowd_inputs) do |crowd_input| | ||
json.extract! crowd_input, :id, :user_id, :tps_id, :prabowo_count, :jokowi_count, :broken_count, :problem | ||
json.url crowd_input_url(crowd_input, format: :json) | ||
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 @@ | ||
= render 'form' |
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,14 @@ | ||
class CreateCrowdInputs < ActiveRecord::Migration | ||
def change | ||
create_table :crowd_inputs do |t| | ||
t.integer :user_id | ||
t.integer :tps_id | ||
t.integer :prabowo_count | ||
t.integer :jokowi_count | ||
t.integer :broken_count | ||
t.text :problem | ||
|
||
t.timestamps | ||
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
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,49 @@ | ||
require 'test_helper' | ||
|
||
class CrowdInputsControllerTest < ActionController::TestCase | ||
setup do | ||
@crowd_input = crowd_inputs(:one) | ||
end | ||
|
||
test "should get index" do | ||
get :index | ||
assert_response :success | ||
assert_not_nil assigns(:crowd_inputs) | ||
end | ||
|
||
test "should get new" do | ||
get :new | ||
assert_response :success | ||
end | ||
|
||
test "should create crowd_input" do | ||
assert_difference('CrowdInput.count') do | ||
post :create, crowd_input: { broken_count: @crowd_input.broken_count, jokowi_count: @crowd_input.jokowi_count, prabowo_count: @crowd_input.prabowo_count, problem: @crowd_input.problem, tps_id: @crowd_input.tps_id, user_id: @crowd_input.user_id } | ||
end | ||
|
||
assert_redirected_to crowd_input_path(assigns(:crowd_input)) | ||
end | ||
|
||
test "should show crowd_input" do | ||
get :show, id: @crowd_input | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get :edit, id: @crowd_input | ||
assert_response :success | ||
end | ||
|
||
test "should update crowd_input" do | ||
patch :update, id: @crowd_input, crowd_input: { broken_count: @crowd_input.broken_count, jokowi_count: @crowd_input.jokowi_count, prabowo_count: @crowd_input.prabowo_count, problem: @crowd_input.problem, tps_id: @crowd_input.tps_id, user_id: @crowd_input.user_id } | ||
assert_redirected_to crowd_input_path(assigns(:crowd_input)) | ||
end | ||
|
||
test "should destroy crowd_input" do | ||
assert_difference('CrowdInput.count', -1) do | ||
delete :destroy, id: @crowd_input | ||
end | ||
|
||
assert_redirected_to crowd_inputs_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,17 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
user_id: 1 | ||
tps_id: 1 | ||
prabowo_count: 1 | ||
jokowi_count: 1 | ||
broken_count: 1 | ||
problem: MyText | ||
|
||
two: | ||
user_id: 1 | ||
tps_id: 1 | ||
prabowo_count: 1 | ||
jokowi_count: 1 | ||
broken_count: 1 | ||
problem: MyText |
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,4 @@ | ||
require 'test_helper' | ||
|
||
class CrowdInputsHelperTest < ActionView::TestCase | ||
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,7 @@ | ||
require 'test_helper' | ||
|
||
class CrowdInputTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |