mirror of
https://github.com/ascribe/onion.git
synced 2025-02-14 21:10:27 +01:00
add firstEdition to a piece
This commit is contained in:
parent
773cab6505
commit
773d42a3b8
@ -4,12 +4,12 @@ import alt from '../alt';
|
|||||||
|
|
||||||
import PieceListFetcher from '../fetchers/piece_list_fetcher';
|
import PieceListFetcher from '../fetchers/piece_list_fetcher';
|
||||||
|
|
||||||
|
|
||||||
class PieceListActions {
|
class PieceListActions {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.generateActions(
|
this.generateActions(
|
||||||
'updatePieceList',
|
'updatePieceList',
|
||||||
'updatePieceListRequestActions'
|
'updatePieceListRequestActions',
|
||||||
|
'addFirstEditionToPiece'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ class PieceListActions {
|
|||||||
.catch((err) => reject(err));
|
.catch((err) => reject(err));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchPieceRequestActions() {
|
fetchPieceRequestActions() {
|
||||||
PieceListFetcher
|
PieceListFetcher
|
||||||
.fetchRequestActions()
|
.fetchRequestActions()
|
||||||
@ -40,6 +41,16 @@ class PieceListActions {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchFirstEditionForPiece(pieceId) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
PieceListFetcher.fetchFirstEditionForPiece(pieceId)
|
||||||
|
.then((firstEdition) => {
|
||||||
|
this.actions.addFirstEditionToPiece({pieceId, firstEdition});
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch((err) => reject(err));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default alt.createActions(PieceListActions);
|
export default alt.createActions(PieceListActions);
|
||||||
|
@ -3,14 +3,15 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Router from 'react-router';
|
import Router from 'react-router';
|
||||||
|
|
||||||
|
import PieceListStore from '../../stores/piece_list_store';
|
||||||
|
import PieceListActions from '../../actions/piece_list_actions';
|
||||||
|
|
||||||
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
|
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
|
||||||
import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
|
import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
|
||||||
import Tooltip from 'react-bootstrap/lib/Tooltip';
|
import Tooltip from 'react-bootstrap/lib/Tooltip';
|
||||||
|
|
||||||
import AccordionListItemEditionWidget from './accordion_list_item_edition_widget';
|
import AccordionListItemEditionWidget from './accordion_list_item_edition_widget';
|
||||||
|
|
||||||
import requests from '../../utils/requests';
|
|
||||||
|
|
||||||
import { getLangText } from '../../utils/lang_utils';
|
import { getLangText } from '../../utils/lang_utils';
|
||||||
|
|
||||||
let AccordionListItem = React.createClass({
|
let AccordionListItem = React.createClass({
|
||||||
@ -22,9 +23,14 @@ let AccordionListItem = React.createClass({
|
|||||||
|
|
||||||
mixins: [Router.Navigation],
|
mixins: [Router.Navigation],
|
||||||
|
|
||||||
handleClick(){
|
componentDidMount() {
|
||||||
requests.get('piece_first_edition_id', {'piece_id': this.props.content.id})
|
if(this.props.content.num_editions !== 0) {
|
||||||
.then((res) => this.transitionTo('edition', {editionId: res.bitcoin_id}));
|
PieceListActions.fetchFirstEditionForPiece(this.props.content.id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onChange(state) {
|
||||||
|
this.setState(state);
|
||||||
},
|
},
|
||||||
|
|
||||||
getGlyphicon(){
|
getGlyphicon(){
|
||||||
@ -39,7 +45,6 @@ let AccordionListItem = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className={this.props.className}>
|
<div className={this.props.className}>
|
||||||
@ -57,7 +62,7 @@ let AccordionListItem = React.createClass({
|
|||||||
<h3>{getLangText('by %s', this.props.content.artist_name)}</h3>
|
<h3>{getLangText('by %s', this.props.content.artist_name)}</h3>
|
||||||
<div>
|
<div>
|
||||||
<span>{this.props.content.date_created.split('-')[0]}</span>
|
<span>{this.props.content.date_created.split('-')[0]}</span>
|
||||||
<AccordionListItemEditionWidget
|
<AccordionListItemEditionWidget
|
||||||
piece={this.props.content} />
|
piece={this.props.content} />
|
||||||
{/* <a href={this.props.content.license_type.url} target="_blank" className="pull-right">
|
{/* <a href={this.props.content.license_type.url} target="_blank" className="pull-right">
|
||||||
{getLangText('%s license', this.props.content.license_type.code)}
|
{getLangText('%s license', this.props.content.license_type.code)}
|
||||||
|
@ -6,10 +6,11 @@ import EditionListActions from '../../actions/edition_list_actions';
|
|||||||
import EditionListStore from '../../stores/edition_list_store';
|
import EditionListStore from '../../stores/edition_list_store';
|
||||||
|
|
||||||
import { getLangText } from '../../utils/lang_utils';
|
import { getLangText } from '../../utils/lang_utils';
|
||||||
|
import { mergeOptions } from '../../utils/general_utils';
|
||||||
|
|
||||||
let AccordionListItemEditionWidget = React.createClass({
|
let AccordionListItemEditionWidget = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
piece: React.PropTypes.object
|
piece: React.PropTypes.object.isRequired
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
@ -28,6 +29,9 @@ let AccordionListItemEditionWidget = React.createClass({
|
|||||||
this.setState(state);
|
this.setState(state);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the store to either show or hide the editionListTable
|
||||||
|
*/
|
||||||
toggleTable() {
|
toggleTable() {
|
||||||
let pieceId = this.props.piece.id;
|
let pieceId = this.props.piece.id;
|
||||||
let isEditionListOpen = this.state.isEditionListOpenForPieceId[pieceId] ? this.state.isEditionListOpenForPieceId[pieceId].show : false;
|
let isEditionListOpen = this.state.isEditionListOpenForPieceId[pieceId] ? this.state.isEditionListOpenForPieceId[pieceId].show : false;
|
||||||
@ -40,6 +44,10 @@ let AccordionListItemEditionWidget = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Depending on the state of isEditionListOpenForPieceId we either want to display
|
||||||
|
* a glyphicon arrow pointing upwards or downwards
|
||||||
|
*/
|
||||||
getGlyphicon() {
|
getGlyphicon() {
|
||||||
let pieceId = this.props.piece.id;
|
let pieceId = this.props.piece.id;
|
||||||
let isEditionListOpen = this.state.isEditionListOpenForPieceId[pieceId] ? this.state.isEditionListOpenForPieceId[pieceId].show : false;
|
let isEditionListOpen = this.state.isEditionListOpenForPieceId[pieceId] ? this.state.isEditionListOpenForPieceId[pieceId].show : false;
|
||||||
@ -56,13 +64,29 @@ let AccordionListItemEditionWidget = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
let piece = this.props.piece;
|
||||||
<span
|
let numEditions = piece.num_editions;
|
||||||
onClick={this.toggleTable}
|
|
||||||
className="ascribe-accordion-list-item-edition-widget pull-right">
|
if(numEditions === 1) {
|
||||||
{this.getGlyphicon()} {this.props.piece.num_editions + ' ' + getLangText('Editions')}
|
let firstEditionId = piece && piece.firstEdition ? ', ' + piece.firstEdition.bitcoin_id : '';
|
||||||
</span>
|
let editionMapping = piece && piece.firstEdition ? piece.firstEdition.edition_number + '/' + piece.num_editions : '';
|
||||||
);
|
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
onClick={this.toggleTable}
|
||||||
|
className="ascribe-accordion-list-item-edition-widget pull-right">
|
||||||
|
{this.getGlyphicon()} {editionMapping + ' ' + getLangText('Edition') + firstEditionId}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
onClick={this.toggleTable}
|
||||||
|
className="ascribe-accordion-list-item-edition-widget pull-right">
|
||||||
|
{this.getGlyphicon()} {numEditions + ' ' + getLangText('Editions')}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -16,6 +16,10 @@ let PieceListFetcher = {
|
|||||||
|
|
||||||
fetchRequestActions() {
|
fetchRequestActions() {
|
||||||
return requests.get('pieces_list_request_actions');
|
return requests.get('pieces_list_request_actions');
|
||||||
|
},
|
||||||
|
|
||||||
|
fetchFirstEditionForPiece(pieceId) {
|
||||||
|
return requests.get('piece_first_edition_id', {'piece_id': pieceId});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,26 +27,6 @@ class PieceListStore {
|
|||||||
this.orderAsc = true;
|
this.orderAsc = true;
|
||||||
this.bindActions(PieceListActions);
|
this.bindActions(PieceListActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*onShowEditionList(pieceId) {
|
|
||||||
this.pieceList
|
|
||||||
.forEach((piece) => {
|
|
||||||
if(piece.id === pieceId) {
|
|
||||||
if(piece.show) {
|
|
||||||
piece.show = false;
|
|
||||||
} else {
|
|
||||||
piece.show = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*onCloseAllEditionLists() {
|
|
||||||
this.pieceList
|
|
||||||
.forEach((piece) => {
|
|
||||||
piece.show = false;
|
|
||||||
});
|
|
||||||
}*/
|
|
||||||
|
|
||||||
onUpdatePieceList({ page, pageSize, search, pieceList, orderBy, orderAsc, pieceListCount }) {
|
onUpdatePieceList({ page, pageSize, search, pieceList, orderBy, orderAsc, pieceListCount }) {
|
||||||
this.page = page;
|
this.page = page;
|
||||||
@ -85,11 +65,25 @@ class PieceListStore {
|
|||||||
|
|
||||||
this.pieceList = pieceList;
|
this.pieceList = pieceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdatePieceListRequestActions(requestActions) {
|
onUpdatePieceListRequestActions(requestActions) {
|
||||||
this.pieceList.forEach((piece) => {
|
this.pieceList.forEach((piece) => {
|
||||||
piece.requestAction = requestActions.indexOf(piece.id) > -1;
|
piece.requestAction = requestActions.indexOf(piece.id) > -1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onAddFirstEditionToPiece({pieceId, firstEdition}) {
|
||||||
|
let filteredPieceList = this.pieceList.filter((piece) => piece.id === pieceId);
|
||||||
|
|
||||||
|
if(filteredPieceList.length === 1) {
|
||||||
|
|
||||||
|
let piece = filteredPieceList[0];
|
||||||
|
piece.firstEdition = firstEdition.edition;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error('Could not find a matching piece in piece list since its either not there or piecelist contains duplicates.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default alt.createStore(PieceListStore, 'PieceListStore');
|
export default alt.createStore(PieceListStore, 'PieceListStore');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user