implemented listing item page.
This commit is contained in:
@@ -4,11 +4,13 @@
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@types/jest": "24.0.11",
|
||||
"@types/lokijs": "^1.5.2",
|
||||
"@types/node": "11.13.8",
|
||||
"@types/rc-tree": "^1.11.3",
|
||||
"@types/react": "16.8.14",
|
||||
"@types/react-dom": "16.8.4",
|
||||
"@types/react-router-dom": "^4.3.1",
|
||||
"lokijs": "^1.5.6",
|
||||
"query-string": "^6.4.2",
|
||||
"rc-tree": "^2.0.0",
|
||||
"react": "^16.8.6",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
[{"id":3,"title":"Public","num_of_items":32,"children":[{"id":6,"title":"Pupil Colloquium","num_of_items":0,"children":[{"id":216,"title":"2007, Hamamatsu","num_of_items":48,"children":[]},{"id":7,"title":"2005, Bear Mountain","num_of_items":113,"children":[]},{"id":81,"title":"2003, Crete","num_of_items":123,"children":[]},{"id":8,"title":"2001, Asilomar","num_of_items":128,"children":[]},{"id":82,"title":"1999, Nottingham","num_of_items":96,"children":[]},{"id":217,"title":"1997, Point Clear","num_of_items":93,"children":[]}]}]}]
|
||||
[{"id":3,"title":"Public","num_of_items":32,"children":[{"id":6,"title":"Pupil Colloquium","num_of_items":0,"children":[{"id":216,"title":"2007, Hamamatsu","num_of_items":48,"children":[]},{"id":7,"title":"2005, Bear Mountain","num_of_items":28,"children":[]},{"id":81,"title":"2003, Crete","num_of_items":41,"children":[]},{"id":8,"title":"2001, Asilomar","num_of_items":32,"children":[]},{"id":82,"title":"1999, Nottingham","num_of_items":32,"children":[]},{"id":217,"title":"1997, Point Clear","num_of_items":31,"children":[]}]}]}]
|
||||
@@ -0,0 +1,6 @@
|
||||
.listIcon {
|
||||
vertical-align: middle !important;
|
||||
text-align: center;
|
||||
width: 65px;
|
||||
line-height: 0;
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { TreeNode } from 'rc-tree';
|
||||
import indexJson from '../assets/tree.json';
|
||||
import styles from './Index.module.css';
|
||||
|
||||
import iconFolder from '../assets/images/database/icon_folder.gif';
|
||||
|
||||
export interface IIndexJson {
|
||||
id: number;
|
||||
title: string;
|
||||
num_of_items: number;
|
||||
children: IIndexJson[];
|
||||
}
|
||||
|
||||
export interface IIndexBase {
|
||||
id: number;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export interface IIndex extends IIndexBase {
|
||||
num_of_indexes: number;
|
||||
num_of_items: number;
|
||||
}
|
||||
|
||||
export interface IIndexDetail extends IIndex {
|
||||
path: IIndexBase[];
|
||||
children: IIndex[];
|
||||
}
|
||||
|
||||
export const PUBCIC_INDEX_ID = 3;
|
||||
|
||||
const indexIdKeys: string[] = [];
|
||||
const loadChildren = (data: IIndexJson[]) => {
|
||||
return data.map((index: IIndexJson) => {
|
||||
let title: string = index.title;
|
||||
if (index.num_of_items > 0) {
|
||||
title += ' (' + index.num_of_items + ')';
|
||||
}
|
||||
if (index.children.length > 0) {
|
||||
indexIdKeys.push(String(index.id));
|
||||
return (
|
||||
<TreeNode key={index.id} title={title}>
|
||||
{loadChildren(index.children)}
|
||||
</TreeNode >
|
||||
);
|
||||
}
|
||||
return (<TreeNode key={index.id} title={title} />);
|
||||
});
|
||||
};
|
||||
const indexElement = loadChildren(indexJson);
|
||||
|
||||
class Index {
|
||||
|
||||
static getUrl(id: number): string {
|
||||
return '/database/list/' + String(id);
|
||||
}
|
||||
|
||||
static load() {
|
||||
return {
|
||||
keys: indexIdKeys,
|
||||
element: indexElement
|
||||
};
|
||||
}
|
||||
|
||||
static getDetail(indexId: number): IIndexDetail {
|
||||
let index: IIndexDetail = {
|
||||
id: indexId,
|
||||
title: '',
|
||||
num_of_indexes: 0,
|
||||
num_of_items: 0,
|
||||
path: [],
|
||||
children: []
|
||||
};
|
||||
let found: boolean = false;
|
||||
const loop = (data: IIndexJson[]) => {
|
||||
data.forEach((item: IIndexJson) => {
|
||||
if (found) {
|
||||
return;
|
||||
}
|
||||
const path: IIndexBase = {
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
}
|
||||
index.path.push(path);
|
||||
if (indexId === item.id) {
|
||||
index.id = item.id;
|
||||
index.title = item.title;
|
||||
index.num_of_indexes = item.children.length;
|
||||
index.num_of_items = item.num_of_items;
|
||||
found = true;
|
||||
item.children.forEach((item: IIndexJson) => {
|
||||
index.children.push({
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
num_of_indexes: item.children.length,
|
||||
num_of_items: item.num_of_items
|
||||
});
|
||||
});
|
||||
} else {
|
||||
loop(item.children);
|
||||
}
|
||||
if (found === false) {
|
||||
index.path.pop();
|
||||
}
|
||||
});
|
||||
};
|
||||
loop(indexJson);
|
||||
return index;
|
||||
}
|
||||
|
||||
static renderIndexPath(index: IIndexDetail): JSX.Element {
|
||||
let elements: JSX.Element[] = [];
|
||||
index.path.forEach((path: IIndexBase) => {
|
||||
const url: string = Index.getUrl(path.id);
|
||||
elements.push(<span key={path.id}>/ <Link to={url}>{path.title}</Link> </span>);
|
||||
});
|
||||
return <div>{elements}</div>;
|
||||
}
|
||||
|
||||
static renderList(index: IIndexDetail): JSX.Element {
|
||||
if (index.children.length === 0) {
|
||||
return (<></>);
|
||||
}
|
||||
let evenodd: string = 'even';
|
||||
const treeList = index.children.map((cindex: IIndex) => {
|
||||
evenodd = evenodd === 'even' ? 'odd' : 'even';
|
||||
return (
|
||||
<tr key={cindex.id}>
|
||||
<td className={evenodd}>{Index.renderListItem(cindex)}</td>
|
||||
</tr >
|
||||
);
|
||||
});
|
||||
return (
|
||||
<table className={styles.listTable}>
|
||||
<tbody>
|
||||
{treeList}
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
|
||||
static renderListItem(index: IIndex): JSX.Element {
|
||||
const url = Index.getUrl(index.id);
|
||||
return (
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className={styles.listIcon}>
|
||||
<Link to={url}><img alt={index.title} src={iconFolder} /></Link>
|
||||
</td>
|
||||
<td>
|
||||
<Link to={url}>{index.title}</Link>
|
||||
<br />
|
||||
{index.num_of_indexes} indexes / {index.num_of_items} items
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default Index;
|
||||
@@ -0,0 +1,11 @@
|
||||
.sortCriteria {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pageNavi {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.pageNaviItem {
|
||||
margin: 0 5px;
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import loki from 'lokijs';
|
||||
import qs from 'query-string';
|
||||
import styles from './Item.module.css';
|
||||
|
||||
import itemsJson from '../assets/items.json';
|
||||
|
||||
export interface ISortCondition {
|
||||
limit: number;
|
||||
page: number;
|
||||
orderby: string;
|
||||
order_dir: number;
|
||||
};
|
||||
|
||||
export const SORT_CONDITION_DEFAULT: ISortCondition = {
|
||||
limit: 20,
|
||||
page: 1,
|
||||
orderby: 'title',
|
||||
order_dir: 1
|
||||
};
|
||||
|
||||
const SORT_CONDITION_RANGE_ORDER_BY = ['title', 'doi', 'last_update_date', 'creation_date', 'publication_date'];
|
||||
const SORT_CONDITION_RANGE_ORDER_DIR = ['0', '1'];
|
||||
const SORT_CONDITION_RANGE_LIMIT = ['20', '50', '100'];
|
||||
|
||||
export interface IItemBasic {
|
||||
item_id: number;
|
||||
item_type_id: number;
|
||||
uid: number;
|
||||
description: string;
|
||||
doi: string;
|
||||
last_update_date: number;
|
||||
creation_date: number;
|
||||
publication_year: number;
|
||||
publication_month: number;
|
||||
publication_mday: number;
|
||||
lang: string;
|
||||
title: string;
|
||||
item_type_display_name: string;
|
||||
item_type_name: string;
|
||||
uname: string;
|
||||
name: string;
|
||||
item_url: string;
|
||||
index: {
|
||||
index_id: number;
|
||||
title: string;
|
||||
}[];
|
||||
changelog: {
|
||||
uid: number;
|
||||
log_date: number;
|
||||
log: string;
|
||||
}[];
|
||||
related_to: number[];
|
||||
keyword: string[];
|
||||
file: {
|
||||
file_id: number;
|
||||
original_file_name: string;
|
||||
mime_type: string;
|
||||
file_size: number;
|
||||
timestamp: string;
|
||||
display_name: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
const db = new loki('database');
|
||||
const items: Collection<any> = db.addCollection('items');
|
||||
itemsJson.forEach(item => items.insert(item));
|
||||
|
||||
class Item {
|
||||
|
||||
static getUrl(itemId: number, doi: string) {
|
||||
if (doi !== '') {
|
||||
return '/database/item/id/' + doi;
|
||||
}
|
||||
return '/database/item/' + String(itemId);
|
||||
}
|
||||
|
||||
static getListUrl(url: string, condition: ISortCondition, query: { orderby?: string, order_dir?: number, limit?: number, page?: number }): string {
|
||||
const newOrderby: string = typeof query.orderby !== 'undefined' ? query.orderby : condition.orderby;
|
||||
const newOrderDir: number = typeof query.order_dir !== 'undefined' ? query.order_dir : condition.order_dir;
|
||||
const newLimit: number = typeof query.limit !== 'undefined' ? query.limit : condition.limit;
|
||||
let newPage: number = typeof query.page !== 'undefined' ? query.page : condition.page;
|
||||
if (newLimit !== condition.limit) {
|
||||
newPage = SORT_CONDITION_DEFAULT.page;
|
||||
}
|
||||
let params: string[] = [];
|
||||
params.push('orderby=' + newOrderby);
|
||||
params.push('order_dir=' + String(newOrderDir));
|
||||
params.push('itemcount=' + String(newLimit));
|
||||
params.push('page=' + String(newPage));
|
||||
return (params.length > 0 ? url + '?' + params.join('&') : url);
|
||||
}
|
||||
|
||||
static getSortConditionByQuery(queryString: string): ISortCondition {
|
||||
const query = qs.parse(queryString);
|
||||
let condition = Object.assign({}, SORT_CONDITION_DEFAULT);
|
||||
if (typeof query.orderby === 'string' && SORT_CONDITION_RANGE_ORDER_BY.includes(query.orderby)) {
|
||||
condition.orderby = query.orderby;
|
||||
}
|
||||
if (typeof query.order_dir === 'string' && SORT_CONDITION_RANGE_ORDER_DIR.includes(query.order_dir)) {
|
||||
condition.order_dir = parseInt(query.order_dir, 10);
|
||||
}
|
||||
if (typeof query.itemcount === 'string' && SORT_CONDITION_RANGE_LIMIT.includes(query.itemcount)) {
|
||||
condition.limit = parseInt(query.itemcount, 10);
|
||||
}
|
||||
if (typeof query.page === 'string') {
|
||||
condition.page = parseInt(query.page, 10);
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
static get(itemId: number) {
|
||||
const filter = {
|
||||
'item_id': itemId
|
||||
}
|
||||
return items.findOne(filter);
|
||||
}
|
||||
|
||||
static getListByIndexId(indexId: number, sort: ISortCondition) {
|
||||
const filter = {
|
||||
'index.index_id': indexId
|
||||
}
|
||||
const offset = sort.limit * (sort.page - 1);
|
||||
const order_dir = sort.order_dir === 0;
|
||||
const result = items.chain().find(filter);
|
||||
return {
|
||||
total: result.count(),
|
||||
data: result.simplesort(sort.orderby, order_dir).offset(offset).limit(sort.limit).data()
|
||||
};
|
||||
}
|
||||
|
||||
static renderSortCriteria(baseUrl: string, total: number, condition: ISortCondition, onChangeOrderby: (event: React.ChangeEvent<HTMLSelectElement>) => void, onChangeItemcount: (event: React.ChangeEvent<HTMLSelectElement>) => void): JSX.Element {
|
||||
if (total === 0) {
|
||||
return (<></>);
|
||||
}
|
||||
let orderDir = <></>;
|
||||
if (condition.order_dir !== 0) {
|
||||
const url = Item.getListUrl(baseUrl, condition, { order_dir: 0 });
|
||||
orderDir = (<span>
|
||||
▼ <Link to={url}>▲</Link>
|
||||
</span>);
|
||||
} else {
|
||||
const url = Item.getListUrl(baseUrl, condition, { order_dir: 1 });
|
||||
orderDir = (<span>
|
||||
<Link to={url}>▼</Link> ▲
|
||||
</span>);
|
||||
}
|
||||
return (
|
||||
<div className={styles.sortCriteria}>
|
||||
<table className={styles.listTable}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="odd">
|
||||
Order by
|
||||
<select value={condition.orderby} onChange={onChangeOrderby}>
|
||||
<option value="title">Title</option>
|
||||
<option value="doi">ID</option>
|
||||
<option value="last_update_date">Last Modified Date</option>
|
||||
<option value="creation_date">Created Date</option>
|
||||
<option value="publication_date">Date</option>
|
||||
</select>
|
||||
{orderDir}
|
||||
</td>
|
||||
<td className="odd">
|
||||
No.Item per page
|
||||
<select value={condition.limit} onChange={onChangeItemcount}>
|
||||
<option value="20">20</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
static renderPageNavi(baseUrl: string, total: number, condition: ISortCondition): JSX.Element {
|
||||
if (total === 0) {
|
||||
return (<></>);
|
||||
}
|
||||
const maxPage = Math.floor(total / condition.limit) + 1;
|
||||
const link = (title: string, page: number, id: string) => {
|
||||
const key = 'nav' + id
|
||||
if (page === 0 || page === condition.page) {
|
||||
return (<span key={key} className={styles.pageNaviItem}>{title}</span>);
|
||||
}
|
||||
const url: string = Item.getListUrl(baseUrl, condition, { page: page });
|
||||
return (<Link key={key} className={styles.pageNaviItem} to={url}>{title}</Link>);
|
||||
}
|
||||
const startPage = (condition.page - 5) > 1 ? condition.page - 5 : 1;
|
||||
const endPage = (startPage + 5) > maxPage ? maxPage : startPage + 5;
|
||||
let pageLinks: JSX.Element[] = [];
|
||||
pageLinks.push(link('PREV', condition.page - 1, 'p'));
|
||||
for (let i = startPage; i <= endPage; i++) {
|
||||
pageLinks.push(link(String(i), i, String(i)));
|
||||
}
|
||||
pageLinks.push(link('NEXT', condition.page >= maxPage ? 0 : condition.page + 1, 'n'));
|
||||
return (
|
||||
<div className={styles.pageNavi}>
|
||||
{pageLinks}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
static renderNumOfItems(total: number, condition: ISortCondition): JSX.Element {
|
||||
if (total === 0) {
|
||||
return (<p>No items found.</p>);
|
||||
}
|
||||
let startNum: number = 1 + condition.limit * (condition.page - 1);
|
||||
let endNum: number = condition.limit * condition.page;
|
||||
if (startNum > total) {
|
||||
return (<p>Out of range.</p>);
|
||||
}
|
||||
if (endNum > total) {
|
||||
endNum = total;
|
||||
}
|
||||
return (
|
||||
<p>{startNum} - {endNum} of {total}</p>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Item;
|
||||
@@ -0,0 +1,66 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Item, { IItemBasic } from './Item';
|
||||
|
||||
import iconBook from '../assets/images/database/icon_book.gif';
|
||||
|
||||
interface IItemBook extends IItemBasic {
|
||||
book_id: number;
|
||||
classfication: string;
|
||||
editor: string;
|
||||
publisher: string;
|
||||
isbn: string;
|
||||
url: string;
|
||||
attachment_dl_limit: number;
|
||||
attachment_dl_notify: number;
|
||||
author: string[];
|
||||
};
|
||||
|
||||
class ItemBook {
|
||||
|
||||
static renderTop() {
|
||||
return (
|
||||
<td className="itemType">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconBook} alt="Book" />
|
||||
</td>
|
||||
<td className="itemTypeName">
|
||||
<Link to="/database/itemtype/book">Book</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
Related Book Collection.<br />
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
static renderList(item: IItemBook) {
|
||||
const url = Item.getUrl(item.item_id, item.doi);
|
||||
const authors = item.author.map((author, index) => {
|
||||
const padding = index > 0 ? ', ' : '';
|
||||
return (<span key={index}>{padding}{author}</span>);
|
||||
});
|
||||
return (
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="listIcon">
|
||||
<img src={iconBook} alt="Book" />
|
||||
</td>
|
||||
<td>
|
||||
<Link to={url}>{item.title}</Link><br />
|
||||
{authors}<br />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ItemBook;
|
||||
@@ -0,0 +1,86 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Item, { IItemBasic } from './Item';
|
||||
|
||||
import iconConference from '../assets/images/database/icon_conference.gif';
|
||||
|
||||
interface IItemConference extends IItemBasic {
|
||||
conference_id: number;
|
||||
presentation_type: 'powerpoint' | 'pdf' | 'illustrator' | 'other';
|
||||
conference_title: string;
|
||||
place: string;
|
||||
abstract: string;
|
||||
conference_from_year: number;
|
||||
conference_from_month: number;
|
||||
conference_from_mday: number;
|
||||
conference_to_year: number;
|
||||
conference_to_month: number;
|
||||
conference_to_mday: number;
|
||||
attachment_dl_limit: number;
|
||||
attachment_dl_notify: number;
|
||||
author: string[];
|
||||
};
|
||||
|
||||
class ItemConference {
|
||||
|
||||
static renderTop() {
|
||||
return (
|
||||
<td className="itemType">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconConference} alt="Conference" />
|
||||
</td>
|
||||
<td className="itemTypeName">
|
||||
<Link to="/database/itemtype/conference">Conference</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
Electrical presentation files for conference.<br />
|
||||
<Link to="/database/itemtype/conference/powerpoint">PowerPoint</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/conference/pdf">PDF</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/conference/illustrator">Illustrator</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/conference/other">Other</Link>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
static renderList(item: IItemConference) {
|
||||
const url = Item.getUrl(item.item_id, item.doi);
|
||||
const types = {
|
||||
powerpoint: 'PowerPoint',
|
||||
pdf: 'PDF',
|
||||
illustrator: 'Illustrator',
|
||||
other: 'Other'
|
||||
}
|
||||
const presentationType = '(' + types[item.presentation_type] + ')';
|
||||
const authors = item.author.map((author, index) => {
|
||||
const padding = index > 0 ? ', ' : '';
|
||||
return (<span key={index}>{padding}{author}</span>);
|
||||
});
|
||||
return (
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="listIcon">
|
||||
<img src={iconConference} alt="Conference" />
|
||||
</td>
|
||||
<td>
|
||||
<Link to={url}>{item.title}</Link><br />
|
||||
{item.conference_title} {presentationType} <br />
|
||||
{authors}<br />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ItemConference;
|
||||
@@ -0,0 +1,76 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Item, { IItemBasic } from './Item';
|
||||
|
||||
import iconData from '../assets/images/database/icon_data.gif';
|
||||
|
||||
interface IItemData extends IItemBasic {
|
||||
data_id: number;
|
||||
data_type: 'excel' | 'movie' | 'text' | 'picture' | 'ohter';
|
||||
rights: string;
|
||||
readme: string;
|
||||
use_cc: number;
|
||||
cc_commercial_use: number;
|
||||
cc_modification: number;
|
||||
attachment_dl_limit: number;
|
||||
attachment_dl_notify: number;
|
||||
experimenter: string[];
|
||||
};
|
||||
|
||||
class ItemData {
|
||||
|
||||
static renderTop() {
|
||||
return (
|
||||
<td className="itemType">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconData} alt="Data" />
|
||||
</td>
|
||||
<td className="itemTypeName">
|
||||
<Link to="/database/itemtype/data">Data</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
Result data in numerical text/image/movie formats.<br />
|
||||
<Link to="/database/itemtype/data/excel">Excel</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/data/movie">Movie</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/data/text">Text</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/data/picture">Picture</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/data/other">Other</Link>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
static renderList(item: IItemData) {
|
||||
const url = Item.getUrl(item.item_id, item.doi);
|
||||
const authors = item.experimenter.map((author, index) => {
|
||||
const padding = index > 0 ? ', ' : '';
|
||||
return (<span key={index}>{padding}{author}</span>);
|
||||
});
|
||||
return (
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="listIcon">
|
||||
<img src={iconData} alt="Data" />
|
||||
</td>
|
||||
<td>
|
||||
<Link to={url}>{item.title}</Link><br />
|
||||
{authors}<br />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ItemData;
|
||||
@@ -0,0 +1,80 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Item, { IItemBasic } from './Item';
|
||||
|
||||
import iconModel from '../assets/images/database/icon_model.gif';
|
||||
|
||||
interface IItemModel extends IItemBasic {
|
||||
model_id: number;
|
||||
model_type: 'matlab' | 'neuron' | 'original_program' | 'satellite' | 'genesis' | 'a_cell' | 'other';
|
||||
readme: string;
|
||||
rights: string;
|
||||
use_cc: number;
|
||||
cc_commercial_use: number;
|
||||
cc_modification: number;
|
||||
attachment_dl_limit: number;
|
||||
attachment_dl_notify: number;
|
||||
creator: string[];
|
||||
};
|
||||
|
||||
class ItemModel {
|
||||
|
||||
static renderTop() {
|
||||
return (
|
||||
<td className="itemType">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconModel} alt="Model" />
|
||||
</td>
|
||||
<td className="itemTypeName">
|
||||
<Link to="/database/itemtype/model">Model</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
Model programs/scripts.<br />
|
||||
<Link to="/database/itemtype/model/matlab">Matlab</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/neuron">Neuron</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/original_program">Original Program</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/satellite">Satellite</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/genesis">Genesis</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/a_cell">A-Cell</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/other">Other</Link>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
static renderList(item: IItemModel) {
|
||||
const url = Item.getUrl(item.item_id, item.doi);
|
||||
const authors = item.creator.map((author, index) => {
|
||||
const padding = index > 0 ? ', ' : '';
|
||||
return (<span key={index}>{padding}{author}</span>);
|
||||
});
|
||||
return (
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="listIcon">
|
||||
<img src={iconModel} alt="Model" />
|
||||
</td>
|
||||
<td>
|
||||
<Link to={url}>{item.title}</Link><br />
|
||||
{authors}<br />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ItemModel;
|
||||
@@ -0,0 +1,73 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Item, { IItemBasic } from './Item';
|
||||
|
||||
import iconPaper from '../assets/images/database/icon_paper.gif';
|
||||
|
||||
interface IItemPaper extends IItemBasic {
|
||||
paper_id: number;
|
||||
journal: string;
|
||||
volume: number;
|
||||
number: number | null;
|
||||
page: string;
|
||||
abstract: string;
|
||||
pubmed_id: string;
|
||||
author: string[];
|
||||
};
|
||||
|
||||
class ItemPaper {
|
||||
|
||||
static renderTop() {
|
||||
return (
|
||||
<td className="itemType">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconPaper} alt="Paper" />
|
||||
</td>
|
||||
<td className="itemTypeName">
|
||||
<Link to="/database/itemtype/paper">Paper</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
Related paper collection.
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
static renderList(item: IItemPaper) {
|
||||
const url = Item.getUrl(item.item_id, item.doi);
|
||||
const authors = item.author.map((author, index) => {
|
||||
const padding = index > 0 ? ', ' : '';
|
||||
return (<span key={index}>{padding}{author}</span>);
|
||||
});
|
||||
const pubYear = String(item.publication_year);
|
||||
const volume = item.volume === null ? '' : ';' + String(item.volume);
|
||||
const number = item.number === null ? '' : '(' + String(item.number) + ')';
|
||||
const page = item.page === '' ? '' : ':' + item.page;
|
||||
const pubmedUrl = 'https://www.ncbi.nlm.nih.gov/pubmed/' + item.pubmed_id;
|
||||
const pubmedLink = (<a href={pubmedUrl} target="_blank" rel="noopener noreferrer">{item.pubmed_id}</a>);
|
||||
const pubmed = item.pubmed_id === '' ? <></> : <span>[PMID: {pubmedLink}]</span>;
|
||||
return (
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="listIcon">
|
||||
<img src={iconPaper} alt="Paper" />
|
||||
</td>
|
||||
<td>
|
||||
<Link to={url}>{item.title}</Link><br />
|
||||
{authors}<br />
|
||||
{item.journal} {pubYear} {volume} {number} {page} {pubmed}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ItemPaper;
|
||||
@@ -0,0 +1,56 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Item, { IItemBasic } from './Item';
|
||||
|
||||
import iconUrl from '../assets/images/database/icon_url.gif';
|
||||
|
||||
interface IItemUrl extends IItemBasic {
|
||||
url_id: number;
|
||||
url: string;
|
||||
url_count: number;
|
||||
};
|
||||
|
||||
class ItemUrl {
|
||||
|
||||
static renderTop() {
|
||||
return (
|
||||
<td className="itemType">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconUrl} alt="Url" />
|
||||
</td>
|
||||
<td className="itemTypeName">
|
||||
<Link to="/database/itemtype/url">Url</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
Link information.
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
static renderList(item: IItemUrl) {
|
||||
const url = Item.getUrl(item.item_id, item.doi);
|
||||
return (
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="listIcon">
|
||||
<img src={iconUrl} alt="Url" />
|
||||
</td>
|
||||
<td>
|
||||
<Link to={url}>{item.title}</Link><br />
|
||||
Link to <a href={item.url} target="_blank" rel="noopener noreferrer">{item.url}</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ItemUrl;
|
||||
@@ -1,13 +1,13 @@
|
||||
.itemtype {
|
||||
.itemTypes :global(td.itemType) {
|
||||
width: 50%;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.itemtype table {
|
||||
.itemTypes :global(td.itemType table) {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.itemtypeName {
|
||||
vertical-align: middle !important;
|
||||
.itemTypes :global(td.itemType table .itemTypeName) {
|
||||
vertical-align: middle;
|
||||
font-size: large;
|
||||
}
|
||||
@@ -1,161 +1,28 @@
|
||||
import React, { Component } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import ItemBook from '../common/ItemBook';
|
||||
import ItemConference from '../common/ItemConference';
|
||||
import ItemData from '../common/ItemData';
|
||||
import ItemPaper from '../common/ItemPaper';
|
||||
import ItemModel from '../common/ItemModel';
|
||||
import ItemUrl from '../common/ItemUrl';
|
||||
import styles from './DatabaseItemTypes.module.css';
|
||||
|
||||
import iconConference from '../assets/images/database/icon_conference.gif';
|
||||
import iconPaper from '../assets/images/database/icon_paper.gif';
|
||||
import iconBook from '../assets/images/database/icon_book.gif';
|
||||
import iconData from '../assets/images/database/icon_data.gif';
|
||||
import iconModel from '../assets/images/database/icon_model.gif';
|
||||
import iconUrl from '../assets/images/database/icon_url.gif';
|
||||
|
||||
class DatabaseItemTypes extends Component {
|
||||
render() {
|
||||
return (
|
||||
<table>
|
||||
<table className={styles.itemTypes}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className={styles.itemtype}>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconConference} alt="Conference" />
|
||||
</td>
|
||||
<td className={styles.itemtypeName}>
|
||||
<Link to="/database/itemtype/conference">Conference</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
Electrical presentation files for conference.<br />
|
||||
|
||||
<Link to="/database/itemtype/conference/powerpoint">PowerPoint</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/conference/pdf">PDF</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/conference/illustrator">Illustrator</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/conference/other">Other</Link>
|
||||
</td>
|
||||
<td className={styles.itemtype}>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconPaper} alt="Paper" />
|
||||
</td>
|
||||
<td className={styles.itemtypeName}>
|
||||
<Link to="/database/itemtype/paper">Paper</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
Related paper collection.<br />
|
||||
|
||||
</td>
|
||||
{ItemConference.renderTop()}
|
||||
{ItemPaper.renderTop()}
|
||||
</tr>
|
||||
<tr>
|
||||
<td className={styles.itemtype}>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconBook} alt="Book" />
|
||||
</td>
|
||||
<td className={styles.itemtypeName}>
|
||||
<Link to="/database/itemtype/book">Book</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
Related Book Collection.<br />
|
||||
|
||||
</td>
|
||||
<td className={styles.itemtype}>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconData} alt="Data" />
|
||||
</td>
|
||||
<td className={styles.itemtypeName}>
|
||||
<Link to="/database/itemtype/data">Data</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
Result data in numerical text/image/movie formats.<br />
|
||||
|
||||
<Link to="/database/itemtype/data/excel">Excel</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/data/movie">Movie</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/data/text">Text</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/data/picture">Picture</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/data/other">Other</Link>
|
||||
</td>
|
||||
{ItemBook.renderTop()}
|
||||
{ItemData.renderTop()}
|
||||
</tr>
|
||||
<tr>
|
||||
<td className={styles.itemtype}>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconModel} alt="Model" />
|
||||
</td>
|
||||
<td className={styles.itemtypeName}>
|
||||
<Link to="/database/itemtype/model">Model</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
Model programs/scripts.<br />
|
||||
|
||||
<Link to="/database/itemtype/model/matlab">Matlab</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/neuron">Neuron</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/original_program">Original Program</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/satellite">Satellite</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/genesis">Genesis</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/a_cell">A-Cell</Link>
|
||||
/
|
||||
<Link to="/database/itemtype/model/other">Other</Link>
|
||||
</td>
|
||||
<td className={styles.itemtype}>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img src={iconUrl} alt="Url" />
|
||||
</td>
|
||||
<td className={styles.itemtypeName}>
|
||||
<Link to="/database/itemtype/url">Url</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
Link information.<br />
|
||||
|
||||
</td>
|
||||
{ItemModel.renderTop()}
|
||||
{ItemUrl.renderTop()}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -8,21 +8,9 @@
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.listTable td.listIcon {
|
||||
.listTable :global(.listIcon) {
|
||||
vertical-align: middle;
|
||||
text-align: center;
|
||||
width: 65px;
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
.sortCriteria {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pageNavi {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.pageNaviItem {
|
||||
margin: 0 5px;
|
||||
}
|
||||
+43
-295
@@ -1,72 +1,21 @@
|
||||
import React, { Component, ChangeEvent } from 'react';
|
||||
import { RouteComponentProps, StaticContext } from 'react-router';
|
||||
import { Link } from 'react-router-dom';
|
||||
import qs from 'query-string';
|
||||
|
||||
import Index, { IIndexDetail, PUBCIC_INDEX_ID } from '../common/Index';
|
||||
import Item, { ISortCondition, SORT_CONDITION_DEFAULT } from '../common/Item';
|
||||
import DatabaseListItem from './DatabaseListItem';
|
||||
import styles from './DatabaseList.module.css';
|
||||
|
||||
import treeJson from '../assets/tree.json';
|
||||
import iconFolder from '../assets/images/database/icon_folder.gif';
|
||||
|
||||
interface ITreeJson {
|
||||
id: number;
|
||||
title: string;
|
||||
num_of_items: number;
|
||||
children: ITreeJson[];
|
||||
}
|
||||
|
||||
interface IIndexBase {
|
||||
id: number;
|
||||
title: string;
|
||||
}
|
||||
|
||||
interface IIndex extends IIndexBase {
|
||||
num_of_indexes: number;
|
||||
num_of_items: number;
|
||||
}
|
||||
|
||||
interface IIndexDetail extends IIndex {
|
||||
path: IIndexBase[];
|
||||
children: IIndex[];
|
||||
}
|
||||
|
||||
interface IProps extends RouteComponentProps<{ id: string }, StaticContext, any> { }
|
||||
|
||||
interface IState {
|
||||
index: IIndexDetail;
|
||||
orderby: string;
|
||||
order_dir: number;
|
||||
page: number;
|
||||
itemcount: number;
|
||||
itemElement: JSX.Element[];
|
||||
condition: ISortCondition;
|
||||
items: {
|
||||
total: number;
|
||||
data: any[];
|
||||
}
|
||||
}
|
||||
|
||||
const PUBCIC_INDEX_ID = 3;
|
||||
|
||||
const getIndexUrl = (id: number): string => {
|
||||
return '/database/list/' + String(id);
|
||||
}
|
||||
|
||||
const IndexNode = (index: IIndex): JSX.Element => {
|
||||
const url = getIndexUrl(index.id);
|
||||
return (
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className={styles.listIcon}>
|
||||
<Link to={url}><img alt={index.title} src={iconFolder} /></Link>
|
||||
</td>
|
||||
<td>
|
||||
<Link to={url}>{index.title}</Link>
|
||||
<br />
|
||||
{index.num_of_indexes} indexes / {index.num_of_items} items
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
};
|
||||
|
||||
class DatabaseList extends Component<IProps, IState> {
|
||||
|
||||
public state: IState = {
|
||||
@@ -78,287 +27,86 @@ class DatabaseList extends Component<IProps, IState> {
|
||||
path: [],
|
||||
children: []
|
||||
},
|
||||
orderby: 'title',
|
||||
order_dir: 0,
|
||||
itemcount: 20,
|
||||
page: 1,
|
||||
itemElement: []
|
||||
condition: Object.assign({}, SORT_CONDITION_DEFAULT),
|
||||
items: {
|
||||
total: 0,
|
||||
data: []
|
||||
}
|
||||
};
|
||||
|
||||
constructor(props: IProps) {
|
||||
super(props);
|
||||
const { params } = this.props.match;
|
||||
const query = qs.parse(this.props.location.search);
|
||||
const indexId = params.id ? parseInt(params.id, 10) : PUBCIC_INDEX_ID;
|
||||
const indexInfo = this.getIndexInfo(indexId);
|
||||
this.state.index = indexInfo;
|
||||
if (typeof query.orderby === 'string') {
|
||||
this.state.orderby = query.orderby;
|
||||
}
|
||||
if (typeof query.order_dir === 'string') {
|
||||
this.state.order_dir = parseInt(query.order_dir, 10);
|
||||
}
|
||||
if (typeof query.itemcount === 'string') {
|
||||
this.state.itemcount = parseInt(query.itemcount, 10);
|
||||
}
|
||||
if (typeof query.page === 'string') {
|
||||
this.state.page = parseInt(query.page, 10);
|
||||
}
|
||||
|
||||
this.state.index = Index.getDetail(indexId);
|
||||
this.state.condition = Item.getSortConditionByQuery(this.props.location.search);
|
||||
this.state.items = Item.getListByIndexId(this.state.index.id, this.state.condition);
|
||||
this.handleSelectOrderby = this.handleSelectOrderby.bind(this);
|
||||
this.handleSelectItemcount = this.handleSelectItemcount.bind(this);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps: IProps) {
|
||||
const { params } = nextProps.match;
|
||||
const indexId = params.id ? parseInt(params.id, 10) : PUBCIC_INDEX_ID;
|
||||
const index = Index.getDetail(indexId);
|
||||
const condition = Item.getSortConditionByQuery(nextProps.location.search);
|
||||
const items = Item.getListByIndexId(indexId, condition);
|
||||
this.setState({ index, condition, items });
|
||||
}
|
||||
|
||||
getIndexId(): number {
|
||||
return this.state.index.id;
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps: IProps) {
|
||||
const { params } = nextProps.match;
|
||||
const query = qs.parse(nextProps.location.search);
|
||||
const indexId = params.id ? parseInt(params.id, 10) : PUBCIC_INDEX_ID;
|
||||
const index = this.getIndexInfo(indexId);
|
||||
if (typeof query.orderby === 'string') {
|
||||
this.setState({ orderby: query.orderby });
|
||||
}
|
||||
if (typeof query.order_dir === 'string') {
|
||||
this.setState({ order_dir: parseInt(query.order_dir, 10) });
|
||||
}
|
||||
if (typeof query.itemcount === 'string') {
|
||||
this.setState({ itemcount: parseInt(query.itemcount, 10) });
|
||||
}
|
||||
this.setState({ index });
|
||||
}
|
||||
|
||||
getLinkUrl(query: { orderby?: string, order_dir?: number, itemcount?: number, page?: number }): string {
|
||||
const newOrderby = query.orderby ? query.orderby : this.state.orderby;
|
||||
const newOrderDir = query.order_dir ? query.order_dir : this.state.order_dir;
|
||||
const newItemcount = query.itemcount ? query.itemcount : this.state.itemcount;
|
||||
const newPage = query.page ? query.page : this.state.page;
|
||||
const url = getIndexUrl(this.getIndexId());
|
||||
let params: string[] = [];
|
||||
if ('title' !== newOrderby) {
|
||||
params.push('orderby=' + newOrderby);
|
||||
}
|
||||
if (0 !== newOrderDir) {
|
||||
params.push('order_dir=' + String(newOrderDir));
|
||||
}
|
||||
if (20 !== newItemcount) {
|
||||
params.push('itemcount=' + String(newItemcount));
|
||||
}
|
||||
if (1 !== newPage) {
|
||||
params.push('page=' + String(newPage));
|
||||
}
|
||||
return (params.length > 0 ? url + '?' + params.join('&') : url);
|
||||
}
|
||||
|
||||
handleSelectOrderby(event: ChangeEvent<HTMLSelectElement>) {
|
||||
const target = event.target;
|
||||
const value = target.value;
|
||||
const url = this.getLinkUrl({ orderby: value });
|
||||
const baseUrl = Index.getUrl(this.getIndexId());
|
||||
const url = Item.getListUrl(baseUrl, this.state.condition, { orderby: value });
|
||||
this.props.history.push(url);
|
||||
}
|
||||
|
||||
handleSelectItemcount(event: ChangeEvent<HTMLSelectElement>) {
|
||||
const target = event.target;
|
||||
const value = parseInt(target.value, 10);
|
||||
const url = this.getLinkUrl({ itemcount: value });
|
||||
const baseUrl = Index.getUrl(this.getIndexId());
|
||||
const url = Item.getListUrl(baseUrl, this.state.condition, { limit: value });
|
||||
this.props.history.push(url);
|
||||
}
|
||||
|
||||
getIndexInfo(indexId: number): IIndexDetail {
|
||||
let index: IIndexDetail = {
|
||||
id: indexId,
|
||||
title: '',
|
||||
num_of_indexes: 0,
|
||||
num_of_items: 0,
|
||||
path: [],
|
||||
children: []
|
||||
};
|
||||
let found: boolean = false;
|
||||
const loop = (data: ITreeJson[]) => {
|
||||
data.forEach((item: ITreeJson) => {
|
||||
if (found) {
|
||||
return;
|
||||
}
|
||||
const path: IIndexBase = {
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
}
|
||||
index.path.push(path);
|
||||
if (indexId === item.id) {
|
||||
index.id = item.id;
|
||||
index.title = item.title;
|
||||
index.num_of_indexes = item.children.length;
|
||||
index.num_of_items = item.num_of_items;
|
||||
found = true;
|
||||
item.children.forEach((item: ITreeJson) => {
|
||||
index.children.push({
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
num_of_indexes: item.children.length,
|
||||
num_of_items: item.num_of_items
|
||||
});
|
||||
});
|
||||
} else {
|
||||
loop(item.children);
|
||||
}
|
||||
if (found === false) {
|
||||
index.path.pop();
|
||||
}
|
||||
});
|
||||
};
|
||||
loop(treeJson);
|
||||
return index;
|
||||
}
|
||||
|
||||
renderIndexPath(): JSX.Element {
|
||||
let elements: JSX.Element[] = [];
|
||||
this.state.index.path.forEach((path: IIndexBase) => {
|
||||
const url: string = getIndexUrl(path.id);
|
||||
elements.push(<span key={path.id}>/ <Link to={url}>{path.title}</Link> </span>);
|
||||
renderItemList(): JSX.Element {
|
||||
let evenodd: string = 'even';
|
||||
const itemList = this.state.items.data.map((item) => {
|
||||
evenodd = evenodd === 'even' ? 'odd' : 'even';
|
||||
return (<tr key={item.item_id} className={evenodd}><td><DatabaseListItem id={item.item_id} /></td></tr>);
|
||||
});
|
||||
return <div>{elements}</div>;
|
||||
}
|
||||
|
||||
renderIndexNodeList(): JSX.Element {
|
||||
if (this.state.index.children.length === 0) {
|
||||
if (itemList.length === 0) {
|
||||
return (<></>);
|
||||
}
|
||||
let evenodd: string = 'even';
|
||||
const treeList = this.state.index.children.map((cindex: IIndex) => {
|
||||
evenodd = evenodd === 'even' ? 'odd' : 'even';
|
||||
return (
|
||||
<tr key={cindex.id}>
|
||||
<td className={evenodd}>{IndexNode(cindex)}</td>
|
||||
</tr >
|
||||
);
|
||||
});
|
||||
return (
|
||||
<table className={styles.listTable}>
|
||||
<tbody>
|
||||
{treeList}
|
||||
{itemList}
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
|
||||
renderSortCriteria(): JSX.Element {
|
||||
if (this.state.index.num_of_items === 0) {
|
||||
return (<></>);
|
||||
}
|
||||
let orderDir = <></>;
|
||||
if (this.state.order_dir === 1) {
|
||||
const url = this.getLinkUrl({ order_dir: 0 });
|
||||
orderDir = (<span>
|
||||
▼ <Link to={url}>▲</Link>
|
||||
</span>);
|
||||
} else {
|
||||
const url = this.getLinkUrl({ order_dir: 1 });
|
||||
orderDir = (<span>
|
||||
<Link to={url}>▼</Link> ▲
|
||||
</span>);
|
||||
}
|
||||
return (
|
||||
<div className={styles.sortCriteria}>
|
||||
<table className={styles.listTable}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="odd">
|
||||
Order by
|
||||
<select value={this.state.orderby} onChange={this.handleSelectOrderby}>
|
||||
<option value="title">Title</option>
|
||||
<option value="doi">ID</option>
|
||||
<option value="last_update_date">Last Modified Date</option>
|
||||
<option value="creation_date">Created Date</option>
|
||||
<option value="publication_date">Date</option>
|
||||
</select>
|
||||
{orderDir}
|
||||
</td>
|
||||
<td className="odd">
|
||||
No.Item per page
|
||||
<select value={this.state.itemcount} onChange={this.handleSelectItemcount}>
|
||||
<option value="20">20</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
reunderNumOfItems(): JSX.Element {
|
||||
if (this.state.index.num_of_items === 0) {
|
||||
return (<p>no items found</p>);
|
||||
}
|
||||
let startNum: number = 1 + this.state.itemcount * (this.state.page - 1);
|
||||
let endNum: number = this.state.itemcount * this.state.page;
|
||||
if (startNum > this.state.index.num_of_items) {
|
||||
return (<p>out of range</p>);
|
||||
}
|
||||
if (endNum > this.state.index.num_of_items) {
|
||||
endNum = this.state.index.num_of_items;
|
||||
}
|
||||
return (
|
||||
<p>{startNum} - {endNum} of {this.state.index.num_of_items}</p>
|
||||
);
|
||||
}
|
||||
|
||||
reunderPageNavi(): JSX.Element {
|
||||
if (this.state.index.num_of_items === 0) {
|
||||
return (<></>);
|
||||
}
|
||||
const maxPage = (this.state.index.num_of_items / this.state.itemcount) + 1;
|
||||
const link = (title: string, page: number) => {
|
||||
if (page === 0 || page === this.state.page) {
|
||||
return (<span className={styles.pageNaviItem}>{title}</span>);
|
||||
}
|
||||
const url: string = this.getLinkUrl({ page: page });
|
||||
return (<Link className={styles.pageNaviItem} to={url}>{title}</Link>);
|
||||
}
|
||||
const startPage = (this.state.page - 5) > 1 ? this.state.page - 5 : 1;
|
||||
const endPage = (startPage + 5) > maxPage ? maxPage : startPage + 5;
|
||||
let pageLinks: JSX.Element[] = [];
|
||||
pageLinks.push(link('PREV', this.state.page - 1));
|
||||
for (let i = startPage; i <= endPage; i++) {
|
||||
pageLinks.push(link(String(i), i));
|
||||
}
|
||||
pageLinks.push(link('NEXT', this.state.page === maxPage ? 0 : this.state.page + 1));
|
||||
return (
|
||||
<div className={styles.pageNavi}>
|
||||
{pageLinks}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
render() {
|
||||
const pageNavi = this.reunderPageNavi();
|
||||
const baseUrl = Index.getUrl(this.getIndexId());
|
||||
const pageNavi = Item.renderPageNavi(baseUrl, this.state.items.total, this.state.condition);
|
||||
return (
|
||||
<div className={styles.list}>
|
||||
<h3>Listing item</h3>
|
||||
{this.renderIndexPath()}
|
||||
{this.renderIndexNodeList()}
|
||||
{this.renderSortCriteria()}
|
||||
{this.reunderNumOfItems()}
|
||||
{Index.renderIndexPath(this.state.index)}
|
||||
{Index.renderList(this.state.index)}
|
||||
{Item.renderSortCriteria(baseUrl, this.state.items.total, this.state.condition, this.handleSelectOrderby, this.handleSelectItemcount)}
|
||||
{Item.renderNumOfItems(this.state.items.total, this.state.condition)}
|
||||
{pageNavi}
|
||||
<div>BODY</div>
|
||||
{this.renderItemList()}
|
||||
{pageNavi}
|
||||
</div>
|
||||
);
|
||||
/*
|
||||
|
||||
<table width="100%" cellspacing="5" border="0">
|
||||
<tbody><tr valign="top">
|
||||
<td class="even">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
import Item from '../common/Item';
|
||||
import ItemBook from '../common/ItemBook';
|
||||
import ItemConference from '../common/ItemConference';
|
||||
import ItemData from '../common/ItemData';
|
||||
import ItemModel from '../common/ItemModel';
|
||||
import ItemPaper from '../common/ItemPaper';
|
||||
import ItemUrl from '../common/ItemUrl';
|
||||
|
||||
interface IProps {
|
||||
id: number;
|
||||
}
|
||||
|
||||
interface IState {
|
||||
item_id: number;
|
||||
item: any;
|
||||
}
|
||||
|
||||
class DatabaseListItem extends Component<IProps, IState> {
|
||||
public state: IState = {
|
||||
item_id: 0,
|
||||
item: null,
|
||||
}
|
||||
|
||||
constructor(props: IProps) {
|
||||
super(props);
|
||||
this.state.item_id = props.id;
|
||||
this.state.item = Item.get(props.id);
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.item === null) {
|
||||
return <></>;
|
||||
}
|
||||
switch (this.state.item.item_type_name) {
|
||||
case 'xnpbook':
|
||||
return ItemBook.renderList(this.state.item);
|
||||
case 'xnpconference':
|
||||
return ItemConference.renderList(this.state.item);
|
||||
case 'xnpdata':
|
||||
return ItemData.renderList(this.state.item);
|
||||
case 'xnpmodel':
|
||||
return ItemModel.renderList(this.state.item);
|
||||
case 'xnppaper':
|
||||
return ItemPaper.renderList(this.state.item);
|
||||
case 'xnpurl':
|
||||
return ItemUrl.renderList(this.state.item);
|
||||
default:
|
||||
return <div>ID:{this.state.item_id}</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default DatabaseListItem;
|
||||
@@ -1,11 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import { RouteComponentProps, StaticContext, withRouter } from 'react-router';
|
||||
import Tree, { TreeNode, ExpandData, SelectData } from 'rc-tree';
|
||||
import Tree, { ExpandData, SelectData } from 'rc-tree';
|
||||
import Index from '../common/Index';
|
||||
import styles from './IndexTreeBlock.module.css';
|
||||
import 'rc-tree/assets/index.css';
|
||||
|
||||
import treeJson from '../assets/tree.json';
|
||||
|
||||
interface IProps extends RouteComponentProps<{}, StaticContext, any> { }
|
||||
|
||||
interface IState {
|
||||
@@ -15,13 +14,6 @@ interface IState {
|
||||
selectedKeys: string[];
|
||||
}
|
||||
|
||||
interface ITreeJson {
|
||||
id: number;
|
||||
title: string;
|
||||
num_of_items: number;
|
||||
children: ITreeJson[];
|
||||
}
|
||||
|
||||
class IndexTreeBlock extends Component<IProps, IState> {
|
||||
|
||||
public state: IState = {
|
||||
@@ -37,6 +29,10 @@ class IndexTreeBlock extends Component<IProps, IState> {
|
||||
this.handleClickCloseAll = this.handleClickCloseAll.bind(this);
|
||||
this.handleExpand = this.handleExpand.bind(this);
|
||||
this.handleSelect = this.handleSelect.bind(this);
|
||||
const res = Index.load();
|
||||
this.state.treeElement = res.element;
|
||||
this.state.expandedKeys = res.keys;
|
||||
this.state.expandableKeys = res.keys;
|
||||
}
|
||||
|
||||
handleClickOpenAll() {
|
||||
@@ -57,38 +53,6 @@ class IndexTreeBlock extends Component<IProps, IState> {
|
||||
this.setState({ selectedKeys: [] });
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.loadTreeData();
|
||||
}
|
||||
|
||||
loadTreeData() {
|
||||
const expandedKeys: string[] = [];
|
||||
const loop = (data: ITreeJson[]) => {
|
||||
return data.map((item: ITreeJson) => {
|
||||
let title: string = item.title;
|
||||
if (item.num_of_items > 0) {
|
||||
title += ' (' + item.num_of_items + ')';
|
||||
}
|
||||
if (item.children.length > 0) {
|
||||
expandedKeys.push(String(item.id));
|
||||
return (
|
||||
<TreeNode key={item.id} title={title}>
|
||||
{loop(item.children)}
|
||||
</TreeNode >
|
||||
);
|
||||
}
|
||||
return (<TreeNode key={item.id} title={title} />);
|
||||
});
|
||||
};
|
||||
const data: ITreeJson[] = treeJson;
|
||||
const treeElement: JSX.Element[] = loop(data);
|
||||
this.setState({
|
||||
treeElement,
|
||||
expandedKeys,
|
||||
expandableKeys: expandedKeys
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
|
||||
@@ -1227,6 +1227,11 @@
|
||||
dependencies:
|
||||
"@types/jest-diff" "*"
|
||||
|
||||
"@types/lokijs@^1.5.2":
|
||||
version "1.5.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/lokijs/-/lokijs-1.5.2.tgz#ed228f080033ce1fb16eff4acde65cb9ae0f1bf2"
|
||||
integrity sha512-ZF14v1P1Bjbw8VJRu+p4WS9V926CAOjWF4yq23QmSBWRPe0/GXlUKzSxjP1fi/xi8nrq6zr9ECo8Z/8KsRqroQ==
|
||||
|
||||
"@types/node@*", "@types/node@11.13.8":
|
||||
version "11.13.8"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.13.8.tgz#e5d71173c95533be9842b2c798978f095f912aab"
|
||||
@@ -6093,6 +6098,11 @@ loglevel@^1.4.1:
|
||||
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.1.tgz#e0fc95133b6ef276cdc8887cdaf24aa6f156f8fa"
|
||||
integrity sha1-4PyVEztu8nbNyIh82vJKpvFW+Po=
|
||||
|
||||
lokijs@^1.5.6:
|
||||
version "1.5.6"
|
||||
resolved "https://registry.yarnpkg.com/lokijs/-/lokijs-1.5.6.tgz#6de6b8c3ff7a972fd0104169f81e7ddc244c029f"
|
||||
integrity sha512-xJoDXy8TASTjmXMKr4F8vvNUCu4dqlwY5gmn0g5BajGt1GM3goDCafNiGAh/sfrWgkfWu1J4OfsxWm8yrWweJA==
|
||||
|
||||
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3.1, loose-envify@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
|
||||
|
||||
Reference in New Issue
Block a user