From db173d5a4be713030e4d504e1926189be9f6dd07 Mon Sep 17 00:00:00 2001
From: Gleb Rysev <gr00314@surrey.ac.uk>
Date: Fri, 7 May 2021 17:53:24 +0100
Subject: [PATCH] Minor visuals and fixes

---
 app/controllers/rooms_controller.rb   |   2 +
 app/views/home/home.html.erb          | 102 +++++++++---------
 app/views/leaderboards/index.html.erb |  94 ++++++++---------
 app/views/leaderboards/new.html.erb   |  10 +-
 app/views/leaderboards/show.html.erb  | 142 +++++++++++++-------------
 app/views/rooms/index.html.erb        |   8 +-
 config/locales/en.yml                 |  11 ++
 7 files changed, 195 insertions(+), 174 deletions(-)

diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb
index 3007caf..ac2bdf1 100644
--- a/app/controllers/rooms_controller.rb
+++ b/app/controllers/rooms_controller.rb
@@ -33,6 +33,8 @@ class RoomsController < ApplicationController
   end
 
   def show
+    @rooms = Room.where(leaderboard: Leaderboard.where(board_users: BoardUser.where(user: current_user, status: "accepted")))
+    
     if Room.where(id: @room.id,leaderboard: Leaderboard.where(board_users: BoardUser.where(user: current_user, status: "accepted"))).exists?
       @room_message = RoomMessage.new room: @room
       @room_messages = @room.room_messages.includes(:user)
diff --git a/app/views/home/home.html.erb b/app/views/home/home.html.erb
index 4d8273c..48599ac 100644
--- a/app/views/home/home.html.erb
+++ b/app/views/home/home.html.erb
@@ -9,57 +9,6 @@
   <div class="Insp_Quote"></div><br>
 </div>
 <div class="d-flex justify-content-center">
-
-  <script>
-    Cookies.set('name', 'value');
-    var Text = ""
-    var Auth = ""
-    var ImgURL = ""
-
-    if (Cookies.get('visible') == "false") {
-      $(".Insp_Pic").hide();
-      $(".Insp_Quote").hide();
-      Cookies.set("visible", "false");
-    }
-
-    $("#expand-hidden").click(function () {
-      if (Cookies.get('visible') != "false") {
-        $(".Insp_Pic").hide();
-        $(".Insp_Quote").hide();
-        Cookies.set("visible", "false");
-        $("#expand-hidden").html("Show cute dogs");
-      } else {
-        $(".Insp_Pic").show();
-        $(".Insp_Quote").show();
-        Cookies.set("visible", "true");
-        $("#expand-hidden").html("<i class='fa fa-window-close fa-lg'></i>");
-      }
-
-    });
-
-    fetch("https://dog.ceo/api/breeds/image/random")
-        .then(function(response) {
-            return response.json();
-        })
-        .then(function(data) {
-            console.log(data.message);
-            ImgURL = data.message;
-            $(".Insp_Pic").attr("src",ImgURL);
-        });
-    fetch("https://type.fit/api/quotes")
-        .then(function(response) {
-            return response.json();
-        })
-        .then(function(data) {
-            let quote = data[Math.floor(Math.random() * data.length)];
-            Text = quote.text;
-            Auth = quote.author;
-            $(".Insp_Quote").text(Text + " - " + Auth + "\n");
-            $(".Insp_Quote").css({
-              'width': ($(".Insp_Pic").width() + 'px')
-            });
-        });
-  </script>
 </div>
 <div class="container-md">
     <%unless current_user.habits.nil? %>
@@ -69,3 +18,54 @@
       <%= javascript_pack_tag 'react_habitCard' %>
     <%end%>
 </div>
