Added mappings and routes for tags
This commit is contained in:
parent
cec930966c
commit
6d6efea4d4
|
@ -199,6 +199,39 @@ def delete_note(id):
|
||||||
es_delete_document('note', id)
|
es_delete_document('note', id)
|
||||||
return jsonify(es_document_list('note'))
|
return jsonify(es_document_list('note'))
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tag API Routes
|
||||||
|
#
|
||||||
|
|
||||||
|
''' Get all tags '''
|
||||||
|
@api.route('/tags/')
|
||||||
|
def get_tags():
|
||||||
|
return jsonify(es_document_list('tag'))
|
||||||
|
|
||||||
|
''' Get specific chapter '''
|
||||||
|
@api.route('/tags/<string:id>')
|
||||||
|
def get_tag(id):
|
||||||
|
data = es_get_document('tag', id)
|
||||||
|
return jsonify(data)
|
||||||
|
|
||||||
|
''' New chapter '''
|
||||||
|
@api.route('/tags/', methods=['PUT'])
|
||||||
|
def create_tag():
|
||||||
|
es_create_document('tag', request.data)
|
||||||
|
return jsonify(es_document_list('tag'))
|
||||||
|
|
||||||
|
''' Write chapter '''
|
||||||
|
@api.route('/tags/<string:id>', methods=['POST'])
|
||||||
|
def write_tag(id):
|
||||||
|
es_index_document('tag', id, request.data)
|
||||||
|
return jsonify(es_document_list('tag'))
|
||||||
|
|
||||||
|
''' Delete chapter '''
|
||||||
|
@api.route('/tags/<string:id>', methods=['DELETE'])
|
||||||
|
def delete_tag(id):
|
||||||
|
es_delete_document('tag', id)
|
||||||
|
return jsonify(es_document_list('tag'))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Search API Routes
|
# Search API Routes
|
||||||
#
|
#
|
||||||
|
|
9
setup.py
9
setup.py
|
@ -52,7 +52,14 @@ create_index_settings = {
|
||||||
'html_source': {'type': 'text', 'analyzer': 'html_analyzer'},
|
'html_source': {'type': 'text', 'analyzer': 'html_analyzer'},
|
||||||
'plain_text': {'type': 'text'}
|
'plain_text': {'type': 'text'}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
'note': {
|
||||||
|
'properties': {
|
||||||
|
'title': {'type': 'keyword'},
|
||||||
|
'html_source': {'type': 'text', 'analyzer': 'html_analyzer'},
|
||||||
|
'plain_text': {'type': 'text'}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,6 @@ export const DocTypeDropdown = ({docType, setDocType}) =>
|
||||||
<div className='dropdown-menu'>
|
<div className='dropdown-menu'>
|
||||||
<a className='dropdown-item' onClick={()=>setDocType('chapters')}>Chapters</a>
|
<a className='dropdown-item' onClick={()=>setDocType('chapters')}>Chapters</a>
|
||||||
<a className='dropdown-item' onClick={()=>setDocType('notes')}>Notes</a>
|
<a className='dropdown-item' onClick={()=>setDocType('notes')}>Notes</a>
|
||||||
|
<a className='dropdown-item' onClick={()=>setDocType('tags')}>Tags</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -40,7 +40,7 @@ const EditorContent = ({currentDocument, editorState, mode, handleKeyCommand, on
|
||||||
<Editor editorState={editorState} onChange={onChangeEditorState} keyBindingFn={annotateKeyBindings} />
|
<Editor editorState={editorState} onChange={onChangeEditorState} keyBindingFn={annotateKeyBindings} />
|
||||||
}
|
}
|
||||||
{mode === 'EDIT_MODE' &&
|
{mode === 'EDIT_MODE' &&
|
||||||
<Editor editorState={editorState} handleKeyCommand={handleKeyCommand} onChange={onChangeEditorState} />
|
<Editor editorState={editorState} handleKeyCommand={handleKeyCommand} onChange={onChangeEditorState}/>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div id='editor_bottombar'>
|
<div id='editor_bottombar'>
|
||||||
|
|
|
@ -40,13 +40,17 @@ ReactDOM.render(
|
||||||
}/>
|
}/>
|
||||||
<Route exact path='/edit/notes' render={() =>
|
<Route exact path='/edit/notes' render={() =>
|
||||||
<Redirect to={'/edit/notes/:id'}/>
|
<Redirect to={'/edit/notes/:id'}/>
|
||||||
}/>
|
}/>
|
||||||
|
<Route exact path='/edit/tags' render={() =>
|
||||||
|
<Redirect to={'/edit/tags/:id'}/>
|
||||||
|
}/>
|
||||||
<Route exact path='/notes' render={() =>
|
<Route exact path='/notes' render={() =>
|
||||||
<Redirect to={'/notes/:id'}/>
|
<Redirect to={'/notes/:id'}/>
|
||||||
}/>
|
}/>
|
||||||
<Route exact path='/notes/:id' component={ReaderPageContainer} />
|
<Route exact path='/notes/:id' component={ReaderPageContainer} />
|
||||||
<Route exact path='/edit/:id' component={EditorPageContainer} />
|
<Route exact path='/edit/:id' component={EditorPageContainer} />
|
||||||
<Route exact path='/edit/notes/:id' component={EditorPageContainer} />
|
<Route exact path='/edit/notes/:id' component={EditorPageContainer} />
|
||||||
|
<Route exact path='/edit/tags/:id' component={EditorPageContainer} />
|
||||||
<Route exact path='/search/' component={SearchPageContainer} />
|
<Route exact path='/search/' component={SearchPageContainer} />
|
||||||
<Route exact path='/:id' component={ReaderPageContainer} />
|
<Route exact path='/:id' component={ReaderPageContainer} />
|
||||||
</Switch>
|
</Switch>
|
||||||
|
|
|
@ -6,13 +6,16 @@ import regex from '../modules/regex'
|
||||||
|
|
||||||
const joyceRouter = store => next => action => {
|
const joyceRouter = store => next => action => {
|
||||||
next(action)
|
next(action)
|
||||||
|
// State
|
||||||
|
const chapters = store.getState().chapters
|
||||||
|
const notes = store.getState().notes
|
||||||
|
const tags = store.getState().tags
|
||||||
|
const currentDocument = store.getState().currentDocument
|
||||||
|
const docType = store.getState().docType
|
||||||
|
// Path
|
||||||
const path = store.getState().routerReducer.location !== null ? store.getState().routerReducer.location.pathname : '/'
|
const path = store.getState().routerReducer.location !== null ? store.getState().routerReducer.location.pathname : '/'
|
||||||
const pathID = regex.checkPathForID(path) ? regex.parseIDFromPath(path) : undefined
|
const pathID = regex.checkPathForID(path) ? regex.parseIDFromPath(path) : undefined
|
||||||
const pathNumber = regex.checkPathForNumber(path) ? regex.parseNumberFromPath(path) : undefined
|
const pathNumber = regex.checkPathForNumber(path) ? regex.parseNumberFromPath(path) : undefined
|
||||||
const docType = store.getState().docType
|
|
||||||
const currentDocument = store.getState().currentDocument
|
|
||||||
const chapters = store.getState().chapters
|
|
||||||
const notes = store.getState().notes
|
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case '@@router/LOCATION_CHANGE':
|
case '@@router/LOCATION_CHANGE':
|
||||||
if (regex.checkIfRedirectPath(path) && currentDocument.hasOwnProperty('id')) {
|
if (regex.checkIfRedirectPath(path) && currentDocument.hasOwnProperty('id')) {
|
||||||
|
@ -24,12 +27,18 @@ const joyceRouter = store => next => action => {
|
||||||
if (regex.checkNoteEditorRoute(path) && regex.checkIfRedirectPath(path) && notes.length > 0) {
|
if (regex.checkNoteEditorRoute(path) && regex.checkIfRedirectPath(path) && notes.length > 0) {
|
||||||
store.dispatch(actions.setCurrentDocument(notes[0].id, 'notes'))
|
store.dispatch(actions.setCurrentDocument(notes[0].id, 'notes'))
|
||||||
}
|
}
|
||||||
|
if (regex.checkTagEditorRoute(path) && regex.checkIfRedirectPath(path) && tags.length > 0) {
|
||||||
|
store.dispatch(actions.setCurrentDocument(tags[0].id, 'tags'))
|
||||||
|
}
|
||||||
if (regex.checkChapterEditorRoute(path) && regex.checkIfRedirectPath(path) && chapters.length > 0) {
|
if (regex.checkChapterEditorRoute(path) && regex.checkIfRedirectPath(path) && chapters.length > 0) {
|
||||||
store.dispatch(actions.setCurrentDocument(chapters[0].id, 'chapters'))
|
store.dispatch(actions.setCurrentDocument(chapters[0].id, 'chapters'))
|
||||||
}
|
}
|
||||||
if (regex.checkNoteReaderRoute(path) || regex.checkNoteEditorRoute(path)) {
|
if (regex.checkNoteReaderRoute(path) || regex.checkNoteEditorRoute(path)) {
|
||||||
store.dispatch(actions.setDocType('notes'))
|
store.dispatch(actions.setDocType('notes'))
|
||||||
}
|
}
|
||||||
|
if (regex.checkTagEditorRoute(path)) {
|
||||||
|
store.dispatch(actions.setDocType('tags'))
|
||||||
|
}
|
||||||
if (regex.checkRootRedirectRoute(path) && chapters.length > 0) {
|
if (regex.checkRootRedirectRoute(path) && chapters.length > 0) {
|
||||||
store.dispatch(actions.setCurrentDocument(chapters[0].id, 'chapters'))
|
store.dispatch(actions.setCurrentDocument(chapters[0].id, 'chapters'))
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,9 @@ const regex = {
|
||||||
checkNoteEditorRoute: path => {
|
checkNoteEditorRoute: path => {
|
||||||
return regexCheckBaseFunction(path, /^\/edit\/notes\/([0-9a-zA-Z\-\_]{18,}|\:id)/)
|
return regexCheckBaseFunction(path, /^\/edit\/notes\/([0-9a-zA-Z\-\_]{18,}|\:id)/)
|
||||||
},
|
},
|
||||||
|
checkTagEditorRoute : path => {
|
||||||
|
return regexCheckBaseFunction(path, /^\/edit\/tags\/([0-9a-zA-Z\-\_]{18,}|\:id)/)
|
||||||
|
},
|
||||||
checkPathForNumber: path => {
|
checkPathForNumber: path => {
|
||||||
return regexCheckBaseFunction(path, /\/[0-9]{1,3}$/)
|
return regexCheckBaseFunction(path, /\/[0-9]{1,3}$/)
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
const tags = (state=[], action) => {
|
||||||
|
switch(action.type) {
|
||||||
|
case 'GET_DOCUMENT_LIST':
|
||||||
|
if (action.status === 'success' && action.docType === 'tags') {
|
||||||
|
return action.data
|
||||||
|
} else { return state }
|
||||||
|
case 'DELETE_DOCUMENT':
|
||||||
|
if (action.status === 'success' && action.docType === 'tags') {
|
||||||
|
return action.data
|
||||||
|
} else { return state }
|
||||||
|
case 'SAVE_DOCUMENT':
|
||||||
|
if (action.status === 'success' && action.docType === 'tags') {
|
||||||
|
return action.data
|
||||||
|
} else { return state }
|
||||||
|
default:
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default tags
|
|
@ -8,7 +8,8 @@
|
||||||
padding: 3% 8%;
|
padding: 3% 8%;
|
||||||
border: 1px solid $border_color;
|
border: 1px solid $border_color;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
|
cursor: default;
|
||||||
&.annotations a {
|
&.annotations a {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
animation-duration: 1s;
|
animation-duration: 1s;
|
||||||
|
|
|
@ -10,6 +10,16 @@
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
padding: 2% 5%;
|
padding: 2% 5%;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
|
// Expand top-level DraftJS components to focus on click
|
||||||
|
> div {
|
||||||
|
height: 100%;
|
||||||
|
> div {
|
||||||
|
height: 100%;
|
||||||
|
> div {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#editor_metadata {
|
#editor_metadata {
|
||||||
|
|
Loading…
Reference in New Issue