수정가능 범위 하이라이트, IMPORT 추가, 스크립트 선택 필드Select2 로 변경

This commit is contained in:
yunjy
2022-08-19 16:02:36 +09:00
parent 086e878b60
commit b302bb75fa
5 changed files with 94 additions and 29 deletions
@@ -4,6 +4,7 @@ import java.util.Optional;
import javax.validation.Valid;
import com.eactive.httpmockserver.script.ScriptInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpMethod;
@@ -21,6 +22,9 @@ public class ApiManageController {
@Autowired
private ApiService apiService;
@Autowired
private ScriptInfoService scriptInfoService;
@Autowired
private ApiServiceKeyService apiKeyService;
@@ -47,6 +51,8 @@ public class ApiManageController {
model.addAttribute("apiInfo", apiInfo);
}
model.addAttribute("scriptInfos", scriptInfoService.findAllScriptInfos());
return "page/add-edit-api";
}
@@ -2,5 +2,12 @@ package com.eactive.httpmockserver.script;
public interface Script {
/**
* Script Process Function
* @param requestMessage 수신 받은 요청 메시지
* @param responseMessage 정의된 응답 메시지
* @return 스크립트 수행 후 응답 할 메시지
* @throws Exception
*/
public String postProcess(String requestMessage, String responseMessage) throws Exception;
}
@@ -1,8 +1,15 @@
package com.eactive.httpmockserver.script.dynamic;
import com.eactive.httpmockserver.script.Script;
//IMPORT 클래스는 여기에 정의해 주세요
public class implements Script{
@Override
/**
* Script Process Function
* @param requestMessage 수신 받은 요청 메시지
* @param responseMessage 정의된 응답 메시지
* @return 스크립트 수행 후 응답 할 메시지
* @throws Exception
*/
public String postProcess(String requestMessage, String responseMessage) throws Exception {
return responseMessage;
}
@@ -159,9 +159,9 @@
<div class="form-group row">
<label class="col-sm-3 col-form-label">스크립트 명</label>
<div class="col-sm-9">
<input type="text" th:field="*{scriptName}"
class="form-control"
placeholder="수행 스크립트 명">
<select class="form-control select2bs4" style="width: 100%;" >
<option th:each="scriptInfo : ${scriptInfos}" th:value="${scriptInfo.scriptName}" th:text="${scriptInfo.scriptName + '(' + scriptInfo.scriptDesc + ')'}"></option>
</select>
</div>
</div>
</div>
@@ -230,6 +230,11 @@
<link rel="stylesheet" data-name="vs/editor/editor.main"
th:href="@{/plugins/vs/editor/editor.main.css}">
<link rel="stylesheet" th:href="@{/plugins/select2/css/select2.min.css}">
<link rel="stylesheet" th:href="@{/plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css}">
<script th:src="@{/plugins/select2/js/select2.full.js}"></script>
<script>var require = { paths: { 'vs': '../../plugins/vs' } };</script>
<script th:src="@{/plugins/vs/loader.js}"></script>
@@ -238,6 +243,11 @@
<script th:inline="javascript">
var urlForSidebar = "/manage/findAllApis";
//Initialize Select2 Elements
$('.select2bs4').select2({
theme: 'bootstrap4'
})
function setMonaco(elementId, selectId, initValue){
var targetDivElement = document.getElementById(elementId);
@@ -89,6 +89,9 @@
<th:block layout:fragment="script">
<link rel="stylesheet" data-name="vs/editor/editor.main"
th:href="@{/plugins/vs/editor/editor.main.css}">
<link rel="stylesheet"
th:href="@{/plugins/vs/plugin/constrained-editor-plugin/constrainedEditorPlugin.css}">
<script th:src="@{/plugins/vs/plugin/constrained-editor-plugin/constrainedEditorPlugin.js}"></script>
<script>var require = { paths: { 'vs': '../../plugins/vs' } };</script>
@@ -114,33 +117,65 @@
wrappingIndent: 'none',
automaticLayout: true
});
const readonlyRange = new monaco.Range (1, 0, 7, 0)
editor.onKeyDown (e => {
const contains = editor.getSelections().findIndex (range => readonlyRange.intersectRanges (range))
let currentLineNumber = editor.getPosition().lineNumber
let lineCount = editor.getModel().getLineCount();
console.log(e.ctrlKey)
if(e.ctrlKey && e.keyCode == 33){
return
}
switch(e.keyCode){
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 63:
return
}
const matchTailPart = lineCount == currentLineNumber || lineCount - 1 == currentLineNumber;
if (contains !== -1 || matchTailPart) {
e.stopPropagation ()
e.preventDefault () // for Ctrl+C, Ctrl+V
return false;
const constrainedInstance = constrainedEditor(monaco);
constrainedInstance.initializeIn(editor);
const model = editor.getModel();
let editableLine = 14
const linesContent = editor.getModel().getLinesContent();
for (let i = 0; i < linesContent.length; i++) {
const lineText = linesContent[i].trim();
if(lineText.startsWith('public String postProcess')){
editableLine = i + 2
break
}
});
}
const editableLineTextLength = linesContent[editableLine - 1].length + 1;
constrainedInstance.addRestrictionsTo(model, [{
// range : [ startLine, startColumn, endLine, endColumn ]
range: [3, 1, 3, 26], // Range of Util Variable name
label: 'import',
allowMultiline: true
}, {
range: [editableLine, 1, editableLine, editableLineTextLength], // Range of Function definition
allowMultiline: true,
label: 'funcDefinition'
}]);
model.toggleHighlightOfEditableAreas();
// const readonlyRange = new monaco.Range (1, 0, 7, 0)
// editor.onKeyDown (e => {
// const contains = editor.getSelections().findIndex (range => readonlyRange.intersectRanges (range))
// let currentLineNumber = editor.getPosition().lineNumber
// let lineCount = editor.getModel().getLineCount();
// console.log(e.ctrlKey)
// if(e.ctrlKey && e.keyCode == 33){
// return
// }
// switch(e.keyCode){
// case 13:
// case 14:
// case 15:
// case 16:
// case 17:
// case 18:
// case 63:
// return
// }
//
// const matchTailPart = lineCount == currentLineNumber || lineCount - 1 == currentLineNumber;
// if (contains !== -1 || matchTailPart) {
// e.stopPropagation ()
// e.preventDefault () // for Ctrl+C, Ctrl+V
// return false;
// }
// });
$('#form').submit(function(eventObj) {
$('#scriptName').prop( "disabled", false );