+
+<script>
+  Cookies.set('name', 'value');
+  var Text = ""
+  var Auth = ""
+  var ImgURL = ""
+
+  if (Cookies.get('visible') == "false") {
+    $(".Insp_Pic").hide();
+    $(".Insp_Quote").hide();
+    Cookies.set("visible", "false");
+  }
+
+  $("#expand-hidden").click(function () {
+    if (Cookies.get('visible') != "false") {
+      $(".Insp_Pic").hide();
+      $(".Insp_Quote").hide();
+      Cookies.set("visible", "false");
+      $("#expand-hidden").html("Show cute dogs");
+    } else {
+      $(".Insp_Pic").show();
+      $(".Insp_Quote").show();
+      Cookies.set("visible", "true");
+      $("#expand-hidden").html("<i class='fa fa-window-close fa-lg'></i>");
+    }
+
+  });
+
+  fetch("https://dog.ceo/api/breeds/image/random")
+      .then(function(response) {
+          return response.json();
+      })
+      .then(function(data) {
+          console.log(data.message);
+          ImgURL = data.message;
+          $(".Insp_Pic").attr("src",ImgURL);
+      });
+  fetch("https://type.fit/api/quotes")
+      .then(function(response) {
+          return response.json();
+      })
+      .then(function(data) {
+          let quote = data[Math.floor(Math.random() * data.length)];
+          Text = quote.text;
+          Auth = quote.author;
+          $(".Insp_Quote").text(Text + " - " + Auth + "\n");
+          $(".Insp_Quote").css({
+            'width': ($(".Insp_Pic").width() + 'px')
+          });
+      });
+</script>
diff --git a/app/views/leaderboards/index.html.erb b/app/views/leaderboards/index.html.erb
index db8dcf9..7205aa6 100644
--- a/app/views/leaderboards/index.html.erb
+++ b/app/views/leaderboards/index.html.erb
@@ -1,49 +1,51 @@
-<h2>Active Leaderboards</h2>
-<table class = "table table-striped table-dark">
-  <thead class = "thead-light">
-    <tr>
-      <th>Title</th><th>Interactions</th><th></th><th></th>
-    </tr>
-  </thead>
-  <tbody>
-    <% @leaderboards.each do |leaderboard| %>
+<div class="container-md">
+  <h2><%= t(".active_leaderboards") %></h2>
+  <table class = "table table-striped table-dark">
+    <thead class = "thead-light">
       <tr>
-        <td>
-          <%= leaderboard.title %>
-        </td>
-        <td><%= link_to 'Show', leaderboard %></td>
-        <td><%= link_to 'Edit', edit_leaderboard_path(leaderboard) %></td>
-        <td><%= link_to 'Destroy', leaderboard, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+        <th><%= t(".title") %></th><th><%= t(".interactions") %></th><th></th><th></th>
       </tr>
-    <% end %>
-  </tbody>
-</table>
-<hr>
-<br>
-<%= link_to 'New Leaderboard', new_leaderboard_path %>
-<br>
-<hr>
-<h2>Join a leaderboard</h2>
-<%=form_tag joinWcode_path, method: :post do%>
-  <%= label_tag("Invite Code") %>
-  <%= text_field_tag('code')%>
-  <%= submit_tag("Join")%>
-<%end %>
-<hr>
-<%invites = BoardUser.where(status: "pending", user_id:current_user.id) %>
-<%unless invites.empty?%>
-  <h2>Pending Invites</h2>
-  <table>
-    <th>Name</th><th>Description</th> <th></th> <th></th>
-    <%invites.each do |invite|%>
-      <tr>
-        <td><h6><%=invite.leaderboard.title%></h6></td>
-        <td><h6><%=invite.leaderboard.description%></h6></td>
-        <td><%=button_to "Accept", acceptInvite_path, method: :post, class:"btn btn-info",
-                         params: {:id => invite.id}%></td>
-        <td><%=button_to "Reject", rejectInvite_path, method: :post, class:"btn btn-info",
-                         params: {:id => invite.id}%></td>
-      </tr>
-    <%end%>
+    </thead>
+    <tbody>
+      <% @leaderboards.each do |leaderboard| %>
+        <tr>
+          <td>
+            <%= leaderboard.title %>
+          </td>
+          <td><%= link_to 'Show', leaderboard %></td>
+          <td><%= link_to 'Edit', edit_leaderboard_path(leaderboard) %></td>
+          <td><%= link_to 'Destroy', leaderboard, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+        </tr>
+      <% end %>
+    </tbody>
   </table>
