2017-09-18 23:30:33 -04:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
import MetacodeSelect from '../MetacodeSelect'
|
2017-09-12 15:17:15 -04:00
|
|
|
|
|
|
|
class ContextMenu extends Component {
|
|
|
|
static propTypes = {
|
2017-09-18 23:30:33 -04:00
|
|
|
topicId: PropTypes.string,
|
|
|
|
contextNode: PropTypes.object,
|
|
|
|
contextEdge: PropTypes.object,
|
|
|
|
contextPos: PropTypes.object,
|
|
|
|
contextFetchingSiblingsData: PropTypes.bool,
|
|
|
|
contextSiblingsData: PropTypes.object,
|
|
|
|
metacodeSets: PropTypes.array,
|
|
|
|
contextReset: PropTypes.func,
|
|
|
|
contextDelete: PropTypes.func,
|
|
|
|
contextRemove: PropTypes.func,
|
|
|
|
contextHide: PropTypes.func,
|
|
|
|
contextCenterOn: PropTypes.func,
|
|
|
|
contextPopoutTopic: PropTypes.func,
|
|
|
|
contextUpdatePermissions: PropTypes.func,
|
|
|
|
contextOnMetacodeSelect: PropTypes.func,
|
|
|
|
contextFetchSiblings: PropTypes.func,
|
|
|
|
contextPopulateSiblings: PropTypes.func
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
populateSiblingsSent: false
|
|
|
|
}
|
2017-09-12 15:17:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-09-18 23:30:33 -04:00
|
|
|
const { contextNode, contextPos, contextOnMetacodeSelect, metacodeSets,
|
|
|
|
contextSiblingsData, contextFetchSiblings,
|
|
|
|
contextPopulateSiblings, contextFetchingSiblingsData,
|
|
|
|
topicId } = this.props
|
2017-09-12 15:17:15 -04:00
|
|
|
const style = {
|
|
|
|
position: 'absolute',
|
2017-09-18 23:30:33 -04:00
|
|
|
top: contextPos.y + 'px',
|
|
|
|
left: contextPos.x + 'px'
|
2017-09-12 15:17:15 -04:00
|
|
|
}
|
2017-09-18 23:30:33 -04:00
|
|
|
|
|
|
|
const populateSiblings = () => {
|
|
|
|
if (!this.state.populateSiblingsSent) {
|
|
|
|
contextPopulateSiblings(contextNode.id)
|
|
|
|
this.setState({populateSiblingsSent: true})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: add checks for logged in and other context
|
2017-09-12 15:17:15 -04:00
|
|
|
return <div className="rightclickmenu" style={style}>
|
|
|
|
<ul>
|
|
|
|
<li className="rc-hide">
|
2017-09-18 23:30:33 -04:00
|
|
|
<div className="rc-icon" />Hide until refresh
|
|
|
|
<div className="rc-keyboard">Ctrl+H</div>
|
2017-09-12 15:17:15 -04:00
|
|
|
</li>
|
|
|
|
<li className="rc-remove ">
|
2017-09-18 23:30:33 -04:00
|
|
|
<div className="rc-icon" />Remove from map
|
|
|
|
<div className="rc-keyboard">Ctrl+M</div>
|
2017-09-12 15:17:15 -04:00
|
|
|
</li>
|
|
|
|
<li className="rc-delete ">
|
2017-09-18 23:30:33 -04:00
|
|
|
<div className="rc-icon" />Delete
|
|
|
|
<div className="rc-keyboard">Ctrl+D</div>
|
2017-09-12 15:17:15 -04:00
|
|
|
</li>
|
|
|
|
<li className="rc-popout">
|
2017-09-18 23:30:33 -04:00
|
|
|
<div className="rc-icon" />Open in new tab
|
2017-09-12 15:17:15 -04:00
|
|
|
</li>
|
|
|
|
<li className="rc-spacer"></li>
|
|
|
|
<li className="rc-permission">
|
2017-09-18 23:30:33 -04:00
|
|
|
<div className="rc-icon" />Change permissions
|
2017-09-12 15:17:15 -04:00
|
|
|
<ul>
|
2017-09-18 23:30:33 -04:00
|
|
|
<li className="changeP toCommons">
|
|
|
|
<div className="rc-perm-icon" />commons
|
|
|
|
</li>
|
|
|
|
<li className="changeP toPublic">
|
|
|
|
<div className="rc-perm-icon" />public
|
|
|
|
</li>
|
|
|
|
<li className="changeP toPrivate">
|
|
|
|
<div className="rc-perm-icon" />private
|
|
|
|
</li>
|
2017-09-12 15:17:15 -04:00
|
|
|
</ul>
|
2017-09-18 23:30:33 -04:00
|
|
|
<div className="expandLi" />
|
2017-09-12 15:17:15 -04:00
|
|
|
</li>
|
|
|
|
<li className="rc-metacode">
|
2017-09-18 23:30:33 -04:00
|
|
|
<div className="rc-icon" />Change metacode
|
|
|
|
<div id="metacodeOptionsWrapper">
|
|
|
|
<MetacodeSelect onMetacodeSelect={contextOnMetacodeSelect}
|
|
|
|
metacodeSets={metacodeSets} />
|
|
|
|
</div>
|
|
|
|
<div className="expandLi" />
|
2017-09-12 15:17:15 -04:00
|
|
|
</li>
|
2017-09-18 23:30:33 -04:00
|
|
|
{contextNode && topicId && <li className="rc-siblings"
|
|
|
|
onMouseOver={populateSiblings}>
|
|
|
|
<div className="rc-icon" />Reveal siblings
|
|
|
|
<ul id="fetchSiblingList">
|
|
|
|
<li className="fetchAll"
|
|
|
|
onClick={() => contextFetchSiblings(contextNode)}>All
|
|
|
|
<div className="rc-keyboard">Alt+R</div>
|
|
|
|
</li>
|
|
|
|
{contextSiblingsData && Object.keys(contextSiblingsData).map(key => {
|
|
|
|
return <li key={key}
|
|
|
|
onClick={() => contextFetchSiblings(contextNode, key)}>
|
|
|
|
{contextSiblingsData[key]}
|
|
|
|
</li>
|
|
|
|
})}
|
|
|
|
{contextFetchingSiblingsData && <li id="loadingSiblings">loading</li>}
|
|
|
|
</ul>
|
|
|
|
<div className="expandLi" />
|
|
|
|
</li>}
|
2017-09-12 15:17:15 -04:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
// position the menu where the click happened
|
|
|
|
/*const position = {}
|
|
|
|
const RIGHTCLICK_WIDTH = 300
|
|
|
|
const RIGHTCLICK_HEIGHT = 144 // this does vary somewhat, but we can use static
|
|
|
|
const SUBMENUS_WIDTH = 256
|
|
|
|
const MAX_SUBMENU_HEIGHT = 270
|
|
|
|
const windowWidth = $(window).width()
|
|
|
|
const windowHeight = $(window).height()
|
|
|
|
|
|
|
|
if (windowWidth - e.clientX < SUBMENUS_WIDTH) {
|
|
|
|
position.right = windowWidth - e.clientX
|
|
|
|
$(rightclickmenu).addClass('moveMenusToLeft')
|
|
|
|
} else if (windowWidth - e.clientX < RIGHTCLICK_WIDTH) {
|
|
|
|
position.right = windowWidth - e.clientX
|
|
|
|
} else if (windowWidth - e.clientX < RIGHTCLICK_WIDTH + SUBMENUS_WIDTH) {
|
|
|
|
position.left = e.clientX
|
|
|
|
$(rightclickmenu).addClass('moveMenusToLeft')
|
|
|
|
} else {
|
|
|
|
position.left = e.clientX
|
|
|
|
}
|
|
|
|
|
|
|
|
if (windowHeight - e.clientY < MAX_SUBMENU_HEIGHT) {
|
|
|
|
position.bottom = windowHeight - e.clientY
|
|
|
|
$(rightclickmenu).addClass('moveMenusUp')
|
|
|
|
} else if (windowHeight - e.clientY < RIGHTCLICK_HEIGHT + MAX_SUBMENU_HEIGHT) {
|
|
|
|
position.top = e.clientY
|
|
|
|
$(rightclickmenu).addClass('moveMenusUp')
|
|
|
|
} else {
|
|
|
|
position.top = e.clientY
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ContextMenu
|