fix notes

This commit is contained in:
Hylke Bons 2011-07-17 01:22:39 +01:00
parent f496a3b854
commit 6cf8eca2b7
6 changed files with 54 additions and 54 deletions

View file

@ -444,7 +444,6 @@ namespace SparkleLib {
change_set.UserName = match.Groups [2].Value; change_set.UserName = match.Groups [2].Value;
change_set.UserEmail = match.Groups [3].Value; change_set.UserEmail = match.Groups [3].Value;
change_set.IsMerge = is_merge_commit; change_set.IsMerge = is_merge_commit;
change_set.SupportsNotes = true;
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value), change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value), int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
@ -467,7 +466,7 @@ namespace SparkleLib {
string file_path = entry_line.Substring (39); string file_path = entry_line.Substring (39);
string to_file_path; string to_file_path;
if (change_type.Equals ("A")) { if (change_type.Equals ("A") && !file_path.Contains (".notes")) {
change_set.Added.Add (file_path); change_set.Added.Add (file_path);
} else if (change_type.Equals ("M")) { } else if (change_type.Equals ("M")) {
@ -487,8 +486,12 @@ namespace SparkleLib {
} }
} }
change_set.Notes.AddRange (GetNotes (change_set.Revision)); if ((change_set.Added.Count + change_set.Edited.Count +
change_sets.Add (change_set); change_set.Deleted.Count) > 0) {
change_set.Notes.AddRange (GetNotes (change_set.Revision));
change_sets.Add (change_set);
}
} }
} }

View file

@ -28,7 +28,6 @@ namespace SparkleLib {
public string Folder; public string Folder;
public string Revision; public string Revision;
public DateTime Timestamp; public DateTime Timestamp;
public bool SupportsNotes = false;
public bool IsMerge = false; public bool IsMerge = false;
public List<string> Added = new List<string> (); public List<string> Added = new List<string> ();

View file

@ -308,7 +308,8 @@ namespace SparkleLib {
if (!this.watcher.EnableRaisingEvents) if (!this.watcher.EnableRaisingEvents)
return; return;
if (args.FullPath.Contains (Path.DirectorySeparatorChar + ".")) if (args.FullPath.Contains (Path.DirectorySeparatorChar + ".") &&
!args.FullPath.Contains (Path.DirectorySeparatorChar + ".notes"))
return; return;
WatcherChangeTypes wct = args.ChangeType; WatcherChangeTypes wct = args.ChangeType;
@ -348,9 +349,9 @@ namespace SparkleLib {
"<timestamp>([0-9]+)</timestamp>.*" + "<timestamp>([0-9]+)</timestamp>.*" +
"<body>(.+)</body>", RegexOptions.Compiled); "<body>(.+)</body>", RegexOptions.Compiled);
foreach (string file_name in Directory.GetFiles (notes_path)) { foreach (string file_path in Directory.GetFiles (notes_path)) {
if (file_name.StartsWith (revision)) { if (Path.GetFileName (file_path).StartsWith (revision)) {
string note_xml = String.Join ("", File.ReadAllLines (file_name)); string note_xml = String.Join ("", File.ReadAllLines (file_path));
Match match_notes = regex_notes.Match (note_xml); Match match_notes = regex_notes.Match (note_xml);
@ -513,6 +514,13 @@ namespace SparkleLib {
writer.Write (note); writer.Write (note);
writer.Close (); writer.Close ();
// The watcher doesn't like .*/ so we need to trigger
// a change manually
FileSystemEventArgs args = new FileSystemEventArgs (WatcherChangeTypes.Changed,
notes_path, note_name);
OnFileActivity (args);
SparkleHelpers.DebugInfo ("Note", "Added note to " + revision); SparkleHelpers.DebugInfo ("Note", "Added note to " + revision);
} }

View file

@ -325,7 +325,7 @@ namespace SparkleShare {
foreach (SparkleChangeSet change_set in activity_day) { foreach (SparkleChangeSet change_set in activity_day) {
string event_entry = "<dl>"; string event_entry = "<dl>";
if (change_set.IsMerge) { if (change_set.IsMerge) {
event_entry += "<dd>Did something magical</dd>"; event_entry += "<dd>Did something magical</dd>";
@ -391,25 +391,23 @@ namespace SparkleShare {
} }
string comments = ""; string comments = "";
if (change_set.SupportsNotes) { comments = "<div class=\"comments\">";
comments = "<div class=\"comments\">";
if (change_set.Notes != null) { if (change_set.Notes != null) {
change_set.Notes.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp))); change_set.Notes.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp)));
foreach (SparkleNote note in change_set.Notes) { foreach (SparkleNote note in change_set.Notes) {
comments += "<div class=\"comment-text\">" + comments += "<div class=\"comment-text\">" +
"<p class=\"comment-author\"" + "<p class=\"comment-author\"" +
" style=\"background-image: url('file://" + GetAvatar (note.UserEmail, 48) + "');\">" + " style=\"background-image: url('file://" + GetAvatar (note.UserEmail, 48) + "');\">" +
note.UserName + "</p>" + note.UserName + "</p>" +
note.Body + note.Body +
"</div>"; "</div>";
}
} }
comments += "</div>";
} }
comments += "</div>";
string avatar_email = ""; string avatar_email = "";
if (File.Exists (GetAvatar (change_set.UserEmail, 48))) if (File.Exists (GetAvatar (change_set.UserEmail, 48)))
avatar_email = change_set.UserEmail; avatar_email = change_set.UserEmail;
@ -458,7 +456,8 @@ namespace SparkleShare {
} }
string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log) string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log)
.Replace ("<!-- $username -->", UserName); .Replace ("<!-- $username -->", UserName)
.Replace ("<!-- $user-avatar-url -->", "file://" + GetAvatar (UserEmail, 48));
return html; return html;
} }

