Browse Source

Added comments to projects

Nathaniel van Diepen 10 years ago
parent
commit
8882cc96e0
10 changed files with 264 additions and 25 deletions
  1. 1 1
      bugs.appcache
  2. 19 1
      data/pages/project.template
  3. 1 1
      data/version
  4. 1 0
      index.php
  5. 21 21
      install/install.sql
  6. 11 1
      js/index.js
  7. 193 0
      js/jquery.timeago.js
  8. 1 0
      php/include.php
  9. 14 0
      php/messages.php
  10. 2 0
      php/project.php

+ 1 - 1
bugs.appcache

@@ -111,4 +111,4 @@ NETWORK:
 *
 
 FALLBACK:
-Version Sun Oct 27 23:44:34 MDT 2013
+Version Mon Nov 18 12:42:06 MST 2013

+ 19 - 1
data/pages/project.template

@@ -3,4 +3,22 @@
 </h3>
 <div>
 	{{description}}
-</div>
+</div>
+<h4>
+	Comments
+</h4>
+<ul>
+	{{#each comments}}
+		<li>
+			<a style="font-size:small;color:gray;text-decoration:none;" href="#~{{name}}">
+				{{name}}
+			</a>
+			<time class="timeago">
+				{{timestamp}}
+			</time>
+			<div>
+				{{message}}
+			</div>
+		</li>
+	{{/each}}
+</ul>

+ 1 - 1
data/version

@@ -1 +1 @@
-Sun Oct 27 23:44:34 MDT 2013
+Mon Nov 18 12:42:06 MST 2013

+ 1 - 0
index.php

@@ -113,6 +113,7 @@
 		<script src="js/jquery.storage.js"></script>
 		<script src="js/jquery.cookie.js"></script>
 		<script src="js/jquery.nicescroll.js"></script>
+		<script src="js/jquery.timeago.js"></script>
 		<script src="js/shortcut.js"></script>
 		<script src="js/index.js"></script>
 	</head>

+ 21 - 21
install/install.sql

@@ -3,7 +3,7 @@
 -- http://www.phpmyadmin.net
 --
 -- Host: 127.0.0.1
--- Generation Time: Oct 21, 2013 at 01:08 AM
+-- Generation Time: Nov 18, 2013 at 07:31 PM
 -- Server version: 5.6.11
 -- PHP Version: 5.5.3
 
@@ -22,7 +22,7 @@ SET time_zone = "+00:00";
 --
 -- Table structure for table `issues`
 --
--- Creation: Oct 06, 2013 at 08:17 PM
+-- Creation: Oct 07, 2013 at 07:42 PM
 --
 
 DROP TABLE IF EXISTS `issues`;
@@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS `issues` (
   KEY `u_id` (`u_id`),
   KEY `u_id_2` (`u_id`),
   KEY `s_id` (`s_id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 
 --
 -- RELATIONS FOR TABLE `issues`:
@@ -51,12 +51,13 @@ CREATE TABLE IF NOT EXISTS `issues` (
 --
 -- Table structure for table `messages`
 --
--- Creation: Oct 20, 2013 at 11:07 PM
+-- Creation: Nov 18, 2013 at 06:30 PM
 --
 
 DROP TABLE IF EXISTS `messages`;
 CREATE TABLE IF NOT EXISTS `messages` (
   `id` int(100) NOT NULL AUTO_INCREMENT,
+  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `from_id` int(100) NOT NULL,
   `to_id` int(100) DEFAULT NULL,
   `p_id` int(11) DEFAULT NULL,
@@ -69,12 +70,10 @@ CREATE TABLE IF NOT EXISTS `messages` (
   KEY `s_id` (`s_id`),
   KEY `i_id` (`i_id`),
   KEY `p_id` (`p_id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
+) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
 
 --
 -- RELATIONS FOR TABLE `messages`:
---   `p_id`
---       `projects` -> `id`
 --   `from_id`
 --       `users` -> `id`
 --   `to_id`
@@ -83,6 +82,8 @@ CREATE TABLE IF NOT EXISTS `messages` (
 --       `scrums` -> `id`
 --   `i_id`
 --       `issues` -> `id`
+--   `p_id`
+--       `projects` -> `id`
 --
 
 -- --------------------------------------------------------
@@ -90,7 +91,7 @@ CREATE TABLE IF NOT EXISTS `messages` (
 --
 -- Table structure for table `projects`
 --
--- Creation: Oct 20, 2013 at 11:04 PM
+-- Creation: Oct 24, 2013 at 04:53 PM
 --
 
 DROP TABLE IF EXISTS `projects`;
@@ -101,7 +102,7 @@ CREATE TABLE IF NOT EXISTS `projects` (
   `description` text NOT NULL,
   PRIMARY KEY (`id`),
   KEY `u_id` (`u_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
 
 --
 -- RELATIONS FOR TABLE `projects`:
@@ -114,7 +115,7 @@ CREATE TABLE IF NOT EXISTS `projects` (
 --
 -- Table structure for table `rels`
 --
--- Creation: Oct 06, 2013 at 08:21 PM
+-- Creation: Oct 07, 2013 at 07:42 PM
 --
 
 DROP TABLE IF EXISTS `rels`;
@@ -144,7 +145,7 @@ CREATE TABLE IF NOT EXISTS `rels` (
 --
 -- Table structure for table `scrums`
 --
--- Creation: Oct 20, 2013 at 11:05 PM
+-- Creation: Oct 07, 2013 at 07:42 PM
 --
 
 DROP TABLE IF EXISTS `scrums`;
@@ -157,14 +158,14 @@ CREATE TABLE IF NOT EXISTS `scrums` (
   PRIMARY KEY (`id`),
   KEY `u_id` (`u_id`),
   KEY `p_id` (`p_id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 
 --
 -- RELATIONS FOR TABLE `scrums`:
---   `p_id`
---       `projects` -> `id`
 --   `u_id`
 --       `users` -> `id`
+--   `p_id`
+--       `projects` -> `id`
 --
 
 -- --------------------------------------------------------
@@ -172,7 +173,7 @@ CREATE TABLE IF NOT EXISTS `scrums` (
 --
 -- Table structure for table `users`
 --
--- Creation: Oct 06, 2013 at 08:17 PM
+-- Creation: Oct 07, 2013 at 07:42 PM
 --
 
 DROP TABLE IF EXISTS `users`;
@@ -185,7 +186,7 @@ CREATE TABLE IF NOT EXISTS `users` (
   `key` varchar(128) NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `name` (`name`)
-) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;
+) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;
 
 --
 -- Constraints for dumped tables
@@ -202,11 +203,11 @@ ALTER TABLE `issues`
 -- Constraints for table `messages`
 --
 ALTER TABLE `messages`
-  ADD CONSTRAINT `messages_ibfk_5` FOREIGN KEY (`p_id`) REFERENCES `projects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
   ADD CONSTRAINT `messages_ibfk_1` FOREIGN KEY (`from_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
   ADD CONSTRAINT `messages_ibfk_2` FOREIGN KEY (`to_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
   ADD CONSTRAINT `messages_ibfk_3` FOREIGN KEY (`s_id`) REFERENCES `scrums` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
-  ADD CONSTRAINT `messages_ibfk_4` FOREIGN KEY (`i_id`) REFERENCES `issues` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
+  ADD CONSTRAINT `messages_ibfk_4` FOREIGN KEY (`i_id`) REFERENCES `issues` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+  ADD CONSTRAINT `messages_ibfk_5` FOREIGN KEY (`p_id`) REFERENCES `projects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
 
 --
 -- Constraints for table `projects`
@@ -226,9 +227,8 @@ ALTER TABLE `rels`
 -- Constraints for table `scrums`
 --
 ALTER TABLE `scrums`
-  ADD CONSTRAINT `scrums_ibfk_2` FOREIGN KEY (`p_id`) REFERENCES `projects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
-  ADD CONSTRAINT `scrums_ibfk_1` FOREIGN KEY (`u_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-SET FOREIGN_KEY_CHECKS=1;
+  ADD CONSTRAINT `scrums_ibfk_1` FOREIGN KEY (`u_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+  ADD CONSTRAINT `scrums_ibfk_2` FOREIGN KEY (`p_id`) REFERENCES `projects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
 
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

+ 11 - 1
js/index.js

@@ -1,4 +1,4 @@
-// TODO - Add initial page loading and handlers
+   // TODO - Add initial page loading and handlers
 (function($,History,console){
 	var State = History.getState(),
 		Old = {},
@@ -286,6 +286,7 @@
 				render.links('#topbar');
 				render.buttons('#topbar');
 				render.menus('#topbar');
+				render.time('#topbar');
 				if(State.url == location.origin+'/page-index'){
 					$('#topbar').find('.topbar-history').hide();
 				}
@@ -302,8 +303,17 @@
 				render.accordions('#content');
 				render.menus('#content');
 				render.form('#content');
+				render.time('#content');
 				$(window).resize();
 			},
+			time: function(selector){
+				$(selector).find('time.timeago').each(function(){
+					var time = new Date($(this).text()*1000);
+					$(this).replaceWith(
+						$('<abbr>').attr('title',time.toISOString()).timeago()
+					);
+				});
+			},
 			accordions: function(selector){
 				$(selector).find('.accordion').each(function(){
 					var icons = {};

+ 193 - 0
js/jquery.timeago.js

@@ -0,0 +1,193 @@
+/**
+ * Timeago is a jQuery plugin that makes it easy to support automatically
+ * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
+ *
+ * @name timeago
+ * @version 1.3.0
+ * @requires jQuery v1.2.3+
+ * @author Ryan McGeary
+ * @license MIT License - http://www.opensource.org/licenses/mit-license.php
+ *
+ * For usage and examples, visit:
+ * http://timeago.yarp.com/
+ *
+ * Copyright (c) 2008-2013, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
+ */
+
+(function (factory) {
+  if (typeof define === 'function' && define.amd) {
+    // AMD. Register as an anonymous module.
+    define(['jquery'], factory);
+  } else {
+    // Browser globals
+    factory(jQuery);
+  }
+}(function ($) {
+  $.timeago = function(timestamp) {
+    if (timestamp instanceof Date) {
+      return inWords(timestamp);
+    } else if (typeof timestamp === "string") {
+      return inWords($.timeago.parse(timestamp));
+    } else if (typeof timestamp === "number") {
+      return inWords(new Date(timestamp));
+    } else {
+      return inWords($.timeago.datetime(timestamp));
+    }
+  };
+  var $t = $.timeago;
+
+  $.extend($.timeago, {
+    settings: {
+      refreshMillis: 60000,
+      allowFuture: false,
+      localeTitle: false,
+      cutoff: 0,
+      strings: {
+        prefixAgo: null,
+        prefixFromNow: null,
+        suffixAgo: "ago",
+        suffixFromNow: "from now",
+        seconds: "less than a minute",
+        minute: "about a minute",
+        minutes: "%d minutes",
+        hour: "about an hour",
+        hours: "about %d hours",
+        day: "a day",
+        days: "%d days",
+        month: "about a month",
+        months: "%d months",
+        year: "about a year",
+        years: "%d years",
+        wordSeparator: " ",
+        numbers: []
+      }
+    },
+    inWords: function(distanceMillis) {
+      var $l = this.settings.strings;
+      var prefix = $l.prefixAgo;
+      var suffix = $l.suffixAgo;
+      if (this.settings.allowFuture) {
+        if (distanceMillis < 0) {
+          prefix = $l.prefixFromNow;
+          suffix = $l.suffixFromNow;
+        }
+      }
+
+      var seconds = Math.abs(distanceMillis) / 1000;
+      var minutes = seconds / 60;
+      var hours = minutes / 60;
+      var days = hours / 24;
+      var years = days / 365;
+
+      function substitute(stringOrFunction, number) {
+        var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
+        var value = ($l.numbers && $l.numbers[number]) || number;
+        return string.replace(/%d/i, value);
+      }
+
+      var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
+        seconds < 90 && substitute($l.minute, 1) ||
+        minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
+        minutes < 90 && substitute($l.hour, 1) ||
+        hours < 24 && substitute($l.hours, Math.round(hours)) ||
+        hours < 42 && substitute($l.day, 1) ||
+        days < 30 && substitute($l.days, Math.round(days)) ||
+        days < 45 && substitute($l.month, 1) ||
+        days < 365 && substitute($l.months, Math.round(days / 30)) ||
+        years < 1.5 && substitute($l.year, 1) ||
+        substitute($l.years, Math.round(years));
+
+      var separator = $l.wordSeparator || "";
+      if ($l.wordSeparator === undefined) { separator = " "; }
+      return $.trim([prefix, words, suffix].join(separator));
+    },
+    parse: function(iso8601) {
+      var s = $.trim(iso8601);
+      s = s.replace(/\.\d+/,""); // remove milliseconds
+      s = s.replace(/-/,"/").replace(/-/,"/");
+      s = s.replace(/T/," ").replace(/Z/," UTC");
+      s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
+      return new Date(s);
+    },
+    datetime: function(elem) {
+      var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title");
+      return $t.parse(iso8601);
+    },
+    isTime: function(elem) {
+      // jQuery's `is()` doesn't play well with HTML5 in IE
+      return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
+    }
+  });
+
+  // functions that can be called via $(el).timeago('action')
+  // init is default when no action is given
+  // functions are called with context of a single element
+  var functions = {
+    init: function(){
+      var refresh_el = $.proxy(refresh, this);
+      refresh_el();
+      var $s = $t.settings;
+      if ($s.refreshMillis > 0) {
+        setInterval(refresh_el, $s.refreshMillis);
+      }
+    },
+    update: function(time){
+      $(this).data('timeago', { datetime: $t.parse(time) });
+      refresh.apply(this);
+    },
+    updateFromDOM: function(){
+      $(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
+      refresh.apply(this);
+    }
+  };
+
+  $.fn.timeago = function(action, options) {
+    var fn = action ? functions[action] : functions.init;
+    if(!fn){
+      throw new Error("Unknown function name '"+ action +"' for timeago");
+    }
+    // each over objects here and call the requested function
+    this.each(function(){
+      fn.call(this, options);
+    });
+    return this;
+  };
+
+  function refresh() {
+    var data = prepareData(this);
+    var $s = $t.settings;
+
+    if (!isNaN(data.datetime)) {
+      if ( $s.cutoff == 0 || distance(data.datetime) < $s.cutoff) {
+        $(this).text(inWords(data.datetime));
+      }
+    }
+    return this;
+  }
+
+  function prepareData(element) {
+    element = $(element);
+    if (!element.data("timeago")) {
+      element.data("timeago", { datetime: $t.datetime(element) });
+      var text = $.trim(element.text());
+      if ($t.settings.localeTitle) {
+        element.attr("title", element.data('timeago').datetime.toLocaleString());
+      } else if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) {
+        element.attr("title", text);
+      }
+    }
+    return element.data("timeago");
+  }
+
+  function inWords(date) {
+    return $t.inWords(distance(date));
+  }
+
+  function distance(date) {
+    return (new Date().getTime() - date.getTime());
+  }
+
+  // fix for IE6 suckage
+  document.createElement("abbr");
+  document.createElement("time");
+}));

+ 1 - 0
php/include.php

@@ -10,6 +10,7 @@
 	require_once(PATH_PHP.'functions.php');
 	require_once(PATH_PHP.'security.php');
 	require_once(PATH_PHP.'captcha.php');
+	require_once(PATH_PHP.'messages.php');
 	require_once(PATH_PHP.'user.php');
 	require_once(PATH_PHP.'project.php');
 	require_once(PATH_PHP.'emails.php');

+ 14 - 0
php/messages.php

@@ -0,0 +1,14 @@
+<?php
+	require_once(realpath(dirname(__FILE__)).'/config.php');
+	require_once(PATH_PHP.'database.php');
+	function messages($id,$type){
+		switch($type){
+			case 'project':
+				if($res = query("SELECT m.id, u.name, m.message, UNIX_TIMESTAMP(m.timestamp) as timestamp FROM `messages` m JOIN `users` u ON u.id = m.from_id WHERE m.p_id='%d'",Array($id))){
+					return $res->fetch_all(MYSQLI_ASSOC);
+				}
+			break;
+		}
+		return Array();
+	}
+?>

+ 2 - 0
php/project.php

@@ -1,11 +1,13 @@
 <?php
 	require_once(realpath(dirname(__FILE__)).'/config.php');
 	require_once(PATH_PHP.'database.php');
+	require_once(PATH_PHP.'messages.php');
 	function projectObj($id){
 		if($res = query("SELECT p.title,p.id,p.description,u.name as user FROM `projects` p JOIN `users` u ON u.id = p.u_id  WHERE p.id='%d'",Array($id))){
 			if($res->num_rows == 1){
 				$project = $res->fetch_assoc();
 				$project['user'] = userObj($project['user']);
+				$project['comments'] = messages($project['id'],'project');
 				return $project;
 			}
 		}