Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  Fix regex to detect tasks in notes.
  Fix note task list state toggle on tasks with formatting.
  Tweak note and editor positioning on note detail view.
  Fix issues with note markdown not being updated on edit.
  Fix Backbone.Model.fetch promise errors.
  Tweak notes markdown styles.
  Debounce Backbone.sync to prevent multiple saves on the same model.
  Fix task lists “double update” bug.
  Add date_created and date_modified defaults to board, card and comment models.
  Add note task lists feature.
  Don’t use Raven when in debug mode
  • Loading branch information
elving committed Jun 18, 2014
2 parents 16e116d + 3df0a68 commit 74158ab
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/account/styles/_card-detail.styl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

.note-editor-form {
display: none;
margin: 15px auto;
margin: 0 auto 15px;
}

.note-editor-preview,
Expand Down
2 changes: 0 additions & 2 deletions app/account/styles/_note-editor.styl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.note-editor {
padding: 15px;

&.is-previewing {
.note-editor-form {
display: none !important;
Expand Down
17 changes: 15 additions & 2 deletions app/account/views/note-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = Zeppelin.FormView.extend({
'click [data-action=cancel]': 'toggleEditMode',
'click [data-action=submit]': 'submit',
'click [data-action=modify]': 'closePreview',
'click [data-action=preview]': 'onClickPreview'
'click [data-action=preview]': 'onClickPreview',
'click div.markdown input[type=checkbox]': 'onNoteTaskChange'
},

elements: {
Expand All @@ -38,6 +39,8 @@ module.exports = Zeppelin.FormView.extend({

template: require('account/templates/note-detail'),

changeFromNote: false,

toggleEditMode: function() {
this.$el.toggleClass('is-editing');

Expand All @@ -64,7 +67,11 @@ module.exports = Zeppelin.FormView.extend({
$input.val(content);
}

this.getElement('content').html(_.markdown(content));
if (!this.changeFromNote) {
this.getElement('content').html(_.markdown(content));
}

this.changeFromNote = false;
return this;
},

Expand Down Expand Up @@ -99,6 +106,12 @@ module.exports = Zeppelin.FormView.extend({

onContentChange: function(note, content) {
this.updateContent(content);
},

onNoteTaskChange: function(event) {
var $task = $(event.currentTarget);
this.changeFromNote = true;
this.model.updateTask(_.parseInt($task.attr('data-index')), $task.prop('checked'));
}
});

2 changes: 2 additions & 0 deletions app/core/models/board.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = Zeppelin.Model.extend({
defaults: function() {
return {
date_created: _.now(),
date_modified: _.now(),
color: '#E5E5E5',
html_url: '',
created_by: {
Expand Down
2 changes: 2 additions & 0 deletions app/core/models/card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = Zeppelin.Model.extend({
defaults: function() {
return {
date_created: _.now(),
date_modified: _.now(),
html_url: '',
download_html_url: '',
original_html_url: '',
Expand Down
3 changes: 2 additions & 1 deletion app/core/models/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = Zeppelin.Model.extend({
username: App.User.get('username'),
gravatar_url: App.User.get('gravatar_url')
},
date_created: _.now()
date_created: _.now(),
date_modified: _.now()
};
},

Expand Down
27 changes: 27 additions & 0 deletions app/core/models/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,32 @@ module.exports = Card.extend({
return _.extend({
type: 'note'
}, Card.prototype.defaults());
},

updateTask: function(index, checked) {
var self = this,
note = this.get('content'),
tasks = note.match(/(^\-\s*\[[x ]\]\s*).+/gm),
changingTask = tasks[index],
tasksCounter = 0,
originalTask = changingTask;

if (checked) {
changingTask = changingTask.replace('[ ]', '[x]');
} else {
changingTask = changingTask.replace('[x]', '[ ]');
}

this.save({
content: note.replace(/(^\-\s*\[[x ]\]\s*).+/gm, function(match) {
if (tasksCounter === index) {
tasksCounter += 1;
return changingTask;
} else {
tasksCounter += 1;
return match;
}
})
});
}
});
41 changes: 41 additions & 0 deletions app/core/styles/_markdown.styl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
}
}

ol, ul {
margin-left: 15px;
padding: 0 0 0 15px;
}

p, h1, h2, h3, h4,
h5, h6, ol, ul, blockquote{
margin-bottom: 15px;
margin-top: 15px;
}

blockquote {
border-left: 2px solid #E0E0E0;
}
Expand All @@ -29,10 +40,40 @@

& > li > ul {
list-style-type: circle;
margin-bottom: 0;
}
}

.faux-link {
color: #50BEF7;
}

.has-task {
margin-left: -15px;
list-style: none;

input[type="checkbox"] {
cursor: pointer;
margin-right: 10px;
vertical-align: baseline;
}
}
}

.is-item .markdown {
h1 {
font-size: 28px;
}

h2 {
font-size: 24px;
}

h3 {
font-size: 20px;
}

.has-task input[type="checkbox"] {
pointer-events: none;
}
}
20 changes: 20 additions & 0 deletions app/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
var originalSync = Backbone.sync;

Backbone.sync = function(method, model, options) {
var lastXHR;

lastXHR = model._lastXHR && model._lastXHR[method];

if ((lastXHR && lastXHR.readyState !== 4) &&
(options && options.safe !== false)) {
lastXHR.abort('stale');
}

if (!model._lastXHR) {
model._lastXHR = {};
}

return model._lastXHR[method] = originalSync.apply(this, arguments);
};


Swag.registerHelpers();

$.ajaxSetup({
Expand Down
32 changes: 31 additions & 1 deletion app/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ _.mixin({'decodeJWT': function(token) {

_.mixin({'markdown': function(text) {
var parser,
renderer = new marked.Renderer();
renderer = new marked.Renderer(),
noteTaskIndex = 0;

renderer.link = function(href, title, text) {
if (title) {
Expand All @@ -78,6 +79,21 @@ _.mixin({'markdown': function(text) {
}
};

renderer.listitem = function(text) {
var originalText = text;

if (/^\s*\[[x ]\]\s*/.test(text)) {
text = text
.replace(/^\s*\[ \]\s*/, '<input type="checkbox" data-index="' + noteTaskIndex + '" class="markdown-task">')
.replace(/^\s*\[x\]\s*/, '<input type="checkbox" data-index="' + noteTaskIndex + '" class="markdown-task" checked>')

noteTaskIndex += 1;
return '<li class="has-task">' + text + '</li>';
} else {
return '<li>' + text + '</li>';
}
};

var parser = marked.setOptions({
gfm: true,
tables: true,
Expand Down Expand Up @@ -112,6 +128,20 @@ _.mixin({'markdownNoLinks': function(text) {
}
};

renderer.listitem = function(text) {
var originalText = text;

if (/^\s*\[[x ]\]\s*/.test(text)) {
text = text
.replace(/^\s*\[ \]\s*/, '<input type="checkbox" class="markdown-task" data-original-text="' + originalText + '">')
.replace(/^\s*\[x\]\s*/, '<input type="checkbox" class="markdown-task" data-original-text="' + originalText + '" checked>')

return '<li class="has-task">' + text + '</li>';
} else {
return '<li>' + text + '</li>';
}
};

var parser = marked.setOptions({
gfm: true,
tables: true,
Expand Down

0 comments on commit 74158ab

Please sign in to comment.