Skip to content

Commit cbc9f49

Browse files
committed
adding underline to summary text editors
1 parent 0b16ead commit cbc9f49

File tree

9 files changed

+75
-144
lines changed

9 files changed

+75
-144
lines changed

WebContent/WEB-INF/jsp/assessment/AssessmentTextEditors.jsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@
413413
<div class="box-body pad">
414414
<div class="col-md-6">
415415
<form>
416-
<div name="engagmentnotes" toolbar="None"
417-
id="engagmentnotes" readonly="true" clickToEnable="false">
416+
<div name="engagementnotes" toolbar="None"
417+
id="engagementnotes" readonly="true" clickToEnable="false">
418418
<s:property value="assessment.accessNotes" />
419419
</div>
420420
</form>

WebContent/dist/js/overview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WebContent/dist/js/vulnview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WebContent/src/assessment/overview.js

Lines changed: 36 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ require('../loading/css/jquery-loading.css');
55
import Editor from '@toast-ui/editor'
66
import codeSyntaxHighlight from '@toast-ui/editor-plugin-code-syntax-highlight'
77
import colorSyntax from '@toast-ui/editor-plugin-color-syntax'
8-
import tableMergedCell from '@toast-ui/editor-plugin-table-merged-cell'
9-
import '@toast-ui/editor/dist/toastui-editor.css';
10-
import 'tui-color-picker/dist/tui-color-picker.css';
11-
import '@toast-ui/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.css';
128
import '../loading/js/jquery-loading';
139
import 'jquery';
1410
import 'datatables.net';
@@ -19,18 +15,15 @@ import 'jquery-ui';
1915
import 'jquery-confirm';
2016
import '../scripts/jquery.autocomplete.min';
2117
import 'select2';
22-
import { marked } from 'marked';
2318
import Chart from 'chart.js/auto';
24-
import TurndownService from 'turndown'
25-
let html2md = new TurndownService()
19+
import {FactionEditor} from '../utils/editor';
2620

2721

2822

2923
global._token = $("#_token")[0].value;
30-
let editors = {
31-
risk: {},
32-
summary: {}
33-
};
24+
let assessmentId = $("#assessmentId")[0].value
25+
console.log(assessmentId);
26+
let editors = new FactionEditor(assessmentId);
3427
let initialHTML={}
3528

3629

@@ -66,9 +59,6 @@ function alertMessage(resp, success) {
6659
global._token = resp.token;
6760
}
6861

69-
function getEditorText(name) {
70-
return editors[name].getHTML()
71-
}
7262
function showLoading(com) {
7363
$(com).loading({ overlay: true, base: 0.3 });
7464
}
@@ -114,8 +104,8 @@ function saveAllEditors(showLoadingScreen = false) {
114104
if (showLoadingScreen) {
115105
showLoading(".content");
116106
}
117-
let risk = getEditorText('risk');
118-
let sum = getEditorText('summary');
107+
let risk = editors.getEditorText('risk');
108+
let sum = editors.getEditorText('summary');
119109
let data = "riskAnalysis=" + encodeURIComponent(risk);
120110
data += "&summary=" + encodeURIComponent(sum);
121111
data += "&id=app" + $("#appid")[0].value
@@ -139,7 +129,7 @@ function saveAllEditors(showLoadingScreen = false) {
139129

140130
function saveEditor(type) {
141131

142-
let edits = getEditorText(type);
132+
let edits = editors.getEditorText(type);
143133
let name = "";
144134
let data = "";
145135
if (type == "risk") {
@@ -178,95 +168,23 @@ function queueSave(type) {
178168
}
179169
});
180170

181-
}
182-
function b64DecodeUnicode(str) {
183-
str = decodeURIComponent(str);
184-
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
185-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
186-
}).join(''));
187-
}
188-
function setEditorContents(contents, editor, isEncoded) {
189-
if (isEncoded) {
190-
contents = b64DecodeUnicode(contents)
191-
}
192-
console.log(contents)
193-
editors[editor].setHTML(contents, false);
194-
editors[editor].moveCursorToStart(false);
195-
}
196-
function entityDecode(encoded){
197-
let textArea = document.createElement("textarea");
198-
textArea.innerHTML = encoded;
199-
return textArea.innerText;
200-
201171
}
202172

