Skip to content
Open

Cate #11

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1b9ef49
(chore)added events section
katherine95 Apr 23, 2018
cfdac60
(chore)set up ckeditor
katherine95 Apr 23, 2018
779f82a
(chore)generated events model and migrations
katherine95 Apr 23, 2018
623f7ec
(chore)added two gems
katherine95 Apr 23, 2018
63c0ee5
(chore)set up bootstrap-sass
katherine95 Apr 23, 2018
fc9ee38
(chore)generated simple_form
katherine95 Apr 23, 2018
171b8f2
(chore)generated Events controller
katherine95 Apr 23, 2018
49295fd
(feature)create an event
katherine95 Apr 23, 2018
e43d2a6
(chore)created events views
katherine95 Apr 23, 2018
5a7344d
(chore)created a partial
katherine95 Apr 23, 2018
e59f18e
(chore)added index view
katherine95 Apr 23, 2018
f2edfb2
(chore)added view for displaying events
katherine95 Apr 23, 2018
99b436f
(chore)configured routes
katherine95 Apr 23, 2018
2ed4c37
(chore)configured routes
katherine95 Apr 23, 2018
fcb823d
(chore)installed ckeditor
katherine95 Apr 23, 2018
585184c
(chore)installed Devise gem
katherine95 Apr 24, 2018
0398bf3
(task)added flash messages
katherine95 Apr 24, 2018
4b560b9
(chore)generated Admin model
katherine95 Apr 24, 2018
6438f5f
(chore)generated Devise views
katherine95 Apr 24, 2018
180595b
(chore)set up admin views
katherine95 Apr 24, 2018
f5b2095
(chore)created navigation partial
katherine95 Apr 24, 2018
40cb3ae
(chore)rendered the navigation view
katherine95 Apr 24, 2018
ed7e0ff
(chore)added authenticate action
katherine95 Apr 24, 2018
7f8e712
(chore)added validation
katherine95 Apr 24, 2018
c08b7c3
(update)added admin actions on index page
katherine95 Apr 24, 2018
18be3ee
(chore)created dashboard
katherine95 Apr 24, 2018
9697f1c
(chore)added navigation partial
katherine95 Apr 24, 2018
ffb117b
(update)updated rendering of events
katherine95 Apr 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ gem 'sqlite3'
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

