Skip to content

Commit

Permalink
Add UI support to load/list Bookmark url data
Browse files Browse the repository at this point in the history
  • Loading branch information
nneves committed Jan 17, 2018
1 parent a8e6edb commit 62e90a3
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 100 deletions.
3 changes: 0 additions & 3 deletions UI/src/src/AddLink/AddLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export default class AddLink extends Component {
this.state = {
value: '',
};

//this.handleChange = this.handleChange.bind(this);
//this.handleClick = this.handleClick.bind(this);
}

handleChange = (event) => {
Expand Down
5 changes: 0 additions & 5 deletions UI/src/src/AddLink/DocumentLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ const cardtitleStyle = {
};

export default class DocumentLink extends Component {
constructor(props) {
super(props);
this.state = {
};
}

getUrl = () => {
if (!this.props.data.hasOwnProperty("url")) {
Expand Down
10 changes: 4 additions & 6 deletions UI/src/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
//import PropTypes from 'prop-types';

import ApiUtils from './ApiUtils.js';
import { COUCHDB_SEARCHENGINE, COUCHDB_BOOKMARKENGINE } from './envvars.js';

import injectTapEventPlugin from 'react-tap-event-plugin';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
Expand All @@ -21,10 +22,6 @@ import CircularProgress from 'material-ui/CircularProgress';
// http://stackoverflow.com/a/34015469/988941
injectTapEventPlugin();

// https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables
const COUCHDB_SEARCHENGINE = process.env.REACT_APP_COUCHDB_SEARCHENGINE || "searchengine";
const COUCHDB_BOOKMARKENGINE = process.env.REACT_APP_COUCHDB_BOOKMARKENGINE || "bookmarkengine";

const styleCircularProgress = {
height: 24
};
Expand All @@ -43,6 +40,7 @@ export default class App extends Component {
offset: 0,
rows: []
},
manageBookmarkTableData: [],
visibleAddLink: false,
visibleUploadBookmark: false,
visibleManageBookmark: false,
Expand Down Expand Up @@ -193,8 +191,7 @@ export default class App extends Component {
if (response.hasOwnProperty("total_rows") === false) {
throw new Error(response);
}
this.showMessage(`Success: Found ${response.total_rows} Bookmarks`);
console.log(response);
//this.showMessage(`Success: Found ${response.total_rows} Bookmarks`);
this.setState({manageBookmarkData: response});
this.setState({idleStatus: true});
})
Expand Down Expand Up @@ -236,6 +233,7 @@ export default class App extends Component {

<UploadBookmark
visible={this.state.visibleUploadBookmark}
loadManageBookmark={this.loadManageBookmark}
/>
<ManageBookmark
visible={this.state.visibleManageBookmark}
Expand Down
12 changes: 9 additions & 3 deletions UI/src/src/Bookmarks/ManageBookmark.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { Component } from 'react';

import ManageBookmarkTable from './ManageBookmarkTable';

export default class ManageBookmark extends Component {
constructor(props) {
super(props);
Expand All @@ -15,10 +17,14 @@ export default class ManageBookmark extends Component {
render() {
return (
<div className={this.props.visible ? 'show' : 'hide'}>
<div className="px4 mx2 mt2 mb0">
<div className="px4 mx2 mt3 mb0">
{this.props.manageBookmarkData.rows.map((data) => {
console.log(data);
return (<div key={data.key}>ID={data.id}</div>);
return (
<ManageBookmarkTable
key={'manageBookmarkTable-'+data.key}
tableKey={data.key}
/>
);
})}
</div>
</div>
Expand Down
130 changes: 130 additions & 0 deletions UI/src/src/Bookmarks/ManageBookmarkTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import React, { Component } from 'react';

import { COUCHDB_BOOKMARKENGINE } from './../envvars.js';

import RaisedButton from 'material-ui/RaisedButton';
import {Toolbar, ToolbarGroup, ToolbarTitle} from 'material-ui/Toolbar';
import {
Table,
TableBody,
TableHeader,
TableHeaderColumn,
TableRow,
TableRowColumn,
} from 'material-ui/Table';

import Paper from 'material-ui/Paper';

const stylePaper = {
height: "100%",
width: "100%",
margin: 0,
textAlign: "left",
display: "inline-block",
marginLeft: "-1px",
};

const styleBtn = {
height: "100%",
width: "100%",
display: "inline-block",
};

export default class ManageBookmarkTable extends Component {
constructor(props) {
super(props);
this.state = {
data: []
};
}

loadManageBookmarkTable = () => {
const docKey = this.props.tableKey
const couchUrl = `/couchdb/${COUCHDB_BOOKMARKENGINE}/${docKey}`;
this.setState({idleStatus: false});

fetch(`${couchUrl}`, {
method: 'GET',
headers: {
'Accept': 'application/json',
}
})
.then((response) => response.json())
.then((response) => {
/*
if (response.hasOwnProperty("total_rows") === false) {
throw new Error(response);
}
*/
//console.log(response.bookmarkList);
this.setState({data: response.bookmarkList});
this.setState({idleStatus: true});
})
.catch((err) => {
console.log(err);
this.setState({idleStatus: true});
});
};

renderTable = () => {
const key = this.props.tableKey;
const data = this.state.data;
return data.length > 0 ? this.renderTableWithData(key, data) : this.renderTableEmpty(key)
}

renderTableEmpty = (key) => {
return (
<div key={'renderTbl-'+key} className="px4 mx2 mt2 mb0">
<RaisedButton label={"Load Bookmark: "+key} style={styleBtn} onClick={this.loadManageBookmarkTable} />
</div>
)
}

renderTableRown = (key, idx, elem) => {
return (
<TableRow key={'tbl-row-'+idx+'-'+key}>
<TableRowColumn key={'tbl-row-col1-'+idx+'-'+key}>{elem}</TableRowColumn>
</TableRow>
);
}

renderTableWithData = (key, data) => {
let tableRown = data.map((elem, idx) => {
return this.renderTableRown(key, idx, elem);
});

return (
<div key={'renderTbl-'+key} className="px4 mx2 mt2 mb0">
<Paper key={'paper-'+key} style={stylePaper} zDepth={2} rounded={false}>
<Toolbar>
<ToolbarGroup>
<ToolbarTitle text={key} />
</ToolbarGroup>
</Toolbar>
<Table key={'tbl-'+key} selectable={false} >
<TableHeader key={'tbl-hdr-'+key} displaySelectAll={false} adjustForCheckbox={false}>
<TableRow key={'tbl-hdr-row-'+key}>
<TableHeaderColumn key={'tbl-hdr-row-col-'+key}>URL</TableHeaderColumn>
</TableRow>
</TableHeader>
<TableBody key={'tbl-body-'+key} displayRowCheckbox={false}>
{ tableRown }
</TableBody>
</Table>
</Paper>
</div>
)
}

render() {
return (
<div key={'manageBookmarkTableInner-'+this.props.tableKey} className="px4 mx2 mt3 mb0">
{ this.renderTable() }
</div>
)
}
}

ManageBookmarkTable.propTypes = {
tableKey: React.PropTypes.string
};
102 changes: 49 additions & 53 deletions UI/src/src/Bookmarks/UploadBookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,72 @@ import Gallery from 'react-fine-uploader'

import 'react-fine-uploader/gallery/gallery.css'

const uploader = new FineUploaderTraditional({
options: {
autoUpload: true,
debug: false,
chunking: {
enabled: true,
concurrent: {
enabled: false
export default class UploadBookmark extends Component {

uploader = new FineUploaderTraditional({
options: {
autoUpload: true,
debug: false,
chunking: {
enabled: true,
concurrent: {
enabled: false
},
partSize: 200000, //200KB per chunk
success: {
endpoint: `/bookmarkchunkscompleted`
}
},
partSize: 200000, //200KB per chunk
success: {
endpoint: `/bookmarkchunkscompleted`
}
},
deleteFile: {
enabled: false,
},
forceMultipart: {
enabled: true
},
request: {
endpoint: `/bookmarkchunks`,
forceMultipart: true
},
retry: {
enableAuto: true
},
validation: { // validation for the images uploaded
allowedExtensions: ['html', 'csv', 'txt'],
sizeLimit: 20971520 // 20 MB = 20 * 1024 * 1024 bytes 20971520
},
callbacks: {
onComplete: (id, name, response) => {
// console.log(id, name, response);
deleteFile: {
enabled: false,
},
onStatusChange: (id, oldStatus, newStatus) => {
// console.log(id, oldStatus, newStatus);
forceMultipart: {
enabled: true
},
onUploadChunkSuccess: (id, chunkData, responseJSON, xhr) => {
// console.log(id, chunkData, responseJSON);
request: {
endpoint: `/bookmarkchunks`,
forceMultipart: true
},
onError: (id, name, errorReason, xhr) => {
// console.log(id, name, errorReason);
retry: {
enableAuto: true
},
onValidate: (name, buttonContainer) => {
// console.log(name, buttonContainer);
validation: { // validation for the images uploaded
allowedExtensions: ['html', 'csv', 'txt'],
sizeLimit: 20971520 // 20 MB = 20 * 1024 * 1024 bytes 20971520
},
callbacks: {
onComplete: (id, name, response) => {
// console.log(id, name, response);
this.props.loadManageBookmark();
},
onStatusChange: (id, oldStatus, newStatus) => {
// console.log(id, oldStatus, newStatus);
},
onUploadChunkSuccess: (id, chunkData, responseJSON, xhr) => {
// console.log(id, chunkData, responseJSON);
},
onError: (id, name, errorReason, xhr) => {
// console.log(id, name, errorReason);
},
onValidate: (name, buttonContainer) => {
// console.log(name, buttonContainer);
}
}
}
}
})

export default class UploadBookmark extends Component {
constructor(props) {
super(props);
this.state = {
};

}
});

render() {
return (
<div className={this.props.visible ? 'show' : 'hide'}>
<div className="px4 mx2 mt2 mb0">
<Gallery uploader={ uploader } />
<Gallery uploader={ this.uploader } />
</div>
</div>
)
}
}

UploadBookmark.propTypes = {
visible: React.PropTypes.bool
visible: React.PropTypes.bool,
loadManageBookmark: React.PropTypes.func,
};
17 changes: 4 additions & 13 deletions UI/src/src/Cards/Carditem.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,22 @@ const cardtitleStyle = {

export default class Carditem extends Component {

constructor(props) {
super(props);

this.trimContent = this.trimContent.bind(this);
this.getImageBase64 = this.getImageBase64.bind(this);
this.getUrl = this.getUrl.bind(this);
this.handleTouchTap = this.handleTouchTap.bind(this);
}

trimContent() {
trimContent = () => {
return (this.props.content.substring(0,100)+"...");
}

getImageBase64() {
getImageBase64 = () => {
return (this.props.image);
}

getUrl() {
getUrl = () => {
var url = this.props.url;
if (url.toLowerCase().indexOf("http") === -1)
url = "http://" + url;
return (url);
}

handleTouchTap(event) {
handleTouchTap = (event) => {
this.props.removeSubmit(this.props.id);
}

Expand Down
Loading

0 comments on commit 62e90a3

Please sign in to comment.