Commit 3a34792b authored by Giannis Kopanas's avatar Giannis Kopanas Committed by Alexandros Georgantas

feat(applicationparameters): get config from db create graphql query

parent 02c84dd2
scalar JSON
type applicationParameter {
id: ID
context: String
area: String
config: String
config: JSON
}
type updateParametersInput {
input updateParametersInput {
context: String
area: String
config: String
}
extend type Query {
getApplicationParameters(context: String!, area: String!): [ApplicationParameter!]!
getApplicationParameters(context: String, area: String): [applicationParameter!]!
}
extend type Mutation {
updateApplicationParameters(input: updateParametersInput!): ApplicationParameter!
updateApplicationParameters(input: updateParametersInput!): applicationParameter!
}
......@@ -2,27 +2,40 @@ const { ApplicationParameter } = require('editoria-data-model/src').models
const getApplicationParameters = async (_, args, ctx) => {
const { context, area } = args
const parameters = await ApplicationParameter.query().where({ context, area })
return parameters
}
const parameters = await ApplicationParameter.query()
.skipUndefined()
.where({ context, area })
const updateApplicationParameter = async (_, args, ctx) => {
const { context, area, config } = args
// console.log(parameters)
const parameter = await ApplicationParameter.query().findOne({
context,
area,
})
// console.log(
// parameters.map(parameter => {
// console.log(parameter.config,11111)
// parameter.config = JSON.parse(parameter.config)
// console.log(parameter.config, 222)
// return parameter
// }),
// )
const updatedParameter = await parameter.$query().updateAndFetch({ config })
return updatedParameter
return parameters
}
// const updateApplicationParameter = async (_, args, ctx) => {
// const { context, area, config } = args
// const parameter = await ApplicationParameter.query().findOne({
// context,
// area,
// })
// const updatedParameter = await parameter.$query().updateAndFetch({ config })
// return updatedParameter
// }
module.exports = {
Query: {
getApplicationParameters,
},
Mutation: {
updateApplicationParameter,
},
// Mutation: {
// updateApplicationParameter,
// },
}
const authorize = require('./authorize')
const applicationParameter = require('./applicationParameter')
const book = require('./book')
const bookComponent = require('./bookComponent')
const bookCollection = require('./bookCollection')
......@@ -17,6 +18,7 @@ const merge = require('lodash/merge')
module.exports = {
typeDefs: [
authorize.typeDefs,
applicationParameter.typeDefs,
book.typeDefs,
bookComponent.typeDefs,
bookCollection.typeDefs,
......@@ -30,6 +32,7 @@ module.exports = {
resolvers: merge(
{},
authorize.resolvers,
applicationParameter.resolvers,
book.resolvers,
bookComponent.resolvers,
bookCollection.resolvers,
......
......@@ -71,7 +71,7 @@ export class BookBuilder extends React.Component {
render() {
const {
book,
state,
config,
history,
addBookComponent,
onMetadataAdd,
......@@ -94,17 +94,15 @@ export class BookBuilder extends React.Component {
loading,
loadingRules,
setState,
refetchingBookBuilderRules,
onWorkflowUpdate,
} = this.props
if (loading || loadingRules) return 'Loading...'
if (!book) return null
const { canViewTeamManager, canViewMultipleFilesUpload } = rules
const { divisions, productionEditors } = book
const productionEditorActions = []
const headerActions = [
<MetadataButton book={book} onMetadataAdd={() => onMetadataAdd(book)} />,
......@@ -151,6 +149,7 @@ export class BookBuilder extends React.Component {
<Header bookTitle={book.title} actions={headerActions} />
<DivisionsArea
addBookComponent={addBookComponent}
config={config}
onWorkflowUpdate={onWorkflowUpdate}
addBookComponents={addBookComponents}
setState={setState}
......
......@@ -257,7 +257,7 @@ const mapProps = args => ({
const Composed = adopt(mapper, mapProps)
const Connected = props => {
const { match, history, currentUser } = props
const { match, history, currentUser, config } = props
const { id: bookId } = match.params
return (
......@@ -293,6 +293,7 @@ const Connected = props => {
return (
<BookBuilder
addBookComponent={addBookComponent}
config={config}
state={state}
setState={setState}
addBookComponents={addBookComponents}
......
import React, { Component } from 'react'
import config from 'config'
import styled, { keyframes, css } from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
// import { flow } from 'lodash'
......@@ -164,6 +163,7 @@ const BookComponent = ({
onWarning,
connectDragSource,
connectDropTarget,
config,
currentUser,
history,
componentType,
......@@ -263,8 +263,9 @@ const BookComponent = ({
<ActionsLeft lock={lock}>
<GrabIcon {...provided.dragHandleProps}>{icon}</GrabIcon>
<ComponentTypeMenu
divisionType={divisionType}
componentType={componentType}
config={config}
divisionType={divisionType}
onChange={onUpdateComponentType}
/>
{/* {lock && (
......@@ -272,9 +273,10 @@ const BookComponent = ({
)} */}
</ActionsLeft>
<BookComponentTitle
title={title}
bookComponentId={id}
bookId={bookId}
config={config}
title={title}
divisionType={divisionType}
componentType={componentType}
uploading={uploading}
......@@ -304,6 +306,7 @@ const BookComponent = ({
<SecondRow
bookComponentId={id}
config={config}
onWorkflowUpdate={onWorkflowUpdate}
onWarning={onWarning}
bookId={bookId}
......
import React from 'react'
import { find, indexOf } from 'lodash'
import config from 'config'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import withLink from 'editoria-common/src/withLink'
......@@ -59,6 +58,7 @@ const Title = styled.span`
const BookComponentTitle = ({
bookComponentId,
bookId,
config,
uploading,
lock,
history,
......@@ -72,7 +72,11 @@ const BookComponentTitle = ({
// history.push(`/books/${bookId}/bookComponents/${bookComponentId}`)
// }
const { divisions } = config.bookBuilder
const { config: divisions } = find(config, {
context: 'bookBuilder',
area: 'divisions',
})
// const { componentType } = bookComponent
const { showNumberBeforeComponents } = find(divisions, ['name', divisionType])
......
import React from 'react'
import styled, { css, keyframes } from 'styled-components'
import { State } from 'react-powerplug'
import { find, map } from 'lodash'
import config from 'config'
import { th } from '@pubsweet/ui-toolkit'
import { Menu as UIMenu } from './Menu'
......@@ -223,10 +221,19 @@ const Opener = props => {
)
}
const ComponentTypeMenu = ({ onChange, divisionType, componentType }) => {
const { bookBuilder } = config
const { divisions } = bookBuilder
const ComponentTypeMenu = ({
onChange,
divisionType,
componentType,
config,
}) => {
const { config: divisions } = find(config, {
context: 'bookBuilder',
area: 'divisions',
})
const division = find(divisions, { name: divisionType })
const options = map(division.allowedComponentTypes, componentType => ({
label: componentType,
value: componentType,
......
import { find, map } from 'lodash'
import config from 'config'
import React from 'react'
// import { DragDropContext } from 'react-dnd'
// import HTML5Backend from 'react-dnd-html5-backend'
......@@ -161,6 +160,7 @@ class Division extends React.Component {
render() {
const {
bookId,
config,
currentUser,
updateBookComponentUploading,
updateBookComponentContent,
......@@ -204,6 +204,7 @@ class Division extends React.Component {
<div ref={provided.innerRef} {...provided.draggableProps}>
<BookComponent
bookId={bookId}
config={config}
onAdminUnlock={onAdminUnlock}
onWorkflowUpdate={onWorkflowUpdate}
currentUser={currentUser}
......@@ -246,12 +247,18 @@ class Division extends React.Component {
</Draggable>
)
})
const divisionsConfig = find(config.bookBuilder.divisions, ['name', label])
const divisionsConfig = find(config, {
context: 'bookBuilder',
area: 'divisions',
})
const componentConfig = find(divisionsConfig.config, ['name', label])
let addButtons = null
if (canViewAddComponent) {
addButtons = map(divisionsConfig.allowedComponentTypes, componentType => (
addButtons = map(componentConfig.allowedComponentTypes, componentType => (
<AddComponentButton
add={this.onAddClick}
label={`add ${componentType}`}
......
......@@ -197,6 +197,7 @@ class DivisionsArea extends Component {
render() {
const {
bookId,
config,
currentUser,
history,
onWarning,
......@@ -226,6 +227,7 @@ class DivisionsArea extends Component {
<Division
add={addBookComponent}
addBookComponents={addBookComponents}
config={config}
onWorkflowUpdate={onWorkflowUpdate}
onAdminUnlock={onAdminUnlock}
currentUser={currentUser}
......
import { findIndex, find, forIn } from 'lodash'
import React, { Component } from 'react'
import config from 'config'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
// import { AlignmentTool } from '@pubsweet/ui'
import AlignmentTool from './AlignmentTool'
import WorkflowList from './WorkflowList'
import UploadFileButton from './UploadFileButton'
import ProgressModal from './ProgressModal'
// import {AlignmentTool} from '@pubsweet/ui'
const SecondRowContainer = styled.div`
display: flex;
......@@ -29,18 +25,13 @@ class SecondRow extends Component {
// this.toggleModal = this.toggleModal.bind(this)
this.progressValues = [-1, 0, 1]
this.progressOrder = []
// this.state = {
// nextProgressValues: {
// title: null,
// type: null,
// value: null,
// },
// modalType: null,
// showModal: false,
// }
const stagesConfig = find(props.config, {
context: 'bookBuilder',
area: 'stages',
})
for (let i = 0; i < config.bookBuilder.stages.length; i += 1) {
this.progressOrder.push(config.bookBuilder.stages[i].type)
for (let i = 0; i < stagesConfig.length; i += 1) {
this.progressOrder.push(stagesConfig[i].type)
}
}
......@@ -50,15 +41,18 @@ class SecondRow extends Component {
workflowStages,
updateWorkflowState,
onWorkflowUpdate,
config,
} = this.props
const instanceConfig = find(config, {
context: 'bookBuilder',
area: 'instance',
})
const isLast =
workflowStages.length - 1 ===
findIndex(workflowStages, { label: title, type })
if (
config.bookBuilder &&
config.bookBuilder.instance &&
config.bookBuilder.instance === 'UCP'
) {
if (instanceConfig === 'UCP') {
if (type === 'file_prep' && (value === -1 || value === 0)) {
if (
find(workflowStages, { type: 'edit' }).value === 0 ||
......@@ -295,11 +289,7 @@ class SecondRow extends Component {
updateWorkflowState(bookComponentId, workflowStages)
}
}
if (
config.bookBuilder &&
config.bookBuilder.instance &&
config.bookBuilder.instance === 'BOOKSPRINTS'
) {
if (instanceConfig === 'BOOKSPRINTS') {
if (type === 'clean_up') {
if (value === 0) {
const nextProgressValues = {
......@@ -454,12 +444,12 @@ class SecondRow extends Component {
const {
bookId,
bookComponentId,
config,
onWarning,
componentType,
uploading,
lock,
showModal,
goToEditor,
showModalToggle,
updateBookComponentContent,
updateBookComponentUploading,
......@@ -505,6 +495,7 @@ class SecondRow extends Component {
stateRule => stateRule.bookComponentId === bookComponentId,
)}
bookId={bookId}
config={config}
currentValues={workflowStages}
update={this.updateStateList}
values={this.progressValues}
......
import PropTypes from 'prop-types'
import React from 'react'
import config from 'config'
import { map, uniqueId, last, indexOf, find } from 'lodash'
import { map, last, indexOf, find } from 'lodash'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import Arrow from './Arrow'
import Label from './Label'
import WorkflowItem from './WorkflowItem'
......@@ -23,6 +21,7 @@ const Container = styled.div`
`
const WorkflowList = ({
bookId,
config,
className,
currentValues,
update,
......@@ -31,10 +30,12 @@ const WorkflowList = ({
}) => {
if (!bookComponentStateRules) return null
const { stage } = bookComponentStateRules
let stageItems
if (config && config.bookBuilder && config.bookBuilder.stages) {
stageItems = config.bookBuilder.stages
}
const { config: stageItems } = find(config, {
context: 'bookBuilder',
area: 'stages',
})
const lastItem = last(stageItems).type
const getCurrentValue = (currentObjects, type) => {
const currentObject = find(currentObjects, ['type', type])
......@@ -47,8 +48,8 @@ const WorkflowList = ({
const progressOrder = []
for (let i = 0; i < config.bookBuilder.stages.length; i += 1) {
progressOrder.push(config.bookBuilder.stages[i].type)
for (let i = 0; i < stageItems.length; i += 1) {
progressOrder.push(stageItems[i].type)
}
const renderStateItem = (
......
import React from 'react'
import { find, indexOf } from 'lodash'
import config from 'config'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import withLink from 'editoria-common/src/withLink'
......
......@@ -20,6 +20,7 @@ const Connected = WrappedComponent => props => (
<Composed>
{({ loading, currentUser, config, client }) => {
if (loading) return 'Loading...'
return (
<WrappedComponent
client={client}
......
......@@ -5,8 +5,8 @@ import { Query } from 'react-apollo'
import gql from 'graphql-tag'
const APPLICATION_PARAMETER = gql`
query ApplicationParameter {
getApplicationParameters {
query ApplicationParameters($context: String, $area: String) {
getApplicationParameters(context: $context, area: $area) {
id
context
area
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment