Skip to content

Commit

Permalink
[CE-473] Add default parameters for example code
Browse files Browse the repository at this point in the history
Example chain code have default parameters in user dashboard.

Change-Id: Id4eac88339d3d2108727845b508a87e35c3ffea0
Signed-off-by: Haitao Yue <hightall@me.com>
  • Loading branch information
hightall committed Sep 11, 2018
1 parent d956c29 commit a5be12d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}

.tabs {
margin: 0 0 -17px -8px;
margin: 0 0 -1px -8px;

:global {
.ant-tabs-bar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ export default class Deploy extends Component {

render() {
const { stepDirection, current, version, versionId, chainName, chainId, installing, instantiating } = this.state;
const { chains, codes } = this.props;
const { chains, codes, currentSmartContract } = this.props;
const { getFieldDecorator } = this.props.form;
const defaultValues = currentSmartContract.default || {};
const defaultParameters = defaultValues.parameters || {};
const defaultInstantiateParameters = defaultParameters.instantiate ? defaultParameters.instantiate.join(",") : "";
const versionOptions = codes.map(code => <Option value={code._id}>{code.version}</Option>);
const chainOptions = chains.map(chain => <Option value={chain._id}>{chain.name}</Option>);
const versionDesc = (
Expand Down Expand Up @@ -221,7 +224,7 @@ export default class Deploy extends Component {
extra="Must use ',' separate arguments."
>
{getFieldDecorator('args', {
initialValue: '',
initialValue: defaultInstantiateParameters,
rules: [
{
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ export default class AdvancedProfile extends Component {
operation: 'invoke',
onSubmit: this.operateAPI,
submitting: operating,
currentDeploy,
};
const queryProps = {
operation: 'query',
onSubmit: this.operateAPI,
submitting: operating,
result: queryResult,
currentDeploy,
};

const contentList = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ export default class OperateDeploy extends Component {
});
};
render() {
const { form: { getFieldDecorator }, operation, submitting, result } = this.props;
const { form: { getFieldDecorator }, operation, submitting, result, currentDeploy } = this.props;
const smartContract = currentDeploy.smartContract || {};
const defaultValues = smartContract.default || {};
const parameters = defaultValues.parameters || {};
const functions = defaultValues.functions || {};
const functionName = operation === "query" ? functions.query || "" : functions.invoke || "";
const parameter = operation === "query" ? parameters.query || [] : parameters.invoke || [];
const parameterStr = parameter.join(",");
const formItemLayout = {
labelCol: {
xs: { span: 24 },
Expand Down Expand Up @@ -74,7 +81,7 @@ export default class OperateDeploy extends Component {
label="Function Name"
>
{getFieldDecorator('functionName', {
initialValue: '',
initialValue: functionName,
rules: [
{
required: true,
Expand All @@ -89,7 +96,7 @@ export default class OperateDeploy extends Component {
extra="Must use ',' separate arguments."
>
{getFieldDecorator('args', {
initialValue: '',
initialValue: parameterStr,
rules: [
{
required: true,
Expand Down
1 change: 1 addition & 0 deletions user-dashboard/src/app/model/smart-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = app => {
description: { type: String },
path: { type: String },
createTime: { type: Date, default: Date.now },
default: { type: Schema.Types.Mixed },
});

SmartContractSchema.post('remove', function(doc) {
Expand Down
2 changes: 1 addition & 1 deletion user-dashboard/src/app/service/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DeployService extends Service {
}
async query(id) {
const { ctx } = this;
const deploy = await ctx.model.SmartContractDeploy.findOne({ _id: id }, '_id name status deployTime').populate('smartContractCode chain smartContract', '_id version name chainId type size');
const deploy = await ctx.model.SmartContractDeploy.findOne({ _id: id }, '_id name status deployTime').populate('smartContractCode chain smartContract', '_id version name chainId type size default');
if (!deploy) {
return {
success: false,
Expand Down
3 changes: 2 additions & 1 deletion user-dashboard/src/app/service/smart_contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SmartContractService extends Service {
name: smartContract.name,
description: smartContract.description,
path: smartContractPath,
default: smartContract.default,
user: userId,
});
await ctx.model.SmartContractCode.create({
Expand Down Expand Up @@ -145,7 +146,7 @@ class SmartContractService extends Service {
}
async querySmartContract(id) {
const { ctx } = this;
const smartContract = await ctx.model.SmartContract.findOne({ _id: id }, '_id description name createTime');
const smartContract = await ctx.model.SmartContract.findOne({ _id: id }, '_id description name createTime default');
if (!smartContract) {
return {
success: false,
Expand Down
13 changes: 12 additions & 1 deletion user-dashboard/src/config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,18 @@ module.exports = appInfo => {
name: 'chaincode_example02',
path: '/var/www/resource/smart_contract/fabric/chaincode_example02',
version: 'v1.0',
description: 'This is a demo smart contract example02.',
description: 'This is a demo smart contract example02 for fabric v1.0, can not install&instantiate on fabric v1.2',
default: {
parameters: {
instantiate: ['a', '100', 'b', '100'],
invoke: ['a', 'b', '1'],
query: ['a'],
},
functions: {
invoke: 'invoke',
query: 'query',
},
},
},
],
},
Expand Down

0 comments on commit a5be12d

Please sign in to comment.