Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
editoria
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yannis Barlas
editoria
Commits
df064f27
Commit
df064f27
authored
7 years ago
by
john
Browse files
Options
Downloads
Patches
Plain Diff
automate team creation and deletion for books
parent
8919b18b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/components/Dashboard/Dashboard.jsx
+94
-36
94 additions, 36 deletions
app/components/Dashboard/Dashboard.jsx
app/components/utils/config.js
+1
-0
1 addition, 0 deletions
app/components/utils/config.js
with
95 additions
and
36 deletions
app/components/Dashboard/Dashboard.jsx
+
94
−
36
View file @
df064f27
...
...
@@ -15,8 +15,10 @@ export class Dashboard extends React.Component {
super
(
props
)
this
.
createBook
=
this
.
createBook
.
bind
(
this
)
this
.
makeTeamsForBook
=
this
.
makeTeamsForBook
.
bind
(
this
)
this
.
createTeamsForBook
=
this
.
createTeamsForBook
.
bind
(
this
)
this
.
findBooksWithNoTeams
=
this
.
findBooksWithNoTeams
.
bind
(
this
)
this
.
removeBook
=
this
.
removeBook
.
bind
(
this
)
this
.
removeTeamsForBook
=
this
.
removeTeamsForBook
.
bind
(
this
)
this
.
toggleModal
=
this
.
toggleModal
.
bind
(
this
)
this
.
state
=
{
...
...
@@ -24,67 +26,123 @@ export class Dashboard extends React.Component {
}
}
componentWillMount
()
{
const
{
getTeams
}
=
this
.
props
.
actions
getTeams
()
}
/*
If a
book
has no teams, it is a new one
.
Make
the default teams for it automatically
.
Get
book
s and teams
.
Make
sure all books have teams associated with them
.
*/
componentDidUpdate
()
{
// console.log('did')
const
{
books
,
teams
}
=
this
.
props
each
(
books
,
book
=>
{
const
teamsForBook
=
filter
(
teams
,
t
=>
{
return
t
.
object
.
id
===
book
.
id
})
componentWillMount
()
{
const
{
actions
}
=
this
.
props
const
{
getCollections
,
getTeams
}
=
actions
if
(
isEmpty
(
teamsForBook
))
this
.
makeTeamsForBook
(
book
)
})
getCollections
().
then
(
()
=>
getTeams
()
).
then
(
()
=>
this
.
findBooksWithNoTeams
()
)
}
/*
Toggle showing 'add book' modal
*/
toggleModal
()
{
this
.
setState
({
showModal
:
!
this
.
state
.
showModal
})
}
/*
Create a new book with the given title.
Once you have the new book's db id, make the teams for it as well.
*/
createBook
(
newTitle
)
{
const
{
createCollection
}
=
this
.
props
.
actions
const
collection
=
{
const
book
=
{
title
:
newTitle
||
'
Untitled
'
}
createCollection
(
collection
)
createCollection
(
book
).
then
(
res
=>
{
const
createdBook
=
res
.
collection
this
.
createTeamsForBook
(
createdBook
)
})
}
removeBook
(
collection
)
{
/*
Remove the given book.
Also remove all teams associated with it.
*/
removeBook
(
book
)
{
const
{
deleteCollection
}
=
this
.
props
.
actions
deleteCollection
(
collection
)
deleteCollection
(
book
).
then
(
res
=>
{
this
.
removeTeamsForBook
(
book
)
})
}
makeTeamsForBook
(
book
)
{
/*
Find all books that have no teams associated with them.
If one is found, make the teams for it.
This will most likely only happen once:
# The first time the app is run, on the collection created by
# the command 'pubsweet setupdb'.
*/
// TODO -- refactor so that less operations run most of the time
findBooksWithNoTeams
()
{
const
{
books
,
teams
}
=
this
.
props
each
(
books
,
book
=>
{
const
teamsForBook
=
filter
(
teams
,
t
=>
{
return
t
.
object
.
id
===
book
.
id
})
if
(
isEmpty
(
teamsForBook
))
{
this
.
createTeamsForBook
(
book
)
}
})
}
/*
Create the teams found in the config file for the given book.
This should run either when a new book is created,
or when a book with no teams associated with it is found.
*/
createTeamsForBook
(
book
)
{
const
{
createTeam
}
=
this
.
props
.
actions
each
(
teamTypes
,
teamType
=>
{
// TODO -- Review the idea that the name needs to be plural for some teams
// const name = teamType.name === 'Production Editor' ? teamType.name : teamType.name + 's'
//
// const newTeam = {
// members: [],
// name: name,
// object: {
// id: book.id,
// type: 'collection'
// },
// teamType: teamType
// }
//
// createTeam(newTeam)
const
name
=
(
teamType
.
name
===
'
Production Editor
'
)
?
teamType
.
name
:
teamType
.
name
+
'
s
'
const
newTeam
=
{
members
:
[],
name
:
name
,
object
:
{
id
:
book
.
id
,
type
:
'
collection
'
},
teamType
:
teamType
}
createTeam
(
newTeam
)
})
}
/*
Delete all teams associated with the given book.
This should only run after a book is deleted.
*/
removeTeamsForBook
(
book
)
{
const
{
actions
,
teams
}
=
this
.
props
const
{
deleteTeam
}
=
actions
const
teamsToDelete
=
filter
(
teams
,
team
=>
{
return
team
.
object
.
id
===
book
.
id
})
each
(
teamsToDelete
,
team
=>
{
deleteTeam
(
team
)
})
}
...
...
This diff is collapsed.
Click to expand it.
app/components/utils/config.js
+
1
−
0
View file @
df064f27
/* global CONFIG */
const
teamTypes
=
CONFIG
.
authsome
.
teams
const
chapter
=
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment