ProjectAuth.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 { Icon, Button, Row, Col, Input, Select, Popconfirm, Table, Modal, Form, Radio } from 'antd'
  23. const FormItem = Form.Item
  24. const InputGroup = Input.Group
  25. const RadioGroup = Radio.Group
  26. const Option = Select.Option
  27. const styles = require('../Project.less')
  28. import { uuid } from 'utils/util'
  29. const utilStyles = require('assets/less/util.less')
  30. interface IAuthProps {
  31. vizs?: any
  32. form?: any
  33. currentProjectRole?: object
  34. onChangeModulePermission?: (event: any, record: object) => any
  35. onChangeVizPermission?: (event: any, record: object) => any
  36. }
  37. export class Auth extends React.Component <IAuthProps, {}> {
  38. constructor (props) {
  39. super(props)
  40. }
  41. public render () {
  42. const role = 1
  43. const authModules = [ 'viz', 'view', 'source', 'widget', 'schedule', 'share', 'download']
  44. const organizationMembers = authModules.map((auth, index) => {
  45. return {
  46. user: auth,
  47. permission: this.props.currentProjectRole ? this.props.currentProjectRole['permission'][`${auth}Permission`] : void 0
  48. }
  49. })
  50. const columns = [
  51. {
  52. dataIndex: 'user',
  53. key: 'user',
  54. render: (text) => text.toUpperCase()
  55. },
  56. {
  57. dataIndex: 'permission',
  58. // className: isHidden ? utilStyles.hide : '',
  59. key: 'settings',
  60. width: '59%',
  61. render: (text, record) => {
  62. switch (record.user) {
  63. case 'share':
  64. case 'download':
  65. return (
  66. <Radio.Group size="small" disabled={!role} value={text} onChange={this.props.onChangeModulePermission.bind(this, record)}>
  67. <Radio value={false}>禁止</Radio>
  68. <Radio value={true}>允许</Radio>
  69. </Radio.Group>
  70. )
  71. default:
  72. return (
  73. <Radio.Group size="small" disabled={!role} value={text} onChange={this.props.onChangeModulePermission.bind(this, record)}>
  74. <Radio value={0}>隐藏</Radio>
  75. <Radio value={1}>只读</Radio>
  76. <Radio value={2}>修改</Radio>
  77. <Radio value={3}>删除</Radio>
  78. </Radio.Group>
  79. )
  80. }
  81. }
  82. }]
  83. const dvColumns = [
  84. {
  85. dataIndex: 'key',
  86. key: `name${uuid(8, 16)}`
  87. },
  88. {
  89. dataIndex: 'name',
  90. key: `key${uuid(8, 16)}`,
  91. width: '59%',
  92. render: (text, record) => {
  93. const isTitle = record.isTitle
  94. if (!isTitle) {
  95. return (
  96. <Radio.Group size="small" value={record.permission} onChange={this.props.onChangeVizPermission.bind(this, record)}>
  97. <Radio value={0}>隐藏</Radio>
  98. <Radio value={1}>显示</Radio>
  99. </Radio.Group>
  100. )
  101. }
  102. }
  103. }
  104. ]
  105. return (
  106. <div className={styles.auth}>
  107. <div className={styles.module}>
  108. <div className={styles.title}>
  109. 功能权限设置
  110. </div>
  111. <Table
  112. bordered
  113. showHeader={false}
  114. columns={columns}
  115. pagination={false}
  116. dataSource={organizationMembers}
  117. />
  118. </div>
  119. <div className={styles.dv}>
  120. <div className={styles.title}>
  121. 可视化权限设置
  122. </div>
  123. <Table
  124. bordered
  125. rowKey="key"
  126. showHeader={false}
  127. columns={dvColumns}
  128. dataSource={this.props.vizs}
  129. pagination={false}
  130. defaultExpandAllRows={true}
  131. />
  132. </div>
  133. </div>
  134. )
  135. }
  136. }
  137. export default Auth