Skip to content

Commit

Permalink
Merge pull request #2516 from VictoriaAlbanese/victoria_tutorial_page
Browse files Browse the repository at this point in the history
Tutorials up and running
  • Loading branch information
tylerpuleo authored Oct 14, 2016
2 parents 94f5112 + da6ea62 commit 6460837
Show file tree
Hide file tree
Showing 28 changed files with 353 additions and 318 deletions.
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,3 @@ DEPENDENCIES
will_paginate
will_paginate-bootstrap
yaml_db!

BUNDLED WITH
1.12.3
Binary file added app/assets/images/missing_news.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/assets/images/missing_tutorial.jpg
Binary file not shown.
24 changes: 3 additions & 21 deletions app/assets/javascripts/tutorials/index.js.coffee
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
# Place all the behaviors and hooks related to the matching controller here.

IS.onReady "tutorials/index", ->
# Setup toggle buttons
$('.btn').button()
$('.binary-filters .btn').each () ->
tmp = ($ this).children()[0]
if ($ tmp).prop("checked")
($ this).button('toggle')

# Setup auto-submit
($ '.tutorials_filter_checkbox').click ->
($ '#tutorials_search').submit()

($ '.tutorials_sort_select').change ->
($ '#tutorials_search').submit()

($ '.tutorials_order_select').change ->
($ '#tutorials_search').submit()

($ '.binary-filters .btn').on 'click', (e) ->
e.preventDefault()
cb = ($ ($ e.target).children()[0])
cb.prop("checked", not cb.prop("checked"))
($ '#tutorials_search').submit()
# Close sidenav when a link is clicked
$('.mdl-navigation__link').click ->
$('.mdl-layout__obfuscator').trigger('click')
3 changes: 2 additions & 1 deletion app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ body {
}
.article_page_title {
white-space: nowrap;
font-size: 20px;
font-size: 18px;
}
}

Expand All @@ -239,6 +239,7 @@ body {
height: 210px;
background-size: cover;
margin-right: 5px;
background-position: center center;
}

.mainContent {
Expand Down
55 changes: 55 additions & 0 deletions app/assets/stylesheets/tutorials.css.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
// Place all the styles related to the Tutorials controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.tutorials-controller {
.mainContent {
padding: 0 !important; // Removes all the extra padding
margin: 0 !important; // flushes border
width: 100% !important; // makes page body fill the screen
// instead of having a fixed width
.tutorialsContainer {
margin-left: auto;
margin-right: auto;
padding: 100px;
}
@media (min-width: 768px) {
.tutorialsContainer {
width: 750px;
}
}
@media (min-width: 992px) {
.tutorialsContainer {
width: 970px;
}
}
@media (min-width: 1200px) {
.tutorialsContainer {
width: 1400px;
}
}
.mdl-layout__drawer-button {
color: white !important;
}
.mdl-layout__header{
background-color: #0D47A1;
color: white;
}
.mdl-card__title {
height: 300px !important;
}
.mdl-card {
height:420px !important;
}
}

.back_to_top {
background-color: transparent;
border-color: transparent;
text-decoration: underline;
color: #0645AD;
}
.mdl-layout__container {
position: relative;
}

.mdl-card__supporting-text{
font-size: 1.5rem;
width: 100%;;
}
}
62 changes: 14 additions & 48 deletions app/controllers/tutorials_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class TutorialsController < ApplicationController
# GET /tutorials
# GET /tutorials.json
skip_before_filter :authorize, only: [:show, :index]
skip_before_filter :authorize, only: [:index]
before_filter :authorize_admin, only: [:create, :update, :destroy]

include ApplicationHelper
Expand All @@ -10,31 +10,11 @@ class TutorialsController < ApplicationController
def index
@params = params

# Main List
if !params[:sort].nil?
sort = params[:sort]
else
sort = 'updated_at'
end

if !params[:order].nil?
order = params[:order]
else
order = 'DESC'
end

if !params[:per_page].nil?
pagesize = params[:per_page]
else
pagesize = 6
end

@new_tutorial = Tutorial.new

@tutorials = Tutorial.search(params[:search], current_user.try(:admin)).paginate(page: params[:page],
per_page: pagesize)

@tutorials = @tutorials.order("#{sort} #{order}")
@getting_started = Tutorial.where(category: 'Getting Started')
@working_with_data = Tutorial.where(category: 'Working With Data')
@visualization = Tutorial.where(category: 'Visualizations')

