Skip to content

Commit

Permalink
Add widget for created authors
Browse files Browse the repository at this point in the history
  • Loading branch information
appukuttan-shailesh committed Mar 4, 2021
1 parent 989736b commit 94cd2be
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 66 deletions.
142 changes: 98 additions & 44 deletions src/CreateLivePaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class CreateLivePaper extends React.Component {
this.state = {
authors: [{ firstname: "", lastname: "", affiliation: "" }],
corresponding_author: { firstname: "", lastname: "", affiliation: "" }, // "email" removed
created_author: [{ firstname: "", lastname: "", affiliation: "" }], // "email" removed; currently only one creating author permitted
created_author: [{ firstname: "", lastname: "", affiliation: "" }], // "email" removed
approved_author: { firstname: "", lastname: "", affiliation: "" }, // "email" removed
year: new Date()
.toISOString()
Expand Down Expand Up @@ -173,8 +173,10 @@ class CreateLivePaper extends React.Component {
this.handlePublishedChange = this.handlePublishedChange.bind(this);
this.handleYearChange = this.handleYearChange.bind(this);
this.handleAuthorsChange = this.handleAuthorsChange.bind(this);
this.handleCreatedAuthorChange = this.handleCreatedAuthorChange.bind(this);
this.makePageTitleString = this.makePageTitleString.bind(this);
this.makeAuthorsString = this.makeAuthorsString.bind(this);
this.makeCreatedAuthorsString = this.makeCreatedAuthorsString.bind(this);
this.makeAffiliationsString = this.makeAffiliationsString.bind(this);
this.handleAddSection = this.handleAddSection.bind(this);
this.storeSectionInfo = this.storeSectionInfo.bind(this);
Expand Down Expand Up @@ -304,6 +306,7 @@ class CreateLivePaper extends React.Component {
addDerivedData(data) {
data["page_title"] = this.makePageTitleString();
data["authors_string"] = this.makeAuthorsString();
data["created_authors_string"] = this.makeCreatedAuthorsString();
data["affiliations_string"] = this.makeAffiliationsString();
return data;
}
Expand Down Expand Up @@ -337,6 +340,7 @@ class CreateLivePaper extends React.Component {

handleDownload() {
this.makeAuthorsString();
this.makeCreatedAuthorsString();
this.makeAffiliationsString();

function render(data) {
Expand Down Expand Up @@ -632,6 +636,23 @@ class CreateLivePaper extends React.Component {
});
}

handleCreatedAuthorChange(data) {
// remove all entries where firstname and lastname both are empty
function isNotEmpty(item) {
if (item.firstname.trim() !== "" || item.lastname.trim() !== "") {
return true;
} else return false;
}
var created_author_data = data.filter(isNotEmpty);

if (created_author_data.length === 0) {
created_author_data = [{ firstname: "", lastname: "", affiliation: "" }];
}
this.setState({
created_author: created_author_data,
});
}

makePageTitleString() {
const year = new Date(this.state.year).getFullYear();
const author_data = this.state.authors;
Expand Down Expand Up @@ -678,6 +699,30 @@ class CreateLivePaper extends React.Component {
return authors_string;
}

makeCreatedAuthorsString() {
var created_authors_string = "";
this.state.created_author.forEach(function (created_author, index) {
if (created_authors_string !== "") {
created_authors_string = created_authors_string + ", ";
}
if (
created_author.firstname.trim() !== "" ||
created_author.lastname.trim() !== ""
) {
created_authors_string =
created_authors_string +
created_author.firstname +
" " +
created_author.lastname;
if (created_author.affiliation) {
created_authors_string +=
" (" + created_author.affiliation.italics() + ")";
}
}
});
return created_authors_string;
}

makeAffiliationsString() {
var unique_affs = [];
this.state.authors.forEach(function (item) {
Expand Down Expand Up @@ -1040,51 +1085,60 @@ class CreateLivePaper extends React.Component {
this.state.created_author[0]
) && (
<div>
<TextField
label="Creating Author First Name"
variant="outlined"
fullWidth={true}
name="created_author_other_firstname"
value={this.state.created_author[0].firstname}
onChange={this.handleFieldChange}
InputProps={{
style: {
padding: "5px 15px",
},
}}
style={{ width: "45%", marginRight: "2.5%" }}
/>
<TextField
label="Creating Author Last Name"
variant="outlined"
fullWidth={true}
name="created_author_other_lastname"
value={this.state.created_author[0].lastname}
onChange={this.handleFieldChange}
InputProps={{
style: {
padding: "5px 15px",
},
}}
style={{ width: "45%" }}
/>
<br />
<br />
<TextField
label="Creating Author Affiliation"
variant="outlined"
fullWidth={true}
name="created_author_other_affiliation"
value={this.state.created_author[0].affiliation}
onChange={this.handleFieldChange}
InputProps={{
style: {
padding: "5px 15px",
},
}}
style={{ width: "92.5%" }}
<DynamicTable
value={this.state.created_author}
onChangeValue={this.handleCreatedAuthorChange}
/>
</div>

// // ------------------------------------
// <div>
// <TextField
// label="Creating Author First Name"
// variant="outlined"
// fullWidth={true}
// name="created_author_other_firstname"
// value={this.state.created_author[0].firstname}
// onChange={this.handleFieldChange}
// InputProps={{
// style: {
// padding: "5px 15px",
// },
// }}
// style={{ width: "45%", marginRight: "2.5%" }}
// />
// <TextField
// label="Creating Author Last Name"
// variant="outlined"
// fullWidth={true}
// name="created_author_other_lastname"
// value={this.state.created_author[0].lastname}
// onChange={this.handleFieldChange}
// InputProps={{
// style: {
// padding: "5px 15px",
// },
// }}
// style={{ width: "45%" }}
// />
// <br />
// <br />
// <TextField
// label="Creating Author Affiliation"
// variant="outlined"
// fullWidth={true}
// name="created_author_other_affiliation"
// value={this.state.created_author[0].affiliation}
// onChange={this.handleFieldChange}
// InputProps={{
// style: {
// padding: "5px 15px",
// },
// }}
// style={{ width: "92.5%" }}
// />
// </div>
// // -------------------------------------
)}
{/* <br />
<div>
Expand Down
18 changes: 10 additions & 8 deletions src/DynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ export default class DynamicTable extends React.Component {
</td>
<td style={{ padding: "5px 0px 5px 10 px" }}>
<div>
<Tooltip title="Move author down">
<Tooltip title="Move down">
<IconButton
color="primary"
size="small"
aria-label="move author down"
aria-label="move down"
component="span"
style={{ paddingRight: "5px" }}
onClick={context.handleItemMoveDown.bind(context, ind)}
Expand All @@ -126,11 +126,11 @@ export default class DynamicTable extends React.Component {
/>
</IconButton>
</Tooltip>
<Tooltip title="Move author up">
<Tooltip title="Move up">
<IconButton
color="primary"
size="small"
aria-label="move author up"
aria-label="move up"
component="span"
style={{ paddingRight: "5px" }}
onClick={context.handleItemMoveUp.bind(context, ind)}
Expand All @@ -146,11 +146,11 @@ export default class DynamicTable extends React.Component {
/>
</IconButton>
</Tooltip>
<Tooltip title="Delete author">
<Tooltip title="Delete">
<IconButton
color="secondary"
size="small"
aria-label="delete author"
aria-label="delete"
component="span"
onClick={context.handleItemDeleted.bind(context, ind)}
>
Expand Down Expand Up @@ -181,14 +181,16 @@ export default class DynamicTable extends React.Component {
</thead>
<tbody>{this.renderRows()}</tbody>
</table>

<div style={{width:"100%", display:"flex", justifyContent:"flex-end", paddingTop:"10px"}}>
<Button
variant="contained"
color="primary"
onClick={this.handleAdd.bind(this)}
style={{width:"85px"}}
>
Add Author
Add
</Button>
</div>
<hr />
</div>
);
Expand Down
16 changes: 2 additions & 14 deletions src/LivePaper.njk
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,8 @@
<p>
<strong style="font-weight:bolder">Created by:
</strong>
{% if created_author[0].firstname %}
{{ created_author[0].firstname + " " + created_author[0].lastname }}
{% if created_author[0].affiliation %}
(
<em>{{ created_author[0].affiliation }}</em>
)
{% endif %}
{# {% if created_author[0].email %}
(
<em>
<a href="mailto:{{created_author[0].email}}" ">{{ created_author[0].email }}</a>
</em>
)
{% endif %} #}
{% if created_authors_string %}
{{ created_authors_string | safe }}
{% else %}
To be filled...
{% endif %}
Expand Down

0 comments on commit 94cd2be

Please sign in to comment.