gem 'ckeditor', '~> 4.1'
gem 'devise'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
Expand All @@ -36,6 +36,8 @@ gem 'jbuilder', '~> 2.5'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'simple_form', '~> 3.2'
gem 'bootstrap-sass', '~> 3.3'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand Down
36 changes: 32 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ GEM
arel (7.1.4)
autoprefixer-rails (7.2.5)
execjs
bcrypt (3.1.11)
bindex (0.5.0)
bootstrap-sass (3.2.0.2)
sass (~> 3.2)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.3)
byebug (9.1.0)
ckeditor (4.2.4)
cocaine
orm_adapter (~> 0.5.0)
climate_control (0.2.0)
cocaine (0.6.0)
terrapin (= 0.6.0)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
Expand All @@ -55,6 +63,12 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
crass (1.0.3)
devise (4.4.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
erubis (2.7.0)
execjs (2.7.0)
ffi (1.9.18)
Expand Down Expand Up @@ -85,6 +99,7 @@ GEM
nio4r (2.2.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
puma (3.11.1)
rack (2.0.3)
rack-test (0.6.3)
Expand Down Expand Up @@ -116,6 +131,9 @@ GEM
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
sass (3.5.5)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
Expand All @@ -127,6 +145,9 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
simple_form (3.5.1)
actionpack (> 4, < 5.2)
activemodel (> 4, < 5.2)
spring (2.0.2)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1)
Expand All @@ -140,6 +161,8 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
terrapin (0.6.0)
climate_control (>= 0.0.3, < 1.0)
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
Expand All @@ -150,6 +173,8 @@ GEM
thread_safe (~> 0.1)
uglifier (4.1.3)
execjs (>= 0.3.0, < 3)
warden (1.2.7)
rack (>= 1.0)
web-console (3.5.1)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand All @@ -164,15 +189,18 @@ PLATFORMS

DEPENDENCIES
autoprefixer-rails
bootstrap-sass (~> 3.2.0)
bootstrap-sass (~> 3.3)
byebug
ckeditor (~> 4.1)
coffee-rails (~> 4.2)
devise
jbuilder (~> 2.5)
jquery-rails
listen (~> 3.0.5)
puma (~> 3.0)
rails (~> 5.0.5)
sass-rails (~> 5.0)
simple_form (~> 3.2)
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
Expand All @@ -182,4 +210,4 @@ DEPENDENCIES
web-console (>= 3.3.0)

BUNDLED WITH
1.15.2
1.16.1
3 changes: 2 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// about supported directives.
//
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require ckeditor/init
//= require_tree .
34 changes: 34 additions & 0 deletions app/assets/javascripts/ckeditor/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

CKEDITOR.editorConfig = function(config) {
config.language = 'en';
config.width = '700';
config.filebrowserBrowseUrl = "/ckeditor/attachment_files";
config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";
config.filebrowserImageBrowseUrl = "/ckeditor/pictures";
config.filebrowserImageUploadUrl = "/ckeditor/pictures";
config.filebrowserUploadUrl = "/ckeditor/attachment_files";

config.toolbar_Pure = [
'/', {
name: 'basicstyles',
items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']
}, {
name: 'paragraph',
items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl']
}, {
name: 'links',
items: ['Link', 'Unlink']
}, '/', {
name: 'styles',
items: ['Styles', 'Format', 'Font', 'FontSize']
}, {
name: 'colors',
items: ['TextColor', 'BGColor']
}, {
name: 'insert',
items: ['Image', 'Table', 'HorizontalRule', 'PageBreak']
}
];
config.toolbar = 'Pure';
return true;
};
3 changes: 3 additions & 0 deletions app/assets/javascripts/events.coffee
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/
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
*
*= require_tree .
*= require_self
*/
*/
@import "bootstrap-sprockets";
@import "bootstrap";
3 changes: 3 additions & 0 deletions app/assets/stylesheets/events.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Events controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
72 changes: 72 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class EventsController < ApplicationController
#This authenticates admin whenever an event is to be created, updated or destroyed.
before_action :authenticate_admin!, except: [:index, :show]
before_action :find_event, only: [:edit, :update, :show, :delete]

# Index action to render all events
def index
@events = Event.all
end

# New action for creating event
def new
@event = Event.new
end

# Create action saves the event into database
def create
@event = Event.new
if @event.save(event_params)
flash[:notice] = "Successfully created event!"
redirect_to event_path(@event)
else
flash[:alert] = "Error creating new event!"
render :new
end
end

# Edit action retrives the event and renders the edit page
def edit
@event = Event.find(params[:id])
end

# Update action updates the event with the new information
def update
@event = Event.find(params[:id])
if @event.update_attributes(event_params)
flash[:notice] = "Successfully updated event!"
redirect_to event_path(@events)
else
flash[:alert] = "Error updating event!"
render :edit
end
end

# The show action renders the individual event after retrieving the the id
def show
@events = Event.all
render :index
end

# The destroy action removes the event permanently from the database
def destroy
@event = Event.find(params[:id])
if @event.present?
@event.destroy
flash[:notice] = "Successfully deleted event!"
redirect_to events_path
else
flash[:alert] = "Error updating event!"
end
end

private

def event_params
params.require(:event). permit(:title, :body)
end

def find_event
@event = Event.find(params[:id])
end
end
1 change: 1 addition & 0 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class WelcomeController < ApplicationController
def index
@events = Event.all
end
end
2 changes: 2 additions & 0 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module EventsHelper
end
6 changes: 6 additions & 0 deletions app/models/admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Admin < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
7 changes: 7 additions & 0 deletions app/models/ckeditor/asset.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Ckeditor::Asset < ActiveRecord::Base
include Ckeditor::Orm::ActiveRecord::AssetBase

delegate :url, :current_path, :content_type, to: :data

validates :data, presence: true
end
7 changes: 7 additions & 0 deletions app/models/ckeditor/attachment_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Ckeditor::AttachmentFile < Ckeditor::Asset
mount_uploader :data, CkeditorAttachmentFileUploader, mount_on: :data_file_name

def url_thumb
@url_thumb ||= Ckeditor::Utils.filethumb(filename)
end
end
7 changes: 7 additions & 0 deletions app/models/ckeditor/picture.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Ckeditor::Picture < Ckeditor::Asset
mount_uploader :data, CkeditorPictureUploader, mount_on: :data_file_name

def url_content
url(:content)
end
end
6 changes: 6 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Event < ActiveRecord::Base
#This validates presence of title, and makes sure that the length is not more than 140 words
#validates :title, presence: true, length: {maximum: 140}
#This validates presence of body
#validates :body, presence: true
end
38 changes: 38 additions & 0 deletions app/uploaders/ckeditor_attachment_file_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# encoding: utf-8
require 'carrierwave'

class CkeditorAttachmentFileUploader < CarrierWave::Uploader::Base
include Ckeditor::Backend::CarrierWave

# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# include CarrierWave::ImageScience

# Choose what kind of storage to use for this uploader:
storage :file

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/ckeditor/attachments/#{model.id}"
end

# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end

# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end

# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
Ckeditor.attachment_file_types
end
end
Loading