recur = params.key?(:recur) ? params[:recur].to_bool : false

Expand All @@ -44,17 +24,6 @@ def index
end
end

# GET /tutorials/1
# GET /tutorials/1.json
def show
@tutorial = Tutorial.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @tutorial.to_hash(false) }
end
end

# POST /tutorials
# POST /tutorials.json
def create
Expand All @@ -64,7 +33,7 @@ def create
respond_to do |format|
if @tutorial.save
format.html do
redirect_to @tutorial,
redirect_to tutorials_url,
notice: 'Tutorial was successfully created.'
end
format.json do
Expand All @@ -86,30 +55,27 @@ def edit
@tutorial = Tutorial.find(params[:id])
end

def show
redirect_to '/tutorials',
notice: 'Tutorial was successfully updated.'
end

# PUT /tutorials/1
# PUT /tutorials/1.json
def update
@tutorial = Tutorial.find(params[:id])
update = tutorial_params

# ADMIN REQUEST
if update.key?(:featured)
if update['featured'] == 'true'
update['featured_at'] = Time.now
else
update['featured_at'] = nil
end
end

respond_to do |format|
if @tutorial.update_attributes(update)
format.html do
redirect_to @tutorial,
notice: 'Tutorial was successfully updated.'
end
format.html { redirect_to tutorials_url }
format.json { render json: {}, status: :ok }
else
format.html { render action: 'show' }
format.html { render action: 'index' }
format.json do
render json: @tutorial.errors.full_messages,
status: :unprocessable_entity
Expand All @@ -136,7 +102,7 @@ def destroy
private

def tutorial_params
params[:tutorial].permit(:content, :title, :featured, :user_id, :hidden,
:featured_media_id, :featured_at)
params[:tutorial].permit(:content, :title, :user_id, :hidden, :youtube_url,
:featured_media_id, :category)
end
end
28 changes: 9 additions & 19 deletions app/models/tutorial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,44 @@ class Tutorial < ActiveRecord::Base
include ActionView::Helpers::DateHelper
include ActionView::Helpers::SanitizeHelper

has_many :media_objects

validates_presence_of :title
validates_presence_of :user_id
validates_presence_of :youtube_url
validates_presence_of :category

has_many :media_objects

validates :title, length: { maximum: 128 }

has_many :media_objects
belongs_to :user

alias_attribute :name, :title

alias_attribute :owner, :user

before_save :summernote_media_objects

def self.search(search, include_hidden = false)
def self.search(search)
res = if search
where('lower(title) LIKE lower(?)', "%#{search}%")
else
all
end

if include_hidden
res
else
res.where(hidden: false)
end
res
end

def to_hash(recurse = true)
h = {
id: id,
name: name,
featured: featured,
path: UrlGenerator.new.tutorial_path(self),
url: UrlGenerator.new.tutorial_url(self),
hidden: hidden,
category: category,
youtubeUrl: youtube_url,
timeAgoInWords: time_ago_in_words(created_at),
createdAt: created_at.strftime('%B %d, %Y'),
ownerName: owner.name,
ownerUrl: UrlGenerator.new.user_url(owner)
}

# The featured media object is the instructions pdf
unless featured_media_id.nil?
h.merge!(mediaSrc: media_objects.find(featured_media_id).tn_src)
end
Expand All @@ -61,8 +55,4 @@ def to_hash(recurse = true)

h
end