-<%end%>
\ No newline at end of file
+  <hr>
+  <br>
+  <%= link_to 'New Leaderboard', new_leaderboard_path %>
+  <br>
+  <hr>
+  <h2>Join a leaderboard</h2>
+  <%=form_tag joinWcode_path, method: :post do%>
+    <%= label_tag("Invite Code") %>
+    <%= text_field_tag('code')%>
+    <%= submit_tag("Join")%>
+  <%end %>
+  <hr>
+  <%invites = BoardUser.where(status: "pending", user_id:current_user.id) %>
+  <%unless invites.empty?%>
+    <h2>Pending Invites</h2>
+    <table>
+      <th>Name</th><th>Description</th> <th></th> <th></th>
+      <%invites.each do |invite|%>
+        <tr>
+          <td><h6><%=invite.leaderboard.title%></h6></td>
+          <td><h6><%=invite.leaderboard.description%></h6></td>
+          <td><%=button_to "Accept", acceptInvite_path, method: :post, class:"btn btn-info",
+                           params: {:id => invite.id}%></td>
+          <td><%=button_to "Reject", rejectInvite_path, method: :post, class:"btn btn-info",
+                           params: {:id => invite.id}%></td>
+        </tr>
+      <%end%>
+    </table>
+  <%end%>
+</div>
diff --git a/app/views/leaderboards/new.html.erb b/app/views/leaderboards/new.html.erb
index d75a405..cea6d71 100644
--- a/app/views/leaderboards/new.html.erb
+++ b/app/views/leaderboards/new.html.erb
@@ -1,5 +1,7 @@
-<div class="container text-center custom-page-heading">
-  <%= link_to t('.back'), leaderboards_path, :class => "btn float-left habit-back-btn" %>
-  <h1>New Leaderboard</h1>
+<div class="container-md">
+  <div class="container text-center custom-page-heading">
+    <%= link_to t('.back'), leaderboards_path, :class => "btn float-left habit-back-btn" %>
+    <h1><%= t(".new_leaderboard") %></h1>
+  </div>
+  <%= render 'form', leaderboard: @leaderboard %>
 </div>
-<%= render 'form', leaderboard: @leaderboard %>
diff --git a/app/views/leaderboards/show.html.erb b/app/views/leaderboards/show.html.erb
index 4f4f526..4274b76 100644
--- a/app/views/leaderboards/show.html.erb
+++ b/app/views/leaderboards/show.html.erb
@@ -1,75 +1,77 @@
-<h1><%=@room.leaderboard.title%></h1>
-<h3><%=@leaderboard.description%></h3>
-<%= link_to t('.leaderboard_chat'), room_path(@room), class: 'btn btn-info btn-md' %>
-<table class="table table-striped table-dark">
-  <thead>
-  <tr>
-    <th>Rank</th><th></th><th>Name</th><th>Score</th>
-  </tr>
-  </thead>
-  <tbody>
-  <%if @leaderboard == Leaderboard.find_by_id(0)%>
-    <%get_all_users(@leaderboard) %>
-    <%end %>
-  <%@users = sort_users(@leaderboard) %>
-  <% @users.each_with_index do |user,i| %>
+<div class="container-md">
+  <h1><%=@room.leaderboard.title%></h1>
+  <h3><%=@leaderboard.description%></h3>
+  <%= link_to t('.leaderboard_chat'), room_path(@room), class: 'btn btn-info btn-md' %>
+  <table class="table table-striped table-dark">
+    <thead>
     <tr>
-      <td><%= i + 1 %></td>
-      <td>
-        <%unless user.image.nil?%>
-          <%= image_tag user.image %>
-        <%end %>
-      </td>
-      <td>
-        <%if user.name.nil?%>
-          <%= user.email%>
-        <%else %>
-          <%= user.name %>
-        <%end %>
-      </td>
-      <td>
-        <%=
-          score = @leaderboard.board_users.find_by(user: user).score
-          if score.nil?
-            0
-          else
-            score
-          end
-        %>
-      </td>
+      <th>Rank</th><th></th><th>Name</th><th>Score</th>
     </tr>
-  <% end %>
-  </tbody>
-</table>
-<br/>
-<hr>
-<%unless current_user.auths.empty? %>
-  <h3>Invite Your Friends</h3>
-  <table>
-    <th></th><th></th>
-    <%data = User.get_friends(session[:fb_token])%>
-    <%data.each do |person|%>
+    </thead>
+    <tbody>
+    <%if @leaderboard == Leaderboard.find_by_id(0)%>
+      <%get_all_users(@leaderboard) %>
+      <%end %>
+    <%@users = sort_users(@leaderboard) %>
+    <% @users.each_with_index do |user,i| %>
       <tr>
