ProjectForm.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React from 'react'
  21. import classnames from 'classnames'
  22. import { Form, Row, Col, Input, Tag, Button, Select } from 'antd'
  23. import { FormComponentProps } from 'antd/lib/form/Form'
  24. const TextArea = Input.TextArea
  25. const Option = Select.Option
  26. const FormItem = Form.Item
  27. const styles = require('../Project.less')
  28. import Avatar from 'components/Avatar'
  29. const utilStyles = require('assets/less/util.less')
  30. interface IProjectsFormProps {
  31. type?: string
  32. organizations?: any
  33. onTransfer?: () => any
  34. onModalOk?: () => any
  35. modalLoading: boolean
  36. onWidgetTypeChange?: () => any
  37. onCheckUniqueName?: (pathname: any, data: any, resolve: () => any, reject: (error: string) => any) => any
  38. }
  39. export class ProjectsForm extends React.PureComponent<IProjectsFormProps & FormComponentProps, {}> {
  40. constructor (props) {
  41. super(props)
  42. }
  43. public render () {
  44. const { type, organizations, modalLoading, onCheckUniqueName, onWidgetTypeChange } = this.props
  45. const { getFieldDecorator } = this.props.form
  46. const commonFormItemStyle = {
  47. labelCol: { span: 3 },
  48. wrapperCol: { span: 24 }
  49. }
  50. const modalButtons = [(
  51. <Button
  52. key="submit"
  53. size="large"
  54. type="primary"
  55. htmlType="submit"
  56. onClick={this.props.onModalOk}
  57. loading={modalLoading}
  58. disabled={modalLoading}
  59. >
  60. 保 存
  61. </Button>
  62. )]
  63. const transferButtons = [(
  64. <Button
  65. key="submit"
  66. size="large"
  67. type="primary"
  68. onClick={this.props.onTransfer}
  69. loading={modalLoading}
  70. disabled={modalLoading}
  71. >
  72. 移交
  73. </Button>
  74. )]
  75. const organizationOptions = organizations ? organizations.map((o) => {
  76. const orgId = this.props.form.getFieldValue('orgId_hc')
  77. if (this.props.type === 'transfer' && o.id === Number(orgId)) {
  78. return []
  79. }
  80. const disabled = o.allowCreateProject === false
  81. return (
  82. <Option key={o.id} value={`${o.id}`} disabled={disabled} className={styles.selectOption}>
  83. <div className={styles.title}>
  84. <span className={styles.owner} style={{color: disabled ? '#ccc' : '#444444'}}>{o.name}</span>
  85. {`${o.id}` !== this.props.form.getFieldValue('orgId')
  86. ? o.role === 1 ? <Tag color={`${ disabled ? '#ccc' : '#108ee9'}`}>Owner</Tag> : ''
  87. : ''}
  88. </div>
  89. {`${o.id}` !== this.props.form.getFieldValue('orgId')
  90. ? (<Avatar size="small" path={o.avatar}/>)
  91. : ''}
  92. </Option>
  93. )
  94. }) : ''
  95. const isShowOrganization = classnames({
  96. [utilStyles.hide]: (this.props.type === 'organizationProject') || (this.props.type === 'edit')
  97. })
  98. const isShowDesc = classnames({
  99. [utilStyles.hide]: this.props.type === 'transfer'
  100. })
  101. // const isShowVisibility = classnames({
  102. // [utilStyles.hide]: this.props.type !== 'edit'
  103. // })
  104. let modalTitle = '创建'
  105. if (type === 'edit') {
  106. modalTitle = '修改'
  107. } else if (type === 'transfer') {
  108. modalTitle = '移交'
  109. }
  110. return (
  111. <div className={styles.formWrapper}>
  112. <div className={styles.header}>
  113. <div className={styles.title}>
  114. {modalTitle}项目
  115. </div>
  116. <div className={styles.desc}>
  117. 项目属于组织,可以在项目中连接数据源,生成可视化图表
  118. </div>
  119. </div>
  120. <div className={styles.body}>
  121. <Form>
  122. <Row gutter={8}>
  123. <Col span={24}>
  124. {type !== 'add' && (
  125. <FormItem className={utilStyles.hide}>
  126. {getFieldDecorator('id', {})(
  127. <Input />
  128. )}
  129. </FormItem>
  130. )}
  131. {type === 'transfer' && (
  132. <FormItem className={utilStyles.hide}>
  133. {getFieldDecorator('orgId_hc', {})(
  134. <Input />
  135. )}
  136. </FormItem>
  137. )}
  138. {type !== 'organizationProject' && (
  139. <FormItem label="组织" {...commonFormItemStyle} className={isShowOrganization}>
  140. {getFieldDecorator('orgId', {
  141. rules: [{
  142. required: true,
  143. message: 'Name 不能为空'
  144. }]
  145. })(
  146. <Select
  147. placeholder="Please select a organization"
  148. onChange={onWidgetTypeChange}
  149. >
  150. {organizationOptions}
  151. </Select>
  152. )}
  153. </FormItem>
  154. )}
  155. {type !== 'transfer' && (
  156. <FormItem label="名称" {...commonFormItemStyle} className={isShowDesc}>
  157. {getFieldDecorator('name', {
  158. rules: [{
  159. required: true,
  160. message: 'Name 不能为空'
  161. }, {
  162. validator: onCheckUniqueName
  163. }],
  164. validateFirst: true
  165. })(
  166. <Input placeholder="Name" />
  167. )}
  168. </FormItem>
  169. )}
  170. </Col>
  171. <Col span={24}>
  172. {type !== 'transfer' && (
  173. <FormItem label="描述" {...commonFormItemStyle} className={isShowDesc}>
  174. {getFieldDecorator('description', {
  175. initialValue: ''
  176. })(
  177. <TextArea
  178. placeholder="Description"
  179. autosize={{minRows: 2, maxRows: 6}}
  180. />
  181. )}
  182. </FormItem>
  183. )}
  184. </Col>
  185. <Col span={24}>
  186. <FormItem label="可见" {...commonFormItemStyle}>
  187. {getFieldDecorator('visibility', {
  188. // hidden: this.props.type !== 'edit',
  189. initialValue: 'true'
  190. })(
  191. <Select>
  192. <Option key="visibility" value="true">
  193. 公开
  194. </Option>
  195. <Option key="hidden" value="false">
  196. 授权
  197. </Option>
  198. </Select>
  199. )}
  200. </FormItem>
  201. </Col>
  202. <Col span={24}>
  203. {type !== 'add' && type !== 'transfer' && (
  204. <FormItem className={utilStyles.hide}>
  205. {getFieldDecorator('pic', {})(
  206. <Input />
  207. )}
  208. </FormItem>
  209. )}
  210. </Col>
  211. </Row>
  212. </Form>
  213. </div>
  214. <div className={styles.footer}>
  215. {type === 'transfer' ? transferButtons : modalButtons}
  216. </div>
  217. </div>
  218. )
  219. }
  220. }
  221. export default Form.create<IProjectsFormProps & FormComponentProps>()(ProjectsForm)