def summernote_media_objects
self.content = MediaObject.create_media_objects(content, 'tutorial_id', id, user_id)
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def to_hash(recurse = true, show_hidden = false)
dataSets: data_sets.search('').map { |o| o.to_hash false },
mediaObjects: media_objects.map { |o| o.to_hash false },
projects: projects.search(false, show_hidden).map { |o| o.to_hash false },
tutorials: tutorials.search(false, show_hidden).map { |o| o.to_hash false },
tutorials: tutorials.search(false).map { |o| o.to_hash false },
visualizations: visualizations.search(false, show_hidden).map { |o| o.to_hash false }
)
end
Expand Down
12 changes: 1 addition & 11 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,7 @@
<ul class="nav navbar-nav">
<li class="navbtn" title="Browse through projects created by iSENSE users"><%=link_to projects_path do %><i class='fa fa-folder-open'></i> Projects<%end%></li>
<li class="navbtn" title="Explore data visualizations built by iSENSE users"><%=link_to visualizations_path do %><i class='fa fa-picture-o'></i> Visualizations<%end%></li>
<li class="dropdown navbtn">
<a href="#" class="dropdown-toggle" title="Learn how to use iSENSE" data-toggle="dropdown"><i class="fa fa-info-circle"></i> Tutorials <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><%= link_to "See All Tutorials", tutorials_path%></li>
<li class="divider"></li>
<% @featured_tutorials = Tutorial.where("featured = ? and hidden = ?", true, false).order("title ASC").limit(10) %>
<% @featured_tutorials.each do |tutorial| %>
<li><%= link_to tutorial.title.html_safe, tutorial_path(tutorial)%></li>
<% end %>
</ul>
</li>
<li class="navbtn" title="Learn how to use iSENSE"><%=link_to tutorials_path do %><i class='fa fa-info-circle'></i> Tutorials<%end%></li>
<li class="navbtn" title="Check out the latest iSENSE news and updates"><%=link_to news_index_path do %><i class='fa fa-book'></i> News<%end%></li>
<% if is_admin? %>
<li class="navbtn"><%= link_to users_path do%><i class="fa fa-users"></i> Users<%end%></li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_article_box.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<div class="col-md-<%= width %>">
<div class="wide-item">
<% left_image = image_path('missing_tutorial.jpg') %>
<% left_image = image_path('missing_news.jpg') %>
<% if image_id != nil %>
<% left_image = MediaObject.find(image_id).src %>
<% end %>
Expand Down
7 changes: 4 additions & 3 deletions app/views/shared/_media_objects_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<th style="max-width:60%">Name</th>
<th style="max-width:10%"></th>
<th style="max-width:10%"></th>
<% if ["Project","News","Tutorial","Visualization"].include? object.class.name && (can_edit? object) %>
<% if (["Project","News","Tutorial","Visualization"].include? object.class.name) && (can_edit? object) %>
<th class="featured-title">Featured Image</th>
<% end %>
</tr>
Expand All @@ -33,10 +33,11 @@
&nbsp;|&nbsp;<%= link_to "Delete", mo, method: 'delete', class: "media_delete", data: { confirm: "Are you sure?" } %>
<% end %>
</td>
<% if ["Project","News","Tutorial","Visualization"].include? object.class.name %>
<% if (["Project","News","Tutorial","Visualization"].include? object.class.name) %>
<td>
<div class="center">
<% if ((mo.media_type == "image") && (can_edit? object))%>
<% if (["Project","News","Visualization"].include? object.class.name) && (mo.media_type == "image") && (can_edit? object) ||
(["Tutorial"].include? object.class.name) && (mo.media_type == "pdf") && (can_edit? object)%>
<input type="radio" title="Select to set this as your featured project image." class="img_selector" name="img_selector" obj_id="<%=object.id%>" <%if object.featured_media_id == mo.id%>checked<%end%> mo_id="<%=mo.id%>"></input>
<%end%>
</div>
Expand Down
18 changes: 9 additions & 9 deletions app/views/tutorials/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<div class="row">
<%= form_for(@tutorial) do |f| %>
<div class="col-md-12">
<div class="form-group">
<div class="form-group col-xs-12">
<strong>Title: </strong><%= f.text_field :title, class: "form-control" %>
</div>
<div class="checkbox">
<div class="checkbox-inner">
<%= f.check_box :featured %> <strong>Featured</strong>
</div>
<span class="help-block">Featuring a tutorial makes it possible to be in the drop-down for tutorials on the navbar. The first five featured (alphabetically sorted) tutorials are shown in the list.</span>
</div>
<div class="col-xs-12" style="margin-top: 10px; margin-bottom: 30px;">
<%= f.label ':category', 'Categories:'%>
<br/>
<%= f.select(:category, options_for_select([['Getting Started','Getting Started'], ['Working With Data', 'Working With Data'], ['Visualizations', 'Visualizations']]), class: "form-control") %>
</div>
<div class="clear"><br></div>
<div class="actions">
<div class="actions col-xs-12">
<%= f.submit "Submit",class: "btn btn-default" %>
<br/>
</div>
</div>
<% end %>
</div>
</div>
Loading

0 comments on commit 6460837

Please sign in to comment.