Skip to content

Commit

Permalink
Merge branch 'feature/encode-controller' into develop
Browse files Browse the repository at this point in the history
* feature/encode-controller:
  rails g scaffold encode log:text started_at:timestamp ended_at:timestamp runtime:float completed:boolean user:references published:boolean

# Conflicts:
#	config/routes.rb
  • Loading branch information
Simba830 committed Jul 3, 2020
2 parents af2bd40 + b2be0e6 commit 65d309d
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/encodes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the encodes controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
65 changes: 65 additions & 0 deletions app/assets/stylesheets/scaffolds.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
body {
background-color: #fff;
color: #333;
margin: 33px; }

body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

pre {
background-color: #eee;
padding: 10px;
font-size: 11px; }

a {
color: #000; }

a:visited {
color: #666; }

a:hover {
color: #fff;
background-color: #000; }

th {
padding-bottom: 5px; }

td {
padding: 0 5px 7px; }

div.field,
div.actions {
margin-bottom: 10px; }

#notice {
color: green; }

.field_with_errors {
padding: 2px;
background-color: red;
display: table; }

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px 7px 0;
margin-bottom: 20px;
background-color: #f0f0f0; }

#error_explanation h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px -7px 0;
background-color: #c00;
color: #fff; }

#error_explanation ul li {
font-size: 12px;
list-style: square; }

label {
display: block; }
74 changes: 74 additions & 0 deletions app/controllers/encodes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class EncodesController < ApplicationController
before_action :set_encode, only: [:show, :edit, :update, :destroy]

# GET /encodes
# GET /encodes.json
def index
@encodes = Encode.all
end

# GET /encodes/1
# GET /encodes/1.json
def show
end

# GET /encodes/new
def new
@encode = Encode.new
end

# GET /encodes/1/edit
def edit
end

# POST /encodes
# POST /encodes.json
def create
@encode = Encode.new(encode_params)

respond_to do |format|
if @encode.save
format.html { redirect_to @encode, notice: 'Encode was successfully created.' }
format.json { render :show, status: :created, location: @encode }
else
format.html { render :new }
format.json { render json: @encode.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /encodes/1
# PATCH/PUT /encodes/1.json
def update
respond_to do |format|
if @encode.update(encode_params)
format.html { redirect_to @encode, notice: 'Encode was successfully updated.' }
format.json { render :show, status: :ok, location: @encode }
else
format.html { render :edit }
format.json { render json: @encode.errors, status: :unprocessable_entity }
end
end
end

# DELETE /encodes/1
# DELETE /encodes/1.json
def destroy
@encode.destroy
respond_to do |format|
format.html { redirect_to encodes_url, notice: 'Encode was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_encode
@encode = Encode.find(params[:id])
end

# Only allow a list of trusted parameters through.
def encode_params
params.require(:encode).permit(:log, :started_at, :ended_at, :runtime, :completed, :user_id, :published)
end
end
2 changes: 2 additions & 0 deletions app/helpers/encodes_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module EncodesHelper
end
3 changes: 3 additions & 0 deletions app/models/encode.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Encode < ApplicationRecord
belongs_to :user
end
2 changes: 2 additions & 0 deletions app/views/encodes/_encode.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! encode, :id, :log, :started_at, :ended_at, :runtime, :completed, :user_id, :published, :created_at, :updated_at
json.url encode_url(encode, format: :json)
52 changes: 52 additions & 0 deletions app/views/encodes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<%= form_with(model: encode, local: true) do |form| %>
<% if encode.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(encode.errors.count, "error") %> prohibited this encode from being saved:</h2>

<ul>
<% encode.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= form.label :log %>
<%= form.text_area :log %>
</div>

<div class="field">
<%= form.label :started_at %>
<%= form.datetime_select :started_at %>
</div>

<div class="field">
<%= form.label :ended_at %>
<%= form.datetime_select :ended_at %>
</div>

<div class="field">
<%= form.label :runtime %>
<%= form.text_field :runtime %>
</div>

<div class="field">
<%= form.label :completed %>
<%= form.check_box :completed %>
</div>

<div class="field">
<%= form.label :user_id %>
<%= form.text_field :user_id %>
</div>

<div class="field">
<%= form.label :published %>
<%= form.check_box :published %>
</div>

<div class="actions">
<%= form.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/encodes/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Encode</h1>

<%= render 'form', encode: @encode %>

<%= link_to 'Show', @encode %> |
<%= link_to 'Back', encodes_path %>
39 changes: 39 additions & 0 deletions app/views/encodes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<p id="notice"><%= notice %></p>

<h1>Encodes</h1>

<table>
<thead>
<tr>
<th>Log</th>
<th>Started at</th>
<th>Ended at</th>
<th>Runtime</th>
<th>Completed</th>
<th>User</th>
<th>Published</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @encodes.each do |encode| %>
<tr>
<td><%= encode.log %></td>
<td><%= encode.started_at %></td>
<td><%= encode.ended_at %></td>
<td><%= encode.runtime %></td>
<td><%= encode.completed %></td>
<td><%= encode.user_id %></td>
<td><%= encode.published %></td>
<td><%= link_to 'Show', encode %></td>
<td><%= link_to 'Edit', edit_encode_path(encode) %></td>
<td><%= link_to 'Destroy', encode, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Encode', new_encode_path %>
1 change: 1 addition & 0 deletions app/views/encodes/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @encodes, partial: "encodes/encode", as: :encode
5 changes: 5 additions & 0 deletions app/views/encodes/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New Encode</h1>

<%= render 'form', encode: @encode %>

<%= link_to 'Back', encodes_path %>
39 changes: 39 additions & 0 deletions app/views/encodes/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Log:</strong>
<%= @encode.log %>
</p>

<p>
<strong>Started at:</strong>
<%= @encode.started_at %>
</p>

<p>
<strong>Ended at:</strong>
<%= @encode.ended_at %>
</p>

<p>
<strong>Runtime:</strong>
<%= @encode.runtime %>
</p>

<p>
<strong>Completed:</strong>
<%= @encode.completed %>
</p>

<p>
<strong>User:</strong>
<%= @encode.user_id %>
</p>

<p>
<strong>Published:</strong>
<%= @encode.published %>
</p>

<%= link_to 'Edit', edit_encode_path(@encode) %> |
<%= link_to 'Back', encodes_path %>
1 change: 1 addition & 0 deletions app/views/encodes/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "encodes/encode", encode: @encode
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
devise_for :users
resources :encodes
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
15 changes: 15 additions & 0 deletions db/migrate/20200703005757_create_encodes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateEncodes < ActiveRecord::Migration[6.0]
def change
create_table :encodes do |t|
t.text :log
t.timestamp :started_at
t.timestamp :ended_at
t.float :runtime
t.boolean :completed
t.references :user, null: false, foreign_key: true
t.boolean :published

t.timestamps
end
end
end

0 comments on commit 65d309d

Please sign in to comment.