/*
Usage:
<%= react_component("PageLookupSidebar", {document_id: @document.id}) %>
*/
import React from "react"
import PropTypes from "prop-types"
import Drawer from '@material-ui/core/Drawer';
import List from '@material-ui/core/List';
import Divider from '@material-ui/core/Divider';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import ListSubheader from '@material-ui/core/ListSubheader';
import Chip from '@material-ui/core/Chip';
import SimpleFormat from './SimpleFormat.js';
import ExpandLess from '@material-ui/icons/ExpandLess';
import ExpandMore from '@material-ui/icons/ExpandMore';
import Collapse from '@material-ui/core/Collapse';
var pluralize = require('pluralize');
import axios from 'axios';
class PageLookupSidebar extends React.Component {
constructor(props) {
super(props);
this.state = {
open: false,
loading: false,
show_data: false,
category_open: {}
};
}
classIcon(class_name) {
return window.ContentTypeData[class_name].icon;
}
classColor(class_name) {
return window.ContentTypeData[class_name].color;
}
async loadPage(page_type, page_id) {
this.setDrawerVisible(true);
this.setState({
show_data: false,
category_open: {}
});
// make api request
await axios.get(
"/api/v1/" + page_type.toLowerCase() + "/" + page_id
+ '?application_token=4756de490e82956dc6329e6650aaec664e27ccd27e153e2f'
+ '&authorization_token=167bb93139303904cf67f6480a29e71c9f1eaf7a28e902e1',
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
}
).then(response => {
// load response into list
this.setState({
page_data: response.data,
show_data: !response.data.hasOwnProperty('error'),
page_type: page_type,
page_id: page_id
});
}).catch(err => {
console.log(err);
this.setDrawerVisible(false);
return null;
});
};
content_page_view_path(content_type, content_id) {
return '/plan/' + pluralize(content_type.toLowerCase()) + '/' + content_id;
};
content_page_edit_path(content_type, content_id) {
return '/plan/' + pluralize(content_type.toLowerCase()) + '/' + content_id + '/edit';
};
content_page_tag_path(content_type, tag_slug) {
return '/plan/' + pluralize(content_type.toLowerCase()) + '/tagged/' + tag_slug;
}
link_destroy_path(document_id, page_type, page_id) {
return '/documents/' + document_id + '/unlink/' + page_type + '/' + page_id;
}
setDrawerVisible(open) {
this.setState({ open: open });
};
toggleCategoryOpen(category) {
this.setState({ category_open: {
[category]: !this.state.category_open[category]
}});
};
fieldData(field) {
switch (field.type) {
case "name":
case "text_area":
// console.log(field.value);
return (