Skip to content

Commit

Permalink
Merge a6a00a5 into 699d178
Browse files Browse the repository at this point in the history
  • Loading branch information
slabounty committed Dec 26, 2014
2 parents 699d178 + a6a00a5 commit 2628e6d
Show file tree
Hide file tree
Showing 23 changed files with 180 additions and 136 deletions.
8 changes: 6 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ gem 'bcrypt-ruby', '3.1.2'
gem 'faker', '1.1.2'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'
gem "font-awesome-rails"
gem 'unobtrusive_flash', '>=3'
gem 'jquery_file_download-rails', '~> 0.0.1'

gem 'dot_grid'
gem 'bootstrap-colorpicker2-rails', '~> 0.0.1'


group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
gem 'rspec-rails', '3.0'
gem 'rspec-its'
end

group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
gem 'capybara', '2.4'
gem 'factory_girl_rails', '4.2.0'
end

Expand Down
46 changes: 32 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GEM
bootstrap-will_paginate (0.0.9)
will_paginate
builder (3.1.4)
capybara (2.1.0)
capybara (2.4.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
Expand Down Expand Up @@ -70,23 +70,27 @@ GEM
faker (1.1.2)
i18n (~> 0.5)
ffi (1.9.3)
font-awesome-rails (4.2.0.0)
railties (>= 3.2, < 5.0)
hike (1.2.3)
i18n (0.6.11)
jbuilder (1.0.2)
activesupport (>= 3.0.0)
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery_file_download-rails (0.0.1)
railties (>= 3.1.0)
json (1.8.1)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
mini_portile (0.6.0)
mini_portile (0.6.1)
minitest (4.7.5)
multi_json (1.10.1)
netrc (0.7.7)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
nokogiri (1.6.5)
mini_portile (~> 0.6.0)
pdf-core (0.2.5)
pg (0.15.1)
prawn (1.2.1)
Expand Down Expand Up @@ -119,17 +123,25 @@ GEM
rest-client (1.7.2)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)
rspec-rails (2.13.1)
rspec-core (3.0.4)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-its (1.1.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.0.4)
rspec-support (~> 3.0.0)
rspec-rails (3.0.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.4)
rubyzip (0.9.9)
sass (3.3.14)
sass-rails (4.0.1)
Expand Down Expand Up @@ -173,6 +185,8 @@ GEM
uglifier (2.1.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
unobtrusive_flash (3.1.0)
railties
websocket (1.0.7)
will_paginate (3.0.4)
xpath (2.0.0)
Expand All @@ -186,23 +200,27 @@ DEPENDENCIES
bootstrap-colorpicker2-rails (~> 0.0.1)
bootstrap-sass (= 2.3.2.0)
bootstrap-will_paginate (= 0.0.9)
capybara (= 2.1.0)
capybara (= 2.4)
coffee-rails (= 4.0.1)
coveralls
dot_grid
factory_girl_rails (= 4.2.0)
faker (= 1.1.2)
font-awesome-rails
jbuilder (= 1.0.2)
jquery-rails (= 3.0.4)
jquery_file_download-rails (~> 0.0.1)
pg (= 0.15.1)
rails (~> 4.0.0)
rails_12factor (= 0.0.2)
rspec-rails (= 2.13.1)
rspec-its
rspec-rails (= 3.0)
sass-rails (= 4.0.1)
sdoc (= 0.3.20)
selenium-webdriver (= 2.35.1)
sprockets (= 2.11.0)
sqlite3 (= 1.3.8)
turbolinks (= 1.1.1)
uglifier (= 2.1.1)
unobtrusive_flash (>= 3)
will_paginate (= 3.0.4)
3 changes: 3 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
//= require turbolinks
//= require_tree .
//= require bootstrap-colorpicker
//= require unobtrusive_flash
//= require unobtrusive_flash_bootstrap
//= require jquery.fileDownload
30 changes: 30 additions & 0 deletions app/assets/javascripts/user_documents.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$(document).ready(function() {

// Here???
UnobtrusiveFlash.flashOptions['timeout'] = 2000; // milliseconds

$('.colorpicker').colorpicker();

$(".documents li").on("click", function(){
document_id = $(this).attr('id').match(/\d+/)[0];

$.ajax({
url: "/documents/" + document_id + "/edit",
type: 'GET',
success: function(data){
$('.colorpicker').colorpicker();
},
failure: function(data){
console.log('Failure in getting edit!');
}
});
});

$('#document_form').on('click', '#document_generate', function(e){
e.preventDefault();
$.fileDownload('/documents/generate_and_send', {
httpMethod: "POST",
data: $('#document_form form').serialize()
});
});
});
11 changes: 9 additions & 2 deletions app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "bootstrap";
@import "bootstrap-colorpicker";
@import "font-awesome";

/* mixins, variables, etc. */

Expand Down Expand Up @@ -195,13 +196,19 @@ input {

/* documents */


.documents {
list-style: none;
margin: 10px 0 0 0;

.odd {
background-color: #D7EEF5;
}

li {
padding: 10px 0;
border-top: 1px solid #e8e8e8;
padding: 10px 10px;
/*border-top: 1px solid #e8e8e8;*/
border: 1px solid #e8e8e8;
}
}

Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include SessionsHelper
after_filter :prepare_unobtrusive_flash
end
84 changes: 56 additions & 28 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,76 @@ class DocumentsController < ApplicationController
before_action :signed_in_user

def create
if params[:commit] == 'Save'
@document = current_user.documents.build(document_params)
if @document.save
flash[:success] = "Document created!"
#redirect_to root_url
render 'static_pages/home'
else
render 'static_pages/home'
respond_to do |format|
format.js do
if params[:commit] == 'Save'
@document = current_user.documents.build(document_params)
if @document.save
flash[:success] = "Document created!"
render 'edit'
else
flash[:success] = "Could not create document."
render 'edit'
end
else
generate_and_send
end
end
else
document = ::DotGrid::Document.new(
{
file_name: document_params[:file_name],
orientation: document_params[:orientation],
page_type: document_params[:page_type],
dot_weight: document_params[:dot_weight].to_f,
margin: document_params[:margin].to_f,
page_size: document_params[:page_size].upcase,
grid_color: document_params[:grid_color],
spacing: document_params[:spacing].to_i,
planner_color_1: document_params[:planner_color_1],
planner_color_2: document_params[:planner_color_2]
})
document.generate

send_file document.file_name, filename: document.file_name
end
end

def update
respond_to do |format|
format.js do
if params[:commit] == 'Save'
@document = Document.find(params[:id])
if @document.update(document_params)
flash[:success] = "Document updated."
render 'edit'
else
flash[:success] = "Document update failed."
render 'edit'
end
end
end
format.html do
generate_and_send
end
end
end

def edit
Rails.logger.error "\n\n\n params = #{params.inspect} \n\n\n"
@document = Document.find(params[:id])
render 'shared/_document_form'
respond_to do |format|
format.js
end
end

def destroy
Document.find(params[:id]).destroy
flash[:success] = "Document deleted."
redirect_to current_user
redirect_to root_path
end

def generate_and_send
document = ::DotGrid::Document.new(
{
file_name: document_params[:file_name],
orientation: document_params[:orientation],
page_type: document_params[:page_type],
dot_weight: document_params[:dot_weight].to_f,
margin: document_params[:margin].to_f,
page_size: document_params[:page_size].upcase,
grid_color: document_params[:grid_color],
spacing: document_params[:spacing].to_i,
planner_color_1: document_params[:planner_color_1],
planner_color_2: document_params[:planner_color_2]
})

cookies['fileDownload'] = 'true'
document.generate

send_file document.file_name, filename: document.file_name, x_sendfile: true
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
redirect_back_or root_path
else
flash.now[:error] = 'Invalid email/password combination' # Not quite right!
render 'new'
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class StaticPagesController < ApplicationController
def home
@document = current_user.documents.build if signed_in?
@documents = current_user.documents if signed_in?
@document = Document.new if signed_in?
end

def help
Expand Down
9 changes: 2 additions & 7 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create
if @user.save
sign_in @user
flash[:success] = "Welcome to Dot Grid!"
redirect_to @user
redirect_to root_path
else
render 'new'
end
Expand All @@ -28,17 +28,12 @@ def edit
def update
if @user.update_attributes(user_params)
flash[:success] = "Profile updated"
redirect_to @user
redirect_to root_path
else
render 'edit'
end
end

def show
@user = User.find(params[:id])
@documents = @user.documents.paginate(page: params[:page])
end

def destroy
User.find(params[:id]).destroy
flash[:success] = "User deleted."
Expand Down
8 changes: 3 additions & 5 deletions app/views/documents/_document.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<li>
<li id=document_<%="#{document.id}" %> class="<%= cycle("odd", "even")%>">
<span class="name"><%= document.name %></span>
<%= link_to "edit", edit_document_path(document) %>
<%= link_to "generate", edit_document_path(document) %>
<%= link_to "delete", document, method: :delete,
data: { confirm: "You sure?" } %>
<%= link_to content_tag(:i,nil, :class=>"fa fa-trash-o"), document, method: :delete, data: { confirm: 'Are you sure?' } %>

<span class="timestamp">
Created <%= time_ago_in_words(document.created_at) %> ago.
</span>
Expand Down
1 change: 1 addition & 0 deletions app/views/documents/edit.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#document_form").html("<%= escape_javascript(render partial: 'shared/document_form', locals: { document: @document } ) %>");
1 change: 0 additions & 1 deletion app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li>
Expand Down
4 changes: 1 addition & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
<div class="unobtrusive-flash-container"></div>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
Expand Down
Loading

0 comments on commit 2628e6d

Please sign in to comment.