看板模板编辑器添加自动补全功能

This commit is contained in:
datagear 2020-03-07 11:29:32 +08:00
parent 9d2cc50c62
commit 59445364cd
2 changed files with 85 additions and 9 deletions

View File

@ -661,6 +661,12 @@ dashboard.dashboardTemplateResource=\u770B\u677F\u6A21\u677F\u8D44\u6E90
dashboard.confirmDiscardCurrentTemplateContent=\u5F53\u524D\u6A21\u677F\u5185\u5BB9\u5DF2\u4FEE\u6539\uFF0C\u786E\u5B9A\u653E\u5F03\u5417\uFF1F
dashboard.saveFailForAtLeastOneTemplate=\u4FDD\u5B58\u5931\u8D25\uFF0C\u770B\u677F\u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u6A21\u677F
dashboard.deleteFailForAtLeastOneTemplate=\u5220\u9664\u5931\u8D25\uFF0C\u770B\u677F\u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u6A21\u677F
dashboard.templateEditor.autoComplete.chart-widget=\u56FE\u8868\u90E8\u4EF6
dashboard.templateEditor.autoComplete.chart-options=\u56FE\u8868\u8BBE\u7F6E\u9879
dashboard.templateEditor.autoComplete.chart-theme=\u56FE\u8868\u4E3B\u9898
dashboard.templateEditor.autoComplete.echarts-theme=echarts\u4E3B\u9898
dashboard.templateEditor.autoComplete.map-urls=\u5730\u56FEURL
dashboard.templateEditor.autoComplete.chart-renderer=\u56FE\u8868\u6E32\u67D3\u5668
dashboard.auth.resouceTypeLabel=\u770B\u677F
#Chart plugin

View File

@ -127,16 +127,91 @@ readonly 是否只读操作允许为null
{
return "${contextPath}/analysis/dashboard/" + action;
};
po.getLastTagText = function(text)
{
if(!text)
return text;
var idx = -1;
for(var i=text.length-1;i>=0;i--)
{
var c = text.charAt(i);
if(c == '>' || c == '<')
{
idx = i;
break;
}
}
return (idx < 0 ? text : text.substr(idx));
};
po.getTemplatePrevTagText = function(row, column)
{
var text = po.templateEditor.session.getLine(row).substring(0, column);
//反向查找直到'>'或'<'
var prevRow = row;
while((!text || !(/[<>]/g.test(text))) && (prevRow--) >= 0)
text = po.templateEditor.session.getLine(prevRow) + text;
return po.getLastTagText(text);
};
po.resolveHtmlTagName = function(text)
{
var re = text.match(/<\S*/);
if(re)
return re[0].substr(1);
return "";
};
po.initTemplateEditor = function()
{
var templateEditorCompleters =
po.templateEditorCompletions = [
{name: "dg-chart-widget", value: "dg-chart-widget", caption: "",
meta: "<@spring.message code='dashboard.templateEditor.autoComplete.chart-widget' />", tagNames: ["div"]},
{name: "dg-chart-options", value: "dg-chart-options", caption: "",
meta: "<@spring.message code='dashboard.templateEditor.autoComplete.chart-options' />", tagNames: ["div","body"]},
{name: "dg-chart-renderer", value: "dg-chart-renderer", caption: "",
meta: "<@spring.message code='dashboard.templateEditor.autoComplete.chart-renderer' />", tagNames: ["div"]},
{name: "dg-chart-theme", value: "dg-chart-theme", caption: "",
meta: "<@spring.message code='dashboard.templateEditor.autoComplete.chart-theme' />", tagNames: ["body"]},
{name: "dg-echarts-theme", value: "dg-echarts-theme", caption: "",
meta: "<@spring.message code='dashboard.templateEditor.autoComplete.echarts-theme' />", tagNames: ["body"]},
{name: "dg-echarts-map-urls", value: "dg-echarts-map-urls", caption: "",
meta: "<@spring.message code='dashboard.templateEditor.autoComplete.map-urls' />", tagNames: ["body"]}
];
po.templateEditorCompleters =
[
{
identifierRegexps : [/[a-zA-Z_0-9\.\$]/],
identifierRegexps : [/[a-zA-Z_0-9\-]/],
getCompletions: function(editor, session, pos, prefix, callback)
{
return [];
var prevText = po.getTemplatePrevTagText(pos.row, pos.column);
var tagName = po.resolveHtmlTagName(prevText);
if(tagName)
{
tagName = tagName.toLowerCase();
var completions = [];
for(var i=0; i<po.templateEditorCompletions.length; i++)
{
var comp = po.templateEditorCompletions[i];
if(!comp.tagNames || $.inArray(tagName, comp.tagNames) > -1)
completions.push(comp);
}
callback(null, completions);
}
else
callback(null, []);
}
}
];
@ -706,12 +781,7 @@ readonly 是否只读操作允许为null
var chartId = charts[0].id;
var chartName = charts[0].name;
var text = po.templateEditor.session.getLine(cursor.row).substring(0, cursor.column);
//获取所处标签字符串
var prevRow = cursor.row;
while((!text || !(/[<>]/g.test(text))) && (prevRow--) >= 0)
text = po.templateEditor.session.getLine(prevRow) + text;
var text = po.getTemplatePrevTagText(cursor.row, cursor.column);
// =
if(/=\s*$/g.test(text))