-
Notifications
You must be signed in to change notification settings - Fork 0
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
0602c8f
commit 89d2d9b
Showing
57 changed files
with
778 additions
and
55 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
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 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 |
---|---|---|
|
@@ -38,7 +38,13 @@ | |
.discussion-title { | ||
margin-bottom: 0; | ||
} | ||
|
||
|
||
.pt{ | ||
&-1 { | ||
margin-top: 1rem; | ||
} | ||
} | ||
.pt-5 { | ||
margin-top: 5rem; | ||
} | ||
|
||
|
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 Channels 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,3 @@ | ||
// Place all the styles related to the Replies 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,73 @@ | ||
class ChannelsController < ApplicationController | ||
before_action :set_channel, only: %i[ show edit update destroy ] | ||
|
||
# GET /channels or /channels.json | ||
def index | ||
@channels = Channel.all | ||
@discussions = Discussion.all | ||
end | ||
|
||
# GET /channels/1 or /channels/1.json | ||
def show | ||
@discussions = @channel.discussions | ||
@channels = Channel.all | ||
end | ||
|
||
# GET /channels/new | ||
def new | ||
@channel = Channel.new | ||
end | ||
|
||
# GET /channels/1/edit | ||
def edit | ||
end | ||
|
||
# POST /channels or /channels.json | ||
def create | ||
@channel = Channel.new(channel_params) | ||
|
||
respond_to do |format| | ||
if @channel.save | ||
format.html { redirect_to channels_path, notice: "Channel was successfully created." } | ||
format.json { render :show, status: :created, location: @channel } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @channel.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /channels/1 or /channels/1.json | ||
def update | ||
respond_to do |format| | ||
if @channel.update(channel_params) | ||
format.html { redirect_to channels_path, notice: "Channel was successfully updated." } | ||
format.json { render :show, status: :ok, location: @channel } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @channel.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /channels/1 or /channels/1.json | ||
def destroy | ||
@channel.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to channels_url, notice: "Channel was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_channel | ||
@channel = Channel.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def channel_params | ||
params.require(:channel).permit(:channel) | ||
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,78 @@ | ||
class RepliesController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :set_reply, only: %i[ show edit update destroy ] | ||
before_action :set_discussion | ||
|
||
# GET /replies or /replies.json | ||
def index | ||
@replies = Reply.all | ||
end | ||
|
||
# GET /replies/1 or /replies/1.json | ||
def show | ||
end | ||
|
||
# GET /replies/new | ||
def new | ||
@reply = @discussion.replies.new | ||
end | ||
|
||
# GET /replies/1/edit | ||
def edit | ||
end | ||
|
||
# POST /replies or /replies.json | ||
def create | ||
@reply = @discussion.replies.create(reply_params) | ||
@reply.user_id = current_user.id | ||
respond_to do |format| | ||
if @reply.save | ||
format.html { redirect_to discussion_path(@discussion), notice: "Reply was successfully created." } | ||
format.js | ||
format.json { render :show, status: :created, location: @reply } | ||
else | ||
format.html { redirect_to discussion_path(@discussion), notice: "Reply wasn't successfully created." } | ||
format.js | ||
format.json { render json: @reply.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /replies/1 or /replies/1.json | ||
def update | ||
respond_to do |format| | ||
if @reply.update(reply_params) | ||
format.html { redirect_to discussion_path(@discussion), notice: "Reply was successfully updated." } | ||
format.json { render :show, status: :ok, location: @reply } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @reply.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /replies/1 or /replies/1.json | ||
def destroy | ||
@reply.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to discussion_path(@discussion), notice: "Reply was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_discussion | ||
@discussion = Discussion.find(params[:discussion_id]) | ||
end | ||
|
||
def set_reply | ||
@reply = Reply.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def reply_params | ||
params.require(:reply).permit(:reply) | ||
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 ChannelsHelper | ||
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 RepliesHelper | ||
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,4 @@ | ||
class Channel < ApplicationRecord | ||
has_many :discussions | ||
has_many :users, through: :discussions | ||
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,2 +1,7 @@ | ||
class Discussion < ApplicationRecord | ||
belongs_to :channel | ||
belongs_to :user | ||
has_many :replies, dependent: :destroy | ||
|
||
validates :title, :content, presence: true | ||
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,5 @@ | ||
class Reply < ApplicationRecord | ||
belongs_to :discussion | ||
belongs_to :user | ||
validates :reply, presence: true | ||
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,2 @@ | ||
json.extract! channel, :id, :channel, :created_at, :updated_at | ||
json.url channel_url(channel, format: :json) |
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,11 @@ | ||
<%= simple_form_for(@channel) do |f| %> | ||
<%= f.error_notification %> | ||
|
||
<div class="field"> | ||
<div class="control"> | ||
<%= f.input :channel, input_html: { class: 'input' }, wrapper: false, label_html: { class: 'label' } %> | ||
</div> | ||
</div> | ||
|
||
<%= f.button :submit, class: 'button is-info' %> | ||
<% 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,3 @@ | ||
<h1 class="title is-3">Editing Channel</h1> | ||
|
||
<%= render 'form', channel: @channel %> |
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,37 @@ | ||
<h1 class="title is-2">Topics/Channels</h1> | ||
|
||
<% if true #has_role?(:admin) %> | ||
<div class="level"> | ||
<div class="level-left"></div> | ||
<div class="level-right"> | ||
<%= link_to 'New Channel', new_channel_path, class:'button is-dark' %> | ||
</div> | ||
</div> | ||
<table class="table is-fullwidth"> | ||
<thead> | ||
<tr> | ||
<th>Channel</th> | ||
<th colspan="3"></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @channels.each do |channel| %> | ||
<tr> | ||
<td><%= link_to channel.channel, channel %></td> | ||
<td> | ||
<div class="buttons is-right"> | ||
<%= link_to 'View Channel', channel, class:'button' %> | ||
<%= link_to 'Edit Channel', edit_channel_path(channel), class:'button' %> | ||
<%= link_to 'Delete', channel, class:'button is-danger', method: :delete, data: { confirm: "Are you sure you want to delete this channel? " } %> | ||
</div> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% else %> | ||
<p class="has-text-center">Sorry! You don't have access this page.</p> | ||
<% 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 @@ | ||
json.array! @channels, partial: "channels/channel", as: :channel |
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,6 @@ | ||
<div class="columns is-centered"> | ||
<div class="column is-4"> | ||
<h1 class="title is-3">Create a new topic/channel</h1> | ||
<%= render 'form', channel: @channel %> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="level"> | ||
<div class="level-left"> | ||
<h1 class="title is-2"><%= @channel.channel %></h1> | ||
</div> | ||
<div class="level-right"> | ||
<% if true #has_role?(:admin) %> | ||
<%= link_to 'Edit Channel', edit_channel_path(@channel), class:"button" %> | ||
<% end %> | ||
</div> | ||
</div> | ||
<hr /> | ||
<div class="columns"> | ||
<%= render 'shared/discussions' %> | ||
<%= render 'discussions/sidebar' %> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "channels/channel", channel: @channel |
Oops, something went wrong.