-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOC-demo-annotations
390 lines (354 loc) · 12.4 KB
/
POC-demo-annotations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!doctype html>
<html>
<head>
<title>Orion Compare Editor Sample</title>
<style type="text/css">
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #ededed;
}
.lineHighlight{
outline: 2px dotted black;
}
.lineHighlightGutter{
background-image: url('problem.gif');;
}
.lineHighlightGutter1{
background-color: red;
}
.lineHighlightGutter2{
border-width: 3px;
}
.compareContainer {
position: absolute;
top: 80px; /* $ToolbarHeight + 1 */
bottom: 0;
width: 99%;
overflow-y: auto;
margin-left:5px;
border:1px solid #bebebe;
}
.commentHighlight{
background-color: #f1922e;
}
.commentHighlightGutter{
background-color: #f1922e;;
}
</style>
<link rel="stylesheet" type="text/css" href="built-compare.css"/>
<link rel="stylesheet" type="text/css" href="comments.css"/>
<script src="loadSamples.js"></script>
<script src="jquery-3.2.1.min.js"></script>
<script src="mustache.min.js"></script>
<script src="require.js"></script>
<script>
var compare, widget, requirePromise = new Promise(function (resolve, reject) {
require(["./built-compare-amd.js"], function (Compare) {
resolve(Compare);
});
});
function _createCommentDiv(comment){
var template = $('#showCommentTemplate').html().trim();
var div = document.createElement("div");
div.innerHTML = Mustache.render(template, {
isDraft: comment.isDraft,
url: "http://www.gravatar.com/avatar/eda7273d344fd5af7d547fda96737d83.jpg?d=identicon&r=pg&s=26",
author: comment.author.name,
date: comment.updated,
message: comment.message,
id: comment.id,
root:comment.root,
replies:comment.replies
});
var container = div.firstChild;
return container;
}
//recursively constructs the comment DOM node (comment, replies, (hidden) edit and reply forms)
function createDiv2Insert(comment){
var debth = 0;
var div = document.createElement("div");
div.id = "rootComment";
var width = $('.textviewScroll:first').width() - 40;
div.setAttribute("style", "width: " + width + "px");
var rootdiv = document.createElement("div");
rootdiv.id = comment.root;
function recursivefunction(comment){
debth++;
for (var key in comment){
if(key ==="id"){
var container = _createCommentDiv(comment);
var commentdiv = container.querySelector("#"+comment.id);
}
var savedebth = debth;
if (key === "replies" && comment[key].length > 0){
var arr = comment[key];
var replylength = comment[key].length;
for (var i = 0;i < replylength; i++) {
var replydiv = recursivefunction(comment[key][i]);
replydiv.setAttribute("style", "padding-left: " + debth*20 + "px");
container.appendChild(replydiv);
debth = savedebth;
}
}
}
return container;
}//recursivefunction
rootdiv.appendChild(recursivefunction(comment));
div.appendChild(rootdiv);
return div;
}
function showTheComments(){
showComments("show");
}
function hideTheComments(){
showComments("hide");
}
function showComments(showhide) {
// Comments and highlighting
var editor = widget.getMainEditor();
var viewModel = editor.getTextView().getModel();
//annotationModel is the handler you add or remove you annotation models
var annotationModel = editor.getAnnotationModel();
if (annotationModel) {
//Get the line styler inside the editor
var annoStyler = editor.getAnnotationStyler();
if(showhide == "show"){
//Add your annotation type to the editor
annoStyler.addAnnotationType("compare.customize.commentcontent");
annoStyler.addAnnotationType("compare.customize.linehighlight");
//Add the same annotation type ot the annotation ruler(gutter)
editor.getAnnotationRuler().addAnnotationType("compare.customize.commentcontent");
editor.getAnnotationRuler().addAnnotationType("compare.customize.linehighlight");
var commentAnnotations = [];
var highlightAnnotations = [];
var commentAnnotation, highlightAnnotation;
var comments = widget.options.comments;
for (var i = comments.length - 1; i >= 0; i--) {
comment = comments[i];
var startLineNumber = comment.startLine;
var endLineNumber = comment.endLine;
var endIndexComment = viewModel.getLineStart(endLineNumber);
var startIndexComment = endIndexComment;
var startIndexHighlight = viewModel.getLineStart(startLineNumber-1);
var endIndexHighlight = viewModel.getLineStart(endLineNumber);
var div2Insert = createDiv2Insert(comment);
commentAnnotation =
{
start: endIndexComment,
end: endIndexComment,
endLineNumber: endLineNumber,
title: "",
type: "compare.customize.commentcontent",
html: "",
rangeStyle: {styleClass: "lineHighlight", node: div2Insert}
//,style: {styleClass: "lineHighlightGutter1"}, //Gutter style at the line
};
highlightAnnotation =
{
start: startIndexHighlight,
end: endIndexHighlight,
// startLineNumber: startLineNumber,
// endLineNumber: endLineNumber,
title: "",
type: "compare.customize.linehighlight",
html: "",
style: {styleClass: "commentHighlight"} //Gutter style at the line
,lineStyle: {styleClass: "commentHighlightLine"}
};
commentAnnotations.push(commentAnnotation);
highlightAnnotations.push(highlightAnnotation);
}
annotationModel.replaceAnnotations([], commentAnnotations);
annotationModel.replaceAnnotations([], highlightAnnotations);
} else{
annotationModel.removeAnnotations("compare.customize.commentcontent");
annotationModel.removeAnnotations("compare.customize.linehighlight");
}
}
}
function openComment(startLine,endLine){
//This function controls if the comment form is allowed to open or not
var messageSelection = document.getElementById('message');
//check if there is annotation for this lines
var textModel = compare.getCompareView().getWidget().getMainEditor().getTextView().getModel();
var editor = compare.getCompareView().getWidget().getMainEditor();
var annotationModel = editor.getAnnotationModel();
var endIndex = textModel.getLineStart(endLine);
var startIndex = endIndex;
var aa = annotationModel.getAnnotations(startIndex, endIndex);
var openAComment = true;
while (aa.hasNext()) {
var a = aa.next();
if (a.type === "compare.customize.commentform" ||
a.type === "compare.customize.commentcontent" ||
a.type === "compare.customize.linehighlight"){
messageSelection.innerHTML = "There is already annotation for startLine: " + startLine + " and endLine: " + endLine;
openAComment = false;
}
}
if(openAComment){
messageSelection.innerHTML = "The selection startline is: " + startLine + " end line is: " + endLine;
}
}
requirePromise.then(function (Compare) {
var document = window.document;
/** Buttons */
var bCompare = document.getElementById("doCompare"); //$NON-NLS-0$
var bLoadSample = document.getElementById("loadSample"); //$NON-NLS-0$
var bAnimateDiffs = document.getElementById("animateDiffs"); //$NON-NLS-0$
var bAnimateInterval = document.getElementById("animateInterval"); //$NON-NLS-0$
var bgotoLine = document.getElementById("gotoLine1"); //$NON-NLS-0$
var bshowTheComments = document.getElementById("showTheComments");
var bhideTheComments = document.getElementById("hideTheComments");
var compareType = "byTwoContents"; //$NON-NLS-0$
var contentType = "js"; //$NON-NLS-0$
var options = {
parentDivId: "compareParentDiv", //$NON-NLS-0$
newFile: {
Name: "left." + contentType,
readonly: true,
Content: sampleLeft
},
oldFile: {
Name: "right." + contentType,
readonly: true,
Content: sampleRight
},
comments: sampleComments
};
compare = new Compare(options, "compareCmdDiv", "twoWay", true/*toggleable*/); //$NON-NLS-1$ //$NON-NLS-0$
widget = compare.getCompareView().getWidget();
function onLoadSample() {
if(sampleLeft && sampleRight) {
var widget = compare.getCompareView().getWidget();
widget.options.oldFile.Content = sampleRight;
widget.options.newFile.Content = sampleLeft;
widget.options.mapper = null;
compare.refresh(true);
}
}
function animateDiffs() {
var widget = compare.getCompareView().getWidget();
if(widget.nextChange()){
var interval = parseInt(bAnimateInterval.options[bAnimateInterval.selectedIndex].value, 10);
window.setTimeout(animateDiffs, interval);
}
}
function onAnimateDiffs() {
var widget = compare.getCompareView().getWidget();
widget.initDiffNav();
var interval = parseInt(bAnimateInterval.options[bAnimateInterval.selectedIndex].value, 10);
window.setTimeout(animateDiffs, interval);
}
function doCompare() {
var widget = compare.getCompareView().getWidget();
if(widget.type === "twoWay"){ //$NON-NLS-0$
var editors = widget.getEditors();
var oldContents = editors[0].getTextView().getText();
var newContents = editors[1].getTextView().getText();
widget.options.oldFile.Content = oldContents;
widget.options.newFile.Content = newContents;
widget.options.mapper = null;
compare.refresh(true);
}
}
function doGoToLine(commentIndex){
var widget = compare.getCompareView().getWidget();
var editors = widget.getEditors();
var editorR = editors[0];
var editorL = editors[1];
editorL.onGotoLine(commentIndex, 0, 0, function() {});
}
/* Adding events */
bCompare.onclick = doCompare;
bLoadSample.onclick = onLoadSample;
bAnimateDiffs.onclick = onAnimateDiffs;
bshowTheComments.onclick = showTheComments;
bhideTheComments.onclick = hideTheComments;
var lineruler = document. getElementsByClassName("rulerLines");
}); // end promise
</script>
<script id="showCommentTemplate" type="text/html">
<div class="container">
<div id={{id}} class="contentContainer">
<div class="nameAndTimeContainer">
<span class ="commenterAvatar"><img src={{url}}></span>
<span class="commenterName">{{ author }}</span>
<span class="commentTime">{{ date }}</span>
<span class="commentId">{{ id }}</span>
</div>
<div class="commentContentContainer">
{{{ message }}}
</div>
</div>
</div>
</script>
</head>
<body>
<div style="height:30px;width:99%;">
<table>
<tr>
<td>
<label style="padding-left:5px;margin-top:1px;" for="compareTypeSelect">Compare with</label>
<select id="compareTypeSelect" style="margin-top:5px;">
<option value="byTwoContents">Two text contents</option>
<option value="byFileURLs">Two file URLs</option>
<!-- <option value="byDiff">Base contents + unified diff</option> -->
</select>
</td>
<td id="contentTypes">
<label style="padding-left:5px;margin-top:1px;" for="fileTypeSelect">Content type</label>
<select id="contentTypeSelect" style="margin-top:5px;">
<option value="js">JavaScript</option>
<option value="html">HTML</option>
<option value="css">Css</option>
<option value="java">Java</option>
<option value="txt">Plain</option>
</select>
</td>
</tr>
</table>
</div>
<hr>
<div style="height:28px;width:99%;">
<table style="float:left;">
<tr>
<td>
<button id="loadSample" type="button">Load sample</button>
</td>
<td>
<button id="doCompare" type="button">Compare Again</button>
</td>
<td>
<button id="animateDiffs" type="button">Walk all diffs</button>
</td>
<td>
<label for="animateInterval">With</label>
<select id="animateInterval">
<option value="500">500ms</option>
<option value="1000">1000ms</option>
<option value="1500">1500ms</option>
<option value="2000">2000ms</option>
<option value="3000">3000ms</option>
</select>
</td>
<td>
<button id="showTheComments" type="button">Show the comments</button>
</td>
<td>
<button id="hideTheComments" type="button">Hide The comments</button>
</td>
<td><p id=showselection style= "color:red;"> Select the text you want to add annotation </p></td>
<td><div id="message" style= "color:blue; border:solid 1px"> </div></td>
</tr>
</table>
<span id="compareCmdDiv" style="float:right;"></span>
</div>
<hr>
<div>
<div id="compareParentDiv" class="compareContainer"></div>
</div>
</body>
</html>