Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 4 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ group :development, :test do
gem 'mysql2', '~> 0.3.18'
end

gem 'slim-rails'
gem 'activeadmin', '~> 1.0.0.pre2'
gem 'devise'
gem 'bullet', :group => 'development'
gem 'jquery-ui-rails'
gem 'exception_notification'
gem 'pundit'
gem 'bootstrap-sass', '~> 3.3.5'

group :test do
gem 'cucumber-rails', :require => false
# database_cleaner is not required, but highly recommended
Expand All @@ -71,4 +62,7 @@ gem 'activeadmin', '~> 1.0.0.pre2'
gem 'devise'
gem 'bullet', :group => 'development'
gem 'jquery-ui-rails'
gem 'exception_notification'
gem 'pundit'
gem 'bootstrap-sass', '~> 3.3.5'
gem 'exception_notification'
gem 'rails_autolink'
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ GEM
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_autolink (1.1.6)
rails (> 3.1)
rails_serve_static_assets (0.0.4)
rails_stdout_logging (0.0.4)
railties (4.2.0)
Expand Down Expand Up @@ -295,6 +297,7 @@ DEPENDENCIES
pundit
rails (= 4.2.0)
rails_12factor
rails_autolink
rspec-rails (~> 3.0)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
Expand Down
33 changes: 33 additions & 0 deletions app/assets/javascripts/showbill.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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/

$(document).on "ready", ->
$('.showbill').on "keyup", ->
$.ajax({method: "PATCH", url: "showbill/" + $(this).attr("id"), data: make_data($(this)) , dataType:"script"})

# converts div.html to textarea.text
$('.showbill-div').on "click", ->
if $('textarea').is('.showbill')
text = $('.showbill-div').html().replace( /<br>/g,"\n")
$('.showbill').text(disable_links(clean_text(text)))
$('.showbill').show().focus()
$('.showbill-div').hide()

$('.showbill').on "blur", ->
$('.showbill').hide()
$('.showbill-div').show()

make_data = (item) ->
return {} =
#we'll need description in one line. Replacing \n by <br> to don't lose them.
description: item.val().replace(/\n/g, "<br />")
id: $(item).attr("id")

#extracts link_text from link_tag by deleting <a...> and </a>
disable_links = (text) ->
text.replace(/<a.*?">/g, "").replace(/<\/a>/g,"")

clean_text = (text) ->
text.replace(/^\n*\s*\n*\s*/,"").replace(/\s*$/,"")

13 changes: 13 additions & 0 deletions app/controllers/showbill_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ShowbillController < ApplicationController

def update

if current_user.present?
@error = t(:error_update_text) unless @showbill = Showbill_singleton.instance.update(params[:description])
else
@error = t(:you_can_not_edit_it)
end

end

end
1 change: 1 addition & 0 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ def users_to_show
else
@users = User.order(:name)
end
@showbill = Showbill_singleton.instance.text
end
end
2 changes: 2 additions & 0 deletions app/helpers/showbill_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ShowbillHelper
end
21 changes: 21 additions & 0 deletions app/models/showbill_singleton.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'singleton'

class Showbill_singleton
include Singleton

attr_accessor :text

def initialize
@text = "Some default description"
end

def update(text)
text.present? ? @text = text : false
end

def text
@text.present? ? @text : initialize
end


end
7 changes: 7 additions & 0 deletions app/views/showbill/_showbill.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.row
.col-md-12 class = "showbill-div"
= auto_link(@showbill)
.row
- if current_user.present?
.col-md-12
= text_area_tag("showbill", @showbill, {class: "showbill width-max-avail", hidden: "hidden"})
9 changes: 9 additions & 0 deletions app/views/showbill/update.js.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- if @error
| $("#error_label").text("
= @error
| ");
| $("#error_row").show();
- else
| $("#error_row").hide();
| $('.showbill-div').text("");
| $('.showbill-div').append('#{auto_link(@showbill)}');
2 changes: 2 additions & 0 deletions app/views/user/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
= render :partial => '/showbill/showbill', :showbills => @showbills

- @users.each do |user|
.row id = user.name_without_spaces
.col-md-2 class = "name bold"
Expand Down
2 changes: 2 additions & 0 deletions app/views/user/update.js.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
= @error
| ");
| $("#error_row").show();
- else
| $("#error_row").hide();
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ en:
user_details: "User Details"
sign_up: "Sign up"
or: "or"
you_can_not_edit_it: "You can not edit it!"
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Rails.application.routes.draw do

devise_for :users, :controllers => {:registrations => "user/registrations"}

resources :user, only: [:index, :update]
resources :showbill, only: [:update]

devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
Expand Down