diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92f67fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore all paperclip uploads +/public/system + +.DS_Store \ No newline at end of file diff --git a/Capfile b/Capfile new file mode 100644 index 0000000..913cd13 --- /dev/null +++ b/Capfile @@ -0,0 +1,38 @@ +# Load DSL and set up stages +require "capistrano/setup" + +# Include default deployment tasks +require "capistrano/deploy" + +# Load the SCM plugin appropriate to your project: +# +# require "capistrano/scm/hg" +# install_plugin Capistrano::SCM::Hg +# or +# require "capistrano/scm/svn" +# install_plugin Capistrano::SCM::Svn +# or +require "capistrano/scm/git" +install_plugin Capistrano::SCM::Git + +# Include tasks from other gems included in your Gemfile +# +# For documentation on these, see for example: +# +# https://github.com/capistrano/rvm +# https://github.com/capistrano/rbenv +# https://github.com/capistrano/chruby +# https://github.com/capistrano/bundler +# https://github.com/capistrano/rails +# https://github.com/capistrano/passenger +# + +require 'capistrano/rails' +require 'capistrano/passenger' + +require 'capistrano/rbenv' +set :rbenv_type, :user +set :rbenv_ruby, '2.4.0' + +# Load custom tasks from `lib/capistrano/tasks` if you have any defined +Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..6bea7fc --- /dev/null +++ b/Gemfile @@ -0,0 +1,44 @@ +source 'https://rubygems.org' + +git_source(:github) do |repo_name| + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + "https://github.com/#{repo_name}.git" +end + +gem 'rails', '~> 5.0.1' +gem 'puma', '~> 3.0' +gem 'sass-rails', '~> 5.0' +gem 'uglifier', '>= 1.3.0' +gem 'coffee-rails', '~> 4.2' +gem 'jquery-rails' +gem 'jbuilder', '~> 2.5' +gem 'redis', '~> 3.0' + +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +group :development do + gem 'sqlite3' + gem 'meta_request' + gem 'web-console' + gem "awesome_print", require:"ap" +end +group :production do + gem 'pg' +end + +gem 'haml' +gem 'paperclip' +gem 'simple_form' +gem 'bootstrap-sass' +gem 'devise' +gem 'acts_as_votable' +gem 'kaminari' + +gem 'rails_admin' + +gem 'remotipart', '~> 1.2' + +gem 'capistrano', '~> 3.7', '>= 3.7.1' +gem 'capistrano-rails', '~> 1.2' +gem 'capistrano-passenger', '~> 0.2.0' +gem 'capistrano-rbenv', '~> 2.1' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..0226431 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,266 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.0.1) + actionpack (= 5.0.1) + nio4r (~> 1.2) + websocket-driver (~> 0.6.1) + actionmailer (5.0.1) + actionpack (= 5.0.1) + actionview (= 5.0.1) + activejob (= 5.0.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.0.1) + actionview (= 5.0.1) + activesupport (= 5.0.1) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.0.1) + activesupport (= 5.0.1) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (5.0.1) + activesupport (= 5.0.1) + globalid (>= 0.3.6) + activemodel (5.0.1) + activesupport (= 5.0.1) + activerecord (5.0.1) + activemodel (= 5.0.1) + activesupport (= 5.0.1) + arel (~> 7.0) + activesupport (5.0.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + acts_as_votable (0.10.0) + airbrussh (1.1.2) + sshkit (>= 1.6.1, != 1.7.0) + arel (7.1.4) + autoprefixer-rails (6.6.1) + execjs + awesome_print (1.7.0) + bcrypt (3.1.11-x86-mingw32) + bootstrap-sass (3.3.7) + autoprefixer-rails (>= 5.2.1) + sass (>= 3.3.4) + builder (3.2.2) + callsite (0.0.11) + capistrano (3.7.1) + airbrussh (>= 1.0.0) + capistrano-harrow + i18n + rake (>= 10.0.0) + sshkit (>= 1.9.0) + capistrano-bundler (1.2.0) + capistrano (~> 3.1) + sshkit (~> 1.2) + capistrano-harrow (0.5.3) + capistrano-passenger (0.2.0) + capistrano (~> 3.0) + capistrano-rails (1.2.2) + capistrano (~> 3.1) + capistrano-bundler (~> 1.1) + capistrano-rbenv (2.1.0) + capistrano (~> 3.1) + sshkit (~> 1.3) + climate_control (0.1.0) + cocaine (0.5.8) + climate_control (>= 0.0.3, < 1.0) + coffee-rails (4.2.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.2.x) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.0.4) + debug_inspector (0.0.2) + devise (4.2.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 5.1) + responders + warden (~> 1.2.3) + erubis (2.7.0) + execjs (2.7.0) + font-awesome-rails (4.7.0.1) + railties (>= 3.2, < 5.1) + globalid (0.3.7) + activesupport (>= 4.1.0) + haml (4.0.7) + tilt + i18n (0.7.0) + jbuilder (2.6.1) + activesupport (>= 3.0.0, < 5.1) + multi_json (~> 1.2) + jquery-rails (4.2.2) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-ui-rails (5.0.5) + railties (>= 3.2.16) + kaminari (0.17.0) + actionpack (>= 3.0.0) + activesupport (>= 3.0.0) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + meta_request (0.4.0) + callsite (~> 0.0, >= 0.0.11) + rack-contrib (~> 1.1) + railties (>= 3.0.0, < 5.1.0) + method_source (0.8.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mimemagic (0.3.2) + mini_portile2 (2.1.0) + minitest (5.10.1) + multi_json (1.12.1) + nested_form (0.3.2) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (4.0.1) + nio4r (1.2.1) + nokogiri (1.7.0.1-x86-mingw32) + mini_portile2 (~> 2.1.0) + orm_adapter (0.5.0) + paperclip (5.1.0) + activemodel (>= 4.2.0) + activesupport (>= 4.2.0) + cocaine (~> 0.5.5) + mime-types + mimemagic (~> 0.3.0) + pg (0.19.0-x86-mingw32) + puma (3.6.2) + rack (2.0.1) + rack-contrib (1.2.0) + rack (>= 0.9.1) + rack-pjax (1.0.0) + nokogiri (~> 1.5) + rack (>= 1.1) + rack-test (0.6.3) + rack (>= 1.0) + rails (5.0.1) + actioncable (= 5.0.1) + actionmailer (= 5.0.1) + actionpack (= 5.0.1) + actionview (= 5.0.1) + activejob (= 5.0.1) + activemodel (= 5.0.1) + activerecord (= 5.0.1) + activesupport (= 5.0.1) + bundler (>= 1.3.0, < 2.0) + railties (= 5.0.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.2) + activesupport (>= 4.2.0, < 6.0) + nokogiri (~> 1.6) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + rails_admin (1.1.1) + builder (~> 3.1) + coffee-rails (~> 4.0) + font-awesome-rails (>= 3.0, < 5) + haml (~> 4.0) + jquery-rails (>= 3.0, < 5) + jquery-ui-rails (~> 5.0) + kaminari (~> 0.14) + nested_form (~> 0.3) + rack-pjax (>= 0.7) + rails (>= 4.0, < 6) + remotipart (~> 1.3) + sass-rails (>= 4.0, < 6) + railties (5.0.1) + actionpack (= 5.0.1) + activesupport (= 5.0.1) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.0.0) + redis (3.3.2) + remotipart (1.3.1) + responders (2.3.0) + railties (>= 4.2.0, < 5.1) + sass (3.4.23) + sass-rails (5.0.6) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + simple_form (3.4.0) + actionpack (> 4, < 5.1) + activemodel (> 4, < 5.1) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.0) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13-x86-mingw32) + sshkit (1.11.5) + net-scp (>= 1.1.2) + net-ssh (>= 2.8.0) + thor (0.19.4) + thread_safe (0.3.5) + tilt (2.0.5) + tzinfo (1.2.2) + thread_safe (~> 0.1) + tzinfo-data (1.2016.10) + tzinfo (>= 1.0.0) + uglifier (3.0.4) + execjs (>= 0.3.0, < 3) + warden (1.2.6) + rack (>= 1.0) + web-console (3.4.0) + actionview (>= 5.0) + activemodel (>= 5.0) + debug_inspector + railties (>= 5.0) + websocket-driver (0.6.4) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) + +PLATFORMS + x86-mingw32 + +DEPENDENCIES + acts_as_votable + awesome_print + bootstrap-sass + capistrano (~> 3.7, >= 3.7.1) + capistrano-passenger (~> 0.2.0) + capistrano-rails (~> 1.2) + capistrano-rbenv (~> 2.1) + coffee-rails (~> 4.2) + devise + haml + jbuilder (~> 2.5) + jquery-rails + kaminari + meta_request + paperclip + pg + puma (~> 3.0) + rails (~> 5.0.1) + rails_admin + redis (~> 3.0) + remotipart (~> 1.2) + sass-rails (~> 5.0) + simple_form + sqlite3 + tzinfo-data + uglifier (>= 1.3.0) + web-console + +BUNDLED WITH + 1.13.6 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..e85f913 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..b16e53d --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/background.jpg b/app/assets/images/background.jpg new file mode 100644 index 0000000..e5c0577 Binary files /dev/null and b/app/assets/images/background.jpg differ diff --git a/app/assets/images/bg-green-stripes.png b/app/assets/images/bg-green-stripes.png new file mode 100644 index 0000000..a8303cf Binary files /dev/null and b/app/assets/images/bg-green-stripes.png differ diff --git a/app/assets/images/chaton_bg.jpg b/app/assets/images/chaton_bg.jpg new file mode 100644 index 0000000..735e163 Binary files /dev/null and b/app/assets/images/chaton_bg.jpg differ diff --git a/app/assets/images/default-avatar.jpg b/app/assets/images/default-avatar.jpg new file mode 100644 index 0000000..8329fe9 Binary files /dev/null and b/app/assets/images/default-avatar.jpg differ diff --git a/app/assets/images/default-avatar.png b/app/assets/images/default-avatar.png new file mode 100644 index 0000000..822078a Binary files /dev/null and b/app/assets/images/default-avatar.png differ diff --git a/app/assets/images/stripe-blue.png b/app/assets/images/stripe-blue.png new file mode 100644 index 0000000..1025d2e Binary files /dev/null and b/app/assets/images/stripe-blue.png differ diff --git a/app/assets/images/stripe-gray-bg.png b/app/assets/images/stripe-gray-bg.png new file mode 100644 index 0000000..d944a1d Binary files /dev/null and b/app/assets/images/stripe-gray-bg.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000..c2fe244 --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,19 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require bootstrap-sprockets +//= require jquery.remotipart +//= require chat +//= require cable +//= require_tree . \ No newline at end of file diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js new file mode 100644 index 0000000..71ee1e6 --- /dev/null +++ b/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the rails generate channel command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/app/assets/javascripts/channels/appearances.coffee b/app/assets/javascripts/channels/appearances.coffee new file mode 100644 index 0000000..abd83d4 --- /dev/null +++ b/app/assets/javascripts/channels/appearances.coffee @@ -0,0 +1,9 @@ +$(document).ready -> + App.personal_chat = App.cable.subscriptions.create { + channel: "AppearancesChannel" + }, + connected: -> + disconnected: -> + received: (data) -> + user = $(".user-#{data['user_id']}") + user.toggleClass 'online', data['online'] \ No newline at end of file diff --git a/app/assets/javascripts/channels/rooms.coffee b/app/assets/javascripts/channels/rooms.coffee new file mode 100644 index 0000000..a75b11a --- /dev/null +++ b/app/assets/javascripts/channels/rooms.coffee @@ -0,0 +1,36 @@ +$(document).ready -> + messages = $('#messages') + if $('#messages').length > 0 + messages_to_bottom = -> messages.scrollTop(messages.prop("scrollHeight")) + messages_to_bottom() + + App.global_chat = App.cable.subscriptions.create { + channel: "ChatRoomsChannel" + chat_room_id: messages.data('chat-room-id') + }, + connected: -> + # Called when the subscription is ready for use on the server + + disconnected: -> + # Called when the subscription has been terminated by the server + + received: (data) -> + messages.append data['message'] + messages_to_bottom() + + send_message: (message, chat_room_id) -> + @perform 'send_message', message: message, chat_room_id: chat_room_id + + + $('#new_message').submit (e) -> + $this = $(this) + textarea = $this.find('#message_body') + if $.trim(textarea.val()).length >= 1 + App.global_chat.send_message textarea.val(), messages.data('chat-room-id') + textarea.val('') + e.preventDefault() + return false + $('#message_body').keypress (e) -> + if e && e.keyCode == 13 + e.preventDefault() + $(this).submit() \ No newline at end of file diff --git a/app/assets/javascripts/channels/university_chat.coffee b/app/assets/javascripts/channels/university_chat.coffee new file mode 100644 index 0000000..1fc912e --- /dev/null +++ b/app/assets/javascripts/channels/university_chat.coffee @@ -0,0 +1,35 @@ +$(document).ready -> + university_messages = $('#university_messages') + if $('#university_messages').length > 0 + messages_to_bottom = -> university_messages.scrollTop(university_messages.prop("scrollHeight")) + messages_to_bottom() + + App.university_chat = App.cable.subscriptions.create { + channel: "UniversityChatsChannel" + university_id: university_messages.data('university-id') + }, + connected: -> + # Called when the subscription is ready for use on the server + + disconnected: -> + # Called when the subscription has been terminated by the server + + received: (data) -> + university_messages.append data['message'] + messages_to_bottom() + + send_message: (message, university_id) -> + @perform 'send_message', message: message, university_id: university_id + + $('#new_university_message').submit (e) -> + $this = $(this) + textarea = $this.find('#university_message_body') + if $.trim(textarea.val()).length >= 1 + App.university_chat.send_message textarea.val(), university_messages.data('university-id') + textarea.val('') + e.preventDefault() + return false + $('#new_university_message').keypress (e) -> + if e && e.keyCode == 13 + e.preventDefault() + $(this).submit() \ No newline at end of file diff --git a/app/assets/javascripts/chat.js b/app/assets/javascripts/chat.js new file mode 100644 index 0000000..8e0cfea --- /dev/null +++ b/app/assets/javascripts/chat.js @@ -0,0 +1,387 @@ +var chatboxFocus = new Array(); +var chatBoxes = new Array(); + +var ready = function() { + + chatBox = { + /** + * creates an inline chatbox on the page by calling the + * createChatBox function passing along the unique conversation_id + * + * @param conversation_id + */ + chatWith: function(conversation_id) { + chatBox.createChatBox(conversation_id); + $("#chatbox_" + conversation_id + " .chatboxtextarea").focus(); + }, + + /** + * closes the chatbox by essentially hiding it from the page + * + * @param conversation_id + */ + + close: function(conversation_id) { + $('#chatbox_' + conversation_id).css('display', 'none'); + chatBox.restructure(); + }, + + /** + * Plays a notification sound when a new chat message arrives + */ + + notify: function() { + var audioplayer = $('#chatAudio')[0]; + audioplayer.play(); + }, + + /** + * Handles 'smart layouts' of the chatboxes. Like when new chatboxes are + * added or removed from the view, it restructures them so that they appear + * neatly aligned on the page + */ + + restructure: function() { + align = 0; + for (x in chatBoxes) { + chatbox_id = chatBoxes[x]; + + if ($("#chatbox_" + chatbox_id).css('display') != 'none') { + if (align == 0) { + $("#chatbox_" + chatbox_id).css('right', '20px'); + } else { + width = (align) * (280 + 7) + 20; + $("#chatbox_" + chatbox_id).css('right', width + 'px'); + } + align++; + } + } + + }, + + /** + * Takes in two parameters. It is responsible for fetching the specific conversation's + * html page and appending it to the body of our home page e.g if conversation_id = 1 + * + * $.get("conversations/1, function(data){ + * // rest of the logic here + * }, "html") + * + * @param conversation_id + * @param minimizeChatBox + */ + + createChatBox: function(conversation_id, minimizeChatBox) { + + App.personal_chat = App.cable.subscriptions.create({ + channel: "ConversationNotificationsChannel", + conversation_id : conversation_id + }, { + send_message: function(message, conversation_id) { + return this.perform('send_message', { + message: message, + conversation_id: conversation_id + }); + }, + connected: function() {}, + disconnected: function() {}, + received: function(data) { + if(data['message_user_id']==$('meta[name=user-id]').attr("content")){ + $("#chatbox_" + conversation_id + " .chatboxcontent").append('
  • '+data['message']+'
  • '); + }else{ + $("#chatbox_" + conversation_id + " .chatboxcontent").append('
  • '+data['message']+'
  • '); + } + $("#chatbox_" + conversation_id + " .chatboxcontent").scrollTop($("#chatbox_" + conversation_id + " .chatboxcontent")[0].scrollHeight); + } + }); + if ($("#chatbox_" + conversation_id).length > 0) { + if ($("#chatbox_" + conversation_id).css('display') == 'none') { + $("#chatbox_" + conversation_id).css('display', 'block'); + chatBox.restructure(); + } + $("#chatbox_" + conversation_id + " .chatboxtextarea").focus(); + return; + } + + $("body").append('
    ') + + $.get("/conversations/" + conversation_id, function(data) { + $('#chatbox_' + conversation_id).html(data); + $("#chatbox_" + conversation_id + " .chatboxcontent").scrollTop($("#chatbox_" + conversation_id + " .chatboxcontent")[0].scrollHeight); + }, "html"); + + $("#chatbox_" + conversation_id).css('bottom', '0px'); + + chatBoxeslength = 0; + + for (x in chatBoxes) { + if ($("#chatbox_" + chatBoxes[x]).css('display') != 'none') { + chatBoxeslength++; + } + } + + if (chatBoxeslength == 0) { + $("#chatbox_" + conversation_id).css('right', '20px'); + } else { + width = (chatBoxeslength) * (280 + 7) + 20; + $("#chatbox_" + conversation_id).css('right', width + 'px'); + } + + chatBoxes.push(conversation_id); + + if (minimizeChatBox == 1) { + minimizedChatBoxes = new Array(); + + if ($.cookie('chatbox_minimized')) { + minimizedChatBoxes = $.cookie('chatbox_minimized').split(/\|/); + } + minimize = 0; + for (j = 0; j < minimizedChatBoxes.length; j++) { + if (minimizedChatBoxes[j] == conversation_id) { + minimize = 1; + } + } + + if (minimize == 1) { + $('#chatbox_' + conversation_id + ' .chatboxcontent').css('display', 'none'); + $('#chatbox_' + conversation_id + ' .chatboxinput').css('display', 'none'); + } + } + + chatboxFocus[conversation_id] = false; + + $("#chatbox_" + conversation_id + " .chatboxtextarea").blur(function() { + chatboxFocus[conversation_id] = false; + $("#chatbox_" + conversation_id + " .chatboxtextarea").removeClass('chatboxtextareaselected'); + }).focus(function() { + chatboxFocus[conversation_id] = true; + $('#chatbox_' + conversation_id + ' .chatboxhead').removeClass('chatboxblink'); + $("#chatbox_" + conversation_id + " .chatboxtextarea").addClass('chatboxtextareaselected'); + }); + + $("#chatbox_" + conversation_id).click(function() { + if ($('#chatbox_' + conversation_id + ' .chatboxcontent').css('display') != 'none') { + $("#chatbox_" + conversation_id + " .chatboxtextarea").focus(); + } + }); + + $("#chatbox_" + conversation_id).show(); + + }, + + /** + * Responsible for listening to the keypresses when chatting. If the Enter button is pressed, + * we submit our conversation form to our rails app + * + * @param event + * @param chatboxtextarea + * @param conversation_id + */ + + checkInputKey: function(event, chatboxtextarea, conversation_id) { + if (event.keyCode == 13 && event.shiftKey == 0) { + event.preventDefault(); + + message = chatboxtextarea.val(); + message = message.replace(/^\s+|\s+$/g, ""); + + if (message != '') { + App.personal_chat.send_message(message, conversation_id); + $(chatboxtextarea).val(''); + $(chatboxtextarea).focus(); + $(chatboxtextarea).css('height', '44px'); + } + } + + var adjustedHeight = chatboxtextarea.clientHeight; + var maxHeight = 94; + + if (maxHeight > adjustedHeight) { + adjustedHeight = Math.max(chatboxtextarea.scrollHeight, adjustedHeight); + if (maxHeight) adjustedHeight = Math.min(maxHeight, adjustedHeight); + if (adjustedHeight > chatboxtextarea.clientHeight) $(chatboxtextarea).css('height', adjustedHeight + 8 + 'px'); + } else { + $(chatboxtextarea).css('overflow', 'auto'); + } + + }, + + /** + * Responsible for handling minimize and maximize of the chatbox + * + * @param conversation_id + */ + + toggleChatBoxGrowth: function(conversation_id) { + if ($('#chatbox_' + conversation_id + ' .chatboxcontent').css('display') == 'none') { + + var minimizedChatBoxes = new Array(); + + if ($.cookie('chatbox_minimized')) { + minimizedChatBoxes = $.cookie('chatbox_minimized').split(/\|/); + } + + var newCookie = ''; + + for (i = 0; i < minimizedChatBoxes.length; i++) { + if (minimizedChatBoxes[i] != conversation_id) { + newCookie += conversation_id + '|'; + } + } + + newCookie = newCookie.slice(0, -1) + + + $.cookie('chatbox_minimized', newCookie); + $('#chatbox_' + conversation_id + ' .chatboxcontent').css('display', 'block'); + $('#chatbox_' + conversation_id + ' .chatboxinput').css('display', 'block'); + $("#chatbox_" + conversation_id + " .chatboxcontent").scrollTop($("#chatbox_" + conversation_id + " .chatboxcontent")[0].scrollHeight); + } else { + + var newCookie = conversation_id; + + if ($.cookie('chatbox_minimized')) { + newCookie += '|' + $.cookie('chatbox_minimized'); + } + + + $.cookie('chatbox_minimized', newCookie); + $('#chatbox_' + conversation_id + ' .chatboxcontent').css('display', 'none'); + $('#chatbox_' + conversation_id + ' .chatboxinput').css('display', 'none'); + } + + } + } + + + /** + * Cookie plugin + * + * Copyright (c) 2006 Klaus Hartl (stilbuero.de) + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + */ + + jQuery.cookie = function(name, value, options) { + if (typeof value != 'undefined') { // name and value given, set cookie + options = options || {}; + if (value === null) { + value = ''; + options.expires = -1; + } + var expires = ''; + if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { + var date; + if (typeof options.expires == 'number') { + date = new Date(); + date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); + } else { + date = options.expires; + } + expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE + } + // CAUTION: Needed to parenthesize options.path and options.domain + // in the following expressions, otherwise they evaluate to undefined + // in the packed version for some reason... + var path = options.path ? '; path=' + (options.path) : ''; + var domain = options.domain ? '; domain=' + (options.domain) : ''; + var secure = options.secure ? '; secure' : ''; + document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); + } else { // only name given, get cookie + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = jQuery.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + }; + + +} + +$(document).ready(ready); +//$(document).on("page:load", ready); +var ready = function () { + + /** + * When the send message link on our home page is clicked + * send an ajax request to our rails app with the author_id and + * receiver_id + */ + + $(document).on('click','.start-conversation',function (e) { + e.preventDefault(); + + var author_id = $(this).data('sid'); + var receiver_id = $(this).data('rip'); + console.log("/conversations_api") + + $.post("/conversations_api", { author_id: author_id, receiver_id: receiver_id }, function (data) { + chatBox.chatWith(data.conversation_id); + }); + }); + + /** + * Used to minimize the chatbox + */ + + $(document).on('click', '.toggleChatBox', function (e) { + e.preventDefault(); + + var id = $(this).data('cid'); + chatBox.toggleChatBoxGrowth(id); + }); + + /** + * Used to close the chatbox + */ + + $(document).on('click', '.closeChat', function (e) { + e.preventDefault(); + + var id = $(this).data('cid'); + chatBox.close(id); + }); + + + /** + * Listen on keypress' in our chat textarea and call the + * chatInputKey in chat.js for inspection + */ + + $(document).on('keydown', '.chatboxtextarea', function (event) { + var id = $(this).data('cid'); + chatBox.checkInputKey(event, $(this), id); + }); + + /** + * When a conversation link is clicked show up the respective + * conversation chatbox + */ + + $('a.conversation').click(function (e) { + e.preventDefault(); + + var conversation_id = $(this).data('cid'); + chatBox.chatWith(conversation_id); + }); +} + +$(document).ready(ready); +//$(document).on("page:load", ready); + +$(document).on('ready', function(){ + $(document).on('change', 'input[name="personal_message[attachment]"]',function(){ + $(this).parents("form:first").submit(); + }); +}); \ No newline at end of file diff --git a/app/assets/javascripts/loadMoreComments.js b/app/assets/javascripts/loadMoreComments.js new file mode 100644 index 0000000..b2f243b --- /dev/null +++ b/app/assets/javascripts/loadMoreComments.js @@ -0,0 +1,38 @@ +var Append = {}; +Append.open = false; +function ClickableCommentsLink(){ + $('.more-comments').click( function() { + $(this).on('ajax:success', function(event, data, status,xhr) { + event.preventDefault(); + var postId = $(this).data("post-id"); + $("#comments_" + postId).html(data); + $("#comments-paginator-" + postId).html(" 4){ Append.comment = false; Append.link = false; } + }) +}); diff --git a/app/assets/javascripts/notification.coffee b/app/assets/javascripts/notification.coffee new file mode 100644 index 0000000..16d1ad1 --- /dev/null +++ b/app/assets/javascripts/notification.coffee @@ -0,0 +1,72 @@ +class UserNotification + constructor: -> + @notifications = $("[data-behaviour='notifications']"); + @messages = $("[data-behaviour='message-notifications']") + + setup: -> + if @notifications.length > 0 + @makeNotificationsAjaxRequest() + @notifications.on "click" , @handleNotificationClick + @messages.on "click" , @handleMessageNotificationClick + + makeNotificationsAjaxRequest: -> + $.ajax( + url:'/notifications.json' + dataType: "JSON", + method: "GET", + success: @handleSuccess + ) + + handleNotificationClick: (e) => + $.ajax( + url: "/notifications/mark_notifications_as_read", + dataType: "JSON", + method: "POST", + success: -> + $("[data-behaviour='notifications-count']").html(0); + ) + + handleMessageNotificationClick: (e) => + $.ajax( + url: "/notifications/mark_messages_notification_as_read", + dataType: "JSON", + method: "POST", + success: -> + $("[data-behaviour='message-notifications-count']").html(0); + ) + + handleSuccess: (data)=> + notification_items = $.map data, (notification) -> + if(notification.type != 'conversations') + notification.template + + unread_notication_count = 0 + $.each data, (i, notification) -> + if(notification.type != 'conversations') + if notification.unread + unread_notication_count += 1 + + $("[data-behaviour='notifications-count']").html(unread_notication_count); + $("[data-behaviour='notifications-item']").html(notification_items); + + message_items = $.map data, (notification) -> + if(notification.type == 'conversations') + notification.template + + unread_messages_count = 0 + $.each data, (i, notification) -> + if(notification.type == 'conversations') + if notification.unread + unread_messages_count += 1 + $("[data-behaviour='message-notifications-count']").html(unread_messages_count); + $("[data-behaviour='message-notifications-item']").html(message_items); + + +jQuery -> + (new UserNotification).setup() + App.user_notifications = App.cable.subscriptions.create { + channel: "UserNotificationsChannel" + }, + received: (data) -> + (new UserNotification).makeNotificationsAjaxRequest() + return \ No newline at end of file diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js new file mode 100644 index 0000000..3a0c6f0 --- /dev/null +++ b/app/assets/javascripts/posts.js @@ -0,0 +1,25 @@ +/* +|-------------------------------------------------------------------------- +| Load Preview Of Image +|-------------------------------------------------------------------------- +*/ +var loadFile = function(event) { + var type = event.target.files[0].type; + if(type == 'image/jpeg' || type =='image/gif' || type == 'image/png'){ + var output = document.getElementById('image-preview'); + output.src = URL.createObjectURL(event.target.files[0]); + } +}; +/* +|-------------------------------------------------------------------------- +| In Comment Section +|-------------------------------------------------------------------------- +*/ +$(function(){ + $('div.view_post_bottom>span.comment_counter').click(function(){ + $(this).parent('div.view_post_bottom').siblings('div.post-bottom').slideToggle(); + }); + $('.new_comment').submit(function(){ + $(this).closest('div.comment-like-form').siblings('div.post-bottom').slideDown(); + }); +}); \ No newline at end of file diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000..86f6b0c --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,759 @@ +/* + *= require_tree . + *= require_self + */ + +@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'); +@import url('https://fonts.googleapis.com/css?family=Montserrat:400,700'); + +html { + height: 100%; +} +body { + background: #fafafa image-url('stripe-gray-bg.png'); + font-family: Montserrat, sans-serif; + font-size:12px; +} +.alert { + margin-bottom: 0px; +} +.clear{ + clear:both +} +.post__avatar,.comment__avatar{ + width:50px; + height:50px; + max-width:none; + float:left; + margin-right:10px; +} +.comment__avatar{ + width:40px; + height:40px; +} +.flat__buttons { + padding: 5px 15px !important; + margin-right: 5px !important; + border-radius: 20px; +} +.notification-dropdown{ + margin-right: 5px; +} +.h-100{ + height:100% +} +.mauto{ + margin:0 auto +} +.mt20{ + margin-top:20px +} +.mb20{ + margin-bottom:20px; +} +.bgwhite{ + background:white; +} +.bglgray{ + background:#fafafa; +} +.sb1{ + border:1px solid #ccc; +} +.mwidth960{ + max-width:960px; +} +.w250{ + width:250px +} +.padding20{ + padding:20px +} +.dib{ + display:inline-block; +} +.colorb{ + color:blue; +} +.colorr{ + color:red; +} +.personal_message_attachment{ + overflow: hidden; + position: absolute; + bottom: 11px; + right: 6px; +} + +.personal_message_attachment [type=file] { + cursor: inherit; + display: block; + font-size: 999px; + filter: alpha(opacity=0); + min-height: 100%; + min-width: 100%; + opacity: 0; + position: absolute; + right: 0; + text-align: right; + top: 0; +} +.personal_message_attachment span{ + font-size:20px; +} + +.like-button a{ + font-size:20px; + color:green; +} + +.navigation_box{ + font-size:16px +} +.notification-dropdown > button{ + border:none; + margin-top: 10px; +} +.navbar-header .navigation_box{ + float: left; + margin-top: 12px; + font-size: 18px; +} + +.btn-file { + position: relative; + overflow: hidden; +} +.btn-file input[type=file] { + position: absolute; + top: 0; + right: 0; + min-width: 100%; + min-height: 100%; + font-size: 100px; + text-align: right; + filter: alpha(opacity=0); + opacity: 0; + outline: none; + background: white; + cursor: inherit; + display: block; +} +.navigation_box,.navigation_box:hover{ + color:#525252; + text-decoration:none +} +.search-form{ + float:left; + margin:8px 0 0 40px; +} +.search-form #username{ + width:360px +} +/* +|-------------------------------------------------------------------------- +| Navbar +|-------------------------------------------------------------------------- +*/ +.navbar { + border: 0; + margin-bottom: 0; + font-size: 12px; + background: rgba(26, 188, 174, 0.58); + border-bottom: 1px solid #1ab39e; +} +.navbar .navbar-brand { + letter-spacing: 5px; +} +.navbar-nav li a:hover { + color: black !important; +} +.notification-dropdown button{ + border-radius: 15px; +} +.notifications-count,.message-notifications-count{ + color:red +} +/* +|-------------------------------------------------------------------------- +| ChatBox +|-------------------------------------------------------------------------- +*/ +.chat_box { + border: 1px solid #eee; + margin-top:40px; + font-size:16px; + max-height:800px; + overflow-y:scroll; +} + +.chat_box li { + list-style: none; + border-radius:0 !important; + padding:0 !important; +} +.chat_box a,.chat_box_heading{ + width:100%; + padding:20px; + display: block; + transition:all 1s; +} +.chat_box_heading{ + text-align:center; + background:#1ABC9C; + color:white; + padding:3px 5px; +} +.chat_box a:hover{ + background:#EAF1EF; + color:#337ab7; + text-decoration:none +} +.chat__avatar{ + width:32px; + height:32px; + float:left; + margin-right:10px; + max-width:none; +} +.user_online_block{ + float:right +} +.online_status.online{ + background: rgb(66, 183, 42); border-radius: 50%; display: inline-block; height: 6px; margin-left: 4px; width: 6px; +} +/* +|-------------------------------------------------------------------------- +| Copyright +|-------------------------------------------------------------------------- +*/ +.copyright-part { + background-color: #2f2f2f; + color: #fff; + padding:15px 10px; +} +/* +|-------------------------------------------------------------------------- +| POST CUSTOMISATIONS +|-------------------------------------------------------------------------- +*/ +.post-wrapper { + padding-top: 40px; + margin: 0 auto; + width: 100%; + max-width:642px; +} +.post__image{ + margin:0 auto +} + +.post { + background-color: #fff; + border:1px solid #bcbcbc; +} +.post-head{ + padding:10px 15px; +} +.post-user-name{ + font-size:12px; +} +.post-user-name a,.comment-user-name a{ + font-size:16px; +} +.time-ago{ + font-size:10px; +} +.content,.comment{ + margin-top:20px; +} +.delete-comment-icon { + float: right; + color: #515151; +} +.post-bottom { + padding:10px 20px; + background:#eee; + display:none; +} +.view_post_bottom{ + padding:5px 20px; +} +.comment_counter{ + cursor: pointer; + color:blue; +} +/* +|-------------------------------------------------------------------------- +| Univeristy +|-------------------------------------------------------------------------- +*/ +.university-index-wrapper{ + background:#fafafa; + padding:10px; + margin: 40px auto 20px; + width: 100%; + max-width:700px; + border:1px solid #aaa; +} +.university-show-wrapper{ + max-width:1100px; + margin:0 auto; +} +.university_timeline_image { + width:100% +} +.university-index-box{ + width:200px; + display:inline-block; + margin-right:20px +} +.university-index-box:last{ + margin-right:0 +} +.university-card-thumbnail img{ + width:200px; + height:200px; +} +.university-card{ + position:relative; + font-size:150%; + text-align:center +} +.university-index-box a,.university-index-box a:hover{ + color:black; + cursor:pointer; + text-decoration:none; +} +/* +|-------------------------------------------------------------------------- +| Attachment +|-------------------------------------------------------------------------- +*/ +.attachment-files,.attachment-info{ + margin-left:20px; +} +/* +|-------------------------------------------------------------------------- +| Comment Area +|-------------------------------------------------------------------------- +*/ +.comment-form textarea:focus,.comment-form input:focus,.chatbox textarea:focus{ + outline : none; +} + + +.comment_content { + font-size: 15px; + line-height: 18px; + border: medium none; + width: 100%; + color: #4B4F54; +} + +.comment-like-form { + padding-top: 24px; + margin-top: 13px; + margin-left: 24px; + margin-right: 24px; + min-height: 68px; + align-items: center; + border-top: 1px solid #EEEFEF; + flex-direction: row; + justify-content: center; +} +/* +|-------------------------------------------------------------------------- +| Wrapper and styling for the new, edit & devise views +|-------------------------------------------------------------------------- +*/ +.edit-links { + margin-top: 20px; + margin-bottom: 40px; +} +.registration-bg,.login-bg { + padding-top: 2em; + background-image: image-url('chaton_bg.jpg'); + -moz-background-size: cover; + -webkit-background-size: cover; + -o-background-size: cover; + background-size: cover; + min-height:83% +} +.log-in{ + margin-left: auto; + margin-right: auto; + text-align:center; + border: 1px solid #ccc; +} + +#image-preview { + margin: 0 auto; + padding:20px +} + +#post_image { + padding: 1em; + margin: 0px auto; +} +#paginator { + color: #4090DB; + height: 120px; + width: 120px; + margin: 60px auto 40px; + position: relative; + display: table; + border: 2px solid #4090DB; + border-radius: 50%; + :hover { + border: 1px solid #2D6DA8; + border-radius: 50%; + } +} + +#load_more { + display: table-cell; + font-size: 12px; + padding: 0px 9px; + vertical-align: middle; + text-decoration: none; + a :hover { + color: #2D6DA8; + } +} + +.comments { + .paginator { + margin: 0.5em; + .more-comments { + color: #A5A7AA; + } + } +} + +.comment-submit-button { + position: absolute; + left: -9999px; +} + +.profile-header { + padding: 20px 0; + background:white; + border:1px solid #bcbcbc +} + +.profile-image { + margin: 20px auto; + height: 152px; + width: 152px; +} + +.user-name-and-follow { + display: inline; +} + +.profile-user-name { + display: inline; +} + +.edit-button { + border-color: #818488; + color: #818488; +} + +.profile-bio { + margin-top: 20px; +} + +#user_bio { + border: 1px solid gray; +} + +#user_avatar { + padding: 1em; + margin: 0px auto; +} +/* +|-------------------------------------------------------------------------- +| Likes +|-------------------------------------------------------------------------- +*/ +.likes { + margin-bottom: 7px; + color: #4b4f54; +} + +.like { + text-decoration: none; + color: red; +} + +.like-button a:hover, a:focus { + text-decoration: none; + color: red; +} + +/* +|-------------------------------------------------------------------------- +| Notifications +|-------------------------------------------------------------------------- +*/ + +.notification-index-list { + margin-top: 5em; + list-style: none; + li { + margin-top: 1em; + background-color: white; + padding: 1em; + } +} +.notification-unread{ + border-left:3px solid green; +} +/* +|-------------------------------------------------------------------------- +| Follow Unfollow Button +|-------------------------------------------------------------------------- +*/ +.follow-button,.unfollow-button{ + float:right +} +/* +|-------------------------------------------------------------------------- +| All Users +|-------------------------------------------------------------------------- +*/ +.user_listings{ + padding:10px 20px; + background:white; +} +.user{ + margin-bottom: 10px; + border-bottom: 1px solid #bbb; + padding: 10px 0; +} +.user_username a{ + font-size:20px; +} +/* +|-------------------------------------------------------------------------- +| All Users +|-------------------------------------------------------------------------- +*/ +.suggestion_box_main{ + padding: 0; + list-style-type: none; +} +.suggestion_box_heading{ + padding:10px 20px; + border-bottom:1px solid #ccc; + font-size:14px; +} +.suggestion_box_main li{ + padding:10px 20px; +} +/* +|-------------------------------------------------------------------------- +| ChatBox +|-------------------------------------------------------------------------- +*/ +.chatbox { + position: fixed; + position: expression("absolute"); + width: 280px; + display: none; +} +.chatbox form{ + margin-bottom: 0; +} +.chatboxhead { + background: #4496BC; + color: white; + padding: 0.5rem; + overflow: hidden; + padding-left:15px; +} + +.chatboxhead h1 { + display: inline; + font-size: 17px; + font-weight: 700; +} + +.chatboxblink { + background-color: #176689; + border-right: 1px solid #176689; + border-left: 1px solid #176689; +} + +.chatboxcontent { + height: 280px; + width: 280px; + overflow-y: auto; + padding: 7px; + border-left: 1px solid #cccccc; + border-right: 1px solid #cccccc; + border-bottom: 1px solid #eeeeee; + background: #e5e5e5; + line-height: 1.3em; + list-style: none; +} + +.chatboxcontent li { + padding: 0.5rem; + overflow: hidden; + display: flex; +} + +.chatboxcontent .avatar { + width: 32px; + position: relative; +} + +.chatboxcontent .avatar img { + display: block; +} + +.other .avatar:after { + content: ""; + position: absolute; + top: 0; + right: 0; + width: 0; + height: 0; + border: 5px solid white; + border-left-color: transparent; + border-bottom-color: transparent; +} + +.self { + justify-content: flex-end; + align-items: flex-end; +} + +.self .chatboxmessagecontent { + order: 1; + border-bottom-right-radius: 0; +} + +.self .avatar { + order: 2; +} + +.self .avatar:after { + content: ""; + position: absolute; + bottom: 0; + left: 0; + width: 0; + height: 0; + border: 5px solid white; + border-right-color: transparent; + border-top-color: transparent; + box-shadow: transparent; +} + +.chatboxmessagecontent { + background: white; + padding: 10px; + border-radius: 2px; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); +} + +.chatboxmessagecontent p { + font-size: 12px; + margin: 0 0 0.2rem 0; +} + +.chatboxmessagecontent time { + font-size: 9px; + color: #ccc; +} + +.chatboxinput { + padding: 5px; + background-color: #ffffff; + border-left: 1px solid #cccccc; + border-right: 1px solid #cccccc; + border-bottom: 1px solid #cccccc; +} + +.chatboxtextarea { + width: 262px; + height: 44px; + padding: 3px 0pt 3px 3px; + overflow: hidden; + resize: none !important; + border:none; +} + +.chatboxmessage { + margin-left: 1em; +} + +.chatboxinfo { + margin-left: -1em; + color: #666666; +} + +.chatboxoptions { + float: right; +} + +.chatboxoptions a { + text-decoration: none; + color: white; + font-weight: bold; +} + +.chatboxtitle { + float: left; +} +#messages,#university_messages{ + max-height: 400px; + overflow-y: scroll; + overflow-x: hidden; +} +.card-block{ + margin-bottom:10px; +} +/* +|-------------------------------------------------------------------------- +| Conversation +|-------------------------------------------------------------------------- +*/ +.conversation_list_item{ + background:#fafafa; +} +.conversation_box{ + border: 1px solid #eee; + margin-top: 40px; + font-size: 16px; + max-height: 600px; + overflow-y: scroll; +} +.conversation_box li{ + list-style: none; + border-radius: 0 !important; + padding: 0 !important; +} +.conversation_list_item{ + padding: 5px 10px; + transition:all 1s; +} +.conversation_list_item:hover{ + background: #EAF1EF; + color: #337ab7; +} +.conversation_list_item a{ + text-decoration: none; +} +.conversation_list_item__message{ + font-size:75%; + color:black; +} +#conversation-body{ + max-height: 400px; + overflow-y: scroll; + overflow-x: hidden; +} \ No newline at end of file diff --git a/app/channels/appearances_channel.rb b/app/channels/appearances_channel.rb new file mode 100644 index 0000000..00bf6b3 --- /dev/null +++ b/app/channels/appearances_channel.rb @@ -0,0 +1,22 @@ +class AppearancesChannel < ApplicationCable::Channel + def subscribed + redis.set("user_#{current_user.id}_online", "1") + stream_from("appearances_channel") + ActionCable.server.broadcast "appearances_channel", + user_id: current_user.id, + online: true + end + + def unsubscribed + redis.del("user_#{current_user.id}_online") + ActionCable.server.broadcast "appearances_channel", + user_id: current_user.id, + online: false + end + + private + + def redis + Redis.new + end +end \ No newline at end of file diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..3854916 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,20 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + identified_by :current_user + + def connect + self.current_user = find_verified_user + #logger.add_tags 'ActionCable Channel Logs', current_user.user_name + end + + protected + + def find_verified_user # this checks whether a user is authenticated with devise + if verified_user = env['warden'].user + verified_user + else + reject_unauthorized_connection + end + end + end +end \ No newline at end of file diff --git a/app/channels/chat_rooms_channel.rb b/app/channels/chat_rooms_channel.rb new file mode 100644 index 0000000..84d51f2 --- /dev/null +++ b/app/channels/chat_rooms_channel.rb @@ -0,0 +1,13 @@ +class ChatRoomsChannel < ApplicationCable::Channel + def subscribed + stream_from "chat_rooms_#{params['chat_room_id']}_channel" + end + + def unsubscribed + # Any cleanup needed when channel is unsubscribed + end + + def send_message(data) + current_user.messages.create!(body: data['message'], chat_room_id: data['chat_room_id']) + end +end \ No newline at end of file diff --git a/app/channels/conversation_notifications_channel.rb b/app/channels/conversation_notifications_channel.rb new file mode 100644 index 0000000..407f9d7 --- /dev/null +++ b/app/channels/conversation_notifications_channel.rb @@ -0,0 +1,23 @@ +class ConversationNotificationsChannel < ApplicationCable::Channel + def subscribed + stream_from("conversation_notifications_#{params['conversation_id']}_channel") + end + + def unsubscribed + end + + def send_message(data) + conversation = Conversation.find_by(id: data['conversation_id']) + if conversation && conversation.participates?(current_user) + personal_message = current_user.personal_messages.build({body: data['message']}) + personal_message.conversation = conversation + personal_message.save! + if(current_user.id == personal_message.conversation.author_id) + Notification.find_or_initialize_by(recipient: personal_message.conversation.receiver,actor: current_user,action: 'messaged',notifiable: personal_message.conversation).update_attributes!(read_at: nil) + end + if(current_user.id == personal_message.conversation.receiver_id) + Notification.find_or_initialize_by(recipient: personal_message.conversation.author,actor: current_user,action: 'messaged',notifiable: personal_message.conversation).update_attributes!(read_at: nil) + end + end + end +end \ No newline at end of file diff --git a/app/channels/university_chats_channel.rb b/app/channels/university_chats_channel.rb new file mode 100644 index 0000000..f6114d9 --- /dev/null +++ b/app/channels/university_chats_channel.rb @@ -0,0 +1,15 @@ +class UniversityChatsChannel < ApplicationCable::Channel + def subscribed + stream_from "university_chats_#{params['university_id']}_channel" + end + + def unsubscribed + # Any cleanup needed when channel is unsubscribed + end + + def send_message(data) + if(current_user.is_university_approved( data['university_id']) ) + current_user.university_messages.create!(body: data['message'], university_id: data['university_id']) + end + end +end \ No newline at end of file diff --git a/app/channels/user_notifications_channel.rb b/app/channels/user_notifications_channel.rb new file mode 100644 index 0000000..d3243c7 --- /dev/null +++ b/app/channels/user_notifications_channel.rb @@ -0,0 +1,5 @@ +class UserNotificationsChannel < ApplicationCable::Channel + def subscribed + stream_from "user_notifications_#{current_user.id}_channel" + end +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..6549e72 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,13 @@ +class ApplicationController < ActionController::Base + #protect_from_forgery with: :exception + + before_action :configure_permitted_parameters, if: :devise_controller? + + protected + + def configure_permitted_parameters + added_attrs = [:user_name,:first_name,:last_name, :email, :password, :password_confirmation, :remember_me,:is_female] + devise_parameter_sanitizer.permit(:sign_up, keys: added_attrs) + devise_parameter_sanitizer.permit(:account_update, keys: added_attrs) + end +end \ No newline at end of file diff --git a/app/controllers/chat_rooms_controller.rb b/app/controllers/chat_rooms_controller.rb new file mode 100644 index 0000000..3123eea --- /dev/null +++ b/app/controllers/chat_rooms_controller.rb @@ -0,0 +1,32 @@ +class ChatRoomsController < ApplicationController + before_action :authenticate_user! + def index + @chat_rooms = ChatRoom.all + end + + def new + @chat_room = ChatRoom.new + end + + def show + @chat_rooms = ChatRoom.all + @chat_room = ChatRoom.includes(:messages).find_by(id: params[:id]) + @message = Message.new + end + + def create + @chat_room = current_user.chat_rooms.build(chat_room_params) + if @chat_room.save + flash[:success] = 'Chat room added!' + redirect_to chat_rooms_path + else + render 'new' + end + end + + private + + def chat_room_params + params.require(:chat_room).permit(:title) + end +end \ No newline at end of file diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..396c82e --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,52 @@ +class CommentsController < ApplicationController + before_action :authenticate_user! + before_action :set_post + + def index + @comments = @post.comments.order('created_at asc') + @postable = @post.postable + + respond_to do |format| + format.html { render layout: !request.xhr? } + end + end + + def create + @comment = @post.comments.build(comment_params) + @comment.user_id = current_user.id + if @comment.save + unless @post.user.id == current_user.id + Notification.find_or_initialize_by(recipient: @post.user,actor: current_user,action: 'commented',notifiable: @post).update_attributes!(read_at: nil) + end + respond_to do |format| + format.html { redirect_to root_path } + format.js + end + else + flash[:alert] = 'Check the comment form, something went wrong.' + render root_path + end + end + + def destroy + @comment = @post.comments.find(params[:id]) + + if @comment.user_id == current_user.id + @comment.destroy + respond_to do |format| + format.html { redirect_to root_path } + format.js + end + end + end + + private + def comment_params + params.require(:comment).permit(:content) + end + + def set_post + @post = Post.find(params[:post_id]) + end + +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb new file mode 100644 index 0000000..7e3fa86 --- /dev/null +++ b/app/controllers/conversations_controller.rb @@ -0,0 +1,29 @@ +class ConversationsController < ApplicationController + before_action :authenticate_user! + before_action :set_conversation, except: [:index] + before_action :check_participating!, except: [:index] + + def show + @personal_message = PersonalMessage.new + @conversations = Conversation.participating(current_user).order('updated_at DESC') + + respond_to do |format| + format.html { render :layout => false } # your-action.html.erb + end + end + + def index + @conversations = Conversation.participating(current_user).order('updated_at DESC') + end + + private + + def set_conversation + @conversation = Conversation.find_by(id: params[:id]) + end + + def check_participating! + redirect_to root_path unless @conversation && @conversation.participates?(current_user) + end + +end \ No newline at end of file diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb new file mode 100644 index 0000000..1531099 --- /dev/null +++ b/app/controllers/dashboard_controller.rb @@ -0,0 +1,17 @@ +class DashboardController < ApplicationController + before_action :authenticate_user! + def index + @posts = Post.where(postable_type: 'User').of_followed_users(current_user.following).order('created_at DESC').page params[:page] + @post = current_user.posts.build + end + def search + if(!params[:username]) + flash[:danger] = "No search as given" + redirect_to root_path + end + @result = User.search_name(params[:username]); + puts "__________________________________________________________________" + puts params[:username] + puts @result + end +end \ No newline at end of file diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb new file mode 100644 index 0000000..2618947 --- /dev/null +++ b/app/controllers/messages_controller.rb @@ -0,0 +1,2 @@ +class MessagesController < ApplicationController +end \ No newline at end of file diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb new file mode 100644 index 0000000..4ee01d0 --- /dev/null +++ b/app/controllers/notifications_controller.rb @@ -0,0 +1,22 @@ +class NotificationsController < ApplicationController + before_action :authenticate_user! + + def index + @notifications = Notification.where(recipient: current_user).recent + end + def mark_notifications_as_read + @notifications = Notification.where(recipient: current_user).where.not(notifiable_type: 'Conversation').unread + @notifications.update_all(read_at: Time.zone.now) + render json: {success: true} + end + def mark_messages_notification_as_read + @notifications = Notification.where(recipient: current_user,notifiable_type: 'Conversation').where(notifiable_type: 'Conversation').unread + @notifications.update_all(read_at: Time.zone.now) + render json: {success: true} + end + def mark_all_as_read + @notifications = Notification.where(recipient: current_user).unread + @notifications.update_all(read_at: Time.zone.now) + render json: {success: true} + end +end diff --git a/app/controllers/personal_messages_controller.rb b/app/controllers/personal_messages_controller.rb new file mode 100644 index 0000000..067f87b --- /dev/null +++ b/app/controllers/personal_messages_controller.rb @@ -0,0 +1,50 @@ +class PersonalMessagesController < ApplicationController + before_action :find_conversation! , except: [:api] + before_action :authenticate_user! + +def create + @conversation ||= Conversation.create(author_id: current_user.id, + receiver_id: @receiver.id) + @personal_message = current_user.personal_messages.build(personal_message_params) + @personal_message.conversation_id = @conversation.id + @personal_message.save! + + redirect_to conversation_path(@conversation) + end + + def new + redirect_to conversation_path(@conversation) and return if @conversation + @personal_message = current_user.personal_messages.build + end + + def api + if Conversation.between(params[:author_id], params[:receiver_id]).present? + @conversation = Conversation.between(params[:author_id],params[:receiver_id]).first + else + @conversation = Conversation.create!(conversation_api_params) + end + render json: { conversation_id: @conversation.id } + end + + private + + def personal_message_params + params.require(:personal_message).permit(:body,:attachment) + end + + def conversation_api_params + params.permit(:author_id, :receiver_id) + end + + + def find_conversation! + if params[:receiver_id] + @receiver = User.find_by(id: params[:receiver_id]) + redirect_to(root_path) and return unless @receiver + @conversation = Conversation.between(current_user.id, @receiver.id)[0] + else + @conversation = Conversation.find_by(id: params[:conversation_id]) + redirect_to(root_path) and return unless @conversation && @conversation.participates?(current_user) + end + end +end \ No newline at end of file diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb new file mode 100644 index 0000000..252376a --- /dev/null +++ b/app/controllers/posts_controller.rb @@ -0,0 +1,104 @@ +class PostsController < ApplicationController + before_action :authenticate_user! + before_action :load_postable + before_action :set_post, only: [:show, :edit, :update, :destroy, :like,:unlike] + before_action :owned_post, only: [:edit, :update, :destroy] + before_action :university_approval, only: [:create,:edit, :update, :destroy,:like ,:unlike] + + def create + @posts = Post.of_followed_users(current_user.following).order('created_at DESC').page params[:page] + @post = @postable.posts.build(post_params) + @post.user_id = current_user.id + if @post.save + flash[:success] = "The given post has been created!" + if(@post.postable_type == 'User') + redirect_to profile_path(current_user.user_name) + else + redirect_to @postable + end + else + flash[:alert] = "The given new post couldn't be created! Please check the form." + redirect_to [@postable] + end + end + def show + end + def edit + end + + def update + if @post.update(post_params) + flash[:success] = "Post updated." + if(@post.postable_type == 'User') + redirect_to profile_path(current_user.user_name) + else + redirect_to @postable + end + else + flash[:alert] = "Update failed. Please check the form." + render :edit + end + end + + def destroy + @post.destroy + flash[:success] = "The given post has been deleted." + redirect_to profile_path(current_user.user_name) + end + + def like + if @post.liked_by current_user + if @post.user.id != current_user.id + Notification.create(recipient: @post.user,actor: current_user,action: 'liked',notifiable: @post) + end + respond_to do |format| + format.html { redirect_to :back } + format.js + end + end + end + def unlike + if @post.unliked_by current_user + respond_to do |format| + format.js + format.html { redirect_to :back } + end + end + end + + private + def post_params + params.require(:post).permit(:attachment, :content) + end + + def set_post + @post = @postable.posts.find(params[:id]) + end + + def load_postable + @klass = [User,University].detect{|c| params["#{c.name.underscore}_id"]} + @postable = @klass.find(params["#{@klass.name.underscore}_id"]); + end + + def owned_post + if(@klass.name == 'University') + unless current_user == @post.user || current_user.role.name =='admin' || (current_user.is_univerisity_moderator(@post.postable.id) && !@post.user.is_univerisity_moderator(@post.postable.id)) + flash[:alert] = "That post doesn't belong to you!" + redirect_to root_path + end + else + unless current_user == @post.user || current_user.role.name =='admin' + flash[:alert] = "That post doesn't belong to you!" + redirect_to root_path + end + end + end + def university_approval + if(@klass.name == 'University') + unless current_user.is_university_approved(@postable.id) + flash[:alert] = "You are not eligible to post without approvals!" + redirect_to root_path + end + end + end +end diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb new file mode 100644 index 0000000..2721d76 --- /dev/null +++ b/app/controllers/profiles_controller.rb @@ -0,0 +1,46 @@ +class ProfilesController < ApplicationController + before_action :authenticate_user! + before_action :set_user + before_action :owned_profile, only: [:edit, :update] + + def show + @posts = @user.posts.order('created_at DESC') + end + + def edit + end + + def update + if @user.update(profile_params) + flash[:success] = 'Your profile has been updated.' + redirect_to profile_path(@user.user_name) + else + @user.errors.full_messages + flash[:error] = @user.errors.full_messages + render :edit + end + end + + def show_all_users + + end + + private + + def profile_params + params.require(:user).permit(:avatar, :bio) + end + + def owned_profile + unless current_user == @user + flash[:alert] = "That profile doesn't belong to you!" + redirect_to root_path + end + end + + def set_user + @user = User.find_by(user_name: params[:user_name]) + @users= User.all + end + +end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb new file mode 100644 index 0000000..2dc551c --- /dev/null +++ b/app/controllers/registrations_controller.rb @@ -0,0 +1,12 @@ +class RegistrationsController < Devise::RegistrationsController + + private + + def sign_up_params + params.require(:user).permit(:email, :user_name, :password, :password_confirmation,:is_female) + end + + def account_update_params + params.require(:user).permit(:email, :user_name, :password, :password_confirmation, :current_password,:is_female) + end +end diff --git a/app/controllers/relationships_controller.rb b/app/controllers/relationships_controller.rb new file mode 100644 index 0000000..e7580f8 --- /dev/null +++ b/app/controllers/relationships_controller.rb @@ -0,0 +1,22 @@ +class RelationshipsController < ApplicationController + def follow_user + @user = User.find_by! user_name: params[:user_name] + if current_user.follow @user.id + Notification.find_or_initialize_by(recipient: @user,actor: current_user,action: 'followed',notifiable: current_user).update_attributes!(read_at: nil) + respond_to do |format| + format.html { redirect_to root_path } + format.js + end + end + end + + def unfollow_user + @user = User.find_by! user_name: params[:user_name] + if current_user.unfollow @user.id + respond_to do |format| + format.html { redirect_to root_path } + format.js + end + end + end +end \ No newline at end of file diff --git a/app/controllers/universities_controller.rb b/app/controllers/universities_controller.rb new file mode 100644 index 0000000..af9d6c8 --- /dev/null +++ b/app/controllers/universities_controller.rb @@ -0,0 +1,148 @@ +class UniversitiesController < ApplicationController + before_action :authenticate_user! + before_action :set_university, only: [:show, :edit, :update, :destroy,:members] + before_action :administration_right, only: [:create,:update,:destroy,:demote_moderator,:make_moderator] + before_action :set_university_id_and_user_id_and_user, only: [:moderation_right,:delete,:approve,:ban,:make_moderator,:demote_moderator] + before_action :moderation_right, only: [:delete,:approve,:ban,] + + def index + @universities = University.all + end + + def new + @university = University.new + end + + def edit + end + + def create + @university = University.new(university_params) + if @university.save + redirect_to @university, notice: 'University was successfully created.' + else + render :new + end + end + + def update + if @university.update(university_params) + redirect_to @university, notice: 'University was successfully updated.' + else + render :edit + end + end + + def destroy + @university.destroy + redirect_to universities_url, notice: 'University was successfully deleted.' + end + + def show + @posts = @university.posts.order('created_at DESC').page params[:page] + @post = @university.posts.build + end + + def chat + @university = University.includes(:university_message).find_by(id: params[:id]) + @university_message = UniversityMessage.new + end + + def members + @members = UniversityMembership.includes(:university,:user).where(university_id: @university.id) + @moderator_role_id = Role.where(name: 'moderator').first.id + @approved_role_id = Role.where(name: 'group_approved').first.id + @pending_role_id = Role.where(name: 'group_pending_approval').first.id + @banned_role_id = Role.where(name: 'banned').first.id + end + + def join + @university_id = params[:id] + @user_id = current_user.id + if current_user.join_university_toggle @university_id + render_js + end + end + def unjoin + @university_id = params[:id] + @user_id = current_user.id + if current_user.join_university_toggle @university_id + render_js + end + end + def delete + @user = User.find(@user_id) + if @user.delete_university_user @university_id + render_js + end + end + def approve + if can_change_responsibility(@university_id,@user) + role_update("group_approved") + Notification.find_or_initialize_by(recipient: @user,actor: current_user,action: 'approved',notifiable: @university).update_attributes!(read_at: nil) + end + end + def make_moderator + if can_change_responsibility(@university_id,@user) + role_update("moderator") + Notification.find_or_initialize_by(recipient: @user,actor: current_user,action: 'promoted',notifiable: @university).update_attributes!(read_at: nil) + end + end + def demote_moderator + if can_change_responsibility(@university_id,@user) + role_update("group_approved") + end + end + def ban + if can_change_responsibility(@university_id,@user) + role_update("banned") + end + end + + private + def university_params + params.require(:university).permit(:name,:thumbnail_image,:timeline_image, :description) + end + def set_university + @university = University.find(params[:id]) + end + def set_university_id_and_user_id_and_user + @university_id = params[:id] + @university = University.find(@university_id) + @user_id = params[:user_id] + @user = User.find(@user_id) + end + + def administration_right + unless current_user.role.name =='admin' + redirect_for_invalid_activity + end + end + def moderation_right + unless is_responsible_user(@university_id,current_user) + redirect_for_invalid_activity + end + end + def is_responsible_user(university_id,user) + user.university_role_name(university_id) == 'moderator' or current_user.role.name =='admin' + end + def can_change_responsibility(university_id,user) + !is_responsible_user(university_id,user) or current_user.role.name =='admin' + end + def redirect_for_invalid_activity + flash[:alert] = "Only responsible person can accomplish such responsibility!" + redirect_to universities_path + end + def role_update(role_name) + if @user.university_role_update @university_id , role_name + render_js + else + redirect_for_invalid_activity + end + end + def render_js + respond_to do |format| + format.js + end + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..4961716 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,7 @@ +class UsersController < ApplicationController + before_action :authenticate_user! + def show + @posts = current_user.posts.order('created_at DESC').page params[:page] + @post = current_user.posts.build + end +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..8ef4f81 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,47 @@ +module ApplicationHelper + def alert_for(flash_type) + { + success: 'alert-success text-center', + error: 'alert-danger text-center', + alert: 'alert-warning text-center', + notice: 'alert-info text-center' + }[flash_type.to_sym] || flash_type.to_s + end + def current_user_is_following(current_user_id, followed_user_id) + relationship = Follow.find_by(follower_id: current_user_id, following_id: followed_user_id) + return true if relationship + end + + def form_image_select(post) + return image_tag post.attachment.url(:original), + id: 'image-preview', + class: 'img-responsive' if post.attachment.exists? + image_tag '', id: 'image-preview', class: 'img-responsive' + end + + def profile_avatar_select(user) + return image_tag user.avatar.url(:medium), + id: 'image-preview', + class: 'img-responsive img-circle profile-image' if user.avatar.exists? + image_tag 'default-avatar.jpg', id: 'image-preview', + class: 'img-responsive img-circle profile-image' + end + def post_avatar_select(user) + return image_tag user.avatar.url(:medium), + class: 'img-responsive post__avatar' if user.avatar.exists? + image_tag 'default-avatar.jpg',class: 'img-responsive post__avatar' + end + def comment_avatar_select(user) + return image_tag user.avatar.url(:medium), + class: 'img-responsive comment__avatar' if user.avatar.exists? + image_tag 'default-avatar.jpg',class: 'img-responsive comment__avatar' + end + def chat_avatar_select(user) + return image_tag user.avatar.url(:medium), + class: 'img-responsive chat__avatar' if user.avatar.exists? + image_tag 'default-avatar.jpg',class: 'img-responsive chat__avatar' + end + def online_status(user) + content_tag(:span, nil, class: "user-#{user.id} online_status #{'online' if user.online?}") +end +end \ No newline at end of file diff --git a/app/helpers/notification_helper.rb b/app/helpers/notification_helper.rb new file mode 100644 index 0000000..bb9207b --- /dev/null +++ b/app/helpers/notification_helper.rb @@ -0,0 +1,2 @@ +module NotificationHelper +end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb new file mode 100644 index 0000000..795d473 --- /dev/null +++ b/app/helpers/posts_helper.rb @@ -0,0 +1,47 @@ +module PostsHelper + def display_likes(post) + votes = post.votes_for.up.by_type(User) + return list_likers(votes) if votes.size <= 4 + count_likers(votes) + end + + def liked_post(post) + if current_user.voted_for? post + return link_to '', [:unlike,post.postable,post], remote: true, id: "like_#{post.id}", + class: "glyphicon glyphicon-heart" + else + link_to '', [:like,post.postable,post], remote: true, id: "like_#{post.id}", + class: "glyphicon glyphicon-heart-empty" + end + end + + def count_likers(votes) + vote_count = votes.size + vote_count.to_s + ' Likes' + end + + def count_comments(post) + counter=post.comments.count + "#{counter} Comments" if counter==1 + "#{counter} Comment" + end + + private + + def list_likers(votes) + user_name = [] + unless votes.blank? + votes.voters.each do |voter| + user_name.push(link_to voter.user_name, + profile_path(voter.user_name), + class: 'user-name') + end + user_name.to_sentence.html_safe + like_plural(votes) + end + end + + def like_plural(votes) + return ' likes this' if votes.count > 1 + ' like this' + end +end diff --git a/app/helpers/universities_helper.rb b/app/helpers/universities_helper.rb new file mode 100644 index 0000000..05358a4 --- /dev/null +++ b/app/helpers/universities_helper.rb @@ -0,0 +1,21 @@ +module UniversitiesHelper + def current_user_is_joined(current_user_id, university_id) + relationship = UniversityMembership.find_by(user_id: current_user_id, university_id: university_id) + return true if relationship + end + def moderation_links_and_power(post) + return current_user == post.user || current_user.role.name =='admin' || (current_user.is_univerisity_moderator(post.postable.id) && !post.user.is_univerisity_moderator(post.postable.id)) + end + def moderation_power(user,university) + if current_user.role.name == 'admin' + return true + end + if current_user.is_univerisity_moderator(university.id) && !user.is_univerisity_moderator(university.id) + return true + end + if !current_user.is_univerisity_moderator(university.id) + return false + end + return false + end +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000..a009ace --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/jobs/conversation_notification_job.rb b/app/jobs/conversation_notification_job.rb new file mode 100644 index 0000000..8a41cdf --- /dev/null +++ b/app/jobs/conversation_notification_job.rb @@ -0,0 +1,27 @@ +class ConversationNotificationJob < ApplicationJob + queue_as :default + + def perform(personal_message) + message = render_message(personal_message) + ActionCable.server.broadcast "conversation_notifications_#{personal_message.conversation.id}_channel", + message: message, + conversation_id: personal_message.conversation.id, + message_user_id: personal_message.user_id + + ActionCable.server.broadcast "conversation_notifications_#{personal_message.receiver.id}_channel", + # notification: render_notification(personal_message), + message: message, + conversation_id: personal_message.conversation.id + end + + private + + # def render_notification(message) + # NotificationsController.render partial: 'notifications/notification', locals: {message: message} + # end + + def render_message(message) + PersonalMessagesController.render partial: 'personal_messages/personal_message', + locals: {personal_message: message} + end +end diff --git a/app/jobs/message_broadcast_job.rb b/app/jobs/message_broadcast_job.rb new file mode 100644 index 0000000..fb57cd3 --- /dev/null +++ b/app/jobs/message_broadcast_job.rb @@ -0,0 +1,14 @@ +class MessageBroadcastJob < ApplicationJob + queue_as :default + + def perform(message) + ActionCable.server.broadcast "chat_rooms_#{message.chat_room.id}_channel", + message: render_message(message) + end + + private + + def render_message(message) + MessagesController.render partial: 'messages/message', locals: {message: message} + end +end \ No newline at end of file diff --git a/app/jobs/university_message_broadcast_job.rb b/app/jobs/university_message_broadcast_job.rb new file mode 100644 index 0000000..3a4b10d --- /dev/null +++ b/app/jobs/university_message_broadcast_job.rb @@ -0,0 +1,12 @@ +class UniversityMessageBroadcastJob < ApplicationJob + queue_as :default + + def perform(message) + ActionCable.server.broadcast "university_chats_#{message.university.id}_channel",message: render_message(message) + end + + private + def render_message(message) + UniversitiesController.render partial: 'universities/messages', locals: {message: message} + end +end \ No newline at end of file diff --git a/app/jobs/user_notifications_broadcast_job.rb b/app/jobs/user_notifications_broadcast_job.rb new file mode 100644 index 0000000..a95762f --- /dev/null +++ b/app/jobs/user_notifications_broadcast_job.rb @@ -0,0 +1,13 @@ +class UserNotificationsBroadcastJob < ApplicationJob + queue_as :default + + def perform(notification) + ActionCable.server.broadcast "user_notifications_#{notification.recipient_id}_channel",notify: true + #ActionCable.server.broadcast "user_notifications_#{notification.recipient_id}_channel",notification_type:notification.notifiable_type.underscore.pluralize,template: render_notifications(notification) + end + + private + def render_notifications(notification) + NotificationsController.render partial: "notifications/#{notification.notifiable_type.underscore.pluralize}/#{notification.action}", locals: {notification: notification} + end +end \ No newline at end of file diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..286b223 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/chat_room.rb b/app/models/chat_room.rb new file mode 100644 index 0000000..6382e34 --- /dev/null +++ b/app/models/chat_room.rb @@ -0,0 +1,4 @@ +class ChatRoom < ApplicationRecord + belongs_to :user + has_many :messages, dependent: :destroy +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..03fc03f --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,5 @@ +class Comment < ActiveRecord::Base + belongs_to :user + belongs_to :post + +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/conversation.rb b/app/models/conversation.rb new file mode 100644 index 0000000..6ddb676 --- /dev/null +++ b/app/models/conversation.rb @@ -0,0 +1,23 @@ +class Conversation < ApplicationRecord + belongs_to :author, class_name: 'User' + belongs_to :receiver, class_name: 'User' + + validates :author, uniqueness: {scope: :receiver} + has_many :personal_messages, -> { order(created_at: :asc) }, dependent: :destroy + + scope :participating, -> (user) do + where("(conversations.author_id = ? OR conversations.receiver_id = ?)", user.id, user.id) + end + + def with(current_user) + author == current_user ? receiver : author + end + + def participates?(user) + author == user || receiver == user + end + + scope :between, -> (sender_id, receiver_id) do + where(author_id: sender_id, receiver_id: receiver_id).or(where(author_id: receiver_id, receiver_id: sender_id)).limit(1) + end +end diff --git a/app/models/follow.rb b/app/models/follow.rb new file mode 100644 index 0000000..381ec34 --- /dev/null +++ b/app/models/follow.rb @@ -0,0 +1,4 @@ +class Follow < ActiveRecord::Base + belongs_to :follower, foreign_key: 'follower_id', class_name: 'User' + belongs_to :following, foreign_key: 'following_id', class_name: 'User' +end \ No newline at end of file diff --git a/app/models/message.rb b/app/models/message.rb new file mode 100644 index 0000000..f9d1888 --- /dev/null +++ b/app/models/message.rb @@ -0,0 +1,7 @@ +class Message < ApplicationRecord + belongs_to :user + belongs_to :chat_room + + validates :body, presence: true, length: {minimum: 2, maximum: 1000} + after_create_commit { MessageBroadcastJob.perform_later(self) } +end diff --git a/app/models/notification.rb b/app/models/notification.rb new file mode 100644 index 0000000..49f8b7f --- /dev/null +++ b/app/models/notification.rb @@ -0,0 +1,12 @@ +class Notification < ApplicationRecord + belongs_to :recipient , class_name: "User" + belongs_to :actor , class_name: "User" + belongs_to :notifiable , polymorphic: true + + scope :unread,->{where(read_at: nil)} + scope :recent,->{order(updated_at: :desc).limit(10)} + + after_commit do + UserNotificationsBroadcastJob.perform_later(self) + end +end diff --git a/app/models/personal_message.rb b/app/models/personal_message.rb new file mode 100644 index 0000000..32a59ba --- /dev/null +++ b/app/models/personal_message.rb @@ -0,0 +1,13 @@ +class PersonalMessage < ApplicationRecord + belongs_to :conversation + belongs_to :user + validates :body, presence: true + + has_attached_file :attachment + do_not_validate_attachment_file_type :attachment + + after_create_commit do + conversation.touch + ConversationNotificationJob.perform_later(self) + end +end diff --git a/app/models/post.rb b/app/models/post.rb new file mode 100644 index 0000000..53aa9d5 --- /dev/null +++ b/app/models/post.rb @@ -0,0 +1,24 @@ +class Post < ActiveRecord::Base + acts_as_votable + + belongs_to :postable,polymorphic: true + belongs_to :user + has_many :comments, dependent: :destroy + + validates :user_id, presence: true + validates :content, length: { minimum: 3, maximum: 300 } + + has_attached_file :attachment + do_not_validate_attachment_file_type :attachment + + scope :of_followed_users, -> (following_users) { where user_id: following_users } + + def is_pdf? + attachment.instance.attachment_content_type =~ %r(pdf) + end + + def is_image? + attachment.instance.attachment_content_type =~ %r(image) + end + +end diff --git a/app/models/role.rb b/app/models/role.rb new file mode 100644 index 0000000..4ec36e4 --- /dev/null +++ b/app/models/role.rb @@ -0,0 +1,3 @@ +class Role < ApplicationRecord + has_many :users +end diff --git a/app/models/university.rb b/app/models/university.rb new file mode 100644 index 0000000..9f643ee --- /dev/null +++ b/app/models/university.rb @@ -0,0 +1,19 @@ +class University < ApplicationRecord + validates :thumbnail_image, presence: true + validates :timeline_image, presence: true + validates :name, presence: true + validates :description, presence: true + + has_attached_file :thumbnail_image #, styles: { :small => "330x" } + has_attached_file :timeline_image #, styles: { :small => "330x" } + + validates_attachment_content_type :thumbnail_image, :content_type => /\Aimage\/.*\Z/ + validates_attachment_content_type :timeline_image, :content_type => /\Aimage\/.*\Z/ + + has_many :posts,as: :postable + + has_many :university_memberships + has_many :members,through: :university_memberships,source: :user + + has_many :university_message ,dependent: :destroy +end diff --git a/app/models/university_membership.rb b/app/models/university_membership.rb new file mode 100644 index 0000000..378da70 --- /dev/null +++ b/app/models/university_membership.rb @@ -0,0 +1,5 @@ +class UniversityMembership < ApplicationRecord + belongs_to :user + belongs_to :university + belongs_to :role +end diff --git a/app/models/university_message.rb b/app/models/university_message.rb new file mode 100644 index 0000000..7c0e753 --- /dev/null +++ b/app/models/university_message.rb @@ -0,0 +1,8 @@ +class UniversityMessage < ApplicationRecord + belongs_to :user + belongs_to :university + + validates :body, presence: true, length: {minimum: 2, maximum: 1000} + + after_create_commit { UniversityMessageBroadcastJob.perform_later(self) } +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..cbe7b41 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,111 @@ +class User < ActiveRecord::Base + before_create :set_default_role + acts_as_voter + + # Just For Devise + attr_accessor :login + + validates :user_name, :uniqueness => {:case_sensitive => false },length: { minimum: 2, maximum:50 } + validates_format_of :user_name, with: /^[a-zA-Z0-9_\.]*$/, :multiline => true + + + devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:login] + + def self.find_first_by_auth_conditions(warden_conditions) + conditions = warden_conditions.dup + if login = conditions.delete(:login) + where(conditions).where(["lower(user_name) = :value OR lower(email) = :value", { :value => login.downcase }]).first + else + if conditions[:user_name].nil? + where(conditions).first + else + where(user_name: conditions[:user_name]).first + end + end + end + + validates :first_name, :last_name ,:user_name ,:presence => true,length: { minimum: 2, maximum:50 } + + + has_many :posts,as: :postable, dependent: :destroy + has_many :comments, dependent: :destroy + + has_many :chat_rooms, dependent: :destroy + has_many :messages, dependent: :destroy + + has_many :authored_conversations, class_name: 'Conversation', foreign_key: 'author_id' + has_many :received_conversations, class_name: 'Conversation', foreign_key: 'received_id' + has_many :personal_messages, dependent: :destroy + + has_many :notifications,foreign_key: :recipient_id + + has_many :follower_relationships, foreign_key: :following_id, class_name: 'Follow' + has_many :followers, through: :follower_relationships, source: :follower + has_many :following_relationships, foreign_key: :follower_id, class_name: 'Follow' + has_many :following, through: :following_relationships, source: :following + + has_many :university_memberships + has_many :university_groups,through: :university_memberships + + has_many :university_messages ,dependent: :destroy + + belongs_to :role + + # For PaperClip Gem + has_attached_file :avatar, styles: { medium: '152x152#' } + validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/ + + def full_name + first_name + " " + last_name + end + + def follow(user_id) + following_relationships.create(following_id: user_id) + end + + def unfollow(user_id) + following_relationships.find_by(following_id: user_id).destroy + end + + def online? + !Redis.new.get("user_#{self.id}_online").nil? + end + def delete_university_user(university_id) + university_memberships.find_by(university_id: university_id).destroy + end + def join_university_toggle(university_id) + if(university_memberships.find_by(university_id: university_id)) + delete_university_user(university_id); + else + university_memberships.create(university_id: university_id,role_id: Role.where(name: 'group_pending_approval').first.id) + end + end + + def university_role_name(university_id) + rid = university_memberships.find_by(university_id: university_id) + if(rid.present?) + return rid.role.name + end + 'group_pending_approval' + end + def is_university_admin(university_id) + role.name == 'admin' or role.name == 'moderator' + end + def is_univerisity_moderator(university_id) + university_role_name(university_id) == 'moderator' or is_university_admin(university_id) + end + def is_university_approved(university_id) + is_univerisity_moderator(university_id) or university_role_name(university_id) == 'group_approved' + end + def university_role_update(university_id,role_name) + university_memberships.find_by(university_id: university_id).update(role_id: Role.where(name: role_name).first.id) + end + + scope :users_to_be_followed, ->(user) { where(following: user) } + scope :search_name, -> (name) { where("user_name like ?", "#{name}%")} + + private + def set_default_role + self.role ||= Role.find_by_name('registered') + end +end diff --git a/app/views/chat_rooms/_chat_room.html.haml b/app/views/chat_rooms/_chat_room.html.haml new file mode 100644 index 0000000..a7473da --- /dev/null +++ b/app/views/chat_rooms/_chat_room.html.haml @@ -0,0 +1,3 @@ +%li{:class => 'list-group-item'} + .text-center + = link_to "#{chat_room.title}", chat_room_path(chat_room) \ No newline at end of file diff --git a/app/views/chat_rooms/index.html.haml b/app/views/chat_rooms/index.html.haml new file mode 100644 index 0000000..6909313 --- /dev/null +++ b/app/views/chat_rooms/index.html.haml @@ -0,0 +1,17 @@ +.container + .row + .col-sm-4 + .chat_box.list-group + %li.list-group-item + .chat_box_heading Chat Room + %li.list-group-item + .text-center + = link_to 'New chat room', new_chat_room_path + %li + = render @chat_rooms + + .col-sm-8 + %article.post-wrapper + .post + .post-head + %p Join Chat Room To Start Sending Messages \ No newline at end of file diff --git a/app/views/chat_rooms/new.html.haml b/app/views/chat_rooms/new.html.haml new file mode 100644 index 0000000..7136eb5 --- /dev/null +++ b/app/views/chat_rooms/new.html.haml @@ -0,0 +1,11 @@ +.container + .row + .col-sm-8.col-offset-4 + %article.post-wrapper + .post + .post-head + %h4 Add a Chat Room + + = simple_form_for @chat_room do |f| + = f.input :title, autofocus: true, class: 'form-control' + = f.submit "Add!", class: 'btn btn-primary' \ No newline at end of file diff --git a/app/views/chat_rooms/show.html.haml b/app/views/chat_rooms/show.html.haml new file mode 100644 index 0000000..f5c3b89 --- /dev/null +++ b/app/views/chat_rooms/show.html.haml @@ -0,0 +1,24 @@ +.container + .row + .col-sm-4 + .chat_box.list-group + %li.list-group-item + .chat_box_heading Chat Room + %li.list-group-item + .text-center + = link_to 'New chat room', new_chat_room_path + %li + = render @chat_rooms + + .col-sm-8 + %article.post-wrapper + .post + .post-head + %h2= @chat_room.title + #messages{'data-chat-room-id' => @chat_room.id } + = render @chat_room.messages + + = simple_form_for @message, url: '#' do |f| + .form-group + = f.input :body, class: 'form-control',label: false,autofocus: true + = f.submit "Send Message", class: 'btn btn-success' \ No newline at end of file diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml new file mode 100644 index 0000000..edc695e --- /dev/null +++ b/app/views/comments/_comment.html.haml @@ -0,0 +1,13 @@ +.comment + - if comment.user == current_user || current_user.role.name == 'admin' + = link_to [postable,post,comment], method: :delete, data: {postable:post.postable_type.underscore.pluralize,postable_id:post.postable.id,post_id: post.id, value: post.comments.count, confirm: "Are you sure?" }, remote: true, id: "delete-#{comment.id}", class: "delete-comment" do + %span(class="glyphicon glyphicon-remove delete-comment-icon") + .comment-user-thumnail + = comment_avatar_select(comment.user) + .comment-user-name + = link_to comment.user.full_name, profile_path(comment.user.user_name) + %span.time-ago + = time_ago_in_words comment.created_at + ago + .comment-content + = comment.content \ No newline at end of file diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb new file mode 100644 index 0000000..15b9e75 --- /dev/null +++ b/app/views/comments/create.js.erb @@ -0,0 +1,14 @@ +$('#comment_content_<%= @post.id %>').val('') +$('#comment_content_<%= @post.id %>').blur(); +Append.comment_count += 1 +$(Append.id).attr('data-value', Append.comment_count); + +if (Append.comment || Append.open ){ + $('#comments_<%= @post.id %>').prepend("<%=j render 'comments/comment', postable:@post.postable,post: @post, comment: @comment %>"); +} +else if ((Append.comment && Append.open) === false && Append.link === true) { + $('#comments_' + Append.post_id).append("
    View all " + Append.comment_count + " comments
    "); + ClickableCommentsLink(); +} + +else if ((Append.comment && Append.open && Append.link) === false) { $('#more_comments_<%= @post.id %>').html("View all <%= @post.comments.count %> comments"); } \ No newline at end of file diff --git a/app/views/comments/destroy.js.erb b/app/views/comments/destroy.js.erb new file mode 100644 index 0000000..4910c08 --- /dev/null +++ b/app/views/comments/destroy.js.erb @@ -0,0 +1,2 @@ +$('#comments_<%= @post.id %>').html("<%= j render @post.comments, post: @post, comment: @comment %>"); +Append.comment_count -= 1 \ No newline at end of file diff --git a/app/views/comments/index.html.haml b/app/views/comments/index.html.haml new file mode 100644 index 0000000..2e7fc4b --- /dev/null +++ b/app/views/comments/index.html.haml @@ -0,0 +1 @@ += render @comments, post: @post,postable: @postable diff --git a/app/views/conversations/_conversation.html.haml b/app/views/conversations/_conversation.html.haml new file mode 100644 index 0000000..8805718 --- /dev/null +++ b/app/views/conversations/_conversation.html.haml @@ -0,0 +1,10 @@ +%div{:class => 'conversation_list_item'} + = link_to conversation_path(conversation) do + .conversation_list_item__image + = post_avatar_select(current_user) + .conversation_list_item__text + = link_to conversation.with(current_user).user_name,profile_path(conversation.with(current_user)) + %br + .conversation_list_item__message + = conversation.personal_messages.last.body.truncate(50) + %div{style: 'clear:both'} diff --git a/app/views/conversations/_personal_message.html.haml b/app/views/conversations/_personal_message.html.haml new file mode 100644 index 0000000..aa825e5 --- /dev/null +++ b/app/views/conversations/_personal_message.html.haml @@ -0,0 +1,8 @@ +%p= personal_message.body +%p + at + %strong= personal_message.created_at + %br/ + by + %strong= personal_message.user.user_name +%hr/ diff --git a/app/views/conversations/index.html.haml b/app/views/conversations/index.html.haml new file mode 100644 index 0000000..924ac69 --- /dev/null +++ b/app/views/conversations/index.html.haml @@ -0,0 +1,14 @@ +.container + .row + .col-sm-4 + .conversation_box.list-group + %li.list-group-item + .chat_box_heading Conversations + %li + = render @conversations + + .col-sm-8 + %article.post-wrapper + .post + .post-head + %p Click on left to any conversation to chat \ No newline at end of file diff --git a/app/views/conversations/show.html.haml b/app/views/conversations/show.html.haml new file mode 100644 index 0000000..4cb17e5 --- /dev/null +++ b/app/views/conversations/show.html.haml @@ -0,0 +1,24 @@ +%header.chatboxhead + .chatboxtitle + = @conversation.with(current_user).user_name + .chatboxoptions + = link_to " ".html_safe, "#", class: "toggleChatBox", "data-cid" => @conversation.id + = link_to " ".html_safe, "#", class: "closeChat", "data-cid" => @conversation.id + + %br{:clear => "all"} + +.chatboxcontent + - if @conversation.personal_messages.any? + = render @conversation.personal_messages.order(created_at: :asc).reverse_order().limit(100) +.chatboxinput + = form_for([@personal_message], :html => {id: "conversation_form_#{@conversation.id}"}) do |f| + = hidden_field_tag 'conversation_id', @conversation.id,class: 'conversation_id' + = f.text_area :body, class: 'chatboxtextarea',label: false,autofocus: true ,"data-cid" => @conversation.id + + = simple_form_for([@personal_message], remote: true,:html => {multipart: true,id: "conversation_attachment_form_#{@conversation.id}"}) do |f| + = hidden_field_tag 'conversation_id', @conversation.id,class: 'conversation_id' + = hidden_field_tag 'personal_message[body]', "Uploaded File" + .personal_message_attachment + %span{class: "personal_attachment_upload glyphicon glyphicon-upload"} + = f.input :attachment,label: false,wrapper: false + %div{style: {clear: 'both'}} \ No newline at end of file diff --git a/app/views/dashboard/_search_form.html.haml b/app/views/dashboard/_search_form.html.haml new file mode 100644 index 0000000..6dc9aa6 --- /dev/null +++ b/app/views/dashboard/_search_form.html.haml @@ -0,0 +1,5 @@ += form_tag("/search", method: "get",class: 'form-inline search-form') do + .form-group + = text_field_tag :username,nil, placeholder:"Search Username", class: 'form-control' + = button_tag(type: 'submit', id: "search-button", class: "btn btn-primary") do + %span{class: 'glyphicon glyphicon-search'} \ No newline at end of file diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml new file mode 100644 index 0000000..093d155 --- /dev/null +++ b/app/views/dashboard/index.html.haml @@ -0,0 +1,14 @@ +.container + .row + .col-sm-8 + %main#posts + = render 'layouts/follower_suggestion',currently_logged_in_user: current_user + .post-wrapper + .post + .padding20 + = render 'posts/form',post: @post,postable: current_user + = render 'posts/posts',posts: @posts,postable: current_user + #paginator.text-center + = link_to_next_page @posts, 'Load More', remote: true, id: 'load_more' + .col-sm-4 + = render 'layouts/chat_box',followed_user: @followed_user \ No newline at end of file diff --git a/app/views/dashboard/index.js.erb b/app/views/dashboard/index.js.erb new file mode 100644 index 0000000..6a8b4b9 --- /dev/null +++ b/app/views/dashboard/index.js.erb @@ -0,0 +1,3 @@ +$('#posts').append("<%= escape_javascript(render 'posts/posts',posts:@posts,postable: current_user)%>"); +$('#paginator').html("<%= escape_javascript(link_to_next_page(@posts, 'LOAD MORE', remote: true, id: 'load_more'))%>"); +if (!$('#load_more').length) { $('#paginator').remove(); } \ No newline at end of file diff --git a/app/views/dashboard/search.html.haml b/app/views/dashboard/search.html.haml new file mode 100644 index 0000000..cb74849 --- /dev/null +++ b/app/views/dashboard/search.html.haml @@ -0,0 +1,19 @@ +.post-wrapper + .user_listings + -@result.where.not(id: current_user.id).each do |user| + .user + .user_head + = link_to 'Message', '#' ,class: 'start-conversation btn btn-danger follow-button flat__buttons',"data-sid" => current_user.id, "data-rip" => user.id + = render 'profiles/follow_and_unfollow_button' , :user => user + .user_avatar + = post_avatar_select(user) + .user_username + = link_to user.user_name , profile_path(user.user_name) + .user_fullname + = user.full_name + .clear + .user_bio + = user.bio + -if(@result.blank?) + %p No result found + %p Try searching more :) \ No newline at end of file diff --git a/app/views/devise/confirmations/new.html.haml b/app/views/devise/confirmations/new.html.haml new file mode 100644 index 0000000..a915412 --- /dev/null +++ b/app/views/devise/confirmations/new.html.haml @@ -0,0 +1,15 @@ +.registration-bg + .container + .row + .col-md-4.col-md-offset-8 + .log-in.panel + .panel-heading + %h2 Resend confirmation instructions + = simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| + = f.error_notification + = f.full_error :confirmation_token + .form-inputs + = f.input :email, required: true, autofocus: true + .form-actions + = f.button :submit, "Resend confirmation instructions" + = render "devise/shared/links" diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb new file mode 100644 index 0000000..ae24ad6 --- /dev/null +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -0,0 +1,6 @@ +

    <%= t('.greeting', recipient: @resource.email, default: "Welcome #{@resource.email}!") %>

    + +

    <%= t('.instruction', default: 'You can confirm your account email through the link below:') %>

    + +

    <%= link_to t('.action', default: 'Confirm my account'), + confirmation_url(@resource, confirmation_token: @token, locale: I18n.locale) %>

    diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..f757e10 --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

    <%= t('.greeting', recipient: @resource.email, default: "Hello #{@resource.email}!") %>

    + +

    <%= t('.instruction', default: 'Someone has requested a link to change your password, and you can do this through the link below.') %>

    + +

    <%= link_to t('.action', default: 'Change my password'), edit_password_url(@resource, reset_password_token: @token, locale: I18n.locale) %>

    + +

    <%= t('.instruction_2', default: "If you didn't request this, please ignore this email.") %>

    +

    <%= t('.instruction_3', default: "Your password won't change until you access the link above and create a new one.") %>

    diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..98e723d --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

    <%= t('.greeting', recipient: @resource.email, default: "Hello #{@resource.email}!") %>

    + +

    <%= t('.message', default: 'Your account has been locked due to an excessive amount of unsuccessful sign in attempts.') %>

    + +

    <%= t('.instruction', default: 'Click the link below to unlock your account:') %>

    + +

    <%= link_to t('.action', default: 'Unlock my account'), unlock_url(@resource, unlock_token: @resource.unlock_token, locale: I18n.locale) %>

    diff --git a/app/views/devise/passwords/edit.html.haml b/app/views/devise/passwords/edit.html.haml new file mode 100644 index 0000000..f2336ee --- /dev/null +++ b/app/views/devise/passwords/edit.html.haml @@ -0,0 +1,17 @@ +.registration-bg + .container + .row + .col-md-4.col-md-offset-8 + .log-in.panel + .panel-heading + %h2 Change your password + = simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| + = f.input :reset_password_token, as: :hidden + = f.full_error :reset_password_token + = devise_error_messages! + .form-inputs + = f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) + = f.input :password_confirmation, label: "Confirm your new password", required: true + .form-actions + = f.button :submit, "Change my password" + = render "devise/shared/links" diff --git a/app/views/devise/passwords/new.html.haml b/app/views/devise/passwords/new.html.haml new file mode 100644 index 0000000..8e6f14c --- /dev/null +++ b/app/views/devise/passwords/new.html.haml @@ -0,0 +1,22 @@ +.registration-bg + .container + .row + .col-md-4.col-md-offset-8 + .log-in.panel + .panel-heading + %h2 Forgot your password? + = simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| + = f.error_notification + = devise_error_messages! + .panel-body + .form-inputs + = f.input :user_name, required: true, autofocus: true + .form-actions + = f.button :submit, "Send me reset password instructions" + %hr + = render "devise/shared/links" + %br + %hr + %p We will send you a link to reset password. + %p Please check in spam folder if you didn't get any emails from us. + %p If you still don't get email then please contact us. diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml new file mode 100644 index 0000000..ec2deef --- /dev/null +++ b/app/views/devise/registrations/edit.html.haml @@ -0,0 +1,30 @@ +.post-wrapper + .post + .post-body + .container-fluid + %h4 Edit Basic Info + %hr + = simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| + = f.error_notification + .form-inputs + = f.input :email, required: true, autofocus: true + = f.input :user_name, required: true + = f.input :first_name, required: true + = f.input :last_name, required: true + + = f.check_box :is_female, {}, false + = f.label :is_female, "Male" + + = f.check_box :is_female, {}, true + = f.label :is_female, "Female" + + + - if devise_mapping.confirmable? && resource.pending_reconfirmation? + %p + Currently waiting confirmation for: #{resource.unconfirmed_email} + = f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false + = f.input :password_confirmation, required: false + = f.input :current_password, hint: "we need your current password to confirm your changes", required: true + .form-actions + = f.button :submit, "Update" + = link_to "Back", :back, class: 'btn btn-primary' diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml new file mode 100644 index 0000000..c2bcae7 --- /dev/null +++ b/app/views/devise/registrations/new.html.haml @@ -0,0 +1,29 @@ +.registration-bg + .container + .row + .col-md-4.col-md-offset-8 + .log-in.panel + .panel-heading + %h4 Create Your Account + = simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| + = f.error_notification + .panel-body + = f.input :email, required: true, autofocus: true, label: false, placeholder: 'Email' + = f.input :user_name, required: true, label: false, placeholder: 'User Name' + = f.input :first_name, required: true, label: false, placeholder: 'First Name' + = f.input :last_name, required: true, label: false, placeholder: 'Last Name' + + = f.input :password, required: true, label: false, placeholder: 'Password' + = f.input :password_confirmation, required: true, label: false, placeholder: 'Confirm Password' + + = f.check_box :is_female, {}, false + = f.label :is_female, "Male" + + = f.check_box :is_female, {}, true + = f.label :is_female, "Female" + + + + = f.button :submit, "Sign up", class: 'btn-info btn-block' + + %p After Registering You will need to confirm your account . Check Your Email Please diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml new file mode 100644 index 0000000..99abcab --- /dev/null +++ b/app/views/devise/sessions/new.html.haml @@ -0,0 +1,24 @@ +.login-bg + .container + .row + .col-md-4.col-md-offset-8 + .log-in.panel + .panel-heading + %h4 Log in + %hr + = simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| + = f.error_notification + .panel-body + = f.input :login, required: true, autofocus: true, label: false, placeholder: 'User Name' + = f.input :password, required: true, label: false, placeholder: 'Password' + = f.input :remember_me, as: :boolean if devise_mapping.rememberable? + = f.button :submit, "Log in", class: 'btn-lg btn-info btn-block' + + -if devise_mapping.recoverable? + = link_to "Forgot your password?", new_password_path(resource_name),class: 'btn btn-danger' + -if devise_mapping.recoverable? + = link_to "Sign up", new_registration_path(resource_name),class: 'btn btn-success' + + %div{style: 'clear:both'} + + %br diff --git a/app/views/devise/shared/_links.html.haml b/app/views/devise/shared/_links.html.haml new file mode 100644 index 0000000..4aa61c8 --- /dev/null +++ b/app/views/devise/shared/_links.html.haml @@ -0,0 +1,18 @@ +- if controller_name != 'sessions' + = link_to "Log in", new_session_path(resource_name),class:'btn btn-primary' + +- if devise_mapping.registerable? && controller_name != 'registrations' + = link_to "Sign up", new_registration_path(resource_name),class:'btn btn-success' + +- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' + = link_to "Forgot your password?", new_password_path(resource_name),class:'btn btn-alert' + +- if devise_mapping.confirmable? && controller_name != 'confirmations' + = link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name),class:'btn btn-info' + +- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' + = link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name),class:'btn btn-warning' + +- if devise_mapping.omniauthable? + - resource_class.omniauth_providers.each do |provider| + = link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider),class:'btn btn-alert' \ No newline at end of file diff --git a/app/views/devise/unlocks/new.html.haml b/app/views/devise/unlocks/new.html.haml new file mode 100644 index 0000000..b33139d --- /dev/null +++ b/app/views/devise/unlocks/new.html.haml @@ -0,0 +1,16 @@ +.registration-bg + .container + .row + .col-md-4.col-md-offset-8 + .log-in.panel + .panel-heading + %h4 Resend unlock instructions + = simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| + = f.error_notification + .panel-body + = f.full_error :unlock_token + .form-inputs + = f.input :email, required: true, autofocus: true + .form-actions + = f.button :submit, "Resend unlock instructions" + = render "devise/shared/links" diff --git a/app/views/layouts/_chat_box.html.haml b/app/views/layouts/_chat_box.html.haml new file mode 100644 index 0000000..fd092e6 --- /dev/null +++ b/app/views/layouts/_chat_box.html.haml @@ -0,0 +1,14 @@ +.chat_box.list-group + %li.list-group-item + .chat_box_heading Online Chat + %li.list-group-item + .text-center + =link_to "Follow Other User to Chat",all_users_path + - current_user.following.each do |user| + %li.list-group-item + =link_to "#", class: "start-conversation","data-sid" => current_user.id, "data-rip" => user.id do + .chat_avatar + = chat_avatar_select(user) + = user.full_name + .user_online_block + = online_status user \ No newline at end of file diff --git a/app/views/layouts/_follower_suggestion.html.haml b/app/views/layouts/_follower_suggestion.html.haml new file mode 100644 index 0000000..4bd8705 --- /dev/null +++ b/app/views/layouts/_follower_suggestion.html.haml @@ -0,0 +1,22 @@ +.post-wrapper + .post + .suggestion_box_heading + You may want to follow + .sugesstion_box_show_all.pull-right + = link_to "See All >" , all_users_path + .clear + %ul.suggestion_box_main + - ids = currently_logged_in_user.following.pluck(:id) + - if User.where.not(id: ids).where.not(id: currently_logged_in_user.id).limit(5).offset(rand(User.count)).each do|user| + %li + = render 'profiles/follow_and_unfollow_button' , :user => user + .user_info + = chat_avatar_select(user) + .suggestion_box_name + .suggestion_box_user_name + = user.user_name + .suggestion_box_full_name + = user.full_name + .clear + - end.empty? + %li You can check All users if you wanna follow someone :) diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml new file mode 100644 index 0000000..ad7f89a --- /dev/null +++ b/app/views/layouts/_footer.html.haml @@ -0,0 +1,2 @@ +%footer.container-fluid.text-center.copyright-part + %p © Chat Ounce 2017. All rights reserved. Yes, all of them. \ No newline at end of file diff --git a/app/views/layouts/_form_error.html.haml b/app/views/layouts/_form_error.html.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml new file mode 100644 index 0000000..cfe05e0 --- /dev/null +++ b/app/views/layouts/_navbar.html.haml @@ -0,0 +1,30 @@ +%nav.navbar.navbar-default + .navbar-header + %button.navbar-toggle.collapsed{"data-target" => "#bs-navbar-collapse-1", "data-toggle" => "collapse", type: "button"} + %span.sr-only Toggle Navigation + %span.icon-bar + %span.icon-bar + = link_to "Chat Ounce", root_path , class: 'navbar-brand' + - if user_signed_in? + = link_to current_user.full_name, profile_path(current_user.user_name), class: 'navigation_box' + = render 'dashboard/search_form' + + .collapse.navbar-collapse#bs-navbar-collapse-1 + %ul.nav.navbar-nav.navbar-right + - if user_signed_in? + %li + = link_to "University", universities_path, class: 'navigation_box' + %li + = render 'notifications/notifications_dropdown' + %li + = render 'notifications/mesages_notifications_dropdown' + %li + = link_to "All Users", all_users_path, class: 'navigation_box' + %li + = link_to "Public Chat Room", chat_rooms_path, class: 'navigation_box' + %li + = link_to edit_profile_path(current_user.user_name), class: 'navigation_box' do + %span{class:'glyphicon glyphicon-cog colorb'} + %li + = link_to destroy_user_session_path, method: :delete, class: 'navigation_box' do + %span{class:'glyphicon glyphicon-off colorr'} \ No newline at end of file diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 0000000..11700bc --- /dev/null +++ b/app/views/layouts/application.html.haml @@ -0,0 +1,25 @@ +%html + %head + + %title Chat Ounce + + %meta{:charset => "utf-8"} + %meta{"http-equiv" => "X-UA-Compatible", :content => "IE=edge"} + %meta{:name => "viewport", :content => "width=device-width, initial-scale=1"} + %meta{:content => user_signed_in? ? current_user.id : "",:name=>'user-id'} + + = stylesheet_link_tag 'application', media: 'all' + + = javascript_include_tag 'application' + + = csrf_meta_tags + + %body + = render 'layouts/navbar' + + -flash.each do |name, msg| + = content_tag :div, msg, class: [:alert, alert_for(name)] + + = yield + + = render 'layouts/footer' \ No newline at end of file diff --git a/app/views/messages/_message.html.haml b/app/views/messages/_message.html.haml new file mode 100644 index 0000000..b3bdf95 --- /dev/null +++ b/app/views/messages/_message.html.haml @@ -0,0 +1,13 @@ +.card + .card-block + .row + .col-md-1 + = post_avatar_select message.user + .col-md-11 + %p.card-text + %span.text-muted + = message.user.user_name + #{time_ago_in_words(message.created_at)} ago says + + %br + = message.body \ No newline at end of file diff --git a/app/views/notifications/_mesages_notifications_dropdown.html.haml b/app/views/notifications/_mesages_notifications_dropdown.html.haml new file mode 100644 index 0000000..3eaf34b --- /dev/null +++ b/app/views/notifications/_mesages_notifications_dropdown.html.haml @@ -0,0 +1,5 @@ +.dropdown.notification-dropdown{data: {behaviour: 'message-notifications'}} + %button.btn.btn-default.navbar__buttons.dropdown-toggle{ type: 'button', id: 'dropdownMenu1', data: { toggle: 'dropdown' }, 'aria-haspopup'=> true, 'aria-expanded'=> true } + %span{class: 'message-notifications-count',data: {behaviour: 'message-notifications-count'}} + %span.glyphicon.glyphicon-envelope.colorb + %ul.dropdown-menu{ 'aria-labelledby'=> 'dropdownMenu1', data: {behaviour: 'message-notifications-item'}} \ No newline at end of file diff --git a/app/views/notifications/_notifications_dropdown.html.haml b/app/views/notifications/_notifications_dropdown.html.haml new file mode 100644 index 0000000..6be9a14 --- /dev/null +++ b/app/views/notifications/_notifications_dropdown.html.haml @@ -0,0 +1,5 @@ +.dropdown.notification-dropdown{data: {behaviour: 'notifications'}} + %button.btn.btn-default.navbar__buttons.dropdown-toggle{ type: 'button', id: 'dropdownMenu1', data: { toggle: 'dropdown' }, 'aria-haspopup'=> true, 'aria-expanded'=> true } + %span{class: 'notifications-count', data: {behaviour: 'notifications-count'}} + %span.glyphicon.glyphicon-bell.colorb + %ul.dropdown-menu{ 'aria-labelledby'=> 'dropdownMenu1',data: {behaviour: 'notifications-item'}} diff --git a/app/views/notifications/conversations/_messaged.html.haml b/app/views/notifications/conversations/_messaged.html.haml new file mode 100644 index 0000000..d77b248 --- /dev/null +++ b/app/views/notifications/conversations/_messaged.html.haml @@ -0,0 +1,3 @@ +%li{class: "#{"notification-unread" if !notification.read_at?}"} + = link_to '#',"data-sid" => notification.notifiable.author_id, "data-rip" => notification.notifiable.receiver_id,class: 'dropdown-item start-conversation' do + = "#{notification.actor.full_name} messaged you at #{time_ago_in_words(notification.created_at)} ago" \ No newline at end of file diff --git a/app/views/notifications/index.json.jbuilder b/app/views/notifications/index.json.jbuilder new file mode 100644 index 0000000..0f12635 --- /dev/null +++ b/app/views/notifications/index.json.jbuilder @@ -0,0 +1,6 @@ +json.array! @notifications do |notification| + json.id notification.id + json.type notification.notifiable_type.underscore.pluralize + json.unread !notification.read_at? + json.template render partial: "notifications/#{notification.notifiable_type.underscore.pluralize}/#{notification.action}",locals: {notification: notification}, formats: [:html] +end \ No newline at end of file diff --git a/app/views/notifications/posts/_commented.html.haml b/app/views/notifications/posts/_commented.html.haml new file mode 100644 index 0000000..331d573 --- /dev/null +++ b/app/views/notifications/posts/_commented.html.haml @@ -0,0 +1,3 @@ +%li{class: "#{"notification-unread" if !notification.read_at?}"} + = link_to [notification.notifiable.postable,notification.notifiable],class: 'dropdown-item' do + = "#{notification.actor.full_name} #{notification.action} on #{notification.notifiable_type.underscore.humanize.downcase}" \ No newline at end of file diff --git a/app/views/notifications/posts/_liked.html.haml b/app/views/notifications/posts/_liked.html.haml new file mode 100644 index 0000000..97438f8 --- /dev/null +++ b/app/views/notifications/posts/_liked.html.haml @@ -0,0 +1,3 @@ +%li{class: "#{"notification-unread" if !notification.read_at?}"} + = link_to [notification.notifiable.postable,notification.notifiable],class: 'dropdown-item' do + = "#{notification.actor.full_name} likes your post" \ No newline at end of file diff --git a/app/views/notifications/universities/_approved.html.haml b/app/views/notifications/universities/_approved.html.haml new file mode 100644 index 0000000..01667d4 --- /dev/null +++ b/app/views/notifications/universities/_approved.html.haml @@ -0,0 +1,3 @@ +%li{class: "#{"notification-unread" if !notification.read_at?}"} + = link_to [notification.notifiable],class: 'dropdown-item' do + = "#{notification.actor.full_name} approved you at #{notification.notifiable.name} university" \ No newline at end of file diff --git a/app/views/notifications/universities/_promoted.html.haml b/app/views/notifications/universities/_promoted.html.haml new file mode 100644 index 0000000..67c7089 --- /dev/null +++ b/app/views/notifications/universities/_promoted.html.haml @@ -0,0 +1,3 @@ +%li{class: "#{"notification-unread" if !notification.read_at?}"} + = link_to [notification.notifiable],class: 'dropdown-item' do + = "#{notification.actor.full_name} promoted you to moderator #{notification.notifiable.name} university" \ No newline at end of file diff --git a/app/views/notifications/users/_followed.html.haml b/app/views/notifications/users/_followed.html.haml new file mode 100644 index 0000000..4823dde --- /dev/null +++ b/app/views/notifications/users/_followed.html.haml @@ -0,0 +1,3 @@ +%li{class: "#{"notification-unread" if !notification.read_at?}"} + = link_to profile_path(notification.notifiable.user_name),class: 'dropdown-item' do + = "#{notification.actor.full_name} is following you at #{time_ago_in_words(notification.created_at)} ago" \ No newline at end of file diff --git a/app/views/personal_messages/_personal_message.html.haml b/app/views/personal_messages/_personal_message.html.haml new file mode 100644 index 0000000..bd81459 --- /dev/null +++ b/app/views/personal_messages/_personal_message.html.haml @@ -0,0 +1,15 @@ +%li{class: personal_message.user_id == personal_message.conversation.author_id ? "self" : "other"} + .avatar + = chat_avatar_select(personal_message.user) + .chatboxmessagecontent + %p= personal_message.body + - if personal_message.attachment.exists? + - if !(personal_message.attachment.content_type =~ /^image/).nil? + = link_to (image_tag (personal_message.attachment.url), class:'img-responsive'),personal_message.attachment.url,target: '_blank' + - else + = link_to personal_message.attachment.instance.attachment_file_name,personal_message.attachment.url + + %time{:datetime => "#{personal_message.created_at}", :title => "#{personal_message.created_at.strftime("%d %b %Y at %I:%M%p")}"} + = personal_message.user.user_name + = personal_message.created_at.strftime("%H:%M %p") + diff --git a/app/views/personal_messages/new.html.haml b/app/views/personal_messages/new.html.haml new file mode 100644 index 0000000..5f8b672 --- /dev/null +++ b/app/views/personal_messages/new.html.haml @@ -0,0 +1,7 @@ +%h1 + New message to #{@receiver.user_name} += form_for @personal_message do |f| + = hidden_field_tag 'receiver_id', @receiver.id + = f.label :body + = f.text_area :body + = f.submit diff --git a/app/views/posts/_form.html.haml b/app/views/posts/_form.html.haml new file mode 100644 index 0000000..577877a --- /dev/null +++ b/app/views/posts/_form.html.haml @@ -0,0 +1,17 @@ +- if post.errors.any? + #error_explanation + %h4 + = pluralize(post.errors.count, "error") + prohibited this post from being saved: + %ul + - post.errors.full_messages.each do |message| + %li= message + += simple_form_for [postable,post], html: { multipart: true } do |f| + = f.input :content, label: false, placeholder: 'Write your feelings...', input_html: { rows: 2 } + %label{class: 'btn btn-default btn-file'} + %span{class: 'glyphicon glyphicon-share'} + Upload + = f.input :attachment, label: false,wrapper: false,input_html: { onChange: 'loadFile(event)' } + = f.button :submit, class: 'btn-success' += form_image_select(post) \ No newline at end of file diff --git a/app/views/posts/_likes.html.haml b/app/views/posts/_likes.html.haml new file mode 100644 index 0000000..4f9fb7a --- /dev/null +++ b/app/views/posts/_likes.html.haml @@ -0,0 +1,2 @@ +.likes{id: "likes_#{post.id}"} + = display_likes post diff --git a/app/views/posts/_post.html.haml b/app/views/posts/_post.html.haml new file mode 100644 index 0000000..9eb319f --- /dev/null +++ b/app/views/posts/_post.html.haml @@ -0,0 +1,58 @@ +%article.post-wrapper + .post + .post-head + .post-user-thumbnail + = post_avatar_select(post.user) + .post-user-name + = link_to post.user.full_name, profile_path(post.user.user_name) + posted a new status + .time-ago + = time_ago_in_words post.created_at + ago + .clear + .attachment + .attachment-content + = post.content + .clear + .image.center-block + - if post.attachment.exists? + - if !(post.attachment.content_type =~ /^image/).nil? + .attachment-image + = image_tag (URI(request.url) + post.attachment.url), class:'img-responsive post__image' + - else + .attachment-info + File Name : + = post.attachment.instance.attachment_file_name + File Size (KB) : + = post.attachment.instance.attachment_file_size/1000 + + .attachment-files + = link_to "Download","#{URI(request.url) + post.attachment.url}", class: "btn btn-success" + + .view_post_bottom + = count_likers post.votes_for.up.by_type(User) + %span{class:'comment_counter'} + = count_comments post + = render 'posts/post_modifier_link',post: post + .post-bottom + = render 'posts/likes', post: post + + .comments{id: "comments_#{post.id}"} + - if post.comments.any? + = render post.comments.order('created_at asc').first(4), {post: post,postable:postable} + - unless post.comments.count <= 4 + .paginator{id: "#comments-paginator-#{post.id}"} + =link_to "View all #{post.comments.count} comments",[postable,post,:comments], remote: true, class: 'more-comments', id: "more_comments_#{post.id}", data: {post_id: "#{post.id}", type: "html", value: "#{post.comments.count}"} + - else + %p No comments + .comment-like-form.row + .like-button.col-xs-1 + =liked_post post + .comment-form.col-xs-11 + = form_for([postable,post, post.comments.build], remote: true) do |f| + = f.text_field :content, placeholder: 'Add a comment...', + class: "comment_content", + id: "comment_content_#{post.id}", + data: { post_id: "#{post.id}",'postable-type': "#{post.postable_type.underscore.pluralize}",'postable-id': "#{post.postable_id}", + value: "#{post.comments.count}" } + = f.submit 'New Comment', class: 'comment-submit-button' diff --git a/app/views/posts/_post_modifier_link.html.haml b/app/views/posts/_post_modifier_link.html.haml new file mode 100644 index 0000000..c0d2c89 --- /dev/null +++ b/app/views/posts/_post_modifier_link.html.haml @@ -0,0 +1,8 @@ +- if post.postable_type == 'University' + - if moderation_links_and_power(post) + = link_to "Edit Post", [:edit,post.postable,post] + = link_to "Delete Post", [post.postable,post], method: :delete, data: { confirm: "Are you sure you want to delete others post?" } +- else + -if post.user.id == current_user.id || current_user.role.name == 'admin' + = link_to "Edit Post", [:edit,post.postable,post] + = link_to "Delete Post", [post.postable,post], method: :delete, data: { confirm: "Are you sure you want to delete this post?" } \ No newline at end of file diff --git a/app/views/posts/_posts.html.haml b/app/views/posts/_posts.html.haml new file mode 100644 index 0000000..fdf0154 --- /dev/null +++ b/app/views/posts/_posts.html.haml @@ -0,0 +1 @@ += render posts,postable: postable \ No newline at end of file diff --git a/app/views/posts/edit.html.haml b/app/views/posts/edit.html.haml new file mode 100644 index 0000000..5b19678 --- /dev/null +++ b/app/views/posts/edit.html.haml @@ -0,0 +1,6 @@ +.post-wrapper + .post + .form-body + = render 'form',post: @post,postable:@postable + .text-center.edit-links + = link_to "Cancel", root_path,class: 'btn btn-primary' diff --git a/app/views/posts/like.js.erb b/app/views/posts/like.js.erb new file mode 100644 index 0000000..b24e2e8 --- /dev/null +++ b/app/views/posts/like.js.erb @@ -0,0 +1,3 @@ +$("#like_<%= @post.id %>").removeClass('glyphicon-heart-empty').addClass('glyphicon-heart'); +$("#like_<%= @post.id %>").removeAttr('href').attr('href', '<%= @post.postable_type.downcase.pluralize %>/<%= @post.postable.id %>/posts/<%= @post.id %>/unlike'); +$("#likes_<%= @post.id %>").html("<%= j (render partial: 'posts/likes', locals: { post: @post} ) %>"); \ No newline at end of file diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml new file mode 100644 index 0000000..240182a --- /dev/null +++ b/app/views/posts/show.html.haml @@ -0,0 +1 @@ += render 'post', post: @post,postable: @postable \ No newline at end of file diff --git a/app/views/posts/unlike.js.erb b/app/views/posts/unlike.js.erb new file mode 100644 index 0000000..f699fba --- /dev/null +++ b/app/views/posts/unlike.js.erb @@ -0,0 +1,3 @@ +$("#like_<%= @post.id %>").removeClass('glyphicon-heart').addClass('glyphicon-heart-empty'); +$("#like_<%= @post.id %>").removeAttr('href').attr('href', '<%= @post.postable_type.downcase.pluralize %>/<%= @post.postable.id %>/posts/<%= @post.id %>/like'); +$("#likes_<%= @post.id %>").html("<%= j (render partial: 'posts/likes', locals: { post: @post} ) %>"); \ No newline at end of file diff --git a/app/views/profiles/_follow_and_unfollow_button.html.haml b/app/views/profiles/_follow_and_unfollow_button.html.haml new file mode 100644 index 0000000..af65647 --- /dev/null +++ b/app/views/profiles/_follow_and_unfollow_button.html.haml @@ -0,0 +1,4 @@ +- if current_user_is_following(current_user.id, user.id) + = link_to 'Following', unfollow_user_path(user.user_name), remote: true, class: 'btn btn-success unfollow-button flat__buttons', id: "button-#{user.id}", method: :post +- else + = link_to 'Follow', follow_user_path(user.user_name), remote: true, class: 'btn btn-default follow-button flat__buttons', id: "button-#{user.id}", method: :post \ No newline at end of file diff --git a/app/views/profiles/edit.html.haml b/app/views/profiles/edit.html.haml new file mode 100644 index 0000000..d82d68e --- /dev/null +++ b/app/views/profiles/edit.html.haml @@ -0,0 +1,25 @@ +.post-wrapper + .post + .post-body + .image-wrap + = simple_form_for @user, url: {action: "update"}, html: { multipart: true } do |f| + .row + .col-md-12 + .form-group.text-center + %h4 Change your profile image: + .img-circle.avatar-image + = profile_avatar_select(@user) + %h4 Update your bio: + %label{class: 'btn btn-default btn-file'} + %span{class: 'glyphicon glyphicon-share'} + Upload + = f.input :avatar, label: false,wrapper: false,input_html: { onChange: 'loadFile(event)' } + + %div{style: 'clear:both'} + .col-md-12 + .form-group.text-center + %h4 Update your bio: + = f.input :bio, label: false, input_html: { rows: 4 } + .form-group.text-center + = f.button :submit, 'Update Profile', class: 'btn btn-success' + = link_to 'Edit Basic Info',edit_user_registration_path , class: "btn btn-primary" \ No newline at end of file diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml new file mode 100644 index 0000000..c25927b --- /dev/null +++ b/app/views/profiles/show.html.haml @@ -0,0 +1,26 @@ +.post-wrapper + .row.profile-header + .col-sm-6 + .img-circle + = profile_avatar_select(@user) + .col-sm-6 + .user-name-and-follow + %h3.profile-user-name + = @user.user_name + %p.profile-bio + = @user.bio + .user-statistics + %p + = pluralize @user.posts.count, 'post' + %div + - if @user == current_user + = link_to 'Edit Profile', edit_profile_path(@user.user_name), + class: 'btn edit-button flat__buttons' + = link_to 'Edit Basic Info', edit_user_registration_path, + class: 'btn edit-button flat__buttons' + - else + = render 'follow_and_unfollow_button',user: @user + + +-@posts.each do |post| + = render 'posts/post', {post: post,postable:post.user} diff --git a/app/views/profiles/show_all_users.html.haml b/app/views/profiles/show_all_users.html.haml new file mode 100644 index 0000000..89f6a3d --- /dev/null +++ b/app/views/profiles/show_all_users.html.haml @@ -0,0 +1,17 @@ +.post-wrapper + .user_listings + -@users.where.not(id: current_user.id).each do |user| + .user + .user_head + + = link_to 'Message', '#' ,class: 'start-conversation btn btn-danger follow-button flat__buttons',"data-sid" => current_user.id, "data-rip" => user.id + = render 'follow_and_unfollow_button' , :user => user + .user_avatar + = post_avatar_select(user) + .user_username + = link_to user.user_name , profile_path(user.user_name) + .user_fullname + = user.full_name + .clear + .user_bio + = user.bio \ No newline at end of file diff --git a/app/views/relationships/follow_user.js.erb b/app/views/relationships/follow_user.js.erb new file mode 100644 index 0000000..de87c8d --- /dev/null +++ b/app/views/relationships/follow_user.js.erb @@ -0,0 +1,3 @@ +$('#button-<%= @user.id %>').attr('class', 'btn btn-success unfollow-button flat__buttons') + .text('Following') + .attr('href', "/<%= @user.user_name %>/unfollow_user") \ No newline at end of file diff --git a/app/views/relationships/unfollow_user.js.erb b/app/views/relationships/unfollow_user.js.erb new file mode 100644 index 0000000..075ee39 --- /dev/null +++ b/app/views/relationships/unfollow_user.js.erb @@ -0,0 +1,3 @@ +$('#button-<%= @user.id %>').text('Follow') + .attr('class', 'btn btn-default follow-button flat__buttons') + .attr('href', "/<%= @user.user_name %>/follow_user") \ No newline at end of file diff --git a/app/views/universities/_common_links.html.haml b/app/views/universities/_common_links.html.haml new file mode 100644 index 0000000..8fd36f4 --- /dev/null +++ b/app/views/universities/_common_links.html.haml @@ -0,0 +1,6 @@ +.btn-group.post-wrapper + = link_to 'Discussion',university_path(@university),class: 'btn btn-primary' + = link_to 'Members',members_university_path(@university),class: 'btn btn-success' + = link_to 'Group Chat',chat_university_path(@university),class: 'btn btn-info' + - if current_user.role.name == 'admin' + = link_to 'Edit University',edit_university_path(@university),class: 'btn btn-warning' \ No newline at end of file diff --git a/app/views/universities/_form.html.haml b/app/views/universities/_form.html.haml new file mode 100644 index 0000000..109ea07 --- /dev/null +++ b/app/views/universities/_form.html.haml @@ -0,0 +1,15 @@ +- if university.errors.any? + #error_explanation + %h4 + = pluralize(university.errors.count, "error") + prohibited this university from being saved: + %ul + - university.errors.full_messages.each do |message| + %li= message + += simple_form_for university, html: { multipart: true } do |f| + = f.input :thumbnail_image, inline_label: 'Thummnail Image' + = f.input :timeline_image, inline_label: 'Timeline Image' + = f.input :name, label: false, placeholder: 'University Name' ,:autofocus => true + = f.input :description, label: false, placeholder: 'University Description' + = f.button :submit, class: 'btn-success btn-block' diff --git a/app/views/universities/_join_and_unjoin_button.html.haml b/app/views/universities/_join_and_unjoin_button.html.haml new file mode 100644 index 0000000..5cdcc4f --- /dev/null +++ b/app/views/universities/_join_and_unjoin_button.html.haml @@ -0,0 +1,4 @@ +- if current_user_is_joined(user.id, university.id) + = link_to 'Leave This University',unjoin_university_path(university,user), remote: true,class: 'btn btn-danger flat_button',id: "join_university_#{university.id}",method: :post +- else + = link_to 'Join This University',join_university_path(university,user), remote: true,class: 'btn btn-success flat_button',id: "join_university_#{university.id}",method: :post \ No newline at end of file diff --git a/app/views/universities/_join_university.html.haml b/app/views/universities/_join_university.html.haml new file mode 100644 index 0000000..ab644e7 --- /dev/null +++ b/app/views/universities/_join_university.html.haml @@ -0,0 +1,12 @@ +.mt20.bgwhite.sb1.padding20.mb20 + %p Please Join the group and wait for admin and wait for moderators to approve + %p After joining only you are able to: + %ul + %li See Posts + %li Create Interative Posts + %li Share Images + %li Share Files + %li Chat With University Members + %li Comments on each other posts + %li See the member of this university + %p By joining this University you agree with our terms and conditions \ No newline at end of file diff --git a/app/views/universities/_members_common_links.html.haml b/app/views/universities/_members_common_links.html.haml new file mode 100644 index 0000000..637574d --- /dev/null +++ b/app/views/universities/_members_common_links.html.haml @@ -0,0 +1,15 @@ +%div{class: "padding20 bglgray sb1 dib w250 text-center" ,id: "user_box_#{member.user.id}"} + = profile_avatar_select(member.user) + %h6= link_to member.user.full_name,profile_path(member.user.user_name) + - if(current_user.is_univerisity_moderator(@university.id)) + - if(type == 'pending') + = link_to 'Approve',approve_university_path(university.id,member.user.id),class: 'btn btn-success',id:"approve_user_#{member.user.id}",remote: true,method: :post + - if( (type == 'pending' or type =='moderators' or type =='members' or type =='banned') && moderation_power(member.user,university)) + = link_to 'Delete',delete_university_path(university.id,member.user.id),class: 'btn btn-danger',id:"delete_user_#{member.user.id}",remote: true,method: :post + - if( (type == 'pending' or type =='moderators' or type =='members') && moderation_power(member.user,university) ) + = link_to 'Ban',ban_university_path(university.id,member.user.id),class: 'btn btn-warning',id:"ban_user_#{member.user.id}",remote: true,method: :post + - if(current_user.is_university_admin(@university.id)) + -if(type == 'moderators') + = link_to 'Demote',demote_moderator_university_path(university.id,member.user.id),class: 'btn btn-info',id:"demote_user_#{member.user.id}",remote: true,method: :post + -if(type == 'members') + = link_to 'Promote',make_moderator_university_path(university.id,member.user.id),class: 'btn btn-info',id:"promote_user_#{member.user.id}",remote: true,method: :post \ No newline at end of file diff --git a/app/views/universities/_messages.html.haml b/app/views/universities/_messages.html.haml new file mode 100644 index 0000000..b3bdf95 --- /dev/null +++ b/app/views/universities/_messages.html.haml @@ -0,0 +1,13 @@ +.card + .card-block + .row + .col-md-1 + = post_avatar_select message.user + .col-md-11 + %p.card-text + %span.text-muted + = message.user.user_name + #{time_ago_in_words(message.created_at)} ago says + + %br + = message.body \ No newline at end of file diff --git a/app/views/universities/approve.js.erb b/app/views/universities/approve.js.erb new file mode 100644 index 0000000..01bb1d5 --- /dev/null +++ b/app/views/universities/approve.js.erb @@ -0,0 +1 @@ +$('#approve_user_<%= @user_id %>').attr('class', 'btn btn-success') .text('Approved') .attr('href', "#").attr("disabled", true) \ No newline at end of file diff --git a/app/views/universities/ban.js.erb b/app/views/universities/ban.js.erb new file mode 100644 index 0000000..3556ff6 --- /dev/null +++ b/app/views/universities/ban.js.erb @@ -0,0 +1 @@ +$('#ban_user_<%= @user_id %>').attr('class', 'btn btn-success') .text('Banned') .attr('href', "#").attr("disabled", true) \ No newline at end of file diff --git a/app/views/universities/chat.html.haml b/app/views/universities/chat.html.haml new file mode 100644 index 0000000..af1309c --- /dev/null +++ b/app/views/universities/chat.html.haml @@ -0,0 +1,12 @@ +.bgwhite.sb1.mt20.mwidth960.mauto.padding20 + = render 'common_links' + %hr + - if current_user.is_university_approved(@university.id) + #university_messages{'data-university-id': @university.id } + - @university.university_message.order(created_at: :asc).reverse_order().limit(150).each do |message| + = render 'messages',message: message + + = form_for @university_message, url: '#' do |f| + .form-group + = f.text_area :body, class: 'form-control' + = f.submit "Send Messages", class: 'btn btn-primary ' \ No newline at end of file diff --git a/app/views/universities/delete.js.erb b/app/views/universities/delete.js.erb new file mode 100644 index 0000000..baa7ce5 --- /dev/null +++ b/app/views/universities/delete.js.erb @@ -0,0 +1 @@ +$('#user_box_<%= @user_id %>').remove(); \ No newline at end of file diff --git a/app/views/universities/demote_moderator.js.erb b/app/views/universities/demote_moderator.js.erb new file mode 100644 index 0000000..5822b25 --- /dev/null +++ b/app/views/universities/demote_moderator.js.erb @@ -0,0 +1 @@ +$('#demote_user_<%= @user_id %>').attr('class', 'btn btn-success') .text('Demoted') .attr('href', "#").attr("disabled", true) \ No newline at end of file diff --git a/app/views/universities/edit.html.haml b/app/views/universities/edit.html.haml new file mode 100644 index 0000000..697b04e --- /dev/null +++ b/app/views/universities/edit.html.haml @@ -0,0 +1,7 @@ +.post-wrapper + .post + .padding20 + %h4 Editing University + = render 'form', university: @university + = link_to 'Show', @university,class: 'btn btn-success' + = link_to 'Back', universities_path,class: 'btn btn-primary' diff --git a/app/views/universities/index.html.haml b/app/views/universities/index.html.haml new file mode 100644 index 0000000..eb05d58 --- /dev/null +++ b/app/views/universities/index.html.haml @@ -0,0 +1,15 @@ +.university-index-wrapper + %h2 Universities + -if current_user.role.name == 'admin' + = link_to 'New University', new_university_path,class:'btn btn-primary' + .div{style: 'clear:both'} + %br + - @universities.each do|university| + .university-index-box + .university-card + =link_to university_path(university) do + .university-card-thumbnail + = image_tag university.thumbnail_image.url(:original) + .university-card-details + .university-card-title + = university.name diff --git a/app/views/universities/join.js.erb b/app/views/universities/join.js.erb new file mode 100644 index 0000000..0cc9d02 --- /dev/null +++ b/app/views/universities/join.js.erb @@ -0,0 +1,3 @@ +$('#join_university_<%= @university_id %>').attr('class', 'btn btn-danger flat__buttons') + .text('Leave This University') + .attr('href', "/universities/<%= @university_id %>/unjoin/<%= @user_id %>") diff --git a/app/views/universities/make_moderator.js.erb b/app/views/universities/make_moderator.js.erb new file mode 100644 index 0000000..23a96ad --- /dev/null +++ b/app/views/universities/make_moderator.js.erb @@ -0,0 +1 @@ +$('#promote_user_<%= @user_id %>').attr('class', 'btn btn-success') .text('Promoted') .attr('href', "#").attr("disabled", true) \ No newline at end of file diff --git a/app/views/universities/members.html.haml b/app/views/universities/members.html.haml new file mode 100644 index 0000000..d391274 --- /dev/null +++ b/app/views/universities/members.html.haml @@ -0,0 +1,28 @@ +.bgwhite.sb1.mt20.mwidth960.mauto.padding20 + = render 'common_links' + %hr + - if current_user.is_university_approved(@university.id) + %h4 Moderators + -@members.each do |member| + -if(member.role_id == @moderator_role_id) + = render 'members_common_links',university: @university , member: member,type: 'moderators' + %hr + %h4 Members + -@members.each do |member| + -if(member.role_id == @approved_role_id) + = render 'members_common_links',university: @university , member: member,type: 'members' + %hr + - if current_user.is_university_approved(@university.id) + - if(current_user.is_univerisity_moderator(@university.id)) + %h4 Pending To Be Approved + -@members.each do |member| + -if(member.role_id == @pending_role_id) + = render 'members_common_links',university: @university , member: member,type: 'pending' + %hr + %h4 Banned Users + -@members.each do |member| + -if(member.role_id == @banned_role_id) + = render 'members_common_links',university: @university , member: member,type: 'banned' + %hr + - else + = render 'join_university' \ No newline at end of file diff --git a/app/views/universities/new.html.haml b/app/views/universities/new.html.haml new file mode 100644 index 0000000..bf19d9c --- /dev/null +++ b/app/views/universities/new.html.haml @@ -0,0 +1,6 @@ +.post-wrapper + .post + .padding20 + %h4 Creating New University: + = render 'form', university: @university + = link_to 'Back', universities_path,class: 'btn btn-primary' diff --git a/app/views/universities/show.html.haml b/app/views/universities/show.html.haml new file mode 100644 index 0000000..d790b0c --- /dev/null +++ b/app/views/universities/show.html.haml @@ -0,0 +1,27 @@ +.university-show-wrapper + .university-timeline + = link_to (image_tag @university.timeline_image.url(:original), class: 'university_timeline_image' ),universities_path(@university) + .container-fluid + .row + .col-sm-8 + = render 'common_links' + - if current_user.is_university_approved(@university.id) + %main#posts + .post-wrapper + .post + .padding20 + = render 'posts/form',{post: @post,postable: @university} + = render 'posts/posts',{posts: @posts,postable: @university} + #paginator.text-center + = link_to_next_page @posts, 'Load More', remote: true, id: 'load_more' + - else + = render 'join_university' + .col-sm-4 + .post-wrapper + = render 'join_and_unjoin_button',university:@university,user:current_user + - if current_user.is_university_approved(@university.id) + .post-wrapper + .post + .post-head + %h4 Description + = @university.description diff --git a/app/views/universities/show.js.erb b/app/views/universities/show.js.erb new file mode 100644 index 0000000..21dcb5f --- /dev/null +++ b/app/views/universities/show.js.erb @@ -0,0 +1,3 @@ +$('#posts').append("<%= escape_javascript(render 'posts/posts',posts:@posts,postable: @university)%>"); +$('#paginator').html("<%= escape_javascript(link_to_next_page(@posts, 'LOAD MORE', remote: true, id: 'load_more'))%>"); +if (!$('#load_more').length) { $('#paginator').remove(); } \ No newline at end of file diff --git a/app/views/universities/unjoin.js.erb b/app/views/universities/unjoin.js.erb new file mode 100644 index 0000000..71a00ab --- /dev/null +++ b/app/views/universities/unjoin.js.erb @@ -0,0 +1,3 @@ +$('#join_university_<%= @university_id %>').attr('class', 'btn btn-success flat__buttons') + .text('Join This University') + .attr('href', "/universities/<%= @university_id %>/join/<%= @user_id %>") diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml new file mode 100644 index 0000000..918d614 --- /dev/null +++ b/app/views/users/show.html.haml @@ -0,0 +1,14 @@ +.container + .row + .col-sm-8 + %main#posts + .post-wrapper + .post + .padding20 + = render 'posts/form',{post: @post,postable: current_user} + = render 'posts/posts',{posts: @posts,postable: current_user} + #paginator.text-center + = link_to_next_page @posts, 'LOAD MORE', remote: true, id: 'load_more' + + .col-sm-4 + = render 'layouts/chat_box',followed_user: @followed_user \ No newline at end of file diff --git a/bin/bundle b/bin/bundle new file mode 100644 index 0000000..e3c2f62 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby.exe +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100644 index 0000000..bec72ac --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby.exe +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100644 index 0000000..f6ed5a2 --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby.exe +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100644 index 0000000..929edb7 --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby.exe +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/update b/bin/update new file mode 100644 index 0000000..deb1df2 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby.exe +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..f7ba0b5 --- /dev/null +++ b/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..7e671a2 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,15 @@ +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Kubh + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + end +end diff --git a/config/application.yml b/config/application.yml new file mode 100644 index 0000000..631fb58 --- /dev/null +++ b/config/application.yml @@ -0,0 +1,9 @@ +PORT: 80 + +production: + GMAIL_DOMAIN: gmail.com + GMAIL_USERNAME: remeahali@gmail.com + GMAIL_PASSWORD: bloggeris7 + SENDGRID_API_KEY: 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 + SECRET_KEY_BASE: 120b5ece87eb593ab6f1412f6dedf33bc7e60ed24b80ef296e0a4b33520e525a0c2809c2b04960d90155ddc1bbf3f7645d134a9253847f10cde44cf203ba2b5g + PORT: 80 \ No newline at end of file diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..30f5120 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000..0bbde6f --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,9 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: redis://localhost:6379/1 diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..220b1a0 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,15 @@ +development: + adapter: sqlite3 + pool: 5 + timeout: 5000 + database: db/development.sqlite3 + +production: + adapter: postgresql + user: chatounce_admin + password: pgsql77 + pool: 5 + timeout: 5000 + host: localhost + min_messages: WARNING + database: chat_ounce \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 0000000..e70b410 --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,10 @@ +# config valid only for current version of Capistrano +lock "3.7.1" + +set :application, "chat_ounce" +set :repo_url, "git@bitbucket.org:bloggervista/chat-ounce.git" + +set :deploy_to, '/home/shirshak/chat_ounce' + +append :linked_files, "config/database.yml", "config/secrets.yml" +append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "vendor/bundle", "public/system", "public/uploads" \ No newline at end of file diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 0000000..3758804 --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,62 @@ +server '127.0.0.1', user: 'shirshak', roles: %w{app db web} +# server-based syntax +# ====================== +# Defines a single server with a list of roles and multiple properties. +# You can define all roles on a single server, or split them: + +# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value +# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value +# server "db.example.com", user: "deploy", roles: %w{db} + + + +# role-based syntax +# ================== + +# Defines a role with one or multiple servers. The primary server in each +# group is considered to be the first unless any hosts have the primary +# property set. Specify the username and a domain or IP for the server. +# Don't use `:all`, it's a meta role. + +# role :app, %w{deploy@example.com}, my_property: :my_value +# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value +# role :db, %w{deploy@example.com} + + + +# Configuration +# ============= +# You can set any configuration variable like in config/deploy.rb +# These variables are then only loaded and set in this stage. +# For available Capistrano configuration variables see the documentation page. +# http://capistranorb.com/documentation/getting-started/configuration/ +# Feel free to add new variables to customise your setup. + + + +# Custom SSH Options +# ================== +# You may pass any option but keep in mind that net/ssh understands a +# limited set of options, consult the Net::SSH documentation. +# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start +# +# Global options +# -------------- +# set :ssh_options, { +# keys: %w(/home/rlisowski/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(password) +# } +# +# The server-based syntax can be used to override options: +# ------------------------------------ +# server "example.com", +# user: "user_name", +# roles: %w{web app}, +# ssh_options: { +# user: "user_name", # overrides user setting above +# keys: %w(/home/user_name/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(publickey password) +# # password: "please use keys" +# } diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..426333b --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..7121427 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,55 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = true + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker + # +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..b73629e --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,88 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + config.public_file_server.enabled = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "chat_ounce_#{Rails.env}" + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..30587ef --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=3600' + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000..51639b6 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000..01ef3e6 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..5a6a32d --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 0000000..22a91d1 --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,274 @@ +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. + config.secret_key = 'fc26fc8e83b27809ccd908bd9d0e3826e012b0b678a7a29f0e03d9bceed2b2c530fe3943356e8392ac6cdee3d1ab280a45705b151854d837727ce97b935d9b76' + + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'admin@chatounce.com' + + # Configure the class responsible to send e-mails. + config.mailer = 'Devise::Mailer' + + # Configure the parent class responsible to send e-mails. + config.parent_mailer = 'ActionMailer::Base' + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [:email] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [:email] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [:email] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. The supported strategies are: + # :database = Support basic authentication with authentication key + password + # config.http_authenticatable = false + + # If 401 status code should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # particular strategies by setting this option. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing skip: :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + + # When false, Devise will not attempt to reload routes on eager load. + # This can reduce the time taken to boot the app but if your application + # requires the Devise mappings to be loaded during boot time the application + # won't boot properly. + # config.reload_routes = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 11. If + # using other algorithms, it sets how many times you want the password to be hashed. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. Note that, for bcrypt (the default + # algorithm), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + config.stretches = Rails.env.test? ? 1 : 11 + + # Set up a pepper to generate the hashed password. + # config.pepper = '0fa4db07a697113efe4c1e406abf0699f12fc6dc211cf7f2dc73cf37465067da1b8407c7937d28eacc7f78b1ed1861bc300f2ce4dd336c9815703a7d688435ba' + + # Send a notification email when the user's password is changed + config.send_password_change_notification = false + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, + # access will be blocked just in the third day. Default is 0.days, meaning + # the user cannot access the website without confirming their account. + config.allow_unconfirmed_access_for = 2.days + + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + config.confirmation_keys = [:email] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + config.remember_for = 2.weeks + + # Invalidates all the remember me tokens when the user signs out. + config.expire_all_remember_me_on_sign_out = true + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # Options to be passed to the created cookie. For instance, you can set + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. + config.password_length = 6..128 + + # Email regex used to validate email formats. It simply asserts that + # one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + config.unlock_keys = [:email] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + config.maximum_attempts = 10 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + config.unlock_in = 1.hour + + # Warn on the last attempt before the account is locked. + config.last_attempt_warning = true + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + config.reset_password_keys = [:email] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + config.sign_in_after_reset_password = true + + # ==> Configuration for :encryptable + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # You can use :sha1, :sha512 or algorithms from others authentication tools as + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # for default behavior) and :restful_authentication_sha1 (then you should set + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt + #config.encryptor = :sha512 + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ['*/*', :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(scope: :user).unshift :some_external_strategy + # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using OmniAuth, Devise cannot automatically set OmniAuth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' +end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb new file mode 100644 index 0000000..ed1fe79 --- /dev/null +++ b/config/initializers/kaminari_config.rb @@ -0,0 +1,10 @@ +Kaminari.configure do |config| + config.default_per_page = 10 + # config.max_per_page = nil + # config.window = 4 + # config.outer_window = 0 + # config.left = 0 + # config.right = 0 + # config.page_method_name = :page + # config.param_name = :page +end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 index 0000000..671abb6 --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,24 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.0 upgrade. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Enable per-form CSRF tokens. Previous versions had false. +Rails.application.config.action_controller.per_form_csrf_tokens = true + +# Enable origin-checking CSRF mitigation. Previous versions had false. +Rails.application.config.action_controller.forgery_protection_origin_check = true + +# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. +# Previous versions had false. +ActiveSupport.to_time_preserves_timezone = true + +# Require `belongs_to` associations by default. Previous versions had false. +Rails.application.config.active_record.belongs_to_required_by_default = true + +# Do not halt callback chains when a callback returns false. Previous versions had true. +ActiveSupport.halt_callback_chains_on_return_false = false + +# Configure SSL options to enable HSTS with subdomains. Previous versions had false. +Rails.application.config.ssl_options = { hsts: { subdomains: true } } diff --git a/config/initializers/rails_admin.rb b/config/initializers/rails_admin.rb new file mode 100644 index 0000000..99e6dc6 --- /dev/null +++ b/config/initializers/rails_admin.rb @@ -0,0 +1,44 @@ +RailsAdmin.config do |config| + + config.authorize_with do + redirect_to main_app.root_path unless current_user.role.name == 'admin' + end + ### Popular gems integration + + ## == Devise == + # config.authenticate_with do + # warden.authenticate! scope: :user + # end + # config.current_user_method(&:current_user) + + ## == Cancan == + # config.authorize_with :cancan + + ## == Pundit == + # config.authorize_with :pundit + + ## == PaperTrail == + # config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0 + + ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration + + ## == Gravatar integration == + ## To disable Gravatar integration in Navigation Bar set to false + # config.show_gravatar true + + config.actions do + dashboard # mandatory + index # mandatory + new + export + bulk_delete + show + edit + delete + show_in_app + + ## With an audit adapter, you can add: + # history_index + # history_show + end +end diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 0000000..1ccfcc4 --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_chat_ounce_session' diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb new file mode 100644 index 0000000..d5492e5 --- /dev/null +++ b/config/initializers/simple_form.rb @@ -0,0 +1,166 @@ +# Use this setup block to configure all options available in SimpleForm. +SimpleForm.setup do |config| + # Wrappers are used by the form builder to generate a + # complete input. You can remove any component from the + # wrapper, change the order or even add your own to the + # stack. The options given below are used to wrap the + # whole input. + config.wrappers :default, class: :input, + hint_class: :field_with_hint, error_class: :field_with_errors do |b| + ## Extensions enabled by default + # Any of these extensions can be disabled for a + # given input by passing: `f.input EXTENSION_NAME => false`. + # You can make any of these extensions optional by + # renaming `b.use` to `b.optional`. + + # Determines whether to use HTML5 (:email, :url, ...) + # and required attributes + b.use :html5 + + # Calculates placeholders automatically from I18n + # You can also pass a string as f.input placeholder: "Placeholder" + b.use :placeholder + + ## Optional extensions + # They are disabled unless you pass `f.input EXTENSION_NAME => true` + # to the input. If so, they will retrieve the values from the model + # if any exists. If you want to enable any of those + # extensions by default, you can change `b.optional` to `b.use`. + + # Calculates maxlength from length validations for string inputs + b.optional :maxlength + + # Calculates pattern from format validations for string inputs + b.optional :pattern + + # Calculates min and max from length validations for numeric inputs + b.optional :min_max + + # Calculates readonly automatically from readonly attributes + b.optional :readonly + + ## Inputs + b.use :label_input + b.use :hint, wrap_with: { tag: :span, class: :hint } + b.use :error, wrap_with: { tag: :span, class: :error } + + ## full_messages_for + # If you want to display the full error message for the attribute, you can + # use the component :full_error, like: + # + # b.use :full_error, wrap_with: { tag: :span, class: :error } + end + + # The default wrapper to be used by the FormBuilder. + config.default_wrapper = :default + + # Define the way to render check boxes / radio buttons with labels. + # Defaults to :nested for bootstrap config. + # inline: input + label + # nested: label > input + config.boolean_style = :nested + + # Default class for buttons + config.button_class = 'btn' + + # Method used to tidy up errors. Specify any Rails Array method. + # :first lists the first message for each field. + # Use :to_sentence to list all errors for each field. + # config.error_method = :first + + # Default tag used for error notification helper. + config.error_notification_tag = :div + + # CSS class to add for error notification helper. + config.error_notification_class = 'error_notification' + + # ID to add for error notification helper. + # config.error_notification_id = nil + + # Series of attempts to detect a default label method for collection. + # config.collection_label_methods = [ :to_label, :name, :title, :to_s ] + + # Series of attempts to detect a default value method for collection. + # config.collection_value_methods = [ :id, :to_s ] + + # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none. + # config.collection_wrapper_tag = nil + + # You can define the class to use on all collection wrappers. Defaulting to none. + # config.collection_wrapper_class = nil + + # You can wrap each item in a collection of radio/check boxes with a tag, + # defaulting to :span. Please note that when using :boolean_style = :nested, + # SimpleForm will force this option to be a label. + # config.item_wrapper_tag = :span + + # You can define a class to use in all item wrappers. Defaulting to none. + # config.item_wrapper_class = nil + + # How the label text should be generated altogether with the required text. + # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" } + + # You can define the class to use on all labels. Default is nil. + # config.label_class = nil + + # You can define the default class to be used on forms. Can be overriden + # with `html: { :class }`. Defaulting to none. + # config.default_form_class = nil + + # You can define which elements should obtain additional classes + # config.generate_additional_classes_for = [:wrapper, :label, :input] + + # Whether attributes are required by default (or not). Default is true. + # config.required_by_default = true + + # Tell browsers whether to use the native HTML5 validations (novalidate form option). + # These validations are enabled in SimpleForm's internal config but disabled by default + # in this configuration, which is recommended due to some quirks from different browsers. + # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations, + # change this configuration to true. + config.browser_validations = false + + # Collection of methods to detect if a file type was given. + # config.file_methods = [ :mounted_as, :file?, :public_filename ] + + # Custom mappings for input types. This should be a hash containing a regexp + # to match as key, and the input type that will be used when the field name + # matches the regexp as value. + # config.input_mappings = { /count/ => :integer } + + # Custom wrappers for input types. This should be a hash containing an input + # type as key and the wrapper that will be used for all inputs with specified type. + # config.wrapper_mappings = { string: :prepend } + + # Namespaces where SimpleForm should look for custom input classes that + # override default inputs. + # config.custom_inputs_namespaces << "CustomInputs" + + # Default priority for time_zone inputs. + # config.time_zone_priority = nil + + # Default priority for country inputs. + # config.country_priority = nil + + # When false, do not use translations for labels. + # config.translate_labels = true + + # Automatically discover new inputs in Rails' autoload path. + # config.inputs_discovery = true + + # Cache SimpleForm inputs discovery + # config.cache_discovery = !Rails.env.development? + + # Default class for inputs + # config.input_class = nil + + # Define the default class of the input wrapper of the boolean input. + config.boolean_label_class = 'checkbox' + + # Defines if the default input wrapper class should be included in radio + # collection wrappers. + # config.include_default_input_wrapper_class = true + + # Defines which i18n scope will be used in Simple Form. + # config.i18n_scope = 'simple_form' +end diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb new file mode 100644 index 0000000..ea4a63d --- /dev/null +++ b/config/initializers/simple_form_bootstrap.rb @@ -0,0 +1,136 @@ +# Use this setup block to configure all options available in SimpleForm. +SimpleForm.setup do |config| + config.error_notification_class = 'alert alert-danger' + config.button_class = 'btn btn-default' + config.boolean_label_class = nil + + config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :label, class: 'control-label' + + b.use :input, class: 'form-control' + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :readonly + b.use :label, class: 'control-label' + + b.use :input + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.optional :readonly + + b.wrapper tag: 'div', class: 'checkbox' do |ba| + ba.use :label_input + end + + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.optional :readonly + b.use :label, class: 'control-label' + b.use :input + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :label, class: 'col-sm-3 control-label' + + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input, class: 'form-control' + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :readonly + b.use :label, class: 'col-sm-3 control-label' + + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.optional :readonly + + b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr| + wr.wrapper tag: 'div', class: 'checkbox' do |ba| + ba.use :label_input, class: 'col-sm-9' + end + + wr.use :error, wrap_with: { tag: 'span', class: 'help-block' } + wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.optional :readonly + + b.use :label, class: 'col-sm-3 control-label' + + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :label, class: 'sr-only' + + b.use :input, class: 'form-control' + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + # Wrappers for forms and inputs using the Bootstrap toolkit. + # Check the Bootstrap docs (http://getbootstrap.com) + # to learn about the different styles for forms and inputs, + # buttons and other elements. + config.default_wrapper = :vertical_form + config.wrapper_mappings = { + check_boxes: :vertical_radio_and_checkboxes, + radio_buttons: :vertical_radio_and_checkboxes, + file: :vertical_file_input, + boolean: :vertical_boolean, + } +end diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..bbfc396 --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100644 index 0000000..6641f9d --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,62 @@ +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n + +en: + devise: + confirmations: + confirmed: "Your email address has been successfully confirmed." + send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." + failure: + already_authenticated: "You are already logged in." + inactive: "Your account is not activated yet." + invalid: "Invalid %{authentication_keys} or password." + locked: "Your account is locked." + last_attempt: "You have one more attempt before your account is locked." + not_found_in_database: "Invalid %{authentication_keys} or password." + timeout: "Your session expired. Please sign in again to continue." + unauthenticated: "You need to sign in or sign up before continuing." + unconfirmed: "You have to confirm your email address before continuing." + mailer: + confirmation_instructions: + subject: "Confirmation instructions" + reset_password_instructions: + subject: "Reset password instructions" + unlock_instructions: + subject: "Unlock instructions" + password_change: + subject: "Password Changed" + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." + passwords: + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." + updated: "Your password has been changed successfully. You are now signed in." + updated_not_active: "Your password has been changed successfully." + registrations: + destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." + updated: "Your account has been updated successfully." + sessions: + signed_in: "Signed in successfully." + signed_out: "Signed out successfully." + already_signed_out: "Signed out successfully." + unlocks: + send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." + errors: + messages: + already_confirmed: "was already confirmed, please try signing in" + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: "has expired, please request a new one" + not_found: "not found" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..c7f311f --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,47 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum, this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted this block will be run, if you are using `preload_app!` +# option you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..282433d --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,104 @@ +Rails.application.routes.draw do + mount RailsAdmin::Engine => '/admin', as: 'rails_admin' + #---------------------------------------------------- + # Index + #---------------------------------------------------- + root 'dashboard#index' + #---------------------------------------------------- + # Follow And Unfollow User + #---------------------------------------------------- + get 'relationships/follow_user' + get 'relationships/unfollow_user' + post ':user_name/follow_user', to: 'relationships#follow_user', as: :follow_user , :user_name => /[a-zA-Z0-9_\.]*/ + post ':user_name/unfollow_user', to: 'relationships#unfollow_user', as: :unfollow_user ,:user_name => /[a-zA-Z0-9_\.]*/ + + #---------------------------------------------------- + # Notifications + #---------------------------------------------------- + resources :notifications do + collection do + post :mark_notifications_as_read + post :mark_messages_notification_as_read + end + end + #---------------------------------------------------- + # Making Devise to support preety url + #---------------------------------------------------- + devise_scope :user do + get "/register" => "devise/registrations#new", as: "new_user_registration" + end + devise_for :users, skip: [:sessions] + as :user do + get 'login', to: 'devise/sessions#new', as: :new_user_session + post 'login', to: 'devise/sessions#create', as: :user_session + delete 'logout', to: 'devise/sessions#destroy', as: :destroy_user_session + end + + #---------------------------------------------------- + # Concerns for Post , Comments and Likes + #---------------------------------------------------- + concern :postable do + resources :posts ,except:[:new] do + resources :comments,only:[:index,:create,:destroy] + member do + get 'like' + get 'unlike' + end + end + end + + #---------------------------------------------------- + # Post witch concerns of post comment likes + #---------------------------------------------------- + resources :users,only: [:show] ,concerns: :postable + #---------------------------------------------------- + # University + #---------------------------------------------------- + resources :universities,concerns: :postable do + member do + get 'members',:as=>'members' + + post 'join/:user_id', :to => "universities#join", :as => 'join' + post 'unjoin/:user_id', :to => "universities#unjoin", :as => 'unjoin' + + post 'approve/:user_id', :to => "universities#approve", :as => 'approve' + post 'ban/:user_id', :to => "universities#ban", :as => 'ban' + post 'delete/:user_id', :to => "universities#delete", :as => 'delete' + + post 'make_moderator/:user_id', :to => "universities#make_moderator", :as => 'make_moderator' + post 'demote_moderator/:user_id', :to => "universities#demote_moderator", :as => 'demote_moderator' + + get 'chat', :to => "universities#chat", :as => 'chat' + end + end + #---------------------------------------------------- + # Showing All Users + #---------------------------------------------------- + get 'all-users', to: 'profiles#show_all_users' + + #---------------------------------------------------- + # Profile + #---------------------------------------------------- + get 'profiles/show' + get '@:user_name', to: 'profiles#show', as: :profile ,:user_name => /[a-zA-Z0-9_\.]*/ + get '@:user_name/edit', to: 'profiles#edit', as: :edit_profile , :user_name => /[a-zA-Z0-9_\.]*/ + patch '@:user_name/edit', to: 'profiles#update', as: :update_profile ,:user_name => /[a-zA-Z0-9_\.]*/ + + #---------------------------------------------------- + # Chat Message + #---------------------------------------------------- + resources :chat_rooms, only: [:new, :create, :show, :index] + + #---------------------------------------------------- + # Search + #---------------------------------------------------- + get 'search' , to: 'dashboard#search' + #---------------------------------------------------- + # Personal Message + #---------------------------------------------------- + resources :personal_messages, only: [:new, :create] + resources :conversations, only: [:index, :show] + post 'conversations_api', to: 'personal_messages#api' + + mount ActionCable.server => '/cable' +end \ No newline at end of file diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000..67eee2e --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,6 @@ +development: + secret_key_base: 3bcfc5638e4ccbaa0a617cd2804724e656b11938fcf515e67bc79d7a1df02a74815e53647b310a28899f6498d3c5bc36735be67120925a97188755699e43153e +test: + secret_key_base: 110b5ece87eb593ab6f1412f6dedf33bc7e60ed24b80ef296e0a4b33520e525a0c2809c2b04960d90155ddc1bbf3f7645d134a9253847f10cde44cf203ba2b5f +production: + secret_key_base: 110b5ecf87eb593ab6f1412f6dedf33bc7e60ed24b80ef296e0a4b33520e525a0c2809c2b04960d90155ddc1bbf3f7645d134a9253847f10cde44cf203ba2b5g diff --git a/db/migrate/20150617010614_create_posts.rb b/db/migrate/20150617010614_create_posts.rb new file mode 100644 index 0000000..23230ab --- /dev/null +++ b/db/migrate/20150617010614_create_posts.rb @@ -0,0 +1,9 @@ +class CreatePosts < ActiveRecord::Migration + def change + create_table :posts do |t| + t.text :content + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20150617013037_add_attachment_image_to_posts.rb b/db/migrate/20150617013037_add_attachment_image_to_posts.rb new file mode 100644 index 0000000..af7844e --- /dev/null +++ b/db/migrate/20150617013037_add_attachment_image_to_posts.rb @@ -0,0 +1,11 @@ +class AddAttachmentImageToPosts < ActiveRecord::Migration + def self.up + change_table :posts do |t| + t.attachment :attachment + end + end + + def self.down + remove_attachment :posts, :attachment + end +end diff --git a/db/migrate/20150711011916_devise_create_users.rb b/db/migrate/20150711011916_devise_create_users.rb new file mode 100644 index 0000000..5144934 --- /dev/null +++ b/db/migrate/20150711011916_devise_create_users.rb @@ -0,0 +1,43 @@ +class DeviseCreateUsers < ActiveRecord::Migration + def change + create_table(:users) do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + t.boolean :admin + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, default: 0, null: false + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip + + ## Confirmable + t.string :confirmation_token + t.datetime :confirmed_at + t.datetime :confirmation_sent_at + t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + t.string :unlock_token # Only if unlock strategy is :email or :both + t.datetime :locked_at + + + t.timestamps null: false + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + add_index :users, :confirmation_token, unique: true + add_index :users, :unlock_token, unique: true + end +end diff --git a/db/migrate/20150711011919_add_first_name_last_name_user_name_to_user.rb b/db/migrate/20150711011919_add_first_name_last_name_user_name_to_user.rb new file mode 100644 index 0000000..093f277 --- /dev/null +++ b/db/migrate/20150711011919_add_first_name_last_name_user_name_to_user.rb @@ -0,0 +1,7 @@ +class AddFirstNameLastNameUserNameToUser < ActiveRecord::Migration + def change + add_column :users, :first_name, :string + add_column :users, :last_name, :string + add_column :users, :user_name, :string + end +end diff --git a/db/migrate/20150711072447_add_user_id_to_posts.rb b/db/migrate/20150711072447_add_user_id_to_posts.rb new file mode 100644 index 0000000..1bea36e --- /dev/null +++ b/db/migrate/20150711072447_add_user_id_to_posts.rb @@ -0,0 +1,6 @@ +class AddUserIdToPosts < ActiveRecord::Migration + def change + add_reference :posts, :user, index: true + add_foreign_key :posts, :users + end +end diff --git a/db/migrate/20150713011155_create_comments.rb b/db/migrate/20150713011155_create_comments.rb new file mode 100644 index 0000000..677de33 --- /dev/null +++ b/db/migrate/20150713011155_create_comments.rb @@ -0,0 +1,13 @@ +class CreateComments < ActiveRecord::Migration + def change + create_table :comments do |t| + t.references :user, index: true + t.references :post, index: true + t.text :content + + t.timestamps null: false + end + add_foreign_key :comments, :users + add_foreign_key :comments, :posts + end +end diff --git a/db/migrate/20151016102706_add_attachment_avatar_to_users.rb b/db/migrate/20151016102706_add_attachment_avatar_to_users.rb new file mode 100644 index 0000000..1d87ba8 --- /dev/null +++ b/db/migrate/20151016102706_add_attachment_avatar_to_users.rb @@ -0,0 +1,11 @@ +class AddAttachmentAvatarToUsers < ActiveRecord::Migration + def self.up + change_table :users do |t| + t.attachment :avatar + end + end + + def self.down + remove_attachment :users, :avatar + end +end diff --git a/db/migrate/20151016103736_add_bio_to_users.rb b/db/migrate/20151016103736_add_bio_to_users.rb new file mode 100644 index 0000000..7198e99 --- /dev/null +++ b/db/migrate/20151016103736_add_bio_to_users.rb @@ -0,0 +1,5 @@ +class AddBioToUsers < ActiveRecord::Migration + def change + add_column :users, :bio, :text + end +end diff --git a/db/migrate/20151029095601_acts_as_votable_migration.rb b/db/migrate/20151029095601_acts_as_votable_migration.rb new file mode 100644 index 0000000..5f381af --- /dev/null +++ b/db/migrate/20151029095601_acts_as_votable_migration.rb @@ -0,0 +1,27 @@ +class ActsAsVotableMigration < ActiveRecord::Migration + def self.up + create_table :votes do |t| + + t.references :votable, :polymorphic => true + t.references :voter, :polymorphic => true + + t.boolean :vote_flag + t.string :vote_scope + t.integer :vote_weight + + t.timestamps + end + + if ActiveRecord::VERSION::MAJOR < 4 + add_index :votes, [:votable_id, :votable_type] + add_index :votes, [:voter_id, :voter_type] + end + + add_index :votes, [:voter_id, :voter_type, :vote_scope] + add_index :votes, [:votable_id, :votable_type, :vote_scope] + end + + def self.down + drop_table :votes + end +end diff --git a/db/migrate/20160629131918_add_index_to_user.rb b/db/migrate/20160629131918_add_index_to_user.rb new file mode 100644 index 0000000..eab9ba5 --- /dev/null +++ b/db/migrate/20160629131918_add_index_to_user.rb @@ -0,0 +1,5 @@ +class AddIndexToUser < ActiveRecord::Migration + def change + add_index :users, :user_name,unique: true + end +end diff --git a/db/migrate/20160630205627_create_follow_join_table.rb b/db/migrate/20160630205627_create_follow_join_table.rb new file mode 100644 index 0000000..b40c8d3 --- /dev/null +++ b/db/migrate/20160630205627_create_follow_join_table.rb @@ -0,0 +1,14 @@ +class CreateFollowJoinTable < ActiveRecord::Migration + def change + create_table 'follows' do |t| + t.integer 'following_id', :null => false + t.integer 'follower_id', :null => false + + t.timestamps null: false + end + + add_index :follows, :following_id + add_index :follows, :follower_id + add_index :follows, [:following_id, :follower_id], unique: true + end +end \ No newline at end of file diff --git a/db/migrate/20170108121402_add_gender_to_users.rb b/db/migrate/20170108121402_add_gender_to_users.rb new file mode 100644 index 0000000..75a0990 --- /dev/null +++ b/db/migrate/20170108121402_add_gender_to_users.rb @@ -0,0 +1,5 @@ +class AddGenderToUsers < ActiveRecord::Migration[5.0] + def change + add_column :users, :is_female, :boolean, default: false + end +end diff --git a/db/migrate/20170109015355_create_chat_rooms.rb b/db/migrate/20170109015355_create_chat_rooms.rb new file mode 100644 index 0000000..cfcfb81 --- /dev/null +++ b/db/migrate/20170109015355_create_chat_rooms.rb @@ -0,0 +1,10 @@ +class CreateChatRooms < ActiveRecord::Migration[5.0] + def change + create_table :chat_rooms do |t| + t.string :title + t.references :user, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20170109021542_create_messages.rb b/db/migrate/20170109021542_create_messages.rb new file mode 100644 index 0000000..f25e343 --- /dev/null +++ b/db/migrate/20170109021542_create_messages.rb @@ -0,0 +1,11 @@ +class CreateMessages < ActiveRecord::Migration[5.0] + def change + create_table :messages do |t| + t.text :body + t.references :user, foreign_key: true + t.references :chat_room, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20170109033234_create_conversations.rb b/db/migrate/20170109033234_create_conversations.rb new file mode 100644 index 0000000..37f7581 --- /dev/null +++ b/db/migrate/20170109033234_create_conversations.rb @@ -0,0 +1,13 @@ +class CreateConversations < ActiveRecord::Migration[5.0] + def change + create_table :conversations do |t| + t.integer :author_id + t.integer :receiver_id + + t.timestamps + end + add_index :conversations, :author_id + add_index :conversations, :receiver_id + add_index :conversations, [:author_id, :receiver_id], unique: true + end +end diff --git a/db/migrate/20170109033246_create_personal_messages.rb b/db/migrate/20170109033246_create_personal_messages.rb new file mode 100644 index 0000000..27a49bd --- /dev/null +++ b/db/migrate/20170109033246_create_personal_messages.rb @@ -0,0 +1,11 @@ +class CreatePersonalMessages < ActiveRecord::Migration[5.0] + def change + create_table :personal_messages do |t| + t.text :body + t.belongs_to :conversation, foreign_key: true + t.belongs_to :user, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20170111190236_create_universities.rb b/db/migrate/20170111190236_create_universities.rb new file mode 100644 index 0000000..a6547c9 --- /dev/null +++ b/db/migrate/20170111190236_create_universities.rb @@ -0,0 +1,10 @@ +class CreateUniversities < ActiveRecord::Migration[5.0] + def change + create_table :universities do |t| + t.string :name + t.text :description + + t.timestamps + end + end +end diff --git a/db/migrate/20170111190314_add_attachment_thumbnail_image_to_universities.rb b/db/migrate/20170111190314_add_attachment_thumbnail_image_to_universities.rb new file mode 100644 index 0000000..89c4ac2 --- /dev/null +++ b/db/migrate/20170111190314_add_attachment_thumbnail_image_to_universities.rb @@ -0,0 +1,11 @@ +class AddAttachmentThumbnailImageToUniversities < ActiveRecord::Migration + def self.up + change_table :universities do |t| + t.attachment :thumbnail_image + end + end + + def self.down + remove_attachment :universities, :thumbnail_image + end +end diff --git a/db/migrate/20170111190347_add_attachment_timeline_image_to_universities.rb b/db/migrate/20170111190347_add_attachment_timeline_image_to_universities.rb new file mode 100644 index 0000000..9f10803 --- /dev/null +++ b/db/migrate/20170111190347_add_attachment_timeline_image_to_universities.rb @@ -0,0 +1,11 @@ +class AddAttachmentTimelineImageToUniversities < ActiveRecord::Migration + def self.up + change_table :universities do |t| + t.attachment :timeline_image + end + end + + def self.down + remove_attachment :universities, :timeline_image + end +end diff --git a/db/migrate/20170112103924_create_roles.rb b/db/migrate/20170112103924_create_roles.rb new file mode 100644 index 0000000..10bcf07 --- /dev/null +++ b/db/migrate/20170112103924_create_roles.rb @@ -0,0 +1,9 @@ +class CreateRoles < ActiveRecord::Migration[5.0] + def change + create_table :roles do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20170112104003_add_role_id_to_user.rb b/db/migrate/20170112104003_add_role_id_to_user.rb new file mode 100644 index 0000000..06e891d --- /dev/null +++ b/db/migrate/20170112104003_add_role_id_to_user.rb @@ -0,0 +1,5 @@ +class AddRoleIdToUser < ActiveRecord::Migration[5.0] + def change + add_reference :users, :role, foreign_key: true + end +end diff --git a/db/migrate/20170112120211_add_columns_to_post.rb b/db/migrate/20170112120211_add_columns_to_post.rb new file mode 100644 index 0000000..5ae4320 --- /dev/null +++ b/db/migrate/20170112120211_add_columns_to_post.rb @@ -0,0 +1,10 @@ +class AddColumnsToPost < ActiveRecord::Migration[5.0] + def up + add_column :posts, :postable_type, :string + add_column :posts, :postable_id, :integer + end + def down + remove_column :posts, :postable_type, :string + remove_column :posts, :postable_id, :integer + end +end diff --git a/db/migrate/20170112120249_remove_admin_from_user.rb b/db/migrate/20170112120249_remove_admin_from_user.rb new file mode 100644 index 0000000..2db07a9 --- /dev/null +++ b/db/migrate/20170112120249_remove_admin_from_user.rb @@ -0,0 +1,9 @@ +class RemoveAdminFromUser < ActiveRecord::Migration[5.0] + def up + remove_column :users, :admin + end + + def down + add_column :users, :admin, :boolean + end +end diff --git a/db/migrate/20170112174749_add_indexing_to_posts.rb b/db/migrate/20170112174749_add_indexing_to_posts.rb new file mode 100644 index 0000000..b71c5e6 --- /dev/null +++ b/db/migrate/20170112174749_add_indexing_to_posts.rb @@ -0,0 +1,5 @@ +class AddIndexingToPosts < ActiveRecord::Migration[5.0] + def change + add_index :posts,[:postable_id,:postable_type] + end +end diff --git a/db/migrate/20170114064428_create_university_memberships.rb b/db/migrate/20170114064428_create_university_memberships.rb new file mode 100644 index 0000000..cabed00 --- /dev/null +++ b/db/migrate/20170114064428_create_university_memberships.rb @@ -0,0 +1,14 @@ +class CreateUniversityMemberships < ActiveRecord::Migration[5.0] + def change + create_table :university_memberships do |t| + t.integer "user_id" + t.integer "university_id" + t.integer "role_id" + t.timestamps + end + add_index :university_memberships, :user_id + add_index :university_memberships, :university_id + add_index :university_memberships, :role_id + add_index :university_memberships, [:user_id, :university_id], unique: true + end +end \ No newline at end of file diff --git a/db/migrate/20170115053259_add_attachment_attachment_to_personal_messages.rb b/db/migrate/20170115053259_add_attachment_attachment_to_personal_messages.rb new file mode 100644 index 0000000..112a3a3 --- /dev/null +++ b/db/migrate/20170115053259_add_attachment_attachment_to_personal_messages.rb @@ -0,0 +1,11 @@ +class AddAttachmentAttachmentToPersonalMessages < ActiveRecord::Migration + def self.up + change_table :personal_messages do |t| + t.attachment :attachment + end + end + + def self.down + remove_attachment :personal_messages, :attachment + end +end diff --git a/db/migrate/20170115070355_create_notifications.rb b/db/migrate/20170115070355_create_notifications.rb new file mode 100644 index 0000000..9407cd8 --- /dev/null +++ b/db/migrate/20170115070355_create_notifications.rb @@ -0,0 +1,14 @@ +class CreateNotifications < ActiveRecord::Migration[5.0] + def change + create_table :notifications do |t| + t.integer :recipient_id + t.integer :actor_id + t.datetime :read_at + t.string :action + t.integer :notifiable_id + t.string :notifiable_type + + t.timestamps + end + end +end diff --git a/db/migrate/20170116043801_create_university_messages.rb b/db/migrate/20170116043801_create_university_messages.rb new file mode 100644 index 0000000..3e2cf3b --- /dev/null +++ b/db/migrate/20170116043801_create_university_messages.rb @@ -0,0 +1,11 @@ +class CreateUniversityMessages < ActiveRecord::Migration[5.0] + def change + create_table :university_messages do |t| + t.text :body + t.references :user, foreign_key: true + t.references :university, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..85cb50b --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,198 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20170116043801) do + + create_table "chat_rooms", force: :cascade do |t| + t.string "title" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_chat_rooms_on_user_id" + end + + create_table "comments", force: :cascade do |t| + t.integer "user_id" + t.integer "post_id" + t.text "content" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["post_id"], name: "index_comments_on_post_id" + t.index ["user_id"], name: "index_comments_on_user_id" + end + + create_table "conversations", force: :cascade do |t| + t.integer "author_id" + t.integer "receiver_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["author_id", "receiver_id"], name: "index_conversations_on_author_id_and_receiver_id", unique: true + t.index ["author_id"], name: "index_conversations_on_author_id" + t.index ["receiver_id"], name: "index_conversations_on_receiver_id" + end + + create_table "follows", force: :cascade do |t| + t.integer "following_id", null: false + t.integer "follower_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["follower_id"], name: "index_follows_on_follower_id" + t.index ["following_id", "follower_id"], name: "index_follows_on_following_id_and_follower_id", unique: true + t.index ["following_id"], name: "index_follows_on_following_id" + end + + create_table "messages", force: :cascade do |t| + t.text "body" + t.integer "user_id" + t.integer "chat_room_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["chat_room_id"], name: "index_messages_on_chat_room_id" + t.index ["user_id"], name: "index_messages_on_user_id" + end + + create_table "notifications", force: :cascade do |t| + t.integer "recipient_id" + t.integer "actor_id" + t.datetime "read_at" + t.string "action" + t.integer "notifiable_id" + t.string "notifiable_type" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "personal_messages", force: :cascade do |t| + t.text "body" + t.integer "conversation_id" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "attachment_file_name" + t.string "attachment_content_type" + t.integer "attachment_file_size" + t.datetime "attachment_updated_at" + t.index ["conversation_id"], name: "index_personal_messages_on_conversation_id" + t.index ["user_id"], name: "index_personal_messages_on_user_id" + end + + create_table "posts", force: :cascade do |t| + t.text "content" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "attachment_file_name" + t.string "attachment_content_type" + t.integer "attachment_file_size" + t.datetime "attachment_updated_at" + t.integer "user_id" + t.string "postable_type" + t.integer "postable_id" + t.index ["postable_id", "postable_type"], name: "index_posts_on_postable_id_and_postable_type" + t.index ["user_id"], name: "index_posts_on_user_id" + end + + create_table "roles", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "universities", force: :cascade do |t| + t.string "name" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "thumbnail_image_file_name" + t.string "thumbnail_image_content_type" + t.integer "thumbnail_image_file_size" + t.datetime "thumbnail_image_updated_at" + t.string "timeline_image_file_name" + t.string "timeline_image_content_type" + t.integer "timeline_image_file_size" + t.datetime "timeline_image_updated_at" + end + + create_table "university_memberships", force: :cascade do |t| + t.integer "user_id" + t.integer "university_id" + t.integer "role_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["role_id"], name: "index_university_memberships_on_role_id" + t.index ["university_id"], name: "index_university_memberships_on_university_id" + t.index ["user_id", "university_id"], name: "index_university_memberships_on_user_id_and_university_id", unique: true + t.index ["user_id"], name: "index_university_memberships_on_user_id" + end + + create_table "university_messages", force: :cascade do |t| + t.text "body" + t.integer "user_id" + t.integer "university_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["university_id"], name: "index_university_messages_on_university_id" + t.index ["user_id"], name: "index_university_messages_on_user_id" + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" + t.integer "failed_attempts", default: 0, null: false + t.string "unlock_token" + t.datetime "locked_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "first_name" + t.string "last_name" + t.string "user_name" + t.string "avatar_file_name" + t.string "avatar_content_type" + t.integer "avatar_file_size" + t.datetime "avatar_updated_at" + t.text "bio" + t.boolean "is_female", default: false + t.integer "role_id" + t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + t.index ["role_id"], name: "index_users_on_role_id" + t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true + t.index ["user_name"], name: "index_users_on_user_name", unique: true + end + + create_table "votes", force: :cascade do |t| + t.string "votable_type" + t.integer "votable_id" + t.string "voter_type" + t.integer "voter_id" + t.boolean "vote_flag" + t.string "vote_scope" + t.integer "vote_weight" + t.datetime "created_at" + t.datetime "updated_at" + t.index ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope" + t.index ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope" + end + +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..a915402 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,15 @@ +['registered', 'banned', 'moderator', 'admin','group_approved','group_pending_approval'].each do |role| + Role.find_or_create_by({name: role}) +end + +admin_user = {email: 'admin@admin.com', + password_confirmation: 'admin123', + password: 'admin123', + first_name: "Admin", + last_name: "Admin", + user_name: "Administrator", + bio: "Admin is the super user", + is_female: false + } +a = Role.where(name: 'admin').first.users.build(admin_user) +a.save! diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..b612547 --- /dev/null +++ b/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
    +
    +

    The page you were looking for doesn't exist.

    +

    You may have mistyped the address or the page may have moved.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/public/422.html b/public/422.html new file mode 100644 index 0000000..a21f82b --- /dev/null +++ b/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
    +
    +

    The change you wanted was rejected.

    +

    Maybe you tried to change something you didn't have access to.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..061abc5 --- /dev/null +++ b/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
    +
    +

    We're sorry, but something went wrong.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..64349fb Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..3c9c7c0 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep new file mode 100644 index 0000000..e69de29