Skip to content

Commit a5be12d

Browse files
committed
[CE-473] Add default parameters for example code
Example chain code have default parameters in user dashboard. Change-Id: Id4eac88339d3d2108727845b508a87e35c3ffea0 Signed-off-by: Haitao Yue <hightall@me.com>
1 parent d956c29 commit a5be12d

File tree

8 files changed

+34
-9
lines changed

8 files changed

+34
-9
lines changed

user-dashboard/src/app/assets/src/components/PageHeader/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919

2020
.tabs {
21-
margin: 0 0 -17px -8px;
21+
margin: 0 0 -1px -8px;
2222

2323
:global {
2424
.ant-tabs-bar {

user-dashboard/src/app/assets/src/routes/SmartContract/Info/deploy.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ export default class Deploy extends Component {
147147

148148
render() {
149149
const { stepDirection, current, version, versionId, chainName, chainId, installing, instantiating } = this.state;
150-
const { chains, codes } = this.props;
150+
const { chains, codes, currentSmartContract } = this.props;
151151
const { getFieldDecorator } = this.props.form;
152+
const defaultValues = currentSmartContract.default || {};
153+
const defaultParameters = defaultValues.parameters || {};
154+
const defaultInstantiateParameters = defaultParameters.instantiate ? defaultParameters.instantiate.join(",") : "";
152155
const versionOptions = codes.map(code => <Option value={code._id}>{code.version}</Option>);
153156
const chainOptions = chains.map(chain => <Option value={chain._id}>{chain.name}</Option>);
154157
const versionDesc = (
@@ -221,7 +224,7 @@ export default class Deploy extends Component {
221224
extra="Must use ',' separate arguments."
222225
>
223226
{getFieldDecorator('args', {
224-
initialValue: '',
227+
initialValue: defaultInstantiateParameters,
225228
rules: [
226229
{
227230
required: true,

user-dashboard/src/app/assets/src/routes/SmartContract/InvokeQuery/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,14 @@ export default class AdvancedProfile extends Component {
148148
operation: 'invoke',
149149
onSubmit: this.operateAPI,
150150
submitting: operating,
151+
currentDeploy,
151152
};
152153
const queryProps = {
153154
operation: 'query',
154155
onSubmit: this.operateAPI,
155156
submitting: operating,
156157
result: queryResult,
158+
currentDeploy,
157159
};
158160

159161
const contentList = {

user-dashboard/src/app/assets/src/routes/SmartContract/InvokeQuery/operate.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ export default class OperateDeploy extends Component {
3737
});
3838
};
3939
render() {
40-
const { form: { getFieldDecorator }, operation, submitting, result } = this.props;
40+
const { form: { getFieldDecorator }, operation, submitting, result, currentDeploy } = this.props;
41+
const smartContract = currentDeploy.smartContract || {};
42+
const defaultValues = smartContract.default || {};
43+
const parameters = defaultValues.parameters || {};
44+
const functions = defaultValues.functions || {};
45+
const functionName = operation === "query" ? functions.query || "" : functions.invoke || "";
46+
const parameter = operation === "query" ? parameters.query || [] : parameters.invoke || [];
47+
const parameterStr = parameter.join(",");
4148
const formItemLayout = {
4249
labelCol: {
4350
xs: { span: 24 },
@@ -74,7 +81,7 @@ export default class OperateDeploy extends Component {
7481
label="Function Name"
7582
>
7683
{getFieldDecorator('functionName', {
77-
initialValue: '',
84+
initialValue: functionName,
7885
rules: [
7986
{
8087
required: true,
@@ -89,7 +96,7 @@ export default class OperateDeploy extends Component {
8996
extra="Must use ',' separate arguments."
9097
>
9198
{getFieldDecorator('args', {
92-
initialValue: '',
99+
initialValue: parameterStr,
93100
rules: [
94101
{
95102
required: true,

user-dashboard/src/app/model/smart-contract.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = app => {
1414
description: { type: String },
1515
path: { type: String },
1616
createTime: { type: Date, default: Date.now },
17+
default: { type: Schema.Types.Mixed },
1718
});
1819

1920
SmartContractSchema.post('remove', function(doc) {

user-dashboard/src/app/service/deploy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DeployService extends Service {
2929
}
3030
async query(id) {
3131
const { ctx } = this;
32-
const deploy = await ctx.model.SmartContractDeploy.findOne({ _id: id }, '_id name status deployTime').populate('smartContractCode chain smartContract', '_id version name chainId type size');
32+
const deploy = await ctx.model.SmartContractDeploy.findOne({ _id: id }, '_id name status deployTime').populate('smartContractCode chain smartContract', '_id version name chainId type size default');
3333
if (!deploy) {
3434
return {
3535
success: false,

user-dashboard/src/app/service/smart_contract.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class SmartContractService extends Service {
3636
name: smartContract.name,
3737
description: smartContract.description,
3838
path: smartContractPath,
39+
default: smartContract.default,
3940
user: userId,
4041
});
4142
await ctx.model.SmartContractCode.create({
@@ -145,7 +146,7 @@ class SmartContractService extends Service {
145146
}
146147
async querySmartContract(id) {
147148
const { ctx } = this;
148-
const smartContract = await ctx.model.SmartContract.findOne({ _id: id }, '_id description name createTime');
149+
const smartContract = await ctx.model.SmartContract.findOne({ _id: id }, '_id description name createTime default');
149150
if (!smartContract) {
150151
return {
151152
success: false,

user-dashboard/src/config/config.default.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,18 @@ module.exports = appInfo => {
4444
name: 'chaincode_example02',
4545
path: '/var/www/resource/smart_contract/fabric/chaincode_example02',
4646
version: 'v1.0',
47-
description: 'This is a demo smart contract example02.',
47+
description: 'This is a demo smart contract example02 for fabric v1.0, can not install&instantiate on fabric v1.2',
48+
default: {
49+
parameters: {
50+
instantiate: ['a', '100', 'b', '100'],
51+
invoke: ['a', 'b', '1'],
52+
query: ['a'],
53+
},
54+
functions: {
55+
invoke: 'invoke',
56+
query: 'query',
57+
},
58+
},
4859
},
4960
],
5061
},

0 commit comments

Comments
 (0)