Permalink
Browse files

Improved everything.

  • Loading branch information...
1 parent 1e65e80 commit 80072503f3da42a27e67dff0a6f332c653b4b1c4 @michael michael committed Oct 21, 2012
Showing with 83 additions and 37 deletions.
  1. +13 −4 console.css
  2. +25 −14 console.js
  3. +5 −10 document.js
  4. +39 −4 documents/hello.json
  5. +1 −5 index.html
View
@@ -128,7 +128,6 @@ h2 { font-size: 160%; padding-bottom: 15px; }
/* Testsuites
-------------------------------------------------------------------------------*/
-
.testsuites {
background: rgba(0, 0, 0, 0.1);
padding-bottom: 5px;
@@ -288,13 +287,23 @@ textarea {
}
.visualization .document .node {
- /*height: 50px;*/
margin-bottom: 1px;
- background: rgba(0,0,0, 0.1);
- padding: 10px;
+ padding: 2px 10px;
overflow: auto;
}
+.visualization .document .node .suggestion {
+ background: rgba(171, 201, 36, 0.4);
+}
+
+.visualization .document .node .mark-1 {
+ background: rgba(171, 201, 36, 0.4);
+}
+
+.visualization .document .node .mark-2 {
+ background: rgba(16, 167, 222, 0.4);
+}
+
.visualization .document .node.section {
font-weight: bold;
}
View
@@ -43,35 +43,31 @@ $(function() {
"annotation": [
{
- "name": "Emphasize",
- "op": ["insert", {"id": "em:1", "type": "em", "node": "section:1", "pos": [8, 10]}]
+ "name": "Insert Annotation",
+ "op": ["insert", {"id": "suggestion:1", "type": "suggestion", "node": "text:2", "pos": [4, 5]}]
},
{
- "name": "Strong",
- "op": ["insert", {"id": "em:1", "type": "str", "node": "text:2", "pos": [0, 3]}]
- },
- {
- "name": "Suggestion",
- "op": ["insert", {"id": "suggestion:1", "type": "suggestion", "node": "text:2", "pos": [5, 5]}]
+ "name": "Update Annotation",
+ "op": ["update", {"id": "suggestion:1", "type": "suggestion", "node": "text:2", "pos": [5, 10]}]
}
],
"comment": [
{
- "name": "Insert Comment (on document)",
+ "name": "Insert Comment (document)",
"op": ["insert", {"id": "comment:a", "content": "I like this document!"}]
},
{
- "name": "Insert Comment (on node)",
- "op": ["insert", {"id": "comment:a", "content": "Good argumentation."}]
+ "name": "Insert Comment (node)",
+ "op": ["insert", {"id": "comment:a", "node": "text:2", "content": "Good argumentation."}]
},
{
- "name": "Insert Comment (on annotation)",
- "op": ["insert", {"id": "comment:a", "node": "text:2", "annotation": "suggestion:1", "content": "Better idea."}]
+ "name": "Insert Comment (annotation)",
+ "op": ["insert", {"id": "comment:a", "node": "text:2", "annotation": "suggestion:1", "content": "A way of saying helo."}]
},
{
"name": "Update comment",
- "op": ["update", {"id": "comment:a", "content": "Hello wrrld"}]
+ "op": ["insert", {"id": "comment:a", "content": "A way of saying hello."}]
}
]
};
@@ -246,9 +242,24 @@ $(function() {
var op = this.model.model.operations[this.sha];
if (op) $('#command').val(JSON.stringify(op.op, null, ' '));
+ this.renderAnnotations();
this.renderScope();
},
+ renderAnnotations: function() {
+ var that = this;
+ _.each(this.model.nodes(), function(node) {
+ // console.log('rendering annotations for'+ node.id);
+ var annotations = that.model.annotations(node.id);
+ // console.log('annotations', annotations);
+ _.each(annotations, function(a) {
+ // console.log('ann', a.pos);
+ var elems = $('div[data-id="'+a.node+'"]').children().slice(a.pos[0], a.pos[0] + a.pos[1]);
+ elems.addClass(a.type);
+ });
+ });
+ },
+
renderScope: function() {
this.$('#scope').html(_.tpl('scope', {
scope: this.scope,
View
@@ -315,10 +315,6 @@ var RawDocument = function(doc, schema) {
annotations: {},
comments: {}
};
-
- // Also reset annotations
- this.annotations = {};
- this.comments = {};
},
// TODO: error handling
@@ -457,7 +453,7 @@ var Document = _.inherits(RawDocument, {
RawDocument.call(this, options);
},
- getAnnotations: function(node) {
+ annotations: function(node) {
var annotations = {};
_.each(this.content.annotations, function(a) {
if (a.node === node) annotations[a.id] = a;
@@ -502,7 +498,7 @@ var Document = _.inherits(RawDocument, {
},
// Store annotation op in the operation graph
- storeAnnotationOp: function(op, scope) {
+ storeAdditionOp: function(op, scope) {
// Get latest sha
var sha = this.model.refs.master;
@@ -525,7 +521,7 @@ var Document = _.inherits(RawDocument, {
}
if (_.include(['annotation', 'comment'], options.scope) && !options.silent) {
- this.storeAnnotationOp(op, options.scope);
+ this.storeAdditionOp(op, options.scope);
}
},
@@ -541,9 +537,7 @@ var Document = _.inherits(RawDocument, {
// Checkout annotations
_.each(ops, function(op, index) {
var additions = this.model.additions[op.sha];
-
if (additions) {
- // console.log('additions found', additions);
// Applying annotation ops
_.each(additions.annotations, function(op) {
this.apply(op, {silent: true, scope: "annotation"});
@@ -623,6 +617,8 @@ Document.methods = {
insert: function(doc, options) {
var id = options.id ? options.id : Math.uuid();
+
+ if (doc.nodes[id]) throw('id ' +options.id+ ' already exists.');
// Construct a new document node
var newNode = _.clone(options.data);
@@ -764,7 +760,6 @@ Document.methods = {
};
-
// Annotation Methods
// --------
View
@@ -15,7 +15,7 @@
}
}
],
- "user": "foouser",
+ "user": "michael",
"sha": "1b6544d5f9724c33aa8dbb5becc51c0d",
"head": "master"
},
@@ -31,7 +31,7 @@
}
}
],
- "user": "foouser",
+ "user": "michael",
"sha": "b0595f2d3863db5ecd82d43e7ec05da0",
"head": "master",
"parent": "1b6544d5f9724c33aa8dbb5becc51c0d"
@@ -53,12 +53,47 @@
]
}
],
- "user": "foouser",
+ "user": "michael",
"sha": "f7bd8120adb16d179c454ce57b57b50d",
"head": "master",
"parent": "b0595f2d3863db5ecd82d43e7ec05da0"
}
},
- "additions": {},
+ "additions": {
+ "f7bd8120adb16d179c454ce57b57b50d": {
+ "annotations": [
+ [
+ "insert",
+ {
+ "id": "suggestion:1",
+ "type": "suggestion",
+ "node": "text:2",
+ "pos": [
+ 0,
+ 3
+ ]
+ }
+ ]
+ ],
+ "comments": [
+ [
+ "insert",
+ {
+ "id": "comment:a",
+ "node": "text:2",
+ "content": "A way of saying helo.",
+ "annotation": "suggestion:1"
+ }
+ ],
+ [
+ "update",
+ {
+ "id": "comment:a",
+ "content": "A way of saying hello."
+ }
+ ]
+ ]
+ }
+ },
"id": "doc:hello"
}
View
@@ -64,11 +64,7 @@
<div class="document">
<% _.each(nodes, function(node) { %>
<div class="node <%= node.type %>" data-id="<%= node.id %>">
- <%= node.content %>
- <% annotations = document.getAnnotations(node.id); %>
- <% _.each(annotations, function(a) { %>
- <div class="annotation" data-id="<%= a.id %>"></div>
- <% }); %>
+ <% _.each(node.content, function(ch) { %><span><%= ch %></span><% }); %>
</div>
<% }); %>
</div>

0 comments on commit 8007250

Please sign in to comment.