Browse Source

Miscellaneous fixes

Unknown 7 years ago
parent
commit
f5da99051b
6 changed files with 118 additions and 27 deletions
  1. 15 22
      canvas/index.php
  2. 34 3
      canvas/js/canvas.js
  3. 1 1
      canvas/js/dashboard.js
  4. 1 1
      canvas/php/dashboard.php
  5. 67 0
      canvas/php/look-for-collaborators.php
  6. BIN
      icon/favicon.ico

+ 15 - 22
canvas/index.php

@@ -89,16 +89,9 @@
                         <div class="dropdown collaborators">
                             <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1">
                             <!-- <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> -->
-                                <img src="../icon/collaborators.svg" alt="collaborators" /><span>Collaborators (0 Online)</span>
+                                <img src="../icon/collaborators.svg" alt="collaborators" /><span>Collaborators (0 active)</span>
                                 <!-- <span class="caret"></span> -->
                             </button>
-                            <!--
-                            <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
-                                <li><a id="toDashboard" href="php/dashboard.php">Add/Remove Members</a></li>
-                                <li role="separator" class="divider"></li>
-                                <li><a id="logout" href="#">View Online Members (0)</a></li>
-                            </ul>
-                            -->
                         </div>
                         <?php } ?>
                     </div>
@@ -789,7 +782,7 @@
                                 <label>Send this canvas to:</label>
                             </p>
                             <p>
-                                <input type="email" name="share-canvas-email" placeholder="type an email adress here..."/>
+                                <input type="email" name="share-canvas-email" placeholder="Please enter an email address..."/>
                             </p>
                             <p class="text-center">
                                 <button class="share_canvas_send" type="button" name="share-canvas-send">Send</button>
@@ -904,43 +897,43 @@
                     </h2>
                     <table>
                         <tr>
-                            <th>Online</th><th>Name</th><th>Username</th><th>Remove</th>
+                            <th>Active</th><th>Name</th><th>Username</th><th>Remove</th>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"></td><td>Arturo Calvo</td><td>arturo.calvo@adaptcentre.ie</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"></td><td>Arturo Calvo</td><td>arturo.calvo@adaptcentre.ie</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"><span class="glyphicon glyphicon-ok-sign"></span></td><td>Conal Cosgrove</td><td>conalc86@gmail.com</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"><span class="glyphicon glyphicon-ok-sign"></span></td><td>Conal Cosgrove</td><td>conalc86@gmail.com</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"></td><td>Danny</td><td>dkoning@protonmail.com</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"></td><td>Danny</td><td>dkoning@protonmail.com</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"><span class="glyphicon glyphicon-ok-sign"></span></td><td>Dave Lewis</td><td>dave.lewis@adaptcentre.ie</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"><span class="glyphicon glyphicon-ok-sign"></span></td><td>Dave Lewis</td><td>dave.lewis@adaptcentre.ie</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"></td><td>dylan terry</td><td>dylanterry2@gmail.com</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"></td><td>dylan terry</td><td>dylanterry2@gmail.com</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"></td><td>Firebird</td><td>gormlemi@tcd.ie</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"></td><td>Firebird</td><td>gormlemi@tcd.ie</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"></td><td>Gary Gunn</td><td>ggunn@tcd.ie</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"></td><td>Gary Gunn</td><td>ggunn@tcd.ie</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"></td><td>hugh</td><td>eganhu@tcd.ie</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"></td><td>hugh</td><td>eganhu@tcd.ie</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"><span class="glyphicon glyphicon-ok-sign"></span></td><td>Kaytlin Chaloner</td><td>chalonek@tcd.ie</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"><span class="glyphicon glyphicon-ok-sign"></span></td><td>Kaytlin Chaloner</td><td>chalonek@tcd.ie</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"></td><td>owen</td><td>414owen@mailinator.com</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"></td><td>owen</td><td>414owen@mailinator.com</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                         <tr>
-                            <td class="collaborators-online"></td><td>Paul Culhane</td><td>culhanp@tcd.ie</td><td class="collaborators-online"><span class="glyphicon glyphicon-remove-sign"></span></td>
+                            <td class="collaborators-active"></td><td>Paul Culhane</td><td>culhanp@tcd.ie</td><td class="collaborators-active"><span class="glyphicon glyphicon-remove-sign"></span></td>
                         </tr>
                     </table>
