Просмотр исходного кода

Merge branch 'master' of http://gogs.ioobot.com:6680/xy/online

wly 7 лет назад
Родитель
Сommit
4f8e6dfe1d

+ 11 - 10
src/app/App.jsx

@@ -363,10 +363,10 @@ class GraphqlSidebar extends Component {
                     ({loading, error, data}) => {
                         if (loading) return <Spin style={{marginLeft: 3}}/>;
                         if (error) return 'error!';
-                        // console.log('CASE_SCHEMA_AND_PROJECT data', data);
-                        localStorage.setItem('ecommerce', data.caseSchema.find(obj => obj.schemaName === 'ecommerce').schemaData);
-                        localStorage.setItem('subscribe', data.caseSchema.find(obj => obj.schemaName === 'subscribe').schemaData);
-                        localStorage.setItem('bills', data.caseSchema.find(obj => obj.schemaName === 'bills').schemaData);
+                        console.log('CASE_SCHEMA_AND_PROJECT data', data);
+                        localStorage.setItem('ecommerce', data.caseProject.find(project => project.schema_id.schemaName === 'ecommerce').schema_id.schemaData);
+                        localStorage.setItem('subscribe', data.caseProject.find(project => project.schema_id.schemaName === 'subscribe').schema_id.schemaData);
+                        localStorage.setItem('bills', data.caseProject.find(project => project.schema_id.schemaName === 'bills').schema_id.schemaData);
                         return (
                             <Menu
                                 theme="dark"
@@ -390,15 +390,16 @@ class GraphqlSidebar extends Component {
                                     key="trial-case"
                                     title={<span><Icon type="appstore" theme="twoTone"/><span><FormattedMessage id="Case Show"/></span></span>}>
                                     {
-                                        data.caseSchema.map((schema) =>
-                                            <Menu.Item key={schema.schemaName}>
+                                        data.caseProject.map((project) =>
+                                            <Menu.Item key={project.schema_id.schemaName}>
                                                 <Link to={{
-                                                    pathname: `/graphql-service/trial-case/${schema.schemaName}`,
+                                                    pathname: `/graphql-service/trial-case/${project.schema_id.schemaName}`,
                                                     state: {
-                                                        schemaName: schema.schemaName,
-                                                        schemaID: schema.id
+                                                        schemaName: project.schema_id.schemaName,
+                                                        schemaID: project.schema_id.id,
+                                                        projectID: project.id
                                                     }
-                                                }}>{schema.schemaName}</Link>
+                                                }}>{project.schema_id.schemaName}</Link>
                                             </Menu.Item>)
                                     }
                                 </SubMenu>

+ 4 - 4
src/app/common/deploy/tencent/TencentConfig.js

@@ -75,7 +75,8 @@ class TencentConfig extends Component {
     };
 
     render() {
-        let {userID, projectID, trialcase} = this.props;
+        let projectID = this.props.projectID ? this.props.projectID : 'ecommerce_projectID';
+
         return (
             <Query query={gql(GET_PROJECT)} variables={{id: projectID}}>
                 {
@@ -97,7 +98,6 @@ class TencentConfig extends Component {
                             deploy = data.project_by_id.deploy_id;
                             cloudID = data.project_by_id.cloud_id.id;
                         }
-                        console.log('object',data);
                         let defaultName = data.project_by_id.projectName;
                         return (
                             <div>
@@ -181,9 +181,9 @@ class TencentConfig extends Component {
                                             </FormattedMessage>
                                         </Col>
                                         <Col offset={2} span={6}>
-                                            <Button type='primary' disabled={this.state.couldDeploy? '': 'disabled'} onClick={()=>this.deployFC()}><FormattedMessage id="deploy"/>!</Button>
+                                            <Button type='primary' disabled={data.project_by_id.schema_id.schemaState === 'ok'? '': 'disabled'} onClick={()=>this.deployFC()}><FormattedMessage id="deploy"/>!</Button>
                                             {
-                                                this.state.couldDeploy?
+                                                data.project_by_id.schema_id.schemaState === 'ok'?
                                                     ''
                                                     :
                                                     <div>

+ 37 - 0
src/app/common/manage/AliyunResult.js

@@ -0,0 +1,37 @@
+import React, {Component} from 'react';
+import {Switch, Input, Icon} from 'antd';
+
+class AliyunResult extends Component {
+    constructor(props) {
+        super(props);
+        this.state = {
+            url: '1111',
+            checked: true
+        }
+    }
+
+    render() {
+        return (
+            <div>
+                <div style={{width: 300}}>
+                    <span>URL: </span>
+                    <Input
+                        placeholder="display your URL"
+                        prefix={<Icon type="copy"/>}
+                        value={this.state.url}
+                        onChange={() => {}}
+                        disabled={!this.state.checked}
+                    />
+                </div>
+                <div style={{marginTop: 30}}>
+                    <span>fc switch </span>
+                    <Switch defaultChecked onChange={(checked) => {
+                        this.setState({checked})
+                    }}/>
+                </div>
+            </div>
+        )
+    }
+}
+
+export default AliyunResult;

+ 37 - 0
src/app/common/manage/AmazonResult.js

@@ -0,0 +1,37 @@
+import React, {Component} from 'react';
+import {Switch, Input, Icon} from 'antd';
+
+class AmazonResult extends Component {
+    constructor(props) {
+        super(props);
+        this.state = {
+            url: '1111',
+            checked: true
+        }
+    }
+
+    render() {
+        return (
+            <div>
+                <div style={{width: 300}}>
+                    <span>URL: </span>
+                    <Input
+                        placeholder="display your URL"
+                        prefix={<Icon type="copy"/>}
+                        value={this.state.url}
+                        onChange={() => {}}
+                        disabled={!this.state.checked}
+                    />
+                </div>
+                <div style={{marginTop: 30}}>
+                    <span>fc switch </span>
+                    <Switch defaultChecked onChange={(checked) => {
+                        this.setState({checked})
+                    }}/>
+                </div>
+            </div>
+        )
+    }
+}
+
+export default AmazonResult;

+ 50 - 20
src/app/common/manage/Manage.jsx

@@ -1,34 +1,64 @@
 import React, {Component} from 'react';
-import {Switch, Input, Icon} from 'antd';
+import {FormattedMessage} from 'react-intl';
+import {Card} from 'antd';
+
+import TencentResult from './TencentResult';
+import AliyunResult from './AliyunResult';
+import AmazonResult from './AmazonResult';
+
+
+const tabListNoTitle = [{
+    key: 'tencent',
+    tab: <FormattedMessage id='Tencent'/>,
+}];
+
+// [{
+//     key: 'tencent',
+//     tab: <FormattedMessage id='Tencent'/>,
+// }, {
+//     key: 'aliyun',
+//     tab: <FormattedMessage id='Aliyun'/>,
+// }, {
+//     key: 'amazon',
+//     tab: <FormattedMessage id='AWS'/>,
+// }];
+
 
 class Manage extends Component {
     constructor(props) {
         super(props);
         this.state = {
-            url: '1111',
-            checked: true
-        }
+            cloud: 'tencent'
+        };
+    }
+
+    componentWillReceiveProps(next) {
+        this.setState({
+            projectID: next.projectID
+        })
     }
 
     render() {
+        const contentListNoTitle = {
+            tencent: <TencentResult userID={this.props.userID} projectID={this.props.projectID} trialcase={this.props.trialcase}/>,
+            aliyun: <AliyunResult/>,
+            amazon: <AmazonResult/>,
+        };
+
         return (
             <div>
-                <div style={{width: 300}}>
-                    <span>URL: </span>
-                    <Input
-                        placeholder="display your URL"
-                        prefix={<Icon type="copy"/>}
-                        value={this.state.url}
-                        onChange={() => {}}
-                        disabled={!this.state.checked}
-                    />
-                </div>
-                <div style={{marginTop: 30}}>
-                    <span>fc switch </span>
-                    <Switch defaultChecked onChange={(checked) => {
-                        this.setState({checked})
-                    }}/>
-                </div>
+                <Card
+                    style={{width: '100%'}}
+                    tabList={tabListNoTitle}
+                    activeTabKey={this.state.cloud}
+                    onTabChange={(cloud) => {
+                        this.setState({
+                            cloud
+                        })
+                    }}
+                >
+                    {contentListNoTitle[this.state.cloud]}
+                </Card>
             </div>
         )
     }

+ 38 - 0
src/app/common/manage/TencentResult.js

@@ -0,0 +1,38 @@
+import React, {Component} from 'react';
+import {Switch, Input, Icon} from 'antd';
+
+class TencentResult extends Component {
+    constructor(props) {
+        super(props);
+        this.state = {
+            url: '1111',
+            checked: true
+        }
+    }
+
+    render() {
+        return (
+            <div>
+                <div style={{width: 300}}>
+                    <span>Tencent</span>
+                    <span>URL: </span>
+                    <Input
+                        placeholder="display your URL"
+                        prefix={<Icon type="copy"/>}
+                        value={this.state.url}
+                        onChange={() => {}}
+                        disabled={!this.state.checked}
+                    />
+                </div>
+                <div style={{marginTop: 30}}>
+                    <span>fc switch </span>
+                    <Switch defaultChecked onChange={(checked) => {
+                        this.setState({checked})
+                    }}/>
+                </div>
+            </div>
+        )
+    }
+}
+
+export default TencentResult;

+ 4 - 5
src/app/graphqlService/TrialCase.jsx

@@ -50,10 +50,9 @@ class TrialCase extends Component {
     }
 
     render() {
-        let schemaID = this.props.history.location.state ? this.props.history.location.state.schemaID : "ecommerce_schemaID";
-        let schemaName = this.props.history.location.state ? this.props.history.location.state.schemaName : "ecommerce";
-        let projectID = this.props.history.location.state ? this.props.history.location.state.projectID : "";
-        let _this = this;
+        let schemaID = this.props.location.state ? this.props.location.state.schemaID : "ecommerce_schemaID";
+        let schemaName = this.props.location.state ? this.props.location.state.schemaName : "ecommerce";
+        let projectID = this.props.location.state ? this.props.location.state.projectID : "";
         return (
             <div>
                 <Menu
@@ -83,7 +82,7 @@ class TrialCase extends Component {
                                     case 'deploy':
                                         return <Deploy trialcase={true} userID={this.state.userID} projectID={projectID}/>;
                                     case 'manage':
-                                        return <Manage/>;
+                                        return <Manage trialcase={true} userID={this.state.userID} projectID={projectID}/>;
                                     case 'graphiql':
                                         return <Graphql/>;
                                     case 'template':

+ 4 - 4
src/app/graphqlService/UserCreate.jsx

@@ -47,9 +47,9 @@ class UserCreate extends Component {
 
 
     render() {
-        let schemaID = this.props.history.location.state ? this.props.history.location.state.schemaID : "ecommerce_schemaID";
-        let schemaName = this.props.history.location.state ? this.props.history.location.state.schemaName : "ecommerce";
-        let projectID = this.props.history.location.state ? this.props.history.location.state.projectID : "";
+        let schemaID = this.props.location.state ? this.props.location.state.schemaID : "ecommerce_schemaID";
+        let schemaName = this.props.location.state ? this.props.location.state.schemaName : "ecommerce";
+        let projectID = this.props.location.state ? this.props.location.state.projectID : "";
         return (
             <div>
                 <Menu
@@ -78,7 +78,7 @@ class UserCreate extends Component {
                                     case 'deploy':
                                         return <Deploy trialcase={false} userID={this.state.userID} projectID={projectID}/>;
                                     case 'manage':
-                                        return <Manage/>;
+                                        return <Manage trialcase={false} userID={this.state.userID} projectID={projectID}/>;
                                     case 'graphiql':
                                         return <Graphql/>;
                                     case 'template':

+ 59 - 28
src/app/graphqlService/component/schema/Schema.jsx

@@ -10,7 +10,7 @@ import {
     SHOW_TABLE,
     UPDATE_SCHEMA,
     UPDATE_SCHEMA_PROJECT_NAME,
-    SEARCH_SCHEMA,
+    SEARCH_SCHEMA,ADD_PROJECT_AND_SCHEMA,
     ADD_SCHEMA, SHOW_PROJECT
 } from '../../../../gql'
 import Table from "./Table";
@@ -385,6 +385,7 @@ class Schema extends Component {
                                                                             <CopySchemaButton
                                                                                 userID={userID}
                                                                                 history={this.props.history}
+                                                                                schemaID={this.state.schemaID}
                                                                                 schemaName={this.state.schemaName}
                                                                             />
                                                                         </div>
@@ -413,6 +414,7 @@ class Schema extends Component {
                                                                         <CopySchemaButton
                                                                             userID={userID}
                                                                             history={this.props.history}
+                                                                            schemaID={this.state.schemaID}
                                                                             schemaName={this.state.schemaName}
                                                                         />
                                                                     </div>
@@ -503,47 +505,75 @@ class CopySchemaButton extends Component {
         };
     }
 
+    handleOk = (userID, create_project_and_schema) => {
+        let {history,schemaName,schemaID} = this.props;
+        let projectName = schemaName + '_' + Math.random().toString().slice(-3) + Math.random().toString().slice(-4);
+        let schemaId = idGen('schema');
+        let projectId= idGen('project');
+        let createdAt = new Date().getTime();
+
+        let schemaVarObj = {
+            schemaId,
+            schemaName:projectName,
+            user_id: userID,
+            schemaCreatedAt: createdAt,
+            schemaUpdatedAt: '',
+            schemaState: 'copy',
+            schemaData: JSON.stringify([]),
+            reference:  schemaID
+        };
+        let projectVarObj = {
+            projectCreatedAt: createdAt,
+            projectUpdatedAt: '',
+            database_id: '',
+            apiGWGroup_id: '',
+            projectName,
+            deploy_id: '',
+            projectId,
+            projectType: 'graphql',
+            cloud_id: '',
+            user_id: userID,
+            wxConfig_id: '',
+            schema_id: schemaId
+        };
+
+        create_project_and_schema({
+            variables: {...schemaVarObj,...projectVarObj},
+            refetchQueries:[{query: gql(SHOW_PROJECT), variables: {projectType:'graphql',user_id: userID}}]
+        });
+
+        history.push({
+            pathname: `/graphql-service/my-create/${schemaName}`,
+            state: {
+                schemaName,
+                schemaID:schemaId,
+                projectID: projectId,
+                copy: true,
+                reference: schemaID
+            }
+        });
+    };
+
     render() {
-        let userID = getCookie('user_id');
-        let {history, schemaName} = this.props;
-        let schemaID = schemaName + '_schemaID';
+        let {userID} = this.props;
+        // let schemaID = schemaName + '_schemaID';
         return (
             <div>
                 <Mutation
-                    mutation={gql(ADD_SCHEMA)}
-                    refetchQueries={[{query: gql(SHOW_SCHEMA), variables: {user_id: userID}}]}
+                    mutation={gql(ADD_PROJECT_AND_SCHEMA)}
+                    // refetchQueries={[{query: gql(SHOW_SCHEMA), variables: {user_id: userID}}]}
                 >
-                    {(create_schema, {loading, error}) => {
+                    {(create_project_and_schema, {loading, error}) => {
                         if (loading)
                             return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
                         if (error)
                             return 'error';
 
-                        let varObj = {
-                            id: idGen('schema'),
-                            user_id: userID,
-                            createdAt: new Date().getTime(),
-                            updatedAt: '',
-                            schemaState: 'copy',
-                            schemaData: JSON.stringify([]),
-                            reference: schemaID,
-                            schemaName: schemaName + '_' + Math.random().toString().slice(-3) + Math.random().toString().slice(-4)
-                        };
-
                         return (
                             <Button
                                 type="primary"
                                 onClick={() => {
-                                    create_schema({variables: varObj});
-                                    history.push({
-                                        pathname: `/graphql-service/my-create/${varObj.schemaName}`,
-                                        state: {
-                                            schemaName: varObj.schemaName,
-                                            schemaID: varObj.id,
-                                            copy: true,
-                                            reference: varObj.reference
-                                        }
-                                    });
+                                    this.handleOk(userID, create_project_and_schema);
                                 }}
 
                             ><FormattedMessage id="copy"/></Button>
@@ -708,6 +738,7 @@ class ModifySchemaNameInput extends Component {
     render() {
         let userID = this.props.userID;
         let schemaName = this.props.schemaName;
+        console.log('schemaId',this.props.schemaID);
         return (
             <Mutation mutation={gql(UPDATE_SCHEMA_PROJECT_NAME)}>
                 {(update_schema_project_name, {loading, error}) => {

+ 5 - 2
src/app/graphqlService/component/schema/index.css

@@ -118,9 +118,12 @@ p.show {
   border-bottom: 1px solid #e9e9e9;
 }
 
+.schema-table-list-content .ant-row div:first-child{
+    cursor: pointer;
+}
+
 .name {
-  color: #3c658a;
-  cursor: pointer;
+    color: #006eff;
 }
 
 .schema-table-list-content:last-child {

+ 4 - 4
src/app/wechatService/WxTrialCase.js

@@ -24,9 +24,9 @@ class WxTrialCase extends Component {
     };
 
     render() {
-        let configID = this.props.history.location.state ? this.props.history.location.state.configID : "ecommerce_wxConfigID";
-        let appName = this.props.history.location.state ? this.props.history.location.state.appName : "ecommerce";
-        let projectID = this.props.history.location.state ? this.props.history.location.state.projectID : "";
+        let configID = this.props.location.state ? this.props.location.state.configID : "ecommerce_wxConfigID";
+        let appName = this.props.location.state ? this.props.location.state.appName : "ecommerce";
+        let projectID = this.props.location.state ? this.props.location.state.projectID : "";
         return (
             <div>
                 <Menu
@@ -57,7 +57,7 @@ class WxTrialCase extends Component {
                                 case 'wechat-deploy':
                                     return <WxDeploy trialcase={true} userID={this.state.userID} configID={configID}/>;
                                 case 'wechat-manage':
-                                    return <Manage/>;
+                                    return <Manage trialcase={true} userID={this.state.userID} configID={configID}/>;
                                 default:
                                     return <WxConfig/>
                             }

+ 4 - 4
src/app/wechatService/WxUserCreate.js

@@ -45,9 +45,9 @@ class WxUserCreate extends Component {
     };
 
     render() {
-        let configID = this.props.history.location.state ? this.props.history.location.state.configID : "ecommerce_wxConfigID";
-        let appName = this.props.history.location.state ? this.props.history.location.state.appName : "ecommerce";
-        let projectID = this.props.history.location.state ? this.props.history.location.state.projectID : "";
+        let configID = this.props.location.state ? this.props.location.state.configID : "ecommerce_wxConfigID";
+        let appName = this.props.location.state ? this.props.location.state.appName : "ecommerce";
+        let projectID = this.props.location.state ? this.props.location.state.projectID : "";
         return (
             <div>
                 <Menu
@@ -78,7 +78,7 @@ class WxUserCreate extends Component {
                                 case 'wechat-deploy':
                                     return <WxDeploy trialcase={false} userID={this.state.userID} configID={configID}/>;
                                 case 'wechat-manage':
-                                    return <Manage/>;
+                                    return <Manage trialcase={false} userID={this.state.userID} configID={configID}/>;
                                 default:
                                     return <WxConfig/>
                             }

+ 26 - 6
src/gql.js

@@ -207,7 +207,10 @@ const UPDATE_SCHEMA_PROJECT_NAME = `
                     projectName: $schemaName,
                 ){
                     projectName,
-                    id
+                    id,
+                    schema_id{
+                       id
+                    }
                 }
             }
         `;
@@ -344,12 +347,29 @@ const ADD_PROJECT_AND_WX = `
 
 const CASE_SCHEMA_AND_PROJECT = `
             query CASE_SCHEMA_AND_PROJECT($user_id: ID, $projectType: String ) {
-                caseSchema:schema_by_props(user_id: "ioobot") {
-                    schemaData
-                    schemaName
+                caseProject:project_by_props(
+                    projectType: $projectType,
+                    user_id: "ioobot"
+                ) {
+                    updatedAt
+                    apiGWGroup_id {
+                        id
+                    }
+                    createdAt
+                    projectName
                     id
-                    reference
-                    schemaState
+                    projectType
+                    wxConfig_id {
+                        id
+                        appName
+                    }
+                    schema_id {
+                        schemaData
+                        schemaName
+                        id
+                        reference
+                        schemaState
+                    }
                 }
                 
                 project:project_by_props(