Browse Source

refactor: 将验证方法提取出来

qufenxi
alan 6 years ago
parent
commit
2334d1a068
  1. 1
      .eslintrc.js
  2. 6
      src/app/link_set/left/left_item/left.item.component.ts
  3. 6
      src/app/link_set/left/left_item/left.item.icon.component.ts
  4. 6
      src/app/link_set/more/more.link.component.ts
  5. 64
      src/app/link_set/right/right_edit/right.edit.component.ts
  6. 4
      src/app/link_set/right/right_edit/right.edit.constant.ts
  7. 58
      src/app/link_set/right/right_edit/right.edit.mysql.component.ts
  8. 4
      src/app/link_set/right/right_edit/right.edit.service.ts
  9. 16
      src/demo/plugin.redis.edit.ts

1
.eslintrc.js

@ -25,6 +25,7 @@ module.exports = {
'for-direction': 2, 'for-direction': 2,
// 关键字前后必须有空格 // 关键字前后必须有空格
'keyword-spacing': 2, 'keyword-spacing': 2,
'key-spacing':2,
// 最大块嵌套深度为 5 层 // 最大块嵌套深度为 5 层
'max-depth': [2, 5], 'max-depth': [2, 5],
// 最大回调深度为 3 层 // 最大回调深度为 3 层

6
src/app/link_set/left/left_item/left.item.component.ts

@ -5,8 +5,8 @@ import {ACTION_COPY, ACTION_TEST, ACTION_DELETE, DEFAULT_INFO} from '@private/co
const className = 'fr.component.linkSet.left.item'; const className = 'fr.component.linkSet.left.item';
const Widget: WidgetType = { const Widget: WidgetType = {
props: { props: {
title:'', title: '',
id:'', id: '',
creator: '', creator: '',
}, },
_store() { _store() {
@ -30,7 +30,7 @@ const Widget: WidgetType = {
}, },
{ {
type: TextButton, type: TextButton,
cls:'link-title', cls: 'link-title',
textAlign: 'left', textAlign: 'left',
text: title, text: title,
title, title,

6
src/app/link_set/left/left_item/left.item.icon.component.ts

@ -22,7 +22,7 @@ const Widget: WidgetType = {
el: { el: {
type: Icon, type: Icon,
cls, cls,
extraCls: 'action-icon', baseCls: 'action-icon',
height: 24, height: 24,
width: 26, width: 26,
title, title,
@ -47,14 +47,14 @@ const Widget: WidgetType = {
eventName: BI.BubbleCombo.EVENT_EXPAND, eventName: BI.BubbleCombo.EVENT_EXPAND,
action () { action () {
iconContent.element.css({ iconContent.element.css({
visibility:'visible', visibility: 'visible',
}); });
}, },
}, { }, {
eventName: BI.BubbleCombo.EVENT_AFTER_HIDEVIEW, eventName: BI.BubbleCombo.EVENT_AFTER_HIDEVIEW,
action () { action () {
iconContent.element.css({ iconContent.element.css({
visibility:'hidden', visibility: 'hidden',
}); });
}, },
}], }],

6
src/app/link_set/more/more.link.component.ts

@ -10,9 +10,9 @@ const Widget: WidgetType = {
cls: 'more-link', cls: 'more-link',
items: [ items: [
{ {
el:{ el: {
type: Vertical, type: Vertical,
items:[{ items: [{
type: SearchEditor, type: SearchEditor,
width: 300, width: 300,
watermark: BI.i18nText('Dec-Dcm_Search'), watermark: BI.i18nText('Dec-Dcm_Search'),
@ -22,7 +22,7 @@ const Widget: WidgetType = {
}, },
{ {
type: Left, type: Left,
cls:'more-link-item', cls: 'more-link-item',
ref(ref: any) { ref(ref: any) {
morkLinkItem = ref; morkLinkItem = ref;
}, },

64
src/app/link_set/right/right_edit/right.edit.component.ts

@ -4,14 +4,14 @@ import charset from './right.edit.constant';
import Model from '../../link-set.model'; import Model from '../../link-set.model';
import FormItem from '@shared/components/form.item.component'; import FormItem from '@shared/components/form.item.component';
import Title from '@shared/components/title.component'; import Title from '@shared/components/title.component';
import {getDrivers} from './right.edit.service'; import {getDrivers, connectNameChecker} from './right.edit.service';
let ConnectionName: any = null; let ConnectionName: any = null;
const className = 'fr.component.right.edit'; const className = 'fr.component.right.edit';
const Widget: WidgetType = { const Widget: WidgetType = {
_store() { _store() {
return BI.Models.getModel(Model); return BI.Models.getModel(Model);
}, },
watch:{ watch: {
connectionNameErr(msg: string) { connectionNameErr(msg: string) {
if (msg) { if (msg) {
BI.Bubbles.show('singleBubble', msg, ConnectionName, { BI.Bubbles.show('singleBubble', msg, ConnectionName, {
@ -34,7 +34,7 @@ const Widget: WidgetType = {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName'), text: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName'),
hint: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName-Change-Confirm'), hint: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName-Change-Confirm'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
width: 300, width: 300,
@ -62,14 +62,14 @@ const Widget: WidgetType = {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_First_Step'), text: BI.i18nText('Dec-Dcm_First_Step'),
height: 400, height: 400,
form:{ form: {
type: Vertical, type: Vertical,
cls: 'right-form', cls: 'right-form',
items:[ items: [
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Driver'), text: BI.i18nText('Dec-Dcm_Connection_Form_Driver'),
form:{ form: {
type: TextValueCombo, type: TextValueCombo,
cls: 'bi-border', cls: 'bi-border',
width: 300, width: 300,
@ -89,10 +89,10 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_URL'), text: BI.i18nText('Dec-Dcm_Connection_Form_URL'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300, width: 300,
value: linkSelected.url, value: linkSelected.url,
listeners: [{ listeners: [{
@ -109,12 +109,18 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'), text: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'),
form:{ form: {
type: TextValueCombo, type: TextValueCombo,
cls: 'bi-border', cls: 'bi-border',
width: 300, width: 300,
text: linkSelected.originalCharsetName === '' ? BI.i18nText('Dec-Dcm_Connection_Form_Auto') : linkSelected.originalCharsetName, text: linkSelected.originalCharsetName === '' ? BI.i18nText('Dec-Dcm_Connection_Form_Auto') : linkSelected.originalCharsetName,
items: BI.Constants.getConstant(charset), items: [
{
text: BI.i18nText('Dec-Dcm_Connection_Form_Auto'),
value: '',
},
...BI.Constants.getConstant(charset),
],
listeners: [{ listeners: [{
eventName: BI.TextValueCombo.EVENT_CHANGE, eventName: BI.TextValueCombo.EVENT_CHANGE,
action() { action() {
@ -129,11 +135,11 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_UserName'), text: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
allowBlank:true, allowBlank: true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300, width: 300,
value: linkSelected.user, value: linkSelected.user,
listeners: [{ listeners: [{
@ -150,12 +156,12 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Password'), text: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
inputType:'password', inputType: 'password',
allowBlank:true, allowBlank: true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300, width: 300,
value: linkSelected.password, value: linkSelected.password,
listeners: [{ listeners: [{
@ -177,13 +183,13 @@ const Widget: WidgetType = {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'), text: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'),
height: 100, height: 100,
form:{ form: {
type: TextAreaEditor, type: TextAreaEditor,
cls: 'bi-border', cls: 'bi-border',
allowBlank:true, allowBlank: true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300, width: 300,
height:100, height: 100,
value: linkSelected.validationQuery, value: linkSelected.validationQuery,
listeners: [{ listeners: [{
eventName: BI.Editor.EVENT_CHANGE, eventName: BI.Editor.EVENT_CHANGE,
@ -199,7 +205,7 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'), text: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'),
form:{ form: {
type: MultiSelectItem, type: MultiSelectItem,
text: BI.i18nText('Dec-Dcm_Yes'), text: BI.i18nText('Dec-Dcm_Yes'),
selected: linkSelected.testOnBorrow, selected: linkSelected.testOnBorrow,
@ -218,21 +224,15 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Connection_Max_Number'), text: BI.i18nText('Dec-Dcm_Connection_Form_Connection_Max_Number'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
allowBlank:true, allowBlank: true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 60, width: 60,
value: linkSelected.maxActive, value: linkSelected.maxActive,
errorText: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input-Number'), errorText: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input-Number'),
validationChecker (v: string) { validationChecker: connectNameChecker,
if (/^\+?[1-9][0-9]*$/.test(v)) {
return true;
}
return false;
},
listeners: [{ listeners: [{
eventName: BI.Editor.EVENT_CHANGE, eventName: BI.Editor.EVENT_CHANGE,
action() { action() {

4
src/app/link_set/right/right_edit/right.edit.constant.ts

@ -1,10 +1,6 @@
export const ConstantName = 'bi.constant.database.conf.charset.list'; export const ConstantName = 'bi.constant.database.conf.charset.list';
export const Constant = BI.constant(ConstantName, [ export const Constant = BI.constant(ConstantName, [
{
text: '自动',
value: '',
},
{ {
text: 'GBK', text: 'GBK',
value: 'GBK', value: 'GBK',

58
src/app/link_set/right/right_edit/right.edit.mysql.component.ts

@ -4,7 +4,7 @@ import charset from './right.edit.constant';
import Model from '../../link-set.model'; import Model from '../../link-set.model';
import FormItem from '@shared/components/form.item.component'; import FormItem from '@shared/components/form.item.component';
import Title from '@shared/components/title.component'; import Title from '@shared/components/title.component';
import {getDrivers} from './right.edit.service'; import {getDrivers, connectNameChecker} from './right.edit.service';
const className = 'fr.component.right.edit.mysql'; const className = 'fr.component.right.edit.mysql';
const Widget: WidgetType = { const Widget: WidgetType = {
_store() { _store() {
@ -22,7 +22,7 @@ const Widget: WidgetType = {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName'), text: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName'),
hint: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName-Change-Confirm'), hint: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName-Change-Confirm'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
width: 300, width: 300,
@ -41,7 +41,7 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Driver'), text: BI.i18nText('Dec-Dcm_Connection_Form_Driver'),
form:{ form: {
type: TextValueCombo, type: TextValueCombo,
cls: 'bi-border', cls: 'bi-border',
width: 300, width: 300,
@ -61,10 +61,10 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_URL'), text: BI.i18nText('Dec-Dcm_Connection_Form_URL'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300, width: 300,
value: linkSelected.url, value: linkSelected.url,
listeners: [{ listeners: [{
@ -81,12 +81,18 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'), text: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'),
form:{ form: {
type: TextValueCombo, type: TextValueCombo,
cls: 'bi-border', cls: 'bi-border',
width: 300, width: 300,
text: linkSelected.originalCharsetName === '' ? BI.i18nText('Dec-Dcm_Connection_Form_Auto') : linkSelected.originalCharsetName, text: linkSelected.originalCharsetName === '' ? BI.i18nText('Dec-Dcm_Connection_Form_Auto') : linkSelected.originalCharsetName,
items: BI.Constants.getConstant(charset), items: [
{
text: BI.i18nText('Dec-Dcm_Connection_Form_Auto'),
value: '',
},
...BI.Constants.getConstant(charset),
],
listeners: [{ listeners: [{
eventName: BI.TextValueCombo.EVENT_CHANGE, eventName: BI.TextValueCombo.EVENT_CHANGE,
action() { action() {
@ -101,11 +107,11 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_UserName'), text: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
allowBlank:true, allowBlank: true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300, width: 300,
value: linkSelected.user, value: linkSelected.user,
listeners: [{ listeners: [{
@ -122,12 +128,12 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Password'), text: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
inputType:'password', inputType: 'password',
allowBlank:true, allowBlank: true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300, width: 300,
value: linkSelected.password, value: linkSelected.password,
listeners: [{ listeners: [{
@ -149,13 +155,13 @@ const Widget: WidgetType = {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'), text: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'),
height: 100, height: 100,
form:{ form: {
type: TextAreaEditor, type: TextAreaEditor,
cls: 'bi-border', cls: 'bi-border',
allowBlank:true, allowBlank: true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300, width: 300,
height:100, height: 100,
value: linkSelected.validationQuery, value: linkSelected.validationQuery,
listeners: [{ listeners: [{
eventName: BI.Editor.EVENT_CHANGE, eventName: BI.Editor.EVENT_CHANGE,
@ -171,7 +177,7 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'), text: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'),
form:{ form: {
type: MultiSelectItem, type: MultiSelectItem,
text: BI.i18nText('Dec-Dcm_Yes'), text: BI.i18nText('Dec-Dcm_Yes'),
selected: linkSelected.testOnBorrow, selected: linkSelected.testOnBorrow,
@ -190,21 +196,15 @@ const Widget: WidgetType = {
{ {
type: FormItem, type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Connection_Max_Number'), text: BI.i18nText('Dec-Dcm_Connection_Form_Connection_Max_Number'),
form:{ form: {
type: Editor, type: Editor,
cls: 'bi-border', cls: 'bi-border',
allowBlank:true, allowBlank: true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 60, width: 60,
value: linkSelected.maxActive, value: linkSelected.maxActive,
errorText: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input-Number'), errorText: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input-Number'),
validationChecker (v: string) { validationChecker: connectNameChecker,
if (/^\+?[1-9][0-9]*$/.test(v)) {
return true;
}
return false;
},
listeners: [{ listeners: [{
eventName: BI.Editor.EVENT_CHANGE, eventName: BI.Editor.EVENT_CHANGE,
action() { action() {

4
src/app/link_set/right/right_edit/right.edit.service.ts

@ -18,3 +18,7 @@ export function getDrivers(linkSelected: LinkType): {text: string; value: string
return drivers; return drivers;
} }
export function connectNameChecker(name: string): boolean {
return /^\+?[1-9][0-9]*$/.test(name);
}

16
src/demo/plugin.redis.edit.ts

@ -1,7 +1,7 @@
import './style.scss'; import './style.scss';
const RedisConstantName = 'dec.constant.database.conf.connect.form.redis.value'; const RedisConstantName = 'dec.constant.database.conf.connect.form.redis.value';
const form = { const form = {
url:'192.168.1.22', url: '192.168.1.22',
port: 6379, port: 6379,
password: '123456', password: '123456',
}; };
@ -11,8 +11,8 @@ const Widget = BI.inherit(BI.Widget, {
render() { render() {
return { return {
type: 'bi.vertical', type: 'bi.vertical',
cls:'bi-plugin-redis', cls: 'bi-plugin-redis',
bgap:10, bgap: 10,
items: [ items: [
{ {
type: 'bi.left', type: 'bi.left',
@ -29,7 +29,7 @@ const Widget = BI.inherit(BI.Widget, {
type: 'bi.editor', type: 'bi.editor',
cls: 'bi-border', cls: 'bi-border',
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Addr'), watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Addr'),
value:form.url, value: form.url,
allowBlank: true, allowBlank: true,
width: 300, width: 300,
height: 24, height: 24,
@ -56,11 +56,7 @@ const Widget = BI.inherit(BI.Widget, {
value: form.port, value: form.port,
errorText: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input-Number'), errorText: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input-Number'),
validationChecker (v: string) { validationChecker (v: string) {
if (/^\+?[1-9][0-9]*$/.test(v)) { return /^\+?[1-9][0-9]*$/.test(v);
return true;
}
return false;
}, },
}], }],
}, },
@ -78,7 +74,7 @@ const Widget = BI.inherit(BI.Widget, {
{ {
type: 'bi.editor', type: 'bi.editor',
cls: 'bi-border', cls: 'bi-border',
inputType:'password', inputType: 'password',
value: form.password, value: form.password,
allowBlank: true, allowBlank: true,
width: 300, width: 300,

Loading…
Cancel
Save