203-
function createEditor(id){
204-
initialHTML[id] = entityDecode($(`#${id}`).html());
205-
$(`#${id}`).html("");
206-
editors[id]= new Editor({
207-
el: document.querySelector(`#${id}`),
208-
previewStyle: 'vertical',
209-
height: 'auto',
210-
autofocus: false,
211-
height: '560px',
212-
plugins: [colorSyntax, tableMergedCell],
213-
hooks: {
214-
addImageBlobHook: async (blob,callback, source)=>{
215-
const encodedImage = await imageToURL(blob)
216-
let data = "encodedImage=" + encodeURIComponent(encodedImage);
217-
data += "&assessmentId="+$("#appid")[0].value;
218-
$.post("UploadImage",data).done(function(resp) {
219-
let uuid = resp.message;
220-
callback("getImage?id=" + uuid);
221-
});
222-
223-
}
224-
}
225-
});
226-
editors[id].hide();
227-
editors[id].setHTML(initialHTML[id], false);
228-
initialHTML[id] = editors[id].getHTML();
229-
editors[id].show();
230-
editors[id].on('change', function() {
231-
if (document.getElementById(`${id}_header`).innerHTML == "") {
232-
queueSave(id);
233-
}
234-
});
235-
236-
/// This is a hack becuase toastui does not have inital undo history set correctly
237-
/// https://github.com/nhn/tui.editor/issues/3195
238-
editors[id].on( 'keydown', function(a,e){
239-
const html = editors[id].getHTML()
240-
if ((e.ctrlKey || e.metaKey) && e.key == 'z' && html == initialHTML[id]) {
241-
e.preventDefault();
242-
throw new Error("Prevent Undo");
243-
}
244-
})
245-
246-
}
247173
$(function() {
174+
248175
global._token = $("#_token")[0].value;
249-
createEditor("summary")
250-
createEditor("risk")
251-
let initialNotes = entityDecode($("#engagmentnotes").html());
252-
$("#engagmentnotes").html("");
253-
editors.engagenotes = new Editor({
254-
el: document.querySelector('#engagmentnotes'),
255-
toolbarItems:[],
256-
previewStyle: 'vertical',
257-
autofocus: false,
258-
viewer: true,
259-
height: '520px',
260-
initialEditType: 'wysiwyg'
261-
});
262-
editors.engagenotes.setHTML(initialNotes, false);
263-
editors.engagenotes.on('keydown', function(t,e) {
264-
if ( !((e.ctrlKey || e.metaKey) && e.key == 'c')) {
265-
e.preventDefault();
266-
throw new Error("Prevent Edit");
267-
}
268-
176+
editors.createEditor("summary",true, () => {
177+
if (document.getElementById(`summary_header`).innerHTML == "") {
178+
queueSave("summary");
179+
}
180+
});
181+
editors.createEditor("risk", true, () => {
182+
if (document.getElementById(`risk_header`).innerHTML == "") {
183+
queueSave("risk");
184+
}
269185
});
186+
let initialNotes = editors.entityDecode($("#engagementnotes").html());
187+
editors.createReadOnly("engagementnotes", initialNotes);
270188
let errorMessageShown=false;
271189
setInterval(() => {
272190
$.get("summary/check/locks").done((resp) => {
@@ -296,7 +214,7 @@ $(function() {
296214
$("#" + type).addClass("disabled")
297215

298216
document.getElementById(`${type}_header`).innerHTML = `<i class="lockUser">Editing by ${resp[type].lockBy} ${resp[type].lockAt}</i>`
299-
setEditorContents(resp[type].updatedText, type, true);
217+
editors.setEditorContents(type, resp[type].updatedText, true);
300218
} else {
301219
if (document.getElementById(`${type}_header`).innerHTML.indexOf("*") == -1) {
302220
document.getElementById(`${type}_header`).innerHTML = "";
@@ -564,7 +482,7 @@ $(function() {
564482
$(".saveTemp").click(function() {
565483
var id = $(this).attr("for");
566484
var data = "term=" + $("#" + id).val();
567-
data += "&summary=" + encodeURIComponent(getEditorText($("#" + id).attr("for")));
485+
data += "&summary=" + encodeURIComponent(editors.getEditorText($("#" + id).attr("for")));
568486
if ($("#" + id).attr("for") == "step_description")
569487
data += "&exploit=true";
570488
data += "&_token=" + global._token;
@@ -606,7 +524,7 @@ $(function() {
606524
selectedText = $("#tempName").val();
607525
}
608526
let data = `term=${selectedText.trim()}`
609-
data += "&summary=" + encodeURIComponent(getEditorText(type));
527+
data += "&summary=" + encodeURIComponent(editors.getEditorText(type));
610528
data += `&type=${type}`;
611529
data += "&active=true"
612530
data += "&_token=" + global._token;
@@ -711,8 +629,8 @@ $(function() {
711629
await $.get('tempSearchDetail?tmpId=' + value)
712630
.done(function(data) {
713631
let template = data.templates[0].text;
714-
let text = getEditorText(type) + "\n\n" + template;
715-
setEditorContents(text, type, false);
632+
let text = editors.getEditorText(type) + "\n\n" + template;
633+
editors.setEditorContents(type, text, false);
716634
});
717635

718636
}
@@ -738,21 +656,21 @@ $(function() {
738656
overWrite: {
739657
text: "OverWrite",
740658
action: function() {
741-
setEditorContents(text, type, false);
659+
editors.setEditorContents(type, text, false);
742660
}
743661
},
744662
prepend: {
745663
text: "Prepend",
746664
action: function() {
747-
text = text + "\n\n" + getEditorText(type);
748-
setEditorContents(text, type, false);
665+
text = text + "\n\n" + editors.getEditorText(type);
666+
editors.setEditorContents(type, text, false);
749667
}
750668
},
751669
append: {
752670
text: "Append",
753671
action: function() {
754-
text = getEditorText(type) + "\n\n" + text;
755-
setEditorContents(text, type, false);
672+
text = editors.getEditorText(type) + "\n\n" + text;
673+
editors.setEditorContents(type, text, false);
756674
}
757675
},
758676
cancel: function() {
@@ -788,7 +706,7 @@ $(function() {
788706
);
789707
},
790708
onSelect: function(e, term, item) {
791-
var s = getEditorText($(el).attr("for"));
709+
var s = editors.getEditorText($(el).attr("for"));
792710
var tmpId = term.split(":")[0];
793711
$(el).val(term.split(":")[1].trim());
794712
$(el).attr("tmpId", tmpId);
@@ -805,7 +723,7 @@ $(function() {
805723
.done(function(data) {
806724
let type = $(el).attr("for");
807725
let text = data.templates[0].text;
808-
setEditorContents(text, type, false);
726+
editors.setEditorContents(type, text, false);
809727
});
810728
}
811729

@@ -815,9 +733,9 @@ $(function() {
815733
action: function() {
816734
$.get('tempSearchDetail?tmpId=' + tmpId)
817735
.done(function(data) {
818-
var text = "<br />" + getEditorText($(el).attr("for"));
736+
var text = "<br />" + editors.getEditorText($(el).attr("for"));
819737
let type = $(el).attr("for");
820-
setEditorContents(text, type, false);
738+
editors.setEditorContents(type, text, false);
821739
});
822740
}
823741

@@ -827,9 +745,9 @@ $(function() {
827745
action: function() {
828746
$.get('tempSearchDetail?tmpId=' + tmpId)
829747
.done(function(data) {
830-
var text = getEditorText($(el).attr("for")) + "<br />";
748+
var text = editors.getEditorText($(el).attr("for")) + "<br />";
831749
let type = $(el).attr("for");
832-
setEditorContents(text, type, false);
750+
editors.setEditorContents(type, text, false);
833751
});
834752
}
835753

@@ -846,7 +764,7 @@ $(function() {
846764
.done(function(data) {
847765
let type = $(el).attr("for");
848766
let text = data.templates[0].text;
849-
setEditorContents(text, type, false);
767+
editors.setEditorContents(type, text, false);
850768
});
851769
}
852770

WebContent/src/assessment/vulnview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class EditLocks {
190190
}
191191

192192

193-
class VulnerablilityView {
193+
class VulnerabilityView {
194194

195195
constructor(assessmentId) {
196196
this._token = $("#_token")[0].value;
@@ -1227,7 +1227,7 @@ $(function () {
12271227
location.href = "#NoteView"
12281228
}
12291229
})
1230-
global.vulnView = new VulnerablilityView($("#assessmentId")[0].value);
1230+
global.vulnView = new VulnerabilityView($("#assessmentId")[0].value);
12311231
})
12321232

12331233

WebContent/src/utils/editor.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,26 @@ export class FactionEditor {
142142
}
143143
}
144144
}
145+
createReadOnly(id,initialHTML){
146+
$(`#${id}`).html("");
147+
this.editors[id]=new Editor({
148+
el: document.querySelector(`#${id}`),
149+
toolbarItems:[],
150+
previewStyle: 'vertical',
151+
autofocus: false,
152+
viewer: true,
153+
height: '520px',
154+
initialEditType: 'wysiwyg'
155+
});
156+
this.editors[id].setHTML(initialHTML, false);
157+
this.editors[id].on('keydown', function(t,e) {
158+
if ( !((e.ctrlKey || e.metaKey) && e.key == 'c')) {
159+
e.preventDefault();
160+
throw new Error("Prevent Edit");
161+
}
162+
163+
});
164+
}
145165

146166
createEditor(id, offloadImages, onChangeCallback) {
147167
if(typeof onChangeCallback == 'undefined'){
@@ -249,7 +269,8 @@ export class FactionEditor {
249269
getEditorText(id) {
250270
let html = this.editors[id].getHTML();
251271
html = html.replace(/\+\+([^+\n]+)\+\+/g, '<u>$1</u>');
252-
return Array.from($(html)).filter(a => a.innerHTML != "<br>").map(a => a.outerHTML).join("")
272+
//return Array.from($(html)).filter(a => a.innerHTML != "<br>").map(a => a.outerHTML).join("")
273+
return html
253274
}
254275
changeOff(id){
255276
this.editors[id].off('change')
@@ -273,7 +294,7 @@ export class FactionEditor {
273294
if (isEncoded) {
274295
contents = this.b64DecodeUnicode(contents)
275296
}
276-
contents = contents.replaceAll("<br />", "\n");
297+
//contents = contents.replaceAll("<br />", "\n");
277298
contents = contents.replace(/<u>([^<]+)<\/u>/g, '++$1++');
278299
this.editors[id].setHTML(contents, false);
279300
this.editors[id].moveCursorToStart(false);
@@ -286,7 +307,7 @@ export class FactionEditor {
286307
if (isEncoded) {
287308
contents = this.b64DecodeUnicode(contents)
288309
}
289-
contents = contents.replaceAll("<br />", "\n");
310+
//contents = contents.replaceAll("<br />", "\n");
290311
contents = contents.replace(/<u>([^<]+)<\/u>/g, '++$1++');
291312
this.editors[id].setHTML(contents, false);
292313
this.editors[id].moveCursorToStart(false);

0 commit comments

Comments
 (0)