View file

@ -12,17 +12,11 @@
<div class="clearer"></div> <div class="clearer"></div>
<div class="comments-section"> <div class="comments-section">
<div class="comments-wrapper"> <!-- $event-comments -->
<!-- $event-comments --> <textarea class="comment-textarea"></textarea>
<div class="comment-text"> <input class="comment-button" type="button" value="Add note"
<textarea class="comment-textarea"></textarea> id="<!-- $event-folder -->~<!-- $event-revision -->">
<input class="comment-button" type="button" value="Add note" <div style='clear: both'></div>
id="<!-- $event-folder -->~<!-- $event-revision -->">
<div style='clear: both'></div>
</div>
<div style='clear: both'></div>
</div>
<div class="clearer"></div>
</div> </div>
<div class="clearer"></div> <div class="clearer"></div>
</div> </div>

View file

@ -5,11 +5,9 @@
<script type="text/javascript" src="<!-- $jquery-url -->"></script> <script type="text/javascript" src="<!-- $jquery-url -->"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function () { $(document).ready(function () {
$('.comments-wrapper').each (function () { $('.comments-section').each (function () {
if ($(this).find ('.comments').children ().size () < 1) { if ($(this).find ('.comments').children ().size () < 1) {
$(this).hide (); $(this).hide ();
} else {
$(this).css ('cursor', 'default');
} }
}); });
@ -21,8 +19,7 @@
// Show the form when 'Add note' is clicked // Show the form when 'Add note' is clicked
$('.note').click(function () { $('.note').click(function () {
$(this).parent ().find ('.comments-wrapper').show (); $(this).parent ().find ('.comments-section').show ();
//$(this).parent ().find ('.comments-wrapper').css ('cursor', 'default');
}); });
// Hide the 'Show all' link when there are less than 10 events // Hide the 'Show all' link when there are less than 10 events
@ -50,19 +47,23 @@
if (text == '') if (text == '')
return; return;
// Clear the textarea
textarea.val (''); textarea.val ('');
table = $(this).parent ().find ("table"); table = $(this).parent ().find (".comments");
comments = table.html (); comments = table.html ();
comments += '<tr>' +
' <td class=\"comment-author\"><!-- $username --></td>' + // Add the note to the html
' <td class=\"comment-timestamp\">just now</td>' + comments += '<div class="comment-text">' +
'</tr>' + '<p class="comment-author"' +
'<tr>' + ' style="background-image: url(\'<!-- $user-avatar-url -->\');">' +
' <td class=\"comment-text\" colspan=\"2\">' + text + '</td>' + '<!-- $username --></p>' +
'</tr>'; text +
'</div>';
table.html (comments); table.html (comments);
// Feed the note to the backend
location = this.id + '~' + text; location = this.id + '~' + text;
}); });
}); });
@ -297,10 +298,6 @@
margin-top: 12px; margin-top: 12px;
} }
.comments-section:hover {
cursor: pointer;
}
.comment-text { .comment-text {
padding-bottom: 15px; padding-bottom: 15px;
} }