1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00

add link functionality

This commit is contained in:
Tim Daubenschütz 2015-06-04 11:41:56 +02:00
parent 0747c89a35
commit 302f05b68e
5 changed files with 37 additions and 7 deletions

View File

@ -1,9 +1,12 @@
import React from 'react'; import React from 'react';
import Router from 'react-router';
import AccordionListItemTable from './accordion_list_item_table'; import AccordionListItemTable from './accordion_list_item_table';
import { getLangText } from '../../utils/lang_utils'; import { getLangText } from '../../utils/lang_utils';
let Link = Router.Link;
let AccordionListItem = React.createClass({ let AccordionListItem = React.createClass({
propTypes: { propTypes: {
className: React.PropTypes.string, className: React.PropTypes.string,

View File

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import Router from 'react-router';
import EditionListStore from '../../stores/edition_list_store'; import EditionListStore from '../../stores/edition_list_store';
import EditionListActions from '../../actions/edition_list_actions'; import EditionListActions from '../../actions/edition_list_actions';
@ -18,6 +19,8 @@ import TableItemAclFiltered from '../ascribe_table/table_item_acl_filtered';
import { getLangText } from '../../utils/lang_utils'; import { getLangText } from '../../utils/lang_utils';
let Link = Router.Link;
let AccordionListItemTableEditions = React.createClass({ let AccordionListItemTableEditions = React.createClass({
propTypes: { propTypes: {
@ -108,7 +111,8 @@ let AccordionListItemTableEditions = React.createClass({
'#', '#',
TableItemText, TableItemText,
1, 1,
true true,
{to: 'edition', paramsKey: 'editionId', contentKey: 'bitcoin_id'}
), ),
new TableColumnContentModel( new TableColumnContentModel(
(item) => { (item) => {
@ -119,7 +123,8 @@ let AccordionListItemTableEditions = React.createClass({
getLangText('Bitcoin Address'), getLangText('Bitcoin Address'),
TableItemText, TableItemText,
5, 5,
true true,
{to: 'edition', paramsKey: 'editionId', contentKey: 'bitcoin_id'}
), ),
new TableColumnContentModel( new TableColumnContentModel(
(item) => { (item) => {
@ -130,7 +135,8 @@ let AccordionListItemTableEditions = React.createClass({
getLangText('Actions'), getLangText('Actions'),
TableItemAclFiltered, TableItemAclFiltered,
4, 4,
false false,
{to: 'edition', paramsKey: 'editionId', contentKey: 'bitcoin_id'}
) )
]; ];

View File

@ -25,7 +25,7 @@ let ResourceViewer = React.createClass({
mixins: [InjectInHeadMixin], mixins: [InjectInHeadMixin],
componentDidMount() { componentDidMount() {
this.inject('http://antani.com'); //this.inject('http://antani.com');
}, },
render() { render() {

View File

@ -1,16 +1,31 @@
import React from 'react'; import React from 'react';
import Router from 'react-router';
import TableColumnContentModel from '../../models/table_column_content_model'; import TableColumnContentModel from '../../models/table_column_content_model';
import TableColumnMixin from '../../mixins/table_column_mixin'; import TableColumnMixin from '../../mixins/table_column_mixin';
let TableItemWrapper = React.createClass({ let TableItemWrapper = React.createClass({
mixins: [TableColumnMixin], mixins: [TableColumnMixin, Router.Navigation],
propTypes: { propTypes: {
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)), columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
columnContent: React.PropTypes.object, columnContent: React.PropTypes.object,
columnWidth: React.PropTypes.number.isRequired columnWidth: React.PropTypes.number.isRequired
}, },
/**
* If a link is defined in columnContent, then we can use
* Router.Navigation.transitionTo to redirect the user
* programmatically
*/
transition(column) {
if(column.link) {
let params = {};
params[column.link.paramsKey] = this.props.columnContent[column.link.contentKey];
this.transitionTo(column.link.to, params);
}
},
render() { render() {
return ( return (
<div> <div>
@ -21,8 +36,13 @@ let TableItemWrapper = React.createClass({
let columnClass = this.calcColumnClasses(this.props.columnList, i, this.props.columnWidth); let columnClass = this.calcColumnClasses(this.props.columnList, i, this.props.columnWidth);
let transition = this.transition.bind(this, column);
return ( return (
<div className={columnClass + ' ascribe-table-item-column'} key={i}> <div
className={columnClass + ' ascribe-table-item-column'}
key={i}
onClick={transition}>
<TypeElement {...typeElementProps} /> <TypeElement {...typeElementProps} />
</div> </div>
); );

View File

@ -1,12 +1,13 @@
class TableColumnContentModel { class TableColumnContentModel {
// ToDo: Add validation for all passed-in parameters // ToDo: Add validation for all passed-in parameters
constructor(transformFn, columnName, displayName, displayType, rowWidth, canBeOrdered) { constructor(transformFn, columnName, displayName, displayType, rowWidth, canBeOrdered, link) {
this.transformFn = transformFn; this.transformFn = transformFn;
this.columnName = columnName; this.columnName = columnName;
this.displayName = displayName; this.displayName = displayName;
this.displayType = displayType; this.displayType = displayType;
this.rowWidth = rowWidth; this.rowWidth = rowWidth;
this.canBeOrdered = canBeOrdered; this.canBeOrdered = canBeOrdered;
this.link = link;
} }
} }