Skip to content

Commit

Permalink
#64 add feature: add copy_to and multi_fields feature when create ind…
Browse files Browse the repository at this point in the history
…ex version [vip:platform/pallas#879]
  • Loading branch information
NathanChan committed Jun 11, 2019
1 parent f96b00d commit 3c7a223
Show file tree
Hide file tree
Showing 15 changed files with 812 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<el-table :data="childInfo" border style="width: 100%">
<el-table-column label="字段名">
<template scope="scope">
<el-input v-model="scope.row.fieldName" :disabled="isEditable"></el-input>
<el-input class="nested-input" v-model="scope.row.fieldName" :disabled="isEditable"></el-input>
<el-tag type="success" v-if="checkArrayNotEmpty(scope.row.copyTo)">copy to: {{scope.row.copyTo}}</el-tag>
<el-button type="warning" @click="viewSchemaMultiFields(scope.row)" v-if="scope.row.multiField.length !== 0" ><i class="fa"></i>多域字段</el-button>
</template>
</el-table-column>
<el-table-column label="ES类型">
Expand Down Expand Up @@ -39,6 +41,19 @@
<el-table-column v-if="!isEditable" label="操作" min-width="60">
<template scope="scope">
<el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
<el-button type="warning" @click="viewSchemaCopyTo(scope.row)">copyTo</el-button>
</template>
<template scope="scope">
<el-dropdown trigger="click">
<span class="el-dropdown-link">
操作<i class="el-icon-caret-bottom el-icon--right"></i>
</span>
<el-dropdown-menu class="dropdown-operation" slot="dropdown">
<el-dropdown-item ><a @click="handleDelete(scope.row)"><span><i class="fa fa-play-circle"></i>删除</span></a></el-dropdown-item>
<el-dropdown-item ><a @click="viewSchemaMultiFields(scope.row)"><span><i class="fa fa-play-circle"></i>添加多域字段</span></a></el-dropdown-item>
<el-dropdown-item ><a @click="viewSchemaCopyTo(scope.row)"><span><i class="fa fa-play-circle"></i>添加copyTo</span></a></el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
Expand All @@ -48,15 +63,28 @@
<el-button v-if="!isEditable" type="confirm" @click="confirmBtn()">确定</el-button>
</div>
</el-dialog>
<schema-multi-field-dialog :is-schema-multi-fields-visible="isSchemaMultiFieldsVisible" :schema-multi-fields-info="schemaExtInfo" :version-operation="versionOperation" :schema-parent-field-name="schemaParentFieldName" @close-schema-dialog="closeSchemaMultiFieldsDialog" @add-schema-multi-field="addSchemaMultiFields"></schema-multi-field-dialog>
<schema-copy-to-dialog :is-copy-to-fields-visible="isCopyToFieldsVisible" :schema-copy-to-info="schemaExtInfo" :copy-to-list="validCopyToFields" :schema-parent-field-name="schemaParentFieldName" @close-schema-dialog="closeSchemaCopyToDialog" @add-schema-copy-to="addSchemaCopyTo" ></schema-copy-to-dialog>
</div>
</template>

<script>
import SchemaCopyToDialog from './schema_copy_to_dialog';
import SchemaMultiFieldDialog from './schema_multi_field_dialog';
export default {
props: ['isSchemaChildVisible', 'schemaChildInfo', 'versionOperation', 'schemaParentFieldName'],
components: {
'schema-copy-to-dialog': SchemaCopyToDialog,
'schema-multi-field-dialog': SchemaMultiFieldDialog,
},
props: ['isSchemaChildVisible', 'schemaChildInfo', 'versionOperation', 'schemaParentFieldName', 'versionInfo'],
data() {
return {
childInfo: [],
schemaExtInfo: {},
validCopyToFields: [],
isCopyToFieldsVisible: false,
isSchemaMultiFieldsVisible: false,
initDynamic: false,
fieldTypes: [{
value: 'text',
Expand Down Expand Up @@ -103,6 +131,8 @@ export default {
fieldName: '',
fieldType: '',
multi: '',
copyTo: [],
multiField: [],
search: false,
docValue: false,
};
Expand Down Expand Up @@ -144,8 +174,77 @@ export default {
},
openDialog() {
this.childInfo = JSON.parse(JSON.stringify(this.schemaChildInfo.children));
Object.keys(this.childInfo).forEach((element, index) => {
this.childInfo[index].multiField =
this.childInfo[index].multiField || [];
});
this.initDynamic = this.schemaChildInfo.dynamic;
},
checkArrayNotEmpty(arr) {
return arr && arr.length > 0;
},
viewSchemaMultiFields(row) {
this.isSchemaMultiFieldsVisible = true;
this.schemaExtInfo = row;
},
viewSchemaCopyTo(row) {
this.schemaExtInfo = row;
this.validCopyToFields = [];
this.versionInfo.schema.forEach((el) => {
if (el.dbFieldType === 'N/A') {
if (el.fieldType === 'nested') {
// skip current nested doc
if (el.fieldName === this.schemaChildInfo.fieldName) return;
this.getNestedFieldName(el, '', this.validCopyToFields);
return;
}
this.validCopyToFields.push(el.fieldName);
}
});
// get the tmp nested field
this.childInfo.forEach((el) => {
if (el.fieldType === 'nested') {
this.getNestedFieldName(el, this.schemaChildInfo.fieldName, this.validCopyToFields);
return;
}
this.validCopyToFields.push(`${this.schemaChildInfo.fieldName}.${el.fieldName}`);
});
this.copyToListFilter(this.validCopyToFields, `${this.schemaChildInfo.fieldName}.${row.fieldName}`);
this.isCopyToFieldsVisible = true;
},
getNestedFieldName(field, parentFieldName, fieldArr) {
if (field.fieldType !== 'nested') {
fieldArr.push(`${parentFieldName}${field.fieldName}`);
return;
}
field.children.forEach((child) => {
if (child.fieldType === 'nested') {
this.getNestedFieldName(child, `${parentFieldName}${field.fieldName}.`, fieldArr);
} else {
fieldArr.push(`${parentFieldName}${field.fieldName}.${child.fieldName}`);
}
});
},
copyToListFilter(fieldArr, fieldName) {
const index = fieldArr.indexOf(fieldName);
if (index >= 0) {
fieldArr.splice(index, 1);
}
},
closeSchemaCopyToDialog() {
this.isCopyToFieldsVisible = false;
},
closeSchemaMultiFieldsDialog() {
this.isSchemaMultiFieldsVisible = false;
},
addSchemaCopyTo(array) {
console.log(JSON.stringify(array));
this.isCopyToFieldsVisible = false;
},
addSchemaMultiFields(array) {
console.log(JSON.stringify(array));
this.isSchemaMultiFieldsVisible = false;
},
},
computed: {
isEditable() {
Expand All @@ -162,7 +261,10 @@ export default {

<style type="text/css">
.schema-content {
margin-bottom: 10px;
margin-bottom: 10px;
}
.nested-input {
width: 50%;
}
.schema-info-dialog .el-dialog__footer {
padding: 10px 20px 15px;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<template>
<el-dialog title="选择复制的域" v-model="isCopyToFieldsVisible" @open="initSelectList" :before-close="closeDialog">
<div class="copy-to-field">
<el-transfer
filterable
v-model="copyToFieldSelected"
:data="copyToFieldList"
:titles="['可选的域', '已选的域']"></el-transfer>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="closeDialog()">取 消</el-button>
<el-button type="confirm" @click="sumbitCopyToField">确定</el-button>
</div>
</el-dialog>
</template>

<script>
export default {
props: ['isCopyToFieldsVisible', 'schemaCopyToInfo', 'copyToList', 'schemaParentFieldName'],
data() {
return {
copyToFieldList: [],
copyToFieldSelected: [],
};
},
methods: {
closeDialog() {
this.$emit('close-schema-dialog');
},
sumbitCopyToField() {
if (this.copyToFieldSelected.length > 0) {
this.schemaCopyToInfo.copyTo = [];
this.copyToFieldSelected.forEach((element) => {
this.schemaCopyToInfo.copyTo.push(element);
});
this.$emit('add-schema-copy-to', this.schemaCopyToInfo.copyTo);
} else {
this.$message.errorMessage('请选择要复制的域!');
}
},
initSelectList() {
this.copyToFieldSelected = [];
const arr = JSON.parse(JSON.stringify(this.copyToList));
this.copyToFieldList = arr.map((obj) => {
const rObj = {};
rObj.key = obj;
rObj.label = obj;
return rObj;
});
},
},
};
</script>

<style>
.copy-to-field {
margin: 10px;
}
.copy-to-field .el-transfer-panel {
width: 250px;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export default {
rObj.search = obj.search;
rObj.docValue = obj.docValue;
rObj.children = obj.children || [];
rObj.multiField = obj.multiField || [];
rObj.copyTo = obj.copyTo || [];
return rObj;
});
this.$emit('schema-import-success', arr);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<template>
<div class="schema-info-dialog">
<el-dialog :title="childTitle" size="large" v-model="isSchemaMultiFieldsVisible" @open="openDialog" :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false">
<div class="schema-content">
<el-button type="primary" icon="plus" @click="handleAdd" v-if="!isEditable">新增字段</el-button>

</div>
<el-table :data="multiFieldInfo" border style="width: 100%">
<el-table-column label="字段名">
<template scope="scope">
<el-input v-model="scope.row.fieldName" :disabled="isEditable"></el-input>
</template>
</el-table-column>
<el-table-column label="ES类型">
<template scope="scope">
<select v-model="scope.row.fieldType" size="small" :disabled="isEditable">
<option v-for="item in fieldTypes" :value="item.value" :key="item.value">{{item.label}}</option>
</select>
</template>
</el-table-column>
<el-table-column label="多值/单值">
<template scope="scope">
<select v-model="scope.row.multi" size="small" :disabled="isEditable">
<option label="单值" :value="false">单值</option>
<option label="多值" :value="true">多值</option>
</select>
</template>
</el-table-column>
<el-table-column label="查询关键字">
<template scope="scope">
<el-checkbox v-model="scope.row.search" :disabled="isEditable">是否查询</el-checkbox>
</template>
</el-table-column>
<el-table-column label="排序或聚合">
<template scope="scope">
<el-checkbox v-model="scope.row.docValue" :disabled="isEditable">用于排序或聚合</el-checkbox>
</template>
</el-table-column>
<el-table-column v-if="!isEditable" label="操作" min-width="60">
<template scope="scope">
<el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div slot="footer" class="dialog-footer">

<el-button @click="cancelBtn()">取消</el-button>
<el-button v-if="!isEditable" type="confirm" @click="confirmBtn()">确定</el-button>
</div>
</el-dialog>
</div>
</template>

<script>
export default {
props: ['isSchemaMultiFieldsVisible', 'schemaMultiFieldsInfo', 'versionOperation', 'schemaParentFieldName'],
data() {
return {
multiFieldInfo: [],
fieldTypes: [{
value: 'text',
label: 'text',
}, {
value: 'keyword',
label: 'keyword',
}, {
value: 'date',
label: 'date',
}, {
value: 'boolean',
label: 'boolean',
}, {
value: 'object',
label: 'object',
}, {
value: 'nested',
label: 'nested',
}, {
value: 'long',
label: 'long',
}, {
value: 'integer',
label: 'integer',
}, {
value: 'short',
label: 'short',
}, {
value: 'byte',
label: 'byte',
}, {
value: 'double',
label: 'double',
}, {
value: 'float',
label: 'float',
}],
};
},
methods: {
handleAdd() {
const addMultiFieldInfo = {
fieldName: '',
fieldType: '',
multi: '',
search: false,
docValue: false,
};
this.multiFieldInfo.push(addMultiFieldInfo);
},
cancelBtn() {
this.$emit('close-schema-dialog');
},
handleDelete(row) {
this.$message.confirmMessage(`确定删除字段${row.fieldName}吗?`, () => {
this.$array.removeByValue(this.multiFieldInfo, row);
});
},
confirmBtn() {
if (this.checkChildInput(this.multiFieldInfo)) {
// eslint-disable-next-line max-len
this.schemaMultiFieldsInfo.multiField.splice(0, this.schemaMultiFieldsInfo.multiField.length);
this.multiFieldInfo.forEach((element) => {
this.schemaMultiFieldsInfo.multiField.push(element);
});
this.$emit('add-schema-multi-field', this.schemaMultiFieldsInfo.multiField);
}
},
checkChildInput(arr) {
let flag = true;
Object.keys(arr).forEach((element, index) => {
if (arr[index].fieldName === '') {
this.$message.errorMessage('字段名不能为空');
flag = false;
} else {
flag = true;
}
});
return flag;
},
openDialog() {
this.multiFieldInfo = JSON.parse(JSON.stringify(this.schemaMultiFieldsInfo.multiField));
},
},
computed: {
isEditable() {
return this.versionOperation === 'view';
},
childTitle() {
const title = `${this.schemaMultiFieldsInfo.fieldName}多域字段`;
return title;
},
},
};
</script>
<style type="text/css">
.schema-content {
margin-bottom: 10px;
}
.schema-info-dialog .el-dialog__footer {
padding: 10px 20px 15px;
}
</style>
Loading

0 comments on commit 3c7a223

Please sign in to comment.