Browse Source

sqlEditor交互修改

master
windy 7 years ago
parent
commit
164506b02d
  1. 2
      Gruntfile.js
  2. 22
      bi/base.css
  3. 739
      bi/base.js
  4. 12
      demo/js/base/editor/demo.sql_editor.js
  5. 22
      dist/base.css
  6. 739
      dist/base.js
  7. 22
      dist/bundle.css
  8. 739
      dist/bundle.js
  9. 37
      dist/demo.js
  10. 3
      src/base/formula/codemirror/show-hint.js
  11. 45
      src/base/formula/codemirror/sql-hint.js
  12. 177
      src/base/formula/codemirror/sql-mode.js
  13. 2
      src/base/formula/config.js
  14. 9
      src/base/formula/editor.sql.js
  15. 3
      src/css/base/formula/codemirror.css
  16. 19
      src/css/base/sql/sql.css
  17. 2
      src/less/base/formula/codemirror.less
  18. 23
      src/less/base/sql/sql.less

2
Gruntfile.js

@ -38,6 +38,7 @@ module.exports = function (grunt) {
baseJs: { baseJs: {
src: [ src: [
'src/third/**/*.js', 'src/third/**/*.js',
'src/base/formula/config.js',
'src/base/pane.js', 'src/base/pane.js',
'src/base/single/single.js', 'src/base/single/single.js',
'src/base/single/text.js', 'src/base/single/text.js',
@ -172,6 +173,7 @@ module.exports = function (grunt) {
bi_baseJs: { bi_baseJs: {
src: [ src: [
'src/third/**/*.js', 'src/third/**/*.js',
'src/base/formula/config.js',
'src/base/pane.js', 'src/base/pane.js',
'src/base/single/single.js', 'src/base/single/single.js',
'src/base/single/text.js', 'src/base/single/text.js',

22
bi/base.css

@ -591,9 +591,6 @@ span.CodeMirror-selectedtext {
color: black; color: black;
cursor: pointer; cursor: pointer;
} }
.CodeMirror-hints {
z-index: 1000000000;
}
li.CodeMirror-hint-active { li.CodeMirror-hint-active {
background: #08f; background: #08f;
color: white; color: white;
@ -1036,6 +1033,25 @@ body .bi-button.button-ignore.disabled.clear:active,
color: #faaa39; color: #faaa39;
border: 1px solid #f4cbcb; border: 1px solid #f4cbcb;
} }
.bi-sql-editor .cm-s-default span[class*="#"] {
color: #faaa39;
}
.bi-sql-editor .cm-s-default .cm-keyword {
color: #3685f2;
}
.bi-sql-editor .cm-s-default .cm-function {
color: #faaa39;
}
.CodeMirror-hints .sql-fr-function {
color: #faaa39;
}
.CodeMirror-hints .sql-keyword {
color: #3685f2;
}
.CodeMirror-hints .CodeMirror-hint-active {
background: #3f8ce8;
color: #ffffff;
}
.bi-collection-table-cell { .bi-collection-table-cell {
-webkit-box-sizing: border-box; -webkit-box-sizing: border-box;
/*Safari3.2+*/ /*Safari3.2+*/

739
bi/base.js

File diff suppressed because one or more lines are too long

12
demo/js/base/editor/demo.sql_editor.js

@ -6,16 +6,24 @@ Demo.SQLEditor = BI.inherit(BI.Widget, {
baseCls: "demo-editor" baseCls: "demo-editor"
}, },
render: function () { render: function () {
var self = this;
this.formula = BI.createWidget({ this.formula = BI.createWidget({
type : 'bi.sql_editor', type : 'bi.sql_editor',
width : 300, width : 300,
height : 200, height : 200,
value : 'select * from DEMO_CONTRACT' value : "select * from DEMO_CONTRACT where 合同类型 = '长期协议' and 购买数量 = sum([1,2,3,4])"
}); });
BI.createWidget({ BI.createWidget({
type: "bi.left", type: "bi.left",
element: this, element: this,
items: [this.formula], items: [this.formula, {
type: "bi.button",
height: 24,
handler: function () {
BI.Msg.alert("", self.formula.getValue());
}
}],
hgap: 20, hgap: 20,
vgap: 20 vgap: 20
}) })

22
dist/base.css vendored

@ -591,9 +591,6 @@ span.CodeMirror-selectedtext {
color: black; color: black;
cursor: pointer; cursor: pointer;
} }
.CodeMirror-hints {
z-index: 1000000000;
}
li.CodeMirror-hint-active { li.CodeMirror-hint-active {
background: #08f; background: #08f;
color: white; color: white;
@ -1036,6 +1033,25 @@ body .bi-button.button-ignore.disabled.clear:active,
color: #faaa39; color: #faaa39;
border: 1px solid #f4cbcb; border: 1px solid #f4cbcb;
} }
.bi-sql-editor .cm-s-default span[class*="#"] {
color: #faaa39;
}
.bi-sql-editor .cm-s-default .cm-keyword {
color: #3685f2;
}
.bi-sql-editor .cm-s-default .cm-function {
color: #faaa39;
}
.CodeMirror-hints .sql-fr-function {
color: #faaa39;
}
.CodeMirror-hints .sql-keyword {
color: #3685f2;
}
.CodeMirror-hints .CodeMirror-hint-active {
background: #3f8ce8;
color: #ffffff;
}
.bi-collection-table-cell { .bi-collection-table-cell {
-webkit-box-sizing: border-box; -webkit-box-sizing: border-box;
/*Safari3.2+*/ /*Safari3.2+*/

739
dist/base.js vendored

File diff suppressed because one or more lines are too long

22
dist/bundle.css vendored

@ -2186,9 +2186,6 @@ span.CodeMirror-selectedtext {
color: black; color: black;
cursor: pointer; cursor: pointer;
} }
.CodeMirror-hints {
z-index: 1000000000;
}
li.CodeMirror-hint-active { li.CodeMirror-hint-active {
background: #08f; background: #08f;
color: white; color: white;
@ -2631,6 +2628,25 @@ body .bi-button.button-ignore.disabled.clear:active,
color: #faaa39; color: #faaa39;
border: 1px solid #f4cbcb; border: 1px solid #f4cbcb;
} }
.bi-sql-editor .cm-s-default span[class*="#"] {
color: #faaa39;
}
.bi-sql-editor .cm-s-default .cm-keyword {
color: #3685f2;
}
.bi-sql-editor .cm-s-default .cm-function {
color: #faaa39;
}
.CodeMirror-hints .sql-fr-function {
color: #faaa39;
}
.CodeMirror-hints .sql-keyword {
color: #3685f2;
}
.CodeMirror-hints .CodeMirror-hint-active {
background: #3f8ce8;
color: #ffffff;
}
.bi-collection-table-cell { .bi-collection-table-cell {
-webkit-box-sizing: border-box; -webkit-box-sizing: border-box;
/*Safari3.2+*/ /*Safari3.2+*/

739
dist/bundle.js vendored

File diff suppressed because one or more lines are too long

37
dist/demo.js vendored

@ -831,7 +831,38 @@ BI.shortcut("demo.multifile_editor", Demo.CodeEditor);Demo.RichEditor = BI.inher
this.editor.setValue("这是一条<font size=\"4\" color=\"#009de3\">测试</font>数据"); this.editor.setValue("这是一条<font size=\"4\" color=\"#009de3\">测试</font>数据");
} }
}); });
BI.shortcut("demo.rich_editor", Demo.RichEditor);Demo.CodeEditor = BI.inherit(BI.Widget, { BI.shortcut("demo.rich_editor", Demo.RichEditor);/**
* Created by Windy on 2017/12/15.
*/
Demo.SQLEditor = BI.inherit(BI.Widget, {
props: {
baseCls: "demo-editor"
},
render: function () {
var self = this;
this.formula = BI.createWidget({
type : 'bi.sql_editor',
width : 300,
height : 200,
value : "select * from DEMO_CONTRACT where 合同类型 = '长期协议' and 购买数量 = sum([1,2,3,4])"
});
BI.createWidget({
type: "bi.left",
element: this,
items: [this.formula, {
type: "bi.button",
height: 24,
handler: function () {
BI.Msg.alert("", self.formula.getValue());
}
}],
hgap: 20,
vgap: 20
})
}
});
BI.shortcut("demo.sql_editor", Demo.SQLEditor);Demo.CodeEditor = BI.inherit(BI.Widget, {
props: { props: {
baseCls: "demo-editor" baseCls: "demo-editor"
}, },
@ -4700,6 +4731,10 @@ BI.shortcut("demo.value_chooser_pane", Demo.ValueChooserPane);Demo.ADDONS_CONFIG
pId: 202, pId: 202,
text: "bi.textarea_editor", text: "bi.textarea_editor",
value: "demo.textarea_editor" value: "demo.textarea_editor"
}, {
pId: 202,
text: "bi.sql_editor",
value: "demo.sql_editor"
}, { }, {
pId: 202, pId: 202,
text: "bi.formula_editor", text: "bi.formula_editor",

3
src/base/formula/codemirror/show-hint.js

@ -73,6 +73,8 @@
else { else {
this.cm.replaceRange(getText(completion), completion.from || data.from, this.cm.replaceRange(getText(completion), completion.from || data.from,
completion.to || data.to, "complete"); completion.to || data.to, "complete");
if(completion.isKeyword === true){
}else{
var to = this.cm.getCursor(); var to = this.cm.getCursor();
this.cm.markText(completion.from || data.from, to, {className: "#function", atomic: true}); this.cm.markText(completion.from || data.from, to, {className: "#function", atomic: true});
this.cm.replaceSelection("() "); this.cm.replaceSelection("() ");
@ -81,6 +83,7 @@
this.cm.setCursor(to); this.cm.setCursor(to);
this.cm.focus(); this.cm.focus();
} }
}
CodeMirror.signal(data, "pick", completion); CodeMirror.signal(data, "pick", completion);
this.close(); this.close();
}, },

45
src/base/formula/codemirror/sql-hint.js

@ -65,7 +65,7 @@
} }
function match(string, word) { function match(string, word) {
if (BI.isNotEmptyString(string)) { if (BI.isNotEmptyString(string) && word.length !== string.length) {
var len = string.length; var len = string.length;
var sub = getText(word).substr(0, len); var sub = getText(word).substr(0, len);
return string.toUpperCase() === sub.toUpperCase(); return string.toUpperCase() === sub.toUpperCase();
@ -75,7 +75,7 @@
function addMatches(result, search, wordlist, formatter) { function addMatches(result, search, wordlist, formatter) {
if (isArray(wordlist)) { if (isArray(wordlist)) {
for (var i = 0; i < wordlist.length; i++) for (var i = 0; i < wordlist.length; i++)
if (match(search, wordlist[i])) result.push(formatter(wordlist[i])) if (match(search, wordlist[i])) result.push(formatter(wordlist[i], i));
} else { } else {
for (var word in wordlist) if (wordlist.hasOwnProperty(word)) { for (var word in wordlist) if (wordlist.hasOwnProperty(word)) {
var val = wordlist[word] var val = wordlist[word]
@ -240,6 +240,20 @@
var disableKeywords = options && options.disableKeywords; var disableKeywords = options && options.disableKeywords;
defaultTable = defaultTableName && getTable(defaultTableName); defaultTable = defaultTableName && getTable(defaultTableName);
keywords = getKeywords(editor); keywords = getKeywords(editor);
var keywordsCount = BI.size(keywords);
var functions = [];
var desc = {};
var cur = editor.getCursor();
var token = editor.getTokenAt(cur);
BI.each(BI.FormulaCollections, function(idx, formula){
if(formula.lastIndexOf(token.string, 0) == 0 && !BI.contains(functions, formula)){
functions.push(formula);
}
});
BI.each(BI.FormulaJson, function(idx, formula){
desc[formula.name.toLowerCase()] = formula.def;
});
keywords = BI.concat(BI.keys(keywords), functions);
identifierQuote = getIdentifierQuote(editor); identifierQuote = getIdentifierQuote(editor);
if (defaultTableName && !defaultTable) if (defaultTableName && !defaultTable)
@ -250,9 +264,8 @@
if (defaultTable.columns) if (defaultTable.columns)
defaultTable = defaultTable.columns; defaultTable = defaultTable.columns;
var cur = editor.getCursor();
var result = []; var result = [];
var token = editor.getTokenAt(cur), start, end, search; var start, end, search;
if (token.end > cur.ch) { if (token.end > cur.ch) {
token.end = cur.ch; token.end = cur.ch;
token.string = token.string.slice(0, cur.ch - token.start); token.string = token.string.slice(0, cur.ch - token.start);
@ -269,10 +282,28 @@
if (search.charAt(0) == "." || search.charAt(0) == identifierQuote) { if (search.charAt(0) == "." || search.charAt(0) == identifierQuote) {
start = nameCompletion(cur, token, result, editor); start = nameCompletion(cur, token, result, editor);
} else { } else {
addMatches(result, search, tables, function(w) {return w;}); addMatches(result, search, tables, function(w) {return w});
addMatches(result, search, defaultTable, function(w) {return w;}); addMatches(result, search, defaultTable, function(w) {return w});
if (!disableKeywords) if (!disableKeywords)
addMatches(result, search, keywords, function(w) {return w.toUpperCase();}); addMatches(result, search, keywords, function(w, i) {
var isKeyword = i < keywordsCount;
return {
isKeyword: isKeyword,
text: w,
description: desc[w] || "SQL关键字",
className: isKeyword ? "sql-keyword" : "sql-fr-function",
render: function (Element, self, data) {
var label = BI.createWidget({
type: "bi.label",
element: Element,
text: data.displayText || getText(data)
});
label.setTitle(data.description, {
container: "body"
});
}
};
});
} }
return {list: result, from: Pos(cur.line, start), to: Pos(cur.line, end)}; return {list: result, from: Pos(cur.line, start), to: Pos(cur.line, end)};

177
src/base/formula/codemirror/sql-mode.js

File diff suppressed because one or more lines are too long

2
src/base/formula/config.js

File diff suppressed because one or more lines are too long

9
src/base/formula/editor.sql.js

@ -14,7 +14,6 @@ BI.SQLEditor = BI.inherit(BI.Widget, {
BI.CodeEditor.superclass._init.apply(this, arguments); BI.CodeEditor.superclass._init.apply(this, arguments);
var o = this.options, self = this; var o = this.options, self = this;
this.editor = CodeMirror(this.element[0], { this.editor = CodeMirror(this.element[0], {
//mode: {name: 'text/x-sql'},
mode: "text/x-sql", mode: "text/x-sql",
textWrapping: true, textWrapping: true,
lineWrapping: true, lineWrapping: true,
@ -25,7 +24,9 @@ BI.SQLEditor = BI.inherit(BI.Widget, {
this.editor.on("change", function (cm, change) { this.editor.on("change", function (cm, change) {
self._checkWaterMark(); self._checkWaterMark();
if (o.showHint) { if (o.showHint) {
CodeMirror.showHint(cm, CodeMirror.formulaHint, {completeSingle: false}); CodeMirror.showHint(cm, CodeMirror.sqlHint, {
completeSingle: false
});
} }
BI.nextTick(function () { BI.nextTick(function () {
self.fireEvent(BI.FormulaEditor.EVENT_CHANGE) self.fireEvent(BI.FormulaEditor.EVENT_CHANGE)
@ -91,11 +92,11 @@ BI.SQLEditor = BI.inherit(BI.Widget, {
}, },
getValue: function () { getValue: function () {
return this.editor.getValue();
}, },
setValue: function (v) { setValue: function (v) {
this.editor.setValue(v);
} }
}); });
BI.shortcut("bi.sql_editor", BI.SQLEditor); BI.shortcut("bi.sql_editor", BI.SQLEditor);

3
src/css/base/formula/codemirror.css

@ -471,9 +471,6 @@ span.CodeMirror-selectedtext {
color: black; color: black;
cursor: pointer; cursor: pointer;
} }
.CodeMirror-hints {
z-index: 1000000000;
}
li.CodeMirror-hint-active { li.CodeMirror-hint-active {
background: #08f; background: #08f;
color: white; color: white;

19
src/css/base/sql/sql.css

@ -0,0 +1,19 @@
.bi-sql-editor .cm-s-default span[class*="#"] {
color: #faaa39;
}
.bi-sql-editor .cm-s-default .cm-keyword {
color: #3685f2;
}
.bi-sql-editor .cm-s-default .cm-function {
color: #faaa39;
}
.CodeMirror-hints .sql-fr-function {
color: #faaa39;
}
.CodeMirror-hints .sql-keyword {
color: #3685f2;
}
.CodeMirror-hints .CodeMirror-hint-active {
background: #3f8ce8;
color: #ffffff;
}

2
src/less/base/formula/codemirror.less

@ -579,7 +579,7 @@ span.CodeMirror-selectedtext {
} }
.CodeMirror-hints { .CodeMirror-hints {
z-index: @zIndex-tip; //z-index: @zIndex-tip;
} }
li.CodeMirror-hint-active { li.CodeMirror-hint-active {

23
src/less/base/sql/sql.less

@ -6,4 +6,27 @@
color: @color-bi-text-warning; color: @color-bi-text-warning;
} }
& .cm-s-default .cm-keyword {
color: @color-bi-text-highlight;
}
& .cm-s-default .cm-function {
color: @color-bi-text-warning;
}
}
.CodeMirror-hints {
& .sql-fr-function{
color: @color-bi-text-warning;
}
& .sql-keyword{
color: @color-bi-text-highlight;
}
.CodeMirror-hint-active {
background: @color-bi-background-highlight;
color: @color-bi-text;
}
} }
Loading…
Cancel
Save