Project.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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, Menu, Icon, Tooltip, Popconfirm, Table, Modal} 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. import ProjectRole from './ProjectRole'
  31. import ProjectAdmin from './ProjectAdmin'
  32. interface IProjectsFormProps {
  33. type: string
  34. deleteProject: (id: number) => any
  35. currentProject: any
  36. organizations?: any
  37. onModalOk: () => any
  38. modalLoading: boolean
  39. onCancel: () => any
  40. showEditProjectForm: (e) => any
  41. onCheckUniqueName: (pathname: any, data: any, resolve: () => any, reject: (error: string) => any) => any
  42. onTabsChange: (mode: string) => any
  43. }
  44. interface IProjectsFormStates {
  45. mode: string
  46. name: string
  47. description: string
  48. visibility: string
  49. relationRoleVisible: boolean
  50. authSettingVisible: boolean
  51. }
  52. export class ProjectsForm extends React.PureComponent<IProjectsFormProps & FormComponentProps, IProjectsFormStates> {
  53. constructor (props) {
  54. super(props)
  55. this.state = {
  56. mode: '',
  57. name: '',
  58. description: '',
  59. visibility: '',
  60. relationRoleVisible: false,
  61. authSettingVisible: false
  62. }
  63. }
  64. private checkout = ({item, key, keyPath}) => {
  65. this.setState({
  66. mode: key
  67. }, () => {
  68. const { onTabsChange } = this.props
  69. if (onTabsChange) {
  70. onTabsChange(this.state.mode)
  71. }
  72. })
  73. }
  74. private stopPPG = (e) => {
  75. e.stopPropagation()
  76. }
  77. private deleteProject = (id) => () => {
  78. const {deleteProject, onCancel} = this.props
  79. deleteProject(id)()
  80. onCancel()
  81. }
  82. private toggleModal = (flag: string) => () => {
  83. if (flag === 'relationRoleVisible') {
  84. this.setState({
  85. relationRoleVisible: !this.state[flag]
  86. })
  87. } else {
  88. this.setState({
  89. authSettingVisible: !this.state[flag]
  90. })
  91. }
  92. }
  93. private substr (str: string) {
  94. return str?.length > 14 ? `${str.substr(0, 14)}...` : str
  95. }
  96. public render () {
  97. const { type, organizations, modalLoading, onCheckUniqueName } = this.props
  98. const { getFieldDecorator } = this.props.form
  99. const commonFormItemStyle = {
  100. labelCol: { span: 3 },
  101. wrapperCol: { span: 24 }
  102. }
  103. const modalButtons = [(
  104. <Button
  105. key="submit"
  106. size="large"
  107. type="primary"
  108. onClick={this.props.onModalOk}
  109. loading={modalLoading}
  110. disabled={modalLoading}
  111. >
  112. 保 存
  113. </Button>
  114. )]
  115. const organizationOptions = organizations ? organizations.map((o) => {
  116. const orgId = this.props.form.getFieldValue('orgId_hc')
  117. if (this.props.type === 'transfer' && o.id === Number(orgId)) {
  118. return []
  119. }
  120. const disabled = o.allowCreateProject === false
  121. return (
  122. <Option key={o.id} value={`${o.id}`} disabled={disabled} className={styles.selectOption}>
  123. <div className={styles.title}>
  124. <span className={styles.owner} style={{color: disabled ? '#ccc' : '#444444'}}>{o.name}</span>
  125. {`${o.id}` !== this.props.form.getFieldValue('orgId')
  126. ? <Tag color={`${ disabled ? '#ccc' : '#108ee9'}`}>Owner</Tag>
  127. : ''}
  128. </div>
  129. {`${o.id}` !== this.props.form.getFieldValue('orgId')
  130. ? (<Avatar size="small" path={o.avatar}/>)
  131. : ''}
  132. </Option>
  133. )
  134. }) : ''
  135. const isShowOrganization = classnames({
  136. [utilStyles.hide]: (this.props.type === 'organizationProject') || (this.props.type === 'edit')
  137. })
  138. const isShowDesc = classnames({
  139. [utilStyles.hide]: this.props.type === 'transfer'
  140. })
  141. let modalTitle = '创建'
  142. if (type === 'edit') {
  143. modalTitle = '修改'
  144. } else if (type === 'transfer') {
  145. modalTitle = '移交'
  146. }
  147. let mode = void 0
  148. if (this.state.mode === 'role') {
  149. mode = <ProjectRole/>
  150. } else if (this.state.mode === 'admin') {
  151. mode = <ProjectAdmin/>
  152. } else {
  153. const { currentProject: {name, id, description, visibility, createBy}} = this.props
  154. const currentState = this.props.form.getFieldsValue()
  155. const disabled = name !== currentState.name || description !== currentState.description || `${visibility}` !== currentState.visibility
  156. mode = (
  157. <div className={styles.basic}>
  158. <Form>
  159. <Row gutter={24}>
  160. <Col span={12}>
  161. {type !== 'add' && (
  162. <FormItem className={utilStyles.hide}>
  163. {getFieldDecorator('id', {})(
  164. <Input />
  165. )}
  166. </FormItem>
  167. )}
  168. <FormItem label="名称">
  169. {getFieldDecorator('name', {
  170. // hidden: this.props.type === 'transfer',
  171. rules: [{
  172. required: true,
  173. message: '名称 不能为空'
  174. }, {
  175. validator: onCheckUniqueName
  176. }]
  177. })(
  178. <Input placeholder="名称" />
  179. )}
  180. </FormItem>
  181. </Col>
  182. <Col span={12}>
  183. <FormItem label="可见">
  184. {getFieldDecorator('visibility', {
  185. // hidden: this.props.type !== 'edit',
  186. initialValue: 'true'
  187. })(
  188. <Select>
  189. <Option key="visibility" value="true">
  190. 公开
  191. </Option>
  192. <Option key="hidden" value="false">
  193. 授权
  194. </Option>
  195. </Select>
  196. )}
  197. </FormItem>
  198. </Col>
  199. </Row>
  200. <Row gutter={24}>
  201. <Col span={24}>
  202. <FormItem label="描述">
  203. {getFieldDecorator('description', {
  204. // hidden: this.props.type === 'transfer',
  205. initialValue: ''
  206. })(
  207. <TextArea
  208. placeholder="描述"
  209. autosize={{minRows: 2, maxRows: 6}}
  210. />
  211. )}
  212. </FormItem>
  213. </Col>
  214. </Row>
  215. </Form>
  216. <div className={styles.save}>
  217. <Row>
  218. <Col>
  219. <Button disabled={!disabled} onClick={this.props.onModalOk}>保存修改</Button>
  220. </Col>
  221. </Row>
  222. </div>
  223. <Row className={styles.Zone}>
  224. <div className={styles.title}>
  225. 移交项目
  226. </div>
  227. <div className={styles.titleDesc}>
  228. <p className={styles.desc}> <span className={styles.label}>项目名称</span> <b>{name}</b></p>
  229. <p className={styles.desc}><span className={styles.label}>创建人</span> <b>{createBy.username}</b></p>
  230. <p className={styles.button}>
  231. <Tooltip title="移交">
  232. <Button type="default" onClick={this.props.showEditProjectForm}>移交 {this.substr(name)}</Button>
  233. </Tooltip>
  234. </p>
  235. </div>
  236. </Row>
  237. <Row className={styles.dangerZone}>
  238. <div className={styles.title}>
  239. 删除项目
  240. </div>
  241. <div className={styles.titleDesc}>
  242. <p className={styles.desc}>删除后无法恢复,请确定此次操作</p>
  243. <p className={styles.button}>
  244. <Popconfirm
  245. title="确定删除?"
  246. placement="bottom"
  247. onConfirm={this.deleteProject(id)}
  248. >
  249. <Tooltip title="删除">
  250. <Button type="danger" onClick={this.stopPPG} >删除 {this.substr(name)}</Button>
  251. </Tooltip>
  252. </Popconfirm>
  253. </p>
  254. </div>
  255. </Row>
  256. </div>
  257. )
  258. }
  259. return (
  260. <div className={styles.filterConfig}>
  261. <div className={styles.left}>
  262. <Menu
  263. defaultSelectedKeys={['basic']}
  264. onClick={this.checkout}
  265. >
  266. <Menu.Item key="basic">
  267. <Icon type="setting" />
  268. 基础设置
  269. </Menu.Item>
  270. <Menu.Item key="role">
  271. <Icon type="trademark" />
  272. 角色管理
  273. </Menu.Item>
  274. <Menu.Item key="admin">
  275. <Icon type="user" />
  276. 管理员设置
  277. </Menu.Item>
  278. </Menu>
  279. </div>
  280. <div className={styles.center}>
  281. {mode}
  282. </div>
  283. </div>
  284. )
  285. }
  286. }
  287. export default Form.create<IProjectsFormProps & FormComponentProps>()(ProjectsForm)