Skip to content

Commit

Permalink
enhances facet fields confidentiality
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Sep 17, 2023
1 parent be16ddd commit 035f074
Show file tree
Hide file tree
Showing 46 changed files with 815 additions and 1,099 deletions.
18 changes: 13 additions & 5 deletions src/main/app/Resources/modules/content/form/parameters/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ import cloneDeep from 'lodash/cloneDeep'
import isEmpty from 'lodash/isEmpty'
import get from 'lodash/get'

function formatSections(sections, allFields, dataPath = null, hasConfidentialRights = false, hasLockedRights = false) {
return sections.map(section => formatSection(section, allFields, dataPath, hasConfidentialRights, hasLockedRights))
import {trans} from '#/main/app/intl'

function formatSections(sections, allFields, dataPath = null, isOwner = false, hasConfidentialRights = false, hasLockedRights = false) {
return sections.map(section => formatSection(section, allFields, dataPath, isOwner, hasConfidentialRights, hasLockedRights))
}

function formatSection(section, allFields, dataPath = null, hasConfidentialRights = false, hasLockedRights = false) {
function formatSection(section, allFields, dataPath = null, isOwner = false, hasConfidentialRights = false, hasLockedRights = false) {
const sectionDefinition = cloneDeep(section)

sectionDefinition.icon = get(section, 'display.icon') ? `fa fa-fw fa-${get(section, 'display.icon')}` : undefined
sectionDefinition.subtitle = get(section, 'meta.description')
sectionDefinition.fields = sectionDefinition.fields
.filter(field => !get(field, 'restrictions.metadata') || hasConfidentialRights)
.filter(field => !get(field, 'restrictions.confidentiality')
|| 'none' === get(field, 'restrictions.confidentiality')
|| hasConfidentialRights
|| ('owner' === get(field, 'restrictions.confidentiality') && isOwner)
)
.map(f => formatField(f, allFields, dataPath, hasLockedRights))

return sectionDefinition
Expand All @@ -24,7 +30,9 @@ function formatField(fieldDef, allFields, dataPath = null, hasLockedRights = fal
type: fieldDef.type,
label: fieldDef.label,
required: fieldDef.required,
help: fieldDef.help,
help: fieldDef.restrictions.confidentiality && 'manager' === fieldDef.restrictions.confidentiality ?
[trans('field_confidentiality_manager_help')].concat(Array.isArray(fieldDef.help) ? fieldDef.help : [fieldDef.help]).filter(help => !!help)
: fieldDef.help,
options: fieldDef.options ? cloneDeep(fieldDef.options) : {},
displayed: (data) => isFieldDisplayed(fieldDef, allFields, dataPath ? data[dataPath] : dataPath),
disabled: (data) => {
Expand Down
116 changes: 61 additions & 55 deletions src/main/app/Resources/modules/data/types/fields/components/input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import {MODAL_SELECTION} from '#/main/app/modals/selection'
import {MODAL_FIELD_PARAMETERS} from '#/main/app/data/types/fields/modals/parameters'

import {Button} from '#/main/app/action/components/button'
import {Toolbar} from '#/main/app/action/components/toolbar'
import {CALLBACK_BUTTON, MODAL_BUTTON} from '#/main/app/buttons'

import {getCreatableTypes} from '#/main/app/data/types'
import {DataInput} from '#/main/app/data/components/input'
import {DataInput as DataInputTypes} from '#/main/app/data/types/prop-types'
import {ContentPlaceholder} from '#/main/app/content/components/placeholder'

// todo try to avoid connexion to the store
// todo create working preview
// todo find a way to use collections

const FieldPreview = props =>
Expand All @@ -46,7 +45,6 @@ class FieldList extends Component {
this.update = this.update.bind(this)
this.remove = this.remove.bind(this)
this.removeAll = this.removeAll.bind(this)
this.open = this.open.bind(this)
this.formatField = this.formatField.bind(this)
}

Expand Down Expand Up @@ -81,14 +79,6 @@ class FieldList extends Component {
this.props.onChange([])
}

open(field, allFields, callback) {
this.props.showModal(MODAL_FIELD_PARAMETERS, {
data: field,
fields: allFields.filter(otherField => otherField.id !== field.id),
save: callback
})
}

formatField(field) {
const options = field.options ? Object.assign({}, field.options) : {}

Expand All @@ -112,6 +102,10 @@ class FieldList extends Component {

return (
<div className={classes('field-list-control', this.props.className)}>
{0 === this.props.value.length &&
<ContentPlaceholder className="mb-2" title={this.props.placeholder} size={this.props.size} />
}

{0 !== this.props.value.length &&
<Button
className="btn btn-text-danger btn-delete-all"
Expand Down Expand Up @@ -142,48 +136,54 @@ class FieldList extends Component {
})
.map((field, fieldIndex) =>
<li key={fieldIndex} className="field-item mb-2">
<FieldPreview {...this.formatField(field)} />

<div className="field-item-actions">
<Button
id={`${this.props.id}-${fieldIndex}-edit`}
type={MODAL_BUTTON}
className="btn btn-text-secondary"
icon="fa fa-fw fa-pencil"
label={trans('edit', {}, 'actions')}
tooltip="top"
modal={[MODAL_FIELD_PARAMETERS, {
data: field,
fields: allFields.filter(otherField => otherField.id !== field.id),
save: (data) => this.update(fieldIndex, data)
}]}
/>

<Button
id={`${this.props.id}-${fieldIndex}-delete`}
type={CALLBACK_BUTTON}
className="btn btn-text-danger"
icon="fa fa-fw fa-trash"
label={trans('delete', {}, 'actions')}
tooltip="top"
confirm={{
title: trans('delete_field'),
message: trans('delete_field_confirm')
}}
callback={() => this.remove(fieldIndex)}
dangerous={true}
/>
<div className="field-item-preview">
<FieldPreview {...this.formatField(field)} />
{get(field, 'restrictions.confidentiality') && 'none' !== get(field, 'restrictions.confidentiality') &&
<div className="badge text-bg-primary mt-1">
<span className="fa fa-fw fa-eye icon-with-text-right" />
{trans('confidentiality_'+field.restrictions.confidentiality)}
</div>
}
</div>

<Toolbar
id={`${this.props.id}-${fieldIndex}-actions`}
className="field-item-actions"
tooltip="top"
actions={[
{
name: 'edit',
type: MODAL_BUTTON,
className: 'btn btn-text-secondary',
icon: 'fa fa-fw fa-pencil',
label: trans('edit', {}, 'actions'),
modal: [MODAL_FIELD_PARAMETERS, {
field: field,
isNew: false,
fields: allFields.filter(otherField => otherField.id !== field.id),
save: (data) => this.update(fieldIndex, data)
}]
}, {
name: 'delete',
type: CALLBACK_BUTTON,
className: 'btn btn-text-danger',
icon: 'fa fa-fw fa-trash',
label: trans('delete', {}, 'actions'),
confirm: {
title: trans('delete_field'),
message: trans('delete_field_confirm')
},
callback: () => this.remove(fieldIndex),
dangerous: true
}
]}
/>
</li>
)
}
</ul>
}

{0 === this.props.value.length &&
<ContentPlaceholder className="mb-2" title={this.props.placeholder} size={this.props.size} />
}

<Button
type={CALLBACK_BUTTON}
variant="btn"
Expand All @@ -192,16 +192,22 @@ class FieldList extends Component {
label={trans('add_field')}
callback={() => getCreatableTypes().then(types => {
this.props.showModal(MODAL_SELECTION, {
title: trans('create_field'),
icon: 'fa fa-fw fa-plus',
title: trans('new_field'),
subtitle: trans('new_field_select'),
items: types.map(type => Object.assign({}, type.meta, {name: type.name})),
handleSelect: (type) => this.open({
id: makeId(),
type: type.name,
restrictions: {
locked: false,
lockedEditionOnly: false
}
}, allFields, this.add)
selectAction: (type) => ({
type: MODAL_BUTTON,
modal: [MODAL_FIELD_PARAMETERS, {
field: {
id: makeId(),
type: type.name
},
isNew: true,
fields: allFields,
save: this.add
}]
})
})
})}
/>
Expand Down
Loading

0 comments on commit 035f074

Please sign in to comment.