This repository has been archived by the owner on Feb 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented functionality for loading documents from store
- Documents can be loaded from the store and displayed in an area under the searcher and editor - Improved query functionality so that multi-word queries now work - General fixes and improvements to the message process including adding callback for when messages are saved that displays a message - Cleaned up the document store code by making some duplicate code into a function - Misc. changes and fixes - Assigned each document a UUID that is used to save them - Saved user-created documents to a persistant JSON file as well as to the Tantivy store - Updated frontend to match the new UUID field and added disabled buttons for editing/deleting documents
- Loading branch information
Showing
19 changed files
with
464 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
tantivy_index/ | ||
user_documents/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gource --start-date '2017-01-01' -s .4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gource -s .4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! Renders the selected document that is returned from the document store. | ||
|
||
import React from 'react'; | ||
import { connect } from 'dva'; | ||
import { Button } from 'antd'; | ||
var HtmlToReactParser = require('html-to-react').Parser; | ||
|
||
import { DocumentShape } from '../../utils/commands'; | ||
import gstyles from '../../static/css/globalStyle.css'; | ||
|
||
const DocViewer = ({dispatch, selectedDoc, editDocument}) => { | ||
let {title, body, tags} = selectedDoc; | ||
const htmlToReactParser = new HtmlToReactParser(); | ||
const RenderedBody = htmlToReactParser.parse('<div>' + body + '</div>'); | ||
|
||
return ( | ||
<div className='docViewer' className={gstyles.leftText}> | ||
<br /> | ||
<h1 className={gstyles.inlineH1} >{title}</h1> | ||
<Button disabled onClick={editDocument(dispatch)} type='primary'>Edit</Button> | ||
<Button type='danger' disabled>Delete</Button> | ||
<hr /> | ||
{RenderedBody} | ||
</div> | ||
); | ||
}; | ||
|
||
DocViewer.propTypes = { | ||
dispatch: React.PropTypes.func.isRequired, | ||
selectedDoc: React.PropTypes.shape(DocumentShape).isRequired, | ||
editDocument: React.PropTypes.func.isRequired, | ||
}; | ||
|
||
function mapProps(state) { | ||
return { | ||
selectedDoc: state.documents.returnedDoc, | ||
}; | ||
} | ||
|
||
export default connect(mapProps)(DocViewer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
//! Functions for interacting with the document storage engine. | ||
|
||
import { message } from 'antd'; | ||
|
||
const d = new Date(); | ||
|
||
export default { | ||
namespace: 'documents', | ||
|
||
state: { | ||
queryResults: [], // list of all document titles returned in response to a query | ||
docQueryCbs: [], // list of functions that are called with the list of matched titles every time a query response is received | ||
returnedDoc: { // the document returned from a query for a document | ||
title: 'Placeholder Document', | ||
body: 'Select a document to display by using the search box above. When you select one, it will be displayed here.', | ||
tags: [], | ||
creation_date: '' + d.getTime(), | ||
modification_date: '' + d.getTime(), | ||
id: "00000000-0000-0000-0000-000000000000", | ||
}, | ||
activeEditorId: 0, // the random numeric id of the active document CKEditor instance | ||
}, | ||
|
||
reducers: { | ||
/** | ||
* Registers a callback to be executed every time a new `DocQueryResponse` is received. | ||
*/ | ||
registerDocQueryReceiver (state, {cb}) { | ||
return {...state, | ||
docQueryCbs: [...state.docQueryCbs, cb] | ||
}; | ||
}, | ||
|
||
/** | ||
* Sets the ID of the active editor instance | ||
*/ | ||
setEditorId (state, {id}) { | ||
return {...state, | ||
activeEditorId: id, | ||
}; | ||
}, | ||
|
||
/** | ||
* Called when a doc query response is received from the spawner. Updates the stored list of matched titles and | ||
* executes all stored callbacks. | ||
*/ | ||
docQueryResponseReceived (state, {msg}) { | ||
let matchedDocs; | ||
if(msg.res.DocumentQueryResult) { | ||
matchedDocs = msg.res.DocumentQueryResult.results.map(o => JSON.parse(o).title); | ||
|
||
// execute all registered callbacks | ||
for(var i=0; i<state.docQueryCbs.length; i++) { | ||
state.docQueryCbs[i](matchedDocs); | ||
} | ||
|
||
return {...state, | ||
queryResults: matchedDocs, | ||
}; | ||
} else if(msg.res.Error) { | ||
message.error('Error while processing query: ' + msg.res.Error.status); | ||
} else { | ||
message.error('Unknown error occured while processing query: ' + JSON.stringify(msg)); | ||
} | ||
|
||
return {...state}; | ||
}, | ||
|
||
/** | ||
* Called when a response is received from a request to save a document. | ||
*/ | ||
documentStoreResponseReceived (state, {msg}) { | ||
if(msg.res == 'Ok') { | ||
message.success('Document successfully saved.'); | ||
} else if(msg.res.Error) { | ||
message.error('Error saving document: ' + msg.res.Error.status); | ||
} else { | ||
message.error('Unhandled error occured while tring to save document: ' + JSON.stringify(msg)); | ||
} | ||
|
||
return {...state}; | ||
}, | ||
|
||
/** | ||
* Called when the response of a request for a document is received. | ||
*/ | ||
documentRequestResultReceived (state, {msg}) { | ||
if(msg.res.Document) { | ||
return {...state, | ||
returnedDoc: msg.res.Document.doc, | ||
}; | ||
} else if(msg.res.Error) { | ||
message.error('Error while fetching document from store: ' + msg.res.Error.status); | ||
} else { | ||
message.error('Unexpected response received while fetching document from store: ' + JSON.stringify(msg)); | ||
} | ||
|
||
return {...state}; | ||
} | ||
}, | ||
|
||
effects: { | ||
/** | ||
* Sends a document query to the Tantivy-backed document store. Registers interest in responses with the UUID | ||
* of the sent query and handles the responses by updating the `queryResults` state. | ||
*/ | ||
*sendDocQuery ({query}, {call, put}) { | ||
let cmd = {QueryDocumentStore: {query: query}}; | ||
yield put({ | ||
type: 'platform_communication/sendCommandToInstance', | ||
cb_action: 'documents/docQueryResponseReceived', | ||
cmd: cmd, | ||
instance_name: 'Spawner', | ||
}); | ||
}, | ||
|
||
/** | ||
* Given the content of a CKEditor document, saves it in the document store | ||
*/ | ||
*saveDocument ({title, tags, body, id}, {call, put}) { | ||
let d = new Date(); | ||
let doc = {title: title, tags: tags, body: body, id: id, creation_date: d.getTime() + '', modification_date: d.getTime() + ''}; | ||
let cmd = {InsertIntoDocumentStore: {doc: JSON.stringify(doc)}}; | ||
|
||
yield put({ | ||
type: 'platform_communication/sendCommandToInstance', | ||
cb_action: 'documents/documentStoreResponseReceived', | ||
cmd: cmd, | ||
instance_name: 'Spawner', | ||
}); | ||
}, | ||
|
||
/** | ||
* Asks the document store to return the document with a certain title. | ||
*/ | ||
*requestDocument ({title}, {call, put}) { | ||
let cmd = {GetDocument: {title: title}}; | ||
|
||
yield put({ | ||
type: 'platform_communication/sendCommandToInstance', | ||
cb_action: 'documents/documentRequestResultReceived', | ||
cmd: cmd, | ||
instance_name: 'Spawner', | ||
}); | ||
} | ||
}, | ||
}; |
Oops, something went wrong.