Skip to content
Snippets Groups Projects
Commit 25259a7f authored by Yannis Barlas's avatar Yannis Barlas
Browse files

add roles and username to track changes node

parent 5abb0831
No related branches found
No related tags found
No related merge requests found
...@@ -183,7 +183,8 @@ class Editor extends ProseEditor { ...@@ -183,7 +183,8 @@ class Editor extends ProseEditor {
commandManager: this.commandManager, commandManager: this.commandManager,
containerId: this.props.containerId, containerId: this.props.containerId,
documentSession: this.documentSession, documentSession: this.documentSession,
surfaceManager: this.surfaceManager surfaceManager: this.surfaceManager,
user: this.props.user
}) })
// attach all to context // attach all to context
......
import { get, find } from 'lodash' import { get, filter, find, forEach, union } from 'lodash'
import React from 'react' import React from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
...@@ -36,6 +36,8 @@ export class SimpleEditorWrapper extends React.Component { ...@@ -36,6 +36,8 @@ export class SimpleEditorWrapper extends React.Component {
} }
componentDidMount () { componentDidMount () {
const { user } = this.props
user.roles = this.getRoles()
window.addEventListener('beforeunload', this._releaseLock) window.addEventListener('beforeunload', this._releaseLock)
} }
...@@ -107,8 +109,41 @@ export class SimpleEditorWrapper extends React.Component { ...@@ -107,8 +109,41 @@ export class SimpleEditorWrapper extends React.Component {
updateFragment(book, newChapter) updateFragment(book, newChapter)
} }
getRoles () {
const { user, book } = this.props
const teams = filter(user.teams, function (t) {
return t.object.id === book.id
})
let roles = []
if (user.admin) roles.push('admin')
function addRole (role) {
roles = union(roles, [role])
}
forEach(teams, function (t) {
switch (t.teamType.name) {
case 'Production Editor':
addRole('production-editor')
break
case 'Copy Editor':
addRole('copy-editor')
break
case 'Author':
addRole('author')
break
}
})
return roles
}
render () { render () {
const { book, fragment, history, user } = this.props const { book, fragment, history, user } = this.props
// user.roles = user.getRoles()
console.log(fragment, user)
// TODO -- merge update and updateComments // TODO -- merge update and updateComments
return ( return (
......
...@@ -3,7 +3,11 @@ import { PropertyAnnotation } from 'substance' ...@@ -3,7 +3,11 @@ import { PropertyAnnotation } from 'substance'
class TrackChange extends PropertyAnnotation {} class TrackChange extends PropertyAnnotation {}
TrackChange.define({ TrackChange.define({
status: { type: 'string' } status: { type: 'string' },
user: {
roles: 'array',
username: 'string'
}
}) })
TrackChange.type = 'track-change' TrackChange.type = 'track-change'
......
...@@ -2,23 +2,25 @@ import { AnnotationComponent, createAnnotation, deleteNode } from 'substance' ...@@ -2,23 +2,25 @@ import { AnnotationComponent, createAnnotation, deleteNode } from 'substance'
class TrackChangeComponent extends AnnotationComponent { class TrackChangeComponent extends AnnotationComponent {
render ($$) { render ($$) {
const user = this.context.controller.props.user // const user = this.context.controller.props.user
const status = this.props.node.status const status = this.props.node.status
const trackChangesView = this.toggleTrackChangeView() const trackChangesView = this.toggleTrackChangeView()
let hideDeletes = '' let hideDeletes = ''
let ShowAdditions = '' let showAdditions = ''
if (trackChangesView === false && status === 'delete') { if (trackChangesView === false && status === 'delete') {
hideDeletes = 'sc-track-delete-hide' hideDeletes = 'sc-track-delete-hide'
} }
if (trackChangesView === false && status === 'add') { if (trackChangesView === false && status === 'add') {
ShowAdditions = 'sc-track-add-show' showAdditions = 'sc-track-add-show'
} }
const accept = $$('a').addClass('sc-track-item') const accept = $$('a')
.on('click', this.acceptTrackChange) .addClass('sc-track-item')
.append('accept') .on('click', this.acceptTrackChange)
.append('accept')
const reject = $$('a').addClass('sc-track-item') const reject = $$('a').addClass('sc-track-item')
.on('click', this.rejectTrackChange) .on('click', this.rejectTrackChange)
.append('reject') .append('reject')
...@@ -30,12 +32,12 @@ class TrackChangeComponent extends AnnotationComponent { ...@@ -30,12 +32,12 @@ class TrackChangeComponent extends AnnotationComponent {
.append(reject) .append(reject)
let el = $$('span') let el = $$('span')
.attr('data-id', this.props.node.id) // .attr('data-id', this.props.node.id)
.attr('data-user', user.username) // .attr('data-user', user.username)
.attr('data-role', user.teams[0].name) // .attr('data-role', user.teams[0].name)
.addClass(this.getClassNames()) .addClass(this.getClassNames())
.addClass(hideDeletes) .addClass(hideDeletes)
.addClass(ShowAdditions) .addClass(showAdditions)
.append(this.props.children) .append(this.props.children)
.append(container) .append(container)
...@@ -57,6 +59,7 @@ class TrackChangeComponent extends AnnotationComponent { ...@@ -57,6 +59,7 @@ class TrackChangeComponent extends AnnotationComponent {
const self = this const self = this
const surface = self.getSurface() const surface = self.getSurface()
if (!surface) return
return surface._owner.state.trackChangesView return surface._owner.state.trackChangesView
} }
......
...@@ -4,10 +4,18 @@ export default { ...@@ -4,10 +4,18 @@ export default {
import: function (element, node, converter) { import: function (element, node, converter) {
node.status = element.attr('status') node.status = element.attr('status')
node.user = {
// roles: element.attr('roles').split(','),
user: element.attr('username')
}
}, },
export: function (node, element, converter) { export: function (node, element, converter) {
const status = node.status const { status, user } = node
element.setAttribute('status', status) element.setAttribute('status', status)
element.setAttribute('role', user.roles.join(','))
element.setAttribute('username', user.username)
} }
} }
...@@ -328,6 +328,7 @@ class TrackChangesProvider { ...@@ -328,6 +328,7 @@ class TrackChangesProvider {
createTrackAnnotation (selection, status) { createTrackAnnotation (selection, status) {
const surface = this.getSurface() const surface = this.getSurface()
const info = this.getInfo() const info = this.getInfo()
const { user } = this.config
if (selection.isContainerSelection()) { if (selection.isContainerSelection()) {
return console.warn('Cannot delete a container') return console.warn('Cannot delete a container')
...@@ -338,7 +339,8 @@ class TrackChangesProvider { ...@@ -338,7 +339,8 @@ class TrackChangesProvider {
selection: selection, selection: selection,
node: { node: {
status: status, status: status,
type: 'track-change' type: 'track-change',
user: user
} }
} }
createAnnotation(tx, newNode) createAnnotation(tx, newNode)
......
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