diff --git a/Gemfile b/Gemfile index 606c18a..2fbc318 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem 'coffee-rails', '~> 4.2' # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' +gem 'jquery-ui-rails' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder @@ -32,6 +33,7 @@ gem "mini_magick" gem 'rmagick' gem "animate-rails" gem 'best_in_place', '~> 3.0.1' +gem 'simple_form' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development diff --git a/Gemfile.lock b/Gemfile.lock index 1a524aa..156d366 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,6 +81,8 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + jquery-ui-rails (5.0.5) + railties (>= 3.2.16) json (2.0.2) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) @@ -146,6 +148,9 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + simple_form (3.3.1) + actionpack (> 4, < 5.1) + activemodel (> 4, < 5.1) spring (1.7.2) spring-watcher-listen (2.0.0) listen (>= 2.7, < 4.0) @@ -191,6 +196,7 @@ DEPENDENCIES devise jbuilder (~> 2.5) jquery-rails + jquery-ui-rails listen (~> 3.0.5) mini_magick pg @@ -198,6 +204,7 @@ DEPENDENCIES rails (~> 5.0.0) rmagick sass-rails (~> 5.0) + simple_form spring spring-watcher-listen (~> 2.0.0) sqlite3 diff --git a/app/assets/images/pen-grey.png b/app/assets/images/pen-grey.png new file mode 100644 index 0000000..0b21389 Binary files /dev/null and b/app/assets/images/pen-grey.png differ diff --git a/app/assets/images/white-pen.png b/app/assets/images/white-pen.png new file mode 100644 index 0000000..4f658a3 Binary files /dev/null and b/app/assets/images/white-pen.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 5da2447..2400da3 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,7 @@ // //= require jquery //= require best_in_place +//= require jquery-ui //= require jquery_ujs //= require turbolinks //= require_tree . diff --git a/app/assets/javascripts/autosize.js b/app/assets/javascripts/autosize.js new file mode 100644 index 0000000..f33d0b6 --- /dev/null +++ b/app/assets/javascripts/autosize.js @@ -0,0 +1,55 @@ +/*! + * jQuery Textarea AutoSize plugin + * Author: Javier Julio + * Licensed under the MIT license + */ +;(function ($, window, document, undefined) { + + var pluginName = "textareaAutoSize"; + var pluginDataName = "plugin_" + pluginName; + + var containsText = function (value) { + return (value.replace(/\s/g, '').length > 0); + }; + + function Plugin(element, options) { + this.element = element; + this.$element = $(element); + this.init(); + } + + Plugin.prototype = { + init: function() { + var diff = parseInt(this.$element.css('paddingBottom')) + + parseInt(this.$element.css('paddingTop')) + + parseInt(this.$element.css('borderTopWidth')) + + parseInt(this.$element.css('borderBottomWidth')) || 0; + + if (containsText(this.element.value)) { + this.$element.height(this.element.scrollHeight - diff); + } + + // keyup is required for IE to properly reset height when deleting text + this.$element.on('input keyup', function(event) { + var $window = $(window); + var currentScrollPosition = $window.scrollTop(); + + $(this) + .height(0) + .height(this.scrollHeight - diff); + + $window.scrollTop(currentScrollPosition); + }); + } + }; + + $.fn[pluginName] = function (options) { + this.each(function() { + if (!$.data(this, pluginDataName)) { + $.data(this, pluginDataName, new Plugin(this, options)); + } + }); + return this; + }; + +})(jQuery, window, document); diff --git a/app/assets/stylesheets/mixins/introduction.sass b/app/assets/stylesheets/mixins/introduction.sass index 921d45a..6641953 100644 --- a/app/assets/stylesheets/mixins/introduction.sass +++ b/app/assets/stylesheets/mixins/introduction.sass @@ -2,5 +2,4 @@ height: 24px width: 24px background-repeat: no-repeat - background-size: auto content: '' diff --git a/app/assets/stylesheets/sections/_user-show.sass b/app/assets/stylesheets/sections/_user-show.sass index 493b189..ed84b49 100644 --- a/app/assets/stylesheets/sections/_user-show.sass +++ b/app/assets/stylesheets/sections/_user-show.sass @@ -114,26 +114,42 @@ margin: 0 .globe + +introduction + background-image: image-url('globe.png') + background-size: cover + display: inline-block height: 24px width: 24px margin-right: 0.5rem - .edit-user - text-align: right + a + height: 18px + width: 18px + position: relative + padding: 3px + border-radius: 3px + float: right + display: inline-block - &:before + &:hover + background-color: #3b5998 + + &:hover .edit-user + opacity: 1 + background-image: image-url('icons2.png') + background-size: 27px 219px + background-position: -13px -141px + + .edit-user + text-align: right +introduction background-image: image-url('icons2.png') - background-position: 0 -141px background-size: 27px 219px + background-position: 0 -141px height: 12px width: 12px - display: inline-block - opacity: .4 - - // &:hover - // background-color: #3b5998 - + display: block + opacity: .6 ul margin: 0 diff --git a/app/assets/stylesheets/sections/_wall.sass b/app/assets/stylesheets/sections/_wall.sass index 8a1db04..c0e5194 100644 --- a/app/assets/stylesheets/sections/_wall.sass +++ b/app/assets/stylesheets/sections/_wall.sass @@ -134,3 +134,13 @@ top: 0 right: 0 border-left: 1px solid #ccc + +.comments + display: block + width: 100% + max-width: 100% + min-height: 32px + word-wrap: break-word + border-radius: 0px + overflow: hidden + resize: none diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 7669955..b39faaf 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,2 +1,41 @@ class CommentsController < ApplicationController + before_action :find_post + before_action :find_post, only: [:show, :edit, :update, :destroy] + + def index + @comments = @post.comment + end + + def new + @comment = Comment.new + @comment = @post.comment.build + end + + def create + @comment = @post.comments.create(params[:comment].permit(:content)) + @comment.post_id = @post.id + @comment.user_id = current_user.id + # @comment = @post.comments.create(params[:comment].permit[:content]) + # @comment.post_id = @post.id + if @comment.save + redirect_to root_path + # format.json { render :show, status: :created, location: @post } + else + render 'new' + end + + end + + private + # Use callbacks to share common setup or constraints between actions. + # def comment_params + # params.require(:comment).permit(:content) + # end + + def find_post + @post = Post.find(params[:post_id]) + end + + + # Never trust parameters from the scary internet, only allow the white list through. end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 2982b5f..ef40f80 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -2,16 +2,9 @@ class PostsController < ApplicationController before_action :set_post, only: [:show, :edit, :update, :destroy] before_action :authenticate_user! - # GET /posts - # GET /posts.json - - - # GET /posts/1 - # GET /posts/1.json - - # GET /posts/new def new @post = Post.new + @comment = Comment.new end # GET /posts/1/edit diff --git a/app/controllers/walls_controller.rb b/app/controllers/walls_controller.rb index c01a1d4..95e284a 100644 --- a/app/controllers/walls_controller.rb +++ b/app/controllers/walls_controller.rb @@ -1,12 +1,14 @@ class WallsController < ApplicationController respond_to :json, :html + + def index @posts = Post.order("created_at DESC") @post = Post.new - @walls = Wall.all.includes(:user, :post).to_json(:include => [{post: {only: %i(username image content youtube_url)}},{:user => {only: %i(id)}}]) + @walls = Wall.all.includes(:user, :post, :comment).to_json(:include => [{post: {only: %i(username image content youtube_url)}},{:user => {only: %i(id)}},{:comment => {only: %i(content)}}]) respond_with @wall @user = User.all + @comment = Comment.new + @comments = Comment.order("created_at DESC") end - - end diff --git a/app/helpers/variables/_colors.sass b/app/helpers/variables/_colors.sass new file mode 100644 index 0000000..77af6a5 --- /dev/null +++ b/app/helpers/variables/_colors.sass @@ -0,0 +1,5 @@ +$white: #fff +$dark-blue: #101b25 +$border-color: #ece8e8 +$black: #000 +$fb-blue: #1c4c77 diff --git a/app/helpers/variables/_vars.sass b/app/helpers/variables/_vars.sass new file mode 100644 index 0000000..fdf1c77 --- /dev/null +++ b/app/helpers/variables/_vars.sass @@ -0,0 +1,25 @@ +.m-top + margin-top: 3em + +.n-m + margin: 0 + +.card + background-color: #fff + padding: 0.75em + border: 1px solid #ece8e8 + border-radius: 4px + width: 100% + max-width: 100% + margin-bottom: 1em + position: relative + +.bold + font-weight: bold + +img + height: auto + max-width: 100% + +.table + display: table diff --git a/app/models/comment.rb b/app/models/comment.rb index 1d79d25..4a019df 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,2 +1,4 @@ class Comment < ApplicationRecord + belongs_to :post + belongs_to :user end diff --git a/app/models/post.rb b/app/models/post.rb index 8063faa..b97442f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,5 +1,6 @@ class Post < ApplicationRecord - belongs_to :user, required: true + belongs_to :user + has_many :comments mount_uploader :image, AvatarUploader validates :content, presence: true, length: {minimum: 5} delegate :username, :username=, :email, :email=,:avatar, :avatar=, :to => :user, allow_nil: true diff --git a/app/models/user.rb b/app/models/user.rb index 23df477..ed6bd87 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,6 +10,7 @@ class User < ApplicationRecord # Setup accessible (or protected) attributes for your model has_many :posts, dependent: :delete_all + has_many :comments, dependent: :delete_all attr_accessor :login validates :username, diff --git a/app/models/wall.rb b/app/models/wall.rb index fc2dd47..ea7d11b 100644 --- a/app/models/wall.rb +++ b/app/models/wall.rb @@ -1,6 +1,8 @@ class Wall < ApplicationRecord - has_many :posts + has_many :post has_many :users + has_many :comments + delegate :username, :username=,:avatar, :avatar=, :email, :email=, :to => :user, allow_nil: true devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable diff --git a/app/views/comments/_comments.html.erb b/app/views/comments/_comments.html.erb new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/app/views/comments/_comments.html.erb @@ -0,0 +1 @@ + diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb new file mode 100644 index 0000000..d8a1bc2 --- /dev/null +++ b/app/views/comments/_form.html.erb @@ -0,0 +1,6 @@ +