diff --git a/.gitignore b/.gitignore index 6a502e9..8809fdd 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp + +/public/stylesheets/node_modules +/public/stylesheets/*.map \ No newline at end of file diff --git a/README.md b/README.md index 13a3a87..503b8d2 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -#Web Chatroom \ No newline at end of file +#Web Chatroom + +[![Join the chat at https://gitter.im/FreemanHsu/CloudChat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/FreemanHsu/CloudChat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) \ No newline at end of file diff --git a/app/assets/images/andy.png b/app/assets/images/andy.png new file mode 100644 index 0000000..8d7a731 Binary files /dev/null and b/app/assets/images/andy.png differ diff --git a/app/assets/images/angular.jpg b/app/assets/images/angular.jpg new file mode 100644 index 0000000..7c295d2 Binary files /dev/null and b/app/assets/images/angular.jpg differ diff --git a/app/assets/images/bower.jpg b/app/assets/images/bower.jpg new file mode 100644 index 0000000..aab4295 Binary files /dev/null and b/app/assets/images/bower.jpg differ diff --git a/app/assets/images/cloud.jpeg b/app/assets/images/cloud.jpeg deleted file mode 100644 index 8d41462..0000000 Binary files a/app/assets/images/cloud.jpeg and /dev/null differ diff --git a/app/assets/images/cloudbg.jpg b/app/assets/images/cloudbg.jpg new file mode 100644 index 0000000..da369c4 Binary files /dev/null and b/app/assets/images/cloudbg.jpg differ diff --git a/app/assets/images/clouds.jpeg b/app/assets/images/clouds.jpeg deleted file mode 100644 index c5b2766..0000000 Binary files a/app/assets/images/clouds.jpeg and /dev/null differ diff --git a/app/assets/images/cpp.jpg b/app/assets/images/cpp.jpg new file mode 100644 index 0000000..5009717 Binary files /dev/null and b/app/assets/images/cpp.jpg differ diff --git a/app/assets/images/grunt.jpg b/app/assets/images/grunt.jpg new file mode 100644 index 0000000..7d453a2 Binary files /dev/null and b/app/assets/images/grunt.jpg differ diff --git a/app/assets/images/h5.jpg b/app/assets/images/h5.jpg new file mode 100644 index 0000000..b75a00d Binary files /dev/null and b/app/assets/images/h5.jpg differ diff --git a/app/assets/images/haskell.jpg b/app/assets/images/haskell.jpg new file mode 100644 index 0000000..60333db Binary files /dev/null and b/app/assets/images/haskell.jpg differ diff --git a/app/assets/images/java.jpg b/app/assets/images/java.jpg new file mode 100644 index 0000000..ecc1c81 Binary files /dev/null and b/app/assets/images/java.jpg differ diff --git a/app/assets/images/lisp.jpg b/app/assets/images/lisp.jpg new file mode 100644 index 0000000..a9d0955 Binary files /dev/null and b/app/assets/images/lisp.jpg differ diff --git a/app/assets/images/lua.jpg b/app/assets/images/lua.jpg new file mode 100644 index 0000000..8b97670 Binary files /dev/null and b/app/assets/images/lua.jpg differ diff --git a/app/assets/images/node.jpg b/app/assets/images/node.jpg new file mode 100644 index 0000000..04b785a Binary files /dev/null and b/app/assets/images/node.jpg differ diff --git a/app/assets/images/python.jpg b/app/assets/images/python.jpg new file mode 100644 index 0000000..3b3c105 Binary files /dev/null and b/app/assets/images/python.jpg differ diff --git a/app/assets/images/python2.jpg b/app/assets/images/python2.jpg new file mode 100644 index 0000000..266a251 Binary files /dev/null and b/app/assets/images/python2.jpg differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index afb7af6..d54745c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,5 +13,4 @@ //= require jquery //= require jquery_ujs //= require turbolinks -//= require_tree . -//= require vendor/jquery.anystretch.min \ No newline at end of file +//= require_tree . \ No newline at end of file diff --git a/app/assets/javascripts/chatrooms.js.coffee b/app/assets/javascripts/coffees/chat_log.js.coffee similarity index 100% rename from app/assets/javascripts/chatrooms.js.coffee rename to app/assets/javascripts/coffees/chat_log.js.coffee diff --git a/app/assets/javascripts/homepage.js.coffee b/app/assets/javascripts/coffees/chatrooms.js.coffee similarity index 100% rename from app/assets/javascripts/homepage.js.coffee rename to app/assets/javascripts/coffees/chatrooms.js.coffee diff --git a/app/assets/javascripts/room_mems.js.coffee b/app/assets/javascripts/coffees/homepage.js.coffee similarity index 100% rename from app/assets/javascripts/room_mems.js.coffee rename to app/assets/javascripts/coffees/homepage.js.coffee diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/coffees/message.js.coffee similarity index 100% rename from app/assets/javascripts/users.js.coffee rename to app/assets/javascripts/coffees/message.js.coffee diff --git a/app/assets/javascripts/coffees/room_mems.js.coffee b/app/assets/javascripts/coffees/room_mems.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/coffees/room_mems.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/coffees/tag.js.coffee b/app/assets/javascripts/coffees/tag.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/coffees/tag.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/coffees/user_has_msg.js.coffee b/app/assets/javascripts/coffees/user_has_msg.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/coffees/user_has_msg.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/coffees/users.js.coffee b/app/assets/javascripts/coffees/users.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/coffees/users.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/vendor/jquery.anystretch.min.js b/app/assets/javascripts/vendor/jquery.anystretch.min.js deleted file mode 100644 index f88a6bc..0000000 --- a/app/assets/javascripts/vendor/jquery.anystretch.min.js +++ /dev/null @@ -1,17 +0,0 @@ -/* - * jQuery Anystretch - * Version 1.2 (@jbrooksuk / me.itslimetime.com) - * https://github.com/jbrooksuk/jquery-anystretch - * Based on Dan Millar's Port - * https://github.com/danmillar/jquery-anystretch - * - * Add a dynamically-resized background image to the body - * of a page or any other block level element within it - * - * Copyright (c) 2012 Dan Millar (@danmillar / decode.uk.com) - * Dual licensed under the MIT and GPL licenses. - * - * This is a fork of jQuery Backstretch (v1.2) - * Copyright (c) 2011 Scott Robbin (srobbin.com) -*/ -(function(a){a.fn.anystretch=function(d,c,e){var b=this.selector.length?false:true;return this.each(function(q){var s={positionX:"center",positionY:"center",speed:0,elPosition:"relative",dataName:"stretch"},h=a(this),g=b?a(".anystretch"):h.children(".anystretch"),l=g.data("settings")||s,m=g.data("settings"),j,f,r,p,v,u;if(c&&typeof c=="object"){a.extend(l,c)}if(c&&typeof c=="function"){e=c}a(document).ready(t);return this;function t(){if(d||h.length>=1){var i;if(!b){h.css({position:l.elPosition,background:"none"})}if(g.length==0){g=a("
").attr("class","anystretch").css({left:0,top:0,position:(b?"fixed":"absolute"),overflow:"hidden",zIndex:(b?-999999:-999998),margin:0,padding:0,height:"100%",width:"100%"})}else{g.find("img").addClass("deleteable")}i=a("").css({position:"absolute",display:"none",margin:0,padding:0,border:"none",zIndex:-999999}).bind("load",function(A){var z=a(this),y,x;z.css({width:"auto",height:"auto"});y=this.width||a(A.target).width();x=this.height||a(A.target).height();j=y/x;o(function(){z.fadeIn(l.speed,function(){g.find(".deleteable").remove();if(typeof e=="function"){e()}})})}).appendTo(g);if(h.children(".anystretch").length==0){if(b){a("body").append(g)}else{h.append(g)}}g.data("settings",l);var w="";if(d){w=d}else{if(h.data(l.dataName)){w=h.data(l.dataName)}else{return}}i.attr("src",w);a(window).resize(o)}}function o(i){try{u={left:0,top:0};r=k();p=r/j;if(p>=n()){v=(p-n())/2;if(l.positionY=="center"||l.centeredY){a.extend(u,{top:"-"+v+"px"})}else{if(l.positionY=="bottom"){a.extend(u,{top:"auto",bottom:"0px"})}}}else{p=n();r=p*j;v=(r-k())/2;if(l.positionX=="center"||l.centeredX){a.extend(u,{left:"-"+v+"px"})}else{if(l.positionX=="right"){a.extend(u,{left:"auto",right:"0px"})}}}g.children("img:not(.deleteable)").width(r).height(p).filter("img").css(u)}catch(w){}if(typeof i=="function"){i()}}function k(){return b?h.width():h.innerWidth()}function n(){return b?h.height():h.innerHeight()}})};a.anystretch=function(d,b,e){var c=("onorientationchange" in window)?a(document):a(window);c.anystretch(d,b,e)}})(jQuery); \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css.scss similarity index 99% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.css.scss index 2531de4..bc3a8dc 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css.scss @@ -13,4 +13,4 @@ *= require_tree . *= require_self *= require font-awesome - */ + */ \ No newline at end of file diff --git a/app/assets/stylesheets/chatrooms.css.scss b/app/assets/stylesheets/chatrooms.css.scss deleted file mode 100644 index 3cafc5a..0000000 --- a/app/assets/stylesheets/chatrooms.css.scss +++ /dev/null @@ -1,24 +0,0 @@ -// Place all the styles related to the Chatrooms controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ -th,td{ - text-align:center; - width: 50px; - max-width: 50px; -} - -.content{ - .cover{ - img{ - width: 100px; - height: 100px; - border: 4px; - padding: 4px; - } - } - .name{ - text-align:center; - width: 200px; - max-width: 200px; - } -} diff --git a/app/assets/stylesheets/room_mems.css.scss b/app/assets/stylesheets/room_mems.css.scss deleted file mode 100644 index 711d82a..0000000 --- a/app/assets/stylesheets/room_mems.css.scss +++ /dev/null @@ -1,18 +0,0 @@ -// Place all the styles related to the room_mems controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ - -.name{ - text-align:center; - width: 100px; - max-width: 100px; -} - -.pic{ - img{ - width: 100px; - height: 100px; - border: 4px; - padding: 4px; - } -} \ No newline at end of file diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss deleted file mode 100644 index 6ec6a8f..0000000 --- a/app/assets/stylesheets/scaffolds.css.scss +++ /dev/null @@ -1,69 +0,0 @@ -body { - background-color: #fff; - color: #333; - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -p, ol, ul, td { - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -pre { - background-color: #eee; - padding: 10px; - font-size: 11px; -} - -a { - color: #000; - &:visited { - color: #666; - } - &:hover { - color: #fff; - background-color: #000; - } -} - -div { - &.field, &.actions { - margin-bottom: 10px; - } -} - -#notice { - color: green; -} - -.field_with_errors { - padding: 2px; - background-color: red; - display: table; -} - -#error_explanation { - width: 450px; - border: 2px solid red; - padding: 7px; - padding-bottom: 0; - margin-bottom: 20px; - background-color: #f0f0f0; - h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px; - margin-bottom: 0px; - background-color: #c00; - color: #fff; - } - ul li { - font-size: 12px; - list-style: square; - } -} diff --git a/app/assets/stylesheets/sections/chat_log.css.scss b/app/assets/stylesheets/sections/chat_log.css.scss new file mode 100644 index 0000000..f04477b --- /dev/null +++ b/app/assets/stylesheets/sections/chat_log.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the ChatLog controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sections/chatrooms.css.scss b/app/assets/stylesheets/sections/chatrooms.css.scss new file mode 100644 index 0000000..75cbbb5 --- /dev/null +++ b/app/assets/stylesheets/sections/chatrooms.css.scss @@ -0,0 +1,69 @@ +// Place all the styles related to the Chatrooms controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.thumbnail{ + margin-top: 20px; + margin-bottom: 0; + background-color: rgba(255,255,255,.5); + &:hover{ + background-color: rgba(255,255,255,1); + } + p{ + margin: 10px 0; + height: 60px; + border-top: 1px solid #eee; + border-bottom: 1px solid #eee; + font-weight: 400; + } + img{ + width: 80px; + height: 80px; + border: 1px solid #eee; + border-radius: 50% 50%; + &:hover{ + border: 2px solid #3297ff; + cursor: pointer; + } + } + h3{ + margin-top: -5px; + text-align: center; + font-weight: 400; + } + a{ + color: #000; + display: inline-block; + width: 60px; + height: 20px; + text-align: center; + background-color: #fff; + border-radius: 4px; + float: right; + &:hover{ + text-decoration: none; + background-color: #3297ff; + color: #fff; + } + } +} + +.home-page-roomtag{ + height: 20px; + overflow: hidden; + margin-bottom: 10px; + span{ + margin-right: 5px; + a{ + float:none; + background:rgba(0,0,0,0); + &:hover{ + background:rgba(0,0,0,0); + } + } + &:hover{ + background-color: #337ab7; + cursor: pointer; + } + } +} \ No newline at end of file diff --git a/app/assets/stylesheets/sections/homepage.css.scss b/app/assets/stylesheets/sections/homepage.css.scss index 7e587f6..557c158 100644 --- a/app/assets/stylesheets/sections/homepage.css.scss +++ b/app/assets/stylesheets/sections/homepage.css.scss @@ -1,18 +1,108 @@ // Place all the styles related to the homepage controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ -.home-banner { - .site-nav{ - position: relative; + +.homepage-index{ + background-color: #f1f0ed; +} + +.jumbotron{ + height: 600px; + background: none; + &:after{ + min-height: 600px; + max-height: 600px; + content: ''; + display: block; + position: absolute; + top: 0; left: 0; + bottom: 0; right: 0; - top: 0; - z-index: 9999; - padding-top: 60px; + background: image-url("cloudbg.jpg") center center; + background-size: cover; + z-index: -9999; + } + font-family: DP,sans-serif; + color: #fff; + h1{ + font-size: 5em; + span{ + font-weight: 700; + } + } + p{ + margin: 5px 0; + font-size: 1.5em; + font-weight: 300; + } +} + +.sign-btn{ + height: 54px; + width: 290px; + margin-top: 45px; + a{ + text-align: center; + display: inline-block; + position: relative; + padding: 18px 0; + font-size: 18px; + font-weight: 600; + letter-spacing: 2px; + line-height: 1; + height: 100%; + width: 100%; + border-radius: 5px; + background-color: #fff; + color: rgba(50,151,255,1); + font-family: proxima-nova-alt,Proxima Nova Alt,sans-serif; + border-bottom: 4px solid #eee; + border-left: 2px solid #eee; + &:hover{ + text-decoration: none; + border-bottom: 2px solid #eee; + border-left: none; + } + } +} + +#explore{ + position: relative; + margin-top: -40px; + padding-top: 0px; + height: 60px; + background-color: #dbd8d0; + p{ + color: #7d7669; + padding-top: 20px; + font-size: 1em; + text-align: center; + font-weight: 700; } - .banner-inner { - margin: 0 auto; - height: 800px; - position: relative; - } +} + +.login-btn{ + position: absolute; + right: 50px; + top: 50px; + a{ + cursor: pointer; + display: block; + width: 220px; + height: 40px; + border: 2px solid #fff; + border-radius: 4px; + background-color: rgba(50,151,255,0); + color: #fff; + text-decoration: none; + text-align: center; + font-size: 14px; + padding: 9px 0; + &:hover{ + cursor: pointer; + background-color: #fff; + color: rgba(50,151,255,1); + } + } } \ No newline at end of file diff --git a/app/assets/stylesheets/sections/message.css.scss b/app/assets/stylesheets/sections/message.css.scss new file mode 100644 index 0000000..a1f3a3e --- /dev/null +++ b/app/assets/stylesheets/sections/message.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the message controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sections/room_mems.css.scss b/app/assets/stylesheets/sections/room_mems.css.scss new file mode 100644 index 0000000..aaabda1 --- /dev/null +++ b/app/assets/stylesheets/sections/room_mems.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the room_mems controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ \ No newline at end of file diff --git a/app/assets/stylesheets/sections/tag.css.scss b/app/assets/stylesheets/sections/tag.css.scss new file mode 100644 index 0000000..7cacc1a --- /dev/null +++ b/app/assets/stylesheets/sections/tag.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Tag controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sections/user_has_msg.css.scss b/app/assets/stylesheets/sections/user_has_msg.css.scss new file mode 100644 index 0000000..cc9b8b8 --- /dev/null +++ b/app/assets/stylesheets/sections/user_has_msg.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the UserHasMsg controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sections/users.css.scss b/app/assets/stylesheets/sections/users.css.scss index 31ab165..1efc835 100644 --- a/app/assets/stylesheets/sections/users.css.scss +++ b/app/assets/stylesheets/sections/users.css.scss @@ -1,3 +1,3 @@ // Place all the styles related to the users controller here. // They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ \ No newline at end of file +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/shared/common.css.scss b/app/assets/stylesheets/shared/common.css.scss new file mode 100644 index 0000000..58d42dd --- /dev/null +++ b/app/assets/stylesheets/shared/common.css.scss @@ -0,0 +1,9 @@ +#footer { + margin-top: 20px; + padding: 10px 20px; + color: #a6a6a6; + font-size: 0.8em; + text-align: center; + background: #18191b; + border-bottom: #0a0a0a 5px solid; +} \ No newline at end of file diff --git a/app/assets/stylesheets/shared/normalize.css b/app/assets/stylesheets/shared/normalize.css.scss similarity index 100% rename from app/assets/stylesheets/shared/normalize.css rename to app/assets/stylesheets/shared/normalize.css.scss diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7adc312..9c7595d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,10 +2,22 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - + + @@send_msg_num = 0 + @@recv_msg_num = 0 def current_user @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token] end + def search + @chatroom = Chatroom.where(:roomno => params[:id]) \ + + Chatroom.where(:roomname => params[:id]) + + tag = Tag.find_by_tagname(params[:id]) + tag.chatrooms.each do |c| + @chatroom << c + end + end + helper_method :current_user end diff --git a/app/controllers/chat_log_controller.rb b/app/controllers/chat_log_controller.rb new file mode 100644 index 0000000..4ed088c --- /dev/null +++ b/app/controllers/chat_log_controller.rb @@ -0,0 +1,2 @@ +class ChatLogController < ApplicationController +end diff --git a/app/controllers/chatapp_controller.rb b/app/controllers/chatapp_controller.rb new file mode 100644 index 0000000..7d5c7c2 --- /dev/null +++ b/app/controllers/chatapp_controller.rb @@ -0,0 +1,4 @@ +class ChatappController < ApplicationController + def index + end +end diff --git a/app/controllers/chatrooms_controller.rb b/app/controllers/chatrooms_controller.rb index 2863300..aa689d5 100644 --- a/app/controllers/chatrooms_controller.rb +++ b/app/controllers/chatrooms_controller.rb @@ -1,10 +1,10 @@ class ChatroomsController < ApplicationController before_action :set_chatroom, only: [:show, :edit, :update, :destroy] + # GET /chatrooms # GET /chatrooms.json def index - @chatrooms = Chatroom.all end # GET /chatrooms/1 @@ -27,18 +27,16 @@ def edit # POST /chatrooms.json def create @chatroom = Chatroom.new(chatroom_params) - - @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token] - @chatroom.user_id = @current_user.id + @chatroom.user_id ||= current_user.id respond_to do |format| if @chatroom.save room_mem = RoomMem.new - room_mem.user_id = @current_user.id + room_mem.user_id = current_user.id room_mem.chatroom_id = @chatroom.id room_mem.save - format.html { redirect_to @chatroom, notice: 'Chatroom was successfully created.' } + format.html { redirect_to set_tag_path(@chatroom.id) } format.json { render :show, status: :created, location: @chatroom } else format.html { render :new } @@ -81,6 +79,6 @@ def set_chatroom end # Never trust parameters from the scary internet, only allow the white list through. def chatroom_params - params.require(:chatroom).permit(:roomname, :roomcover, :privacy, :popularity, :memnum, :roomno, :key, :creatorid, :description) + params.require(:chatroom).permit(:roomname, :roomcover, :privacy, :popularity, :memnum, :roomno, :key, :user_id, :description) end end diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb index 832dae7..e67794b 100644 --- a/app/controllers/homepage_controller.rb +++ b/app/controllers/homepage_controller.rb @@ -1,5 +1,5 @@ class HomepageController < ApplicationController def index - @chatrooms = Chatroom.all + @chatrooms = Chatroom.where(:privacy => false).order("popularity DESC, roomname DESC").limit(24) end end diff --git a/app/controllers/message_controller.rb b/app/controllers/message_controller.rb new file mode 100644 index 0000000..4503c19 --- /dev/null +++ b/app/controllers/message_controller.rb @@ -0,0 +1,18 @@ +class MessageController < ApplicationController + def create + message = Message.new + message.content = params[:content] + message.save + + @user_has_msg = UserHasMsg.new + @user_has_msg.sender_id = current_user.id + @user_has_msg.receiver_id = params[:receiver_id] + @user_has_msg.message_id = message.id + @user_has_msg.message = message + message.user_has_msg = @user_has_msg + @user_has_msg.save + redirect_to home_path + end + + +end diff --git a/app/controllers/room_mems_controller.rb b/app/controllers/room_mems_controller.rb index 9ad3b3c..5939f1d 100644 --- a/app/controllers/room_mems_controller.rb +++ b/app/controllers/room_mems_controller.rb @@ -2,4 +2,18 @@ class RoomMemsController < ApplicationController def show @room_mems = RoomMem.where(:chatroom_id => params[:id]) end + + def enter + @room_mem = RoomMem.new + @room_mem.chatroom_id = params[:id] + + if RoomMem.exists?(:user_id => current_user.id, :chatroom_id => params[:id]) + else + @room_mem.user_id = current_user.id + @chatroom = @room_mem.chatroom + @chatroom.memnum = @chatroom.memnum+1 + @chatroom.save + @room_mem.save + end + end end diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb new file mode 100644 index 0000000..6e7315f --- /dev/null +++ b/app/controllers/tag_controller.rb @@ -0,0 +1,23 @@ +class TagController < ApplicationController + def set + @chatroom = Chatroom.find(params[:id]) + end + + def afterset + @chatroom = Chatroom.find(params[:id]) + tmp = [params[:tag1], params[:tag2], params[:tag3] ] + tags = Array.new(3) + for i in 0..2 do + + if Tag.exists?(:tagname => tmp[i]) + tags[i] = Tag.where(:tagname => tmp[i]) + else + tags[i] = Tag.new + tags[i].tagname = tmp[i] + tags[i].save + end + @chatroom.tags << tags[i] + end + redirect_to @chatroom + end +end diff --git a/app/controllers/user_has_msg_controller.rb b/app/controllers/user_has_msg_controller.rb new file mode 100644 index 0000000..e75eddf --- /dev/null +++ b/app/controllers/user_has_msg_controller.rb @@ -0,0 +1,42 @@ +class UserHasMsgController < ApplicationController + def new + @receiver = User.find(params[:receiver_id]) + end + + def send2 + @n = UserHasMsg.where(:sender_id => current_user.id ).count + if params[:num] == 'first' + params[:num] = '-9999' + elsif params[:num] == 'last' + params[:num] = '9999' + end + + @@send_msg_num = @@send_msg_num + params[:num].to_i + if @@send_msg_num < 0 + @@send_msg_num = 0 + elsif @@send_msg_num >= @n + @@send_msg_num = @n - 10 > 0 ? @n - 10 : @n + end + @send_msgs = UserHasMsg.where(:sender_id => current_user.id).limit(10).offset(@@send_msg_num) + end + + def recv + if params[:num] == 'first' + params[:num] = '-9999' + elsif params[:num] == 'last' + params[:num] = '9999' + end + + @n = UserHasMsg.where(:receiver_id => current_user.id ).count + @@recv_msg_num = @@recv_msg_num + params[:num].to_i + if @@recv_msg_num < 0 + @@recv_msg_num = 0 + elsif @@recv_msg_num >= @n + @@recv_msg_num = @n - 10 > 0 ? @n - 10 : @n + end + @recv_msgs = UserHasMsg.where(:receiver_id => current_user.id).limit(10).offset(@@recv_msg_num) + end + + def destroy + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c45b739..e18c38c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,6 +7,40 @@ def login end + def home + @has_friends = Friendship.where(:user_id => current_user.id) + @user = current_user + end + + def show + if User.exists?(params[:id]) + @user = User.find(params[:id]) + else + redirect_to :root + end + end + + def add_friend + @user = User.find(params[:id]) + + unless Friendship.exists?(:user_id => current_user.id, :friend_id => params[:id]) + unless Friendship.exists?(:user_id => params[:id], :friend_id => current_user.id) + unless current_user.id == @user.id + friendship = Friendship.new + friendship.user_id = current_user.id + friendship.friend_id = @user.id + friendship.save + + friendship1 = Friendship.new + friendship1.user_id = @user.id + friendship1.friend_id = current_user.id + friendship1.save + end + end + end + + end + def logout cookies.delete(:auth_token) redirect_to :root @@ -33,8 +67,28 @@ def create redirect_to :root end + def edit + @user = current_user + respond_to { |format| format.html } + end + + def update + @user = current_user + if @user.update(info_params) + redirect_to home_path + else + format.html { render :edit } + format.json { render json: @user.errors, status: :unprocessable_entity } + + end + end + private def user_params params.require(:user).permit(:username, :password) end + + def info_params + params.require(:user).permit(:phone, :email, :nickname, :gender, :description, :avatar) + end end diff --git a/app/helpers/chat_app_helper.rb b/app/helpers/chat_app_helper.rb new file mode 100644 index 0000000..d46260a --- /dev/null +++ b/app/helpers/chat_app_helper.rb @@ -0,0 +1,2 @@ +module ChatAppHelper +end diff --git a/app/helpers/chat_log_helper.rb b/app/helpers/chat_log_helper.rb new file mode 100644 index 0000000..56607f6 --- /dev/null +++ b/app/helpers/chat_log_helper.rb @@ -0,0 +1,2 @@ +module ChatLogHelper +end diff --git a/app/helpers/chatapp_helper.rb b/app/helpers/chatapp_helper.rb new file mode 100644 index 0000000..79a5d30 --- /dev/null +++ b/app/helpers/chatapp_helper.rb @@ -0,0 +1,2 @@ +module ChatappHelper +end diff --git a/app/helpers/message_helper.rb b/app/helpers/message_helper.rb new file mode 100644 index 0000000..afbbb4b --- /dev/null +++ b/app/helpers/message_helper.rb @@ -0,0 +1,2 @@ +module MessageHelper +end diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb new file mode 100644 index 0000000..568c90f --- /dev/null +++ b/app/helpers/tag_helper.rb @@ -0,0 +1,2 @@ +module TagHelper +end diff --git a/app/helpers/user_has_msg_helper.rb b/app/helpers/user_has_msg_helper.rb new file mode 100644 index 0000000..1f58ed5 --- /dev/null +++ b/app/helpers/user_has_msg_helper.rb @@ -0,0 +1,2 @@ +module UserHasMsgHelper +end diff --git a/app/models/chat_log.rb b/app/models/chat_log.rb new file mode 100644 index 0000000..f0f0fef --- /dev/null +++ b/app/models/chat_log.rb @@ -0,0 +1,2 @@ +class ChatLog < ActiveRecord::Base +end diff --git a/app/models/chatroom.rb b/app/models/chatroom.rb index fed779b..5952785 100644 --- a/app/models/chatroom.rb +++ b/app/models/chatroom.rb @@ -1,6 +1,8 @@ class Chatroom < ActiveRecord::Base has_many :users, :through => :room_mems has_many :room_mems + has_many :tags, :through => :room_tags + has_many :room_tags before_create { generate_room_no(:roomno) } def generate_room_no(column) @@ -9,6 +11,7 @@ def generate_room_no(column) end while Chatroom.exists?(column => self[column]) end + PRIVACY_TYPES = [['公开', false],['私密', true]] validates :roomname, presence: true validates :roomcover, allow_blank: true, format: { diff --git a/app/models/friendship.rb b/app/models/friendship.rb new file mode 100644 index 0000000..011ee86 --- /dev/null +++ b/app/models/friendship.rb @@ -0,0 +1,7 @@ +class Friendship < ActiveRecord::Base + belongs_to :user + # 其模型并不存在,所以要给出 :class_name 及 :foreign_key 选项。 + # 以让活动记录知道上哪里去找记录。 + belongs_to :friend, :class_name => "User", :foreign_key => "friend_id" + +end diff --git a/app/models/message.rb b/app/models/message.rb new file mode 100644 index 0000000..7132550 --- /dev/null +++ b/app/models/message.rb @@ -0,0 +1,3 @@ +class Message < ActiveRecord::Base + has_one :user_has_msg +end \ No newline at end of file diff --git a/app/models/room_tag.rb b/app/models/room_tag.rb new file mode 100644 index 0000000..ea9bcdb --- /dev/null +++ b/app/models/room_tag.rb @@ -0,0 +1,4 @@ +class RoomTag < ActiveRecord::Base + belongs_to :tag + belongs_to :chatroom +end diff --git a/app/models/roomtag.rb b/app/models/roomtag.rb deleted file mode 100644 index 04bad26..0000000 --- a/app/models/roomtag.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Roomtag < ActiveRecord::Base -end diff --git a/app/models/tag.rb b/app/models/tag.rb index 972262c..d3101a2 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,2 +1,4 @@ class Tag < ActiveRecord::Base + has_many :chatrooms, :through => :room_tags + has_many :room_tags end diff --git a/app/models/user.rb b/app/models/user.rb index 0ed5e32..0d04add 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,8 +1,13 @@ class User < ActiveRecord::Base has_many :chatrooms, :through => :room_mems has_many :room_mems + has_many :friendships + has_many :user_has_msgs + has_many :messages, :through => :user_has_msgs + # 创建 has_many :through 关联,在 friendships 内找寻 friends。 + has_many :friends, :through => :friendships + has_secure_password - before_create { generate_token(:auth_token) } def generate_token(column) diff --git a/app/models/user_has_msg.rb b/app/models/user_has_msg.rb new file mode 100644 index 0000000..3d78cfb --- /dev/null +++ b/app/models/user_has_msg.rb @@ -0,0 +1,5 @@ +class UserHasMsg < ActiveRecord::Base + belongs_to :message + belongs_to :sender, :class_name => "User", :foreign_key => "sender_id" + belongs_to :receiver, :class_name => "User", :foreign_key => "receiver_id" +end diff --git a/app/views/application/search.html.erb b/app/views/application/search.html.erb new file mode 100644 index 0000000..bbcb69a --- /dev/null +++ b/app/views/application/search.html.erb @@ -0,0 +1,47 @@ +
+
+

搜索结果

+
+
+
+
+ + + + + + + + + + + + + + + + + <% @chatroom.each do |chatroom| %> + + + + + + + + + + + + + + + + <% end %> + +
封面聊天室类型流行人数房号创建人创建时间
<%= image_tag(chatroom.roomcover) %><%= chatroom.roomname %><%= chatroom.privacy %><%= chatroom.popularity %><%= chatroom.memnum %><%= chatroom.roomno %> <%= User.find(chatroom.user_id).username %> <%= time_ago_in_words chatroom.created_at %><%= link_to '进入', chatroom %>
<%= sanitize(chatroom.description) %>
+
+
+ <%= link_to '回到外婆桥', :root %> +
+
\ No newline at end of file diff --git a/app/views/chatapp/index.html b/app/views/chatapp/index.html new file mode 100644 index 0000000..e52997d --- /dev/null +++ b/app/views/chatapp/index.html @@ -0,0 +1,105 @@ +
+ + +
+
+
+
+
+ +
+
+
+ +
+
+
+

AndyHsu/CloudChat

+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/app/views/chatrooms/_chatroom.html.erb b/app/views/chatrooms/_chatroom.html.erb index a133dae..a70c84c 100644 --- a/app/views/chatrooms/_chatroom.html.erb +++ b/app/views/chatrooms/_chatroom.html.erb @@ -1,43 +1,20 @@ -

聊天室一览

- - - - - - - - - - - - - - - - - - <% @chatrooms.each do |chatroom| %> - - - - - - - - - - - - - - - - - <% end %> - -
封面聊天室类型流行度人数房间号创建人创建时间
<%= image_tag(chatroom.roomcover) %><%= chatroom.roomname %><%= chatroom.privacy %><%= chatroom.popularity %><%= chatroom.memnum %><%= chatroom.roomno %><%= chatroom.user_id %><%= chatroom.created_at %><%= link_to '查看', chatroom %><%= link_to '编辑', edit_chatroom_path(chatroom) %><%= link_to '删除', chatroom, method: :delete, data: { confirm: 'Are you sure?' } %>
<%= sanitize(chatroom.description) %>
- -
-<% if current_user %> - <%= link_to '新建聊天室', new_chatroom_path %> -<% end %> \ No newline at end of file +
+ <% @chatrooms.each do |chatroom| %> +
+
+ <%= image_tag(chatroom.roomcover) %> +
+

<%= chatroom.roomname %>

+

<%= sanitize(chatroom.description) %>

+
+ <% chatroom.tags.each do |tag| %> + <%= link_to tag.tagname, search_id_path(tag.tagname), method: :post %> + <% end %> +
+
  • <%= chatroom.memnum %> Members
    + <%= link_to 'JOIN', chatroom %> +
    +
    +
    + <% end %> +
    \ No newline at end of file diff --git a/app/views/chatrooms/_chatroom.json.jbuilder b/app/views/chatrooms/_chatroom.json.jbuilder deleted file mode 100644 index 2ac5208..0000000 --- a/app/views/chatrooms/_chatroom.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@chatrooms) do |chatroom| - json.extract! chatroom, :id, :roomname, :roomcover, :privacy, :popularity, :memnum, :roomno, :key, :creatorid - json.url chatroom_url(chatroom, format: :json) -end diff --git a/app/views/chatrooms/_form.html.erb b/app/views/chatrooms/_form.html.erb index ada261e..150dbed 100644 --- a/app/views/chatrooms/_form.html.erb +++ b/app/views/chatrooms/_form.html.erb @@ -11,27 +11,27 @@
    <% end %>
    - <%= f.label :roomname %>
    + <%= f.label "名称" %>
    <%= f.text_field :roomname %>
    - <%= f.label :roomcover %>
    + <%= f.label "封面url" %>
    <%= f.text_field :roomcover %>
    - <%= f.label :description %>
    + <%= f.label "描述" %>
    <%= f.text_area :description, rows: 6 %>
    - <%= f.label :privacy %>
    - <%= f.text_field :privacy %> + <%= f.label "聊天室类型" %>
    + <%= f.select :privacy, Chatroom::PRIVACY_TYPES, :prompt => "是否公开" %>
    - <%= f.label :key %>
    + <%= f.label "密码" %>
    <%= f.number_field :key %>
    - <%= f.submit %> + <%= f.submit "创建" %>
    <% end %> diff --git a/app/views/chatrooms/edit.html.erb b/app/views/chatrooms/edit.html.erb index 8fca74d..9f36e58 100644 --- a/app/views/chatrooms/edit.html.erb +++ b/app/views/chatrooms/edit.html.erb @@ -1,6 +1,13 @@ -

    Editing chatroom

    - -<%= render 'form' %> - -<%= link_to 'Show', @chatroom %> | -<%= link_to 'Back', :root %> +
    +
    +

    编辑聊天室

    +
    +
    +
    +
    + <%= render 'form' %> +
    +
    + <%= link_to '返回', :root %> +
    +
    diff --git a/app/views/chatrooms/list.html.erb b/app/views/chatrooms/list.html.erb new file mode 100644 index 0000000..cc1bccf --- /dev/null +++ b/app/views/chatrooms/list.html.erb @@ -0,0 +1 @@ +<%= render :partial => "chatroom" %> \ No newline at end of file diff --git a/app/views/chatrooms/new.html.erb b/app/views/chatrooms/new.html.erb index 11e8191..2dc35a0 100644 --- a/app/views/chatrooms/new.html.erb +++ b/app/views/chatrooms/new.html.erb @@ -1,5 +1,13 @@ -

    New chatroom

    - -<%= render 'form' %> - -<%= link_to 'Back', :root %> +
    +
    +

    新建聊天室

    +
    +
    +
    +
    + <%= render 'form' %> +
    +
    + <%= link_to '返回', :root %> +
    +
    \ No newline at end of file diff --git a/app/views/chatrooms/show.html.erb b/app/views/chatrooms/show.html.erb index ba78470..d14c569 100644 --- a/app/views/chatrooms/show.html.erb +++ b/app/views/chatrooms/show.html.erb @@ -1,44 +1,41 @@ -

    <%= notice %>

    -

    到时聚聚,聊聊程序

    - -
    -

    - 当前聊天室: - <%= @chatroom.roomname %> - - 聊天室编号: - <%= @chatroom.roomno %> -

    -

    - <%= (@chatroom.description) %> -

    - -
    - <%= image_tag(@chatroom.roomcover) %> +
    +
    +

    到时聚聚,聊聊程序

    -
    -
    -

    - - - 创建人: - <%= @creater.username %> +

    +
    +

    + 当前聊天室: + <%= @chatroom.roomname %> + + 聊天室编号: + <%= @chatroom.roomno %> +

    +

    <%= (@chatroom.description) %>

    - <%= @chatroom.privacy %> +
    <%= image_tag(@chatroom.roomcover) %>
    -

    -

    - 热度: - <%= @chatroom.popularity %> -

    -

    - 人数: - <%= @chatroom.memnum %> +

    + 创建人: + <%= @creater.username %> + <%= @chatroom.privacy %> +

    +

    + 热度: + <%= @chatroom.popularity %> +

    +

    + 人数: + <%= @chatroom.memnum %> +

    +
    +
    + <%= link_to '查看成员列表', room_mem_path %> | + <%= link_to '进入聊天室', enterroom_path(@chatroom.id) %> | + <%= link_to '返回主页', :root %> +
    -

    -<%= link_to '查看成员列表', room_mem_path %> | -<%= link_to '编辑', edit_chatroom_path(@chatroom) %> | -<%= link_to '返回主页', :root %> + diff --git a/app/views/chatrooms/show.json.jbuilder b/app/views/chatrooms/show.json.jbuilder deleted file mode 100644 index d1bd4a5..0000000 --- a/app/views/chatrooms/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @chatroom, :id, :roomname, :roomcover, :description, :privacy, :popularity, :memnum, :roomno, :key, :creatorid, :created_at, :updated_at diff --git a/app/views/homepage/index.html.erb b/app/views/homepage/index.html.erb index 3f51c07..e237877 100644 --- a/app/views/homepage/index.html.erb +++ b/app/views/homepage/index.html.erb @@ -1,10 +1,32 @@ -
    "> - - <%= render :partial => "chatrooms/chatroom" %> + - \ No newline at end of file +
    +
    +

    + Cloud + Chat +

    +

    + Literally chatting in clouds via cloud. +

    +

    + Share ideas and opinions freely and instantly, +

    +

    + collecting & gathering to inspire afflatus and wisdom. +

    +
    <%= link_to "SIGN UP FOR FREE", signup_path %>
    +
    +
    + +
    +

    Explore the chatrooms

    +
    + +
    + <%= render :partial => "chatrooms/chatroom" %> +
    + +<%= render :partial => "shared/footer" %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 92dd2b7..1992509 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,14 +2,15 @@ Cloudchat + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> + <% if params[:controller]=='chatapp' %> + + <% end %> -<%= render :partial => "shared/banner" %> -<%= yield %> - + <%= yield %> - diff --git a/app/views/message/_recv.html.erb b/app/views/message/_recv.html.erb new file mode 100644 index 0000000..2f2d5fa --- /dev/null +++ b/app/views/message/_recv.html.erb @@ -0,0 +1,28 @@ + + + + + + + + + + + + + <% recv_msgs.each do |c| %> + + + + + + + + + + + <% end %> + +
    头像id性别状态最近登录
    <%= image_tag(c.sender.avatar) %><%= link_to c.sender.username, showuser_path(c.sender.id) %><%= c.sender.gender %><%= c.sender.status %><%= time_ago_in_words c.created_at %> ago
    <%= c.message.content %>
    + + diff --git a/app/views/message/_send.html.erb b/app/views/message/_send.html.erb new file mode 100644 index 0000000..e1e0d63 --- /dev/null +++ b/app/views/message/_send.html.erb @@ -0,0 +1,26 @@ + + + + + + + + + + + + + <% send_msgs.each do |c| %> + + + + + + + + + + + <% end %> + +
    头像id性别状态最近登录
    <%= image_tag(c.receiver.avatar)%> <%= link_to c.receiver.username, showuser_path(c.receiver.id) %><%= c.receiver.gender %><%= c.receiver.status %><%= time_ago_in_words c.created_at %> ago
    <%= c.message.content %>
    \ No newline at end of file diff --git a/app/views/message/create.html.erb b/app/views/message/create.html.erb new file mode 100644 index 0000000..bb07345 --- /dev/null +++ b/app/views/message/create.html.erb @@ -0,0 +1,2 @@ +

    信息发送成功

    +<%= link_to '回到外婆桥', :root %> \ No newline at end of file diff --git a/app/views/room_mems/enter.html.erb b/app/views/room_mems/enter.html.erb new file mode 100644 index 0000000..67df472 --- /dev/null +++ b/app/views/room_mems/enter.html.erb @@ -0,0 +1,13 @@ +
    +
    +

    聊天中

    +
    +
    +
    +
    + +
    +
    + <%= link_to '回到外婆桥', :back %> +
    +
    \ No newline at end of file diff --git a/app/views/room_mems/show.html.erb b/app/views/room_mems/show.html.erb index ddc44bd..ce82c7e 100644 --- a/app/views/room_mems/show.html.erb +++ b/app/views/room_mems/show.html.erb @@ -1,31 +1,39 @@ -

    成员一览表

    +
    +
    +

    成员一览表

    +
    +
    +
    +
    + + + + + + + + + + + + -
    头像成员id性别手机号状态最近登录
    - - - - - - - - - - - - - - <% @room_mems.each do |item| %> - - - - - - - - - - <% end %> - -
    头像成员id性别手机号状态最近登录
    <%= image_tag(item.user.avatar) %><%= item.user.username %><%= item.user.gender %><%= item.user.phone %><%= item.user.status %><%= item.user.updated_at %><%= link_to 'Show', "www.baidu.com" %>
    -<%= link_to '回到外婆桥', :root %> -
    \ No newline at end of file + + <% @room_mems.each do |item| %> + + <%= image_tag(item.user.avatar) %> + <%= item.user.username %> + <%= item.user.gender %> + <%= item.user.phone %> + <%= item.user.status %> + <%= time_ago_in_words item.user.updated_at %> + <%= link_to '用户主页', showuser_path(item.user.id) %> + + <% end %> + + +
    +
    + <%= link_to '回到外婆桥', :root %> +
    +
    diff --git a/app/views/shared/_banner.html.erb b/app/views/shared/_banner.html.erb index 73e2c3f..b999426 100644 --- a/app/views/shared/_banner.html.erb +++ b/app/views/shared/_banner.html.erb @@ -1,11 +1,26 @@
    -
    +
    +
    <% if current_user %> -
  • <%= link_to current_user.username, "#" %>
  • -
  • <%= link_to "logout", logout_path, method: "delete" %>
  • - <% else %> -
  • <%= link_to "login", login_path %>
  • -
  • <%= link_to "signup", signup_path %>
  • - <% end %> +
  • <%= link_to current_user.username, home_path %>
  • +
  • <%= link_to "logout", logout_path, method: "delete" %>
  • + <% else %> +
  • <%= link_to "login", login_path %>
  • +
  • <%= link_to "signup", signup_path %>
  • + <% end %> +
    +
    -
    \ No newline at end of file +
    + diff --git a/app/views/shared/_footer.html.erb b/app/views/shared/_footer.html.erb new file mode 100644 index 0000000..0ddc246 --- /dev/null +++ b/app/views/shared/_footer.html.erb @@ -0,0 +1,4 @@ +
    +

    Created and maintained by Andy Hsu and Dean Chen .

    +

    Welcome to fork the project.

    +
    \ No newline at end of file diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb new file mode 100644 index 0000000..4036a12 --- /dev/null +++ b/app/views/shared/_header.html.erb @@ -0,0 +1,14 @@ +
    + +
    \ No newline at end of file diff --git a/app/views/tag/_form.html.erb b/app/views/tag/_form.html.erb new file mode 100644 index 0000000..7da2690 --- /dev/null +++ b/app/views/tag/_form.html.erb @@ -0,0 +1,15 @@ +
    + <%= form_tag after_set_tag_path(@chatroom.id) do %> +
    +
    +

    标签 1

    + <%= text_field_tag "tag1", params[:tag1] %> +

    标签 2

    + <%= text_field_tag "tag2", params[:tag2] %> +

    标签 3

    + <%= text_field_tag "tag3", params[:tag3] %> + <%= submit_tag "提交", :class => "login-button btn btn-primary" %> +
    +
    + <% end %> +
    \ No newline at end of file diff --git a/app/views/tag/set.html.erb b/app/views/tag/set.html.erb new file mode 100644 index 0000000..96486a3 --- /dev/null +++ b/app/views/tag/set.html.erb @@ -0,0 +1 @@ +<%= render 'form' %> \ No newline at end of file diff --git a/app/views/user_has_msg/_form.html.erb b/app/views/user_has_msg/_form.html.erb new file mode 100644 index 0000000..06496d2 --- /dev/null +++ b/app/views/user_has_msg/_form.html.erb @@ -0,0 +1,6 @@ +
    + <%= form_tag("#", method: :post) do %> + <%= text_area_tag(:content) %> + <%= submit_tag '发送', class: 'btn btn-primary btn-submit' %> + <% end %> +
    \ No newline at end of file diff --git a/app/views/user_has_msg/destroy.html.erb b/app/views/user_has_msg/destroy.html.erb new file mode 100644 index 0000000..34a4eb1 --- /dev/null +++ b/app/views/user_has_msg/destroy.html.erb @@ -0,0 +1,2 @@ +

    UserHasMsg#destroy

    +

    Find me in app/views/user_has_msg/destroy.html.erb

    diff --git a/app/views/user_has_msg/new.html.erb b/app/views/user_has_msg/new.html.erb new file mode 100644 index 0000000..300d41b --- /dev/null +++ b/app/views/user_has_msg/new.html.erb @@ -0,0 +1,13 @@ +
    +
    +

    向 <%= @receiver.username %> 发送站内信

    +
    +
    +
    +
    + <%= render partial: 'form' %> +
    +
    + <%= link_to '回到外婆桥', home_path %> +
    +
    diff --git a/app/views/user_has_msg/recv.html.erb b/app/views/user_has_msg/recv.html.erb new file mode 100644 index 0000000..212b4ff --- /dev/null +++ b/app/views/user_has_msg/recv.html.erb @@ -0,0 +1,17 @@ +
    +
    +

    我收到的的站内信

    +
    +
    +
    +
    + <%= render partial: 'message/recv', locals: {recv_msgs: @recv_msgs} %> +
    +
    + <%= link_to '首页', recvmsg_path('first') %> + <%= link_to '上一页', recvmsg_path('-10') %> + <%= link_to '回到外婆桥', home_path %> + <%= link_to '下一页', recvmsg_path('10') %> + <%= link_to '尾页', recvmsg_path('last') %> +
    +
    \ No newline at end of file diff --git a/app/views/user_has_msg/send2.html.erb b/app/views/user_has_msg/send2.html.erb new file mode 100644 index 0000000..98c4c4c --- /dev/null +++ b/app/views/user_has_msg/send2.html.erb @@ -0,0 +1,17 @@ +
    +
    +

    我发送的站内信

    +
    +
    +
    +
    + <%= render partial: 'message/send', locals: {send_msgs: @send_msgs} %> +
    +
    + <%= link_to '首页', sendmsg_path('first') %> + <%= link_to '上一页', sendmsg_path('-10') %> + <%= link_to '回到外婆桥', home_path %> + <%= link_to '下一页', sendmsg_path('10') %> + <%= link_to '尾页', sendmsg_path('last') %> +
    +
    \ No newline at end of file diff --git a/app/views/users/add_friend.html.erb b/app/views/users/add_friend.html.erb new file mode 100644 index 0000000..b7b2d34 --- /dev/null +++ b/app/views/users/add_friend.html.erb @@ -0,0 +1,43 @@ +
    +
    +

    + 用户 + <%= @user.username %> + 的个人主页 +

    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    头像成员id性别手机号状态最近登录
    <%= image_tag(@user.avatar) %><%= @user.username %><%= @user.gender %><%= @user.phone %><%= @user.status %><%= time_ago_in_words @user.updated_at %><%= link_to '站内信', newmsg_path(@user.id) %>
    +
    +
    + <%= link_to '回到外婆桥', :root %> +
    +
    + + diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 0000000..cf1fb69 --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,52 @@ +
    +
    +

    修改信息

    +
    +
    +
    +
    + <%= form_for(@user) do |f| %> + <% if @user.errors.any? %> +
    +

    <%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:

    + +
      + <% @user.errors.full_messages.each do |message| %> +
    • <%= message %>
    • + <% end %> +
    +
    + <% end %> +
    + <%= f.label "手机号" %>
    + <%= f.text_field :phone %> +
    +
    + <%= f.label "邮箱" %>
    + <%= f.text_field :email %> +
    +
    + <%= f.label "昵称" %>
    + <%= f.text_area :nickname %> +
    +
    + <%= f.label "头像" %>
    + <%= f.text_field :avatar %> +
    +
    + <%= f.label "性别" %>
    + <%= f.select :gender,[['男', 0],['女', 1]], {:selected => 0}%> +
    +
    + <%= f.label "描述" %>
    + <%= f.text_area :description %> +
    +
    + <%= f.submit "提交" %> +
    + <% end %> +
    +
    + <%= link_to '回到外婆桥', :root %> +
    +
    \ No newline at end of file diff --git a/app/views/users/home.html.erb b/app/views/users/home.html.erb new file mode 100644 index 0000000..4329b02 --- /dev/null +++ b/app/views/users/home.html.erb @@ -0,0 +1,39 @@ +<%= render :partial => "shared/header" %> +
    +
    +

    好友列表

    +
    +
    +
    +
    + + + + + + + + + + + + <% @has_friends.each do |item| %> + + + + + + + + <% end %> + +
    头像id状态最近登录
    <%= image_tag(item.friend.avatar) %><%= link_to item.friend.username, showuser_path(item.friend.id) %><%= item.friend.status %><%= time_ago_in_words item.friend.updated_at %><%= link_to '站内信', newmsg_path(item.friend.id) %>
    +
    +
    + <%= link_to '我收到的站内信', recvmsg_path('first') %> | + <%= link_to '我发出的站内信', sendmsg_path('first') %> | + <%= link_to '修改个人信息', user_path %> | + <%= link_to '回到外婆桥', :root %> +
    +
    +<%= render :partial => "shared/footer" %> \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000..a32059d --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,43 @@ +
    +
    +

    + 用户 + <%= @user.username %> + 的个人主页 +

    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    头像成员id性别手机号状态最近登录
    <%= image_tag(@user.avatar) %><%= @user.username %><%= @user.gender %><%= @user.phone %><%= @user.status %><%= time_ago_in_words @user.updated_at %><%= button_to '加为好友', addfriend_path(@user.id), :method => :post %>
    +
    +
    + <%= link_to '回到外婆桥', :root %> +
    +
    + + diff --git a/config/routes.rb b/config/routes.rb index 6863a12..95c222b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,13 +1,35 @@ Rails.application.routes.draw do + get 'user_has_msg/new/:receiver_id' => "user_has_msg#new", :as => "newmsg" + post 'user_has_msg/new/:receiver_id' => "message#create" + get 'user_has_msg/destroy' + resources :chatrooms + resources :users, only: [:create] + resources :room_mems + get "signup" => "users#signup", :as => "signup" get "login" => "users#login", :as => "login" post "create_login_session" => "users#create_login_session" delete "logout" => "users#logout", :as => "logout" - resources :users, only: [:create] - - resources :room_mems + + get "home" => "users#home", :as => "home" + get "home/edit" => "users#edit", :as => "user" + patch "home/edit" => "users#update" + + get "home/recvmsg/:num" => "user_has_msg#recv", :as => "recvmsg" + get "home/sendmsg/:num" => "user_has_msg#send2", :as => "sendmsg" + + get "users/:id" => "users#show", :as => "showuser" + post "users/:id" => "users#add_friend", :as => "addfriend" + get "chatrooms/enter/:id" => "room_mems#enter", :as => "enterroom" + post "chatrooms/search/:id" => "application#search", :as => "search_id" + post "chatrooms/search" => "application#search", :as => "search" + + get "chatrooms/settags/:id" => "tag#set", :as => "set_tag" + post "chatrooms/enter/:id" => "tag#afterset", :as => "after_set_tag" + get "chatapp/:name" => "chatapp#index", :as => "chatapp" + root 'homepage#index' # The priority is based upon order of creation: first created -> highest priority. diff --git a/db/migrate/20150603025853_change_default_of_chatroom.rb b/db/migrate/20150603025853_change_default_of_chatroom.rb index ab5a49b..8a5de1d 100644 --- a/db/migrate/20150603025853_change_default_of_chatroom.rb +++ b/db/migrate/20150603025853_change_default_of_chatroom.rb @@ -3,6 +3,5 @@ def change change_column :chatrooms, :roomcover, :string, :default => "assets/images/ruby.jpg" change_column :chatrooms, :popularity, :integer, :default => 1 change_column :chatrooms, :memnum, :integer, :default => 1 - end end \ No newline at end of file diff --git a/db/migrate/20150531105816_drop_chatroom_table.rb b/db/migrate/20150603095905_drop_roomtags.rb similarity index 52% rename from db/migrate/20150531105816_drop_chatroom_table.rb rename to db/migrate/20150603095905_drop_roomtags.rb index dbd8c0b..18a0eea 100644 --- a/db/migrate/20150531105816_drop_chatroom_table.rb +++ b/db/migrate/20150603095905_drop_roomtags.rb @@ -1,6 +1,6 @@ -class DropChatroomTable < ActiveRecord::Migration +class DropRoomtags < ActiveRecord::Migration def up - drop_table :chatrooms + drop_table :roomtags end def down diff --git a/db/migrate/20150603100813_create_room_tags.rb b/db/migrate/20150603100813_create_room_tags.rb new file mode 100644 index 0000000..894c35b --- /dev/null +++ b/db/migrate/20150603100813_create_room_tags.rb @@ -0,0 +1,10 @@ +class CreateRoomTags < ActiveRecord::Migration + def change + create_table :room_tags do |t| + t.integer :chatroom_id + t.integer :tag_id + + t.timestamps + end + end +end diff --git a/db/migrate/20150604064251_create_friendships.rb b/db/migrate/20150604064251_create_friendships.rb new file mode 100644 index 0000000..0e350f0 --- /dev/null +++ b/db/migrate/20150604064251_create_friendships.rb @@ -0,0 +1,10 @@ +class CreateFriendships < ActiveRecord::Migration + def change + create_table :friendships do |t| + t.integer :user_id + t.integer :friend_id + + t.timestamps + end + end +end diff --git a/db/migrate/20150605124119_create_user_has_msgs.rb b/db/migrate/20150605124119_create_user_has_msgs.rb new file mode 100644 index 0000000..0c19bf7 --- /dev/null +++ b/db/migrate/20150605124119_create_user_has_msgs.rb @@ -0,0 +1,14 @@ +class CreateUserHasMsgs < ActiveRecord::Migration + def change + create_table :user_has_msgs do |t| + t.integer :message_id + t.integer :sender_id + t.integer :receiver_id + t.boolean :send_status + t.boolean :receive_status + t.boolean :is_read + + t.timestamps + end + end +end diff --git a/db/migrate/20150605124306_create_messages.rb b/db/migrate/20150605124306_create_messages.rb new file mode 100644 index 0000000..c57f5a1 --- /dev/null +++ b/db/migrate/20150605124306_create_messages.rb @@ -0,0 +1,9 @@ +class CreateMessages < ActiveRecord::Migration + def change + create_table :messages do |t| + t.text :content + + t.timestamps + end + end +end diff --git a/db/migrate/20150606072748_change_message.rb b/db/migrate/20150606072748_change_message.rb new file mode 100644 index 0000000..75920c0 --- /dev/null +++ b/db/migrate/20150606072748_change_message.rb @@ -0,0 +1,6 @@ +class ChangeMessage < ActiveRecord::Migration + def change + add_column :messages, :user_has_msgs, :integer + remove_column :user_has_msgs, :message_id + end +end diff --git a/db/migrate/20150606073331_set_default_message.rb b/db/migrate/20150606073331_set_default_message.rb new file mode 100644 index 0000000..55f941e --- /dev/null +++ b/db/migrate/20150606073331_set_default_message.rb @@ -0,0 +1,7 @@ +class SetDefaultMessage < ActiveRecord::Migration + def change + change_column :user_has_msgs, :send_status, :boolean, :default => false + change_column :user_has_msgs, :receive_status, :boolean, :default => false + change_column :user_has_msgs, :is_read, :boolean, :default => false + end +end diff --git a/db/migrate/20150606074026_rename_table.rb b/db/migrate/20150606074026_rename_table.rb new file mode 100644 index 0000000..9f18241 --- /dev/null +++ b/db/migrate/20150606074026_rename_table.rb @@ -0,0 +1,5 @@ +class RenameTable < ActiveRecord::Migration + def change + rename_column :messages, :user_has_msgs, :user_has_msg_id + end +end diff --git a/db/migrate/20150606074936_change_table.rb b/db/migrate/20150606074936_change_table.rb new file mode 100644 index 0000000..6ac8c1f --- /dev/null +++ b/db/migrate/20150606074936_change_table.rb @@ -0,0 +1,6 @@ +class ChangeTable < ActiveRecord::Migration + def change + add_column :user_has_msgs, :message_id, :integer + remove_column :messages, :user_has_msg_id + end +end diff --git a/db/migrate/20150606102120_create_chat_logs.rb b/db/migrate/20150606102120_create_chat_logs.rb new file mode 100644 index 0000000..d61d205 --- /dev/null +++ b/db/migrate/20150606102120_create_chat_logs.rb @@ -0,0 +1,12 @@ +class CreateChatLogs < ActiveRecord::Migration + def change + create_table :chat_logs do |t| + t.integer :user_id + t.integer :chatroom_id + t.text :content + t.string :msg_tag + + t.timestamps + end + end +end diff --git a/db/migrate/20150609120828_setdefault.rb b/db/migrate/20150609120828_setdefault.rb new file mode 100644 index 0000000..3f1e38f --- /dev/null +++ b/db/migrate/20150609120828_setdefault.rb @@ -0,0 +1,5 @@ +class Setdefault < ActiveRecord::Migration + def change + change_column :chatrooms, :roomcover, :string, :default => "ruby.jpg" + end +end diff --git a/db/schema.rb b/db/schema.rb index 121c41d..53dc5c7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,20 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150603052523) do +ActiveRecord::Schema.define(version: 20150609120828) do + + create_table "chat_logs", force: true do |t| + t.integer "user_id" + t.integer "chatroom_id" + t.text "content" + t.string "msg_tag" + t.datetime "created_at" + t.datetime "updated_at" + end create_table "chatrooms", force: true do |t| t.string "roomname" - t.string "roomcover", default: "app/assets/images/ruby.jpg" + t.string "roomcover", default: "ruby.jpg" t.boolean "privacy" t.integer "popularity", default: 1 t.integer "memnum", default: 1 @@ -27,6 +36,19 @@ t.text "description" end + create_table "friendships", force: true do |t| + t.integer "user_id" + t.integer "friend_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "messages", force: true do |t| + t.text "content" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "room_mems", force: true do |t| t.integer "chatroom_id" t.integer "user_id" @@ -34,9 +56,9 @@ t.datetime "updated_at" end - create_table "roomtags", force: true do |t| - t.integer "chatroomid" - t.integer "tagid" + create_table "room_tags", force: true do |t| + t.integer "chatroom_id" + t.integer "tag_id" t.datetime "created_at" t.datetime "updated_at" end @@ -47,6 +69,17 @@ t.datetime "updated_at" end + create_table "user_has_msgs", force: true do |t| + t.integer "sender_id" + t.integer "receiver_id" + t.boolean "send_status", default: false + t.boolean "receive_status", default: false + t.boolean "is_read", default: false + t.datetime "created_at" + t.datetime "updated_at" + t.integer "message_id" + end + create_table "users", force: true do |t| t.string "username" t.string "phone" diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..906c050 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # @@ -5,3 +6,90 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + +# Clear the Database +User.delete_all +Tag.delete_all +Chatroom.delete_all +RoomTag.delete_all +RoomMem.delete_all +Message.delete_all +UserHasMsg.delete_all +Friendship.delete_all +ChatLog.delete_all + +names = ['python', 'ruby', 'python2', 'cpp', 'h5', 'grunt', 'angular', 'java', 'haskell', 'lisp', 'lua', 'node', 'bower'] +tagnames = ['UCLA', 'UCSD' , 'USC', 'MIT', 'Stanford', 'Harvad', 'UIUC'] + +# Add Test Users +for i in 1..100 do + r = Random.rand(13) + User.create(username: 'User'+i.to_s, avatar: names[r]+'.jpg', password:'123456') +end + + +# Add Test Chatrooms + +for i in 1..100 do + r = Random.rand(13) + Chatroom.create(roomname: names[r], + roomcover: names[r]+'.jpg', + privacy: r&1 == 1? 'true' : 'false', + memnum: '20', + description:'Dummy '*Random.rand(3)+'Foo '*Random.rand(3), + user_id: 1+Random.rand(100), + popularity: Random.rand(100), + key: r&1 == 1? '1234' : '') +end + +tags = [] +for item in tagnames do + t = Tag.create(tagname: item) + tags << t +end + +for i in 1..100 do + chatroom = Chatroom.find(i) + chatroom.tags = [] + chatroom.tags << tags[Random.rand(7)] + for j in 1..3 do + if Random.rand(100)>50 + chatroom.tags << tags[Random.rand(7)] + end + end +end + +# Add Test RoomMem +for i in 1..100 do + chatroom = Chatroom.find(i) + for j in 1..20 do + user = User.find(j) + chatroom.users << user + end +end + +# Add Test Friendship +for i in 1..100 do + user = User.find(i) + for j in 1..5 do + user2 = User.find(Random.rand(100)+1) + user.friends << user2 + end +end + +# Add Test Message +for i in 1..10 do + user = User.find(i) + for j in 1..5 do + user2 = User.find(Random.rand(100)+1) + msg = Message.create(content: names[Random.rand(13)]) + + u_h_m = UserHasMsg.new + u_h_m.sender = user + u_h_m.receiver = user2 + u_h_m.message = msg + msg.user_has_msg = u_h_m + u_h_m.save + msg.save + end +end \ No newline at end of file diff --git a/public/andy.png b/public/andy.png new file mode 100644 index 0000000..8d7a731 Binary files /dev/null and b/public/andy.png differ diff --git a/public/lib/backbone-min.js b/public/lib/backbone-min.js new file mode 100644 index 0000000..8ea4b13 --- /dev/null +++ b/public/lib/backbone-min.js @@ -0,0 +1,2 @@ +(function(t,e){if(typeof define==="function"&&define.amd){define(["underscore","jquery","exports"],function(i,r,s){t.Backbone=e(t,s,i,r)})}else if(typeof exports!=="undefined"){var i=require("underscore");e(t,exports,i)}else{t.Backbone=e(t,{},t._,t.jQuery||t.Zepto||t.ender||t.$)}})(this,function(t,e,i,r){var s=t.Backbone;var n=[];var a=n.push;var o=n.slice;var h=n.splice;e.VERSION="1.1.2";e.$=r;e.noConflict=function(){t.Backbone=s;return this};e.emulateHTTP=false;e.emulateJSON=false;var u=e.Events={on:function(t,e,i){if(!c(this,"on",t,[e,i])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});return this},once:function(t,e,r){if(!c(this,"once",t,[e,r])||!e)return this;var s=this;var n=i.once(function(){s.off(t,n);e.apply(this,arguments)});n._callback=e;return this.on(t,n,r)},off:function(t,e,r){var s,n,a,o,h,u,l,f;if(!this._events||!c(this,"off",t,[e,r]))return this;if(!t&&!e&&!r){this._events=void 0;return this}o=t?[t]:i.keys(this._events);for(h=0,u=o.length;h").attr(t);this.setElement(r,false)}else{this.setElement(i.result(this,"el"),false)}}});e.sync=function(t,r,s){var n=T[t];i.defaults(s||(s={}),{emulateHTTP:e.emulateHTTP,emulateJSON:e.emulateJSON});var a={type:n,dataType:"json"};if(!s.url){a.url=i.result(r,"url")||M()}if(s.data==null&&r&&(t==="create"||t==="update"||t==="patch")){a.contentType="application/json";a.data=JSON.stringify(s.attrs||r.toJSON(s))}if(s.emulateJSON){a.contentType="application/x-www-form-urlencoded";a.data=a.data?{model:a.data}:{}}if(s.emulateHTTP&&(n==="PUT"||n==="DELETE"||n==="PATCH")){a.type="POST";if(s.emulateJSON)a.data._method=n;var o=s.beforeSend;s.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",n);if(o)return o.apply(this,arguments)}}if(a.type!=="GET"&&!s.emulateJSON){a.processData=false}if(a.type==="PATCH"&&k){a.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")}}var h=s.xhr=e.ajax(i.extend(a,s));r.trigger("request",r,h,s);return h};var k=typeof window!=="undefined"&&!!window.ActiveXObject&&!(window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent);var T={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};e.ajax=function(){return e.$.ajax.apply(e.$,arguments)};var $=e.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var S=/\((.*?)\)/g;var H=/(\(\?)?:\w+/g;var A=/\*\w+/g;var I=/[\-{}\[\]+?.,\\\^$|#\s]/g;i.extend($.prototype,u,{initialize:function(){},route:function(t,r,s){if(!i.isRegExp(t))t=this._routeToRegExp(t);if(i.isFunction(r)){s=r;r=""}if(!s)s=this[r];var n=this;e.history.route(t,function(i){var a=n._extractParameters(t,i);n.execute(s,a);n.trigger.apply(n,["route:"+r].concat(a));n.trigger("route",r,a);e.history.trigger("route",n,r,a)});return this},execute:function(t,e){if(t)t.apply(this,e)},navigate:function(t,i){e.history.navigate(t,i);return this},_bindRoutes:function(){if(!this.routes)return;this.routes=i.result(this,"routes");var t,e=i.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(I,"\\$&").replace(S,"(?:$1)?").replace(H,function(t,e){return e?t:"([^/?]+)"}).replace(A,"([^?]*?)");return new RegExp("^"+t+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(t,e){var r=t.exec(e).slice(1);return i.map(r,function(t,e){if(e===r.length-1)return t||null;return t?decodeURIComponent(t):null})}});var N=e.History=function(){this.handlers=[];i.bindAll(this,"checkUrl");if(typeof window!=="undefined"){this.location=window.location;this.history=window.history}};var R=/^[#\/]|\s+$/g;var O=/^\/+|\/+$/g;var P=/msie [\w.]+/;var C=/\/$/;var j=/#.*$/;N.started=false;i.extend(N.prototype,u,{interval:50,atRoot:function(){return this.location.pathname.replace(/[^\/]$/,"$&/")===this.root},getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=decodeURI(this.location.pathname+this.location.search);var i=this.root.replace(C,"");if(!t.indexOf(i))t=t.slice(i.length)}else{t=this.getHash()}}return t.replace(R,"")},start:function(t){if(N.started)throw new Error("Backbone.history has already been started");N.started=true;this.options=i.extend({root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var r=this.getFragment();var s=document.documentMode;var n=P.exec(navigator.userAgent.toLowerCase())&&(!s||s<=7);this.root=("/"+this.root+"/").replace(O,"/");if(n&&this._wantsHashChange){var a=e.$('