-        <td><h5><%=person['name'] %></h5></td>
-        <td><%=button_to "Invite", inviteUser_path, method: :post, class:"btn btn-info",
-                         params: {:name => person['name'], :leaderboard => @leaderboard.id}%></td>
+        <td><%= i + 1 %></td>
+        <td>
+          <%unless user.image.nil?%>
+            <%= image_tag user.image %>
+          <%end %>
+        </td>
+        <td>
+          <%if user.name.nil?%>
+            <%= user.email%>
+          <%else %>
+            <%= user.name %>
+          <%end %>
+        </td>
+        <td>
+          <%=
+            score = @leaderboard.board_users.find_by(user: user).score
+            if score.nil?
+              0
+            else
+              score
+            end
+          %>
+        </td>
       </tr>
-    <%end%>
+    <% end %>
+    </tbody>
   </table>
-<%end %>
-<button class="btn btn-info codeGen-button"> Generate Invite Code </button>
-<script>
-    let lbID = <%=@leaderboard.id.to_s%>;
-    let lbTitle = "<%=@leaderboard.title.to_s%>";
-    let gener = <%=current_user.id.to_s.to_s%>;
-    $(document).ready(function(){
-        $(".codeGen-button").on("click", e => {
-            if(lbTitle.length > 10){lbTitle = lbTitle.substring(0,10)}
-            let invCode = (lbID+"|"+lbTitle+"|"+gener).toString();
-            $(".InvCode").text("Your Invite Code is: "+invCode);
-        })
-    })
-</script>
-<h3 class="InvCode"></h3>
-<%=button_to "Leave the Board", leaveBoard_path, method: :post, class:"btn btn-info",
-             params: {:id => @leaderboard.id}%>
+  <br/>
+  <hr>
+  <%unless current_user.auths.empty? %>
+    <h3>Invite Your Friends</h3>
+    <table>
+      <th></th><th></th>
+      <%data = User.get_friends(session[:fb_token])%>
+      <%data.each do |person|%>
+        <tr>
+          <td><h5><%=person['name'] %></h5></td>
+          <td><%=button_to "Invite", inviteUser_path, method: :post, class:"btn btn-info",
+                           params: {:name => person['name'], :leaderboard => @leaderboard.id}%></td>
+        </tr>
+      <%end%>
+    </table>
+  <%end %>
+  <button class="btn btn-info codeGen-button"> Generate Invite Code </button>
+  <script>
+      let lbID = <%=@leaderboard.id.to_s%>;
+      let lbTitle = "<%=@leaderboard.title.to_s%>";
+      let gener = <%=current_user.id.to_s.to_s%>;
+      $(document).ready(function(){
+          $(".codeGen-button").on("click", e => {
+              if(lbTitle.length > 10){lbTitle = lbTitle.substring(0,10)}
+              let invCode = (lbID+"|"+lbTitle+"|"+gener).toString();
+              $(".InvCode").text("Your Invite Code is: "+invCode);
+          })
+      })
+  </script>
+  <h3 class="InvCode"></h3>
+  <%=button_to "Leave the Board", leaveBoard_path, method: :post, class:"btn btn-info",
+               params: {:id => @leaderboard.id}%>
+</div>
diff --git a/app/views/rooms/index.html.erb b/app/views/rooms/index.html.erb
index cf60979..4257457 100644
--- a/app/views/rooms/index.html.erb
+++ b/app/views/rooms/index.html.erb
@@ -1,5 +1,7 @@
-<div class="row">
-  <div class="col-12 col-md-3">
-    <%= render partial: 'rooms' %>
+<div class="container-md">
+  <div class="row">
+    <div class="col-12 col-md-3">
+      <%= render partial: 'rooms' %>
+    </div>
   </div>
 </div>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index f3bea93..79d962f 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -6,6 +6,9 @@ en:
     registrations:
       edit:
         back: Back
+        cancel_account: Cancel account
+        push_me: Push me
+        unsubscribe: Unsubscribe
     sessions:
       new:
         email: Email
@@ -23,6 +26,9 @@ en:
   errors:
     messages:
       not_saved: Not saved
+  goals:
+    showgoals:
+      back: Back
   habits:
     edit:
       back: Back
@@ -71,8 +77,13 @@ en:
       leaderboard_title: Leaderboard title
       target_placeholder: Target placeholder
       title_placeholder: Title placeholder
+    index:
+      active_leaderboards: Active leaderboards
+      interactions: Interactions
+      title: Title
     new:
       back: Back
+      new_leaderboard: New leaderboard
     show:
       leaderboard_chat: Leaderboard chat
   rooms:
-- 
GitLab