79 lines
2.3 KiB
JavaScript
79 lines
2.3 KiB
JavaScript
import PouchDB from 'pouchdb';
|
|
import { connect } from 'react-redux'
|
|
|
|
function PDB(){
|
|
const projectsDB = new PouchDB("projectDocs");
|
|
const wbsDB = new PouchDB("wbsDocs");
|
|
const tasksDB = new PouchDB("taskDocs");
|
|
|
|
const remoteDB = new PouchDB('http://192.168.0.234:5984/ditswbs');
|
|
projectsDB.sync(remoteDB, { live: true, retry: true });
|
|
tasksDB.sync(remoteDB, { live: true, retry: true });
|
|
wbsDB.sync(remoteDB, { live: true, retry: true });
|
|
|
|
function GetDoc(docID) {
|
|
return new Promise((resolve, reject)=> {
|
|
projectsDB.get(docID)
|
|
.then((result)=> {return resolve(result)})
|
|
.catch((err)=> {
|
|
if (err.status === 404) {
|
|
console.log('error 404')
|
|
return resolve(null)
|
|
} else {
|
|
console.log('other:', err)
|
|
return reject(err)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
//function commitProjects() {
|
|
// db.put(
|
|
// projects: props.projects,
|
|
// )
|
|
// }
|
|
|
|
// function commitWBS() {
|
|
// evaluate parent child relation based on IDs
|
|
// and determine WBS level of each task in selected project
|
|
// this is dictionary where WBS level against project ID
|
|
// reorder the dictionary
|
|
// put the dictionary in local pouchdb
|
|
// db.put(
|
|
// projects: props.projects,
|
|
// )
|
|
// }
|
|
|
|
// function commitTasks(Tasks) {
|
|
// first check if a project is selected. This is a requirement before tasks can be
|
|
// commmitted
|
|
// if (!props.selectedProjectId) {
|
|
// commit tasks for selected projectID equals to one of the entries in task parentID
|
|
// Step1 verify if current input list of tasks have selected selected projectID as
|
|
// parentCount = 0
|
|
// const parents = Tasks.parentId
|
|
// parents.map ( parent => {if ( parent seletecProjectId eq ) {
|
|
// parentCount = parentCount+1 }}
|
|
//
|
|
// parent. If one or more do not have selected tasks fail the check return their
|
|
// with the a descriptive error message.
|
|
//...
|
|
// Step2
|
|
// This step is nested in step 1. If initial check is successful then commit inputed
|
|
// if (parents.length = parentCount ) {
|
|
// ... commit code}
|
|
// exit with error
|
|
// }
|
|
// }
|
|
|
|
}
|
|
|
|
export default connect(mapStateToProps)(PDB);
|
|
|
|
function mapStateToProps(state) {
|
|
return {
|
|
tasks: state.tasksReducer.tasks,
|
|
projects: state.projectsReducer.projects,
|
|
selectedProjectId: state.projectsReducer.selectedProjectId,
|
|
};
|
|
} |