-                    <label><input type="checkbox" name="show-only-online" /> Show only online collaborators</label><br />
+                    <label><input type="checkbox" name="show-only-active" /> Show only active collaborators</label><br />
                     <button type="button" class="window-button" id="add-collaborator">Add collaborator</button>
                 </div>
                 <!-- End of Collaborators -->

+ 34 - 3
canvas/js/canvas.js

@@ -6,6 +6,9 @@ $(document).ready(function() {
     // Declare the currently loaded tags belonging to the user
     var tags;
     
+    // Declare current user
+    var username = $("input[name='username']").val();
+    
     // Fixes bug when added item field zooms on tag click
     var tagWindowIsOpen = false;
     
@@ -113,6 +116,12 @@ $(document).ready(function() {
         }
     });
     
+    /* ================================================
+    Collaborative features
+    ================================================= */
+    
+    
+    
     /* ================================================
     Collaborators window
     ================================================= */
@@ -137,6 +146,29 @@ $(document).ready(function() {
         closeCollaboratorsWindow();
     });
     
+    // When the user checks the "Show only active collaborators" checkbox
+    $("input[name='show-only-active']").on("change", function() {
+        // If the user only wants to see active collaborators
+        if($(this).is(":checked")) {
+            // For every collaborator
+            $("div#collaborators-window tr").each(function() {
+                // If this collaborator is offline
+                if($(this).find("td:nth-child(1)").html() === "") {
+                    // Hide this collaborator
+                    $(this).css("display", "none")
+                }
+            });
+        }
+        // If the user only wants to all active collaborators
+        else {
+            // For every collaborator
+            $("div#collaborators-window tr").each(function() {
+                // Show this collaborator
+                $(this).css("display", "table-row");
+            });
+        }
+    });
+
     /* ================================================
     "Jump to" functions
     ================================================= */
@@ -419,7 +451,6 @@ $(document).ready(function() {
     // Get the tags from the database
     function getTags() {
         // Declarations
-        var username = $("input[name='username']").val();
         
         // AJAX
         $.ajax({
@@ -1745,12 +1776,12 @@ $(document).ready(function() {
             var canvas_id = data;
             // send this canvas_id with the next ajax requestedto the php/canvas.php file and use it as the name of the json file to be saved
             
-            // Give the user feedback that the canvas is saved
+            // Give the user feedback that the canvas has been saved
             if (data !== 400 || data !== 401) {
                 if ($('.imp-exp-btn ').find(".save-canvas-feedback") !== null) {
                     $('.imp-exp-btn ').find(".save-canvas-feedback").remove();
                 }
-                $('.canvas-form').find('.imp-exp-btn ').append('<div class="save-canvas-feedback"><p><span class="glyphicon glyphicon-ok" aria-hidden="true"></span>Your canvas is saved in your dashbord</p></div>');
+                $('.canvas-form').find('.imp-exp-btn ').append('<div class="save-canvas-feedback"><p><span class="glyphicon glyphicon-ok" aria-hidden="true"></span>Your canvas has been saved in your dashbord</p></div>');
                 // remove the canvas is saves message as soon as user changes the canvas
                 // $('.canvas-form').on("change keyup", 'textarea', function() {
                 $('.canvas-form').on("change keyup", '.expandable', function() {

+ 1 - 1
canvas/js/dashboard.js

@@ -47,7 +47,7 @@ $(function() {
                 canvas_color_index = index % 5;
             }
 
-            var canvasGalleryHTML = '<div class="canvas-gallery-item col-md-4 col-sm-6 text-center" id="' + canvasItem.canvas_id + '"><div  class="col-md-12 color' + canvas_color_index + '"><h4>Canvas Title:</h4><h3>' + canvasItem.canvas_name + '</h3><p>created: </p><p>' + canvasItem.canvas_date + '</p></div><button type="button" class="remove-canvas"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span>Remove</button></div>';
+            var canvasGalleryHTML = '<div class="canvas-gallery-item col-md-4 col-sm-6 text-center" id="' + canvasItem.canvas_id + '"><div class="col-md-12 color' + canvas_color_index + '"><h4>Canvas Title:</h4><h3>' + canvasItem.canvas_name + '</h3><p>Created:</p><p>' + canvasItem.canvas_date + '</p></div><button type="button" class="remove-canvas"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span>Remove</button></div>';
             //the added divs are appended to the outer gallery div .user-canvas-gallery
             $('.user-dashboard').find('.user-canvas-gallery').append(canvasGalleryHTML);
         }); // end of $.each loop for the user canvas data

+ 1 - 1
canvas/php/dashboard.php

@@ -77,7 +77,7 @@
                      <!-- <div class="canvas-gallery-item col-md-4 col-sm-6 text-center">
                        <div  class="col-md-12 color0">
                           <h3>Canvas Title</h3>
-                          <p>created: <span>2016/09/14</span></p>
+                          <p>Created: <span>2016/09/14</span></p>
                         </div>
                      </div>
                    -->

+ 67 - 0
canvas/php/look-for-collaborators.php

@@ -0,0 +1,67 @@
+<?php
+ /* Receives the email of the user, the name of the canvas and the date
+    and stores it in the database with a randomly-generated canvas_id,
+    that is returned.                                                */
+ 
+ session_start();
+ $params = array();
+ parse_str($_POST['save_canvas'], $params);
+
+ if(!array_key_exists('email_save_canvas', $params) OR
+    !array_key_exists('name_save_canvas', $params) OR
+    !array_key_exists('date_save_canvas', $params)) {
+   echo 400; // Missing parameters
+ }
+
+ else {
+
+   if(isset($_SESSION['canvas_id'])) {
+     // Canvas already exists. Return canvas_id to overwrite JSON file.
+     echo $_SESSION['canvas_id'];
+   }
+
+   else { // New canvas in the database
+
+     // Retrieve user credentials
+     $email = $params['email_save_canvas'];
+     $canvas_name = $params['name_save_canvas'];
+     $date = $params['date_save_canvas'];
+
+     require_once('../../php/db_utils.php');
+     $conn = db_connect(); // Connect to the database
+
+     // Check if the username already exists
+     if(!($result = mysqli_query($conn, "SELECT name FROM user WHERE username = '$email'"))) {
+       echo 400; // Wrong query
+     }
+     else if(mysqli_num_rows($result) != 1) { // User not registered or duplicated
+       echo 401;
+     }
+     else { // User registered
+       // Save this canvas
+       $canvas_id = generateRandomString();
+       if(!mysqli_query($conn, "INSERT INTO canvas (canvas_id, user_id, canvas_name, canvas_date) VALUES ('$canvas_id', '$email', '$canvas_name', '$date')")) {
+         echo 400; // Wrong query
+         echo " #Wrong query :/ ";
+       }
+       else { // Return canvas_id and save it in the current session
+         $_SESSION['canvas_id'] = $canvas_id;
+         echo $canvas_id;
+       }
+     }
+   }
+}
+
+
+/* Generate a random string of a specific length to be used as canvas_id */
+function generateRandomString($length = 10) {
+    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+    $charactersLength = strlen($characters);
+    $randomString = '';
+    for ($i = 0; $i < $length; $i++) {
+        $randomString .= $characters[rand(0, $charactersLength - 1)];
+    }
+    return $randomString;
+}
+
+?>

BIN
icon/favicon.ico