From 7624f9949f9096fb4d5e62a05b05f2eabf3274ea Mon Sep 17 00:00:00 2001 From: Ngoc Hoang Date: Wed, 11 Sep 2019 15:38:41 +0700 Subject: [PATCH] Rating room --- Gemfile | 1 + Gemfile.lock | 2 + app/assets/images/big-star.png | Bin 0 -> 8089 bytes app/assets/images/cancel-off.png | Bin 0 -> 699 bytes app/assets/images/cancel-on.png | Bin 0 -> 715 bytes app/assets/images/mid-star.png | Bin 0 -> 6335 bytes app/assets/javascripts/application.js | 2 + app/assets/javascripts/jquery.raty.js | 119 +++++++++--------- app/assets/javascripts/ratyrate.js.erb | 62 +++++++++ app/controllers/comments_controller.rb | 2 +- app/controllers/rater_controller.rb | 14 +++ app/controllers/rooms_controller.rb | 1 - app/models/average_cache.rb | 4 + app/models/overall_average.rb | 4 + app/models/rate.rb | 7 ++ app/models/rating_cache.rb | 3 + app/models/room.rb | 1 + app/models/user.rb | 2 + app/views/comments/_comment.html.slim | 1 - app/views/rooms/show.html.slim | 4 +- config/routes.rb | 1 + ...62013_delete_column_rate_point_for_room.rb | 9 ++ .../20190911062258_create_rating_caches.rb | 19 +++ db/migrate/20190911062259_create_rates.rb | 19 +++ .../20190911062260_create_average_caches.rb | 17 +++ .../20190911062261_create_overall_averages.rb | 16 +++ ...08_delete_column_rate_for_table_comment.rb | 9 ++ db/schema.rb | 49 +++++++- 28 files changed, 299 insertions(+), 69 deletions(-) create mode 100644 app/assets/images/big-star.png create mode 100644 app/assets/images/cancel-off.png create mode 100644 app/assets/images/cancel-on.png create mode 100644 app/assets/images/mid-star.png create mode 100644 app/assets/javascripts/ratyrate.js.erb create mode 100644 app/controllers/rater_controller.rb create mode 100644 app/models/average_cache.rb create mode 100644 app/models/overall_average.rb create mode 100644 app/models/rate.rb create mode 100644 app/models/rating_cache.rb create mode 100644 db/migrate/20190911062013_delete_column_rate_point_for_room.rb create mode 100644 db/migrate/20190911062258_create_rating_caches.rb create mode 100644 db/migrate/20190911062259_create_rates.rb create mode 100644 db/migrate/20190911062260_create_average_caches.rb create mode 100644 db/migrate/20190911062261_create_overall_averages.rb create mode 100644 db/migrate/20190911063508_delete_column_rate_for_table_comment.rb diff --git a/Gemfile b/Gemfile index 39e75a7..8ddb1b6 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,7 @@ gem "jquery-ui-rails" gem "bootstrap-datepicker-rails", "~> 1.8", ">= 1.8.0.1" gem "country_select", "~> 4.0" gem "jquery-validation-rails" +gem "ratyrate" group :development, :test do gem "byebug", platforms: %i[mri mingw x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 94bf5ca..ee3e020 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -249,6 +249,7 @@ GEM activesupport (>= 5.0) i18n polyamorous (= 2.3.0) + ratyrate (1.2.2.alpha) rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) @@ -386,6 +387,7 @@ DEPENDENCIES puma (~> 3.11) rails (~> 5.2.3) ransack + ratyrate rspec-rails (~> 3.8) rubocop (~> 0.74.0) sass-rails (~> 5.0) diff --git a/app/assets/images/big-star.png b/app/assets/images/big-star.png new file mode 100644 index 0000000000000000000000000000000000000000..9304638ad3b533ca1ea2417d3e013808f61c0de1 GIT binary patch literal 8089 zcmV;KA7KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ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z$d26!?p$C6ke45}*BVJeU~O2gHc$JDa0=*4vyG*(|#~)9nkeCTXzSz zGKcOqy|&k2=MXwc+D_VRvCS0%F=-XH8n@TG-Qf0M+#c$5j{W@6`d2T$cH7q!<THYHs88 z{$6hl8WD$L@mxa^Jr#-btHyD_RKTkuP8Gav#Op!4UTWI&)XyFbZ+_=TzI*F09v!Zw z-*LiOcigyP{fe8f{NRx%Z+u?QYb)-=0O2?qjU&+{*2b2M)QG3v5t8%;i$+N}7Nqg+ z`ndeFdqoR#I<($SStEo=K(Cn?$w8c?tnF41uM2Uz5Wg4kdI_ZGv2DMY`TSeo_su(= zcxp1F;6`qb{C0Huv~#}kmDMXdzJASzjy(Ql8~1)gmp{3$2IELH4t5H)Q>e~hNk9_e zrb}AmXaSy#D-KzBM%+Dy@BLExF@o{&%{5=6mkEz2ZA}eC#7fAN9(^_kLq<*VI88j3Ra- zzO4Y$sGUX$uo4m5X>!LATVIb>*^6bf*A$Ryl_8l{G-+@XCtg8gycB9L;;&#j z>bm!b+s6Lsb?^A{-OSMdSO8i8Q>#aM?#18!4sh3XA3gf86aRScGgfrW9H!wI*s*wZ zrB0z*N5v3lmLpWdC69I8Mb=w=>Bhk>*D+n{c!=A9I1XYAj@Jc#FUDV?=l!_o&j8{e7717vCb<37-{ozv=UUu6fasEc zy!VTDeCM%IihF)bdw*$Nq@BMKB}g6nVCeECvY z?tI|3Tk+%OtVStrqRv}t8Cco?E{Y)XfV0{gmM;Wu{w6?P z#%jr(R8avlU&x%RlQ7eC&~m#0(&cYDZCB;?vu~e+^?+^_nJiom;TN`EqXo5LC%BDhlxc$ z@Um_0PJ)HjHW$soEYsA5o?zJxZzKcPWTK0rW3tZ%V0VEhm}% literal 0 HcmV?d00001 diff --git a/app/assets/images/cancel-off.png b/app/assets/images/cancel-off.png new file mode 100644 index 0000000000000000000000000000000000000000..a3031f055375716b848c29191cabf6253b936379 GIT binary patch literal 699 zcmV;s0!00ZP)LlQBzMVHAd+8!Cx7n4ko2BpKR*l8~R!U*RTd z-KC3@i{RwscE?Or>7D!)-4qlQMGUEfL=(Km2!<>7e((2nscB0J9em*|hwptkhx2@% zbB?#@9f0R~!$uf}AB-`J&bbvyGuB!pb*#0!lD@62t+ig?I_L15bHjiz3>S+9fx3`mlMX0u7HR>SkWlB6Yo%&%RRecz|k z>G1UQM7!Ol*X!~4`1n@=JUl#5tyYn=JiLOW*=#mTx7)=S!|LklKTpX-R`T3bfqw!C(=Xn$g1v;G$#+deS0%Ocx zv)QCjD3GQpV`F0@W@{|~#bS};<71q2dw;I5Z>_z(xVT_`ejb2KCc`T%)><-|4E1`Q z!^1=3IKGv%5BvscXJ=4|#1P83Dl-```crC2O7H8sW2(GjgyYar=!5CjJ! zC~t3XFGvaizgDY}&*uS%qKK1|6XH0&lk_DBf>D%TwY9bNLDHfzX2m%-BMD01y4qo3(5`U!bUg@nP|I3oZ6002ovPDHLkV1f)gL$Ck< literal 0 HcmV?d00001 diff --git a/app/assets/images/cancel-on.png b/app/assets/images/cancel-on.png new file mode 100644 index 0000000000000000000000000000000000000000..08f249365afd29594b51210c6e21ba253897505d GIT binary patch literal 715 zcmV;+0yO=JP)C4}Mrzlg<+1Y8PEBfUp0jJpx4B>@E+cy3`^(Gw`Mf+2&yxZm<$to~Vpgvg&QKNR z_f#1(r6svZt%iF?s+n<8X?B&!h3g9Dbb8_=MX}!;HiQSAh`bp^WMl~Z-44teO7W_Y zV4thSL{h;rJY7!l3%5J4H1!tIzB`Dv+YxO(haWeausGZYkI8^hWj6mzo=L0{%;yxzh{5!Htr?51 zvG|W62MzC8BZ76hRpCyO2zOn<%e)K>NHge!-~)Ap33OdWw6hsLYbCxGNt0%wk_2z7 zfyYvXheSG)5HRK1VB~%mq7Dmurw#bi@hEcOr3&G1ZiF*$M=&9nB#VNf&Q^r$4G5kp zTURh&s)E0%5&hyVD}sp<72~zmAY`Y(9aqO6CXF%=zFHGzO-A&I(pE}v70YQxCPJ{Y z4L+?5-crdLn3ZRPEs!A4ehEY3ZRpL~w9>@aMN+{F4dI@v&>(QDHQum!mG~E^$OS8l z!7?%Uwib*ROP67Hw`ika)gX-(8Ia`-u_IEhxG7U<13kSsMW+$lbb2dUMm5p6pa}cjgA+U$^mJ^AjD?&bdi)8~y+Q002ovPDHLkV1g8IMc@Dc literal 0 HcmV?d00001 diff --git a/app/assets/images/mid-star.png b/app/assets/images/mid-star.png new file mode 100644 index 0000000000000000000000000000000000000000..aebb3ccb5b6c851512227f11ad01c0c106a441b9 GIT binary patch literal 6335 zcmV;w7(nNVP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMM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>y!N9L8jtMeV&qYgOg zaav0t)A{|B1>e_|oxLhDSJBxEQL^r>8Mlblye6QPh5tWLSADq(_(N${<$fFs-fFMy z-@O*Vdx5S4CY8b0wZ&9?sQ}l?l946+#!)%`ZvfcVtmQ8-%WePw002ovPDHLkV1luP BNg@CM literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 539f5bb..6ad41ce 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,6 +13,8 @@ //= require bootstrap-datepicker //= require jquery.validate //= require jquery.validate.additional-methods +//= require jquery.raty +//= require ratyrate /*global toastr*/ toastr.options = { diff --git a/app/assets/javascripts/jquery.raty.js b/app/assets/javascripts/jquery.raty.js index 103a935..c583651 100644 --- a/app/assets/javascripts/jquery.raty.js +++ b/app/assets/javascripts/jquery.raty.js @@ -3,12 +3,13 @@ * * The MIT License * - * author: Washington Botelho - * github: wbotelhos/raty - * version: 2.9.0 + * @author : Washington Botelho + * @doc : http://wbotelhos.com/raty + * @version : 2.7.0 * */ +; (function($) { 'use strict'; @@ -19,7 +20,7 @@ methods.destroy.call(this.self); - this.opt = $.extend(true, {}, $.fn.raty.defaults, options, this.self.data()); + this.opt = $.extend(true, {}, $.fn.raty.defaults, options); methods._adjustCallback.call(this); methods._adjustNumber.call(this); @@ -58,7 +59,7 @@ }, _adjustCallback: function() { - var options = ['number', 'readOnly', 'score', 'scoreName', 'target', 'path']; + var options = ['number', 'readOnly', 'score', 'scoreName', 'target']; for (var i = 0; i < options.length; i++) { if (typeof this.opt[options[i]] === 'function') { @@ -234,9 +235,8 @@ }, _bindOver: function() { - var - that = this, - action = that.opt.half ? 'mousemove.raty' : 'mouseover.raty'; + var that = this, + action = that.opt.half ? 'mousemove.raty' : 'mouseover.raty'; that.stars.on(action, function(evt) { var score = methods._getScoreByPosition.call(that, evt, this); @@ -288,9 +288,8 @@ }, _createCancel: function() { - var - icon = this.opt.path + this.opt.cancelOff, - cancel = $('<' + this.opt.starType + ' />', { title: this.opt.cancelHint, 'class': this.opt.cancelClass }); + var icon = this.opt.path + this.opt.cancelOff, + cancel = $('<' + this.opt.starType + ' />', { title: this.opt.cancelHint, 'class': this.opt.cancelClass }); if (this.opt.starType === 'img') { cancel.attr({ src: icon, alt: 'x' }); @@ -462,16 +461,15 @@ return this.opt.score && this.opt.score >= i ? 'starOn' : 'starOff'; }, - _resetTitle: function() { + _resetTitle: function(star) { for (var i = 0; i < this.opt.number; i++) { this.stars[i].title = methods._getHint.call(this, i + 1); } }, - _roundHalfScore: function(score) { - var - integer = parseInt(score, 10), - decimal = methods._getFirstDecimal.call(this, score); + _roundHalfScore: function(score) { + var integer = parseInt(score, 10), + decimal = methods._getFirstDecimal.call(this, score); if (decimal !== 0) { decimal = decimal > 5 ? 1 : 0.5; @@ -483,16 +481,16 @@ _roundStars: function(score, evt) { var decimal = (score % 1).toFixed(2), - name ; + name ; if (evt || this.move) { name = decimal > 0.5 ? 'starOn' : 'starHalf'; - } else if (decimal > this.opt.round.down) { // Up: [x.76 .. x.99] + } else if (decimal > this.opt.round.down) { // Up: [x.76 .. x.99] name = 'starOn'; if (this.opt.halfShow && decimal < this.opt.round.up) { // Half: [x.26 .. x.75] name = 'starHalf'; - } else if (decimal < this.opt.round.full) { // Down: [x.00 .. x.5] + } else if (decimal < this.opt.round.full) { // Down: [x.00 .. x.5] name = 'starOff'; } } @@ -503,7 +501,7 @@ star = this.stars[Math.ceil(score) - 1]; methods._setIcon.call(this, star, icon); - } // Full down: [x.00 .. x.25] + } // Full down: [x.00 .. x.25] }, _setIcon: function(star, icon) { @@ -615,9 +613,8 @@ destroy: function() { return this.each(function() { - var - self = $(this), - raw = self.data('raw'); + var self = $(this), + raw = self.data('raw'); if (raw) { self.off('.raty').empty().css({ cursor: raw.style.cursor }).removeData('readonly'); @@ -628,9 +625,8 @@ }, getScore: function() { - var - score = [], - value ; + var score = [], + value ; this.each(function() { value = this.score.val(); @@ -673,7 +669,7 @@ if (self.data('readonly') !== readonly) { if (readonly) { - self.off('.raty').children(this.opt.starType).off('.raty'); + self.off('.raty').children('img').off('.raty'); methods._lock.call(this); } else { @@ -725,39 +721,40 @@ }; $.fn.raty.defaults = { - cancel: false, - cancelClass: 'raty-cancel', - cancelHint: 'Cancel this rating!', - cancelOff: 'cancel-off.png', - cancelOn: 'cancel-on.png', - cancelPlace: 'left', - click: undefined, - half: false, - halfShow: true, - hints: ['bad', 'poor', 'regular', 'good', 'gorgeous'], - iconRange: undefined, - mouseout: undefined, - mouseover: undefined, - noRatedMsg: 'Not rated yet!', - number: 5, - numberMax: 20, - path: undefined, - precision: false, - readOnly: false, - round: { down: 0.25, full: 0.6, up: 0.76 }, - score: undefined, - scoreName: 'score', - single: false, - space: true, - starHalf: 'star-half.png', - starOff: 'star-off.png', - starOn: 'star-on.png', - starType: 'img', - target: undefined, - targetFormat: '{score}', - targetKeep: false, - targetScore: undefined, - targetText: '', - targetType: 'hint' + cancel : false, + cancelClass : 'raty-cancel', + cancelHint : 'Cancel this rating!', + cancelOff : 'cancel-off.png', + cancelOn : 'cancel-on.png', + cancelPlace : 'left', + click : undefined, + half : false, + halfShow : true, + hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'], + iconRange : undefined, + mouseout : undefined, + mouseover : undefined, + noRatedMsg : 'Not rated yet!', + number : 5, + numberMax : 20, + path : undefined, + precision : false, + readOnly : false, + round : { down: 0.25, full: 0.6, up: 0.76 }, + score : undefined, + scoreName : 'score', + single : false, + space : true, + starHalf : 'star-half.png', + starOff : 'star-off.png', + starOn : 'star-on.png', + starType : 'img', + target : undefined, + targetFormat : '{score}', + targetKeep : false, + targetScore : undefined, + targetText : '', + targetType : 'hint' }; + })(jQuery); diff --git a/app/assets/javascripts/ratyrate.js.erb b/app/assets/javascripts/ratyrate.js.erb new file mode 100644 index 0000000..bdf21db --- /dev/null +++ b/app/assets/javascripts/ratyrate.js.erb @@ -0,0 +1,62 @@ +$.fn.raty.defaults.half = false; +$.fn.raty.defaults.halfShow = true; +$.fn.raty.defaults.path = "/assets"; +$.fn.raty.defaults.cancel = false; + +$(function(){ + $(".star").each(function() { + var $readonly = ($(this).attr('data-readonly') == 'true'); + var $half = ($(this).attr('data-enable-half') == 'true'); + var $halfShow = ($(this).attr('data-half-show') == 'true'); + var $single = ($(this).attr('data-single') == 'true'); + $(this).raty({ + score: function() { + return $(this).attr('data-rating') + }, + number: function() { + return $(this).attr('data-star-count') + }, + half: $half, + halfShow: $halfShow, + single: $single, + path: $(this).attr('data-star-path'), + starOn: $(this).attr('data-star-on'), + starOff: $(this).attr('data-star-off'), + starHalf: $(this).attr('data-star-half'), + cancel: $(this).attr('data-cancel'), + cancelPlace: $(this).attr('data-cancel-place'), + cancelHint: $(this).attr('data-cancel-hint'), + cancelOn: $(this).attr('data-cancel-on'), + cancelOff: $(this).attr('data-cancel-off'), + noRatedMsg: $(this).attr('data-no-rated-message'), + round: $(this).attr('data-round'), + space: $(this).attr('data-space'), + target: $(this).attr('data-target'), + targetText: $(this).attr('data-target-text'), + targetType: $(this).attr('data-target-type'), + targetFormat: $(this).attr('data-target-format'), + targetScoret: $(this).attr('data-target-score'), + readOnly: $readonly, + click: function(score, evt) { + var _this = this; + if (score == null) { score = 0; } + $.post('<%= Rails.application.class.routes.url_helpers.rate_path %>', + { + score: score, + dimension: $(this).attr('data-dimension'), + id: $(this).attr('data-id'), + klass: $(this).attr('data-classname') + }, + function(data) { + if(data) { + // success code goes here ... + + if ($(_this).attr('data-disable-after-rate') == 'true') { + $(_this).raty('set', { readOnly: true, score: score }); + } + } + }); + } + }); + }); +}); diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 8b45b0d..d5594e8 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -30,7 +30,7 @@ def destroy private def comment_params - params.require(:comment).permit :rate, :content + params.require(:comment).permit :content end def load_room diff --git a/app/controllers/rater_controller.rb b/app/controllers/rater_controller.rb new file mode 100644 index 0000000..a6d775a --- /dev/null +++ b/app/controllers/rater_controller.rb @@ -0,0 +1,14 @@ +class RaterController < ApplicationController + skip_before_action :verify_authenticity_token + + def create + if user_signed_in? + obj = params[:klass].classify.constantize.find(params[:id]) + obj.rate params[:score].to_f, current_user, params[:dimension] + + render :json => true + else + render :json => false + end + end +end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index e59ee35..1b4cfd2 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -19,7 +19,6 @@ def show rooms.each{|rooms| @rooms << Room.find(rooms)} @comment = @room.comments.build @comments = @room.comments.newest - @average_comment = @room.comments.average(:rate) if @room.comments.present? end def create diff --git a/app/models/average_cache.rb b/app/models/average_cache.rb new file mode 100644 index 0000000..f9edf03 --- /dev/null +++ b/app/models/average_cache.rb @@ -0,0 +1,4 @@ +class AverageCache < ActiveRecord::Base + belongs_to :rater, :class_name => "User" + belongs_to :rateable, :polymorphic => true +end diff --git a/app/models/overall_average.rb b/app/models/overall_average.rb new file mode 100644 index 0000000..16acb68 --- /dev/null +++ b/app/models/overall_average.rb @@ -0,0 +1,4 @@ +class OverallAverage < ActiveRecord::Base + belongs_to :rateable, :polymorphic => true +end + diff --git a/app/models/rate.rb b/app/models/rate.rb new file mode 100644 index 0000000..4eabbff --- /dev/null +++ b/app/models/rate.rb @@ -0,0 +1,7 @@ +class Rate < ActiveRecord::Base + belongs_to :rater, :class_name => "User" + belongs_to :rateable, :polymorphic => true + + #attr_accessible :rate, :dimension + +end \ No newline at end of file diff --git a/app/models/rating_cache.rb b/app/models/rating_cache.rb new file mode 100644 index 0000000..1a2b2eb --- /dev/null +++ b/app/models/rating_cache.rb @@ -0,0 +1,3 @@ +class RatingCache < ActiveRecord::Base + belongs_to :cacheable, :polymorphic => true +end \ No newline at end of file diff --git a/app/models/room.rb b/app/models/room.rb index eda6a22..6ae1e81 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -28,6 +28,7 @@ class Room < ApplicationRecord enum type_room: { Nhà_Riêng: 0, Căn_Hộ: 1 } accepts_nested_attributes_for :room_images, allow_destroy: true + ratyrate_rateable "rating_room" delegate :name, to: :area, prefix: true delegate :name, to: :favorite_space, prefix: true diff --git a/app/models/user.rb b/app/models/user.rb index bcd0386..b9ba62d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,6 +13,8 @@ class User < ApplicationRecord validates :type, presence: true mount_uploader :avatar, AvatarUploader + ratyrate_rater + def timeout_in Settings.time_out.minutes end diff --git a/app/views/comments/_comment.html.slim b/app/views/comments/_comment.html.slim index 3879763..9966e46 100644 --- a/app/views/comments/_comment.html.slim +++ b/app/views/comments/_comment.html.slim @@ -2,7 +2,6 @@ div[id="comment_#{comment.id}"] div b = comment.user.name | : - .review-rating [id="rate_#{comment.id}" data-score="#{comment.rate}"] .review-comment = comment.content .small = time_ago_in_words(comment.created_at) diff --git a/app/views/rooms/show.html.slim b/app/views/rooms/show.html.slim index 102cd17..941d38e 100644 --- a/app/views/rooms/show.html.slim +++ b/app/views/rooms/show.html.slim @@ -25,8 +25,8 @@ .number-code = t ".code_room" | #{@room.code_room} - .average_review-rating [data-score="#{@average_comment}"] - + .rating + = rating_for @room, "rating_room", disable_after_rate: false, enable_half: true .detail-location svg.svg-icon.svg-fill style=("width: 24px; height: 24px;") version="1.1" viewbox=("0 0 24 24") g fill="none" fill-rule="evenodd" diff --git a/config/routes.rb b/config/routes.rb index 00fd588..20e157e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true Rails.application.routes.draw do + post '/rate' => 'rater#create', :as => 'rate' root "home#index" get "/favorite_spaces/:id", to: "home#show" get "/autocomplete", to: "search#show" diff --git a/db/migrate/20190911062013_delete_column_rate_point_for_room.rb b/db/migrate/20190911062013_delete_column_rate_point_for_room.rb new file mode 100644 index 0000000..e546e5b --- /dev/null +++ b/db/migrate/20190911062013_delete_column_rate_point_for_room.rb @@ -0,0 +1,9 @@ +class DeleteColumnRatePointForRoom < ActiveRecord::Migration[5.2] + def self.up + remove_column :rooms, :rate_point + end + + def self.down + add_column :rooms, :rate_point, :decimal + end +end diff --git a/db/migrate/20190911062258_create_rating_caches.rb b/db/migrate/20190911062258_create_rating_caches.rb new file mode 100644 index 0000000..71c5848 --- /dev/null +++ b/db/migrate/20190911062258_create_rating_caches.rb @@ -0,0 +1,19 @@ +class CreateRatingCaches < ActiveRecord::Migration[5.2] + + def self.up + create_table :rating_caches do |t| + t.belongs_to :cacheable, :polymorphic => true + t.float :avg, :null => false + t.integer :qty, :null => false + t.string :dimension + t.timestamps + end + + add_index :rating_caches, [:cacheable_id, :cacheable_type] + end + + def self.down + drop_table :rating_caches + end + +end \ No newline at end of file diff --git a/db/migrate/20190911062259_create_rates.rb b/db/migrate/20190911062259_create_rates.rb new file mode 100644 index 0000000..561606c --- /dev/null +++ b/db/migrate/20190911062259_create_rates.rb @@ -0,0 +1,19 @@ +class CreateRates < ActiveRecord::Migration[5.2] + + def self.up + create_table :rates do |t| + t.belongs_to :rater + t.belongs_to :rateable, :polymorphic => true + t.float :stars, :null => false + t.string :dimension + t.timestamps + end + + add_index :rates, [:rateable_id, :rateable_type] + end + + def self.down + drop_table :rates + end + +end \ No newline at end of file diff --git a/db/migrate/20190911062260_create_average_caches.rb b/db/migrate/20190911062260_create_average_caches.rb new file mode 100644 index 0000000..335cba2 --- /dev/null +++ b/db/migrate/20190911062260_create_average_caches.rb @@ -0,0 +1,17 @@ +class CreateAverageCaches < ActiveRecord::Migration[5.2] + + def self.up + create_table :average_caches do |t| + t.belongs_to :rater + t.belongs_to :rateable, :polymorphic => true + t.float :avg, :null => false + t.timestamps + end + end + + def self.down + drop_table :average_caches + end + +end + diff --git a/db/migrate/20190911062261_create_overall_averages.rb b/db/migrate/20190911062261_create_overall_averages.rb new file mode 100644 index 0000000..a803eaf --- /dev/null +++ b/db/migrate/20190911062261_create_overall_averages.rb @@ -0,0 +1,16 @@ +class CreateOverallAverages < ActiveRecord::Migration[5.2] + + def self.up + create_table :overall_averages do |t| + t.belongs_to :rateable, :polymorphic => true + t.float :overall_avg, :null => false + t.timestamps + end + end + + def self.down + drop_table :overall_averages + end + +end + diff --git a/db/migrate/20190911063508_delete_column_rate_for_table_comment.rb b/db/migrate/20190911063508_delete_column_rate_for_table_comment.rb new file mode 100644 index 0000000..70157a9 --- /dev/null +++ b/db/migrate/20190911063508_delete_column_rate_for_table_comment.rb @@ -0,0 +1,9 @@ +class DeleteColumnRateForTableComment < ActiveRecord::Migration[5.2] + def self.up + remove_column :comments, :rate + end + + def self.down + add_column :comments, :rate, :decimal + end +end diff --git a/db/schema.rb b/db/schema.rb index 4b61227..8a3caaa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_09_09_044921) do +ActiveRecord::Schema.define(version: 2019_09_11_063508) do create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "name", null: false @@ -49,6 +49,17 @@ t.index ["location_id"], name: "index_areas_on_location_id" end + create_table "average_caches", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| + t.bigint "rater_id" + t.string "rateable_type" + t.bigint "rateable_id" + t.float "avg", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["rateable_type", "rateable_id"], name: "index_average_caches_on_rateable_type_and_rateable_id" + t.index ["rater_id"], name: "index_average_caches_on_rater_id" + end + create_table "bills", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.bigint "voucher_id" t.bigint "price_id" @@ -89,7 +100,6 @@ t.bigint "user_id" t.bigint "room_id" t.string "content" - t.integer "rate" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["room_id"], name: "index_comments_on_room_id" @@ -126,6 +136,15 @@ t.datetime "updated_at", null: false end + create_table "overall_averages", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| + t.string "rateable_type" + t.bigint "rateable_id" + t.float "overall_avg", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["rateable_type", "rateable_id"], name: "index_overall_averages_on_rateable_type_and_rateable_id" + end + create_table "prices", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.decimal "cost", precision: 8, scale: 2 t.decimal "cleaning_fee", precision: 8, scale: 2, default: "0.0" @@ -135,6 +154,31 @@ t.index ["room_id"], name: "index_prices_on_room_id" end + create_table "rates", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| + t.bigint "rater_id" + t.string "rateable_type" + t.bigint "rateable_id" + t.float "stars", null: false + t.string "dimension" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["rateable_id", "rateable_type"], name: "index_rates_on_rateable_id_and_rateable_type" + t.index ["rateable_type", "rateable_id"], name: "index_rates_on_rateable_type_and_rateable_id" + t.index ["rater_id"], name: "index_rates_on_rater_id" + end + + create_table "rating_caches", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| + t.string "cacheable_type" + t.bigint "cacheable_id" + t.float "avg", null: false + t.integer "qty", null: false + t.string "dimension" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["cacheable_id", "cacheable_type"], name: "index_rating_caches_on_cacheable_id_and_cacheable_type" + t.index ["cacheable_type", "cacheable_id"], name: "index_rating_caches_on_cacheable_type_and_cacheable_id" + end + create_table "room_images", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.bigint "room_id" t.string "image" @@ -157,7 +201,6 @@ t.bigint "location_id" t.string "name" t.string "address" - t.decimal "rate_point", precision: 10 t.text "description" t.integer "guest" t.integer "type_room", default: 0