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
+
+[](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| %>
+
+
<%= 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) %>
+
+
+ <% end %>
+
+
+
+
+
<%= 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 @@
-
\ 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 @@
-
\ 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
+
性别
+
手机号
+
状态
+
最近登录
+
+
+
-
-
-
-
头像
-
成员id
-
性别
-
手机号
-
状态
-
最近登录
-
-
-
-
-
- <% @room_mems.each do |item| %>
-
-
<%= 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" %>
-
- <% end %>
-
-
-
<%= link_to '回到外婆桥', :root %>
-
\ No newline at end of file
+
+ <% @room_mems.each do |item| %>
+
\ 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 %>
+
\ 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 @@
+
\ 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 @@
+
\ 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 @@
+
\ 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 @@
+